2,718
次編輯
(新頁面: // <nowiki> // vim: set noet sts=0 sw=8: /** * morebits.js * =========== * A library full of lots of goodness for user scripts on MediaWiki wikis, including Wikipedia. * * The hig...) |
小 (繁簡轉換) |
||
|
splitWeightedByKeys: function( str, start, end, skip ) {
if( start.length !== end.length ) {
throw new Error( '起始和
}
var level = 0;
skip = [ skip ];
} else {
throw new Error( "不
}
}
Morebits.wikipedia.namespacesFriendly = {
'0': '(
'1': 'Talk',
'2': 'User',
Morebits.wiki.actionCompleted.timeOut = ( typeof window.wpActionCompletedTimeOut === 'undefined' ? 5000 : window.wpActionCompletedTimeOut );
Morebits.wiki.actionCompleted.redirect = null;
Morebits.wiki.actionCompleted.notice = '
Morebits.wiki.actionCompleted.postfix = '已完成';
this.statusText = statusText;
this.errorThrown = errorThrown; // frequently undefined
this.errorText = statusText + '在
this.returnError();
}
returnError: function() {
if ( this.errorCode === "badtoken" ) {
this.statelem.error( "
} else {
this.statelem.error( this.errorText );
if (!currentAction) {
currentAction = '打
}
this.setFollowRedirect = function(followRedirect) {
if (ctx.pageLoaded) {
ctx.statusElement.error("
return;
}
// Need to be able to do something after the page loads
if (!onSuccess) {
ctx.statusElement.error("
ctx.onLoadFailure(this);
return;
}
ctx.loadApi = new Morebits.wiki.api("抓取
ctx.loadApi.setParent(this);
ctx.loadApi.post();
if (!ctx.pageLoaded && !canUseMwUserToken) {
ctx.statusElement.error("
ctx.onSaveFailure(this);
return;
}
if (!ctx.editSummary) {
ctx.statusElement.error("
ctx.onSaveFailure(this);
return;
// shouldn't happen if canUseMwUserToken === true
if (ctx.fullyProtected && !ctx.suppressProtectWarning &&
!confirm('您即
(ctx.fullyProtected === 'infinity' ? '(永久)' : ('(到期:' + ctx.fullyProtected + ')')) +
'。\n\n
ctx.statusElement.error("
ctx.onSaveFailure(this);
return;
}
ctx.saveApi = new Morebits.wiki.api( "保存
ctx.saveApi.setParent(this);
ctx.saveApi.post();
this.lookupCreator = function(onSuccess) {
if (!onSuccess) {
ctx.statusElement.error("
return;
}
}
ctx.lookupCreatorApi = new Morebits.wiki.api("抓取
ctx.lookupCreatorApi.setParent(this);
ctx.lookupCreatorApi.post();
if ( rcid ) {
var patrolstat = new Morebits.status( '
var wikipedia_api = new Morebits.wiki.api( '
action: 'patrol',
rcid: rcid,
if (!ctx.revertOldID) {
ctx.statusElement.error("
ctx.onSaveFailure(this);
return;
if (!ctx.editSummary) {
ctx.statusElement.error("
ctx.onMoveFailure(this);
return;
}
if (!ctx.moveDestination) {
ctx.statusElement.error("
ctx.onMoveFailure(this);
return;
}
ctx.moveApi = new Morebits.wiki.api("抓取移
ctx.moveApi.setParent(this);
ctx.moveApi.post();
// if a non-admin tries to do this, don't bother
if (!Morebits.userIsInGroup('sysop')) {
ctx.statusElement.error("不能
ctx.onDeleteFailure(this);
return;
}
if (!ctx.editSummary) {
ctx.statusElement.error("
ctx.onDeleteFailure(this);
return;
}
ctx.deleteApi = new Morebits.wiki.api("抓取
ctx.deleteApi.setParent(this);
ctx.deleteApi.post();
// if a non-admin tries to do this, don't bother
if (!Morebits.userIsInGroup('sysop')) {
ctx.statusElement.error("不能保
ctx.onProtectFailure(this);
return;
}
if (!ctx.protectEdit && !ctx.protectMove && !ctx.protectCreate) {
ctx.statusElement.error("
ctx.onProtectFailure(this);
return;
}
if (!ctx.editSummary) {
ctx.statusElement.error("
ctx.onProtectFailure(this);
return;
}
ctx.protectApi = new Morebits.wiki.api("抓取保
ctx.protectApi.setParent(this);
ctx.protectApi.post();
// if a non-admin tries to do this, don't bother
if (!Morebits.userIsInGroup('sysop')) {
ctx.statusElement.error("不能
ctx.onStabilizeFailure(this);
return;
}
if (!ctx.flaggedRevs) {
ctx.statusElement.error("
ctx.onStabilizeFailure(this);
return;
}
if (!ctx.editSummary) {
ctx.statusElement.error("
ctx.onStabilizeFailure(this);
return;
ctx.editToken = $(xml).find('page').attr('edittoken');
if (!ctx.editToken) {
ctx.statusElement.error("未能抓取
ctx.onLoadFailure(this);
return;
ctx.loadTime = $(xml).find('page').attr('starttimestamp');
if (!ctx.loadTime) {
ctx.statusElement.error("未能抓取起始
ctx.onLoadFailure(this);
return;
ctx.revertCurID = $(xml).find('rev').attr('revid');
if (!ctx.revertCurID) {
ctx.statusElement.error("未能抓取
ctx.onLoadFailure(this);
return;
if (!ctx.revertUser) {
if ($(xml).find('rev').attr('userhidden') === "") { // username was RevDel'd or oversighted
ctx.revertUser = "<用
} else {
ctx.statusElement.error("未能抓取此修
ctx.onLoadFailure(this);
return;
}
// set revert edit summary
ctx.editSummary = "[[WP:UNDO|取消]]由 " + ctx.revertUser + " 所做出的修
}
// check for invalid titles
if ( $(xml).find('page').attr('invalid') ) {
ctx.statusElement.error("
onFailure(this);
return false; // abort
// only notify user for redirects, not normalization
if ( $(xml).find('redirects').length > 0 ) {
Morebits.status.info("Info", "
}
ctx.pageName = resolvedName; // always update in case of normalization
else {
// could be a circular redirect or other problem
ctx.statusElement.error("不能解
onFailure(this);
code.style.fontFamily = "monospace";
code.appendChild(document.createTextNode(blacklist));
ctx.statusElement.error(['不能保存
} else if ( $(xml).find('captcha').length > 0 ) {
ctx.statusElement.error("不能保存
} else if ( $editNode.attr('code') === 'abusefilter-disallowed' ) {
ctx.statusElement.error('
} else if ( $editNode.attr('info').indexOf('Hit AbuseFilter:') === 0 ) {
var div = document.createElement('div');
div.style.color = "black";
div.innerHTML = $editNode.attr('warning');
ctx.statusElement.error([ '防
// XXX provide the user with a way to automatically retry the action if they so choose -
// I can't see how to do this without creating a UI dependency on Morebits.wiki.page though -- TTO
} else {
ctx.statusElement.error("保存
}
};
var purgeApi = new Morebits.wiki.api("
var result = purgeApi.post( { async: false } ); // just wait for it, result is for debugging
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
ctx.statusElement.info("
if (fnCanUseMwUserToken('edit')) {
ctx.saveApi.post(); // necessarily append or prepend, so this should work as desired
} else if ( errorCode === "notoken" && ctx.conflictRetries++ < ctx.maxConflictRetries ) {
ctx.statusElement.info("
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
if (fnCanUseMwUserToken('edit')) {
// the error might be transient, so try again
ctx.statusElement.info("保存失
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
ctx.saveApi.post(); // give it another go!
// non-admin attempting to edit a protected page - this gives a friendlier message than the default
if ( errorCode === "protectedpage" ) {
ctx.statusElement.error( "不能保存修改:
} else if ( errorCode === "hookaborted" ) {
ctx.statusElement.error( "不能保存修改:被防
} else {
ctx.statusElement.error( "不能保存修改:" + ctx.saveApi.getErrorText() );
ctx.creator = $(xml).find('rev').attr('user');
if (!ctx.creator) {
ctx.statusElement.error("不能
return;
}
if ($(xml).find('page').attr('missing') === "") {
ctx.statusElement.error("不能移
ctx.onMoveFailure(this);
return;
var editprot = $(xml).find('pr[type="edit"]');
if (editprot.length > 0 && editprot.attr('level') === 'sysop' && !ctx.suppressProtectWarning &&
!confirm('您即
(editprot.attr('expiry') === 'infinity' ? '(永久)' : ('(到期:' + editprot.attr('expiry') + ')')) +
'。\n\n
ctx.statusElement.error("
ctx.onMoveFailure(this);
return;
var moveToken = $(xml).find('page').attr('movetoken');
if (!moveToken) {
ctx.statusElement.error("不能抓取移
ctx.onMoveFailure(this);
return;
}
ctx.moveProcessApi = new Morebits.wiki.api("移
ctx.moveProcessApi.setParent(this);
ctx.moveProcessApi.post();
if ($(xml).find('page').attr('missing') === "") {
ctx.statusElement.error("不能
ctx.onDeleteFailure(this);
return;
var editprot = $(xml).find('pr[type="edit"]');
if (editprot.length > 0 && editprot.attr('level') === 'sysop' && !ctx.suppressProtectWarning &&
!confirm('您即
(editprot.attr('expiry') === 'infinity' ? '(永久)' : ('(到期 ' + editprot.attr('expiry') + ')')) +
'。\n\n
ctx.statusElement.error("
ctx.onDeleteFailure(this);
return;
token = $(xml).find('page').attr('deletetoken');
if (!token) {
ctx.statusElement.error("不能抓取
ctx.onDeleteFailure(this);
return;
}
ctx.deleteProcessApi = new Morebits.wiki.api("
ctx.deleteProcessApi.setParent(this);
ctx.deleteProcessApi.post();
if ( errorCode === "internal_api_error_DBQueryError" && ctx.retries++ < ctx.maxRetries ) {
ctx.statusElement.info("
--Morebits.wiki.numberOfActionsLeft; // allow for normal completion if retry succeeds
ctx.deleteProcessApi.post(); // give it another go!
// this is pathetic, but given the current state of Morebits.wiki.page it would
// be a dog's breakfast to try and fix this
ctx.statusElement.error("
if (ctx.onDeleteFailure) {
ctx.onDeleteFailure.call(this, this, ctx.deleteProcessApi);
} else if ( errorCode === "missingtitle" ) {
ctx.statusElement.error("不能
if (ctx.onDeleteFailure) {
ctx.onDeleteFailure.call(this, ctx.deleteProcessApi); // invoke callback
} else {
ctx.statusElement.error( "不能
if (ctx.onDeleteFailure) {
ctx.onDeleteFailure.call(this, ctx.deleteProcessApi); // invoke callback
var missing = ($(xml).find('page').attr('missing') === "");
if (((ctx.protectEdit || ctx.protectMove) && missing)) {
ctx.statusElement.error("不能保
ctx.onProtectFailure(this);
return;
}
if (ctx.protectCreate && !missing) {
ctx.statusElement.error("不能白
ctx.onProtectFailure(this);
return;
var protectToken = $(xml).find('page').attr('protecttoken');
if (!protectToken) {
ctx.statusElement.error("不能抓取保
ctx.onProtectFailure(this);
return;
}
ctx.protectProcessApi = new Morebits.wiki.api("保
ctx.protectProcessApi.setParent(this);
ctx.protectProcessApi.post();
var missing = ($(xml).find('page').attr('missing') === "");
if (missing) {
ctx.statusElement.error("不能保
ctx.onStabilizeFailure(this);
return;
}
ctx.stabilizeProcessApi = new Morebits.wiki.api("配置stabilization
ctx.stabilizeProcessApi.setParent(this);
ctx.stabilizeProcessApi.post();
title: mw.config.get('wgPageName')
};
var renderApi = new Morebits.wiki.api("
renderApi.post();
};
var html = $(xml).find('text').text();
if (!html) {
apiobj.statelem.error("
return;
}
Morebits.status.init = function( root ) {
if( !( root instanceof Element ) ) {
throw new Error( '
}
while( root.hasChildNodes() ) {
Morebits.status.errorEvent = handler;
} else {
throw "Morebits.status.onError:
}
};
// internal counters, etc.
statusElement: new Morebits.status(currentAction || "
worker: null,
countStarted: 0,
this.run = function(worker) {
if (ctx.running) {
ctx.statusElement.error("批量操作已在
return;
}
var total = ctx.pageList.length;
if (!total) {
ctx.statusElement.info("
ctx.running = false;
return;
// just for giggles! (well, serious debugging, actually)
if (ctx.countFinished > total) {
ctx.statusElement.warn("完成(多
Morebits.wiki.removeCheckpoint();
ctx.running = false;
$(this.content).dialog({
autoOpen: false,
buttons: { "占位按
dialogClass: 'morebits-dialog',
width: Math.min(parseInt(window.innerWidth, 10), parseInt(width ? width : 800, 10)),
| |||