MediaWiki:Gadget-friendlyshared.js: Difference between revisions

Content added Content deleted
imported>Amorymeltzer
(Updates at a1b22de: Make use of wgRelevantUserName)
imported>Amorymeltzer
(Repo at d404881: Greatly expand style guidelines, enforce linting rules (#657))
 
Line 1: Line 1:
//<nowiki>
// <nowiki>




(function($){ // eslint-disable-line no-unused-vars
(function($) { // eslint-disable-line no-unused-vars




Line 15: Line 15:


Twinkle.shared = function friendlyshared() {
Twinkle.shared = function friendlyshared() {
if( mw.config.get('wgNamespaceNumber') === 3 && mw.util.isIPAddress(mw.config.get('wgTitle')) ) {
if (mw.config.get('wgNamespaceNumber') === 3 && mw.util.isIPAddress(mw.config.get('wgTitle'))) {
var username = mw.config.get('wgRelevantUserName');
var username = mw.config.get('wgRelevantUserName');
Twinkle.addPortletLink( function(){ Twinkle.shared.callback(username); }, "Shared IP", "friendly-shared", "Shared IP tagging" );
Twinkle.addPortletLink(function() {
Twinkle.shared.callback(username);
}, 'Shared IP', 'friendly-shared', 'Shared IP tagging');
}
}
};
};


Twinkle.shared.callback = function friendlysharedCallback() {
Twinkle.shared.callback = function friendlysharedCallback() {
var Window = new Morebits.simpleWindow( 600, 420 );
var Window = new Morebits.simpleWindow(600, 420);
Window.setTitle( "Shared IP address tagging" );
Window.setTitle('Shared IP address tagging');
Window.setScriptName( "Twinkle" );
Window.setScriptName('Twinkle');
Window.addFooterLink( "Twinkle help", "WP:TW/DOC#shared" );
Window.addFooterLink('Twinkle help', 'WP:TW/DOC#shared');


var form = new Morebits.quickForm( Twinkle.shared.callback.evaluate );
var form = new Morebits.quickForm(Twinkle.shared.callback.evaluate);


var div = form.append( {
var div = form.append({
type: 'div',
type: 'div',
id: 'sharedip-templatelist',
id: 'sharedip-templatelist',
className: 'morebits-scrollbox'
className: 'morebits-scrollbox'
}
}
);
);
div.append( { type: 'header', label: 'Shared IP address templates' } );
div.append({ type: 'header', label: 'Shared IP address templates' });
div.append( { type: 'radio', name: 'shared', list: Twinkle.shared.standardList,
div.append({ type: 'radio', name: 'shared', list: Twinkle.shared.standardList,
event: function( e ) {
event: function(e) {
Twinkle.shared.callback.change_shared( e );
Twinkle.shared.callback.change_shared(e);
e.stopPropagation();
e.stopPropagation();
}
}
} );
});


var org = form.append( { type:'field', label:'Fill in other details (optional) and click "Submit"' } );
var org = form.append({ type: 'field', label: 'Fill in other details (optional) and click "Submit"' });
org.append( {
org.append({
type: 'input',
type: 'input',
name: 'organization',
name: 'organization',
label: 'IP address owner/operator',
label: 'IP address owner/operator',
disabled: true,
disabled: true,
tooltip: 'You can optionally enter the name of the organization that owns/operates the IP address. You can use wikimarkup if necessary.'
tooltip: 'You can optionally enter the name of the organization that owns/operates the IP address. You can use wikimarkup if necessary.'
}
}
);
);
org.append( {
org.append({
type: 'input',
type: 'input',
name: 'host',
name: 'host',
label: 'Host name (optional)',
label: 'Host name (optional)',
disabled: true,
disabled: true,
tooltip: 'The host name (for example, proxy.example.com) can be optionally entered here and will be linked by the template.'
tooltip: 'The host name (for example, proxy.example.com) can be optionally entered here and will be linked by the template.'
}
}
);
);
org.append( {
org.append({
type: 'input',
type: 'input',
name: 'contact',
name: 'contact',
label: 'Contact information (only if requested)',
label: 'Contact information (only if requested)',
disabled: true,
disabled: true,
tooltip: 'You can optionally enter some contact details for the organization. Use this parameter only if the organization has specifically requested that it be added. You can use wikimarkup if necessary.'
tooltip: 'You can optionally enter some contact details for the organization. Use this parameter only if the organization has specifically requested that it be added. You can use wikimarkup if necessary.'
}
}
);
);


form.append( { type:'submit' } );
form.append({ type: 'submit' });


var result = form.render();
var result = form.render();
Window.setContent( result );
Window.setContent(result);
Window.display();
Window.display();
};
};
Line 121: Line 123:


Twinkle.shared.callback.change_shared = function friendlysharedCallbackChangeShared(e) {
Twinkle.shared.callback.change_shared = function friendlysharedCallbackChangeShared(e) {
e.target.form.contact.disabled = (e.target.value !== 'Shared IP edu'); // only supported by {{Shared IP edu}}
e.target.form.contact.disabled = e.target.value !== 'Shared IP edu'; // only supported by {{Shared IP edu}}
e.target.form.organization.disabled = false;
e.target.form.organization.disabled = false;
e.target.form.host.disabled = (e.target.value === 'Whois'); // host= not supported by {{Whois}}
e.target.form.host.disabled = e.target.value === 'Whois'; // host= not supported by {{Whois}}
};
};


Twinkle.shared.callbacks = {
Twinkle.shared.callbacks = {
main: function( pageobj ) {
main: function(pageobj) {
var params = pageobj.getCallbackParameters();
var params = pageobj.getCallbackParameters();
var pageText = pageobj.getPageText();
var pageText = pageobj.getPageText();
Line 133: Line 135:
var text = '{{';
var text = '{{';


for( var i=0; i < Twinkle.shared.standardList.length; i++ ) {
for (var i = 0; i < Twinkle.shared.standardList.length; i++) {
var tagRe = new RegExp( '(\\{\\{' + Twinkle.shared.standardList[i].value + '(\\||\\}\\}))', 'im' );
var tagRe = new RegExp('(\\{\\{' + Twinkle.shared.standardList[i].value + '(\\||\\}\\}))', 'im');
if( tagRe.exec( pageText ) ) {
if (tagRe.exec(pageText)) {
Morebits.status.warn( 'Info', 'Found {{' + Twinkle.shared.standardList[i].value + '}} on the user\'s talk page already...aborting' );
Morebits.status.warn('Info', 'Found {{' + Twinkle.shared.standardList[i].value + '}} on the user\'s talk page already...aborting');
found = true;
found = true;
}
}
}
}


if( found ) {
if (found) {
return;
return;
}
}


Morebits.status.info( 'Info', 'Will add the shared IP address template to the top of the user\'s talk page.' );
Morebits.status.info('Info', 'Will add the shared IP address template to the top of the user\'s talk page.');
text += params.value + '|' + params.organization;
text += params.value + '|' + params.organization;
if( params.value === 'Shared IP edu' && params.contact !== '') {
if (params.value === 'Shared IP edu' && params.contact !== '') {
text += '|' + params.contact;
text += '|' + params.contact;
}
}
if( params.value !== 'Whois' && params.host !== '' ) {
if (params.value !== 'Whois' && params.host !== '') {
text += '|host=' + params.host;
text += '|host=' + params.host;
}
}
Line 165: Line 167:


Twinkle.shared.callback.evaluate = function friendlysharedCallbackEvaluate(e) {
Twinkle.shared.callback.evaluate = function friendlysharedCallbackEvaluate(e) {
var shared = e.target.getChecked( 'shared' );
var shared = e.target.getChecked('shared');
if( !shared || shared.length <= 0 ) {
if (!shared || shared.length <= 0) {
alert( 'You must select a shared IP address template to use!' );
alert('You must select a shared IP address template to use!');
return;
return;
}
}
Line 173: Line 175:
var value = shared[0];
var value = shared[0];


if( e.target.organization.value === '') {
if (e.target.organization.value === '') {
alert( 'You must input an organization for the {{' + value + '}} template!' );
alert('You must input an organization for the {{' + value + '}} template!');
return;
return;
}
}
Line 185: Line 187:
};
};


Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init( e.target );
Morebits.status.init(e.target);


Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
Morebits.wiki.actionCompleted.notice = "Tagging complete, reloading talk page in a few seconds";
Morebits.wiki.actionCompleted.notice = 'Tagging complete, reloading talk page in a few seconds';


var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), "User talk page modification");
var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), 'User talk page modification');
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.setCallbackParameters(params);
Line 199: Line 201:




//</nowiki>
// </nowiki>