「MediaWiki:Gadget-twinkleprotect.js」:修訂間差異

出自竹園Wiki
跳至導覽 跳至搜尋
(已匯入 1 筆修訂:Twinkle)
(繁簡轉換)
 
行 22: 行 22:
}
}


Twinkle.addPortletLink(Twinkle.protect.callback, Morebits.userIsInGroup('sysop') ? "保" : "保", "tw-rpp",
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( "保模板", "Template:Protection templates" );
Window.addFooterLink( "保模板", "Template:Protection templates" );
Window.addFooterLink( "保", "WP:PROT" );
Window.addFooterLink( "保", "WP:PROT" );
Window.addFooterLink( "Twinkle助", "WP:TW/DOC#protect" );
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求保' + (Morebits.userIsInGroup('sysop') ? '而不是自行完成。' : '。'),
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: '预设', name: 'field_preset' });
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("(期:" + new Date(expiry).toUTCString() + ")");
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("前保", Twinkle.protect.protectionLevel);
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: '预设', name: 'field_preset' });
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: '保护选项', name: 'field2' });
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小', value: '1 hour' },
{ label: '1小', value: '1 hour' },
{ label: '2小', value: '2 hours' },
{ label: '2小', value: '2 hours' },
{ label: '3小', value: '3 hours' },
{ label: '3小', value: '3 hours' },
{ label: '6小', value: '6 hours' },
{ 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: '限期', value: 'indefinite' },
{ label: '限期', value: 'indefinite' },
{ label: '自定…', value: 'custom' }
{ 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小', value: '1 hour' },
{ label: '1小', value: '1 hour' },
{ label: '2小', value: '2 hours' },
{ label: '2小', value: '2 hours' },
{ label: '3小', value: '3 hours' },
{ label: '3小', value: '3 hours' },
{ label: '6小', value: '6 hours' },
{ 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: '限期', value: 'indefinite' },
{ label: '限期', value: 'indefinite' },
{ label: '自定…', value: 'custom' }
{ 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小', value: '1 hour' },
{ label: '1小', value: '1 hour' },
{ label: '2小', value: '2 hours' },
{ label: '2小', value: '2 hours' },
{ label: '3小', value: '3 hours' },
{ label: '3小', value: '3 hours' },
{ label: '6小', value: '6 hours' },
{ 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: '限期', value: 'indefinite' },
{ label: '限期', value: 'indefinite' },
{ label: '自定…', value: 'custom' }
{ 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: '标记选项', name: 'field1' });
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: '使用图标(small=yes)',
label: '使用圖標(small=yes)',
tooltip: '将给模板加上|small=yes参数示成右上角的一把挂锁。'
tooltip: '將給模板加上|small=yes參數示成右上角的一把掛鎖。'
},
},
{
{
name: 'noinclude',
name: 'noinclude',
label: '用<noinclude>包裹保模板',
label: '用<noinclude>包裹保模板',
tooltip: '模板包裹在&lt;noinclude&gt;中',
tooltip: '模板包裹在&lt;noinclude&gt;中',
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: '保护类型', name: 'field_preset' });
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: '选项', name: 'field1' });
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: '临时', value: 'temporary' },
{ 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("前保", Twinkle.protect.protectionLevel);
Morebits.status.info("前保", Twinkle.protect.protectionLevel);
}
}


行 494: 行 494:


