MediaWiki:Gadget-twinklewarn.js: Difference between revisions

m
1 revision imported
m (1 revision imported)
 
m (1 revision imported)
(One intermediate revision by the same user not shown)
Line 25: Line 25:
$vandalTalkLink.css("font-weight", "bold");
$vandalTalkLink.css("font-weight", "bold");
$vandalTalkLink.wrapInner($("<span/>").attr("title", "If appropriate, you can use Twinkle to warn the user about their edits to this page."));
$vandalTalkLink.wrapInner($("<span/>").attr("title", "If appropriate, you can use Twinkle to warn the user about their edits to this page."));
 
var extraParam = "vanarticle=" + mw.util.rawurlencode(Morebits.pageNameNorm);
var extraParam = "vanarticle=" + mw.util.rawurlencode(Morebits.pageNameNorm);
var href = $vandalTalkLink.attr("href");
var href = $vandalTalkLink.attr("href");
Line 72: Line 72:
if( Twinkle.getPref( 'customWarningList' ).length ) {
if( Twinkle.getPref( 'customWarningList' ).length ) {
main_group.append( { type: 'option', label: 'Custom warnings', value: 'custom', selected: ( defaultGroup === 9 ) } );
main_group.append( { type: 'option', label: 'Custom warnings', value: 'custom', selected: ( defaultGroup === 9 ) } );
}
if( Morebits.userIsInGroup( 'sysop' ) ) {
main_group.append( { type: 'option', label: 'Blocking', value: 'block', selected: ( defaultGroup === 8 ) } );
}
}


Line 1,163: Line 1,160:
summary: "Warning: Using inaccurate or inappropriate edit summaries"
summary: "Warning: Using inaccurate or inappropriate edit summaries"
}
}
},
}
};


Twinkle.warn.prev_article = null;
Twinkle.warn.prev_reason = null;


