Jump to content

User:Ahecht/Scripts/refresh.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ahecht (talk | contribs) at 13:57, 17 September 2018 (Create based on [https://phabricator.wikimedia.org/T170039#3473755 T170039#3473755] and he:User:IKhitron/101.js). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Based on [https://phabricator.wikimedia.org/T170039#3473755] and [[:he:User:IKhitron/101.js]]

mw.loader.using( [ 'mediawiki.util', 'mediawiki.api' ] ).then( function() {
	var step = 1;
	var count;
	var wait;
	function postPurge(cat, addParams) {
		var apiParams = $.extend({
			action: 'purge', 
			generator: 'categorymembers',
  			'gcmtitle': cat,
  			'gcmlimit': step,
			forcelinkupdate: 1
		}, addParams);
		new mw.Api().post(apiParams)
			.fail(function() {
				alert("Fail");
			})
			.done(function(d) {
			console.log(d);
			count += step;
			if (d.warnings === undefined && d["continue"] !== undefined
					&& d["continue"].gcmcontinue) {
				mw.notify(count + " pages were updated");
				setTimeout(function() {
						postPurge(cat, d["continue"]);
					}, wait);
			} else {
				alert("Done!");
				document.location.reload();
		}});
	}
	if (mw.config.get('wgNamespaceNumber') == 14) {
		wait = 1000;
		new mw.Api().get({
    		meta: 'userinfo',
    		uiprop: 'ratelimits'
		}).done(function(d) {
			if (d && d.query && d.query.userinfo && d.query.userinfo.ratelimits
    				&& d.query.userinfo.ratelimits.purge)
				wait = 2000;
				$(mw.util.addPortletLink('p-cactions', '#', 'refresh', 'pt-refresh'))
					.click(function() {
						count = 0;
						postPurge(mw.config.get('wgPageName')
							.replace(/_/g, " "));
					});
		} );
	}
});