MediaWiki:Gadget-twinkleprod.js: Difference between revisions

Jump to navigation Jump to search
m (1 revision imported)
 
(Add)
 
(2 intermediate revisions by the same user not shown)
Line 10: Line 10:
  ****************************************
  ****************************************
  * Mode of invocation:    Tab ("PROD")
  * Mode of invocation:    Tab ("PROD")
  * Active on:              Existing articles which are not redirects
  * Active on:              Existing articles and files which are not redirects
  * Config directives in:  TwinkleConfig
  * Config directives in:  TwinkleConfig
  */
  */


Twinkle.prod = function twinkleprod() {
Twinkle.prod = function twinkleprod() {
if( mw.config.get('wgNamespaceNumber') !== 0 || !mw.config.get('wgCurRevisionId') || Morebits.wiki.isPageRedirect() ) {
if( [0, 6].indexOf(mw.config.get('wgNamespaceNumber')) === -1 || !mw.config.get('wgCurRevisionId') || Morebits.wiki.isPageRedirect() ) {
return;
return;
}
}


Twinkle.addPortletLink( Twinkle.prod.callback, "PROD", "tw-prod", "Propose deletion via WP:PROD" );
Twinkle.addPortletLink( Twinkle.prod.callback, "PROD", "tw-prod", "Propose deletion via SV:PROD" );
};
};
// Used in edit summaries, for comparisons, etc.
var namespace;


Twinkle.prod.callback = function twinkleprodCallback() {
Twinkle.prod.callback = function twinkleprodCallback() {
Twinkle.prod.defaultReason = Twinkle.getPref('prodReasonDefault');
Twinkle.prod.defaultReason = Twinkle.getPref('prodReasonDefault');
// TODO: add 'book' as well, namespace number 108
switch (mw.config.get('wgNamespaceNumber')) {
case 0:
namespace = 'article';
break;
case 6:
namespace = 'file';
break;
}


var Window = new Morebits.simpleWindow( 800, 410 );
var Window = new Morebits.simpleWindow( 800, 410 );
Window.setTitle( "Proposed deletion (PROD)" );
Window.setTitle( "Proposed deletion (PROD)" );
Window.setScriptName( "Twinkle" );
Window.setScriptName( "Twinkle" );
Window.addFooterLink( "Proposed deletion policy", "WP:PROD" );
Window.addFooterLink( "Proposed deletion policy", "SV:PROD" );
Window.addFooterLink( "BLP PROD policy", "WP:BLPPROD" );
 
Window.addFooterLink( "Twinkle help", "WP:TW/DOC#prod" );
if (namespace === 'article') {
Window.addFooterLink( "BLP PROD policy", "SV:BLPPROD" );
}
 
Window.addFooterLink( "Twinkle help", "SV:TW/DOC#prod" );


var form = new Morebits.quickForm( Twinkle.prod.callback.evaluate );
var form = new Morebits.quickForm( Twinkle.prod.callback.evaluate );
Line 36: Line 53:
var field = form.append( {
var field = form.append( {
type: 'field',
type: 'field',
label: 'PROD type'
label: 'PROD type',
id: 'prodtype_fieldset'
} );
} );
field.append( {
field.append( {
type: 'radio',
type: 'radio',
Line 47: Line 66:
value: 'prod',
value: 'prod',
checked: true,
checked: true,
tooltip: 'Normal proposed deletion, per [[WP:PROD]]'
tooltip: 'Normal proposed deletion, per [[SV:PROD]]'
},
},
{
{
label: 'BLP PROD (proposed deletion of unsourced BLPs)',
label: 'BLP PROD (proposed deletion of unsourced BLPs)',
value: 'prodblp',
value: 'prodblp',
tooltip: 'Proposed deletion of new, completely unsourced biographies of living persons, per [[WP:BLPPROD]]'
tooltip: 'Proposed deletion of new, completely unsourced biographies of living persons, per [[SV:BLPPROD]]'
}
}
]
]
Line 69: Line 88:
Window.display();
Window.display();


// fake a change event on the first prod type radio, to initialize the type-dependent controls
// Fake a change event on the first prod type radio, to initialize the type-dependent controls
var evt = document.createEvent( "Event" );
var evt = document.createEvent( "Event" );
evt.initEvent( 'change', true, true );
evt.initEvent( 'change', true, true );
result.prodtype[0].dispatchEvent( evt );
result.prodtype[0].dispatchEvent( evt );
// Hide fieldset for PROD type if File namespace since only normal PROD is allowed
if (namespace === 'file') {
$('#prodtype_fieldset').hide();
}
};
};