block: {
Twinkle.warn.callback.change_category = function twinklewarnCallbackChangeCategory(e) {
"uw-block": {
var value = e.target.value;
label: "Block",
var sub_group = e.target.root.sub_group;
summary: "You have been blocked from editing",
sub_group.main_group = value;
pageParam: true,
var old_subvalue = sub_group.value;
reasonParam: true,  // allows editing of reason for generic templates
var old_subvalue_re;
suppressArticleInSummary: true
if( old_subvalue ) {
},
old_subvalue = old_subvalue.replace(/\d*(im)?$/, '' );
"uw-blocknotalk": {
old_subvalue_re = new RegExp( $.escapeRE( old_subvalue ) + "(\\d*(?:im)?)$" );
label: "Block - talk page disabled",
}
summary: "You have been blocked from editing and your user talk page has been disabled",
pageParam: true,
reasonParam: true,
suppressArticleInSummary: true
},
"uw-blockindef": {
label: "Block - indefinite",
summary: "You have been indefinitely blocked from editing",
indefinite: true,
pageParam: true,
reasonParam: true,
suppressArticleInSummary: true
},
"uw-ablock": {
label: "Block - IP address",
summary: "Your IP address has been blocked from editing",
pageParam: true,
suppressArticleInSummary: true
},
"uw-vblock": {
label: "Vandalism block",
summary: "You have been blocked from editing for persistent [[WP:VAND|vandalism]]",
pageParam: true
},
"uw-voablock": {
label: "Vandalism-only account block (indefinite)",
summary: "You have been indefinitely blocked from editing because your account is being [[WP:VOA|used only for vandalism]]",
indefinite: true,
pageParam: true
},
"uw-bioblock": {
label: "BLP violations block",
summary: "You have been blocked from editing for violations of Wikipedia's [[WP:BLP|biographies of living persons policy]]",
pageParam: true
},
"uw-sblock": {
label: "Spam block",
summary: "You have been blocked from editing for using Wikipedia for [[WP:SPAM|spam]] purposes"
},
"uw-adblock": {
label: "Advertising block",
summary: "You have been blocked from editing for [[WP:SOAP|advertising or self-promotion]]",
pageParam: true
},
"uw-soablock": {
label: "Spam/advertising-only account block (indefinite)",
summary: "You have been indefinitely blocked from editing because your account is being used only for [[WP:SPAM|spam, advertising, or promotion]]",
indefinite: true,
pageParam: true
},
"uw-nothereblock": {
label: "WP:NOTHERE block (indefinite)",
summary: "You have been indefinitely blocked from editing because it appears that you are not here to [[WP:NOTHERE|build an encyclopedia]]",
indefinite: true
},
"uw-npblock": {
label: "Creating nonsense pages block",
summary: "You have been blocked from editing for creating [[WP:PN|nonsense pages]]",
pageParam: true
},
"uw-copyrightblock": {
label: "Copyright violation block",
summary: "You have been blocked from editing for continued [[WP:COPYVIO|copyright infringement]]",
pageParam: true
},
"uw-spoablock": {
label: "Sockpuppet account block (indefinite)",
summary: "You have been indefinitely blocked from editing because your account is being used only for [[WP:SOCK|sock puppetry]]",
indefinite: true
},
"uw-ipevadeblock": {
label: "Block-evasion block - IP address",
summary: "Your IP address has been blocked from editing because it has been used to [[WP:EVADE|evade a previous block]]"
},
"uw-hblock": {
label: "Harassment block",
summary: "You have been blocked from editing for attempting to [[WP:HARASS|harass]] other users",
pageParam: true
},
"uw-ewblock": {
label: "Edit warring block",
summary: "You have been blocked from editing to prevent further [[WP:DE|disruption]] caused by your engagement in an [[WP:EW|edit war]]",
pageParam: true
},
"uw-3block": {
label: "Three-revert rule violation block",
summary: "You have been blocked from editing for violation of the [[WP:3RR|three-revert rule]]",
pageParam: true
},
"uw-disruptblock": {
label: "Disruptive editing block",
summary: "You have been blocked from editing for [[WP:DE|disruptive editing]]",
pageParam: true
},
"uw-deoablock": {
label: "Disruption/trolling-only account block (indefinite)",
summary: "You have been indefinitely blocked from editing because your account is being used only for [[WP:DE|trolling, disruption or harassment]]",
indefinite: true,
pageParam: true
},
"uw-lblock": {
label: "Legal threat block (indefinite)",
summary: "You have been indefinitely blocked from editing for making [[WP:NLT|legal threats or taking legal action]]",
indefinite: true
},
"uw-aeblock": {
label: "Arbitration enforcement block",
summary: "You have been blocked from editing for violating an [[WP:Arbitration|arbitration decision]] with your edits",
pageParam: true,
reasonParam: true
},
"uw-efblock": {
label: "Edit filter-related block",
summary: "You have been blocked from editing for making disruptive edits that repeatedly triggered the [[WP:EF|edit filter]]"
},
"uw-myblock": {
label: "Social networking block",
summary: "You have been blocked from editing for using user and/or article pages as a [[WP:NOTMYSPACE|blog, web host, social networking site or forum]]",
pageParam: true
},
"uw-dblock": {
label: "Deletion/removal of content block",
summary: "You have been blocked from editing for continued [[WP:VAND|removal of material]]",
pageParam: true
},
"uw-compblock": {
label: "Possible compromised account block (indefinite)",
summary: "You have been indefinitely blocked from editing because it is believed that your [[WP:SECURE|account has been compromised]]",
indefinite: true
},
"uw-botblock": {
label: "Unapproved bot block",
summary: "You have been blocked from editing because it appears you are running a [[WP:BOT|bot script]] without [[WP:BRFA|approval]]",
pageParam: true
},
"uw-ublock": {
label: "Username soft block (indefinite)",
summary: "You have been indefinitely blocked from editing because your username is a violation of the [[WP:U|username policy]]",
indefinite: true,
reasonParam: true
},
"uw-uhblock": {
label: "Username hard block (indefinite)",
summary: "You have been indefinitely blocked from editing because your username is a blatant violation of the [[WP:U|username policy]]",
indefinite: true,
reasonParam: true
},
"uw-softerblock": {
label: "Promotional username soft block (indefinite)",
summary: "You have been indefinitely blocked from editing because your [[WP:U|username]] gives the impression that the account represents a group, organization or website",
indefinite: true
},
"uw-causeblock": {
label: "Promotional username soft block, for charitable causes (indefinite)",
summary: "You have been indefinitely blocked from editing because your [[WP:U|username]] gives the impression that the account represents a group, organization or website",
indefinite: true
},
"uw-botublock": {
label: "Bot username soft block (indefinite)",
summary: "You have been indefinitely blocked from editing because your [[WP:U|username]] indicates this is a [[WP:BOT|bot]] account, which is currently not approved",
indefinite: true
},
"uw-memorialblock": {
label: "Memorial username soft block (indefinite)",
summary: "You have been indefinitely blocked from editing because your [[WP:U|username]] indicates this account may be used as a memorial or tribute to someone",
indefinite: true
},
"uw-ublock-famous": {
label: "Famous username soft block (indefinite)",
summary: "You have been indefinitely blocked from editing because your [[WP:U|username]] matches the name of a well-known living individual",
indefinite: true
},
"uw-ublock-double": {
label: "Similar username soft block (indefinite)",
summary: "You have been indefinitely blocked from editing because your [[WP:U|username]] is too similar to the username of another Wikipedia user",
indefinite: true
},
"uw-uhblock-double": {
label: "Username impersonation hard block (indefinite)",
summary: "You have been indefinitely blocked from editing because your [[WP:U|username]] appears to impersonate another established Wikipedia user",
indefinite: true
},
"uw-vaublock": {
label: "Vandalism-only account and username hard block (indefinite)",
summary: "You have been indefinitely blocked from editing because your account is being [[WP:VOA|used only for vandalism]] and your username is a blatant violation of the [[WP:U|username policy]]",
indefinite: true,
pageParam: true
},
"uw-spamublock": {
label: "Spam-only account and promotional username hard block (indefinite)",
summary: "You have been indefinitely blocked from editing because your account is being used only for [[WP:SPAM|spam or advertising]] and your username is a violation of the [[WP:U|username policy]]",
indefinite: true
}
}
};
 
