Jump to content

User:Ahecht/Scripts/massmove.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Ahecht (talk | contribs) at 16:57, 6 May 2025 (Move some functions out of core to avoid duplicate code (corresponding edit to core re-enables the tool for bots without move-subpages)). The present address (URL) is a permanent link to this version.
(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.
//jshint maxerr:512
var massMoveTitle = "Mass-move tool";
/*Forked version of [[User:Plastikspork/massmove.js]] that adds a link to the left column
and allows adding and removing both prefixes and suffixes

Add the following line to [[Special:MyPage/common.js]] or [[:meta:Special:MyPage/global.js]] to install:

mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:Ahecht/Scripts/massmove.js&action=raw&ctype=text/javascript' ); //[[User:Ahecht/Scripts/massmove.js]] [[User:Plastikspork/massmove.js]]
 
Click on "Mass move" under "Tools" to use the script.*/
mw.loader.using( [ 'mediawiki.api',	'mediawiki.util' ], function () {
	var config = mw.config.get([
		'wgServer', 'wgScript', 'wgArticlePath', 'wgFormattedNamespaces',
		'wgUserGroups', 'wgNamespaceNumber', 'wgTitle',
		'wgCanonicalSpecialPageName', 'wgUserName', 'skin'
	]);
	var mmScriptPrefix = ":en:User:Ahecht/sandbox/Scripts/",
	mmScriptName = "massmove",
	mmCore = `${mmScriptPrefix+mmScriptName}-core.js`,
	mmCoreURL = `${config.wgServer+config.wgScript}?title=${mmCore}&action=raw&ctype=text/javascript`,
	mmSpecialURL = config.wgArticlePath.replace("$1",
		`${config.wgFormattedNamespaces[-1]}:${mmScriptName}`),
	isMover = /sysop|extendedmover|templateeditor|bot/.test(config.wgUserGroups);
	
	if (isMover) {
		mw.util.addPortletLink("p-tb", mmSpecialURL, massMoveTitle, "p-massmove", massMoveTitle);
	}
		
	if (config.wgNamespaceNumber === -1) {
		if (config.wgTitle.toLowerCase() === mmScriptName.toLowerCase()) {
			config.bodyContent = 'mw-content-text';
			document.getElementById(config.bodyContent).innerHTML = `Loading ${massMoveTitle}...`;
			console.log("Loading " + mmCoreURL);
			mw.loader.getScript( mmCoreURL ).then(function() {
				massMove(massMoveTitle, config);
			});
		} else if (isMover && config.wgCanonicalSpecialPageName === 'Movepage') {
			$('div.mw-heading').has('h2#Subpages').next('p').html( (_, t) => t.replace('\n', ' (<a class="plainlinks" href="'+mmSpecialURL+'">'+mmScriptName+'</a>)\n'));
		}
	}
});