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

跳至導覽 跳至搜尋
繁簡轉換
(新頁面: // <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 + '在調用API时发時發生了错误錯誤“' + jqXHR.statusText + '”。';
this.returnError();
}
returnError: function() {
if ( this.errorCode === "badtoken" ) {
this.statelem.error( "效令牌,刷新" );
} else {
this.statelem.error( this.errorText );
 
if (!currentAction) {
currentAction = '打开页開頁面“' + pageName + '”';
}
 
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("错误錯誤:未load()提供onSuccess回調!");
ctx.onLoadFailure(this);
return;
}
 
ctx.loadApi = new Morebits.wiki.api("抓取面…", ctx.loadQuery, fnLoadSuccess, ctx.statusElement, ctx.onLoadFailure);
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.pageName +
(ctx.fullyProtected === 'infinity' ? '(永久)' : ('(到期:' + ctx.fullyProtected + ')')) +
'。\n\n点击确點擊確定以定,或点击點擊取消以取消。')) {
ctx.statusElement.error("全保护页護頁面的编辑編輯被取消。");
ctx.onSaveFailure(this);
return;
}
 
ctx.saveApi = new Morebits.wiki.api( "保存面…", query, fnSaveSuccess, ctx.statusElement, fnSaveError);
ctx.saveApi.setParent(this);
ctx.saveApi.post();
this.lookupCreator = function(onSuccess) {
if (!onSuccess) {
ctx.statusElement.error("错误錯誤:未lookupCreator()提供onSuccess回調!");
return;
}
}
 
ctx.lookupCreatorApi = new Morebits.wiki.api("抓取建者信息", query, fnLookupCreatorSuccess, ctx.statusElement);
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("错误錯誤:回退前未提供修版本ID!");
ctx.onSaveFailure(this);
return;
 
if (!ctx.editSummary) {
ctx.statusElement.error("错误錯誤:移前未提供理由(使用setEditSummary函)!");
ctx.onMoveFailure(this);
return;
}
if (!ctx.moveDestination) {
ctx.statusElement.error("错误錯誤:移前未指定目标页標頁面!");
ctx.onMoveFailure(this);
return;
}
 
ctx.moveApi = new Morebits.wiki.api("抓取移令牌…", query, fnProcessMove, ctx.statusElement, ctx.onMoveFailure);
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("错误錯誤除前未提供理由(使用setEditSummary函)!");
ctx.onDeleteFailure(this);
return;
}
 
ctx.deleteApi = new Morebits.wiki.api("抓取除令牌…", query, fnProcessDelete, ctx.statusElement, ctx.onDeleteFailure);
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("错误錯誤調用protect()前未编辑編輯和/或移和/或白!");
ctx.onProtectFailure(this);
return;
}
if (!ctx.editSummary) {
ctx.statusElement.error("错误錯誤:保前未提供理由(使用setEditSummary函)!");
ctx.onProtectFailure(this);
return;
}
 
ctx.protectApi = new Morebits.wiki.api("抓取保令牌…", query, fnProcessProtect, ctx.statusElement, ctx.onProtectFailure);
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("不能用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;
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("未能抓取前修版本ID。");
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 + " 所做出的修 " + ctx.revertOldID + ":" + ctx.editSummary;
}
 
// check for invalid titles
if ( $(xml).find('page').attr('invalid') ) {
ctx.statusElement.error("标题標題不合法:" + ctx.pageName);
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 );
}
ctx.pageName = resolvedName; // always update in case of normalization
else {
// could be a circular redirect or other problem
ctx.statusElement.error("不能解释页釋頁面的重定向:" + ctx.pageName);
onFailure(this);
 
code.style.fontFamily = "monospace";
code.appendChild(document.createTextNode(blacklist));
ctx.statusElement.error(['不能保存面,因URL ', code, ' 在垃圾黑名中。']);
} else if ( $(xml).find('captcha').length > 0 ) {
ctx.statusElement.error("不能保存面,因服试图让試圖讓您完成一全自动区動區和人图灵测试圖靈測試。");
} else if ( $editNode.attr('code') === 'abusefilter-disallowed' ) {
ctx.statusElement.error('编辑編輯被防过滤過濾规则規則“' + $editNode.attr('info').substring(17) + '”阻止。');
} 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([ '防过滤過濾出了如下警告:', div, '如果您仍希望做出该编辑該編輯重新提交。此警告不再次出。' ]);
// 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("保存由API得到未知错误錯誤");
}
 
};
 
var purgeApi = new Morebits.wiki.api("检测檢測编辑冲編輯衝突,更新服存", purgeQuery, null, ctx.statusElement);
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('您即全保护页護頁面“' + ctx.pageName + '”' +
(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("移动页動頁面…", query, ctx.onMoveSuccess, ctx.statusElement, ctx.onMoveFailure);
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('您即将删將刪除全保护页護頁面“' + ctx.pageName + "”" +
(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("面…", query, ctx.onDeleteSuccess, ctx.statusElement, fnProcessDeleteError);
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( "不能面:" + ctx.deleteProcessApi.getErrorText() );
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("保护页護頁面…", query, ctx.onProtectSuccess, ctx.statusElement, ctx.onProtectFailure);
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定…", query, ctx.onStabilizeSuccess, ctx.statusElement, ctx.onStabilizeFailure);
ctx.stabilizeProcessApi.setParent(this);
ctx.stabilizeProcessApi.post();
title: mw.config.get('wgPageName')
};
var renderApi = new Morebits.wiki.api("入中…", query, fnRenderSuccess, new Morebits.status("预览預覽"));
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( '对象對像不是一Element' );
}
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("完成(多行了" + (ctx.countFinished - total) + ")");
Morebits.wiki.removeCheckpoint();
ctx.running = false;
$(this.content).dialog({
autoOpen: false,
buttons: { "占位按": function() {} },
dialogClass: 'morebits-dialog',
width: Math.min(parseInt(window.innerWidth, 10), parseInt(width ? width : 800, 10)),
2,718

次編輯

導覽選單