Jump to content

User:Zackmann08/scripts/MoveToDraft.js

From Wikipedia, the free encyclopedia
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.
/******************************************************************************
 MoveToDraft
-------------
Version 1
-------------
A script to move unsourced articles to draft space, including cleanup and author notification.
- Moves page to draftspace
- Checks if any files used are non-free
- Checks if any redirects pointed to the page
- Comments out non-free files, turn categories into links, add afc draft template, add redirects
- Adds notification message on author talk page
- Updates talk page banners
- Logs draftification in user subpage

 derived from https://en.wikipedia.org/wiki/User:Evad37/MoveToDraft.js
 and copied from https://en.wikipedia.org/wiki/User:MPGuy2824/MoveToDraft.js ([[Special:Permalink/1333706443]])
******************************************************************************/
/* jshint laxbreak: true, undef: true, maxerr:999 */
/* globals console, window, document, $, mw */
// <nowiki>

// Script info
var mtd = {
	config: {
		script: {
			// For window header
			location: "User:Zackmann08/scripts/MoveToDraft.js",
			version: "1"
		}
	}
},
	API;

$.when(
	// Resource loader modules
	mw.loader.using( [ 'mediawiki.util', 'mediawiki.api', 'mediawiki.Title' ] ),
	// Page ready
	$.ready
).then( function() {
/* ========== Config ======================================================= */
	// MediaWiki configuration values
mtd.config.mw = mw.config.get( [
		"wgArticleId",
		"wgCurRevisionId",
		"wgPageName",
		"wgUserGroups",
		"wgUserName",
		"wgMonthNames",
		"wgNamespaceNumber",
		"wgTitle",
		"wgArticlePath",
		"wgIsMainPage",
		"wgIsRedirect"
	]
);

/* ========== API ========================================================== */
API = new mw.Api( {
	ajax: {
		headers: { 
			"Api-User-Agent": "MoveToDraft/" + mtd.config.script.version + 
				" ( https://en.wikipedia.org/wiki/User:Zackmann08/scripts/MoveToDraft.js )"
		}
	}
} );

var dynamicallyLoadScript = function( url ) {
	let loadScript = document.createElement( 'script' );
	loadScript.src = url + '?action=raw&ctype=text/javascript';
	document.head.appendChild( loadScript );
};

/* ========== Setup ============================================================================= */

// Only operate in article namespace
if( mtd.config.mw.wgNamespaceNumber !== 0 ) {
	return;
}

// Don't draftify MainPage
if( mtd.config.mw.wgIsMainPage === true ) {
	return;
}

// Only operate for existing pages
if ( mtd.config.mw.wgCurRevisionId === 0 ) {
	return;
}

// Only for articles
if ( mtd.config.mw.wgIsRedirect === true ) {
	return;
}

dynamicallyLoadScript(
	mtd.config.mw.wgArticlePath.replace( '$1', 'User:Zackmann08/scripts/MoveToDraft.js/core.js' )
);

});
// </nowiki>