Line 119: Line 143:
value: 'notify',
value: 'notify',
name: 'notify',
name: 'notify',
tooltip: 'Creator of article has to be notified.',
tooltip: 'Creator of ' + namespace + ' has to be notified.',
checked: true,
checked: true,
disabled: true
disabled: true
Line 133: Line 157:
label: boldtext
label: boldtext
});
});
if (mw.config.get('wgArticleId') < 26596183) {
field.append({
type: 'header',
label: 'It appears that this article was created before March 18, 2010, and is thus ineligible for a BLP PROD. Please make sure that this is not the case, or use normal PROD instead.'
});
}
break;
break;


Line 153: Line 171:


if( !pageobj.exists() ) {
if( !pageobj.exists() ) {
statelem.error( "It seems that the page doesn't exist. Perhaps it has already been deleted." );
statelem.error( "It seems that the page doesn't exist. Perhaps it has already been deleted." );
return;
return;
}
}
Line 160: Line 178:
var params = pageobj.getCallbackParameters();
var params = pageobj.getCallbackParameters();


var tag_re = /(\{\{(?:db-?|delete|[aitcmrs]fd|md1)[^{}]*?\|?[^{}]*?\}\})/i;
var tag_re = /({{(?:db-?|delete|[aitcmrs]fd|md1)[^{}]*?\|?[^{}]*?}})/i;
if( tag_re.test( text ) ) {
if( tag_re.test( text ) ) {
statelem.warn( 'Page already tagged with a deletion template, aborting procedure' );
statelem.warn( 'Page already tagged with a deletion template, aborting procedure' );
Line 167: Line 185:


// Remove tags that become superfluous with this action
// Remove tags that become superfluous with this action
text = text.replace(/\{\{\s*([Nn]ew unreviewed article|[Uu]nreviewed|[Uu]serspace draft)\s*(\|(?:\{\{[^{}]*\}\}|[^{}])*)?\}\}\s*/g, "");
text = text.replace(/{{\s*(userspace draft|mtc|(copy|move) to wikimedia commons|(copy |move )?to ?commons)\s*(\|(?:{{[^{}]*}}|[^{}])*)?}}\s*/gi, "");
 
var prod_re = /{{\s*(?:dated prod|dated files|dated prod blp|Prod blp\/dated|Proposed deletion\/dated)\s*\|(?:{{[^{}]*}}|[^{}])*}}/i;
var prod_re = /\{\{\s*(?:dated prod|dated prod blp|Prod blp\/dated|Proposed deletion\/dated)\s*\|(?:\{\{[^\{\}]*\}\}|[^\}\{])*\}\}/i;
var summaryText;
var summaryText;
if( !prod_re.test( text ) ) {
if( !prod_re.test( text ) ) {
Line 183: Line 200:
}
}


summaryText = "Proposing article for deletion per [[WP:" + (params.blp ? "BLP" : "") + "PROD]].";
summaryText = "Proposing " + namespace + " for deletion per [[SV:" + (params.blp ? "BLP" : "") + "PROD]].";
text = "{{subst:prod" + (params.blp ? " blp" : ("|1=" + Morebits.string.formatReasonText(params.reason))) + "}}\n" + text;
text = "{{subst:prod" + (params.blp ? " blp" : ("|1=" + Morebits.string.formatReasonText(params.reason))) + "}}\n" + text;
}
}
else {  // already tagged for PROD, so try endorsing it
else {  // already tagged for PROD, so try endorsing it
var prod2_re = /\{\{(?:Proposed deletion endorsed|prod-?2).*?\}\}/;
var prod2_re = /{{(?:Proposed deletion endorsed|prod-?2).*?}}/;
if( prod2_re.test( text ) ) {
if( prod2_re.test( text ) ) {
statelem.warn( 'Page already tagged with {{prod}} and {{prod-2}} templates, aborting procedure' );
statelem.warn( 'Page already tagged with {{proposed deletion}} and {{proposed deletion endorsed}} templates, aborting procedure' );
return;
return;
}
}
var confirmtext = "A {{prod}} tag was already found on this article. \nWould you like to add a {{prod-2}} (PROD endorsement) tag with your explanation?";
var confirmtext = "A {{proposed deletion}} tag was already found on this " + namespace + ". \nWould you like to add a {{proposed deletion endorsed}} tag with your explanation?";
if (params.blp) {
if (params.blp) {
confirmtext = "A non-BLP {{prod}} tag was found on this article. \nWould you like to add a {{prod-2}} (PROD endorsement) tag with explanation \"article is a biography of a living person with no sources\"?";
confirmtext = "A non-BLP {{proposed deletion}} tag was found on this article.\nWould you like to add a {{proposed deletion endorsed}} tag with explanation \"article is a biography of a living person with no sources\"?";
}
}
if( !confirm( confirmtext ) ) {
if( !confirm( confirmtext ) ) {
Line 201: Line 218:
}
}


summaryText = "Endorsing proposed deletion per [[WP:" + (params.blp ? "BLP" : "") + "PROD]].";
summaryText = "Endorsing proposed deletion per [[SV:" + (params.blp ? "BLP" : "") + "PROD]].";
text = text.replace( prod_re, text.match( prod_re ) + "\n{{prod-2|1=" + (params.blp ?
text = text.replace( prod_re, text.match( prod_re ) + "\n{{proposed deletion endorsed|1=" + (params.blp ?
"article is a [[WP:BLPPROD|biography of a living person with no sources]]" :
"article is a [[SV:BLPPROD|biography of a living person with no sources]]" :
Morebits.string.formatReasonText(params.reason)) + "}}\n" );
Morebits.string.formatReasonText(params.reason)) + "}}\n" );


Line 231: Line 248:
return;
return;
}
}
// [[Template:Proposed deletion notify]] supports File namespace
var notifyTemplate = params.blp ? 'prodwarningBLP' : 'proposed deletion notify';