Twinkle.warn.prev_block_timer = null;
Twinkle.warn.prev_block_reason = null;
Twinkle.warn.prev_article = null;
Twinkle.warn.prev_reason = null;
 
Twinkle.warn.callback.change_category = function twinklewarnCallbackChangeCategory(e) {
var value = e.target.value;
var sub_group = e.target.root.sub_group;
sub_group.main_group = value;
var old_subvalue = sub_group.value;
var old_subvalue_re;
if( old_subvalue ) {
old_subvalue = old_subvalue.replace(/\d*(im)?$/, '' );
old_subvalue_re = new RegExp( $.escapeRE( old_subvalue ) + "(\\d*(?:im)?)$" );
}


while( sub_group.hasChildNodes() ){
while( sub_group.hasChildNodes() ){
Line 1,425: Line 1,214:
};
};


if( value === "singlenotice" || value === "singlewarn" || value === "block" ) {
if( value === "singlenotice" || value === "singlewarn" ) {
// no categories, just create the options right away
// no categories, just create the options right away
createEntries( Twinkle.warn.messages[ value ], sub_group, true );
createEntries( Twinkle.warn.messages[ value ], sub_group, true );
Line 1,442: Line 1,231:
createEntries( groupContents, optgroup, false );
createEntries( groupContents, optgroup, false );
} );
} );
}
if( value === 'block' ) {
// create the block-related fields
var more = new Morebits.quickForm.element( { type: 'div', id: 'block_fields' } );
more.append( {
type: 'input',
name: 'block_timer',
label: 'Period of blocking: ',
tooltip: 'The period the blocking is due for, for example 24 hours, 2 weeks, indefinite etc...'
} );
more.append( {
type: 'input',
name: 'block_reason',
label: '"You have been blocked for ..." ',
tooltip: 'An optional reason, to replace the default generic reason. Only available for the generic block templates.'
} );
e.target.root.insertBefore( more.render(), e.target.root.lastChild );
// restore saved values of fields
if(Twinkle.warn.prev_block_timer !== null) {
e.target.root.block_timer.value = Twinkle.warn.prev_block_timer;
Twinkle.warn.prev_block_timer = null;
}
if(Twinkle.warn.prev_block_reason !== null) {
e.target.root.block_reason.value = Twinkle.warn.prev_block_reason;
Twinkle.warn.prev_block_reason = null;
}
if(Twinkle.warn.prev_article === null) {
Twinkle.warn.prev_article = e.target.root.article.value;
}
e.target.root.article.disabled = false;
$(e.target.root.reason).parent().hide();
e.target.root.previewer.closePreview();
} else if( e.target.root.block_timer ) {
// hide the block-related fields
if(!e.target.root.block_timer.disabled && Twinkle.warn.prev_block_timer === null) {
Twinkle.warn.prev_block_timer = e.target.root.block_timer.value;
}
if(!e.target.root.block_reason.disabled && Twinkle.warn.prev_block_reason === null) {
Twinkle.warn.prev_block_reason = e.target.root.block_reason.value;
}
// hack to fix something really weird - removed elements seem to somehow keep an association with the form
e.target.root.block_reason = null;
$(e.target.root).find("#block_fields").remove();
if(e.target.root.article.disabled && Twinkle.warn.prev_article !== null) {
e.target.root.article.value = Twinkle.warn.prev_article;
Twinkle.warn.prev_article = null;
}
e.target.root.article.disabled = false;
$(e.target.root.reason).parent().show();
e.target.root.previewer.closePreview();
}
}


