Content deleted Content added
missed one |
Ignore rate limit for small queries or users with "noratelimit", display total number of pages to process, avoid unnecessary API calls |
||
Line 5:
mw.loader.using( [ 'mediawiki.util', 'mediawiki.api' ] ).then( function() {
var pageList = [];
function getWait(d, type, totalCount) {
var wait=2000;
if (d && d.query && d.query.userinfo) {
if (d.query.userinfo.
&& ui.query.userinfo.rights.includes("noratelimit")) {
wait = 1;
} else if (d.query.userinfo.ratelimits
&& d.query.userinfo.ratelimits[type]
&& d.query.userinfo.ratelimits[type].user
&& d.query.userinfo.ratelimits[type].user.hits
&& d.query.userinfo.ratelimits[type].user.seconds)
Line 17 ⟶ 22:
var seconds = d.query.userinfo.ratelimits[type].user.seconds;
console.log(type + " rate limit: hits=" + hits + ", seconds=" + seconds);
if (hits < totalCount) {
wait = Math.ceil( (seconds/hits) * 1000 ); } else {
console.log(totalCount+" items to refresh is less than "+hits);
wait =
}
}
}
console.log("Using " + wait + " milliseconds wait between queries");
return wait;
}
function
function postFail(code, error) {
console.error(error);
alert("Error performing " + action + ":" + code + "!");
}
function postDone(p) {
mw.notify((count + 1) + " of " + totalCount + " page(s) were updated", { tag: "bubble"+count } );
count += 1;
setTimeout(function() {
doRefresh(action, count, totalCount, wait);
}, wait);
if (confirm("Done!\n\nReload page?") == true) {
document.___location.reload();
}
}
}
var apiParams = {
title: pageList.shift(),
action: action
};
if (action == "purge") {
apiParams.forcerecursivelinkupdate = "1";
new mw.Api().post(apiParams).fail(postFail).done(postDone);
} else {
apiParams.watchlist = "nochange";
apiParams.nocreate = "1";
apiParams.appendtext = "";
new mw.Api().postWithEditToken(apiParams).fail(postFail).done(postDone);
}
}
function
mw.notify("Fetching " + target.generator + "...", { tag: "
var queryParams = $.extend({
action: 'query',
formatversion: '2',
prop: ''
},
target,
addParams);
console.error(error);
alert("Error fetching page titles: " + code + "!");
} ).done(function(q) {
if(q && q.warnings === undefined && q.query && q.query.pages) {
for (var page in q.query.pages) {
if (q.query.pages[page].title) {
}
}
&& (q["continue"].gticontinue
|| q["continue"].glhcontinue
getList(action, target, q["continue"]);
} else {
console.
new mw.Api().get( {
meta: 'userinfo',
uiprop: 'ratelimits'
} ).fail( function(e) {
console.error(e);
doRefresh(action, 0, pageList.length, 1000);
} ).done( function(ui) {
doRefresh(action, 0, pageList.length, getWait(ui, action, pageList.length));
} );
}
}
} ); }
Line 120 ⟶ 118:
|| (mw.config.get("wgCanonicalSpecialPageName") == "Whatlinkshere") )
{
var linkTitle="", toolTipText="";
var target = mw.config.get("wgRelevantPageName").replace(/_/g, " ");
if ( (mw.config.get('wgNamespaceNumber') == 10) || (mw.config.get('wgNamespaceNumber') == 828) ){
generator: 'transcludedin',
titles: target,
gtilimit: 'max'
linkTitle = "transcluding pages";
toolTipText = "that transclude this template.";
} else if (mw.config.get('wgNamespaceNumber') == 14) {
generator: 'categorymembers',
gcmtitle: target,
gcmlimit: 'max'
linkTitle = "category members";
toolTipText = "in this category.";
} else {
generator: 'linkshere',
titles: target,
glhlimit: 'max'
linkTitle = "linking pages";
toolTipText = "that link to this page.";
}
$(mw.util.addPortletLink('p-cactions', '#', 'Purge ' + linkTitle, 'pt-refresh-purge', 'Perform a "forcelinkupdate" purge on all pages ' + toolTipText))
.click(function() {
getList("purge", target);
});
getList("edit", target);
}
});
|