User:Gryllida/js/showPagePreviewWhenDeleting.js

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

/* Author : Svetlana Tkachenko svetlana@members.fsf.org
This file is a part of deleteLinkInRc.
Licence: GPLv3+
Description: [beta] shows page contents preview when deleting a page
Recommends: User:Gryllida/js/deleteLinkInRc.js
See also <https://en.wikinews.org/wiki/User:Gryllida/Tasks>.
*/ 
mw.loader.using(['mediawiki.api'], function () {
	"use strict";
	
	// == Quit if this is not main namespace ==
	 var thisPageTitle = mw.config.get( 'wgPageName' );
	 
	// == Check whether we are deleting a page ==
	if ($('.deletepage-wrapper').length > 0){
		// == Create an API object ==
		var api = new mw.Api();
		// == Query the wiki API to get HTML of the page contents ==
		api.get( { 
    		action: 'parse',
    		page: mw.config.get( 'wgPageName' )
		} ).done( function ( data ) {
			// == Add the HTML at the end of current page ==
			$('#content').append($('<h1>', {text: 'Page Contents Preview'}));
			$('#content').append(data.parse.text['*']);
        });
	}
});