User:Alexsh/rfp.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/*
Request for page Protection and Page Protection Tagger
Original Source Code by Steel359@enwiki, refactoring and localisation by Alexsh@zhwiki
*/
var ppM = { //RFP process tagname
f:wgULS('保护','保護'),
ft:wgULS('保护\+时间','保護+時間'),
s:wgULS('半保护','半保護'),
st:wgULS('半保护\+时间','半保護+時間'),
m:wgULS('移动保护','移動保護'),
n:wgULS('意见','意見'),
dn:wgULS('完成','完成'),
de:wgULS('已拒绝','已拒絕'),
u:wgULS('已解除','已解除'),
b:wgULS('已封禁','已封禁')
}
var rfpConfig={ //Message and Protect Information
Page:'Wikipedia:请求保护页面', //request for page protection page
Signature:'--~~\~~', //custom signature
resultTmp:'RFPP', //RFP result report template name
runTmp:['Protected','Mini-protected','Protected logo'],
protnm:wgULS('插入保护模板','插入保護模板'),
askExpy:wgULS('请输入过期时间(选项):','請輸入過期時間(選項):'),
Reason:wgULS('请输入理由 (选项)','請輸入理由 (選項)'),
rem:wgULS('请确认保护模板已移除并按下OK储存,如没有移除请按Cancel手动移除。','請確認保護模板已移除並按下OK儲存,如沒有移除請按Cancel手動移除。'),
prot:[// insert Protect template Array:id,action,template,caption,type=ID, protect action, use template,
{'id':'pp-dispute','tm':'n','ti':1,'m':[1,2,3],'cp':[wgULS('保护','保護'),'小',wgULS('图','圖')]},
{'id':'pp-vand','tm':'v','ti':0,'m':1,'cp':wgULS('保护 (破坏)','保護 (破壞)')},
{'id':'pp-mainpage','tm':'main','m':1,'ti':0,'cp':wgULS('保护 (首页)','保護 (首頁)')},
{'id':'pp-template','tm':'t','ti':0,'m':1,'cp':wgULS('保护 (模板)','保護 (模板)')},
{'id':'pp-commons','tm':'mi','ti':0,'m':1,'cp':wgULS('保护 (共享)','保護 (共享)')},
{'id':'pps-vandalism','tm':'s','ti':0,'m':[1,2,3],'cp':[wgULS('半保护','半保護'),'小',wgULS('图','圖')]},
{'id':'ppms','tm':'ms','ti':0,'m':[1,2,3],'cp':[wgULS('移动半保护','移動半保護'),'小',wgULS('图','圖')]},
{'id':'ppm','tm':'ms','ti':0,'m':[1,2,3],'cp':[wgULS('移动保护','移動保護'),'小',wgULS('图','圖')]},
{'id':'unprotect','tm':'unprotected','ti':0,'m':0,'cp':wgULS('解除保护','解除保護')}
],
protagnm:wgULS('处理请求','處理請求'),
protag:[// RFPP result
{'ty':'p','sum':ppM.f,'o':0,'cp':ppM.f},
{'ty':'p','sum':ppM.f,'o':1,'cp':ppM.ft},
{'ty':'s','sum':ppM.s,'o':0,'cp':ppM.s},
{'ty':'s','sum':ppM.s,'o':1,'cp':ppM.st},
{'ty':'n','sum':ppM.n,'o':3,'cp':ppM.n},
{'ty':'do','sum':ppM.dn,'o':0,'cp':ppM.dn},
{'ty':'u','sum':ppM.u,'o':0,'cp':ppM.u},
{'ty':'b','sum':ppM.b,'o':0,'cp':ppM.b},
{'ty':'nea','sum':ppM.de,'o':0,'cp':'(Declined nea)'},
{'ty':'d','sum':ppM.de,'o':2,'cp':ppM.de},
{'ty':'m','sum':ppM.m,'o':0,'cp':ppM.m}
]
}
function pp_process(){ //check jsaction
var arr = rfpConfig.prot;
for (var i = 0;i<arr.length;i++){
if(queryString("jsaction")==arr[i].id){
if(arr[i].m instanceof Array){//if Protection has multiple type (aka is Array)
for(var j=0;j<arr[i].m.length;j++){if(queryString("ty")==arr[i].m[j]) tag_protection(arr[i].id,arr[i].tm,queryString("ty"),arr[i].ti);}
}else{tag_protection(arr[i].id,arr[i].tm,queryString("ty"),arr[i].ti);}
}
}
}
if (wgPageName==rfpConfig.Page&&wgAction=='edit') {addOnloadHook(rfp_tagging);} //Load result tag in RFP page.
if ( wgNamespaceNumber > -1) { addHandler(window,'load',mylinks);}
$(misc_tagging);
if (queryString("jsaction")) {addOnloadHook(pp_process);}
function rfp_tagging(){ // make new siderbar and load RFPP result Array
var arr=rfpConfig.protag;
var boxclone = document.createElement("div");
boxclone.id = 'p-rfpp';
boxclone.setAttribute("class","portlet");
var titolo = document.createElement("h5");
titolo.innerHTML = rfpConfig.protagnm;
boxclone.appendChild(titolo);
var corpo = document.createElement("div");
corpo.setAttribute("class","pBody");
var list_ul = document.createElement("ul");
for(var i=0;i<arr.length;i++){
addPLink(list_ul,null,'javascript:tag_process(\''+arr[i].ty+'\',\''+arr[i].sum+'\','+arr[i].o+')',arr[i].cp)
}
corpo.appendChild(list_ul);
boxclone.appendChild(corpo);
document.getElementById("column-one").insertBefore(boxclone,document.getElementById('p-navigation'));
}
function tag_process(type,summary,other){// onclick tagprocess RFPP
var para = '|'+type,reason='';
switch(other){
case 1:
var exptime = prompt(rfpConfig.askExpy);
if(exptime) para+='|'+exptime;
break;
case 2:
reason = prompt(rfpConfig.Reason);
break;
case 3:
reason = prompt('Note');
break;
default:break;
}
var f = document.editform, t = f.wpTextbox1;
if (t.value.length > 0){
t.value +=':{\{'+rfpConfig.resultTmp+para+'}\}' +reason+rfpConfig.Signature;
f.wpSummary.value += summary;
}
}
function queryString(p) { //search url paramenter value
var re = RegExp('[&?]' + p + '=([^&]*)');
var matches;
if (matches = re.exec(document.location)) {
try { return decodeURI(matches[1]);}
catch (e) {}
}
return null;
}
function misc_tagging(){ //attach RFP into toolbox
mw.util.addPortletLink('p-tb', wgServer + '/wiki/'+rfpConfig.Page, "WP:RFP");
}
function tag_protection(action,tmp,mode,type){ //process protect template
var para='',conf, f = document.editform, t = f.wpTextbox1, unprotconfirm;
if (type) {//Load Expire Time Additional
var fulldisputeexp = prompt(rfpConfig.askExpy);
if (fulldisputeexp) para += '|time={\{subst:#time:c|\+' + fulldisputeexp + '}}';
conf = true;
}
if(mode==0){//If mode = 0 (aka Unprotect)
var pp = RegExp("\{\{.*?rotected.*?\}\}.*?\n");
t.value = t.value.split(pp).join('');
unprotconfirm = confirm(rfpConfig.rem);
}
if (!unprotconfirm&&mode!=0) t.value = '{\{'+rfpConfig.runTmp[mode-1]+'\|'+tmp+para+'}}\n'+t.value;
f.wpSummary.value = "{\{"+action+"}}";
if(mode||unprotconfirm) document.forms[0].wpSave.click();
}
function addPLink(front,pid,action,caption){//Add new Portlet Link to Sidebar. If action is array( aka action have multiple Type)
var x = document.createElement("li");
if(pid) x.id = pid;
for(var i = 0;i<(action instanceof Array?action.length:1);i++){
if(i!=0)x.innerHTML+='.';
var y = document.createElement("a");
y.href = action instanceof Array?action[i]:action;
y.innerHTML = action instanceof Array?caption[i]:caption;
x.appendChild(y);
}
front.appendChild(x);
}
function mylinks() { //process Insert Protected Template
var arr = rfpConfig.prot;
var boxclone = document.createElement("div");
boxclone.id = 'p-navclone';
boxclone.setAttribute("class","portlet");
var titolo = document.createElement("h5");
titolo.innerHTML = rfpConfig.protnm;
boxclone.appendChild(titolo);
var corpo = document.createElement("div");
corpo.setAttribute("class","pBody");
var list_ul = document.createElement("ul");
for(var i=0;i<arr.length;i++){
if(arr[i].m instanceof Array){
var tmp=[];
for (var j = 0;j<arr[i].m.length;j++){tmp[j]='javascript:paste_protage(\''+arr[i].id+'\',\''+arr[i].m[j]+'\')';}
}else{var tmp = 'javascript:paste_protage(\''+arr[i].id+'\',\''+arr[i].m+'\')'}
addPLink(list_ul,arr[i].id,tmp,arr[i].cp);
}
corpo.appendChild(list_ul);
boxclone.appendChild(corpo);
document.getElementById("column-one").insertBefore(boxclone,document.getElementById('p-tb').nextSibling);
}
function paste_protage(action,tmpmd){
location.href=wgScript+'?title='+wgPageName+'&action=edit§ion=0&jsaction='+action+'&ty='+tmpmd;
}