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 15: Line 15:


Twinkle.warn = function twinklewarn() {
Twinkle.warn = function twinklewarn() {
if( mw.config.get('wgNamespaceNumber') === 3 ) {
if( mw.config.get( 'wgRelevantUserName' ) ) {
Twinkle.addPortletLink( Twinkle.warn.callback, "Warn", "tw-warn", "Warn/notify user" );
Twinkle.addPortletLink( Twinkle.warn.callback, "Warn", "tw-warn", "Warn/notify user" );
}
}


// modify URL of talk page on rollback success pages
// Modify URL of talk page on rollback success pages. This is only used
// when a user Ctrl+clicks on a rollback link.
if( mw.config.get('wgAction') === 'rollback' ) {
if( mw.config.get('wgAction') === 'rollback' ) {
var $vandalTalkLink = $("#mw-rollback-success").find(".mw-usertoollinks a").first();
var $vandalTalkLink = $("#mw-rollback-success").find(".mw-usertoollinks a").first();
if ( $vandalTalkLink.length ) {
if ( $vandalTalkLink.length ) {
Twinkle.warn.makeVandalTalkLink($vandalTalkLink);
$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."));
}
}
 
// Override the mw.notify function to allow us to inject a link into the
// rollback success popup. Only users with the 'rollback' right need this,
// but we have no nice way of knowing who has that right (what with global
// groups and the like)
else if( mw.config.get('wgAction') === 'history' ) {
mw.notifyOriginal = mw.notify;
mw.notify = function mwNotifyTwinkleOverride(message, options) {
// This is a horrible, awful hack to add a link to the rollback success
// popup. All other notification popups should be left untouched.
// It won't work for people whose user language is not English.
// As it's a hack, it's liable to stop working or break sometimes,
// particularly if the text or format of the confirmation message
// (MediaWiki:Rollback-success-notify) changes.
var regexMatch;
if ( options && options.title && mw.msg && options.title === mw.msg('actioncomplete') &&
message && Array.isArray(message) && message[0] instanceof HTMLParagraphElement &&
(regexMatch = /^Reverted edits by (.+);\s+changed/.exec(message[0].innerText))
) {
// Create a nicely-styled paragraph to place the link in
var $p = $('<p/>');
$p.css("margin", "0.5em -1.5em -1.5em");
$p.css("padding", "0.5em 1.5em 0.8em");
$p.css("border-top", "1px #666 solid");
$p.css("cursor", "default");
$p.click(function(e) { e.stopPropagation(); });


var extraParam = "vanarticle=" + mw.util.rawurlencode(Morebits.pageNameNorm);
// Create the new talk link and append it to the end of the message
var href = $vandalTalkLink.attr("href");
var $vandalTalkLink = $('<a/>');
if (href.indexOf("?") === -1) {
$vandalTalkLink.text("Warn user with Twinkle");
$vandalTalkLink.attr("href", href + "?" + extraParam);
//$vandalTalkLink.css("display", "block");
} else {
$vandalTalkLink.attr("href", mw.util.getUrl("User talk:" + regexMatch[1]));
$vandalTalkLink.attr("href", href + "&" + extraParam);
Twinkle.warn.makeVandalTalkLink($vandalTalkLink);
 
$p.append($vandalTalkLink);
message[0].appendChild($p.get()[0]);
 
// Don't auto-hide the notification. It only stays around for 5 seconds by
// default, which might not be enough time for the user to read it and
// click the link
options.autoHide = false;
}
}
}
mw.notifyOriginal.apply(mw, arguments);
};
}
 
// for testing, use:
// mw.notify([ $("<p>Reverted edits by foo; changed</p>")[0] ], { title: mw.msg('actioncomplete') } );
};
 
Twinkle.warn.makeVandalTalkLink = function($vandalTalkLink) {
$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 href = $vandalTalkLink.attr("href");
if (href.indexOf("?") === -1) {
$vandalTalkLink.attr("href", href + "?" + extraParam);
} else {
$vandalTalkLink.attr("href", href + "&" + extraParam);
}
}
};
};


