Content deleted Content added
increase number of pages purged at a time |
var api = new mw.Api( { userAgent: 'refresh/0.0.1' } ); |
||
(12 intermediate revisions by the same user not shown) | |||
Line 5:
mw.loader.using( [ 'mediawiki.util', 'mediawiki.api' ] ).then( function() {
var api = new mw.Api( { userAgent: 'refresh/0.0.1' } );
var pageList = [];
const reuse = ( typeof refreshReuseBubble === 'undefined' ? false : refreshReuseBubble );
function shuffleArray(array) {
console.log('Shuffling array...');
for (let i = array.length - 1; i >= 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function getWait(d, totalCount) {
Line 51 ⟶ 60:
var err = error?.textStatus || code;
var errMsg;
//if (confirm("Error performing " + action + ": " + err + "!\n\nContinue?") == true) {
errMsg = "Continuing after "+err+" error...";
postDone();
//} else {
// errMsg = "Aborted due to "+err+" error!";
//}
mw.notify(errMsg, { tag: "bubble" + (reuse ? 0 : "error"), type: 'error',
autoHideSeconds: (action == 'purge') ? 'long' : 'short' } );
Line 63 ⟶ 72:
function postSuccess() {
count = count + ( (action == "purge") ? ((apiParams.titles.match(/\|/g) || []).length + 1) : 1 );
mw.notify(count + " of " + totalCount + " page(s) were
tag: "bubble" + (reuse ? 0 : "count"),
autoHideSeconds: (action == 'purge') ? 'long' : 'short'
} );
Line 73 ⟶ 82:
if (action == "purge") {
// 'purge' is always once every two second unless 'noratelimit',
// so give editors with higher 'edit' rate a boost.
// More than 3 at a time leads to timeouts.
var numPages = wait.edit < 1000 ? 3 : 1;
apiParams.titles = pageList.splice(0, numPages).join('|');
console.log(apiParams.titles);
apiParams.forcerecursivelinkupdate = "1";
api.post(apiParams).fail(postFail).done(postSuccess);
} else {
apiParams.title = pageList.shift();
console.log(apiParams.title);
apiParams.watchlist = "nochange";
apiParams.nocreate = "1";
apiParams.appendtext = "";
}
}
Line 95 ⟶ 110:
target,
addParams);
var list = target?.list || "pages";
if (queryParams.cmsort && window.refreshCatSort) queryParams.cmsort = window.refreshCatSort;
if (queryParams.cmdir && window.refreshCatDir) queryParams.cmdir = window.refreshCatDir;
if (queryParams.srsort && window.refreshSearchSort) queryParams.srsort = window.refreshSearchSort;
console.log(queryParams);
api.get(queryParams).fail(function(code, error) {
console.error(error);
alert("Error fetching page titles: " + code + "!");
} ).done(function(q) {
if(q && q.warnings === undefined && q?.query?.[list]
if (
});
if (q?.continue?.continue !== undefined) {
getList(action, target, q.continue);
} else {
if (window.refreshShuffle) shuffleArray(pageList);
console.log(pageList);
meta: 'userinfo',
uiprop: 'ratelimits|rights'
} ).fail( function(e) {
console.error(e);
Line 134 ⟶ 148:
}
var linkshere = mw.config.get("wgCanonicalSpecialPageName") == "Whatlinkshere";
var sparams = new URLSearchParams(window.___location.search);
var search= (mw.config.get("wgCanonicalSpecialPageName") == "Search" &&
sparams.get('search') && sparams.get('search') != '');
if ( (mw.config.get('wgNamespaceNumber') == 10)
|| (mw.config.get('wgNamespaceNumber') == 14)
|| (mw.config.get('wgNamespaceNumber') == 828)
|| linkshere || search)
{
var linkTitle="linking pages", toolTipText="that link to this page.";
var target = mw.config.get("wgRelevantPageName").replace(/_/g, " ");
var targetNS = mw.Title.newFromText(target).getNamespaceId();
var query = {
generator: 'linkshere',
titles: target,
glhlimit: 'max'
};
if (search) {
toolTipText = "in this search result.";
query = {
list: 'search',
srsearch: sparams.get('search'),
srlimit: 'max',
srsort: 'last_edit_desc',
srprop: ''
};
nslist = [];
for(const e of sparams.entries()) {
var nsp = e[0].match(/^ns(\d+)/);
if (nsp?.[1] && e[1] == 1) nslist.push(nsp[1]);
}
if (nslist.length > 0 ) query.srnamespace = nslist.join("|");
} else if ( (targetNS == 10) || (targetNS == 828) ){
if ( linkshere ) {
toolTipText = "that link to this template.";
} else {
query = {
generator: 'transcludedin',
titles: target,
gtilimit: 'max'
};
linkTitle = "transcluding pages";
toolTipText = "that transclude this template.";
}
} else if (targetNS == 14) {
if ( linkshere ) {
toolTipText = "that link to this category.";
} else {
query = {
list: 'categorymembers',
cmtitle: target,
cmlimit: 'max',
cmsort: 'timestamp',
cmdir: 'desc'
};
linkTitle = "category members";
toolTipText = "in this category.";
}
}
$(mw.util.addPortletLink('p-cactions', '#', 'Purge ' + linkTitle, 'pt-refresh-purge', 'Perform a "forcelinkupdate" purge on all pages ' + toolTipText))
.click(function() {
getList("purge",
});
$(mw.util.addPortletLink('p-cactions', '#', 'Null edit ' + linkTitle, 'pt-refresh-null', 'Perform a null edit on all pages ' + toolTipText))
.click(function() {
getList("edit",
});
}
|