var usertalkpage = new Morebits.wiki.page('User talk:' + initialContrib, "Notifying initial contributor (" + initialContrib + ")");
var usertalkpage = new Morebits.wiki.page('User talk:' + initialContrib, "Notifying initial contributor (" + initialContrib + ")");
var notifytext = "\n{{subst:prodwarning" + (params.blp ? "BLP" : "") + "|1=" + Morebits.pageNameNorm + "|concern=" + params.reason + "}} ~~~~";
var notifytext = "\n{{subst:" + notifyTemplate + "|1=" + Morebits.pageNameNorm + "|concern=" + params.reason + "}} ~~~~";
usertalkpage.setAppendText(notifytext);
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary("Notification: proposed deletion of [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
usertalkpage.setEditSummary("Notification: proposed deletion of [[:" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
usertalkpage.setCreateOption('recreate');
usertalkpage.setCreateOption('recreate');
usertalkpage.setFollowRedirect(true);
usertalkpage.setFollowRedirect(true);
Line 258: Line 278:
if (!pageobj.exists()) {
if (!pageobj.exists()) {
text =
text =
"This is a log of all [[WP:PROD|proposed deletion]] tags applied or endorsed by this user using [[WP:TW|Twinkle]]'s PROD module.\n\n" +
"This is a log of all [[SV:PROD|proposed deletion]] tags applied or endorsed by this user using [[SV:TW|Twinkle]]'s PROD module.\n\n" +
"If you no longer wish to keep this log, you can turn it off using the [[Wikipedia:Twinkle/Preferences|preferences panel]], and " +
"If you no longer wish to keep this log, you can turn it off using the [[Sarkarverse:Twinkle/Preferences|preferences panel]], and " +
"nominate this page for speedy deletion under [[WP:CSD#U1|CSD U1]].\n";
"nominate this page for speedy deletion under [[SV:CSD#U1|CSD U1]].\n";
}
}


Line 272: Line 292:
var summarytext;
var summarytext;
if (params.logEndorsing) {
if (params.logEndorsing) {
text += "\n# [[" + Morebits.pageNameNorm + "]]: endorsed " + (params.blp ? "BLP " : "") + "PROD. ~~~~~";
text += "\n# [[:" + Morebits.pageNameNorm + "]]: endorsed " + (params.blp ? "BLP " : "") + "PROD. ~~~~~";
if (params.reason) {
if (params.reason) {
text += "\n#* '''Reason''': " + params.reason + "\n";
text += "\n#* '''Reason''': " + params.reason + "\n";
}
}
summarytext = "Logging endorsement of PROD nomination of [[" + Morebits.pageNameNorm + "]].";
summarytext = "Logging endorsement of PROD nomination of [[:" + Morebits.pageNameNorm + "]].";
} else {
} else {
text += "\n# [[" + Morebits.pageNameNorm + "]]: " + (params.blp ? "BLP " : "") + "PROD";
text += "\n# [[:" + Morebits.pageNameNorm + "]]: " + (params.blp ? "BLP " : "") + "PROD";
if (params.logInitialContrib) {
if (params.logInitialContrib) {
text += "; notified {{user|" + params.logInitialContrib + "}}";
text += "; notified {{user|" + params.logInitialContrib + "}}";
Line 286: Line 306:
text += "#* '''Reason''': " + params.reason + "\n";
text += "#* '''Reason''': " + params.reason + "\n";
}
}
summarytext = "Logging PROD nomination of [[" + Morebits.pageNameNorm + "]].";
summarytext = "Logging PROD nomination of [[:" + Morebits.pageNameNorm + "]].";
}
}


Line 317: Line 337:
Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.status.init( form );
Morebits.status.init( form );
if (prodtype === 'prodblp' && mw.config.get('wgArticleId') < 26596183) {
if (!confirm( "It appears that this article was created before March 18, 2010, and is thus ineligible for a BLP PROD. Do you want to continue tagging it?" )) {
Morebits.status.warn( 'Notice', 'Aborting per user input.' );
return;
}
}


Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');