Twinkle.protect.doCustomExpiry = function twinkleprotectDoCustomExpiry(target) {
Twinkle.protect.doCustomExpiry = function twinkleprotectDoCustomExpiry(target) {
var custom = prompt('入自定义终时间。\n您可以使用相对时间,如“1 minute”“19 days”,绝对时间“yyyymmddhhmm”(“200602011405”是2006年02月01日14:05(UTC))', '');
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: '解除保', value: 'unprotect' },
{ label: '解除保', value: 'unprotect' },
{
{
label: '全保',
label: '全保',
list: [
list: [
{ label: '常(全)', value: 'pp-protected' },
{ label: '常(全)', value: 'pp-protected' },
{ label: '争议编辑战(全)', value: 'pp-dispute' },
{ label: '爭議編輯戰(全)', value: 'pp-dispute' },
{ label: '期破(全)', value: 'pp-vandalism' },
{ label: '期破(全)', value: 'pp-vandalism' },
{ label: '高风险模板(全)', value: 'pp-template' },
{ label: '高風險模板(全)', value: 'pp-template' },
{ label: '已封禁用讨论页(全)', value: 'pp-usertalk' }
{ label: '已封禁用討論頁(全)', value: 'pp-usertalk' }
]
]
},
},
{
{
label: '半保',
label: '半保',
list: [
list: [
{ label: '常(半)', value: 'pp-semi-protected' },
{ label: '常(半)', value: 'pp-semi-protected' },
{ label: '期破(半)', value: 'pp-semi-vandalism' },
{ label: '期破(半)', value: 'pp-semi-vandalism' },
{ label: '反生者传记(半)', value: 'pp-semi-blp' },
{ label: '反生者傳記(半)', value: 'pp-semi-blp' },
{ label: '傀儡破(半)', value: 'pp-semi-sock' },
{ label: '傀儡破(半)', value: 'pp-semi-sock' },
{ label: '高风险模板(半)', value: 'pp-semi-template' },
{ label: '高風險模板(半)', value: 'pp-semi-template' },
{ label: '已封禁用讨论页(半)', value: 'pp-semi-usertalk' }
{ label: '已封禁用討論頁(半)', value: 'pp-semi-usertalk' }
]
]
},
},
{
{
label: '移',
label: '移',
list: [
list: [
{ label: '常(移)', value: 'pp-move' },
{ label: '常(移)', value: 'pp-move' },
{ label: '争议、移动战(移)', value: 'pp-move-dispute' },
{ label: '爭議、移動戰(移)', value: 'pp-move-dispute' },
{ label: '移(移)', value: 'pp-move-vandalism' },
{ label: '移(移)', value: 'pp-move-vandalism' },
{ label: '高风险页面(移)', value: 'pp-move-indef' }
{ label: '高風險頁面(移)', value: 'pp-move-indef' }
]
]
}
}
行 543: 行 543:


Twinkle.protect.protectionTypesCreate = [
Twinkle.protect.protectionTypesCreate = [
{ label: '解除保', value: 'unprotect' },
{ label: '解除保', value: 'unprotect' },
{
{
label: '白',
label: '白',
list: [
list: [
{ label: '常', value: 'pp-create' }
{ 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}}: 争议', value: 'pp-dispute', selected: true },
{ label: '{{pp-dispute}}: 爭議', value: 'pp-dispute', selected: true },
{ label: '{{pp-usertalk}}: 封禁的用', value: 'pp-usertalk' }
{ label: '{{pp-usertalk}}: 封禁的用', value: 'pp-usertalk' }
]
]
},
},
{
{
label: '全、半保模板',
label: '全、半保模板',
list: [
list: [
{ label: '{{pp-vandalism}}: 破', value: 'pp-vandalism' },
{ label: '{{pp-vandalism}}: 破', value: 'pp-vandalism' },
{ label: '{{pp-template}}: 高风险模板', value: 'pp-template' },
{ label: '{{pp-template}}: 高風險模板', value: 'pp-template' },
{ label: '{{pp-protected}}: 常', value: 'pp-protected' }
{ label: '{{pp-protected}}: 常', value: 'pp-protected' }
]
]
},
},
{
{
label: '半保模板',
label: '半保模板',
list: [
list: [
{ label: '{{pp-semi-usertalk}}: 封禁的用', value: '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}}: 生者传记', value: 'pp-semi-blp' },
{ label: '{{pp-semi-blp}}: 生者傳記', value: 'pp-semi-blp' },
{ label: '{{pp-semi-indef}}: 期', value: 'pp-semi-indef' }
{ label: '{{pp-semi-indef}}: 期', value: 'pp-semi-indef' }
]
]
},
},
{
{
label: '移模板',
label: '移模板',
list: [
list: [
{ label: '{{pp-move-dispute}}: 争议', value: 'pp-move-dispute' },
{ label: '{{pp-move-dispute}}: 爭議', value: 'pp-move-dispute' },
{ label: '{{pp-move-vandalism}}: 破', value: 'pp-move-vandalism' },
{ label: '{{pp-move-vandalism}}: 破', value: 'pp-move-vandalism' },
{ label: '{{pp-move-indef}}: 期', value: 'pp-move-indef' },
{ label: '{{pp-move-indef}}: 期', value: 'pp-move-indef' },
{ label: '{{pp-move}}: 常', value: '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("Twinkle要做什!\n如果您只是想标记该页请选择上面的用保模板标记页”选项。");
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("在面上找到{{" + re_result[1] + "}}\n点击确定以移除,或点击取消以取消。")) {
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 = '移除保模板' + Twinkle.getPref('summaryAd');
summary = '移除保模板' + Twinkle.getPref('summaryAd');
} else {
} else {
if( params.noinclude ) {
if( params.noinclude ) {
行 1,043: 行 1,043:


if ( tag ) {
if ( tag ) {
statusElement.error( [ '已有目的保提名,在 ', rppLink, ',取消操作。' ] );
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( [ '已有目的保提名,在 ', rppLink, ',取消操作。' ] );
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 += "求" + Morebits.string.toUpperCaseFirstChar(words) + ( params.reason !== '' ? ":" +
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*求解除保\s*==\n)/;
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/修RFPP") );
linknode.setAttribute("href", mw.util.getUrl("Wikipedia:Twinkle/修RFPP") );
linknode.appendChild(document.createTextNode('如何修RFPP'));
linknode.appendChild(document.createTextNode('如何修RFPP'));
statusElement.error( [ '法在WP:RFPP上找到相点标记,要修问题请参见', linknode, '。' ] );
statusElement.error( [ '法在WP:RFPP上找到相點標記,要修問題請參見', linknode, '。' ] );
return;
return;
}
}
statusElement.status( '添加新提名…' );
statusElement.status( '添加新提名…' );
rppPage.setEditSummary( '[[' + Morebits.pageNameNorm + ']]' + params.typename + Twinkle.getPref('summaryAd') );
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: '將保護模板包裹在&lt;noinclude&gt;中',
							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>