Line 1,526: Line 1,258:
}
}
e.target.form.article.notArticle = false;
e.target.form.article.notArticle = false;
}
} else if( main_group === 'block' ) {
if( Twinkle.warn.messages.block[value].indefinite ) {
if(Twinkle.warn.prev_block_timer === null) {
Twinkle.warn.prev_block_timer = e.target.form.block_timer.value;
}
e.target.form.block_timer.disabled = true;
e.target.form.block_timer.value = 'indefinite';
} else if( e.target.form.block_timer.disabled ) {
if(Twinkle.warn.prev_block_timer !== null) {
e.target.form.block_timer.value = Twinkle.warn.prev_block_timer;
Twinkle.warn.prev_block_timer = null;
}
e.target.form.block_timer.disabled = false;
}
if( Twinkle.warn.messages.block[value].pageParam ) {
if(Twinkle.warn.prev_article !== null) {
e.target.form.article.value = Twinkle.warn.prev_article;
Twinkle.warn.prev_article = null;
}
e.target.form.article.disabled = false;
} else if( !e.target.form.article.disabled ) {
if(Twinkle.warn.prev_article === null) {
Twinkle.warn.prev_article = e.target.form.article.value;
}
e.target.form.article.disabled = true;
e.target.form.article.value = '';
}
if( Twinkle.warn.messages.block[value].reasonParam ) {
if(Twinkle.warn.prev_block_reason !== null) {
e.target.form.block_reason.value = Twinkle.warn.prev_block_reason;
Twinkle.warn.prev_block_reason = null;
}
e.target.form.block_reason.disabled = false;
} else if( !e.target.form.block_reason.disabled ) {
if(Twinkle.warn.prev_block_reason === null) {
Twinkle.warn.prev_block_reason = e.target.form.block_reason.value;
}
e.target.form.block_reason.disabled = true;
e.target.form.block_reason.value = '';
}
}
}
}
Line 1,608: Line 1,298:


if (article) {
if (article) {
// add linked article for user warnings (non-block templates)
// add linked article for user warnings
text += '|1=' + article;
text += '|1=' + article;
}
}
if (reason && !isCustom) {
if (reason && !isCustom) {
// add extra message for non-block templates
// add extra message
if (templateName === 'uw-csd' || templateName === 'uw-probation' ||
if (templateName === 'uw-csd' || templateName === 'uw-probation' ||
templateName === 'uw-userspacenoindex' || templateName === 'uw-userpage') {
templateName === 'uw-userspacenoindex' || templateName === 'uw-userpage') {
Line 1,627: Line 1,317:
}
}


return text;
},
getBlockNoticeWikitext: function(templateName, article, blockTime, blockReason, isIndefTemplate) {
var text = "{{subst:" + templateName;
if (article && Twinkle.warn.messages.block[templateName].pageParam) {
text += '|page=' + article;
}
if (!/te?mp|^\s*$|min/.exec(blockTime) && !isIndefTemplate) {
if (/indef|\*|max/.exec(blockTime)) {
text += '|indef=yes';
} else {
text += '|time=' + blockTime;
}
}
if (blockReason) {
text += '|reason=' + blockReason;
}
text += "|sig=true}}";
return text;
return text;
},
},
Line 1,656: Line 1,324:
var templatetext;
var templatetext;