Twinkle.warn.callback = function twinklewarnCallback() {
Twinkle.warn.callback = function twinklewarnCallback() {
if( mw.config.get('wgTitle').split( '/' )[0] === mw.config.get('wgUserName') &&
if( mw.config.get( 'wgRelevantUserName' ) === mw.config.get( 'wgUserName' ) &&
!confirm( 'You are about to warn yourself! Are you sure you want to proceed?' ) ) {
!confirm( 'You are about to warn yourself! Are you sure you want to proceed?' ) ) {
return;
return;
Line 68: Line 121:
main_group.append( { type: 'option', label: 'Final warning (4)', value: 'level4', selected: ( defaultGroup === 4 ) } );
main_group.append( { type: 'option', label: 'Final warning (4)', value: 'level4', selected: ( defaultGroup === 4 ) } );
main_group.append( { type: 'option', label: 'Only warning (4im)', value: 'level4im', selected: ( defaultGroup === 5 ) } );
main_group.append( { type: 'option', label: 'Only warning (4im)', value: 'level4im', selected: ( defaultGroup === 5 ) } );
main_group.append( { type: 'option', label: 'Single issue notices', value: 'singlenotice', selected: ( defaultGroup === 6 ) } );
main_group.append( { type: 'option', label: 'Single-issue notices', value: 'singlenotice', selected: ( defaultGroup === 6 ) } );
main_group.append( { type: 'option', label: 'Single issue warnings', value: 'singlewarn', selected: ( defaultGroup === 7 ) } );
main_group.append( { type: 'option', label: 'Single-issue warnings', value: 'singlewarn', selected: ( defaultGroup === 7 ) } );
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 ) } );
Line 140: Line 193:
summary: "General note: Adding unreferenced controversial information about living persons"
summary: "General note: Adding unreferenced controversial information about living persons"
},
},
"uw-defam1": {
"uw-defamatory1": {
label: "Addition of defamatory content",
label: "Addition of defamatory content",
summary: "General note: Addition of defamatory content"
summary: "General note: Addition of defamatory content"
Line 189: Line 242:
label: "Not adhering to neutral point of view",
label: "Not adhering to neutral point of view",
summary: "General note: Not adhering to neutral point of view"
summary: "General note: Not adhering to neutral point of view"
},
"uw-paid1": {
label: "Paid editing without disclosure under the Wikimedia Terms of Use",
summary: "General note: Paid editing without disclosure under the Wikimedia Terms of Use"
},
},
"uw-spam1": {
"uw-spam1": {
label: "Adding spam links",
label: "Adding inappropriate external links",
summary: "General note: Adding spam links"
summary: "General note: Adding inappropriate external links"
}
}
},
},
Line 232: Line 289:
},
},
"Other": {
"Other": {
"uw-attempt1": {
label: "Triggering the edit filter",
summary: "General note: Triggering the edit filter"
},
"uw-chat1": {
"uw-chat1": {
label: "Using talk page as forum",
label: "Using talk page as forum",
Line 298: Line 359:
summary: "Caution: Adding unreferenced controversial information about living persons"
summary: "Caution: Adding unreferenced controversial information about living persons"
},
},
"uw-defam2": {
"uw-defamatory2": {
label: "Addition of defamatory content",
label: "Addition of defamatory content",
summary: "Caution: Addition of defamatory content"
summary: "Caution: Addition of defamatory content"
Line 347: Line 408:
label: "Not adhering to neutral point of view",
label: "Not adhering to neutral point of view",
summary: "Caution: Not adhering to neutral point of view"
summary: "Caution: Not adhering to neutral point of view"
},
"uw-paid2": {
label: "Paid editing without disclosure under the Wikimedia Terms of Use",
summary: "Caution: Paid editing without disclosure under the Wikimedia Terms of Use"
},
},
"uw-spam2": {
"uw-spam2": {
Line 456: Line 521:
summary: "Warning: Adding unreferenced controversial information about living persons"
summary: "Warning: Adding unreferenced controversial information about living persons"
},
},
"uw-defam3": {
"uw-defamatory3": {
label: "Addition of defamatory content",
label: "Addition of defamatory content",
summary: "Warning: Addition of defamatory content"
summary: "Warning: Addition of defamatory content"
Line 505: Line 570:
label: "Not adhering to neutral point of view",
label: "Not adhering to neutral point of view",
summary: "Warning: Not adhering to neutral point of view"
summary: "Warning: Not adhering to neutral point of view"
},
"uw-paid3": {
label: "Paid editing without disclosure under the Wikimedia Terms of Use",
summary: "Warning: Paid editing without disclosure under the Wikimedia Terms of Use"
},
},
"uw-spam3": {
"uw-spam3": {
Line 606: Line 675:
summary: "Final warning: Adding unreferenced controversial information about living persons"
summary: "Final warning: Adding unreferenced controversial information about living persons"
},
},
"uw-defam4": {
"uw-defamatory4": {
label: "Addition of defamatory content",
label: "Addition of defamatory content",
summary: "Final warning: Addition of defamatory content"
summary: "Final warning: Addition of defamatory content"
Line 647: Line 716:
label: "Not adhering to neutral point of view",
label: "Not adhering to neutral point of view",
summary: "Final warning: Not adhering to neutral point of view"
summary: "Final warning: Not adhering to neutral point of view"
},
"uw-paid4": {
label: "Paid editing without disclosure under the Wikimedia Terms of Use",
summary: "Final warning: Paid editing without disclosure under the Wikimedia Terms of Use"
},
},
"uw-spam4": {
"uw-spam4": {
Line 740: Line 813:
summary: "Only warning: Adding unreferenced controversial information about living persons"
summary: "Only warning: Adding unreferenced controversial information about living persons"
},
},
"uw-defam4im": {
"uw-defamatory4im": {
label: "Addition of defamatory content",
label: "Addition of defamatory content",
summary: "Only warning: Addition of defamatory content"
summary: "Only warning: Addition of defamatory content"
Line 798: Line 871:
}*/
}*/
},
},


singlenotice: {
singlenotice: {
"uw-2redirect": {
label: "Creating double redirects through bad page moves",
summary: "Notice: Creating double redirects through bad page moves"
},
"uw-aiv": {
"uw-aiv": {
label: "Bad AIV report",
label: "Bad AIV report",
summary: "Notice: Bad AIV report"
summary: "Notice: Bad AIV report"
},
"uw-articlesig": {
label: "Adding signatures to article space",
summary: "Notice: Adding signatures to article space"
},
},
"uw-autobiography": {
"uw-autobiography": {
Line 846: Line 910:
label: "Adding speculative or unconfirmed information",
label: "Adding speculative or unconfirmed information",
summary: "Notice: Adding speculative or unconfirmed information"
summary: "Notice: Adding speculative or unconfirmed information"
},
"uw-csd": {
label: "Speedy deletion declined",
summary: "Notice: Speedy deletion declined"
},
},
"uw-c&pmove": {
"uw-c&pmove": {
Line 866: Line 926:
label: "Removing proper sources containing dead links",
label: "Removing proper sources containing dead links",
summary: "Notice: Removing proper sources containing dead links"
summary: "Notice: Removing proper sources containing dead links"
},
"uw-directcat": {
label: "Applying stub categories manually",
summary: "Notice: Applying stub categories manually"
},
},
"uw-draftfirst": {
"uw-draftfirst": {
Line 882: Line 938:
label: "Not communicating in English",
label: "Not communicating in English",
summary: "Notice: Not communicating in English"
summary: "Notice: Not communicating in English"
},
"uw-fuir": {
label: "Fair use image has been removed from your userpage",
summary: "Notice: A fair use image has been removed from your userpage"
},
},
"uw-hasty": {
"uw-hasty": {
label: "Hasty addition of speedy deletion tags",
label: "Hasty addition of speedy deletion tags",
summary: "Notice: Allow creators time to improve their articles before tagging them for deletion"
summary: "Notice: Allow creators time to improve their articles before tagging them for deletion"
},
"uw-imageuse": {
label: "Incorrect image linking",
summary: "Notice: Incorrect image linking"
},
"uw-incompleteAFD": {
label: "Incomplete AFD",
summary: "Notice: Incomplete AFD"
},
},
"uw-inline-el": {
"uw-inline-el": {
Line 919: Line 963:
label: "Incorrect use of minor edits check box",
label: "Incorrect use of minor edits check box",
summary: "Notice: Incorrect use of minor edits check box"
summary: "Notice: Incorrect use of minor edits check box"
},
"uw-nonfree": {
label: "Uploading replaceable non-free images",
summary: "Notice: Uploading replaceable non-free images"
},
"uw-notaiv": {
label: "Do not report complex abuse to AIV",
summary: "Notice: Do not report complex abuse to AIV"
},
},
"uw-notenglish": {
"uw-notenglish": {
label: "Creating non-English articles",
label: "Creating non-English articles",
summary: "Notice: Creating non-English articles"
summary: "Notice: Creating non-English articles"
},
"uw-notifysd": {
label: "Notify authors of speedy deletion tagged articles",
summary: "Notice: Please notify authors of articles tagged for speedy deletion"
},
"uw-notvand": {
label: "Mislabelling edits as vandalism",
summary: "Notice: Misidentifying edits as vandalism"
},
},
"uw-notvote": {
"uw-notvote": {
label: "We use consensus, not voting",
label: "We use consensus, not voting",
summary: "Notice: We use consensus, not voting"
summary: "Notice: We use consensus, not voting"
},
"uw-patrolled": {
label: "Mark newpages as patrolled when patrolling",
summary: "Notice: Mark newpages as patrolled when patrolling"
},
},
"uw-plagiarism": {
"uw-plagiarism": {
Line 955: Line 979:
label: "Use preview button to avoid mistakes",
label: "Use preview button to avoid mistakes",
summary: "Notice: Use preview button to avoid mistakes"
summary: "Notice: Use preview button to avoid mistakes"
},
"uw-probation": {
label: "Article is on probation",
summary: "Notice: Article is on probation"
},
},
"uw-redlink": {
"uw-redlink": {
label: "Indiscriminate removal of redlinks",
label: "Indiscriminate removal of redlinks",
summary: "Notice: Be careful when removing redlinks"
summary: "Notice: Be careful when removing redlinks"
},
"uw-refimprove": {
label: "Creating unverifiable articles",
summary: "Notice: Creating unverifiable articles"
},
"uw-removevandalism": {
label: "Incorrect vandalism removal",
summary: "Notice: Incorrect vandalism removal"
},
"uw-repost": {
label: "Recreating material previously deleted via XfD process",
summary: "Notice: Recreating previously deleted material"
},
"uw-samename": {
label: "Rename request impossible",
summary: "Notice: Rename request impossible"
},
},
"uw-selfrevert": {
"uw-selfrevert": {
Line 1,011: Line 1,015:
label: "Posting at the top of talk pages",
label: "Posting at the top of talk pages",
summary: "Notice: Posting at the top of talk pages"
summary: "Notice: Posting at the top of talk pages"
},
"uw-uaa": {
label: "Reporting of username to WP:UAA not accepted",
summary: "Notice: Reporting of username to WP:UAA not accepted"
},
"uw-upincat": {
label: "Accidentally including user page/subpage in a content category",
summary: "Notice: Informing user that one of his/her pages had accidentally been included in a content category"
},
"uw-uploadfirst": {
label: "Attempting to display an external image on a page",
summary: "Notice: Attempting to display an external image on a page"
},
},
"uw-userspace draft finish": {
"uw-userspace draft finish": {
label: "Stale userspace draft",
label: "Stale userspace draft",
summary: "Notice: Stale userspace draft"
summary: "Notice: Stale userspace draft"
},
"uw-userspacenoindex": {
label: "User page/subpage isn't appropriate for search engine indexing",
summary: "Notice: User (sub)page isn't appropriate for search engine indexing"
},
},
"uw-vgscope": {
"uw-vgscope": {
Line 1,045: Line 1,033:
singlewarn: {
singlewarn: {
"uw-3rr": {
"uw-3rr": {
label: "Violating the three-revert rule; see also uw-ew",
label: "Potential three-revert rule violation; see also uw-ew",
summary: "Warning: Violating the three-revert rule"
summary: "Warning: Three-revert rule"
},
},
"uw-affiliate": {
"uw-affiliate": {
Line 1,085: Line 1,073:
summary: "Notice: Avoiding copyright problems",
summary: "Notice: Avoiding copyright problems",
heading: "Wikipedia and copyright"
heading: "Wikipedia and copyright"
},
"uw-dls": {
label: "Replacing dead links with spam links",
summary: "Warning: Replacing dead links with spam links"
},
},
"uw-copyright-remove": {
"uw-copyright-remove": {
Line 1,117: Line 1,101:
label: "Editing while logged out",
label: "Editing while logged out",
summary: "Warning: Editing while logged out"
summary: "Warning: Editing while logged out"
},
"uw-longterm": {
label: "Long term pattern of vandalism",
summary: "Warning: Long term pattern of vandalism"
},
},
"uw-multipleIPs": {
"uw-multipleIPs": {
Line 1,174: Line 1,154:
if( old_subvalue ) {
if( old_subvalue ) {
old_subvalue = old_subvalue.replace(/\d*(im)?$/, '' );
old_subvalue = old_subvalue.replace(/\d*(im)?$/, '' );
old_subvalue_re = new RegExp( $.escapeRE( old_subvalue ) + "(\\d*(?:im)?)$" );
old_subvalue_re = new RegExp( mw.RegExp.escape( old_subvalue ) + "(\\d*(?:im)?)$" );
}
}


Line 1,236: Line 1,216:
Morebits.quickForm.setElementTooltipVisibility(e.target.root.article, true);
Morebits.quickForm.setElementTooltipVisibility(e.target.root.article, true);
Morebits.quickForm.resetElementLabel(e.target.root.article);
Morebits.quickForm.resetElementLabel(e.target.root.article);
// hide the big red notice
// hide the big red notice
$("#tw-warn-red-notice").remove();
$("#tw-warn-red-notice").remove();
// add custom label.redWarning
Twinkle.warn.callback.change_subcategory(e);
};
};


Line 1,244: Line 1,225:
var main_group = e.target.form.main_group.value;
var main_group = e.target.form.main_group.value;
var value = e.target.form.sub_group.value;
var value = e.target.form.sub_group.value;
// Tags that don't take a linked article, but something else (often a username).
// The value of each tag is the label next to the input field
var notLinkedArticle = {
"uw-agf-sock": "Optional username of other account (without User:) ",
"uw-bite": "Username of 'bitten' user (without User:) ",
"uw-socksuspect": "Username of sock master, if known (without User:) ",
"uw-username": "Username violates policy because... ",
"uw-aiv": "Optional username that was reported (without User:) "
};


if( main_group === 'singlenotice' || main_group === 'singlewarn' ) {
if( main_group === 'singlenotice' || main_group === 'singlewarn' ) {
if( value === 'uw-bite' || value === 'uw-username' || value === 'uw-socksuspect' ) {
if( notLinkedArticle[value] ) {
if(Twinkle.warn.prev_article === null) {
if(Twinkle.warn.prev_article === null) {
Twinkle.warn.prev_article = e.target.form.article.value;
Twinkle.warn.prev_article = e.target.form.article.value;
Line 1,252: Line 1,243:
e.target.form.article.notArticle = true;
e.target.form.article.notArticle = true;
e.target.form.article.value = '';
e.target.form.article.value = '';
// change form labels according to the warning selected
Morebits.quickForm.setElementTooltipVisibility(e.target.form.article, false);
Morebits.quickForm.overrideElementLabel(e.target.form.article, notLinkedArticle[value]);
} else if( e.target.form.article.notArticle ) {
} else if( e.target.form.article.notArticle ) {
if(Twinkle.warn.prev_article !== null) {
if(Twinkle.warn.prev_article !== null) {
Line 1,258: Line 1,253:
}
}
e.target.form.article.notArticle = false;
e.target.form.article.notArticle = false;
Morebits.quickForm.setElementTooltipVisibility(e.target.form.article, true);
Morebits.quickForm.resetElementLabel(e.target.form.article);
}
}
}
// change form labels according to the warning selected
if (value === "uw-socksuspect") {
Morebits.quickForm.setElementTooltipVisibility(e.target.form.article, false);
Morebits.quickForm.overrideElementLabel(e.target.form.article, "Username of sock master, if known (without User:) ");
} else if (value === "uw-username") {
Morebits.quickForm.setElementTooltipVisibility(e.target.form.article, false);
Morebits.quickForm.overrideElementLabel(e.target.form.article, "Username violates policy because... ");
} else if (value === "uw-bite") {
Morebits.quickForm.setElementTooltipVisibility(e.target.form.article, false);
Morebits.quickForm.overrideElementLabel(e.target.form.article, "Username of 'bitten' user (without User:) ");
} else {
Morebits.quickForm.setElementTooltipVisibility(e.target.form.article, true);
Morebits.quickForm.resetElementLabel(e.target.form.article);
}
}


Line 1,397: Line 1,379:
params.reason, params.main_group === 'custom') + " ~~~~";
params.reason, params.main_group === 'custom') + " ~~~~";


if ( Twinkle.getPref('showSharedIPNotice') && Morebits.isIPAddress( mw.config.get('wgTitle') ) ) {
if ( Twinkle.getPref('showSharedIPNotice') && mw.util.isIPAddress( mw.config.get('wgTitle') ) ) {
Morebits.status.info( 'Info', 'Adding a shared IP notice' );
Morebits.status.info( 'Info', 'Adding a shared IP notice' );
text +=  "\n{{subst:SharedIPAdvice}}";
text +=  "\n{{subst:Shared IP advice}}";
}
}


Line 1,433: Line 1,415:
summary = messageData.summary;
summary = messageData.summary;
if ( messageData.suppressArticleInSummary !== true && params.article ) {
if ( messageData.suppressArticleInSummary !== true && params.article ) {
if ( params.sub_group === "uw-socksuspect" ) {  // this template requires a username
if ( params.sub_group === "uw-agf-sock" ||
summary += " of [[User:" + params.article + "]]";
params.sub_group === "uw-socksuspect" ||
params.sub_group === "uw-aiv" ) {  // these templates require a username
summary += " of [[:User:" + params.article + "]]";
} else {
} else {
summary += " on [[" + params.article + "]]";
summary += " on [[:" + params.article + "]]";
}
}
}
}
Line 1,450: Line 1,434:


Twinkle.warn.callback.evaluate = function twinklewarnCallbackEvaluate(e) {
Twinkle.warn.callback.evaluate = function twinklewarnCallbackEvaluate(e) {
var userTalkPage = 'User_talk:' + mw.config.get('wgRelevantUserName');


// First, check to make sure a reason was filled in if uw-username was selected
// First, check to make sure a reason was filled in if uw-username was selected
Line 1,473: Line 1,458:
Morebits.status.init( e.target );
Morebits.status.init( e.target );


Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
Morebits.wiki.actionCompleted.redirect = userTalkPage;
Morebits.wiki.actionCompleted.notice = "Warning complete, reloading talk page in a few seconds";
Morebits.wiki.actionCompleted.notice = "Warning 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( userTalkPage, 'User talk page modification' );
wikipedia_page.setCallbackParameters( params );
wikipedia_page.setCallbackParameters( params );
wikipedia_page.setFollowRedirect( true );
wikipedia_page.setFollowRedirect( true );
14,091

edits