MediaWiki:Gadget-twinklewarn.js: Difference between revisions

Jump to navigation Jump to search
create
imported>AzaToth
m (v2.0-556-g0beacc0: use .utc() for timestamps and format them the sme way as the wiki does)
 
(create)
Line 1:
//<nowiki>
 
 
(function($){
 
 
/*
****************************************
Line 13:
* Config directives in: TwinkleConfig
*/
 
Twinkle.warn = function twinklewarn() {
if( mw.config.get('wgNamespaceNumber') === 3 ) {
Twinkle.addPortletLink( Twinkle.warn.callback, "Warn", "tw-warn", "Warn/notify user" );
}
 
// modify URL of talk page on rollback success pages
if( mw.config.get('wgAction') === 'rollback' ) {
Line 24:
$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."));
 
var extraParam = "vanarticle=" + mw.util.rawurlencode(Morebitsmw.pageNameNormconfig.get("wgPageName").replace(/_/g, " "));
var href = $vandalTalkLink.attr("href");
if (href.indexOf("?") === -1) {
Line 34:
}
};
 
Twinkle.warn.callback = function twinklewarnCallback() {
if( mw.config.get('wgTitle').split( '/' )[0] === mw.config.get('wgUserName') &&
Line 40:
return;
}
 
var Window = new Morebits.simpleWindow( 600, 440 );
Window.setTitle( "Warn/notify user" );
Line 46:
Window.addFooterLink( "Choosing a warning level", "WP:UWUL#Levels" );
Window.addFooterLink( "Twinkle help", "WP:TW/DOC#warn" );
 
var form = new Morebits.quickForm( Twinkle.warn.callback.evaluate );
var main_select = form.append( {
Line 53:
tooltip:'First choose a main warning group, then the specific warning to issue.'
} );
 
var main_group = main_select.append( {
type:'select',
Line 59:
event:Twinkle.warn.callback.change_category
} );
 
var defaultGroup = parseInt(Twinkle.getPref('defaultWarningGroup'), 10);
main_group.append( { type:'option', label:'General note (1)', value:'level1', selected: ( defaultGroup === 1 || defaultGroup < 1 || ( Morebits.userIsInGroup( 'sysop' ) ? defaultGroup > 8 : defaultGroup > 7 ) ) } );
Line 74:
main_group.append( { type:'option', label:'Blocking', value:'block', selected: ( defaultGroup === 8 ) } );
}
 
main_select.append( { type:'select', name:'sub_group', event:Twinkle.warn.callback.change_subcategory } ); //Will be empty to begin with.
 
form.append( {
type:'input',
Line 84:
tooltip:'An article can be linked within the notice, perhaps because it was a revert to said article that dispatched this notice. Leave empty for no article to be linked.'
} );
 
var more = form.append( { type: 'field', name: 'reasonGroup', label: 'Warning information' } );
more.append( { type:'textarea', label:'Optional message:', name:'reason', tooltip:'Perhaps a reason, or that a more detailed notice must be appended' } );
 
var previewlink = document.createElement( 'a' );
$(previewlink).click(function(){
Line 96:
more.append( { type: 'div', id: 'warningpreview', label: [ previewlink ] } );
more.append( { type: 'div', id: 'twinklewarn-previewbox', style: 'display: none' } );
 
more.append( { type:'submit', label:'Submit' } );
 
var result = form.render();
Window.setContent( result );
Line 104:
result.main_group.root = result;
result.previewer = new Morebits.wiki.preview($(result).find('div#twinklewarn-previewbox').last()[0]);
 
// We must init the first choice (General Note);
var evt = document.createEvent( "Event" );
Line 110:
result.main_group.dispatchEvent( evt );
};
 
// This is all the messages that might be dispatched by the code
// Each of the individual templates require the following information:
Line 273:
}*/
},
 
 
level2: {
"Common warnings": {
Line 431:
}*/
},
 
 
level3: {
"Common warnings": {
Line 585:
}*/
},
 
 
level4: {
"Common warnings": {
Line 723:
}*/
},
 
 
level4im: {
"Common warnings": {
Line 803:
}*/
},
 
 
singlenotice: {
"uw-2redirect": {
Line 1,051:
}
},
 
 
singlewarn: {
"uw-3rr": {
Line 1,165:
}
},
 
 
block: {
"uw-blockblocked": {
label: "BlockMain template",
summary: "You have been temporarily blocked from editing",
pageParam: true,
reasonParam: true, // allows editing of reason for generic templates
suppressArticleInSummary: true
},
"usernameblock": {
"uw-blocknotalk": {
label: "BlockUnacceptable - talk page disabledusername",
summary: "You have been blocked from editing anddue yourto useran talkunacceptable page has been disabledusername",
indefinite: true, // Indefinite-only block
pageParam: true,
reasonParam: truefalse, // does NOT allow editing of reason
suppressArticleInSummary: true
},
"funnyblock": {
"uw-blockindef": {
label: "BlockJoke - indefiniteblock",
summary: "You have been indefinitelyLOL blocked from editing",
reasonParam: false, // does NOT allow editing of reason
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-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-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;
Line 1,379 ⟶ 1,206:
old_subvalue_re = new RegExp( $.escapeRE( old_subvalue ) + "(\\d*(?:im)?)$" );
}
 
while( sub_group.hasChildNodes() ){
sub_group.removeChild( sub_group.firstChild );
}
 
// worker function to create the combo box entries
var createEntries = function( contents, container ) {
$.each( contents, function( itemKey, itemProperties ) {
var key = (typeof itemKey === "string") ? itemKey : itemProperties.value;
 
var selected = false;
if( old_subvalue && old_subvalue_re.test( key ) ) {
selected = true;
}
 
var elem = new Morebits.quickForm.element( {
type: 'option',
Line 1,404 ⟶ 1,231:
} );
};
 
if( value === "singlenotice" || value === "singlewarn" || value === "block" ) {
// no categories, just create the options right away
Line 1,423 ⟶ 1,250:
} );
}
 
if( value === 'block' ) {
// create the block-related fields
Line 1,440 ⟶ 1,267:
} );
e.target.root.insertBefore( more.render(), e.target.root.lastChild );
 
// restore saved values of fields
if(Twinkle.warn.prev_block_timer !== null) {
Line 1,454 ⟶ 1,281:
}
e.target.root.article.disabled = false;
 
$(e.target.root.reason).parent().hide();
e.target.root.previewer.closePreview();
Line 1,465 ⟶ 1,292:
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;
Line 1,476 ⟶ 1,303:
}
e.target.root.article.disabled = false;
 
$(e.target.root.reason).parent().show();
e.target.root.previewer.closePreview();
}
 
// clear overridden label on article textbox
Morebits.quickForm.setElementTooltipVisibility(e.target.root.article, true);
Morebits.quickForm.resetElementLabel(e.target.root.article);
 
// hide the big red notice
$("#tw-warn-red-notice").remove();
};
 
Twinkle.warn.callback.change_subcategory = function twinklewarnCallbackChangeSubcategory(e) {
var main_group = e.target.form.main_group.value;
var value = e.target.form.sub_group.value;
 
if( main_group === 'singlenotice' || main_group === 'singlewarn' ) {
if( value === 'uw-bite' || value === 'uw-username' || value === 'uw-socksuspect' ) {
Line 1,521 ⟶ 1,348:
e.target.form.block_timer.disabled = false;
}
 
if( Twinkle.warn.messages.block[value].pageParam ) {
if(Twinkle.warn.prev_article !== null) {
Line 1,535 ⟶ 1,362:
e.target.form.article.value = '';
}
 
if( Twinkle.warn.messages.block[value].reasonParam ) {
if(Twinkle.warn.prev_block_reason !== null) {
Line 1,550 ⟶ 1,377:
}
}
 
// change form labels according to the warning selected
if (value === "uw-socksuspect") {
Line 1,565 ⟶ 1,392:
Morebits.quickForm.resetElementLabel(e.target.form.article);
}
 
// add big red notice, warning users about how to use {{uw-[coi-]username}} appropriately
$("#tw-warn-red-notice").remove();
 
var $redWarning;
if (value === "uw-username") {
var $redWarning = $("<div style='color: red;' id='tw-warn-red-notice'>{{uw-username}} should <b>not</b> be used for <b>blatant</b> username policy violations. " +
"Blatant violations should be reported directly to UAA (via Twinkle's ARV tab). " +
"{{uw-username}} should only be used in edge cases in order to engage in discussion with the user.</div>");
$redWarning.insertAfter(Morebits.quickForm.getElementLabelObject(e.target.form.reasonGroup));
} else if (value === "uw-coi-username") {
var $redWarning = $("<div style='color: red;' id='tw-warn-red-notice'>{{uw-coi-username}} should <b>not</b> be used for <b>blatant</b> username policy violations. " +
"Blatant violations should be reported directly to UAA (via Twinkle's ARV tab). " +
"{{uw-coi-username}} should only be used in edge cases in order to engage in discussion with the user.</div>");
Line 1,582 ⟶ 1,407:
}
};
 
Twinkle.warn.callbacks = {
getWarningWikitext: function(templateName, article, reason) {
var text = "{{subst:" + templateName;
 
if (article) {
// add linked article for user warnings (non-block templates)
Line 1,592 ⟶ 1,417:
}
text += '}}';
 
// add extra message for non-block templates
if (reason) {
text += " ''" + reason + "''";
}
 
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) {
text += '|1=' + blockTime;
if (/indef|\*|max/.exec(blockTime)) {
text += '|indef=yes';
} else {
text += '|time=' + blockTime;
}
}
 
if (blockReason) {
text += '|reason=' + blockReason;
}
 
text += "|sig=true}}~~~~";
return text;
},
Line 1,626 ⟶ 1,447:
var linkedarticle = form.article.value;
var templatetext;
 
if (templatename in Twinkle.warn.messages.block) {
templatetext = Twinkle.warn.callbacks.getBlockNoticeWikitext(templatename, linkedarticle, form.block_timer.value,
Line 1,633 ⟶ 1,454:
templatetext = Twinkle.warn.callbacks.getWarningWikitext(templatename, linkedarticle, form.reason.value);
}
 
form.previewer.beginRender(templatetext);
},
Line 1,640 ⟶ 1,461:
var params = pageobj.getCallbackParameters();
var messageData = params.messageData;
 
var history_re = /<!-- Template:(uw-.*?) -->.*?(\d{1,2}:\d{1,2}, \d{1,2} \w+ \d{4}) \(UTC\)/g;
var history = {};
var latest = { date:new Date( 0 ), type:'' };
var current;
 
while( ( current = history_re.exec( text ) ) ) {
var current_date = new Date( current[2] + ' UTC' );
Line 1,656 ⟶ 1,477:
}
}
 
var date = new Date();
 
if( params.sub_group in history ) {
var temp_time = new Date( history[ params.sub_group ] );
temp_time.setUTCHours( temp_time.getUTCHours() + 24 );
 
if( temp_time > date ) {
if( !confirm( "An identical " + params.sub_group + " has been issued in the last 24 hours. \nWould you still like to add this warning/notice?" ) ) {
Line 1,670 ⟶ 1,491:
}
}
 
latest.date.setUTCMinutes( latest.date.getUTCMinutes() + 1 ); // after long debate, one minute is max
 
if( latest.date > date ) {
if( !confirm( "A " + latest.type + " has been issued in the last minute. \nWould you still like to add this warning/notice?" ) ) {
Line 1,679 ⟶ 1,500:
}
}
 
var headerRe = new RegExp( "^==+\\s*(?:" + date.getUTCMonthName() + '|' + date.getUTCMonthNameAbbrev() + ")\\s+" + date.getUTCFullYear() + "\\s*==+", 'm' );
 
if( text.length > 0 ) {
text += "\n\n";
}
 
if( params.main_group === 'block' ) {
if( Twinkle.getPref('blankTalkpageOnIndefBlock') && params.sub_group !== 'uw-lblock' && ( messageData.indefinite || (/indef|\*|max/).exec( params.block_timer ) ) ) {
Line 1,694 ⟶ 1,515:
text += "== " + date.getUTCMonthName() + " " + date.getUTCFullYear() + " ==\n";
}
 
text += Twinkle.warn.callbacks.getBlockNoticeWikitext(params.sub_group, params.article, params.block_timer, params.reason, messageData.indefinite);
} else {
Line 1,703 ⟶ 1,524:
text += Twinkle.warn.callbacks.getWarningWikitext(params.sub_group, params.article, params.reason) + " ~~~~";
}
 
if ( Twinkle.getPref('showSharedIPNotice') && Morebits.isIPAddress( mw.config.get('wgTitle') ) ) {
Morebits.status.info( 'Info', 'Adding a shared IP notice' );
text += "\n{{subst:SharedIPAdvice}}";
}
 
// build the edit summary
var summary;
Line 1,741 ⟶ 1,562:
}
summary += "." + Twinkle.getPref("summaryAd");
 
pageobj.setPageText( text );
pageobj.setEditSummary( summary );
Line 1,748 ⟶ 1,569:
}
};
 
Twinkle.warn.callback.evaluate = function twinklewarnCallbackEvaluate(e) {
 
// First, check to make sure a reason was filled in if uw-username was selected
 
if(e.target.sub_group.value === 'uw-username' && e.target.article.value.trim() === '') {
alert("You must supply a reason for the {{uw-username}} template.");
return;
}
 
// Find the selected <option> element so we can fetch the data structure
var selectedEl = $(e.target.sub_group).find('option[value="' + $(e.target.sub_group).val() + '"]');
 
// Then, grab all the values provided by the form
var params = {
Line 1,770 ⟶ 1,591:
messageData: selectedEl.data("messageData")
};
 
Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.status.init( e.target );
 
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
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' );
wikipedia_page.setCallbackParameters( params );
Line 1,783 ⟶ 1,604:
};
})(jQuery);
 
 
//</nowiki>
0

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu