跳转到内容

User:Wetittwinkle/morebits.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// <nowiki>
(function(window,document,$,undefined){var Morebits={};window.Morebits=Morebits;Morebits.userIsInGroup=function(group){return mw.config.get('wgUserGroups').indexOf(group)!==-1;};Morebits.sanitizeIPv6=function(address){address=address.trim();if(address===''){return null;}
if(!mw.util.isIPv6Address(address)){return address;}
address=address.toUpperCase();var abbrevPos=address.indexOf('::');if(abbrevPos>-1){var CIDRStart=address.indexOf('/');var addressEnd=(CIDRStart>-1)?CIDRStart-1:address.length-1;var repeat,extra,pad;if(abbrevPos===0){repeat='0:';extra=(address=='::')?'0':'';pad=9;}else if(abbrevPos===(addressEnd-1)){repeat=':0';extra='';pad=9;}else{repeat=':0';extra=':';pad=8;}
var replacement=repeat;pad-=address.split(':').length-1;for(var i=1;i<pad;i++){replacement+=repeat;}
replacement+=extra;address=address.replace('::',replacement);}
address=address.replace(/(^|:)0+([0-9A-Fa-f]{1,4})/g,'$1$2');return address;};Morebits.quickForm=function QuickForm(event,eventType){this.root=new Morebits.quickForm.element({type:'form',event:event,eventType:eventType});};Morebits.quickForm.prototype.render=function QuickFormRender(){var ret=this.root.render();ret.names={};return ret;};Morebits.quickForm.prototype.append=function QuickFormAppend(data){return this.root.append(data);};Morebits.quickForm.element=function QuickFormElement(data){this.data=data;this.childs=[];this.id=Morebits.quickForm.element.id++;};Morebits.quickForm.element.id=0;Morebits.quickForm.element.prototype.append=function QuickFormElementAppend(data){var child;if(data instanceof Morebits.quickForm.element){child=data;}else{child=new Morebits.quickForm.element(data);}
this.childs.push(child);return child;};Morebits.quickForm.element.prototype.render=function QuickFormElementRender(internal_subgroup_id){var currentNode=this.compute(this.data,internal_subgroup_id);for(var i=0;i<this.childs.length;++i){currentNode[1].appendChild(this.childs[i].render());}
return currentNode[0];};Morebits.quickForm.element.prototype.compute=function QuickFormElementCompute(data,in_id){var node;var childContainder=null;var label;var id=(in_id?in_id+'_':'')+'node_'+this.id;if(data.adminonly&&!Morebits.userIsInGroup('sysop')){data.type='hidden';}
var i,current,subnode;switch(data.type){case'form':node=document.createElement('form');node.className="quickform";node.setAttribute('action','javascript:void(0);');if(data.event){node.addEventListener(data.eventType||'submit',data.event,false);}
break;case'fragment':node=document.createDocumentFragment();return[node,node];case'select':node=document.createElement('div');node.setAttribute('id','div_'+id);if(data.label){label=node.appendChild(document.createElement('label'));label.setAttribute('for',id);label.appendChild(document.createTextNode(data.label));}
var select=node.appendChild(document.createElement('select'));if(data.event){select.addEventListener('change',data.event,false);}
if(data.multiple){select.setAttribute('multiple','multiple');}
if(data.size){select.setAttribute('size',data.size);}
select.setAttribute('name',data.name);if(data.list){for(i=0;i<data.list.length;++i){current=data.list[i];if(current.list){current.type='optgroup';}else{current.type='option';}
subnode=this.compute(current);select.appendChild(subnode[0]);}}
childContainder=select;break;case'option':node=document.createElement('option');node.values=data.value;node.setAttribute('value',data.value);if(data.selected){node.setAttribute('selected','selected');}
if(data.disabled){node.setAttribute('disabled','disabled');}
node.setAttribute('label',data.label);node.appendChild(document.createTextNode(data.label));break;case'optgroup':node=document.createElement('optgroup');node.setAttribute('label',data.label);if(data.list){for(i=0;i<data.list.length;++i){current=data.list[i];current.type='option';subnode=this.compute(current);node.appendChild(subnode[0]);}}
break;case'field':node=document.createElement('fieldset');label=node.appendChild(document.createElement('legend'));label.appendChild(document.createTextNode(data.label));if(data.name){node.setAttribute('name',data.name);}
if(data.disabled){node.setAttribute('disabled','disabled');}
break;case'checkbox':case'radio':node=document.createElement('div');if(data.list){for(i=0;i<data.list.length;++i){var cur_id=id+'_'+i;current=data.list[i];var cur_div;if(current.type==='header'){cur_div=node.appendChild(document.createElement('h6'));cur_div.appendChild(document.createTextNode(current.label));if(current.tooltip){Morebits.quickForm.element.generateTooltip(cur_div,current);}
continue;}
cur_div=node.appendChild(document.createElement('div'));if(current.hidden){cur_div.setAttribute('hidden','');}
subnode=cur_div.appendChild(document.createElement('input'));subnode.values=current.value;subnode.setAttribute('value',current.value);subnode.setAttribute('name',current.name||data.name);subnode.setAttribute('type',data.type);subnode.setAttribute('id',cur_id);if(current.checked){subnode.setAttribute('checked','checked');}
if(current.disabled){subnode.setAttribute('disabled','disabled');}
label=cur_div.appendChild(document.createElement('label'));label.appendChild(document.createTextNode(current.label));label.setAttribute('for',cur_id);if(current.tooltip){Morebits.quickForm.element.generateTooltip(label,current);}
if(current.style){subnode.setAttribute('style',current.style);}
var event;if(current.subgroup){var tmpgroup=current.subgroup;if(!$.isArray(tmpgroup)){tmpgroup=[tmpgroup];}
var subgroupRaw=new Morebits.quickForm.element({type:'div',id:id+'_'+i+'_subgroup'});$.each(tmpgroup,function(idx,el){var newEl=$.extend({},el);if(!newEl.type){newEl.type=data.type;}
newEl.name=(current.name||data.name)+'.'+newEl.name;subgroupRaw.append(newEl);});var subgroup=subgroupRaw.render(cur_id);subgroup.className="quickformSubgroup";subnode.subgroup=subgroup;subnode.shown=false;event=function(e){if(e.target.checked){e.target.parentNode.appendChild(e.target.subgroup);if(e.target.type==='radio'){var name=e.target.name;if(e.target.form.names[name]!==undefined){e.target.form.names[name].parentNode.removeChild(e.target.form.names[name].subgroup);}
e.target.form.names[name]=e.target;}}else{e.target.parentNode.removeChild(e.target.subgroup);}};subnode.addEventListener('change',event,true);if(current.checked){subnode.parentNode.appendChild(subgroup);}}else if(data.type==='radio'){event=function(e){if(e.target.checked){var name=e.target.name;if(e.target.form.names[name]!==undefined){e.target.form.names[name].parentNode.removeChild(e.target.form.names[name].subgroup);}
delete e.target.form.names[name];}};subnode.addEventListener('change',event,true);}
if(data.event){subnode.addEventListener('change',data.event,false);}else if(current.event){subnode.addEventListener('change',current.event,true);}}}
break;case'input':node=document.createElement('div');node.setAttribute('id','div_'+id);if(data.hidden){node.setAttribute('hidden','');}
if(data.label){label=node.appendChild(document.createElement('label'));label.appendChild(document.createTextNode(data.label));label.setAttribute('for',id);}
subnode=node.appendChild(document.createElement('input'));if(data.value){subnode.setAttribute('value',data.value);}
if(data.placeholder){subnode.setAttribute('placeholder',data.placeholder);}
subnode.setAttribute('name',data.name);subnode.setAttribute('id',id);subnode.setAttribute('type','text');if(data.size){subnode.setAttribute('size',data.size);}
if(data.disabled){subnode.setAttribute('disabled','disabled');}
if(data.readonly){subnode.setAttribute('readonly','readonly');}
if(data.maxlength){subnode.setAttribute('maxlength',data.maxlength);}
if(data.event){subnode.addEventListener('keyup',data.event,false);}
break;case'dyninput':var min=data.min||1;var max=data.max||Infinity;node=document.createElement('div');label=node.appendChild(document.createElement('h5'));label.appendChild(document.createTextNode(data.label));var listNode=node.appendChild(document.createElement('div'));var more=this.compute({type:'button',label:'更多',disabled:min>=max,event:function(e){var new_node=new Morebits.quickForm.element(e.target.sublist);e.target.area.appendChild(new_node.render());if(++e.target.counter>=e.target.max){e.target.setAttribute('disabled','disabled');}
e.stopPropagation();}});node.appendChild(more[0]);var moreButton=more[1];var sublist={type:'_dyninput_element',label:data.sublabel||data.label,name:data.name,value:data.value,size:data.size,remove:false,maxlength:data.maxlength,event:data.event};for(i=0;i<min;++i){var elem=new Morebits.quickForm.element(sublist);listNode.appendChild(elem.render());}
sublist.remove=true;sublist.morebutton=moreButton;sublist.listnode=listNode;moreButton.sublist=sublist;moreButton.area=listNode;moreButton.max=max-min;moreButton.counter=0;break;case'_dyninput_element':node=document.createElement('div');if(data.label){label=node.appendChild(document.createElement('label'));label.appendChild(document.createTextNode(data.label));label.setAttribute('for',id);}
subnode=node.appendChild(document.createElement('input'));if(data.value){subnode.setAttribute('value',data.value);}
subnode.setAttribute('name',data.name);subnode.setAttribute('type','text');if(data.size){subnode.setAttribute('size',data.size);}
if(data.maxlength){subnode.setAttribute('maxlength',data.maxlength);}
if(data.event){subnode.addEventListener('keyup',data.event,false);}
if(data.remove){var remove=this.compute({type:'button',label:'移除',event:function(e){var list=e.target.listnode;var node=e.target.inputnode;var more=e.target.morebutton;list.removeChild(node);--more.counter;more.removeAttribute('disabled');e.stopPropagation();}});node.appendChild(remove[0]);var removeButton=remove[1];removeButton.inputnode=node;removeButton.listnode=data.listnode;removeButton.morebutton=data.morebutton;}
break;case'hidden':node=document.createElement('input');node.setAttribute('type','hidden');node.values=data.value;node.setAttribute('value',data.value);node.setAttribute('name',data.name);break;case'header':node=document.createElement('h5');node.appendChild(document.createTextNode(data.label));break;case'div':node=document.createElement('div');if(data.name){node.setAttribute('name',data.name);}
if(data.label){if(!$.isArray(data.label)){data.label=[data.label];}
var result=document.createElement('span');result.className='quickformDescription';for(i=0;i<data.label.length;++i){if(typeof data.label[i]==='string'){result.appendChild(document.createTextNode(data.label[i]));}else if(data.label[i]instanceof Element){result.appendChild(data.label[i]);}}
node.appendChild(result);}
break;case'submit':node=document.createElement('span');childContainder=node.appendChild(document.createElement('input'));childContainder.setAttribute('type','submit');if(data.label){childContainder.setAttribute('value',data.label);}
childContainder.setAttribute('name',data.name||'submit');if(data.disabled){childContainder.setAttribute('disabled','disabled');}
break;case'button':node=document.createElement('span');childContainder=node.appendChild(document.createElement('input'));childContainder.setAttribute('type','button');if(data.label){childContainder.setAttribute('value',data.label);}
childContainder.setAttribute('name',data.name);if(data.disabled){childContainder.setAttribute('disabled','disabled');}
if(data.event){childContainder.addEventListener('click',data.event,false);}
break;case'textarea':node=document.createElement('div');node.setAttribute('id','div_'+id);if(data.hidden){node.setAttribute('hidden','');}
if(data.label){label=node.appendChild(document.createElement('h5'));label.appendChild(document.createTextNode(data.label));}
subnode=node.appendChild(document.createElement('textarea'));subnode.setAttribute('name',data.name);if(data.cols){subnode.setAttribute('cols',data.cols);}
if(data.rows){subnode.setAttribute('rows',data.rows);}
if(data.disabled){subnode.setAttribute('disabled','disabled');}
if(data.readonly){subnode.setAttribute('readonly','readonly');}
if(data.value){subnode.value=data.value;}
if(data.placeholder){subnode.placeholder=data.placeholder;}
break;default:throw new Error("Morebits.quickForm: unknown element type "+data.type.toString());}
if(!childContainder){childContainder=node;}
if(data.tooltip){Morebits.quickForm.element.generateTooltip(label||node,data);}
if(data.extra){childContainder.extra=data.extra;}
if(data.style){childContainder.setAttribute('style',data.style);}
if(data.className){childContainder.className=(childContainder.className?childContainder.className+" "+data.className:data.className);}
childContainder.setAttribute('id',data.id||id);return[node,childContainder];};Morebits.quickForm.element.autoNWSW=function(){return $(this).offset().top>($(document).scrollTop()+$(window).height()/2)?'sw':'nw';};Morebits.quickForm.element.generateTooltip=function QuickFormElementGenerateTooltip(node,data){$('<span></span>',{'class':'ui-icon ui-icon-help ui-icon-inline morebits-tooltip'}).appendTo(node).tipsy({'fallback':data.tooltip,'fade':true,'gravity':(data.type==="input"||data.type==="select")?Morebits.quickForm.element.autoNWSW:$.fn.tipsy.autoWE,'html':true,'delayOut':250});};Morebits.quickForm.getElements=function QuickFormGetElements(form,fieldName){var $form=$(form);var $elements=$form.find('[name="'+fieldName+'"]');if($elements.length>0){return $elements.toArray();}
$elements=$form.find('#'+fieldName);if($elements.length>0){return $elements.toArray();}
return null;};Morebits.quickForm.getCheckboxOrRadio=function QuickFormGetCheckboxOrRadio(elementArray,value){var found=$.grep(elementArray,function(el){return el.value===value;});if(found.length>0){return found[0];}
return null;};Morebits.quickForm.getElementContainer=function QuickFormGetElementContainer(element){if(element instanceof HTMLFieldSetElement||element instanceof HTMLDivElement||element instanceof HTMLHeadingElement){return element;}
return element.parentNode;};Morebits.quickForm.getElementLabelObject=function QuickFormGetElementLabelObject(element){if(element.type==="button"||element.type==="submit"||element instanceof HTMLDivElement||element instanceof HTMLHeadingElement){return element;}else if(element instanceof HTMLFieldSetElement){return element.getElementsByTagName("legend")[0];}else if(element instanceof HTMLTextAreaElement){return element.parentNode.getElementsByTagName("h5")[0];}else{return element.parentNode.getElementsByTagName("label")[0];}};Morebits.quickForm.getElementLabel=function QuickFormGetElementLabel(element){var labelElement=Morebits.quickForm.getElementLabelObject(element);if(!labelElement){return null;}
return labelElement.firstChild.textContent;};Morebits.quickForm.setElementLabel=function QuickFormSetElementLabel(element,labelText){var labelElement=Morebits.quickForm.getElementLabelObject(element);if(!labelElement){return false;}
labelElement.firstChild.textContent=labelText;return true;};Morebits.quickForm.overrideElementLabel=function QuickFormOverrideElementLabel(element,temporaryLabelText){if(!element.hasAttribute("data-oldlabel")){element.setAttribute("data-oldlabel",Morebits.quickForm.getElementLabel(element));}
return Morebits.quickForm.setElementLabel(element,temporaryLabelText);};Morebits.quickForm.resetElementLabel=function QuickFormResetElementLabel(element){if(element.hasAttribute("data-oldlabel")){return Morebits.quickForm.setElementLabel(element,element.getAttribute("data-oldlabel"));}
return null;};Morebits.quickForm.setElementVisibility=function QuickFormSetElementVisibility(element,visibility){$(element).toggle(visibility);};Morebits.quickForm.setElementTooltipVisibility=function QuickFormSetElementTooltipVisibility(element,visibility){$(Morebits.quickForm.getElementContainer(element)).find(".morebits-tooltip").toggle(visibility);};HTMLFormElement.prototype.getChecked=function(name,type){var elements=this.elements[name];if(!elements){return null;}
var return_array=[];var i;if(elements instanceof HTMLSelectElement){var options=elements.options;for(i=0;i<options.length;++i){if(options[i].selected){if(options[i].values){return_array.push(options[i].values);}else{return_array.push(options[i].value);}}}}else if(elements instanceof HTMLInputElement){if(type&&elements.type!==type){return[];}else if(elements.checked){return[elements.value];}}else{for(i=0;i<elements.length;++i){if(elements[i].checked){if(type&&elements[i].type!==type){continue;}
if(elements[i].values){return_array.push(elements[i].values);}else{return_array.push(elements[i].value);}}}}
return return_array;};RegExp.escape=function(text,space_fix){text=mw.RegExp.escape(text);if(space_fix){text=text.replace(/ |_/g,'[_ ]');}
return text;};Morebits.bytes=function(value){if(typeof value==='string'){var res=/(\d+) ?(\w?)(i?)B?/.exec(value);var number=res[1];var mag=res[2];var si=res[3];if(!number){this.number=0;return;}
if(!si){this.value=number*Math.pow(10,Morebits.bytes.magnitudes[mag]*3);}else{this.value=number*Math.pow(2,Morebits.bytes.magnitudes[mag]*10);}}else{this.value=value;}};Morebits.bytes.magnitudes={'':0,'K':1,'M':2,'G':3,'T':4,'P':5,'E':6,'Z':7,'Y':8};Morebits.bytes.rmagnitudes={0:'',1:'K',2:'M',3:'G',4:'T',5:'P',6:'E',7:'Z',8:'Y'};Morebits.bytes.prototype.valueOf=function(){return this.value;};Morebits.bytes.prototype.toString=function(magnitude){var tmp=this.value;if(magnitude){var si=/i/.test(magnitude);var mag=magnitude.replace(/.*?(\w)i?B?.*/g,'$1');if(si){tmp/=Math.pow(2,Morebits.bytes.magnitudes[mag]*10);}else{tmp/=Math.pow(10,Morebits.bytes.magnitudes[mag]*3);}
if(parseInt(tmp,10)!==tmp){tmp=Number(tmp).toPrecision(4);}
return tmp+' '+mag+(si?'i':'')+'B';}else{var current=0;while(tmp>=1024){tmp/=1024;++current;}
tmp=this.value/Math.pow(2,current*10);if(parseInt(tmp,10)!==tmp){tmp=Number(tmp).toPrecision(4);}
return tmp+' '+Morebits.bytes.rmagnitudes[current]+(current>0?'iB':'B');}};if(!String.prototype.trimLeft){String.prototype.trimLeft=function stringPrototypeLtrim(){return this.replace(/^[\s]+/g,"");};}
if(!String.prototype.trimRight){String.prototype.trimRight=function stringPrototypeRtrim(){return this.replace(/[\s]+$/g,"");};}
if(!String.prototype.trim){String.prototype.trim=function stringPrototypeTrim(){return this.trimRight().trimLeft();};}
Morebits.string={toUpperCaseFirstChar:function(str){str=str.toString();return str.substr(0,1).toUpperCase()+str.substr(1);},toLowerCaseFirstChar:function(str){str=str.toString();return str.substr(0,1).toLowerCase()+str.substr(1);},splitWeightedByKeys:function(str,start,end,skip){if(start.length!==end.length){throw new Error('起始和结束标记必须等长');}
var level=0;var initial=null;var result=[];if(!$.isArray(skip)){if(skip===undefined){skip=[];}else if(typeof skip==='string'){skip=[skip];}else{throw new Error("不适用的跳过参数");}}
for(var i=0;i<str.length;++i){for(var j=0;j<skip.length;++j){if(str.substr(i,skip[j].length)===skip[j]){i+=skip[j].length-1;continue;}}
if(str.substr(i,start.length)===start){if(initial===null){initial=i;}
++level;i+=start.length-1;}else if(str.substr(i,end.length)===end){--level;i+=end.length-1;}
if(!level&&initial!==null){result.push(str.substring(initial,i+1));initial=null;}}
return result;},formatReasonText:function(str){var result=str.toString().trimRight();var unbinder=new Morebits.unbinder(result);unbinder.unbind("<no"+"wiki>","</no"+"wiki>");unbinder.content=unbinder.content.replace(/\|/g,"{{subst:!}}");return unbinder.rebind();},safeReplace:function morebitsStringSafeReplace(string,pattern,replacement){return string.replace(pattern,replacement.replace(/\$/g,"$$$$"));}};Morebits.array={uniq:function(arr){if(!$.isArray(arr)){throw"A non-array object passed to Morebits.array.uniq";}
var result=[];for(var i=0;i<arr.length;++i){var current=arr[i];if(result.indexOf(current)===-1){result.push(current);}}
return result;},dups:function(arr){if(!$.isArray(arr)){throw"A non-array object passed to Morebits.array.dups";}
var uniques=[];var result=[];for(var i=0;i<arr.length;++i){var current=arr[i];if(uniques.indexOf(current)===-1){uniques.push(current);}else{result.push(current);}}
return result;},chunk:function(arr,size){if(!$.isArray(arr)){throw"A non-array object passed to Morebits.array.chunk";}
if(typeof size!=='number'||size<=0){return[arr];}
var result=[];var current;for(var i=0;i<arr.length;++i){if(i%size===0){current=[];result.push(current);}
current.push(arr[i]);}
return result;}};Morebits.pageNameNorm=mw.config.get('wgPageName').replace(/_/g,' ');Morebits.unbinder=function Unbinder(string){if(typeof string!=='string'){throw new Error("不是字符串");}
this.content=string;this.counter=0;this.history={};this.prefix='%UNIQ::'+Math.random()+'::';this.postfix='::UNIQ%';};Morebits.unbinder.prototype={unbind:function UnbinderUnbind(prefix,postfix){var re=new RegExp(prefix+'(.*?)'+postfix,'g');this.content=this.content.replace(re,Morebits.unbinder.getCallback(this));},rebind:function UnbinderRebind(){var content=this.content;content.self=this;for(var current in this.history){if(this.history.hasOwnProperty(current)){content=content.replace(current,this.history[current]);}}
return content;},prefix:null,postfix:null,content:null,counter:null,history:null};Morebits.unbinder.getCallback=function UnbinderGetCallback(self){return function UnbinderCallback(match){var current=self.prefix+self.counter+self.postfix;self.history[current]=match;++self.counter;return current;};};Date.monthNames=['January','February','March','April','May','June','July','August','September','October','November','December'];Date.monthNamesAbbrev=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];Date.prototype.getMonthName=function(){return Date.monthNames[this.getMonth()];};Date.prototype.getMonthNameAbbrev=function(){return Date.monthNamesAbbrev[this.getMonth()];};Date.prototype.getUTCMonthName=function(){return Date.monthNames[this.getUTCMonth()];};Date.prototype.getUTCMonthNameAbbrev=function(){return Date.monthNamesAbbrev[this.getUTCMonth()];};Morebits.wikipedia={};Morebits.wikipedia.namespaces={'-2':'Media','-1':'Special','0':'','1':'Talk','2':'User','3':'User talk','4':'Project','5':'Project talk','6':'File','7':'File talk','8':'MediaWiki','9':'MediaWiki talk','10':'Template','11':'Template talk','12':'Help','13':'Help talk','14':'Category','15':'Category talk','100':'Portal','101':'Portal talk','108':'Book','109':'Book talk','118':'Draft','119':'Draft talk','446':'Education Program','447':'Education Program talk','710':'TimedText','711':'TimedText talk','828':'Module','829':'Module talk'};Morebits.wikipedia.namespacesFriendly={'0':wgULS('(条目)','(條目)'),'1':'Talk','2':'User','3':'User talk','4':'Wikipedia','5':'Wikipedia talk','6':'File','7':'File talk','8':'MediaWiki','9':'MediaWiki talk','10':'Template','11':'Template talk','12':'Help','13':'Help talk','14':'Category','15':'Category talk','100':'Portal','101':'Portal talk','108':'Book','109':'Book talk','118':'Draft','119':'Draft talk','446':'Education Program','447':'Education Program talk','710':'TimedText','711':'TimedText talk','828':'Module','829':'Module talk'};Morebits.wiki={};Morebits.wiki.isPageRedirect=function wikipediaIsPageRedirect(){return!!(mw.config.get("wgIsRedirect")||document.getElementById("softredirect"));};Morebits.wiki.numberOfActionsLeft=0;Morebits.wiki.nbrOfCheckpointsLeft=0;Morebits.wiki.actionCompleted=function(self){if(--Morebits.wiki.numberOfActionsLeft<=0&&Morebits.wiki.nbrOfCheckpointsLeft<=0){Morebits.wiki.actionCompleted.event(self);}};Morebits.wiki.actionCompleted.event=function(){new Morebits.status(Morebits.wiki.actionCompleted.notice,Morebits.wiki.actionCompleted.postfix,'info');if(Morebits.wiki.actionCompleted.redirect){if(!((/^\w+:\/\//).test(Morebits.wiki.actionCompleted.redirect))){Morebits.wiki.actionCompleted.redirect=mw.util.getUrl(Morebits.wiki.actionCompleted.redirect);if(Morebits.wiki.actionCompleted.followRedirect===false){Morebits.wiki.actionCompleted.redirect+="?redirect=no";}}
window.setTimeout(function(){window.location=Morebits.wiki.actionCompleted.redirect;},Morebits.wiki.actionCompleted.timeOut);}};Morebits.wiki.actionCompleted.timeOut=(typeof window.wpActionCompletedTimeOut==='undefined'?5000:window.wpActionCompletedTimeOut);Morebits.wiki.actionCompleted.redirect=null;Morebits.wiki.actionCompleted.notice=wgULS('动作','動作');Morebits.wiki.actionCompleted.postfix='已完成';Morebits.wiki.addCheckpoint=function(){++Morebits.wiki.nbrOfCheckpointsLeft;};Morebits.wiki.removeCheckpoint=function(){if(--Morebits.wiki.nbrOfCheckpointsLeft<=0&&Morebits.wiki.numberOfActionsLeft<=0){Morebits.wiki.actionCompleted.event();}};Morebits.wiki.api=function(currentAction,query,onSuccess,statusElement,onError){this.currentAction=currentAction;this.query=query;this.query.format='xml';this.query.assert='user';this.onSuccess=onSuccess;this.onError=onError;if(statusElement){this.statelem=statusElement;this.statelem.status(currentAction);}else{this.statelem=new Morebits.status(currentAction);}};Morebits.wiki.api.prototype={currentAction:'',onSuccess:null,onError:null,parent:window,query:null,responseXML:null,setParent:function(parent){this.parent=parent;},statelem:null,statusText:null,errorCode:null,errorText:null,post:function(callerAjaxParameters){++Morebits.wiki.numberOfActionsLeft;var ajaxparams=$.extend({},{context:this,type:'POST',url:mw.util.wikiScript('api'),data:Morebits.queryString.create(this.query),dataType:'xml',headers:{'Api-User-Agent':morebitsWikiApiUserAgent}},callerAjaxParameters);return $.ajax(ajaxparams).done(function(xml,statusText){this.statusText=statusText;this.responseXML=xml;this.errorCode=$(xml).find('error').attr('code');this.errorText=$(xml).find('error').attr('info');if(typeof this.errorCode==="string"){this.returnError();return;}
if(this.onSuccess){this.onSuccess.call(this.parent,this);}else{this.statelem.info("完成");}
Morebits.wiki.actionCompleted();}).fail(function(jqXHR,statusText,errorThrown){this.statusText=statusText;this.errorThrown=errorThrown;this.errorText=statusText+wgULS('在调用API时发生了错误“','在存取API時發生了錯誤「')+jqXHR.statusText+wgULS('”。','」。');this.returnError();});},returnError:function(){if(this.errorCode==="badtoken"){this.statelem.error(wgULS("无效令牌,请刷新页面并重试","無效權杖,請重新整理頁面並重試"));}else{this.statelem.error(this.errorText);}
if(this.onError){this.onError.call(this.parent,this);}},getStatusElement:function(){return this.statelem;},getErrorCode:function(){return this.errorCode;},getErrorText:function(){return this.errorText;},getXML:function(){return this.responseXML;}};var morebitsWikiApiUserAgent='morebits.js~zh/2.0 ([[w:zh:WT:TW]])';Morebits.wiki.api.setApiUserAgent=function(ua){morebitsWikiApiUserAgent=(ua?ua+' ':'')+'morebits.js~zh/2.0 ([[w:zh:WT:TW]])';};Morebits.wiki.page=function(pageName,currentAction){if(!currentAction){currentAction=wgULS('打开页面“','開啟頁面「')+pageName+wgULS('”','」');}
var ctx={pageName:pageName,pageExists:false,editSummary:null,tags:'',callbackParameters:null,statusElement:new Morebits.status(currentAction),pageText:null,editMode:'all',appendText:null,prependText:null,createOption:null,minorEdit:false,botEdit:false,pageSection:null,maxConflictRetries:2,maxRetries:2,followRedirect:false,watchlistOption:'nochange',creator:null,revertOldID:null,moveDestination:null,moveTalkPage:false,moveSubpages:false,moveSuppressRedirect:false,protectEdit:null,protectMove:null,protectCreate:null,protectCascade:false,flaggedRevs:null,pageLoaded:false,editToken:null,loadTime:null,lastEditTime:null,revertCurID:null,revertUser:null,fullyProtected:false,suppressProtectWarning:false,conflictRetries:0,retries:0,onLoadSuccess:null,onLoadFailure:null,onSaveSuccess:null,onSaveFailure:null,onLookupCreatorSuccess:null,onMoveSuccess:null,onMoveFailure:null,onDeleteSuccess:null,onDeleteFailure:null,onProtectSuccess:null,onProtectFailure:null,onStabilizeSuccess:null,onStabilizeFailure:null,loadQuery:null,loadApi:null,saveApi:null,lookupCreatorApi:null,moveApi:null,moveProcessApi:null,deleteApi:null,deleteProcessApi:null,protectApi:null,protectProcessApi:null,stabilizeApi:null,stabilizeProcessApi:null};var emptyFunction=function(){};this.getPageName=function(){return ctx.pageName;};this.getPageText=function(){return ctx.pageText;};this.setPageText=function(pageText){ctx.editMode='all';ctx.pageText=pageText;};this.setAppendText=function(appendText){ctx.editMode='append';ctx.appendText=appendText;};this.setPrependText=function(prependText){ctx.editMode='prepend';ctx.prependText=prependText;};this.setEditSummary=function(summary){ctx.editSummary=summary;};this.setTags=function(tags){ctx.tags=tags;};this.setCreateOption=function(createOption){ctx.createOption=createOption;};this.setMinorEdit=function(minorEdit){ctx.minorEdit=minorEdit;};this.setBotEdit=function(botEdit){ctx.botEdit=botEdit;};this.setPageSection=function(pageSection){ctx.pageSection=pageSection;};this.setMaxConflictRetries=function(maxRetries){ctx.maxConflictRetries=maxRetries;};this.setMaxRetries=function(maxRetries){ctx.maxRetries=maxRetries;};this.setCallbackParameters=function(callbackParameters){ctx.callbackParameters=callbackParameters;};this.getCallbackParameters=function(){return ctx.callbackParameters;};this.getCreator=function(){return ctx.creator;};this.setOldID=function(oldID){ctx.revertOldID=oldID;};this.getCurrentID=function(){return ctx.revertCurID;};this.getRevisionUser=function(){return ctx.revertUser;};this.setMoveDestination=function(destination){ctx.moveDestination=destination;};this.setMoveTalkPage=function(flag){ctx.moveTalkPage=!!flag;};this.setMoveSubpages=function(flag){ctx.moveSubpages=!!flag;};this.setMoveSuppressRedirect=function(flag){ctx.moveSuppressRedirect=!!flag;};this.setEditProtection=function(level,expiry){ctx.protectEdit={level:level,expiry:expiry};};this.setMoveProtection=function(level,expiry){ctx.protectMove={level:level,expiry:expiry};};this.setCreateProtection=function(level,expiry){ctx.protectCreate={level:level,expiry:expiry};};this.setCascadingProtection=function(flag){ctx.protectCascade=!!flag;};this.setFlaggedRevs=function(level,expiry){ctx.flaggedRevs={level:level,expiry:expiry};};this.getStatusElement=function(){return ctx.statusElement;};this.setFollowRedirect=function(followRedirect){if(ctx.pageLoaded){ctx.statusElement.error("内部错误:不能在页面加载后修改重定向设置!");return;}
ctx.followRedirect=followRedirect;};this.setWatchlist=function(flag){if(flag){ctx.watchlistOption='watch';}else{ctx.watchlistOption='nochange';}};this.setWatchlistFromPreferences=function(flag){if(flag){ctx.watchlistOption='preferences';}else{ctx.watchlistOption='nochange';}};this.suppressProtectWarning=function(){ctx.suppressProtectWarning=true;};this.exists=function(){return ctx.pageExists;};this.load=function(onSuccess,onFailure){ctx.onLoadSuccess=onSuccess;ctx.onLoadFailure=onFailure||emptyFunction;if(!onSuccess){ctx.statusElement.error("内部错误:未给load()提供onSuccess回调函数!");ctx.onLoadFailure(this);return;}
ctx.loadQuery={action:'query',prop:'info|revisions',intoken:'edit',titles:ctx.pageName};if(ctx.editMode==='all'){ctx.loadQuery.rvprop='content|timestamp';}else if(ctx.editMode==='revert'){ctx.loadQuery.rvprop='timestamp';ctx.loadQuery.rvlimit=1;ctx.loadQuery.rvstartid=ctx.revertOldID;}
if(ctx.followRedirect){ctx.loadQuery.redirects='';}
if(typeof ctx.pageSection==='number'){ctx.loadQuery.rvsection=ctx.pageSection;}
if(Morebits.userIsInGroup('sysop')){ctx.loadQuery.inprop='protection';}
ctx.loadApi=new Morebits.wiki.api(wgULS("抓取页面…","擷取頁面…"),ctx.loadQuery,fnLoadSuccess,ctx.statusElement,ctx.onLoadFailure);ctx.loadApi.setParent(this);ctx.loadApi.post();};this.save=function(onSuccess,onFailure){ctx.onSaveSuccess=onSuccess;ctx.onSaveFailure=onFailure||emptyFunction;var canUseMwUserToken=fnCanUseMwUserToken('edit');if(!ctx.pageLoaded&&!canUseMwUserToken){ctx.statusElement.error("内部错误:试图保存未被加载的页面!");ctx.onSaveFailure(this);return;}
if(!ctx.editSummary){ctx.statusElement.error("内部错误:保存前未设置编辑摘要!");ctx.onSaveFailure(this);return;}
if(ctx.fullyProtected&&!ctx.suppressProtectWarning&&!confirm(wgULS('您即将编辑全保护页面 "','您即將編輯全保護頁面 "')+ctx.pageName+
(ctx.fullyProtected==='infinity'?'(永久)':('(到期:'+ctx.fullyProtected+')'))+
wgULS('。\n\n点击确定以确定,或点击取消以取消。','。\n\n點選確定以繼續,或點選取消以取消。'))){ctx.statusElement.error(wgULS("已取消对全保护页面的编辑。","已取消對全保護頁面的編輯。"));ctx.onSaveFailure(this);return;}
ctx.retries=0;var query={action:'edit',tags:ctx.tags,title:ctx.pageName,summary:ctx.editSummary,token:canUseMwUserToken?mw.user.tokens.get('editToken'):ctx.editToken,watchlist:ctx.watchlistOption};if(typeof ctx.pageSection==='number'){query.section=ctx.pageSection;}
if(ctx.minorEdit){query.minor=true;}else{query.notminor=true;}
if(ctx.botEdit){query.bot=true;}
switch(ctx.editMode){case'append':query.appendtext=ctx.appendText;break;case'prepend':query.prependtext=ctx.prependText;break;case'revert':query.undo=ctx.revertCurID;query.undoafter=ctx.revertOldID;if(ctx.lastEditTime){query.basetimestamp=ctx.lastEditTime;}
query.starttimestamp=ctx.loadTime;break;default:query.text=ctx.pageText;if(ctx.lastEditTime){query.basetimestamp=ctx.lastEditTime;}
query.starttimestamp=ctx.loadTime;break;}
if(['recreate','createonly','nocreate'].indexOf(ctx.createOption)!==-1){query[ctx.createOption]='';}
if(canUseMwUserToken&&ctx.followRedirect){query.redirect=true;}
ctx.saveApi=new Morebits.wiki.api(wgULS("保存页面…","儲存頁面…"),query,fnSaveSuccess,ctx.statusElement,fnSaveError);ctx.saveApi.setParent(this);ctx.saveApi.post();};this.append=function(onSuccess,onFailure){ctx.editMode='append';if(fnCanUseMwUserToken('edit')){this.save(onSuccess,onFailure);}else{ctx.onSaveSuccess=onSuccess;ctx.onSaveFailure=onFailure||emptyFunction;this.load(fnAutoSave,ctx.onSaveFailure);}};this.prepend=function(onSuccess,onFailure){ctx.editMode='prepend';if(fnCanUseMwUserToken('edit')){this.save(onSuccess,onFailure);}else{ctx.onSaveSuccess=onSuccess;ctx.onSaveFailure=onFailure||emptyFunction;this.load(fnAutoSave,ctx.onSaveFailure);}};this.lookupCreator=function(onSuccess){if(!onSuccess){ctx.statusElement.error("内部错误:未给lookupCreator()提供onSuccess回调函数!");return;}
ctx.onLookupCreatorSuccess=onSuccess;var query={'action':'query','prop':'revisions','titles':ctx.pageName,'rvlimit':1,'rvprop':'user','rvdir':'newer'};if(ctx.followRedirect){query.redirects='';}
ctx.lookupCreatorApi=new Morebits.wiki.api(wgULS("抓取页面创建者信息","擷取頁面建立者資訊"),query,fnLookupCreatorSuccess,ctx.statusElement);ctx.lookupCreatorApi.setParent(this);ctx.lookupCreatorApi.post();};this.patrol=function(){if(!$('.patrollink').length){return;}
var patrolhref=$('.patrollink a').attr('href'),rcid=mw.util.getParamValue('rcid',patrolhref);if(rcid){var patrolstat=new Morebits.status(wgULS('标记页面为已巡查','標記頁面為已巡查'));var wikipedia_api=new Morebits.wiki.api(wgULS('进行中…','進行中…'),{action:'patrol',rcid:rcid,token:mw.user.tokens.get('patrolToken')},null,patrolstat);wikipedia_api.post();}};this.revert=function(onSuccess,onFailure){ctx.onSaveSuccess=onSuccess;ctx.onSaveFailure=onFailure||emptyFunction;if(!ctx.revertOldID){ctx.statusElement.error("内部错误:回退前未提供修订版本ID!");ctx.onSaveFailure(this);return;}
ctx.editMode='revert';this.load(fnAutoSave,ctx.onSaveFailure);};this.move=function(onSuccess,onFailure){ctx.onMoveSuccess=onSuccess;ctx.onMoveFailure=onFailure||emptyFunction;if(!ctx.editSummary){ctx.statusElement.error("内部错误:移动前未提供理由(使用setEditSummary函数)!");ctx.onMoveFailure(this);return;}
if(!ctx.moveDestination){ctx.statusElement.error("内部错误:移动前未指定目标页面!");ctx.onMoveFailure(this);return;}
var query={action:'query',prop:'info',intoken:'move',titles:ctx.pageName};if(ctx.followRedirect){query.redirects='';}
if(Morebits.userIsInGroup('sysop')){query.inprop='protection';}
ctx.moveApi=new Morebits.wiki.api(wgULS("抓取移动令牌…","擷取移動權杖…"),query,fnProcessMove,ctx.statusElement,ctx.onMoveFailure);ctx.moveApi.setParent(this);ctx.moveApi.post();};this.deletePage=function(onSuccess,onFailure){ctx.onDeleteSuccess=onSuccess;ctx.onDeleteFailure=onFailure||emptyFunction;if(!Morebits.userIsInGroup('sysop')){ctx.statusElement.error("不能删除页面:只有管理员可进行该操作");ctx.onDeleteFailure(this);return;}
if(!ctx.editSummary){ctx.statusElement.error("内部错误:删除前未提供理由(使用setEditSummary函数)!");ctx.onDeleteFailure(this);return;}
if(fnCanUseMwUserToken('delete')){fnProcessDelete.call(this,this);}else{var query={action:'query',prop:'info',inprop:'protection',intoken:'delete',titles:ctx.pageName};if(ctx.followRedirect){query.redirects='';}
ctx.deleteApi=new Morebits.wiki.api(wgULS("抓取删除令牌…","擷取刪除權杖…"),query,fnProcessDelete,ctx.statusElement,ctx.onDeleteFailure);ctx.deleteApi.setParent(this);ctx.deleteApi.post();}};this.protect=function(onSuccess,onFailure){ctx.onProtectSuccess=onSuccess;ctx.onProtectFailure=onFailure||emptyFunction;if(!Morebits.userIsInGroup('sysop')){ctx.statusElement.error("不能保护页面:只有管理员可进行该操作");ctx.onProtectFailure(this);return;}
if(!ctx.protectEdit&&!ctx.protectMove&&!ctx.protectCreate){ctx.statusElement.error("内部错误:调用protect()前未设置编辑和/或移动和/或白纸保护!");ctx.onProtectFailure(this);return;}
if(!ctx.editSummary){ctx.statusElement.error("内部错误:保护前未提供理由(使用setEditSummary函数)!");ctx.onProtectFailure(this);return;}
var query={action:'query',prop:'info',inprop:'protection',intoken:'protect',titles:ctx.pageName,watchlist:ctx.watchlistOption};if(ctx.followRedirect){query.redirects='';}
ctx.protectApi=new Morebits.wiki.api(wgULS("抓取保护令牌…","擷取保護權杖…"),query,fnProcessProtect,ctx.statusElement,ctx.onProtectFailure);ctx.protectApi.setParent(this);ctx.protectApi.post();};this.stabilize=function(onSuccess,onFailure){ctx.onStabilizeSuccess=onSuccess;ctx.onStabilizeFailure=onFailure||emptyFunction;if(!Morebits.userIsInGroup('sysop')){ctx.statusElement.error("不能应用FlaggedRevs设定:只有管理员能这么做");ctx.onStabilizeFailure(this);return;}
if(!ctx.flaggedRevs){ctx.statusElement.error("内部错误:调用stabilize()前必须设置flaggedRevs!");ctx.onStabilizeFailure(this);return;}
if(!ctx.editSummary){ctx.statusElement.error("内部错误:调用stabilize()前未提供理由(用setEditSummary函数)!");ctx.onStabilizeFailure(this);return;}
var query={action:'query',prop:'info|flagged',intoken:'edit',titles:ctx.pageName};if(ctx.followRedirect){query.redirects='';}
ctx.stabilizeApi=new Morebits.wiki.api("抓取stabilize令牌…",query,fnProcessStabilize,ctx.statusElement,ctx.onStabilizeFailure);ctx.stabilizeApi.setParent(this);ctx.stabilizeApi.post();};var fnCanUseMwUserToken=function(action){if(ctx.followRedirect&&(action!=='edit'||(ctx.editMode!=='append'&&ctx.editMode!=='prepend'))){return false;}
if(Morebits.userIsInGroup('sysop')&&!ctx.suppressProtectWarning){if(Morebits.string.toUpperCaseFirstChar(mw.config.get('wgPageName')).replace(/ /g,'_').trim()!==Morebits.string.toUpperCaseFirstChar(ctx.pageName).replace(/ /g,'_').trim()){return false;}
var editRestriction=mw.config.get('wgRestrictionEdit');if(!editRestriction||editRestriction.indexOf('sysop')!==-1){return false;}}
return!!mw.user.tokens.get('editToken');};var fnAutoSave=function(pageobj){pageobj.save(ctx.onSaveSuccess,ctx.onSaveFailure);};var fnLoadSuccess=function(){var xml=ctx.loadApi.getXML();if(!fnCheckPageName(xml,ctx.onLoadFailure)){return;}
ctx.pageExists=($(xml).find('page').attr('missing')!=="");if(ctx.pageExists){ctx.pageText=$(xml).find('rev').text();}else{ctx.pageText='';}
if(Morebits.userIsInGroup('sysop')){var editprot=$(xml).find('pr[type="edit"]');if(editprot.length>0&&editprot.attr('level')==='sysop'){ctx.fullyProtected=editprot.attr('expiry');}else{ctx.fullyProtected=false;}}
ctx.editToken=$(xml).find('page').attr('edittoken');if(!ctx.editToken){ctx.statusElement.error(wgULS("未能抓取编辑令牌。","未能擷取編輯權杖。"));ctx.onLoadFailure(this);return;}
ctx.loadTime=$(xml).find('page').attr('starttimestamp');if(!ctx.loadTime){ctx.statusElement.error(wgULS("未能抓取起始时间戳。","未能擷取起始時間戳"));ctx.onLoadFailure(this);return;}
ctx.lastEditTime=$(xml).find('rev').attr('timestamp');ctx.revertCurID=$(xml).find('page').attr('lastrevid');if(ctx.editMode==='revert'){ctx.revertCurID=$(xml).find('rev').attr('revid');if(!ctx.revertCurID){ctx.statusElement.error(wgULS("未能抓取当前修订版本ID。","未能擷取目前變更版本ID。"));ctx.onLoadFailure(this);return;}
ctx.revertUser=$(xml).find('rev').attr('user');if(!ctx.revertUser){if($(xml).find('rev').attr('userhidden')===""){ctx.revertUser=wgULS("<用户名已隐藏>","<用戶名已隱藏>");}else{ctx.statusElement.error(wgULS("未能抓取此修订版本的编辑者。","未能擷取此變更版本的編輯者。"));ctx.onLoadFailure(this);return;}}
ctx.editSummary="[[WP:UNDO|取消]]由 "+ctx.revertUser+" 所做出的"+wgULS("修订 ","變更 ")+ctx.revertOldID+":"+ctx.editSummary;}
ctx.pageLoaded=true;ctx.onLoadSuccess(this);};var fnCheckPageName=function(xml,onFailure){if(!onFailure){onFailure=emptyFunction;}
if($(xml).find('page').attr('invalid')){ctx.statusElement.error(wgULS("标题不合法:","標題不合法:")+ctx.pageName);onFailure(this);return false;}
if($(xml).find('page').attr('title')){var resolvedName=$(xml).find('page').attr('title');if($(xml).find('redirects').length>0){Morebits.status.info(wgULS("信息","資訊"),wgULS("从 ","從 ")+ctx.pageName+" 重定向到 "+resolvedName);}
ctx.pageName=resolvedName;}
else{ctx.statusElement.error(wgULS("不能解释页面的重定向:","不能解釋頁面的重定向:")+ctx.pageName);onFailure(this);++Morebits.wiki.numberOfActionsLeft;return false;}
return true;};var fnSaveSuccess=function(){ctx.editMode='all';var xml=ctx.saveApi.getXML();if($(xml).find('edit').attr('result')==="Success"){var link=document.createElement('a');link.setAttribute('href',mw.util.getUrl(ctx.pageName));link.appendChild(document.createTextNode(ctx.pageName));ctx.statusElement.info(['完成(',link,')']);if(ctx.onSaveSuccess){ctx.onSaveSuccess(this);}
return;}
var $editNode=$(xml).find('edit');var blacklist=$editNode.attr('spamblacklist');if(blacklist){var code=document.createElement('code');code.style.fontFamily="monospace";code.appendChild(document.createTextNode(blacklist));ctx.statusElement.error(wgULS(['不能保存页面,因URL ',code,' 在垃圾黑名单中。'],['不能儲存頁面,因URL ',code,' 在垃圾黑名單中。']));}else if($(xml).find('captcha').length>0){ctx.statusElement.error(wgULS("不能保存页面,因服务器试图让您完成一个全自动区分计算机和人类的图灵测试。","不能儲存頁面,因伺服器試圖讓您完成一個全自動區分電腦和人類的圖靈測試。"));}else if($editNode.attr('code')==='abusefilter-disallowed'){ctx.statusElement.error(wgULS('编辑被防滥用过滤器规则“'+$editNode.attr('info').substring(17)+'”阻止。如果您认为您的该次编辑是有意义的,请至 Wikipedia:防滥用过滤器/错误报告 提报。','編輯被防濫用過濾器規則「'+$editNode.attr('info').substring(17)+'」阻止。如果您認為您的該次編輯是有意義的,請至 Wikipedia:防濫用過濾器/錯誤報告 提報。'));}else if($editNode.attr('info').indexOf('Hit AbuseFilter:')===0){var div=document.createElement('div');div.className="toccolours";div.style.fontWeight="normal";div.style.color="black";div.innerHTML=$editNode.attr('warning');ctx.statusElement.error(wgULS(['防滥用过滤器给出了如下警告:',div,'如果您仍希望做出该编辑,请尝试重新提交,根据过滤器的设置您可能可以作出此编辑。'],['防濫用過濾器給出了如下警告:',div,'如果您仍希望做出該編輯,請嘗試重新提交,根據過濾器的設定您可能可以作出此編輯。']));}else{ctx.statusElement.error(wgULS("保存页面时由API得到未知错误","儲存頁面時由API得到未知錯誤"));}
++Morebits.wiki.numberOfActionsLeft;ctx.onSaveFailure(this);};var fnSaveError=function(){var errorCode=ctx.saveApi.getErrorCode();if(errorCode==="editconflict"&&ctx.conflictRetries++<ctx.maxConflictRetries){var purgeQuery={action:'purge',titles:ctx.pageName};var purgeApi=new Morebits.wiki.api(wgULS("检测到编辑冲突,更新服务器缓存","檢測到編輯衝突,更新伺服器快取"),purgeQuery,null,ctx.statusElement);purgeApi.post({async:false});--Morebits.wiki.numberOfActionsLeft;ctx.statusElement.info(wgULS("检测到编辑冲突,重试修改","檢測到編輯衝突,重試修改"));if(fnCanUseMwUserToken('edit')){ctx.saveApi.post();}else{ctx.loadApi.post();}}else if(errorCode==="notoken"&&ctx.conflictRetries++<ctx.maxConflictRetries){ctx.statusElement.info(wgULS("编辑令牌不可用,重试","編輯權杖不可用,重試"));--Morebits.wiki.numberOfActionsLeft;if(fnCanUseMwUserToken('edit')){this.load(fnAutoSave,ctx.onSaveFailure);}else{ctx.loadApi.post();}}else if(errorCode==="undefined"&&ctx.retries++<ctx.maxRetries){ctx.statusElement.info(wgULS("保存失败,重试","儲存失敗,重試"));--Morebits.wiki.numberOfActionsLeft;ctx.saveApi.post();}else{if(errorCode==="protectedpage"){ctx.statusElement.error(wgULS("不能保存修改:页面被全保护","不能儲存修改:頁面被全保護"));}else if(errorCode==="hookaborted"){ctx.statusElement.error(wgULS("不能保存修改:被防滥用过滤器阻止","不能儲存修改:被防濫用過濾器阻止"));}else{ctx.statusElement.error(wgULS("不能保存修改:","不能儲存修改:")+ctx.saveApi.getErrorText());}
ctx.editMode='all';if(ctx.onSaveFailure){ctx.onSaveFailure(this);}}};var fnLookupCreatorSuccess=function(){var xml=ctx.lookupCreatorApi.getXML();if(!fnCheckPageName(xml)){return;}
ctx.creator=$(xml).find('rev').attr('user');if(!ctx.creator){ctx.statusElement.error(wgULS("不能获取页面创建者的名字","無法取得頁面建立者的名字"));return;}
ctx.onLookupCreatorSuccess(this);};var fnProcessMove=function(){var xml=ctx.moveApi.getXML();if($(xml).find('page').attr('missing')===""){ctx.statusElement.error(wgULS("不能移动页面,因其已不存在","無法移動頁面,因其已不存在"));ctx.onMoveFailure(this);return;}
if(Morebits.userIsInGroup('sysop')){var editprot=$(xml).find('pr[type="edit"]');if(editprot.length>0&&editprot.attr('level')==='sysop'&&!ctx.suppressProtectWarning&&!confirm(wgULS('您即将移动全保护页面“','您即將移動全保護頁面「')+ctx.pageName+wgULS('”','」')+
(editprot.attr('expiry')==='infinity'?'(永久)':('(到期:'+editprot.attr('expiry')+')'))+
wgULS('。\n\n点击确定以确定,或点击取消以取消。','。\n\n點選確定以繼續,或點選取消以取消。'))){ctx.statusElement.error(wgULS("对全保护页面的移动已取消。","對全保護頁面的移動已取消。"));ctx.onMoveFailure(this);return;}}
var moveToken=$(xml).find('page').attr('movetoken');if(!moveToken){ctx.statusElement.error(wgULS("不能抓取移动令牌。","不能擷取移動權杖。"));ctx.onMoveFailure(this);return;}
var query={'action':'move','tags':ctx.tags,'from':$(xml).find('page').attr('title'),'to':ctx.moveDestination,'token':moveToken,'reason':ctx.editSummary};if(ctx.moveTalkPage){query.movetalk='true';}
if(ctx.moveSubpages){query.movesubpages='true';}
if(ctx.moveSuppressRedirect){query.noredirect='true';}
if(ctx.watchlistOption==='watch'){query.watch='true';}
ctx.moveProcessApi=new Morebits.wiki.api(wgULS("移动页面…","移動頁面…"),query,ctx.onMoveSuccess,ctx.statusElement,ctx.onMoveFailure);ctx.moveProcessApi.setParent(this);ctx.moveProcessApi.post();};var fnProcessDelete=function(){var pageTitle,token;if(fnCanUseMwUserToken('delete')){token=mw.user.tokens.get('editToken');pageTitle=ctx.pageName;}else{var xml=ctx.deleteApi.getXML();if($(xml).find('page').attr('missing')===""){ctx.statusElement.error(wgULS("不能删除页面,因其已不存在","不能刪除頁面,因其已不存在"));ctx.onDeleteFailure(this);return;}
var editprot=$(xml).find('pr[type="edit"]');if(editprot.length>0&&editprot.attr('level')==='sysop'&&!ctx.suppressProtectWarning&&!confirm(wgULS('您即将删除全保护页面“'+ctx.pageName+"”",'您即將刪除全保護頁面「'+ctx.pageName+"」")+
(editprot.attr('expiry')==='infinity'?'(永久)':('(到期 '+editprot.attr('expiry')+')'))+
wgULS('。\n\n点击确定以确定,或点击取消以取消。','。\n\n點選確定以確定,或點選取消以取消。'))){ctx.statusElement.error(wgULS("对全保护页面的删除已取消。","對全保護頁面的刪除已取消。"));ctx.onDeleteFailure(this);return;}
token=$(xml).find('page').attr('deletetoken');if(!token){ctx.statusElement.error(wgULS("不能抓取删除令牌。","不能擷取刪除權杖。"));ctx.onDeleteFailure(this);return;}
pageTitle=$(xml).find('page').attr('title');}
var query={'action':'delete','tags':ctx.tags,'title':pageTitle,'token':token,'reason':ctx.editSummary};if(ctx.watchlistOption==='watch'){query.watch='true';}
ctx.deleteProcessApi=new Morebits.wiki.api(wgULS("删除页面…","刪除頁面…"),query,ctx.onDeleteSuccess,ctx.statusElement,fnProcessDeleteError);ctx.deleteProcessApi.setParent(this);ctx.deleteProcessApi.post();};var fnProcessDeleteError=function(){var errorCode=ctx.deleteProcessApi.getErrorCode();if(errorCode==="internal_api_error_DBQueryError"&&ctx.retries++<ctx.maxRetries){ctx.statusElement.info(wgULS("数据库查询错误,重试","資料庫查詢錯誤,重試"));--Morebits.wiki.numberOfActionsLeft;ctx.deleteProcessApi.post();}else if(errorCode==="badtoken"){ctx.statusElement.error(wgULS("无效令牌,请刷新页面并重试。","無效權杖,請重新整理頁面並重試。"));if(ctx.onDeleteFailure){ctx.onDeleteFailure.call(this,this,ctx.deleteProcessApi);}}else if(errorCode==="missingtitle"){ctx.statusElement.error(wgULS("不能删除页面,因其已不存在","不能刪除頁面,因其已不存在"));if(ctx.onDeleteFailure){ctx.onDeleteFailure.call(this,ctx.deleteProcessApi);}}else{ctx.statusElement.error(wgULS("不能删除页面:","不能刪除頁面:")+ctx.deleteProcessApi.getErrorText());if(ctx.onDeleteFailure){ctx.onDeleteFailure.call(this,ctx.deleteProcessApi);}}};var fnProcessProtect=function(){var xml=ctx.protectApi.getXML();var missing=($(xml).find('page').attr('missing')==="");if(((ctx.protectEdit||ctx.protectMove)&&missing)){ctx.statusElement.error(wgULS("不能保护页面,因其已不存在","不能保護頁面,因其已不存在"));ctx.onProtectFailure(this);return;}
if(ctx.protectCreate&&!missing){ctx.statusElement.error(wgULS("不能白纸保护页面,因其已存在","不能白紙保護頁面,因其已存在"));ctx.onProtectFailure(this);return;}
var protectToken=$(xml).find('page').attr('protecttoken');if(!protectToken){ctx.statusElement.error(wgULS("不能抓取保护令牌。","不能擷取保護權杖。"));ctx.onProtectFailure(this);return;}
var prs=$(xml).find('pr');var editprot=prs.filter('[type="edit"]');var moveprot=prs.filter('[type="move"]');var createprot=prs.filter('[type="create"]');var protections=[],expirys=[];if(ctx.protectEdit){protections.push('edit='+ctx.protectEdit.level);expirys.push(ctx.protectEdit.expiry);}else if(editprot.length){protections.push('edit='+editprot.attr("level"));expirys.push(editprot.attr("expiry").replace("infinity","indefinite"));}
if(ctx.protectMove){protections.push('move='+ctx.protectMove.level);expirys.push(ctx.protectMove.expiry);}else if(moveprot.length){protections.push('move='+moveprot.attr("level"));expirys.push(moveprot.attr("expiry").replace("infinity","indefinite"));}
if(ctx.protectCreate){protections.push('create='+ctx.protectCreate.level);expirys.push(ctx.protectCreate.expiry);}else if(createprot.length){protections.push('create='+createprot.attr("level"));expirys.push(createprot.attr("expiry").replace("infinity","indefinite"));}
var query={action:'protect',tags:ctx.tags,title:$(xml).find('page').attr('title'),token:protectToken,protections:protections.join('|'),expiry:expirys.join('|'),reason:ctx.editSummary};if(ctx.protectCascade){query.cascade='true';}
if(ctx.watchlistOption==='watch'){query.watch='true';}
ctx.protectProcessApi=new Morebits.wiki.api(wgULS("保护页面…","保護頁面…"),query,ctx.onProtectSuccess,ctx.statusElement,ctx.onProtectFailure);ctx.protectProcessApi.setParent(this);ctx.protectProcessApi.post();};var fnProcessStabilize=function(){var xml=ctx.stabilizeApi.getXML();var missing=($(xml).find('page').attr('missing')==="");if(missing){ctx.statusElement.error("不能保护页面,因其已不存在");ctx.onStabilizeFailure(this);return;}
var stabilizeToken=$(xml).find('page').attr('edittoken');if(!stabilizeToken){ctx.statusElement.error("不能抓取stabilize令牌。");ctx.onStabilizeFailure(this);return;}
var query={action:'stabilize',title:$(xml).find('page').attr('title'),token:stabilizeToken,protectlevel:ctx.flaggedRevs.level,expiry:ctx.flaggedRevs.expiry,reason:ctx.editSummary};if(ctx.watchlistOption==='watch'){query.watch='true';}
ctx.stabilizeProcessApi=new Morebits.wiki.api("配置stabilization设定…",query,ctx.onStabilizeSuccess,ctx.statusElement,ctx.onStabilizeFailure);ctx.stabilizeProcessApi.setParent(this);ctx.stabilizeProcessApi.post();};};Morebits.wiki.flow=function(pageName,currentAction){if(!currentAction){currentAction='打开页面“'+pageName+'”';}
var ctx={pageName:pageName,callbackParameters:null,statusElement:new Morebits.status(currentAction),header:null,headerLastRevision:null,topic:null,content:null,headerLoaded:false,editToken:null,fullyProtected:false,suppressProtectWarning:false,onNewTopicSuccess:null,onNewTopicFailure:null,onViewHeaderSuccess:null,onViewHeaderFailure:null,onEditHeaderSuccess:null,onEditHeaderFailure:null,newTopicApi:null,viewHeaderApi:null,editHeaderApi:null,};var emptyFunction=function(){};this.getPageName=function(){return ctx.pageName;};this.getHeader=function(){return ctx.header;};this.setHeader=function(header){ctx.header=header;};this.getTopic=function(){return ctx.topic;};this.setTopic=function(topic){ctx.topic=topic;};this.getContent=function(){return ctx.content;};this.setContent=function(content){ctx.content=content;};this.setCallbackParameters=function(callbackParameters){ctx.callbackParameters=callbackParameters;};this.getCallbackParameters=function(){return ctx.callbackParameters;};this.getStatusElement=function(){return ctx.statusElement;};this.newTopic=function(onSuccess,onFailure){ctx.onNewTopicSuccess=onSuccess;ctx.onNewTopicFailure=onFailure||emptyFunction;var query={action:'flow',page:ctx.pageName,token:mw.user.tokens.get('editToken'),submodule:'new-topic',nttopic:ctx.topic,ntcontent:ctx.content,ntformat:'wikitext',};ctx.newTopicApi=new Morebits.wiki.api("留言…",query,fnNewTopicSuccess,ctx.statusElement,fnNewTopicError);ctx.newTopicApi.setParent(this);ctx.newTopicApi.post();};this.viewHeader=function(onSuccess,onFailure){ctx.onViewHeaderSuccess=onSuccess;ctx.onViewHeaderFailure=onFailure||emptyFunction;if(!onSuccess){ctx.statusElement.error("内部错误:未给viewHeader()提供onSuccess回调函数!");ctx.onViewHeaderFailure(this);return;}
var query={action:'flow',submodule:'view-header',page:ctx.pageName,vhformat:'wikitext',};ctx.viewHeaderApi=new Morebits.wiki.api(wgULS('抓取Flow描述…','擷取Flow描述…'),query,fnViewHeaderSuccess,ctx.statusElement,ctx.onViewHeaderFailure);ctx.viewHeaderApi.setParent(this);ctx.viewHeaderApi.post();};this.editHeader=function(onSuccess,onFailure){ctx.onEditHeaderSuccess=onSuccess;ctx.onEditHeaderFailure=onFailure||emptyFunction;var query={action:'flow',page:ctx.pageName,token:mw.user.tokens.get('editToken'),submodule:'edit-header',ehprev_revision:ctx.headerLastRevision,ehcontent:ctx.header,ehformat:'wikitext',};ctx.editHeaderApi=new Morebits.wiki.api(wgULS("编辑Flow讨论页描述…","編輯Flow討論頁描述…"),query,fnEditHeaderSuccess,ctx.statusElement,fnEditHeaderError);ctx.editHeaderApi.setParent(this);ctx.editHeaderApi.post();};var fnNewTopicSuccess=function(){var xml=ctx.newTopicApi.getXML();if($(xml).find('new-topic').attr('status')==="ok"){var link=document.createElement('a');link.setAttribute('href',mw.util.getUrl(ctx.pageName));link.appendChild(document.createTextNode(ctx.pageName));ctx.statusElement.info(['完成(',link,')']);if(ctx.onNewTopicSuccess){ctx.onNewTopicSuccess(this);}}else{ctx.statusElement.error(wgULS("保存页面时由API得到未知错误","儲存頁面時由API得到未知錯誤"));++Morebits.wiki.numberOfActionsLeft;ctx.onNewTopicFailure(this);}};var fnNewTopicError=function(){var errorCode=ctx.newTopicApi.getErrorCode();if(errorCode==='invalid-page'){ctx.statusElement.error(wgULS("内部错误:不是Flow页面,无法留言","內部錯誤:不是Flow頁面,無法留言"));}else if(errorCode==='block'){ctx.statusElement.error(wgULS("无法留言,因讨论页被保护","無法留言,因討論頁被保護"));}else if(errorCode==='spamfilter'){ctx.statusElement.error(wgULS("无法留言,因为需要验证码或已经触发URL黑名单","無法留言,因為需要驗證碼或已經觸發URL黑名單"));}else{ctx.statusElement.error(wgULS("留言时由API得到未知错误","留言時由API得到未知錯誤"));}
if(ctx.onNewTopicFailure){ctx.onNewTopicFailure(this);}};var fnViewHeaderSuccess=function(){var xml=ctx.viewHeaderApi.getXML();ctx.header=$(xml).find('content').attr('content');ctx.headerLastRevision=$(xml).find('revision').attr('revisionId');ctx.headerLoaded=true;ctx.onViewHeaderSuccess(this);};var fnEditHeaderSuccess=function(){var xml=ctx.editHeaderApi.getXML();if($(xml).find('edit-header').attr('status')==="ok"){ctx.statusElement.info('完成');ctx.headerLastRevision=$(xml).find('header').attr('header-revision-id');if(ctx.onEditHeaderSuccess){ctx.onEditHeaderSuccess(this);}}else{ctx.statusElement.error(wgULS("保存Flow讨论页描述时由API得到未知错误","儲存Flow討論頁描述時由API得到未知錯誤"));++Morebits.wiki.numberOfActionsLeft;ctx.onEditHeaderFailure(this);}};var fnEditHeaderError=function(){var errorCode=ctx.editHeaderApi.getErrorCode();if(errorCode==='invalid-page'){ctx.statusElement.error(wgULS("内部错误:不是Flow页面,无法编辑描述","內部錯誤:不是Flow頁面,無法編輯描述"));}else if(errorCode==='block'){ctx.statusElement.error(wgULS("无法编辑描述,因讨论页被保护","無法編輯描述,因討論頁被保護"));}else if(errorCode==='spamfilter'){ctx.statusElement.error(wgULS("无法编辑描述,因为需要验证码或已经触发URL黑名单","無法編輯描述,因為需要驗證碼或已經觸發URL黑名單"));}else{ctx.statusElement.error(wgULS("编辑描述时由API得到未知错误","編輯描述時由API得到未知錯誤"));}
if(ctx.onEditHeaderFailure){ctx.onEditHeaderFailure(this);}};};Morebits.wiki.flow.check=function(title,callbackOnFlow,callbackOnNonFlow,onError){var callback=function(obj){var responseXML=obj.responseXML;var pages=responseXML.getElementsByTagName('page');if(pages.length>0){var model=pages[0].getAttribute('contentmodel');if(model==='flow-board'){if(typeof callbackOnFlow==='function'){callbackOnFlow();}}else if(model!==null){if(typeof callbackOnNonFlow==='function'){callbackOnNonFlow();}}else{if(typeof onError==='function'){obj.statelem.error("内部错误:页面标题无效");onError(obj);}}}else{if(typeof onError==='function'){obj.statelem.error("内部错误:调用API时失败");onError(obj);}}};var statusElement=new Morebits.status(wgULS('检查是否为Flow页面','檢查是否為Flow頁面'));var checkApi=new Morebits.wiki.api(wgULS("查询页面信息","檢索頁面信息"),{action:'query',prop:'info',titles:title,},callback,statusElement,onError);checkApi.post();};Morebits.wiki.flow.relevantUserName=function(){var name=mw.config.get('wgRelevantUserName');if(name){return name;}else if(mw.config.get('wgPageContentModel')==='flow-board'){var title=$('a','#contentSub').attr('title');if(title&&title.indexOf('User talk:')===0){return title.substr(10);}else{return null;}}else{return null;}};Morebits.wiki.preview=function(previewbox){this.previewbox=previewbox;$(previewbox).addClass("morebits-previewbox").hide();this.beginRender=function(wikitext,pageTitle){$(previewbox).show();var statusspan=document.createElement('span');previewbox.appendChild(statusspan);Morebits.status.init(statusspan);var pageName=mw.config.get('wgPageName');if(mw.config.get('wgPageContentModel')!=='wikitext'){pageName='Draft:'+pageName;}
var query={action:'parse',prop:'text',pst:'true',text:wikitext,title:pageTitle||pageName};var renderApi=new Morebits.wiki.api(wgULS("加载中…","載入中…"),query,fnRenderSuccess,new Morebits.status(wgULS("预览","預覽")));renderApi.post();};var fnRenderSuccess=function(apiobj){var xml=apiobj.getXML();var html=$(xml).find('text').text();if(!html){apiobj.statelem.error(wgULS("加载预览失败,或模板被清空","載入預覽失敗,或模板被清空"));return;}
previewbox.innerHTML=html;$(previewbox).find("a").attr("target","_blank");};this.closePreview=function(){$(previewbox).empty().hide();};};Morebits.wikitext={};Morebits.wikitext.template={parse:function(text,start){var count=-1;var level=-1;var equals=-1;var current='';var result={name:'',parameters:{}};var key,value;for(var i=start;i<text.length;++i){var test3=text.substr(i,3);if(test3==='{{{'){current+='{{{';i+=2;++level;continue;}
if(test3==='}}}'){current+='}}}';i+=2;--level;continue;}
var test2=text.substr(i,2);if(test2==='{{'||test2==='[['){current+=test2;++i;++level;continue;}
if(test2===']]'){current+=test2;++i;--level;continue;}
if(test2==='}}'){current+=test2;++i;--level;if(level<=0){if(count===-1){result.name=current.substring(2).trim();++count;}else{if(equals!==-1){key=current.substring(0,equals).trim();value=current.substring(equals).trim();result.parameters[key]=value;equals=-1;}else{result.parameters[count]=current;++count;}}
break;}
continue;}
if(text.charAt(i)==='|'&&level<=0){if(count===-1){result.name=current.substring(2).trim();++count;}else{if(equals!==-1){key=current.substring(0,equals).trim();value=current.substring(equals+1).trim();result.parameters[key]=value;equals=-1;}else{result.parameters[count]=current;++count;}}
current='';}else if(equals===-1&&text.charAt(i)==='='&&level<=0){equals=current.length;current+=text.charAt(i);}else{current+=text.charAt(i);}}
return result;}};Morebits.wikitext.page=function mediawikiPage(text){this.text=text;};Morebits.wikitext.page.prototype={text:'',removeLink:function(link_target){var first_char=link_target.substr(0,1);var link_re_string="["+first_char.toUpperCase()+first_char.toLowerCase()+']'+RegExp.escape(link_target.substr(1),true);var link_simple_re=new RegExp("\\[\\[:?("+link_re_string+")\\]\\]",'g');var link_named_re=new RegExp("\\[\\[:?"+link_re_string+"\\|(.+?)\\]\\]",'g');this.text=this.text.replace(link_simple_re,"$1").replace(link_named_re,"$1");},commentOutImage:function(image,reason){var unbinder=new Morebits.unbinder(this.text);unbinder.unbind('<!--','-->');reason=reason?(reason+':'):'';var first_char=image.substr(0,1);var image_re_string="["+first_char.toUpperCase()+first_char.toLowerCase()+']'+RegExp.escape(image.substr(1),true);var links_re=new RegExp("\\[\\[(?:[Ii]mage|[Ff]ile|文件|檔案):\\s*"+image_re_string);var allLinks=Morebits.array.uniq(Morebits.string.splitWeightedByKeys(unbinder.content,'[[',']]'));for(var i=0;i<allLinks.length;++i){if(links_re.test(allLinks[i])){var replacement='<!-- '+reason+allLinks[i]+' -->';unbinder.content=unbinder.content.replace(allLinks[i],replacement,'g');}}
unbinder.unbind('<!--','-->');var gallery_image_re=new RegExp("(^\\s*(?:[Ii]mage|[Ff]ile|文件|檔案):\\s*"+image_re_string+".*?$)",'mg');unbinder.content=unbinder.content.replace(gallery_image_re,"<!-- "+reason+"$1 -->");unbinder.unbind('<!--','-->');var free_image_re=new RegExp("(\\|\\s*(?:[\\w\\s]+\\=)?\\s*(?:(?:[Ii]mage|[Ff]ile|文件|檔案):\\s*)?"+image_re_string+")",'mg');unbinder.content=unbinder.content.replace(free_image_re,"<!-- "+reason+"$1 -->");this.text=unbinder.rebind();},addToImageComment:function(image,data){var first_char=image.substr(0,1);var first_char_regex=RegExp.escape(first_char,true);if(first_char.toUpperCase()!==first_char.toLowerCase()){first_char_regex='['+RegExp.escape(first_char.toUpperCase(),true)+RegExp.escape(first_char.toLowerCase(),true)+']';}
var image_re_string="(?:[Ii]mage|[Ff]ile|文件|檔案):\\s*"+first_char_regex+RegExp.escape(image.substr(1),true);var links_re=new RegExp("\\[\\["+image_re_string);var allLinks=Morebits.array.uniq(Morebits.string.splitWeightedByKeys(this.text,'[[',']]'));for(var i=0;i<allLinks.length;++i){if(links_re.test(allLinks[i])){var replacement=allLinks[i];replacement=replacement.replace(/\]\]$/,'|'+data+']]');this.text=this.text.replace(allLinks[i],replacement,'g');}}
var gallery_re=new RegExp("^(\\s*"+image_re_string+'.*?)\\|?(.*?)$','mg');var newtext="$1|$2 "+data;this.text=this.text.replace(gallery_re,newtext);},removeTemplate:function(template){var first_char=template.substr(0,1);var template_re_string="(?:[Tt]emplate:|模板:)?\\s*["+first_char.toUpperCase()+first_char.toLowerCase()+']'+RegExp.escape(template.substr(1),true);var links_re=new RegExp("\\{\\{"+template_re_string);var allTemplates=Morebits.array.uniq(Morebits.string.splitWeightedByKeys(this.text,'{{','}}',['{{{','}}}']));for(var i=0;i<allTemplates.length;++i){if(links_re.test(allTemplates[i])){this.text=this.text.replace(allTemplates[i],'','g');}}},getText:function(){return this.text;}};Morebits.queryString=function QueryString(qString){this.string=qString;this.params={};if(!qString.length){return;}
qString.replace(/\+/,' ');var args=qString.split('&');for(var i=0;i<args.length;++i){var pair=args[i].split('=');var key=decodeURIComponent(pair[0]),value=key;if(pair.length===2){value=decodeURIComponent(pair[1]);}
this.params[key]=value;}};Morebits.queryString.staticstr=null;Morebits.queryString.staticInit=function(){if(!Morebits.queryString.staticstr){Morebits.queryString.staticstr=new Morebits.queryString(location.search.substring(1));}};Morebits.queryString.get=function(key){Morebits.queryString.staticInit();return Morebits.queryString.staticstr.get(key);};Morebits.queryString.prototype.get=function(key){return this.params[key]?this.params[key]:null;};Morebits.queryString.exists=function(key){Morebits.queryString.staticInit();return Morebits.queryString.staticstr.exists(key);};Morebits.queryString.prototype.exists=function(key){return this.params[key]?true:false;};Morebits.queryString.equals=function(key,value){Morebits.queryString.staticInit();return Morebits.queryString.staticstr.equals(key,value);};Morebits.queryString.prototype.equals=function(key,value){return this.params[key]===value?true:false;};Morebits.queryString.toString=function(){Morebits.queryString.staticInit();return Morebits.queryString.staticstr.toString();};Morebits.queryString.prototype.toString=function(){return this.string?this.string:null;};Morebits.queryString.create=function(arr){var resarr=[];var editToken;for(var i in arr){if(arr[i]===undefined){continue;}
var res;if($.isArray(arr[i])){var v=[];for(var j=0;j<arr[i].length;++j){v[j]=encodeURIComponent(arr[i][j]);}
res=v.join('|');}else{res=encodeURIComponent(arr[i]);}
if(i==='token'){editToken=res;}else{resarr.push(encodeURIComponent(i)+'='+res);}}
if(editToken!==undefined){resarr.push('token='+editToken);}
return resarr.join('&');};Morebits.queryString.prototype.create=Morebits.queryString.create;Morebits.status=function Status(text,stat,type){this.textRaw=text;this.text=this.codify(text);this.type=type||'status';this.generate();if(stat){this.update(stat,type);}};Morebits.status.init=function(root){if(!(root instanceof Element)){throw new Error('对象不是一个Element');}
while(root.hasChildNodes()){root.removeChild(root.firstChild);}
Morebits.status.root=root;Morebits.status.errorEvent=null;};Morebits.status.root=null;Morebits.status.onError=function(handler){if($.isFunction(handler)){Morebits.status.errorEvent=handler;}else{throw"Morebits.status.onError:处理程序不是一个函数";}};Morebits.status.prototype={stat:null,text:null,textRaw:null,type:'status',target:null,node:null,linked:false,link:function(){if(!this.linked&&Morebits.status.root){Morebits.status.root.appendChild(this.node);this.linked=true;}},unlink:function(){if(this.linked){Morebits.status.root.removeChild(this.node);this.linked=false;}},codify:function(obj){if(!$.isArray(obj)){obj=[obj];}
var result;result=document.createDocumentFragment();for(var i=0;i<obj.length;++i){if(typeof obj[i]==='string'){result.appendChild(document.createTextNode(obj[i]));}else if(obj[i]instanceof Element){result.appendChild(obj[i]);}}
return result;},update:function(status,type){this.stat=this.codify(status);if(type){this.type=type;if(type==='error'){Morebits.wiki.numberOfActionsLeft=1000;if(Morebits.status.errorEvent){Morebits.status.errorEvent();}
console.error(this.textRaw+": "+status);}}
this.render();},generate:function(){this.node=document.createElement('div');this.node.appendChild(document.createElement('span')).appendChild(this.text);this.node.appendChild(document.createElement('span')).appendChild(document.createTextNode(':'));this.target=this.node.appendChild(document.createElement('span'));this.target.appendChild(document.createTextNode(''));},render:function(){this.node.className='tw_status_'+this.type;while(this.target.hasChildNodes()){this.target.removeChild(this.target.firstChild);}
this.target.appendChild(this.stat);this.link();},status:function(status){this.update(status,'status');},info:function(status){this.update(status,'info');},warn:function(status){this.update(status,'warn');},error:function(status){this.update(status,'error');}};Morebits.status.info=function(text,status){return new Morebits.status(text,status,'info');};Morebits.status.warn=function(text,status){return new Morebits.status(text,status,'warn');};Morebits.status.error=function(text,status){return new Morebits.status(text,status,'error');};Morebits.status.printUserText=function(comments,message){var p=document.createElement('p');p.textContent=message;var div=document.createElement('div');div.className='toccolours';div.style.marginTop='0';div.style.whiteSpace='pre-wrap';div.textContent=comments;p.appendChild(div);Morebits.status.root.appendChild(p);};Morebits.htmlNode=function(type,content,color){var node=document.createElement(type);if(color){node.style.color=color;}
node.appendChild(document.createTextNode(content));return node;};Morebits.checkboxShiftClickSupport=function(jQuerySelector,jQueryContext){var lastCheckbox=null;function clickHandler(event){var thisCb=this;if(event.shiftKey&&lastCheckbox!==null){var cbs=$(jQuerySelector,jQueryContext);var index=-1,lastIndex=-1,i;for(i=0;i<cbs.length;i++){if(cbs[i]===thisCb){index=i;if(lastIndex>-1)
break;}
if(cbs[i]===lastCheckbox){lastIndex=i;if(index>-1)
break;}}
if(index>-1&&lastIndex>-1){var endState=thisCb.checked;var start,finish;if(index<lastIndex){start=index+1;finish=lastIndex;}else{start=lastIndex;finish=index-1;}
for(i=start;i<=finish;i++){cbs[i].checked=endState;}}}
lastCheckbox=thisCb;return true;}
$(jQuerySelector,jQueryContext).click(clickHandler);};Morebits.batchOperation=function(currentAction){var ctx={pageList:null,options:{chunkSize:50,preserveIndividualStatusLines:false},statusElement:new Morebits.status(currentAction||wgULS("执行批量操作","執行批量操作")),worker:null,countStarted:0,countFinished:0,countFinishedSuccess:0,currentChunkIndex:-1,pageChunks:[],running:false};this.getStatusElement=function(){return ctx.statusElement;};this.setPageList=function(pageList){ctx.pageList=pageList;};this.setOption=function(optionName,optionValue){ctx.options[optionName]=optionValue;};this.run=function(worker){if(ctx.running){ctx.statusElement.error(wgULS("批量操作已在运行","批量操作已在執行"));return;}
ctx.running=true;ctx.worker=worker;ctx.countStarted=0;ctx.countFinished=0;ctx.countFinishedSuccess=0;ctx.currentChunkIndex=-1;ctx.pageChunks=[];var total=ctx.pageList.length;if(!total){ctx.statusElement.info(wgULS("没什么要做的","沒什麼要做的"));ctx.running=false;return;}
ctx.pageChunks=Morebits.array.chunk(ctx.pageList,ctx.options.chunkSize);Morebits.wiki.addCheckpoint();ctx.statusElement.status("0%");fnStartNewChunk();};this.workerSuccess=function(apiobj){if(apiobj&&apiobj.getStatusElement){var statelem=apiobj.getStatusElement();if(ctx.options.preserveIndividualStatusLines){if(apiobj.getPageName||apiobj.pageName||(apiobj.query&&apiobj.query.title)){var pageName=apiobj.getPageName?apiobj.getPageName():(apiobj.pageName||apiobj.query.title);var link=document.createElement('a');link.setAttribute('href',mw.util.getUrl(pageName));link.appendChild(document.createTextNode(pageName));statelem.info(['完成(',link,')']);}else{statelem.info('完成');}}else{statelem.unlink();}}
ctx.countFinishedSuccess++;fnDoneOne(apiobj);};this.workerFailure=function(apiobj){fnDoneOne(apiobj);};var thisProxy=this;var fnStartNewChunk=function(){var chunk=ctx.pageChunks[++ctx.currentChunkIndex];if(!chunk){return;}
ctx.countStarted+=chunk.length;chunk.forEach(function(page){ctx.worker(page,thisProxy);});};var fnDoneOne=function(){ctx.countFinished++;var total=ctx.pageList.length;if(ctx.countFinished===total){var statusString="完成("+ctx.countFinishedSuccess+"/"+ctx.countFinished+"操作成功完成)";if(ctx.countFinishedSuccess<ctx.countFinished){ctx.statusElement.warn(statusString);}else{ctx.statusElement.info(statusString);}
Morebits.wiki.removeCheckpoint();ctx.running=false;return;}
if(ctx.countFinished>total){ctx.statusElement.warn(wgULS("完成(多执行了"+(ctx.countFinished-total)+")","完成(多執行了"+(ctx.countFinished-total)+")"));Morebits.wiki.removeCheckpoint();ctx.running=false;return;}
ctx.statusElement.status(parseInt(100*ctx.countFinished/total,10)+"%");if(ctx.countFinished>=(ctx.countStarted-Math.max(ctx.options.chunkSize/10,2))&&Math.floor(ctx.countFinished/ctx.options.chunkSize)>ctx.currentChunkIndex){fnStartNewChunk();}};};Morebits.simpleWindow=function SimpleWindow(width,height){var content=document.createElement('div');this.content=content;content.className='morebits-dialog-content';content.id='morebits-dialog-content-'+Math.round(Math.random()*1e15);this.height=height;$(this.content).dialog({autoOpen:false,buttons:{"占位按钮":function(){}},dialogClass:'morebits-dialog',width:Math.min(parseInt(window.innerWidth,10),parseInt(width?width:800,10)),height:height+20,close:function(event){$(event.target).dialog("destroy").remove();},resizeStart:function(){this.scrollbox=$(this).find(".morebits-scrollbox")[0];if(this.scrollbox){this.scrollbox.style.maxHeight="none";}},resizeEnd:function(){this.scrollbox=null;},resize:function(){this.style.maxHeight="";if(this.scrollbox){this.scrollbox.style.width="";}}});var $widget=$(this.content).dialog("widget");$widget.find("button").each(function(key,value){value.parentNode.removeChild(value);});var buttonspan=document.createElement("span");buttonspan.className="morebits-dialog-buttons";var linksspan=document.createElement("span");linksspan.className="morebits-dialog-footerlinks";$widget.find(".ui-dialog-buttonpane").append(buttonspan,linksspan);$widget.resizable("option","alsoResize","#"+this.content.id+" .morebits-scrollbox, #"+this.content.id);};Morebits.simpleWindow.prototype={buttons:[],height:600,hasFooterLinks:false,scriptName:null,focus:function(){$(this.content).dialog("moveToTop");return this;},close:function(event){if(event){event.preventDefault();}
$(this.content).dialog("close");return this;},display:function(){if(this.scriptName){var $widget=$(this.content).dialog("widget");$widget.find(".morebits-dialog-scriptname").remove();var scriptnamespan=document.createElement("span");scriptnamespan.className="morebits-dialog-scriptname";scriptnamespan.textContent=this.scriptName+" \u00B7 ";$widget.find(".ui-dialog-title").prepend(scriptnamespan);}
var dialog=$(this.content).dialog("open");if(window.setupTooltips&&window.pg&&window.pg.re&&window.pg.re.diff){dialog.parent()[0].ranSetupTooltipsAlready=false;window.setupTooltips(dialog.parent()[0]);}
this.setHeight(this.height);return this;},setTitle:function(title){$(this.content).dialog("option","title",title);return this;},setScriptName:function(name){this.scriptName=name;return this;},setWidth:function(width){$(this.content).dialog("option","width",width);return this;},setHeight:function(height){this.height=height;if(parseInt(getComputedStyle($(this.content).dialog("widget")[0],null).height,10)>window.innerHeight){$(this.content).dialog("option","height",window.innerHeight-2).dialog("option","position","top");}else{$(this.content).dialog("option","height","auto");}
$(this.content).dialog("widget").find(".morebits-dialog-content")[0].style.maxHeight=parseInt(this.height-30,10)+"px";return this;},setContent:function(content){this.purgeContent();this.addContent(content);return this;},addContent:function(content){this.content.appendChild(content);var thisproxy=this;$(this.content).find('input[type="submit"], button[type="submit"]').each(function(key,value){value.style.display="none";var button=document.createElement("button");button.textContent=(value.hasAttribute("value")?value.getAttribute("value"):(value.textContent?value.textContent:"提交"));button.addEventListener("click",function(){value.click();},false);thisproxy.buttons.push(button);});if(this.buttons.length>0){$(this.content).dialog("widget").find(".morebits-dialog-buttons").empty().append(this.buttons)[0].removeAttribute("data-empty");}else{$(this.content).dialog("widget").find(".morebits-dialog-buttons")[0].setAttribute("data-empty","data-empty");}
return this;},purgeContent:function(){this.buttons=[];$(this.content).dialog("widget").find(".morebits-dialog-buttons").empty();while(this.content.hasChildNodes()){this.content.removeChild(this.content.firstChild);}
return this;},addFooterLink:function(text,wikiPage){var $footerlinks=$(this.content).dialog("widget").find(".morebits-dialog-footerlinks");if(this.hasFooterLinks){var bullet=document.createElement("span");bullet.textContent=" \u2022 ";$footerlinks.append(bullet);}
var link=document.createElement("a");link.setAttribute("href",mw.util.getUrl(wikiPage));link.setAttribute("title",wikiPage);link.setAttribute("target","_blank");link.textContent=text;$footerlinks.append(link);this.hasFooterLinks=true;return this;},setModality:function(modal){$(this.content).dialog("option","modal",modal);return this;}};Morebits.simpleWindow.setButtonsEnabled=function(enabled){$(".morebits-dialog-buttons button").prop("disabled",!enabled);};}(window,document,jQuery));if(typeof arguments==="undefined"){window.SimpleWindow=Morebits.simpleWindow;window.QuickForm=Morebits.quickForm;window.Wikipedia=Morebits.wiki;window.Status=Morebits.status;window.QueryString=Morebits.queryString;}
// </nowiki>