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