「MediaWiki:Gadget-twinkleprotect.js」:修訂間差異
跳至導覽
跳至搜尋
小 (已匯入 1 筆修訂:Twinkle) |
Xiplus-bot(留言 | 貢獻) 小 (繁簡轉換) |
||
行 22: | 行 22: | ||
} |
} |
||
Twinkle.addPortletLink(Twinkle.protect.callback, Morebits.userIsInGroup('sysop') ? "保 |
Twinkle.addPortletLink(Twinkle.protect.callback, Morebits.userIsInGroup('sysop') ? "保護" : "保護", "tw-rpp", |
||
Morebits.userIsInGroup('sysop') ? "保 |
Morebits.userIsInGroup('sysop') ? "保護頁面" : "請求保護頁面" ); |
||
}; |
}; |
||
行 30: | 行 30: | ||
var Window = new Morebits.simpleWindow( 620, 530 ); |
var Window = new Morebits.simpleWindow( 620, 530 ); |
||
Window.setTitle( Morebits.userIsInGroup( 'sysop' ) ? "施行或 |
Window.setTitle( Morebits.userIsInGroup( 'sysop' ) ? "施行或請求保護頁面" : "請求保護頁面" ); |
||
Window.setScriptName( "Twinkle" ); |
Window.setScriptName( "Twinkle" ); |
||
Window.addFooterLink( "保 |
Window.addFooterLink( "保護模板", "Template:Protection templates" ); |
||
Window.addFooterLink( "保 |
Window.addFooterLink( "保護方針", "WP:PROT" ); |
||
Window.addFooterLink( "Twinkle |
Window.addFooterLink( "Twinkle幫助", "WP:TW/DOC#protect" ); |
||
var form = new Morebits.quickForm( Twinkle.protect.callback.evaluate ); |
var form = new Morebits.quickForm( Twinkle.protect.callback.evaluate ); |
||
var actionfield = form.append( { |
var actionfield = form.append( { |
||
type: 'field', |
type: 'field', |
||
label: '操作 |
label: '操作類型' |
||
} ); |
} ); |
||
if( Morebits.userIsInGroup( 'sysop' ) ) { |
if( Morebits.userIsInGroup( 'sysop' ) ) { |
||
行 48: | 行 48: | ||
list: [ |
list: [ |
||
{ |
{ |
||
label: '保 |
label: '保護頁面', |
||
value: 'protect', |
value: 'protect', |
||
checked: true |
checked: true |
||
行 61: | 行 61: | ||
list: [ |
list: [ |
||
{ |
{ |
||
label: ' |
label: '請求保護頁面', |
||
value: 'request', |
value: 'request', |
||
tooltip: '如果您想在WP:RFPP |
tooltip: '如果您想在WP:RFPP請求保護此頁' + (Morebits.userIsInGroup('sysop') ? '而不是自行完成。' : '。'), |
||
checked: !Morebits.userIsInGroup('sysop') |
checked: !Morebits.userIsInGroup('sysop') |
||
}, |
}, |
||
{ |
{ |
||
label: '用保 |
label: '用保護模板標記此頁', |
||
value: 'tag', |
value: 'tag', |
||
tooltip: '可以用此 |
tooltip: '可以用此為頁面加上合適的保護模板。', |
||
disabled: mw.config.get('wgArticleId') === 0 |
disabled: mw.config.get('wgArticleId') === 0 |
||
} |
} |
||
行 75: | 行 75: | ||
} ); |
} ); |
||
form.append({ type: 'field', label: ' |
form.append({ type: 'field', label: '預設', name: 'field_preset' }); |
||
form.append({ type: 'field', label: '1', name: 'field1' }); |
form.append({ type: 'field', label: '1', name: 'field1' }); |
||
form.append({ type: 'field', label: '2', name: 'field2' }); |
form.append({ type: 'field', label: '2', name: 'field2' }); |
||
行 130: | 行 130: | ||
result.push(boldnode); |
result.push(boldnode); |
||
if (expiry === 'infinity') { |
if (expiry === 'infinity') { |
||
result.push("( |
result.push("(無限期)"); |
||
} else { |
} else { |
||
result.push("( |
result.push("(過期:" + new Date(expiry).toUTCString() + ")"); |
||
} |
} |
||
if (cascade) { |
if (cascade) { |
||
result.push("( |
result.push("(聯鎖)"); |
||
} |
} |
||
} |
} |
||
行 155: | 行 155: | ||
if (!result.length) { |
if (!result.length) { |
||
var boldnode = document.createElement('b'); |
var boldnode = document.createElement('b'); |
||
boldnode.textContent = " |
boldnode.textContent = "無保護"; |
||
result.push(boldnode); |
result.push(boldnode); |
||
} |
} |
||
Twinkle.protect.protectionLevel = result; |
Twinkle.protect.protectionLevel = result; |
||
Morebits.status.init($('div[name="currentprot"] span').last()[0]); |
Morebits.status.init($('div[name="currentprot"] span').last()[0]); |
||
Morebits.status.info(" |
Morebits.status.info("當前保護等級", Twinkle.protect.protectionLevel); |
||
} |
} |
||
行 175: | 行 175: | ||
switch (e.target.values) { |
switch (e.target.values) { |
||
case 'protect': |
case 'protect': |
||
field_preset = new Morebits.quickForm.element({ type: 'field', label: ' |
field_preset = new Morebits.quickForm.element({ type: 'field', label: '預設', name: 'field_preset' }); |
||
field_preset.append({ |
field_preset.append({ |
||
type: 'select', |
type: 'select', |
||
name: 'category', |
name: 'category', |
||
label: ' |
label: '選擇預設:', |
||
event: Twinkle.protect.callback.changePreset, |
event: Twinkle.protect.callback.changePreset, |
||
list: (mw.config.get('wgArticleId') ? |
list: (mw.config.get('wgArticleId') ? |
||
行 186: | 行 186: | ||
}); |
}); |
||
field2 = new Morebits.quickForm.element({ type: 'field', label: '保 |
field2 = new Morebits.quickForm.element({ type: 'field', label: '保護選項', 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 |
||
// for existing pages |
// for existing pages |
||
行 196: | 行 196: | ||
list: [ |
list: [ |
||
{ |
{ |
||
label: '修改 |
label: '修改編輯權限', |
||
value: 'editmodify', |
value: 'editmodify', |
||
tooltip: '如果此 |
tooltip: '如果此項被關閉,編輯權限將不被修改。', |
||
checked: true |
checked: true |
||
} |
} |
||
行 206: | 行 206: | ||
type: 'select', |
type: 'select', |
||
name: 'editlevel', |
name: 'editlevel', |
||
label: ' |
label: '編輯權限:', |
||
event: Twinkle.protect.formevents.editlevel |
event: Twinkle.protect.formevents.editlevel |
||
}); |
}); |
||
editlevel.append({ |
editlevel.append({ |
||
type: 'option', |
type: 'option', |
||
label: '(站 |
label: '(站點默認)', |
||
value: 'all' |
value: 'all' |
||
}); |
}); |
||
editlevel.append({ |
editlevel.append({ |
||
type: 'option', |
type: 'option', |
||
label: '禁止未 |
label: '禁止未註冊用戶', |
||
value: 'autoconfirmed' |
value: 'autoconfirmed' |
||
}); |
}); |
||
editlevel.append({ |
editlevel.append({ |
||
type: 'option', |
type: 'option', |
||
label: ' |
label: '僅管理員', |
||
value: 'sysop', |
value: 'sysop', |
||
selected: true |
selected: true |
||
行 228: | 行 228: | ||
type: 'select', |
type: 'select', |
||
name: 'editexpiry', |
name: 'editexpiry', |
||
label: ' |
label: '終止時間:', |
||
event: function(e) { |
event: function(e) { |
||
if (e.target.value === 'custom') { |
if (e.target.value === 'custom') { |
||
行 236: | 行 236: | ||
}, |
}, |
||
list: [ |
list: [ |
||
{ label: '1小 |
{ label: '1小時', value: '1 hour' }, |
||
{ label: '2小 |
{ label: '2小時', value: '2 hours' }, |
||
{ label: '3小 |
{ label: '3小時', value: '3 hours' }, |
||
{ label: '6小 |
{ label: '6小時', value: '6 hours' }, |
||
{ label: '1日', value: '1 day' }, |
{ label: '1日', value: '1 day' }, |
||
{ label: '3日', value: '3 days' }, |
{ label: '3日', value: '3 days' }, |
||
行 248: | 行 248: | ||
{ label: '6月', value: '6 months' }, |
{ label: '6月', value: '6 months' }, |
||
{ label: '1年', value: '1 year' }, |
{ label: '1年', value: '1 year' }, |
||
{ label: ' |
{ label: '無限期', value: 'indefinite' }, |
||
{ label: '自定 |
{ label: '自定義…', value: 'custom' } |
||
] |
] |
||
}); |
}); |
||
行 258: | 行 258: | ||
list: [ |
list: [ |
||
{ |
{ |
||
label: '修改移 |
label: '修改移動權限', |
||
value: 'movemodify', |
value: 'movemodify', |
||
tooltip: '如果此 |
tooltip: '如果此項被關閉,移動權限將不被修改。', |
||
checked: true |
checked: true |
||
} |
} |
||
行 268: | 行 268: | ||
type: 'select', |
type: 'select', |
||
name: 'movelevel', |
name: 'movelevel', |
||
label: '移 |
label: '移動權限:', |
||
event: Twinkle.protect.formevents.movelevel |
event: Twinkle.protect.formevents.movelevel |
||
}); |
}); |
||
movelevel.append({ |
movelevel.append({ |
||
type: 'option', |
type: 'option', |
||
label: '(站 |
label: '(站點默認)', |
||
value: 'all' |
value: 'all' |
||
}); |
}); |
||
movelevel.append({ |
movelevel.append({ |
||
type: 'option', |
type: 'option', |
||
label: '禁止未 |
label: '禁止未註冊用戶', |
||
value: 'autoconfirmed' |
value: 'autoconfirmed' |
||
}); |
}); |
||
movelevel.append({ |
movelevel.append({ |
||
type: 'option', |
type: 'option', |
||
label: ' |
label: '僅管理員', |
||
value: 'sysop', |
value: 'sysop', |
||
selected: true |
selected: true |
||
行 290: | 行 290: | ||
type: 'select', |
type: 'select', |
||
name: 'moveexpiry', |
name: 'moveexpiry', |
||
label: ' |
label: '終止時間:', |
||
event: function(e) { |
event: function(e) { |
||
if (e.target.value === 'custom') { |
if (e.target.value === 'custom') { |
||
行 297: | 行 297: | ||
}, |
}, |
||
list: [ |
list: [ |
||
{ label: '1小 |
{ label: '1小時', value: '1 hour' }, |
||
{ label: '2小 |
{ label: '2小時', value: '2 hours' }, |
||
{ label: '3小 |
{ label: '3小時', value: '3 hours' }, |
||
{ label: '6小 |
{ label: '6小時', value: '6 hours' }, |
||
{ label: '1日', value: '1 day' }, |
{ label: '1日', value: '1 day' }, |
||
{ label: '3日', value: '3 days' }, |
{ label: '3日', value: '3 days' }, |
||
行 309: | 行 309: | ||
{ label: '6月', value: '6 months' }, |
{ label: '6月', value: '6 months' }, |
||
{ label: '1年', value: '1 year' }, |
{ label: '1年', value: '1 year' }, |
||
{ label: ' |
{ label: '無限期', value: 'indefinite' }, |
||
{ label: '自定 |
{ label: '自定義…', value: 'custom' } |
||
] |
] |
||
}); |
}); |
||
行 317: | 行 317: | ||
type: 'select', |
type: 'select', |
||
name: 'createlevel', |
name: 'createlevel', |
||
label: ' |
label: '創建權限:', |
||
event: Twinkle.protect.formevents.createlevel |
event: Twinkle.protect.formevents.createlevel |
||
}); |
}); |
||
行 327: | 行 327: | ||
createlevel.append({ |
createlevel.append({ |
||
type: 'option', |
type: 'option', |
||
label: '禁止未 |
label: '禁止未註冊用戶', |
||
value: 'autoconfirmed' |
value: 'autoconfirmed' |
||
}); |
}); |
||
createlevel.append({ |
createlevel.append({ |
||
type: 'option', |
type: 'option', |
||
label: ' |
label: '僅管理員', |
||
value: 'sysop', |
value: 'sysop', |
||
selected: true |
selected: true |
||
行 339: | 行 339: | ||
type: 'select', |
type: 'select', |
||
name: 'createexpiry', |
name: 'createexpiry', |
||
label: ' |
label: '終止時間:', |
||
event: function(e) { |
event: function(e) { |
||
if (e.target.value === 'custom') { |
if (e.target.value === 'custom') { |
||
行 346: | 行 346: | ||
}, |
}, |
||
list: [ |
list: [ |
||
{ label: '1小 |
{ label: '1小時', value: '1 hour' }, |
||
{ label: '2小 |
{ label: '2小時', value: '2 hours' }, |
||
{ label: '3小 |
{ label: '3小時', value: '3 hours' }, |
||
{ label: '6小 |
{ label: '6小時', value: '6 hours' }, |
||
{ label: '1日', value: '1 day' }, |
{ label: '1日', value: '1 day' }, |
||
{ label: '3日', value: '3 days' }, |
{ label: '3日', value: '3 days' }, |
||
行 358: | 行 358: | ||
{ label: '6月', value: '6 months' }, |
{ label: '6月', value: '6 months' }, |
||
{ label: '1年', selected: true, value: '1 year' }, |
{ label: '1年', selected: true, value: '1 year' }, |
||
{ label: ' |
{ label: '無限期', value: 'indefinite' }, |
||
{ label: '自定 |
{ label: '自定義…', value: 'custom' } |
||
] |
] |
||
}); |
}); |
||
行 366: | 行 366: | ||
type: 'textarea', |
type: 'textarea', |
||
name: 'protectReason', |
name: 'protectReason', |
||
label: '理由(保 |
label: '理由(保護日誌):' |
||
}); |
}); |
||
if (!mw.config.get('wgArticleId')) { // tagging isn't relevant for non-existing pages |
if (!mw.config.get('wgArticleId')) { // tagging isn't relevant for non-existing pages |
||
行 373: | 行 373: | ||
/* falls through */ |
/* falls through */ |
||
case 'tag': |
case 'tag': |
||
field1 = new Morebits.quickForm.element({ type: 'field', label: ' |
field1 = new Morebits.quickForm.element({ type: 'field', label: '標記選項', name: 'field1' }); |
||
field1.append( { |
field1.append( { |
||
type: 'select', |
type: 'select', |
||
name: 'tagtype', |
name: 'tagtype', |
||
label: ' |
label: '選擇保護模板:', |
||
list: Twinkle.protect.protectionTags, |
list: Twinkle.protect.protectionTags, |
||
event: Twinkle.protect.formevents.tagtype |
event: Twinkle.protect.formevents.tagtype |
||
行 386: | 行 386: | ||
{ |
{ |
||
name: 'small', |
name: 'small', |
||
label: '使用 |
label: '使用圖標(small=yes)', |
||
tooltip: ' |
tooltip: '將給模板加上|small=yes參數,顯示成右上角的一把掛鎖。' |
||
}, |
}, |
||
{ |
{ |
||
name: 'noinclude', |
name: 'noinclude', |
||
label: '用<noinclude>包裹保 |
label: '用<noinclude>包裹保護模板', |
||
tooltip: ' |
tooltip: '將保護模板包裹在<noinclude>中', |
||
checked: (mw.config.get('wgNamespaceNumber') === 10) |
checked: (mw.config.get('wgNamespaceNumber') === 10) |
||
} |
} |
||
行 400: | 行 400: | ||
case 'request': |
case 'request': |
||
field_preset = new Morebits.quickForm.element({ type: 'field', label: '保 |
field_preset = new Morebits.quickForm.element({ type: 'field', label: '保護類型', name: 'field_preset' }); |
||
field_preset.append({ |
field_preset.append({ |
||
type: 'select', |
type: 'select', |
||
name: 'category', |
name: 'category', |
||
label: ' |
label: '類型和理由:', |
||
event: Twinkle.protect.callback.changePreset, |
event: Twinkle.protect.callback.changePreset, |
||
list: (mw.config.get('wgArticleId') ? Twinkle.protect.protectionTypes : Twinkle.protect.protectionTypesCreate) |
list: (mw.config.get('wgArticleId') ? Twinkle.protect.protectionTypes : Twinkle.protect.protectionTypesCreate) |
||
}); |
}); |
||
field1 = new Morebits.quickForm.element({ type: 'field', label: ' |
field1 = new Morebits.quickForm.element({ type: 'field', label: '選項', name: 'field1' }); |
||
field1.append( { |
field1.append( { |
||
type: 'select', |
type: 'select', |
||
name: 'expiry', |
name: 'expiry', |
||
label: ' |
label: '時長:', |
||
list: [ |
list: [ |
||
{ label: ' |
{ label: '臨時', value: 'temporary' }, |
||
{ label: '永久', value: 'indefinite' }, |
{ label: '永久', value: 'indefinite' }, |
||
{ label: '', selected: true, value: '' } |
{ label: '', selected: true, value: '' } |
||
行 427: | 行 427: | ||
break; |
break; |
||
default: |
default: |
||
alert(" |
alert("這玩意兒壞掉了!"); |
||
break; |
break; |
||
} |
} |
||
行 460: | 行 460: | ||
if (Twinkle.protect.protectionLevel) { |
if (Twinkle.protect.protectionLevel) { |
||
Morebits.status.init($('div[name="currentprot"] span').last()[0]); |
Morebits.status.init($('div[name="currentprot"] span').last()[0]); |
||
Morebits.status.info(" |
Morebits.status.info("當前保護等級", Twinkle.protect.protectionLevel); |
||
} |
} |
||
行 494: | 行 494: | ||
Twinkle.protect.doCustomExpiry = function twinkleprotectDoCustomExpiry(target) { |
Twinkle.protect.doCustomExpiry = function twinkleprotectDoCustomExpiry(target) { |
||
var custom = prompt(' |
var custom = prompt('輸入自定義終止時間。\n您可以使用相對時間,如「1 minute」或「19 days」,或絕對時間「yyyymmddhhmm」(如「200602011405」是2006年02月01日14:05(UTC))', ''); |
||
if (custom) { |
if (custom) { |
||
var option = document.createElement('option'); |
var option = document.createElement('option'); |
||
行 507: | 行 507: | ||
Twinkle.protect.protectionTypes = [ |
Twinkle.protect.protectionTypes = [ |
||
{ label: '解除保 |
{ label: '解除保護', value: 'unprotect' }, |
||
{ |
{ |
||
label: '全保 |
label: '全保護', |
||
list: [ |
list: [ |
||
{ label: '常 |
{ label: '常規(全)', value: 'pp-protected' }, |
||
{ label: ' |
{ label: '爭議、編輯戰(全)', value: 'pp-dispute' }, |
||
{ label: ' |
{ label: '長期破壞(全)', value: 'pp-vandalism' }, |
||
{ label: '高 |
{ label: '高風險模板(全)', value: 'pp-template' }, |
||
{ label: '已封禁用 |
{ label: '已封禁用戶的討論頁(全)', value: 'pp-usertalk' } |
||
] |
] |
||
}, |
}, |
||
{ |
{ |
||
label: '半保 |
label: '半保護', |
||
list: [ |
list: [ |
||
{ label: '常 |
{ label: '常規(半)', value: 'pp-semi-protected' }, |
||
{ label: ' |
{ label: '長期破壞(半)', value: 'pp-semi-vandalism' }, |
||
{ label: ' |
{ label: '違反生者傳記方針(半)', value: 'pp-semi-blp' }, |
||
{ label: '傀儡破 |
{ label: '傀儡破壞(半)', value: 'pp-semi-sock' }, |
||
{ label: '高 |
{ label: '高風險模板(半)', value: 'pp-semi-template' }, |
||
{ label: '已封禁用 |
{ label: '已封禁用戶的討論頁(半)', value: 'pp-semi-usertalk' } |
||
] |
] |
||
}, |
}, |
||
{ |
{ |
||
label: '移 |
label: '移動保護', |
||
list: [ |
list: [ |
||
{ label: '常 |
{ label: '常規(移動)', value: 'pp-move' }, |
||
{ label: ' |
{ label: '爭議、移動戰(移動)', value: 'pp-move-dispute' }, |
||
{ label: '移 |
{ label: '移動破壞(移動)', value: 'pp-move-vandalism' }, |
||
{ label: '高 |
{ label: '高風險頁面(移動)', value: 'pp-move-indef' } |
||
] |
] |
||
} |
} |
||
行 543: | 行 543: | ||
Twinkle.protect.protectionTypesCreate = [ |
Twinkle.protect.protectionTypesCreate = [ |
||
{ label: '解除保 |
{ label: '解除保護', value: 'unprotect' }, |
||
{ |
{ |
||
label: '白 |
label: '白紙保護', |
||
list: [ |
list: [ |
||
{ label: '常 |
{ label: '常規', value: 'pp-create' } |
||
] |
] |
||
} |
} |
||
行 562: | 行 562: | ||
edit: 'sysop', |
edit: 'sysop', |
||
move: 'sysop', |
move: 'sysop', |
||
reason: ' |
reason: '編輯戰' |
||
}, |
}, |
||
'pp-vandalism': { |
'pp-vandalism': { |
||
edit: 'sysop', |
edit: 'sysop', |
||
move: 'sysop', |
move: 'sysop', |
||
reason: '被自 |
reason: '被自動確認用戶破壞' |
||
}, |
}, |
||
'pp-template': { |
'pp-template': { |
||
edit: 'sysop', |
edit: 'sysop', |
||
move: 'sysop', |
move: 'sysop', |
||
reason: '高 |
reason: '高風險模板' |
||
}, |
}, |
||
'pp-usertalk': { |
'pp-usertalk': { |
||
edit: 'sysop', |
edit: 'sysop', |
||
move: 'sysop', |
move: 'sysop', |
||
reason: '已封禁用 |
reason: '已封禁用戶濫用其對話頁' |
||
}, |
}, |
||
'pp-semi-vandalism': { |
'pp-semi-vandalism': { |
||
edit: 'autoconfirmed', |
edit: 'autoconfirmed', |
||
reason: '被IP用 |
reason: '被IP用戶或新用戶破壞', |
||
template: 'pp-vandalism' |
template: 'pp-vandalism' |
||
}, |
}, |
||
'pp-semi-blp': { |
'pp-semi-blp': { |
||
edit: 'autoconfirmed', |
edit: 'autoconfirmed', |
||
reason: 'IP用 |
reason: 'IP用戶或新用戶違反生者傳記方針' |
||
}, |
}, |
||
'pp-semi-usertalk': { |
'pp-semi-usertalk': { |
||
edit: 'autoconfirmed', |
edit: 'autoconfirmed', |
||
move: 'sysop', |
move: 'sysop', |
||
reason: '已封禁用 |
reason: '已封禁用戶濫用其對話頁' |
||
}, |
}, |
||
'pp-semi-template': { // removed for now |
'pp-semi-template': { // removed for now |
||
edit: 'autoconfirmed', |
edit: 'autoconfirmed', |
||
move: 'sysop', |
move: 'sysop', |
||
reason: '高 |
reason: '高風險模板', |
||
template: 'pp-template' |
template: 'pp-template' |
||
}, |
}, |
||
'pp-semi-sock': { |
'pp-semi-sock': { |
||
edit: 'autoconfirmed', |
edit: 'autoconfirmed', |
||
reason: '持 |
reason: '持續的傀儡破壞' |
||
}, |
}, |
||
'pp-semi-protected': { |
'pp-semi-protected': { |
||
行 614: | 行 614: | ||
'pp-move-dispute': { |
'pp-move-dispute': { |
||
move: 'sysop', |
move: 'sysop', |
||
reason: ' |
reason: '頁面移動戰' |
||
}, |
}, |
||
'pp-move-vandalism': { |
'pp-move-vandalism': { |
||
move: 'sysop', |
move: 'sysop', |
||
reason: '移 |
reason: '移動破壞' |
||
}, |
}, |
||
'pp-move-indef': { |
'pp-move-indef': { |
||
move: 'sysop', |
move: 'sysop', |
||
reason: '高 |
reason: '高風險頁面' |
||
}, |
}, |
||
'unprotect': { |
'unprotect': { |
||
行 639: | 行 639: | ||
Twinkle.protect.protectionTags = [ |
Twinkle.protect.protectionTags = [ |
||
{ |
{ |
||
label: ' |
label: '無(移除現有模板)', |
||
value: 'none' |
value: 'none' |
||
}, |
}, |
||
{ |
{ |
||
label: ' |
label: '無(不移除現有模板)', |
||
value: 'noop' |
value: 'noop' |
||
}, |
}, |
||
{ |
{ |
||
label: '全保 |
label: '全保護模板', |
||
list: [ |
list: [ |
||
{ label: '{{pp-dispute}}: |
{ label: '{{pp-dispute}}: 爭議', value: 'pp-dispute', selected: true }, |
||
{ label: '{{pp-usertalk}}: 封禁的用 |
{ label: '{{pp-usertalk}}: 封禁的用戶', value: 'pp-usertalk' } |
||
] |
] |
||
}, |
}, |
||
{ |
{ |
||
label: '全、半保 |
label: '全、半保護模板', |
||
list: [ |
list: [ |
||
{ label: '{{pp-vandalism}}: 破 |
{ label: '{{pp-vandalism}}: 破壞', value: 'pp-vandalism' }, |
||
{ label: '{{pp-template}}: 高 |
{ label: '{{pp-template}}: 高風險模板', value: 'pp-template' }, |
||
{ label: '{{pp-protected}}: 常 |
{ label: '{{pp-protected}}: 常規', value: 'pp-protected' } |
||
] |
] |
||
}, |
}, |
||
{ |
{ |
||
label: '半保 |
label: '半保護模板', |
||
list: [ |
list: [ |
||
{ label: '{{pp-semi-usertalk}}: 封禁的用 |
{ label: '{{pp-semi-usertalk}}: 封禁的用戶', value: 'pp-semi-usertalk' }, |
||
{ label: '{{pp-semi-sock}}: 傀儡', value: 'pp-semi-sock' }, |
{ label: '{{pp-semi-sock}}: 傀儡', value: 'pp-semi-sock' }, |
||
{ label: '{{pp-semi-blp}}: 生者 |
{ label: '{{pp-semi-blp}}: 生者傳記', value: 'pp-semi-blp' }, |
||
{ label: '{{pp-semi-indef}}: |
{ label: '{{pp-semi-indef}}: 長期', value: 'pp-semi-indef' } |
||
] |
] |
||
}, |
}, |
||
{ |
{ |
||
label: '移 |
label: '移動保護模板', |
||
list: [ |
list: [ |
||
{ label: '{{pp-move-dispute}}: |
{ label: '{{pp-move-dispute}}: 爭議', value: 'pp-move-dispute' }, |
||
{ label: '{{pp-move-vandalism}}: 破 |
{ label: '{{pp-move-vandalism}}: 破壞', value: 'pp-move-vandalism' }, |
||
{ label: '{{pp-move-indef}}: |
{ label: '{{pp-move-indef}}: 長期', value: 'pp-move-indef' }, |
||
{ label: '{{pp-move}}: 常 |
{ label: '{{pp-move}}: 常規', value: 'pp-move' } |
||
] |
] |
||
} |
} |
||
行 795: | 行 795: | ||
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName'); |
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName'); |
||
Morebits.wiki.actionCompleted.notice = "保 |
Morebits.wiki.actionCompleted.notice = "保護完成"; |
||
var statusInited = false; |
var statusInited = false; |
||
行 810: | 行 810: | ||
var protectIt = function twinkleprotectCallbackProtectIt(next) { |
var protectIt = function twinkleprotectCallbackProtectIt(next) { |
||
thispage = new Morebits.wiki.page(mw.config.get('wgPageName'), "保 |
thispage = new Morebits.wiki.page(mw.config.get('wgPageName'), "保護頁面"); |
||
if (mw.config.get('wgArticleId')) { |
if (mw.config.get('wgArticleId')) { |
||
if (form.editmodify.checked) { |
if (form.editmodify.checked) { |
||
行 826: | 行 826: | ||
thispage.setEditSummary(form.protectReason.value + Twinkle.getPref('protectionSummaryAd')); |
thispage.setEditSummary(form.protectReason.value + Twinkle.getPref('protectionSummaryAd')); |
||
} else { |
} else { |
||
alert("您必 |
alert("您必須輸入保護理由,這將被記錄在保護日誌中。"); |
||
return; |
return; |
||
} |
} |
||
行 843: | 行 843: | ||
protectIt(allDone); |
protectIt(allDone); |
||
} else { |
} else { |
||
alert(" |
alert("請告訴Twinkle要做什麼!\n如果您只是想標記該頁,請選擇上面的「用保護模板標記此頁」選項。"); |
||
} |
} |
||
行 856: | 行 856: | ||
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName'); |
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName'); |
||
Morebits.wiki.actionCompleted.followRedirect = false; |
Morebits.wiki.actionCompleted.followRedirect = false; |
||
Morebits.wiki.actionCompleted.notice = " |
Morebits.wiki.actionCompleted.notice = "標記完成"; |
||
Twinkle.protect.callbacks.taggingPageInitial(tagparams); |
Twinkle.protect.callbacks.taggingPageInitial(tagparams); |
||
行 870: | 行 870: | ||
case 'pp-usertalk': |
case 'pp-usertalk': |
||
case 'pp-protected': |
case 'pp-protected': |
||
typename = '全保 |
typename = '全保護'; |
||
break; |
break; |
||
case 'pp-semi-vandalism': |
case 'pp-semi-vandalism': |
||
行 878: | 行 878: | ||
case 'pp-semi-blp': |
case 'pp-semi-blp': |
||
case 'pp-semi-protected': |
case 'pp-semi-protected': |
||
typename = '半保 |
typename = '半保護'; |
||
break; |
break; |
||
case 'pp-move': |
case 'pp-move': |
||
行 884: | 行 884: | ||
case 'pp-move-indef': |
case 'pp-move-indef': |
||
case 'pp-move-vandalism': |
case 'pp-move-vandalism': |
||
typename = '移 |
typename = '移動保護'; |
||
break; |
break; |
||
case 'pp-create': |
case 'pp-create': |
||
行 890: | 行 890: | ||
case 'pp-create-blp': |
case 'pp-create-blp': |
||
case 'pp-create-salt': |
case 'pp-create-salt': |
||
typename = '白 |
typename = '白紙保護'; |
||
break; |
break; |
||
case 'unprotect': |
case 'unprotect': |
||
/* falls through */ |
/* falls through */ |
||
default: |
default: |
||
typename = '解除保 |
typename = '解除保護'; |
||
break; |
break; |
||
} |
} |
||
switch (form.category.value) { |
switch (form.category.value) { |
||
case 'pp-dispute': |
case 'pp-dispute': |
||
typereason = ' |
typereason = '爭議、編輯戰'; |
||
break; |
break; |
||
case 'pp-vandalism': |
case 'pp-vandalism': |
||
case 'pp-semi-vandalism': |
case 'pp-semi-vandalism': |
||
typereason = ' |
typereason = '長期破壞'; |
||
break; |
break; |
||
case 'pp-template': |
case 'pp-template': |
||
case 'pp-semi-template': // removed for now |
case 'pp-semi-template': // removed for now |
||
typereason = '高 |
typereason = '高風險模板'; |
||
break; |
break; |
||
case 'pp-usertalk': |
case 'pp-usertalk': |
||
case 'pp-semi-usertalk': |
case 'pp-semi-usertalk': |
||
typereason = '已封禁用 |
typereason = '已封禁用戶的討論頁'; |
||
break; |
break; |
||
case 'pp-semi-sock': |
case 'pp-semi-sock': |
||
typereason = '傀儡破 |
typereason = '傀儡破壞'; |
||
break; |
break; |
||
case 'pp-semi-blp': |
case 'pp-semi-blp': |
||
typereason = ' |
typereason = '違反生者傳記方針'; |
||
break; |
break; |
||
case 'pp-move-dispute': |
case 'pp-move-dispute': |
||
typereason = ' |
typereason = '爭議、移動戰'; |
||
break; |
break; |
||
case 'pp-move-vandalism': |
case 'pp-move-vandalism': |
||
typereason = '移 |
typereason = '移動破壞'; |
||
break; |
break; |
||
case 'pp-move-indef': |
case 'pp-move-indef': |
||
typereason = '高 |
typereason = '高風險頁面'; |
||
break; |
break; |
||
default: |
default: |
||
行 955: | 行 955: | ||
Morebits.status.init( form ); |
Morebits.status.init( form ); |
||
var rppName = 'Wikipedia: |
var rppName = 'Wikipedia:請求保護頁面'; |
||
// Updating data for the action completed event |
// Updating data for the action completed event |
||
Morebits.wiki.actionCompleted.redirect = rppName; |
Morebits.wiki.actionCompleted.redirect = rppName; |
||
Morebits.wiki.actionCompleted.notice = "提名完成,重定向到 |
Morebits.wiki.actionCompleted.notice = "提名完成,重定向到討論頁"; |
||
var rppPage = new Morebits.wiki.page( rppName, ' |
var rppPage = new Morebits.wiki.page( rppName, '請求保護頁面'); |
||
rppPage.setFollowRedirect( true ); |
rppPage.setFollowRedirect( true ); |
||
rppPage.setCallbackParameters( rppparams ); |
rppPage.setCallbackParameters( rppparams ); |
||
行 967: | 行 967: | ||
break; |
break; |
||
default: |
default: |
||
alert("twinkleprotect: 未知操作 |
alert("twinkleprotect: 未知操作類型"); |
||
break; |
break; |
||
} |
} |
||
行 975: | 行 975: | ||
taggingPageInitial: function( tagparams ) { |
taggingPageInitial: function( tagparams ) { |
||
if (tagparams.tag === 'noop') { |
if (tagparams.tag === 'noop') { |
||
Morebits.status.info(" |
Morebits.status.info("應用保護模板", "沒什麼要做的"); |
||
return; |
return; |
||
} |
} |
||
var protectedPage = new Morebits.wiki.page( mw.config.get('wgPageName'), ' |
var protectedPage = new Morebits.wiki.page( mw.config.get('wgPageName'), '標記頁面'); |
||
protectedPage.setCallbackParameters( tagparams ); |
protectedPage.setCallbackParameters( tagparams ); |
||
protectedPage.load( Twinkle.protect.callbacks.taggingPage ); |
protectedPage.load( Twinkle.protect.callbacks.taggingPage ); |
||
行 991: | 行 991: | ||
var re_result = oldtag_re.exec(text); |
var re_result = oldtag_re.exec(text); |
||
if (re_result) { |
if (re_result) { |
||
if (confirm("在 |
if (confirm("在頁面上找到{{" + re_result[1] + "}}\n點擊確定以移除,或點擊取消以取消。")) { |
||
text = text.replace( oldtag_re, '' ); |
text = text.replace( oldtag_re, '' ); |
||
} |
} |
||
行 1,010: | 行 1,010: | ||
if( params.tag === 'none' ) { |
if( params.tag === 'none' ) { |
||
summary = '移除保 |
summary = '移除保護模板' + Twinkle.getPref('summaryAd'); |
||
} else { |
} else { |
||
if( params.noinclude ) { |
if( params.noinclude ) { |
||
行 1,043: | 行 1,043: | ||
if ( tag ) { |
if ( tag ) { |
||
statusElement.error( [ '已有 |
statusElement.error( [ '已有對此條目的保護提名,在 ', rppLink, ',取消操作。' ] ); |
||
return; |
return; |
||
} |
} |
||
行 1,049: | 行 1,049: | ||
var newtag = '=== [[:' + mw.config.get('wgPageName') + ']] ===' + "\n"; |
var newtag = '=== [[:' + mw.config.get('wgPageName') + ']] ===' + "\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( [ '已有 |
statusElement.error( [ '已有對此條目的保護提名,在 ', rppLink, ',取消操作。' ] ); |
||
return; |
return; |
||
} |
} |
||
行 1,056: | 行 1,056: | ||
switch( params.expiry ) { |
switch( params.expiry ) { |
||
case 'temporary': |
case 'temporary': |
||
words = " |
words = "臨時"; |
||
break; |
break; |
||
case 'indefinite': |
case 'indefinite': |
||
行 1,068: | 行 1,068: | ||
words += params.typename; |
words += params.typename; |
||
newtag += " |
newtag += "請求" + Morebits.string.toUpperCaseFirstChar(words) + ( params.reason !== '' ? ":" + |
||
Morebits.string.formatReasonText(params.reason) : "。" ) + "--~~~~"; |
Morebits.string.formatReasonText(params.reason) : "。" ) + "--~~~~"; |
||
行 1,074: | 行 1,074: | ||
if ( params.category === 'unprotect' ) { |
if ( params.category === 'unprotect' ) { |
||
reg = /(==\s* |
reg = /(==\s*請求解除保護\s*==\n)/; |
||
} else { |
} else { |
||
reg = /({{\/header}}\n)/; |
reg = /({{\/header}}\n)/; |
||
行 1,083: | 行 1,083: | ||
{ |
{ |
||
var linknode = document.createElement('a'); |
var linknode = document.createElement('a'); |
||
linknode.setAttribute("href", mw.util.getUrl("Wikipedia:Twinkle/修 |
linknode.setAttribute("href", mw.util.getUrl("Wikipedia:Twinkle/修復RFPP") ); |
||
linknode.appendChild(document.createTextNode('如何修 |
linknode.appendChild(document.createTextNode('如何修復RFPP')); |
||
statusElement.error( [ ' |
statusElement.error( [ '無法在WP:RFPP上找到相關位點標記,要修復此問題,請參見', linknode, '。' ] ); |
||
return; |
return; |
||
} |
} |
||
statusElement.status( '添加新提名…' ); |
statusElement.status( '添加新提名…' ); |
||
rppPage.setEditSummary( ' |
rppPage.setEditSummary( '請求對[[' + Morebits.pageNameNorm + ']]' + params.typename + Twinkle.getPref('summaryAd') ); |
||
rppPage.setPageText( text ); |
rppPage.setPageText( text ); |
||
rppPage.setCreateOption( 'recreate' ); |
rppPage.setCreateOption( 'recreate' ); |
於 2016年4月10日 (日) 15:27 的最新修訂
//<nowiki>
// vim: set noet sts=0 sw=8:
(function($){
/*
****************************************
*** twinkleprotect.js: Protect/RPP module
****************************************
* Mode of invocation: Tab ("PP"/"RPP")
* Active on: Non-special pages
* Config directives in: TwinkleConfig
*/
// Note: a lot of code in this module is re-used/called by batchprotect.
Twinkle.protect = function twinkleprotect() {
if ( mw.config.get('wgNamespaceNumber') < 0 ) {
return;
}
Twinkle.addPortletLink(Twinkle.protect.callback, Morebits.userIsInGroup('sysop') ? "保護" : "保護", "tw-rpp",
Morebits.userIsInGroup('sysop') ? "保護頁面" : "請求保護頁面" );
};
Twinkle.protect.callback = function twinkleprotectCallback() {
Twinkle.protect.protectionLevel = null;
var Window = new Morebits.simpleWindow( 620, 530 );
Window.setTitle( Morebits.userIsInGroup( 'sysop' ) ? "施行或請求保護頁面" : "請求保護頁面" );
Window.setScriptName( "Twinkle" );
Window.addFooterLink( "保護模板", "Template:Protection templates" );
Window.addFooterLink( "保護方針", "WP:PROT" );
Window.addFooterLink( "Twinkle幫助", "WP:TW/DOC#protect" );
var form = new Morebits.quickForm( Twinkle.protect.callback.evaluate );
var actionfield = form.append( {
type: 'field',
label: '操作類型'
} );
if( Morebits.userIsInGroup( 'sysop' ) ) {
actionfield.append( {
type: 'radio',
name: 'actiontype',
event: Twinkle.protect.callback.changeAction,
list: [
{
label: '保護頁面',
value: 'protect',
checked: true
}
]
} );
}
actionfield.append( {
type: 'radio',
name: 'actiontype',
event: Twinkle.protect.callback.changeAction,
list: [
{
label: '請求保護頁面',
value: 'request',
tooltip: '如果您想在WP:RFPP請求保護此頁' + (Morebits.userIsInGroup('sysop') ? '而不是自行完成。' : '。'),
checked: !Morebits.userIsInGroup('sysop')
},
{
label: '用保護模板標記此頁',
value: 'tag',
tooltip: '可以用此為頁面加上合適的保護模板。',
disabled: mw.config.get('wgArticleId') === 0
}
]
} );
form.append({ type: 'field', label: '預設', name: 'field_preset' });
form.append({ type: 'field', label: '1', name: 'field1' });
form.append({ type: 'field', label: '2', name: 'field2' });
form.append( { type:'submit' } );
var result = form.render();
Window.setContent( result );
Window.display();
// We must init the controls
var evt = document.createEvent( "Event" );
evt.initEvent( 'change', true, true );
result.actiontype[0].dispatchEvent( evt );
// get current protection level asynchronously
if (Morebits.userIsInGroup('sysop')) {
Morebits.wiki.actionCompleted.postfix = false; // avoid Action: completed notice
Morebits.status.init($('div[name="currentprot"] span').last()[0]);
}
Twinkle.protect.fetchProtectionLevel();
};
// Current protection level in a human-readable format
// (a string, or null if no protection; only filled for sysops)
Twinkle.protect.protectionLevel = null;
// 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();
api.get({
format: 'json',
indexpageids: true,
action: 'query',
prop: 'info',
inprop: 'protection',
titles: mw.config.get('wgPageName')
})
.done(function(data){
var pageid = data.query.pageids[0];
var page = data.query.pages[pageid];
var result = [];
var current = {};
var updateResult = function(label, level, expiry, cascade) {
// for sysops, stringify, so they can base their decision on existing protection
if (Morebits.userIsInGroup('sysop')) {
var boldnode = document.createElement('b');
boldnode.textContent = label + ":" + level;
result.push(boldnode);
if (expiry === 'infinity') {
result.push("(無限期)");
} else {
result.push("(過期:" + new Date(expiry).toUTCString() + ")");
}
if (cascade) {
result.push("(聯鎖)");
}
}
};
$.each(page.protection, function( index, protection ) {
if (protection.type !== "aft") {
current[protection.type] = {
level: protection.level,
expiry: protection.expiry,
cascade: protection.cascade === ''
};
updateResult( Morebits.string.toUpperCaseFirstChar(protection.type), protection.level, protection.expiry, protection.cascade );
}
});
// show the protection level to sysops
if (Morebits.userIsInGroup('sysop')) {
if (!result.length) {
var boldnode = document.createElement('b');
boldnode.textContent = "無保護";
result.push(boldnode);
}
Twinkle.protect.protectionLevel = result;
Morebits.status.init($('div[name="currentprot"] span').last()[0]);
Morebits.status.info("當前保護等級", Twinkle.protect.protectionLevel);
}
Twinkle.protect.currentProtectionLevels = current;
});
};
Twinkle.protect.callback.changeAction = function twinkleprotectCallbackChangeAction(e) {
var field_preset;
var field1;
var field2;
var isTemplate = mw.config.get("wgNamespaceNumber") === 10 || mw.config.get("wgNamespaceNumber") === 828;
switch (e.target.values) {
case 'protect':
field_preset = new Morebits.quickForm.element({ type: 'field', label: '預設', name: 'field_preset' });
field_preset.append({
type: 'select',
name: 'category',
label: '選擇預設:',
event: Twinkle.protect.callback.changePreset,
list: (mw.config.get('wgArticleId') ?
Twinkle.protect.protectionTypes :
Twinkle.protect.protectionTypesCreate)
});
field2 = new Morebits.quickForm.element({ type: 'field', label: '保護選項', name: 'field2' });
field2.append({ type: 'div', name: 'currentprot', label: ' ' }); // holds the current protection level, as filled out by the async callback
// for existing pages
if (mw.config.get('wgArticleId')) {
field2.append({
type: 'checkbox',
name: 'editmodify',
event: Twinkle.protect.formevents.editmodify,
list: [
{
label: '修改編輯權限',
value: 'editmodify',
tooltip: '如果此項被關閉,編輯權限將不被修改。',
checked: true
}
]
});
var editlevel = field2.append({
type: 'select',
name: 'editlevel',
label: '編輯權限:',
event: Twinkle.protect.formevents.editlevel
});
editlevel.append({
type: 'option',
label: '(站點默認)',
value: 'all'
});
editlevel.append({
type: 'option',
label: '禁止未註冊用戶',
value: 'autoconfirmed'
});
editlevel.append({
type: 'option',
label: '僅管理員',
value: 'sysop',
selected: true
});
field2.append({
type: 'select',
name: 'editexpiry',
label: '終止時間:',
event: function(e) {
if (e.target.value === 'custom') {
Twinkle.protect.doCustomExpiry(e.target);
}
$('input[name=small]', $(e.target).closest('form'))[0].checked = (e.target.selectedIndex >= 8); // 1 month
},
list: [
{ label: '1小時', value: '1 hour' },
{ label: '2小時', value: '2 hours' },
{ label: '3小時', value: '3 hours' },
{ label: '6小時', value: '6 hours' },
{ label: '1日', value: '1 day' },
{ label: '3日', value: '3 days' },
{ label: '1周', selected: true, value: '1 week' },
{ label: '2周', value: '2 weeks' },
{ label: '1月', value: '1 month' },
{ label: '3月', value: '3 months' },
{ label: '6月', value: '6 months' },
{ label: '1年', value: '1 year' },
{ label: '無限期', value: 'indefinite' },
{ label: '自定義…', value: 'custom' }
]
});
field2.append({
type: 'checkbox',
name: 'movemodify',
event: Twinkle.protect.formevents.movemodify,
list: [
{
label: '修改移動權限',
value: 'movemodify',
tooltip: '如果此項被關閉,移動權限將不被修改。',
checked: true
}
]
});
var movelevel = field2.append({
type: 'select',
name: 'movelevel',
label: '移動權限:',
event: Twinkle.protect.formevents.movelevel
});
movelevel.append({
type: 'option',
label: '(站點默認)',
value: 'all'
});
movelevel.append({
type: 'option',
label: '禁止未註冊用戶',
value: 'autoconfirmed'
});
movelevel.append({
type: 'option',
label: '僅管理員',
value: 'sysop',
selected: true
});
field2.append({
type: 'select',
name: 'moveexpiry',
label: '終止時間:',
event: function(e) {
if (e.target.value === 'custom') {
Twinkle.protect.doCustomExpiry(e.target);
}
},
list: [
{ label: '1小時', value: '1 hour' },
{ label: '2小時', value: '2 hours' },
{ label: '3小時', value: '3 hours' },
{ label: '6小時', value: '6 hours' },
{ label: '1日', value: '1 day' },
{ label: '3日', value: '3 days' },
{ label: '1周', value: '1 week' },
{ label: '2周', value: '2 weeks' },
{ label: '1月', selected: true, value: '1 month' },
{ label: '3月', value: '3 months' },
{ label: '6月', value: '6 months' },
{ label: '1年', value: '1 year' },
{ label: '無限期', value: 'indefinite' },
{ label: '自定義…', value: 'custom' }
]
});
} else { // for non-existing pages
var createlevel = field2.append({
type: 'select',
name: 'createlevel',
label: '創建權限:',
event: Twinkle.protect.formevents.createlevel
});
createlevel.append({
type: 'option',
label: '全部',
value: 'all'
});
createlevel.append({
type: 'option',
label: '禁止未註冊用戶',
value: 'autoconfirmed'
});
createlevel.append({
type: 'option',
label: '僅管理員',
value: 'sysop',
selected: true
});
field2.append({
type: 'select',
name: 'createexpiry',
label: '終止時間:',
event: function(e) {
if (e.target.value === 'custom') {
Twinkle.protect.doCustomExpiry(e.target);
}
},
list: [
{ label: '1小時', value: '1 hour' },
{ label: '2小時', value: '2 hours' },
{ label: '3小時', value: '3 hours' },
{ label: '6小時', value: '6 hours' },
{ label: '1日', value: '1 day' },
{ label: '3日', value: '3 days' },
{ label: '1周', value: '1 week' },
{ label: '2周', value: '2 weeks' },
{ label: '1月', value: '1 month' },
{ label: '3月', value: '3 months' },
{ label: '6月', value: '6 months' },
{ label: '1年', selected: true, value: '1 year' },
{ label: '無限期', value: 'indefinite' },
{ label: '自定義…', value: 'custom' }
]
});
}
field2.append({
type: 'textarea',
name: 'protectReason',
label: '理由(保護日誌):'
});
if (!mw.config.get('wgArticleId')) { // tagging isn't relevant for non-existing pages
break;
}
/* falls through */
case 'tag':
field1 = new Morebits.quickForm.element({ type: 'field', label: '標記選項', name: 'field1' });
field1.append( {
type: 'select',
name: 'tagtype',
label: '選擇保護模板:',
list: Twinkle.protect.protectionTags,
event: Twinkle.protect.formevents.tagtype
} );
field1.append( {
type: 'checkbox',
list: [
{
name: 'small',
label: '使用圖標(small=yes)',
tooltip: '將給模板加上|small=yes參數,顯示成右上角的一把掛鎖。'
},
{
name: 'noinclude',
label: '用<noinclude>包裹保護模板',
tooltip: '將保護模板包裹在<noinclude>中',
checked: (mw.config.get('wgNamespaceNumber') === 10)
}
]
} );
break;
case 'request':
field_preset = new Morebits.quickForm.element({ type: 'field', label: '保護類型', name: 'field_preset' });
field_preset.append({
type: 'select',
name: 'category',
label: '類型和理由:',
event: Twinkle.protect.callback.changePreset,
list: (mw.config.get('wgArticleId') ? Twinkle.protect.protectionTypes : Twinkle.protect.protectionTypesCreate)
});
field1 = new Morebits.quickForm.element({ type: 'field', label: '選項', name: 'field1' });
field1.append( {
type: 'select',
name: 'expiry',
label: '時長:',
list: [
{ label: '臨時', value: 'temporary' },
{ label: '永久', value: 'indefinite' },
{ label: '', selected: true, value: '' }
]
} );
field1.append({
type: 'textarea',
name: 'reason',
label: '理由:'
});
break;
default:
alert("這玩意兒壞掉了!");
break;
}
var oldfield;
if (field_preset) {
oldfield = $(e.target.form).find('fieldset[name="field_preset"]')[0];
oldfield.parentNode.replaceChild(field_preset.render(), oldfield);
} else {
$(e.target.form).find('fieldset[name="field_preset"]').css('display', 'none');
}
if (field1) {
oldfield = $(e.target.form).find('fieldset[name="field1"]')[0];
oldfield.parentNode.replaceChild(field1.render(), oldfield);
} else {
$(e.target.form).find('fieldset[name="field1"]').css('display', 'none');
}
if (field2) {
oldfield = $(e.target.form).find('fieldset[name="field2"]')[0];
oldfield.parentNode.replaceChild(field2.render(), oldfield);
} else {
$(e.target.form).find('fieldset[name="field2"]').css('display', 'none');
}
if (e.target.values === 'protect') {
// fake a change event on the preset dropdown
var evt = document.createEvent( "Event" );
evt.initEvent( 'change', true, true );
e.target.form.category.dispatchEvent( evt );
// re-add protection level text, if it's available
if (Twinkle.protect.protectionLevel) {
Morebits.status.init($('div[name="currentprot"] span').last()[0]);
Morebits.status.info("當前保護等級", Twinkle.protect.protectionLevel);
}
// reduce vertical height of dialog
$(e.target.form).find('fieldset[name="field2"] select').parent().css({ display: 'inline-block', marginRight: '0.5em' });
}
};
Twinkle.protect.formevents = {
editmodify: function twinkleprotectFormEditmodifyEvent(e) {
e.target.form.editlevel.disabled = !e.target.checked;
e.target.form.editexpiry.disabled = !e.target.checked || (e.target.form.editlevel.value === 'all');
e.target.form.editlevel.style.color = e.target.form.editexpiry.style.color = (e.target.checked ? "" : "transparent");
},
editlevel: function twinkleprotectFormEditlevelEvent(e) {
e.target.form.editexpiry.disabled = (e.target.value === 'all');
},
movemodify: function twinkleprotectFormMovemodifyEvent(e) {
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.movelevel.style.color = e.target.form.moveexpiry.style.color = (e.target.checked ? "" : "transparent");
},
movelevel: function twinkleprotectFormMovelevelEvent(e) {
e.target.form.moveexpiry.disabled = (e.target.value === 'all');
},
createlevel: function twinkleprotectFormCreatelevelEvent(e) {
e.target.form.createexpiry.disabled = (e.target.value === 'all');
},
tagtype: function twinkleprotectFormTagtypeEvent(e) {
e.target.form.small.disabled = e.target.form.noinclude.disabled = (e.target.value === 'none') || (e.target.value === 'noop');
}
};
Twinkle.protect.doCustomExpiry = function twinkleprotectDoCustomExpiry(target) {
var custom = prompt('輸入自定義終止時間。\n您可以使用相對時間,如「1 minute」或「19 days」,或絕對時間「yyyymmddhhmm」(如「200602011405」是2006年02月01日14:05(UTC))', '');
if (custom) {
var option = document.createElement('option');
option.setAttribute('value', custom);
option.textContent = custom;
target.appendChild(option);
target.value = custom;
} else {
target.selectedIndex = 0;
}
};
Twinkle.protect.protectionTypes = [
{ label: '解除保護', value: 'unprotect' },
{
label: '全保護',
list: [
{ label: '常規(全)', value: 'pp-protected' },
{ label: '爭議、編輯戰(全)', value: 'pp-dispute' },
{ label: '長期破壞(全)', value: 'pp-vandalism' },
{ label: '高風險模板(全)', value: 'pp-template' },
{ label: '已封禁用戶的討論頁(全)', value: 'pp-usertalk' }
]
},
{
label: '半保護',
list: [
{ label: '常規(半)', value: 'pp-semi-protected' },
{ label: '長期破壞(半)', value: 'pp-semi-vandalism' },
{ label: '違反生者傳記方針(半)', value: 'pp-semi-blp' },
{ label: '傀儡破壞(半)', value: 'pp-semi-sock' },
{ label: '高風險模板(半)', value: 'pp-semi-template' },
{ label: '已封禁用戶的討論頁(半)', value: 'pp-semi-usertalk' }
]
},
{
label: '移動保護',
list: [
{ label: '常規(移動)', value: 'pp-move' },
{ label: '爭議、移動戰(移動)', value: 'pp-move-dispute' },
{ label: '移動破壞(移動)', value: 'pp-move-vandalism' },
{ label: '高風險頁面(移動)', value: 'pp-move-indef' }
]
}
];
Twinkle.protect.protectionTypesAdmin = Twinkle.protect.protectionTypes;
Twinkle.protect.protectionTypesCreate = [
{ label: '解除保護', value: 'unprotect' },
{
label: '白紙保護',
list: [
{ label: '常規', value: 'pp-create' }
]
}
];
// NOTICE: keep this synched with [[MediaWiki:Protect-dropdown]]
Twinkle.protect.protectionPresetsInfo = {
'pp-protected': {
edit: 'sysop',
move: 'sysop',
reason: null
},
'pp-dispute': {
edit: 'sysop',
move: 'sysop',
reason: '編輯戰'
},
'pp-vandalism': {
edit: 'sysop',
move: 'sysop',
reason: '被自動確認用戶破壞'
},
'pp-template': {
edit: 'sysop',
move: 'sysop',
reason: '高風險模板'
},
'pp-usertalk': {
edit: 'sysop',
move: 'sysop',
reason: '已封禁用戶濫用其對話頁'
},
'pp-semi-vandalism': {
edit: 'autoconfirmed',
reason: '被IP用戶或新用戶破壞',
template: 'pp-vandalism'
},
'pp-semi-blp': {
edit: 'autoconfirmed',
reason: 'IP用戶或新用戶違反生者傳記方針'
},
'pp-semi-usertalk': {
edit: 'autoconfirmed',
move: 'sysop',
reason: '已封禁用戶濫用其對話頁'
},
'pp-semi-template': { // removed for now
edit: 'autoconfirmed',
move: 'sysop',
reason: '高風險模板',
template: 'pp-template'
},
'pp-semi-sock': {
edit: 'autoconfirmed',
reason: '持續的傀儡破壞'
},
'pp-semi-protected': {
edit: 'autoconfirmed',
reason: null,
template: 'pp-protected'
},
'pp-move': {
move: 'sysop',
reason: null
},
'pp-move-dispute': {
move: 'sysop',
reason: '頁面移動戰'
},
'pp-move-vandalism': {
move: 'sysop',
reason: '移動破壞'
},
'pp-move-indef': {
move: 'sysop',
reason: '高風險頁面'
},
'unprotect': {
edit: 'all',
move: 'all',
create: 'all',
reason: null,
template: 'none'
},
'pp-create': {
create: 'autoconfirmed',
reason: '{{pp-create}}'
}
};
Twinkle.protect.protectionTags = [
{
label: '無(移除現有模板)',
value: 'none'
},
{
label: '無(不移除現有模板)',
value: 'noop'
},
{
label: '全保護模板',
list: [
{ label: '{{pp-dispute}}: 爭議', value: 'pp-dispute', selected: true },
{ label: '{{pp-usertalk}}: 封禁的用戶', value: 'pp-usertalk' }
]
},
{
label: '全、半保護模板',
list: [
{ label: '{{pp-vandalism}}: 破壞', value: 'pp-vandalism' },
{ label: '{{pp-template}}: 高風險模板', value: 'pp-template' },
{ label: '{{pp-protected}}: 常規', value: 'pp-protected' }
]
},
{
label: '半保護模板',
list: [
{ label: '{{pp-semi-usertalk}}: 封禁的用戶', value: 'pp-semi-usertalk' },
{ label: '{{pp-semi-sock}}: 傀儡', value: 'pp-semi-sock' },
{ label: '{{pp-semi-blp}}: 生者傳記', value: 'pp-semi-blp' },
{ label: '{{pp-semi-indef}}: 長期', value: 'pp-semi-indef' }
]
},
{
label: '移動保護模板',
list: [
{ label: '{{pp-move-dispute}}: 爭議', value: 'pp-move-dispute' },
{ label: '{{pp-move-vandalism}}: 破壞', value: 'pp-move-vandalism' },
{ label: '{{pp-move-indef}}: 長期', value: 'pp-move-indef' },
{ label: '{{pp-move}}: 常規', value: 'pp-move' }
]
}
];
Twinkle.protect.callback.changePreset = function twinkleprotectCallbackChangePreset(e) {
var form = e.target.form;
var actiontypes = form.actiontype;
var actiontype;
for( var i = 0; i < actiontypes.length; i++ )
{
if( !actiontypes[i].checked ) {
continue;
}
actiontype = actiontypes[i].values;
break;
}
if (actiontype === 'protect') { // actually protecting the page
var item = Twinkle.protect.protectionPresetsInfo[form.category.value];
if (mw.config.get('wgArticleId')) {
if (item.edit) {
form.editmodify.checked = true;
Twinkle.protect.formevents.editmodify({ target: form.editmodify });
form.editlevel.value = item.edit;
Twinkle.protect.formevents.editlevel({ target: form.editlevel });
} else {
form.editmodify.checked = false;
Twinkle.protect.formevents.editmodify({ target: form.editmodify });
}
if (item.move) {
form.movemodify.checked = true;
Twinkle.protect.formevents.movemodify({ target: form.movemodify });
form.movelevel.value = item.move;
Twinkle.protect.formevents.movelevel({ target: form.movelevel });
} else {
form.movemodify.checked = false;
Twinkle.protect.formevents.movemodify({ target: form.movemodify });
}
} else {
if (item.create) {
form.createlevel.value = item.create;
Twinkle.protect.formevents.createlevel({ target: form.createlevel });
}
}
var reasonField = (actiontype === "protect" ? form.protectReason : form.reason);
if (item.reason) {
reasonField.value = item.reason;
} else {
reasonField.value = '';
}
// sort out tagging options
if (mw.config.get('wgArticleId')) {
if( form.category.value === 'unprotect' ) {
form.tagtype.value = 'none';
} else {
form.tagtype.value = (item.template ? item.template : form.category.value);
}
Twinkle.protect.formevents.tagtype({ target: form.tagtype });
if( /template/.test( form.category.value ) ) {
form.noinclude.checked = true;
form.editexpiry.value = form.moveexpiry.value = "indefinite";
} else if( mw.config.get('wgNamespaceNumber') !== 10 ) {
form.noinclude.checked = false;
}
}
} else { // RPP request
if( form.category.value === 'unprotect' ) {
form.expiry.value = '';
form.expiry.disabled = true;
} else {
form.expiry.disabled = false;
}
}
};
Twinkle.protect.callback.evaluate = function twinkleprotectCallbackEvaluate(e) {
var form = e.target;
var actiontypes = form.actiontype;
var actiontype;
for( var i = 0; i < actiontypes.length; i++ )
{
if( !actiontypes[i].checked ) {
continue;
}
actiontype = actiontypes[i].values;
break;
}
var tagparams;
if( !mw.config.get('wgArticleId') ) {
tagparams = {
tag: 'noop'
};
} else if( actiontype === 'tag' || (actiontype === 'protect' && mw.config.get('wgArticleId')) ) {
tagparams = {
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,
expiry: (actiontype === 'protect') ?
(form.editmodify.checked ? form.editexpiry.value :
(form.movemodify.checked ? form.moveexpiry.value : null)
) : null,
small: form.small.checked,
noinclude: form.noinclude.checked
};
}
switch (actiontype) {
case 'protect':
// protect the page
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
Morebits.wiki.actionCompleted.notice = "保護完成";
var statusInited = false;
var thispage;
var allDone = function twinkleprotectCallbackAllDone() {
if (thispage) {
thispage.getStatusElement().info("完成");
}
if (tagparams) {
Twinkle.protect.callbacks.taggingPageInitial(tagparams);
}
};
var protectIt = function twinkleprotectCallbackProtectIt(next) {
thispage = new Morebits.wiki.page(mw.config.get('wgPageName'), "保護頁面");
if (mw.config.get('wgArticleId')) {
if (form.editmodify.checked) {
thispage.setEditProtection(form.editlevel.value, form.editexpiry.value);
}
if (form.movemodify.checked) {
thispage.setMoveProtection(form.movelevel.value, form.moveexpiry.value);
}
} else {
thispage.setCreateProtection(form.createlevel.value, form.createexpiry.value);
thispage.setWatchlist(false);
}
if (form.protectReason.value) {
thispage.setEditSummary(form.protectReason.value + Twinkle.getPref('protectionSummaryAd'));
} else {
alert("您必須輸入保護理由,這將被記錄在保護日誌中。");
return;
}
if (!statusInited) {
Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.status.init( form );
statusInited = true;
}
thispage.protect(next);
};
if ((form.editmodify && form.editmodify.checked) || (form.movemodify && form.movemodify.checked) ||
!mw.config.get('wgArticleId')) {
protectIt(allDone);
} else {
alert("請告訴Twinkle要做什麼!\n如果您只是想標記該頁,請選擇上面的「用保護模板標記此頁」選項。");
}
break;
case 'tag':
// apply a protection template
Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.status.init( form );
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
Morebits.wiki.actionCompleted.followRedirect = false;
Morebits.wiki.actionCompleted.notice = "標記完成";
Twinkle.protect.callbacks.taggingPageInitial(tagparams);
break;
case 'request':
// file request at RPP
var typename, typereason;
switch( form.category.value ) {
case 'pp-dispute':
case 'pp-vandalism':
case 'pp-template':
case 'pp-usertalk':
case 'pp-protected':
typename = '全保護';
break;
case 'pp-semi-vandalism':
case 'pp-semi-usertalk':
case 'pp-semi-template': // removed for now
case 'pp-semi-sock':
case 'pp-semi-blp':
case 'pp-semi-protected':
typename = '半保護';
break;
case 'pp-move':
case 'pp-move-dispute':
case 'pp-move-indef':
case 'pp-move-vandalism':
typename = '移動保護';
break;
case 'pp-create':
case 'pp-create-offensive':
case 'pp-create-blp':
case 'pp-create-salt':
typename = '白紙保護';
break;
case 'unprotect':
/* falls through */
default:
typename = '解除保護';
break;
}
switch (form.category.value) {
case 'pp-dispute':
typereason = '爭議、編輯戰';
break;
case 'pp-vandalism':
case 'pp-semi-vandalism':
typereason = '長期破壞';
break;
case 'pp-template':
case 'pp-semi-template': // removed for now
typereason = '高風險模板';
break;
case 'pp-usertalk':
case 'pp-semi-usertalk':
typereason = '已封禁用戶的討論頁';
break;
case 'pp-semi-sock':
typereason = '傀儡破壞';
break;
case 'pp-semi-blp':
typereason = '違反生者傳記方針';
break;
case 'pp-move-dispute':
typereason = '爭議、移動戰';
break;
case 'pp-move-vandalism':
typereason = '移動破壞';
break;
case 'pp-move-indef':
typereason = '高風險頁面';
break;
default:
typereason = '';
break;
}
var reason = typereason;
if( form.reason.value !== '') {
if ( typereason !== '' ) {
reason += ":";
}
reason += form.reason.value;
}
if( reason !== '' && reason.charAt( reason.length - 1 ) !== '。' ) {
reason += '。';
}
var rppparams = {
reason: reason,
typename: typename,
category: form.category.value,
expiry: form.expiry.value
};
Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.status.init( form );
var rppName = 'Wikipedia:請求保護頁面';
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = rppName;
Morebits.wiki.actionCompleted.notice = "提名完成,重定向到討論頁";
var rppPage = new Morebits.wiki.page( rppName, '請求保護頁面');
rppPage.setFollowRedirect( true );
rppPage.setCallbackParameters( rppparams );
rppPage.load( Twinkle.protect.callbacks.fileRequest );
break;
default:
alert("twinkleprotect: 未知操作類型");
break;
}
};
Twinkle.protect.callbacks = {
taggingPageInitial: function( tagparams ) {
if (tagparams.tag === 'noop') {
Morebits.status.info("應用保護模板", "沒什麼要做的");
return;
}
var protectedPage = new Morebits.wiki.page( mw.config.get('wgPageName'), '標記頁面');
protectedPage.setCallbackParameters( tagparams );
protectedPage.load( Twinkle.protect.callbacks.taggingPage );
},
taggingPage: function( protectedPage ) {
var params = protectedPage.getCallbackParameters();
var text = protectedPage.getPageText();
var tag, summary;
var oldtag_re = /\s*(?:<noinclude>)?\s*\{\{\s*(pp-[^{}]*?|protected|(?:t|v|s|p-|usertalk-v|usertalk-s|sb|move)protected(?:2)?|protected template|privacy protection)\s*?\}\}\s*(?:<\/noinclude>)?\s*/gi;
var re_result = oldtag_re.exec(text);
if (re_result) {
if (confirm("在頁面上找到{{" + re_result[1] + "}}\n點擊確定以移除,或點擊取消以取消。")) {
text = text.replace( oldtag_re, '' );
}
}
if ( params.tag !== 'none' ) {
tag = params.tag;
if( params.reason ) {
tag += '|reason=' + params.reason;
}
if( ['indefinite', 'infinite', 'never', null].indexOf(params.expiry) === -1 ) {
tag += '|expiry={{subst:#time:c|' + (/^\s*\d+\s*$/.exec(params.expiry) ? params.expiry : '+' + params.expiry) + '}}';
}
if( params.small ) {
tag += '|small=yes';
}
}
if( params.tag === 'none' ) {
summary = '移除保護模板' + Twinkle.getPref('summaryAd');
} else {
if( params.noinclude ) {
text = "<noinclude>{{" + tag + "}}</noinclude>" + text;
} else if( Morebits.wiki.isPageRedirect() ) {
text = text + "\n{{" + tag + "}}";
} else {
text = "{{" + tag + "}}\n" + text;
}
summary = "添加{{" + params.tag + "}}" + Twinkle.getPref('summaryAd');
}
protectedPage.setEditSummary( summary );
protectedPage.setPageText( text );
protectedPage.setCreateOption( 'nocreate' );
protectedPage.suppressProtectWarning(); // no need to let admins know they are editing through protection
protectedPage.save();
},
fileRequest: function( rppPage ) {
var params = rppPage.getCallbackParameters();
var text = rppPage.getPageText();
var statusElement = rppPage.getStatusElement();
var rppRe = new RegExp( '===\\s*(\\[\\[)?\s*:?\s*' + RegExp.escape( Morebits.pageNameNorm, true ) + '\s*(\\]\\])?\\s*===', 'm' );
var tag = rppRe.exec( text );
var rppLink = document.createElement('a');
rppLink.setAttribute('href', mw.util.getUrl(rppPage.getPageName()) );
rppLink.appendChild(document.createTextNode(rppPage.getPageName()));
if ( tag ) {
statusElement.error( [ '已有對此條目的保護提名,在 ', rppLink, ',取消操作。' ] );
return;
}
var newtag = '=== [[:' + mw.config.get('wgPageName') + ']] ===' + "\n";
if( ( new RegExp( '^' + RegExp.escape( newtag ).replace( /\s+/g, '\\s*' ), 'm' ) ).test( text ) ) {
statusElement.error( [ '已有對此條目的保護提名,在 ', rppLink, ',取消操作。' ] );
return;
}
var words;
switch( params.expiry ) {
case 'temporary':
words = "臨時";
break;
case 'indefinite':
words = "永久";
break;
default:
words = "";
break;
}
words += params.typename;
newtag += "請求" + Morebits.string.toUpperCaseFirstChar(words) + ( params.reason !== '' ? ":" +
Morebits.string.formatReasonText(params.reason) : "。" ) + "--~~~~";
var reg;
if ( params.category === 'unprotect' ) {
reg = /(==\s*請求解除保護\s*==\n)/;
} else {
reg = /({{\/header}}\n)/;
}
var originalTextLength = text.length;
text = text.replace( reg, "$1" + newtag + "\n\n");
if (text.length === originalTextLength)
{
var linknode = document.createElement('a');
linknode.setAttribute("href", mw.util.getUrl("Wikipedia:Twinkle/修復RFPP") );
linknode.appendChild(document.createTextNode('如何修復RFPP'));
statusElement.error( [ '無法在WP:RFPP上找到相關位點標記,要修復此問題,請參見', linknode, '。' ] );
return;
}
statusElement.status( '添加新提名…' );
rppPage.setEditSummary( '請求對[[' + Morebits.pageNameNorm + ']]' + params.typename + Twinkle.getPref('summaryAd') );
rppPage.setPageText( text );
rppPage.setCreateOption( 'recreate' );
rppPage.save();
}
};
})(jQuery);
//</nowiki>