Content deleted Content added
Always before a "linkshere" search when script is initialized from "Special:WhatLinksHere". |
var api = new mw.Api( { userAgent: 'refresh/0.0.1' } ); |
||
(10 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',
var numPages = Math.round(wait.purge/wait.edit) || 1;▼
// so give editors with higher 'edit' rate a boost.
// More than 3 at a time leads to timeouts.
apiParams.titles = pageList.splice(0, numPages).join('|');
console.log(apiParams.titles);
apiParams.forcerecursivelinkupdate = "1";
//apiParams.forcelinkupdate = "1";
} else {
apiParams.title = pageList.shift();
console.log(apiParams.title);
apiParams.watchlist = "nochange";
apiParams.nocreate = "1";
apiParams.appendtext = "";
}
}
Line 96 ⟶ 110:
target,
addParams);
var list = target?.list || "pages";
new mw.Api().post(queryParams).fail(function(code, error) {▼
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);
console.error(error);
alert("Error fetching page titles: " + code + "!");
} ).done(function(q) {
if(q && q.warnings === undefined && q?.query?.[list]
if (
});▼
}▼
▲ }
▲ if (q["continue"] !== undefined
)▼
) {▼
▲ getList(action, target, q["continue"]);
} else {
if (window.refreshShuffle) shuffleArray(pageList);
console.log(pageList);
meta: 'userinfo',
uiprop: 'ratelimits|rights'
Line 136 ⟶ 149:
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.";
Line 149 ⟶ 165:
glhlimit: 'max'
};
if (search) {
if ( (targetNS == 10) || (targetNS == 828) ){▼
linkTitle = "search results";
toolTipText = "in this search result.";
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.";
Line 166 ⟶ 199:
} else {
query = {
cmsort: 'timestamp',
cmdir: 'desc'
};
linkTitle = "category members";
|