14,091
edits
m (1 revision) |
m (1 revision imported) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 87: | Line 87: | ||
evt.initEvent( 'change', true, true ); | evt.initEvent( 'change', true, true ); | ||
result.actiontype[0].dispatchEvent( evt ); | result.actiontype[0].dispatchEvent( evt ); | ||
Morebits.wiki.actionCompleted.postfix = false; // avoid Action: completed notice | |||
// get current protection level asynchronously | // get current protection level asynchronously | ||
Twinkle.protect.fetchProtectionLevel(); | |||
}; | }; | ||
Twinkle.protect. | // Contains the current protection level in an object | ||
// Once filled, it will look something like: | |||
// { edit: { level: "sysop", expiry: <some date>, cascade: true }, ... } | |||
Twinkle.protect.currentProtectionLevels = {}; | |||
Twinkle.protect.fetchProtectionLevel = function twinkleprotectFetchProtectionLevel() { | |||
var api = new mw.Api(); | |||
var | var protectDeferred = api.get({ | ||
format: 'json', | |||
indexpageids: true, | |||
action: 'query', | |||
list: 'logevents', | |||
letype: 'protect', | |||
letitle: mw.config.get('wgPageName'), | |||
prop: 'info|flagged', | |||
inprop: 'protection', | |||
titles: mw.config.get('wgPageName') | |||
}); | |||
var stableDeferred = api.get({ | |||
format: 'json', | |||
action: 'query', | |||
list: 'logevents', | |||
letype: 'stable', | |||
letitle: mw.config.get('wgPageName') | |||
}); | |||
$ | $.when.apply($, [protectDeferred, stableDeferred]).done(function(protectData, stableData){ | ||
var | var pageid = protectData[0].query.pageids[0]; | ||
var | var page = protectData[0].query.pages[pageid]; | ||
var current = {}; | |||
type = " | $.each(page.protection, function( index, protection ) { | ||
if (protection.type !== "aft") { | |||
current[protection.type] = { | |||
level: protection.level, | |||
expiry: protection.expiry, | |||
cascade: protection.cascade === '' | |||
}; | |||
} | |||
}); | |||
if (page.flagged) { | |||
current.stabilize = { | |||
level: page.flagged.protection_level, | |||
if ( | expiry: page.flagged.protection_expiry | ||
}; | |||
} | } | ||
// show the protection level and log info | |||
Twinkle.protect.hasProtectLog = !!protectData[0].query.logevents.length; | |||
Twinkle.protect.hasStableLog = !!stableData[0].query.logevents.length; | |||
Twinkle.protect.currentProtectionLevels = current; | |||
Twinkle.protect.callback.showLogAndCurrentProtectInfo(); | |||
}); | }); | ||
}; | |||
Twinkle.protect.callback.showLogAndCurrentProtectInfo = function twinkleprotectCallbackShowLogAndCurrentProtectInfo() { | |||
var currentlyProtected = !$.isEmptyObject(Twinkle.protect.currentProtectionLevels); | |||
if (Twinkle.protect.hasProtectLog || Twinkle.protect.hasStableLog) { | |||
var $linkMarkup = $("<span>"); | |||
if (Twinkle.protect.hasProtectLog) | |||
$linkMarkup.append( | |||
$( '<a target="_blank" href="' + mw.util.getUrl('Special:Log', {action: 'view', page: mw.config.get('wgPageName'), type: 'protect'}) + '">protection log</a>' ), | |||
Twinkle.protect.hasStableLog ? $("<span> • </span>") : null | |||
); | |||
if (Twinkle.protect.hasStableLog) | |||
$linkMarkup.append($( '<a target="_blank" href="' + mw.util.getUrl('Special:Log', {action: 'view', page: mw.config.get('wgPageName'), type: 'stable'}) + '">pending changes log</a>)' )); | |||
Morebits.status.init($('div[name="hasprotectlog"] span')[0]); | |||
Morebits.status.warn( | |||
currentlyProtected ? 'Previous protections' : 'This page has been protected in the past', | |||
$linkMarkup[0] | |||
); | |||
} | } | ||
Twinkle.protect. | |||
Morebits.status.init($('div[name="currentprot"] span')[0]); | |||
var protectionNode = [], statusLevel = 'info'; | |||
if (currentlyProtected) { | |||
$.each(Twinkle.protect.currentProtectionLevels, function(type, settings) { | |||
var label = type === 'stabilize' ? 'Pending Changes' : Morebits.string.toUpperCaseFirstChar(type); | |||
protectionNode.push($("<b>" + label + ": " + settings.level + "</b>")[0]); | |||
if (settings.expiry === 'infinity') { | |||
protectionNode.push(" (indefinite) "); | |||
} else { | |||
protectionNode.push(" (expires " + new Date(settings.expiry).toUTCString() + ") "); | |||
} | |||
if (settings.cascade) { | |||
protectionNode.push("(cascading) "); | |||
} | |||
}); | |||
statusLevel = 'warn'; | |||
} else { | |||
protectionNode.push($("<b>no protection</b>")[0]); | |||
} | |||
Morebits.status[statusLevel]("Current protection level", protectionNode); | |||
}; | }; | ||
Line 162: | Line 210: | ||
label: 'Choose a preset:', | label: 'Choose a preset:', | ||
event: Twinkle.protect.callback.changePreset, | event: Twinkle.protect.callback.changePreset, | ||
list: (mw.config.get('wgArticleId') ? | list: (mw.config.get('wgArticleId') ? | ||
Twinkle.protect.protectionTypes.filter(function(v) { | Twinkle.protect.protectionTypes.filter(function(v) { | ||
return isTemplate || v.label !== 'Template protection'; | return isTemplate || v.label !== 'Template protection'; | ||
}) : | }) : | ||
Twinkle.protect.protectionTypesCreate) | Twinkle.protect.protectionTypesCreate) | ||
}); | }); | ||
Line 171: | Line 219: | ||
field2 = new Morebits.quickForm.element({ type: 'field', label: 'Protection options', name: 'field2' }); | field2 = new Morebits.quickForm.element({ type: 'field', label: 'Protection options', name: 'field2' }); | ||
field2.append({ type: 'div', name: 'currentprot', label: ' ' }); // holds the current protection level, as filled out by the async callback | field2.append({ type: 'div', name: 'currentprot', label: ' ' }); // holds the current protection level, as filled out by the async callback | ||
field2.append({ type: 'div', name: 'hasprotectlog', label: ' ' }); | |||
// for existing pages | // for existing pages | ||
if (mw.config.get('wgArticleId')) { | if (mw.config.get('wgArticleId')) { | ||
Line 201: | Line 250: | ||
label: 'Autoconfirmed', | label: 'Autoconfirmed', | ||
value: 'autoconfirmed' | value: 'autoconfirmed' | ||
}); | |||
editlevel.append({ | |||
type: 'option', | |||
label: 'Extended confirmed', | |||
value: 'extendedconfirmed' | |||
}); | }); | ||
if (isTemplate) { | if (isTemplate) { | ||
Line 224: | Line 278: | ||
} | } | ||
}, | }, | ||
// default expiry selection is conditionally set in Twinkle.protect.callback.changePreset | |||
list: [ | list: [ | ||
{ label: '1 hour', value: '1 hour' }, | { label: '1 hour', value: '1 hour' }, | ||
Line 231: | Line 286: | ||
{ label: '12 hours', value: '12 hours' }, | { label: '12 hours', value: '12 hours' }, | ||
{ label: '1 day', value: '1 day' }, | { label: '1 day', value: '1 day' }, | ||
{ label: '2 days' | { label: '2 days', value: '2 days' }, | ||
{ label: '3 days', value: '3 days' }, | { label: '3 days', value: '3 days' }, | ||
{ label: '4 days', value: '4 days' }, | { label: '4 days', value: '4 days' }, | ||
Line 272: | Line 327: | ||
label: 'Autoconfirmed', | label: 'Autoconfirmed', | ||
value: 'autoconfirmed' | value: 'autoconfirmed' | ||
}); | |||
movelevel.append({ | |||
type: 'option', | |||
label: 'Extended confirmed', | |||
value: 'extendedconfirmed' | |||
}); | }); | ||
if (isTemplate) { | if (isTemplate) { | ||
Line 295: | Line 355: | ||
} | } | ||
}, | }, | ||
// default expiry selection is conditionally set in Twinkle.protect.callback.changePreset | |||
list: [ | list: [ | ||
{ label: '1 hour', value: '1 hour' }, | { label: '1 hour', value: '1 hour' }, | ||
Line 311: | Line 372: | ||
{ label: '3 months', value: '3 months' }, | { label: '3 months', value: '3 months' }, | ||
{ label: '1 year', value: '1 year' }, | { label: '1 year', value: '1 year' }, | ||
{ label: 'indefinite' | { label: 'indefinite', value: 'indefinite' }, | ||
{ label: 'Custom...', value: 'custom' } | { label: 'Custom...', value: 'custom' } | ||
] | ] | ||
Line 341: | Line 402: | ||
pclevel.append({ | pclevel.append({ | ||
type: 'option', | type: 'option', | ||
label: ' | label: 'Pending changes', | ||
value: 'autoconfirmed', | value: 'autoconfirmed', | ||
selected: true | selected: true | ||
}); | }); | ||
field2.append({ | field2.append({ | ||
Line 403: | Line 459: | ||
}); | }); | ||
} | } | ||
createlevel.append({ | |||
type: 'option', | |||
label: 'Extended confirmed', | |||
value: 'extendedconfirmed', | |||
selected: true | |||
}); | |||
createlevel.append({ | createlevel.append({ | ||
type: 'option', | type: 'option', | ||
label: 'Sysop', | label: 'Sysop', | ||
value: 'sysop' | value: 'sysop' | ||
}); | }); | ||
field2.append({ | field2.append({ | ||
Line 450: | Line 511: | ||
case 'tag': | case 'tag': | ||
field1 = new Morebits.quickForm.element({ type: 'field', label: 'Tagging options', name: 'field1' }); | field1 = new Morebits.quickForm.element({ type: 'field', label: 'Tagging options', name: 'field1' }); | ||
field1.append({ type: 'div', name: 'currentprot', label: ' ' }); // holds the current protection level, as filled out by the async callback | |||
field1.append({ type: 'div', name: 'hasprotectlog', label: ' ' }); | |||
field1.append( { | field1.append( { | ||
type: 'select', | type: 'select', | ||
Line 487: | Line 550: | ||
field1 = new Morebits.quickForm.element({ type: 'field', label: 'Options', name: 'field1' }); | field1 = new Morebits.quickForm.element({ type: 'field', label: 'Options', name: 'field1' }); | ||
field1.append({ type: 'div', name: 'currentprot', label: ' ' }); // holds the current protection level, as filled out by the async callback | |||
field1.append({ type: 'div', name: 'hasprotectlog', label: ' ' }); | |||
field1.append( { | field1.append( { | ||
type: 'select', | type: 'select', | ||
Line 509: | Line 574: | ||
var oldfield; | var oldfield; | ||
if (field_preset) { | if (field_preset) { | ||
oldfield = $(e.target.form).find('fieldset[name="field_preset"]')[0]; | oldfield = $(e.target.form).find('fieldset[name="field_preset"]')[0]; | ||
Line 533: | Line 599: | ||
evt.initEvent( 'change', true, true ); | evt.initEvent( 'change', true, true ); | ||
e.target.form.category.dispatchEvent( evt ); | e.target.form.category.dispatchEvent( evt ); | ||
// reduce vertical height of dialog | // reduce vertical height of dialog | ||
$(e.target.form).find('fieldset[name="field2"] select').parent().css({ display: 'inline-block', marginRight: '0.5em' }); | $(e.target.form).find('fieldset[name="field2"] select').parent().css({ display: 'inline-block', marginRight: '0.5em' }); | ||
} | } | ||
// re-add protection level and log info, if it's available | |||
Twinkle.protect.callback.showLogAndCurrentProtectInfo(); | |||
}; | }; | ||
Line 556: | Line 618: | ||
}, | }, | ||
movemodify: function twinkleprotectFormMovemodifyEvent(e) { | movemodify: function twinkleprotectFormMovemodifyEvent(e) { | ||
// sync move settings with edit settings if applicable | |||
if (e.target.form.movelevel.disabled && !e.target.form.editlevel.disabled) { | |||
e.target.form.movelevel.value = e.target.form.editlevel.value; | |||
e.target.form.moveexpiry.value = e.target.form.editexpiry.value; | |||
} else if (e.target.form.editlevel.disabled) { | |||
e.target.form.movelevel.value = 'sysop'; | |||
e.target.form.moveexpiry.value = 'indefinite'; | |||
} | |||
e.target.form.movelevel.disabled = !e.target.checked; | e.target.form.movelevel.disabled = !e.target.checked; | ||
e.target.form.moveexpiry.disabled = !e.target.checked || (e.target.form.movelevel.value === 'all'); | e.target.form.moveexpiry.disabled = !e.target.checked || (e.target.form.movelevel.value === 'all'); | ||
Line 607: | Line 677: | ||
list: [ | list: [ | ||
{ label: 'Highly visible template (TE)', value: 'pp-template' } | { label: 'Highly visible template (TE)', value: 'pp-template' } | ||
] | |||
}, | |||
{ | |||
label: 'Extended confirmed protection', | |||
list: [ | |||
{ label: 'Arbitration enforcement (ECP)', selected: true, value: 'pp-30-500-arb' }, | |||
{ label: 'Persistent vandalism (ECP)', value: 'pp-30-500-vandalism' }, | |||
{ label: 'Disruptive editing (ECP)', value: 'pp-30-500-disruptive' }, | |||
{ label: 'BLP policy violations (ECP)', value: 'pp-30-500-blp' }, | |||
{ label: 'Sockpuppetry (ECP)', value: 'pp-30-500-sock' } | |||
] | ] | ||
}, | }, | ||
Line 614: | Line 694: | ||
{ label: 'Generic (semi)', value: 'pp-semi-protected' }, | { label: 'Generic (semi)', value: 'pp-semi-protected' }, | ||
{ label: 'Persistent vandalism (semi)', selected: true, value: 'pp-semi-vandalism' }, | { label: 'Persistent vandalism (semi)', selected: true, value: 'pp-semi-vandalism' }, | ||
{ label: 'Disruptive editing (semi)', value: 'pp-semi-disruptive' }, | |||
{ label: 'Adding unsourced content (semi)', value: 'pp-semi-unsourced' }, | |||
{ label: 'BLP policy violations (semi)', value: 'pp-semi-blp' }, | { label: 'BLP policy violations (semi)', value: 'pp-semi-blp' }, | ||
{ label: 'Sockpuppetry (semi)', value: 'pp-semi-sock' }, | { label: 'Sockpuppetry (semi)', value: 'pp-semi-sock' }, | ||
Line 624: | Line 706: | ||
{ label: 'Generic (PC)', value: 'pp-pc-protected' }, | { label: 'Generic (PC)', value: 'pp-pc-protected' }, | ||
{ label: 'Persistent vandalism (PC)', value: 'pp-pc-vandalism' }, | { label: 'Persistent vandalism (PC)', value: 'pp-pc-vandalism' }, | ||
{ label: 'Disruptive editing (PC)', value: 'pp-pc-disruptive' }, | |||
{ label: 'Adding unsourced content (PC)', value: 'pp-pc-unsourced' }, | |||
{ label: 'BLP policy violations (PC)', value: 'pp-pc-blp' } | { label: 'BLP policy violations (PC)', value: 'pp-pc-blp' } | ||
] | ] | ||
Line 650: | Line 734: | ||
} | } | ||
]; | ]; | ||
// A page with both regular and PC protection will be assigned its regular | |||
// protection weight plus 2 | |||
Twinkle.protect.protectionWeight = { | |||
sysop: 40, | |||
templateeditor: 30, | |||
extendedconfirmed: 20, | |||
autoconfirmed: 10, | |||
flaggedrevs_autoconfirmed: 5, // Pending Changes protection alone | |||
all: 0, | |||
flaggedrevs_none: 0 // just in case | |||
}; | |||
// NOTICE: keep this synched with [[MediaWiki:Protect-dropdown]] | // NOTICE: keep this synched with [[MediaWiki:Protect-dropdown]] | ||
Line 662: | Line 758: | ||
edit: 'sysop', | edit: 'sysop', | ||
move: 'sysop', | move: 'sysop', | ||
reason: '[[WP:PP#Content disputes|Edit warring / | reason: '[[WP:PP#Content disputes|Edit warring / content dispute]]' | ||
}, | }, | ||
'pp-vandalism': { | 'pp-vandalism': { | ||
Line 678: | Line 774: | ||
move: 'templateeditor', | move: 'templateeditor', | ||
reason: '[[WP:High-risk templates|Highly visible template]]' | reason: '[[WP:High-risk templates|Highly visible template]]' | ||
}, | |||
'pp-30-500-arb': { | |||
edit: 'extendedconfirmed', | |||
move: 'extendedconfirmed', | |||
reason: '[[WP:30/500|Arbitration enforcement]]', | |||
template: 'pp-30-500' | |||
}, | |||
'pp-30-500-vandalism': { | |||
edit: 'extendedconfirmed', | |||
move: 'extendedconfirmed', | |||
reason: 'Persistent [[WP:Vandalism|vandalism]] from (auto)confirmed accounts', | |||
template: 'pp-30-500' | |||
}, | |||
'pp-30-500-disruptive': { | |||
edit: 'extendedconfirmed', | |||
move: 'extendedconfirmed', | |||
reason: 'Persistent [[WP:Disruptive editing|disruptive editing]] from (auto)confirmed accounts', | |||
template: 'pp-30-500' | |||
}, | |||
'pp-30-500-blp': { | |||
edit: 'extendedconfirmed', | |||
move: 'extendedconfirmed', | |||
reason: 'Persistent violations of the [[WP:BLP|biographies of living persons policy]] from (auto)confirmed accounts', | |||
template: 'pp-30-500' | |||
}, | |||
'pp-30-500-sock': { | |||
edit: 'extendedconfirmed', | |||
move: 'extendedconfirmed', | |||
reason: 'Persistent [[WP:Sock puppetry|sock puppetry]]', | |||
template: 'pp-30-500' | |||
}, | }, | ||
'pp-semi-vandalism': { | 'pp-semi-vandalism': { | ||
Line 683: | Line 809: | ||
reason: 'Persistent [[WP:Vandalism|vandalism]]', | reason: 'Persistent [[WP:Vandalism|vandalism]]', | ||
template: 'pp-vandalism' | template: 'pp-vandalism' | ||
}, | |||
'pp-semi-disruptive': { | |||
edit: 'autoconfirmed', | |||
reason: 'Persistent [[WP:Disruptive editing|disruptive editing]]', | |||
template: 'pp-protected' | |||
}, | |||
'pp-semi-unsourced': { | |||
edit: 'autoconfirmed', | |||
reason: 'Persistent addition of [[WP:INTREF|unsourced or poorly sourced content]]', | |||
template: 'pp-protected' | |||
}, | }, | ||
'pp-semi-blp': { | 'pp-semi-blp': { | ||
edit: 'autoconfirmed', | edit: 'autoconfirmed', | ||
reason: 'Violations of the [[WP: | reason: 'Violations of the [[WP:BLP|biographies of living persons policy]]', | ||
template: 'pp-blp' | |||
}, | }, | ||
'pp-semi-usertalk': { | 'pp-semi-usertalk': { | ||
edit: 'autoconfirmed', | edit: 'autoconfirmed', | ||
move: ' | move: 'autoconfirmed', | ||
reason: '[[WP:PP#Talk-page protection|Inappropriate use of user talk page while blocked]]' | reason: '[[WP:PP#Talk-page protection|Inappropriate use of user talk page while blocked]]', | ||
template: 'pp-usertalk' | |||
}, | }, | ||
'pp-semi-template': { // removed for now | 'pp-semi-template': { // removed for now | ||
edit: 'autoconfirmed', | edit: 'autoconfirmed', | ||
move: ' | move: 'autoconfirmed', | ||
reason: '[[WP:High-risk templates|Highly visible template]]', | reason: '[[WP:High-risk templates|Highly visible template]]', | ||
template: 'pp-template' | template: 'pp-template' | ||
Line 701: | Line 839: | ||
'pp-semi-sock': { | 'pp-semi-sock': { | ||
edit: 'autoconfirmed', | edit: 'autoconfirmed', | ||
reason: 'Persistent [[WP:Sock puppetry|sock puppetry]]' | reason: 'Persistent [[WP:Sock puppetry|sock puppetry]]', | ||
template: 'pp-sock' | |||
}, | }, | ||
'pp-semi-protected': { | 'pp-semi-protected': { | ||
Line 711: | Line 850: | ||
stabilize: 'autoconfirmed', // stabilize = Pending Changes | stabilize: 'autoconfirmed', // stabilize = Pending Changes | ||
reason: 'Persistent [[WP:Vandalism|vandalism]]', | reason: 'Persistent [[WP:Vandalism|vandalism]]', | ||
template: 'pp- | template: 'pp-pc' | ||
}, | |||
'pp-pc-disruptive': { | |||
stabilize: 'autoconfirmed', | |||
reason: 'Persistent [[WP:Disruptive editing|disruptive editing]]', | |||
template: 'pp-pc' | |||
}, | |||
'pp-pc-unsourced': { | |||
stabilize: 'autoconfirmed', | |||
reason: 'Persistent addition of [[WP:INTREF|unsourced or poorly sourced content]]', | |||
template: 'pp-pc' | |||
}, | }, | ||
'pp-pc-blp': { | 'pp-pc-blp': { | ||
stabilize: 'autoconfirmed', | stabilize: 'autoconfirmed', | ||
reason: 'Violations of the [[WP:BLP|biographies of living persons policy]]', | reason: 'Violations of the [[WP:BLP|biographies of living persons policy]]', | ||
template: 'pp- | template: 'pp-pc' | ||
}, | }, | ||
'pp-pc-protected': { | 'pp-pc-protected': { | ||
stabilize: 'autoconfirmed', | stabilize: 'autoconfirmed', | ||
reason: null, | reason: null, | ||
template: 'pp- | template: 'pp-pc' | ||
}, | }, | ||
'pp-move': { | 'pp-move': { | ||
Line 752: | Line 901: | ||
}, | }, | ||
'pp-create-salt': { | 'pp-create-salt': { | ||
create: ' | create: 'extendedconfirmed', | ||
reason: '[[WP:SALT|Repeatedly recreated]]' | reason: '[[WP:SALT|Repeatedly recreated]]' | ||
}, | }, | ||
'pp-create-blp': { | 'pp-create-blp': { | ||
create: ' | create: 'extendedconfirmed', | ||
reason: '[[WP:BLPDEL|Recently deleted BLP]]' | reason: '[[WP:BLPDEL|Recently deleted BLP]]' | ||
}, | }, | ||
'pp-create': { | 'pp-create': { | ||
create: ' | create: 'extendedconfirmed', | ||
reason: '{{pp-create}}' | reason: '{{pp-create}}' | ||
} | } | ||
Line 775: | Line 924: | ||
}, | }, | ||
{ | { | ||
label: ' | label: 'Edit protection templates', | ||
list: [ | list: [ | ||
{ label: '{{pp-vandalism}}: vandalism', value: 'pp-vandalism' }, | |||
{ label: '{{pp-dispute}}: dispute/edit war', value: 'pp-dispute', selected: true }, | { label: '{{pp-dispute}}: dispute/edit war', value: 'pp-dispute', selected: true }, | ||
{ label: '{{pp- | { label: '{{pp-blp}}: BLP violations', value: 'pp-blp' }, | ||
{ label: '{{pp-sock}}: sockpuppetry', value: 'pp-sock' }, | |||
{ label: '{{pp- | |||
{ label: '{{pp-template}}: high-risk template', value: 'pp-template' }, | { label: '{{pp-template}}: high-risk template', value: 'pp-template' }, | ||
{ label: '{{pp | { label: '{{pp-usertalk}}: blocked user talk', value: 'pp-usertalk' }, | ||
{ label: '{{pp-protected}}: general protection', value: 'pp-protected' }, | |||
{ label: '{{pp-semi-indef}}: general long-term semi-protection', value: 'pp-semi-indef' }, | |||
{ label: '{{pp-30-500}}: extended confirmed protection', value: 'pp-30-500' } | |||
{ label: '{{pp- | |||
{ label: '{{pp-semi- | |||
{ label: '{{pp- | |||
] | ] | ||
}, | }, | ||
Line 801: | Line 940: | ||
label: 'Pending changes templates', | label: 'Pending changes templates', | ||
list: [ | list: [ | ||
{ label: '{{pp- | { label: '{{pp-pc}}: pending changes', value: 'pp-pc' } | ||
] | ] | ||
}, | }, | ||
Line 831: | Line 970: | ||
if (actiontype === 'protect') { // actually protecting the page | if (actiontype === 'protect') { // actually protecting the page | ||
var item = Twinkle.protect.protectionPresetsInfo[form.category.value]; | var item = Twinkle.protect.protectionPresetsInfo[form.category.value]; | ||
if (mw.config.get('wgArticleId')) { | if (mw.config.get('wgArticleId')) { | ||
if (item.edit) { | if (item.edit) { | ||
Line 837: | Line 977: | ||
form.editlevel.value = item.edit; | form.editlevel.value = item.edit; | ||
Twinkle.protect.formevents.editlevel({ target: form.editlevel }); | Twinkle.protect.formevents.editlevel({ target: form.editlevel }); | ||
form.editexpiry.value = '2 days'; | |||
} else { | } else { | ||
form.editmodify.checked = false; | form.editmodify.checked = false; | ||
Line 847: | Line 988: | ||
form.movelevel.value = item.move; | form.movelevel.value = item.move; | ||
Twinkle.protect.formevents.movelevel({ target: form.movelevel }); | Twinkle.protect.formevents.movelevel({ target: form.movelevel }); | ||
form.moveexpiry.value = '2 days'; | |||
} else { | } else { | ||
form.movemodify.checked = false; | form.movemodify.checked = false; | ||
Line 887: | Line 1,029: | ||
form.noinclude.checked = true; | form.noinclude.checked = true; | ||
form.editexpiry.value = form.moveexpiry.value = form.pcexpiry.value = "indefinite"; | form.editexpiry.value = form.moveexpiry.value = form.pcexpiry.value = "indefinite"; | ||
} else { | } else if( mw.config.get('wgNamespaceNumber') !== 10 ) { | ||
form.noinclude.checked = false; | form.noinclude.checked = false; | ||
} | } | ||
Line 897: | Line 1,039: | ||
form.expiry.disabled = true; | form.expiry.disabled = true; | ||
} else { | } else { | ||
form.expiry.value = ''; | |||
form.expiry.disabled = false; | form.expiry.disabled = false; | ||
} | } | ||
Line 916: | Line 1,059: | ||
} | } | ||
var tagparams; | |||
if( actiontype === 'tag' || (actiontype === 'protect' && mw.config.get('wgArticleId')) ) { | if( actiontype === 'tag' || (actiontype === 'protect' && mw.config.get('wgArticleId')) ) { | ||
tagparams = { | tagparams = { | ||
tag: form.tagtype.value, | tag: form.tagtype.value, | ||
reason: ((form.tagtype.value === 'pp-protected' || form.tagtype.value === 'pp-semi-protected' || form.tagtype.value === 'pp-move') && form.protectReason) ? form.protectReason.value : null, | reason: ((form.tagtype.value === 'pp-protected' || form.tagtype.value === 'pp-semi-protected' || form.tagtype.value === 'pp-move') && form.protectReason) ? form.protectReason.value : null, | ||
small: form.small.checked, | small: form.small.checked, | ||
noinclude: form.noinclude.checked | noinclude: form.noinclude.checked | ||
Line 930: | Line 1,072: | ||
case 'protect': | case 'protect': | ||
// protect the page | // protect the page | ||
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName'); | Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName'); | ||
Morebits.wiki.actionCompleted.notice = "Protection complete"; | Morebits.wiki.actionCompleted.notice = "Protection complete"; | ||
Line 945: | Line 1,086: | ||
} | } | ||
}; | }; | ||
var stabilizeValues = {}; | |||
if (form.pclevel) { | |||
stabilizeValues = { | |||
pclevel: form.pclevel.value, | |||
pcexpiry: form.pcexpiry.value, | |||
protectReason: form.protectReason.value | |||
}; | |||
} | |||
var protectIt = function twinkleprotectCallbackProtectIt(next) { | var protectIt = function twinkleprotectCallbackProtectIt(next) { | ||
Line 957: | Line 1,107: | ||
} else { | } else { | ||
thispage.setCreateProtection(form.createlevel.value, form.createexpiry.value); | thispage.setCreateProtection(form.createlevel.value, form.createexpiry.value); | ||
thispage.setWatchlist(false); | |||
} | } | ||
Line 981: | Line 1,132: | ||
thispage = new Morebits.wiki.page(mw.config.get('wgPageName'), "Applying pending changes protection"); | thispage = new Morebits.wiki.page(mw.config.get('wgPageName'), "Applying pending changes protection"); | ||
thispage.setFlaggedRevs( | thispage.setFlaggedRevs(stabilizeValues.pclevel, stabilizeValues.pcexpiry); | ||
if ( | if (stabilizeValues.protectReason) { | ||
thispage.setEditSummary( | thispage.setEditSummary(stabilizeValues.protectReason); | ||
} else { | } else { | ||
alert("You must enter a protect reason, which will be inscribed into the protection log."); | alert("You must enter a protect reason, which will be inscribed into the protection log."); | ||
Line 1,028: | Line 1,179: | ||
case 'request': | case 'request': | ||
// file request at | // file request at RFPP | ||
var typename, typereason; | var typename, typereason; | ||
switch( form.category.value ) { | switch( form.category.value ) { | ||
Line 1,039: | Line 1,190: | ||
case 'pp-template': | case 'pp-template': | ||
typename = 'template protection'; | typename = 'template protection'; | ||
break; | |||
case 'pp-30-500-arb': | |||
case 'pp-30-500-vandalism': | |||
case 'pp-30-500-disruptive': | |||
case 'pp-30-500-blp': | |||
case 'pp-30-500-sock': | |||
typename = 'extended confirmed'; | |||
break; | break; | ||
case 'pp-semi-vandalism': | case 'pp-semi-vandalism': | ||
case 'pp-semi-disruptive': | |||
case 'pp-semi-unsourced': | |||
case 'pp-semi-usertalk': | case 'pp-semi-usertalk': | ||
case 'pp-semi-sock': | case 'pp-semi-sock': | ||
Line 1,050: | Line 1,210: | ||
case 'pp-pc-blp': | case 'pp-pc-blp': | ||
case 'pp-pc-protected': | case 'pp-pc-protected': | ||
case 'pp-pc-unsourced': | |||
case 'pp-pc-disruptive': | |||
typename = 'pending changes'; | typename = 'pending changes'; | ||
break; | break; | ||
Line 1,077: | Line 1,239: | ||
case 'pp-semi-vandalism': | case 'pp-semi-vandalism': | ||
case 'pp-pc-vandalism': | case 'pp-pc-vandalism': | ||
typereason = 'Persistent vandalism'; | case 'pp-30-500-vandalism': | ||
typereason = 'Persistent [[WP:VAND|vandalism]]'; | |||
break; | |||
case 'pp-semi-disruptive': | |||
case 'pp-pc-disruptive': | |||
case 'pp-30-500-disruptive': | |||
typereason = 'Persistent [[Wikipedia:Disruptive editing|disruptive editing]]'; | |||
break; | |||
case 'pp-semi-unsourced': | |||
case 'pp-pc-unsourced': | |||
typereason = 'Persistent addition of [[WP:INTREF|unsourced or poorly sourced content]]'; | |||
break; | break; | ||
case 'pp-template': | case 'pp-template': | ||
typereason = ' | typereason = '[[WP:HIGHRISK|High-risk template]]'; | ||
break; | |||
case 'pp-30-500-arb': | |||
typereason = '[[WP:30/500|Arbitration enforcement]]'; | |||
break; | break; | ||
case 'pp-usertalk': | case 'pp-usertalk': | ||
Line 1,087: | Line 1,262: | ||
break; | break; | ||
case 'pp-semi-sock': | case 'pp-semi-sock': | ||
typereason = 'Persistent sockpuppetry'; | case 'pp-30-500-sock': | ||
typereason = 'Persistent [[WP:SOCK|sockpuppetry]]'; | |||
break; | break; | ||
case 'pp-semi-blp': | case 'pp-semi-blp': | ||
case 'pp-pc-blp': | case 'pp-pc-blp': | ||
case 'pp-30-500-blp': | |||
typereason = '[[WP:BLP|BLP]] policy violations'; | typereason = '[[WP:BLP|BLP]] policy violations'; | ||
break; | break; | ||
Line 1,137: | Line 1,314: | ||
Morebits.status.init( form ); | Morebits.status.init( form ); | ||
rppName = 'Wikipedia:Requests for page protection'; | var rppName = 'Wikipedia:Requests for page protection'; | ||
// Updating data for the action completed event | // Updating data for the action completed event | ||
Line 1,182: | Line 1,359: | ||
if( params.reason ) { | if( params.reason ) { | ||
tag += '|reason=' + params.reason; | tag += '|reason=' + params.reason; | ||
} | } | ||
if( params.small ) { | if( params.small ) { | ||
Line 1,194: | Line 1,368: | ||
summary = 'Removing protection template' + Twinkle.getPref('summaryAd'); | summary = 'Removing protection template' + Twinkle.getPref('summaryAd'); | ||
} else { | } else { | ||
if( params.noinclude ) { | if( Morebits.wiki.isPageRedirect() ) { | ||
//Only tag if no {{rcat shell}} is found | |||
if (!text.match(/{{(?:redr|this is a redirect|r(?:edirect)?(?:.?cat.*)?[ _]?sh)/i)) { | |||
text = text.replace(/#REDIRECT ?(\[\[.*?\]\])(.*)/i, "#REDIRECT $1$2\n\n{{" + tag + "}}"); | |||
} else { | |||
Morebits.status.info("Redirect category shell present", "nothing to do"); | |||
return; | |||
} | |||
} else if( params.noinclude ) { | |||
text = "<noinclude>{{" + tag + "}}</noinclude>" + text; | text = "<noinclude>{{" + tag + "}}</noinclude>" + text; | ||
} else { | } else { | ||
text = "{{" + tag + "}}\n" + text; | text = "{{" + tag + "}}\n" + text; | ||
Line 1,217: | Line 1,397: | ||
var statusElement = rppPage.getStatusElement(); | var statusElement = rppPage.getStatusElement(); | ||
var rppRe = new RegExp( '===\\s*(\\[\\[)?\\s*:?\\s*' + RegExp.escape( Morebits.pageNameNorm, true ) + '\\s*(\\]\\])?\\s*===', 'm' ); | |||
var rppRe = new RegExp( ' | |||
var tag = rppRe.exec( text ); | var tag = rppRe.exec( text ); | ||
var rppLink = document.createElement('a'); | var rppLink = document.createElement('a'); | ||
rppLink.setAttribute('href', mw.util. | rppLink.setAttribute('href', mw.util.getUrl(rppPage.getPageName()) ); | ||
rppLink.appendChild(document.createTextNode(rppPage.getPageName())); | rppLink.appendChild(document.createTextNode(rppPage.getPageName())); | ||
Line 1,259: | Line 1,409: | ||
} | } | ||
var newtag = '=== | var newtag = '=== [[:' + Morebits.pageNameNorm + ']] ===\n'; | ||
if( ( new RegExp( '^' + RegExp.escape( newtag ).replace( /\s+/g, '\\s*' ), 'm' ) ).test( text ) ) { | if( ( new RegExp( '^' + RegExp.escape( newtag ).replace( /\s+/g, '\\s*' ), 'm' ) ).test( text ) ) { | ||
statusElement.error( [ 'There is already a protection request for this page at ', rppLink, ', aborting.' ] ); | statusElement.error( [ 'There is already a protection request for this page at ', rppLink, ', aborting.' ] ); | ||
return; | return; | ||
} | } | ||
newtag += '* {{pagelinks|1=' + Morebits.pageNameNorm + '}}\n\n'; | |||
var words; | var words; | ||
Line 1,280: | Line 1,431: | ||
words += params.typename; | words += params.typename; | ||
newtag += "'''" + Morebits.string.toUpperCaseFirstChar(words) + ( params.reason !== '' ? ( ":''' " + | newtag += "'''" + Morebits.string.toUpperCaseFirstChar(words) + ( params.reason !== '' ? ( ":''' " + | ||
Morebits.string.formatReasonText(params.reason) ) : ".'''" ) + " ~~~~"; | Morebits.string.formatReasonText(params.reason) ) : ".'''" ) + " ~~~~"; | ||
// If either protection type results in a increased status, then post it under increase | |||
// else we post it under decrease | |||
var increase = false; | |||
var protInfo = Twinkle.protect.protectionPresetsInfo[params.category]; | |||
// function to compute protection weights (see comment at Twinkle.protect.protectionWeight) | |||
var computeWeight = function(mainLevel, stabilizeLevel) { | |||
var result = Twinkle.protect.protectionWeight[mainLevel || 'all']; | |||
if (stabilizeLevel) { | |||
if (result) { | |||
if (stabilizeLevel.level === "autoconfirmed") { | |||
result += 2; | |||
} | |||
} else { | |||
result = Twinkle.protect.protectionWeight["flaggedrevs_" + stabilizeLevel]; | |||
} | |||
} | |||
return result; | |||
}; | |||
// compare the page's current protection weights with the protection we are requesting | |||
var editWeight = computeWeight(Twinkle.protect.currentProtectionLevels.edit && | |||
Twinkle.protect.currentProtectionLevels.edit.level, | |||
Twinkle.protect.currentProtectionLevels.stabilize && | |||
Twinkle.protect.currentProtectionLevels.stabilize.level); | |||
if (computeWeight(protInfo.edit, protInfo.stabilize) > editWeight || | |||
computeWeight(protInfo.move) > computeWeight(Twinkle.protect.currentProtectionLevels.move && | |||
Twinkle.protect.currentProtectionLevels.move.level) || | |||
computeWeight(protInfo.create) > computeWeight(Twinkle.protect.currentProtectionLevels.create && | |||
Twinkle.protect.currentProtectionLevels.create.level)) { | |||
increase = true; | |||
} | |||
var reg; | var reg; | ||
if ( | if ( increase ) { | ||
reg = /(\n==\s*Current requests for | reg = /(\n==\s*Current requests for reduction in protection level\s*==)/; | ||
} else { | } else { | ||
reg = /(\n==\s*Current requests for | reg = /(\n==\s*Current requests for edits to a protected page\s*==)/; | ||
} | } | ||
var originalTextLength = text.length; | var originalTextLength = text.length; | ||
text = text.replace( reg, " | text = text.replace( reg, "\n" + newtag + "\n$1"); | ||
if (text.length === originalTextLength) | if (text.length === originalTextLength) | ||
{ | { | ||
var linknode = document.createElement('a'); | var linknode = document.createElement('a'); | ||
linknode.setAttribute("href", mw.util. | linknode.setAttribute("href", mw.util.getUrl("Wikipedia:Twinkle/Fixing RPP") ); | ||
linknode.appendChild(document.createTextNode('How to fix RPP')); | linknode.appendChild(document.createTextNode('How to fix RPP')); | ||
statusElement.error( [ 'Could not find relevant heading on WP:RPP. To fix this problem, please see ', linknode, '.' ] ); | statusElement.error( [ 'Could not find relevant heading on WP:RPP. To fix this problem, please see ', linknode, '.' ] ); | ||
Line 1,300: | Line 1,485: | ||
} | } | ||
statusElement.status( 'Adding new request...' ); | statusElement.status( 'Adding new request...' ); | ||
rppPage.setEditSummary( "Requesting " + params.typename + (params.typename === "pending changes" ? ' on [[' : ' of [[') + | rppPage.setEditSummary( "Requesting " + params.typename + (params.typename === "pending changes" ? ' on [[:' : ' of [[:') + | ||
Morebits.pageNameNorm + ']].' + Twinkle.getPref('summaryAd') ); | Morebits.pageNameNorm + ']].' + Twinkle.getPref('summaryAd') ); | ||
rppPage.setPageText( text ); | rppPage.setPageText( text ); |