if (templatename in Twinkle.warn.messages.block) {
templatetext = Twinkle.warn.callbacks.getWarningWikitext(templatename, linkedarticle,
templatetext = Twinkle.warn.callbacks.getBlockNoticeWikitext(templatename, linkedarticle, form.block_timer.value,
form.reason.value, form.main_group.value === 'custom');
form.block_reason.value, Twinkle.warn.messages.block[templatename].indefinite);
} else {
templatetext = Twinkle.warn.callbacks.getWarningWikitext(templatename, linkedarticle,
form.reason.value, form.main_group.value === 'custom');
}


form.previewer.beginRender(templatetext);
form.previewer.beginRender(templatetext);
Line 1,719: Line 1,382:
// \n== is not found, then the date header must be at the very start of the page. lastIndexOf
// \n== is not found, then the date header must be at the very start of the page. lastIndexOf
// returns -1 in this case, so lastHeaderIndex gets set to 0 as desired.
// returns -1 in this case, so lastHeaderIndex gets set to 0 as desired.
var lastHeaderIndex = text.lastIndexOf( "\n==" ) + 1;  
var lastHeaderIndex = text.lastIndexOf( "\n==" ) + 1;


if( text.length > 0 ) {
if( text.length > 0 ) {
Line 1,725: Line 1,388:
}
}


if( params.main_group === 'block' ) {
if( messageData.heading ) {
if( Twinkle.getPref('blankTalkpageOnIndefBlock') && params.sub_group !== 'uw-lblock' && ( messageData.indefinite || (/indef|\*|max/).exec( params.block_timer ) ) ) {
text += "== " + messageData.heading + " ==\n";
Morebits.status.info( 'Info', 'Blanking talk page per preferences and creating a new level 2 heading for the date' );
} else if( !dateHeaderRegexResult || dateHeaderRegexResult.index !== lastHeaderIndex ) {
text = "== " + date.getUTCMonthName() + " " + date.getUTCFullYear() + " ==\n";
Morebits.status.info( 'Info', 'Will create a new level 2 heading for the date, as none was found for this month' );
} else if( !dateHeaderRegexResult || dateHeaderRegexResult.index !== lastHeaderIndex ) {
text += "== " + date.getUTCMonthName() + " " + date.getUTCFullYear() + " ==\n";
Morebits.status.info( 'Info', 'Will create a new level 2 heading for the date, as none was found for this month' );
text += "== " + date.getUTCMonthName() + " " + date.getUTCFullYear() + " ==\n";
}
 
text += Twinkle.warn.callbacks.getBlockNoticeWikitext(params.sub_group, params.article, params.block_timer, params.reason, messageData.indefinite);
} else {
if( messageData.heading ) {
text += "== " + messageData.heading + " ==\n";
} else if( !dateHeaderRegexResult || dateHeaderRegexResult.index !== lastHeaderIndex ) {
Morebits.status.info( 'Info', 'Will create a new level 2 heading for the date, as none was found for this month' );
text += "== " + date.getUTCMonthName() + " " + date.getUTCFullYear() + " ==\n";
}
text += Twinkle.warn.callbacks.getWarningWikitext(params.sub_group, params.article,
params.reason, params.main_group === 'custom') + " ~~~~";
}
}
text += Twinkle.warn.callbacks.getWarningWikitext(params.sub_group, params.article,
params.reason, params.main_group === 'custom') + " ~~~~";


if ( Twinkle.getPref('showSharedIPNotice') && Morebits.isIPAddress( mw.config.get('wgTitle') ) ) {
if ( Twinkle.getPref('showSharedIPNotice') && Morebits.isIPAddress( mw.config.get('wgTitle') ) ) {
Line 1,812: Line 1,463:
// Then, grab all the values provided by the form
// Then, grab all the values provided by the form
var params = {
var params = {
reason: e.target.block_reason ? e.target.block_reason.value : e.target.reason.value,
reason: e.target.reason.value,
main_group: e.target.main_group.value,
main_group: e.target.main_group.value,
sub_group: e.target.sub_group.value,
sub_group: e.target.sub_group.value,
article: e.target.article.value,  // .replace( /^(Image|Category):/i, ':$1:' ),  -- apparently no longer needed...
article: e.target.article.value,  // .replace( /^(Image|Category):/i, ':$1:' ),  -- apparently no longer needed...
block_timer: e.target.block_timer ? e.target.block_timer.value : null,
messageData: selectedEl.data("messageData")
messageData: selectedEl.data("messageData")
};
};