User:Ahecht/Scripts/refresh.js: Difference between revisions

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) {
var wait=1000;
function getWait(d, type, totalCount) {
if (d && d.query && d.query.userinfo && d.query.userinfo.ratelimits
var wait=2000;
&& d.query.userinfo.ratelimits[type])
if (d && d.query && d.query.userinfo) {
{
if (d.query.userinfo.ratelimits[type].userrights
&& 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("Using " + wait + " milliseconds wait between queries");
console.log(totalCount+" items to refresh is less than "+hits);
} else {
wait = 20001;
}
}
}
console.log("Using " + wait + " milliseconds wait between queries");
return wait;
}
function postPurgedoRefresh(targetaction, count, waittotalCount, addParamswait) {
function postFail(code, error) {
mw.notify("Fetching " + target.generator + "...", { tag: "bubble"+count } );
console.error(error);
var apiParams = $.extend({
alert("Error performing " + action + ":" + code + "!");
action: 'purge',
}
forcerecursivelinkupdate: 1
},
function postDone(p) {
target,
mw.notify((count + 1) + " of " + totalCount + " page(s) were updated", { tag: "bubble"+count } );
addParams);
count += 1;
//console.log(apiParams);
new mw.Api().post(apiParams)
.failif (function(code,pageList.length > error0) {
setTimeout(function() {
console.error(error);
doRefresh(action, count, totalCount, wait);
alert("Error purging page: " + code + "!");
}, wait);
.done(function(d)} else {
if (confirm("Done!\n\nReload page?") == true) {
//console.log(d);
document.___location.reload();
mw.notify((count + 1) + " pages were updated", { tag: "bubble"+count } );
count += 1;
if (d.warnings === undefined && d["continue"] !== undefined
&& (d["continue"].gticontinue
|| d["continue"].gcmcontinue
|| d["continue"].glhcontinue)) {
setTimeout(function() {
postPurge(target, count, wait, d["continue"]);
}, wait);
} else {
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 postNullgetList(targetaction, count, waittarget, addParams) {
mw.notify("Fetching " + target.generator + "...", { tag: "bubblebubble0"+count } );
var queryParams = $.extend({
action: 'query',
formatversion: '2',
prop: ''
},
target,
addParams);
//consolenew mw.logApi().post(queryParams);.fail(function(code, error) {
console.error(error);
new mw.Api().post(queryParams)
alert("Error fetching page titles: " + code + "!");
.fail(function(code, error) {
} ).done(function(q) {
console.error(error);
if(q && q.warnings === undefined && q.query && q.query.pages) {
alert("Error fetching page title: " + code + "!");
for (var page in q.query.pages) {
})
if (q.query.pages[page].title) {
.done(function(q) {
if pageList.push(q && q.query && q.query.pages && q.query.pages[0page] &&.title);
}
q.query.pages[0].title) {
}
//console.log(q);
varif editParams(q["continue"] !== {undefined
&& (q["continue"].gticontinue
action: 'edit',
title:|| q.query.pages[0"continue"].title,gcmcontinue
|| q["continue"].glhcontinue
watchlist: 'nochange',
nocreate: '1',)
appendtext:) ''{
getList(action, target, q["continue"]);
};
//console.log(editParams);
new mw.Api().postWithToken("csrf", editParams )
.fail(function(code, error) {
console.error(error);
alert("Error performing null edit:" + code + "!");
})
.done( function(e) {
//console.log(e);
mw.notify((count + 1) + " pages were updated", { tag: "bubble"+count } );
count += 1;
if (q.warnings === undefined && q["continue"] !== undefined
&& (q["continue"].gticontinue
|| q["continue"].gcmcontinue
|| q["continue"].glhcontinue)) {
setTimeout(function() {
postNull(target, count, wait, q["continue"]);
}, wait);
} else {
if (confirm("Done!\n\nReload page?") == true) {
document.___location.reload();
}
}
} );
} else {
console.errorlog(qpageList);
new mw.Api().get( {
alert("Error: Page title not found in API response!");
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="";
new mw.Api().get({
var target = mw.config.get("wgRelevantPageName").replace(/_/g, " ");
meta: 'userinfo',
if ( (mw.config.get('wgNamespaceNumber') == 10) || (mw.config.get('wgNamespaceNumber') == 828) ){
uiprop: 'ratelimits'
}).done( target function(d)= {
generator: 'transcludedin',
var linkTitle="", toolTipText="";
titles: target,
var target = mw.config.get("wgRelevantPageName").replace(/_/g, " ");
gtilimit: 'max'
if ( (mw.config.get('wgNamespaceNumber') == 10) || (mw.config.get('wgNamespaceNumber') == 828) ){
target = {};
linkTitle = "transcluding pages";
generator: 'transcludedin',
toolTipText = "that transclude this template.";
titles: target,
} else if (mw.config.get('wgNamespaceNumber') == 14) {
gtilimit: 1
};target = {
generator: 'categorymembers',
linkTitle = "transcluding pages";
gcmtitle: target,
toolTipText = "that transclude this template.";
gcmlimit: 'max'
} else if (mw.config.get('wgNamespaceNumber') == 14) {
target = {};
linkTitle = "category members";
generator: 'categorymembers',
toolTipText = "in this category.";
gcmtitle: target,
} else {
gcmlimit: 1
};target = {
generator: 'linkshere',
linkTitle = "category members";
titles: target,
toolTipText = "in this category.";
glhlimit: 'max'
} else {
target = {};
linkTitle = "linking pages";
generator: 'linkshere',
toolTipText = "that link to this page.";
titles: target,
}
glhlimit: 1
$(mw.util.addPortletLink('p-cactions', '#', 'Purge ' + linkTitle, 'pt-refresh-purge', 'Perform a "forcelinkupdate" purge on all pages ' + toolTipText))
};
.click(function() {
linkTitle = "linking pages";
getList("purge", target);
toolTipText = "that link to this page.";
});
$(mw.util.addPortletLink('p-cactions', '#', 'PurgeNull edit ' + linkTitle, 'pt-refresh-purgenull', 'Perform a "forcelinkupdate"null purgeedit on all pages ' + toolTipText))
.click(function() {
getList("edit", target);
postPurge(target, 0, getWait(d, "purge"));
});
$(mw.util.addPortletLink('p-cactions', '#', 'Null edit ' + linkTitle, 'pt-refresh-null', 'Perform a null edit on all pages ' + toolTipText))
.click(function() {
postNull(target, 0, getWait(d, "edit"));
});
} );
}
});