User:Leyo/del-chem.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// <nowiki>
/* jshint scripturl:true */

window.AjaxQDChemFix = {
	installChemFix: function () {
		mw.util.addPortletLink('p-tb', 'javascript:AjaxQuickDelete.nominateForDeletionChem();', "Nom for del (chem)", 't-ajaxquickdeletechem', null);
		$('#t-ajaxquickdelete > a').attr('href', 'javascript:AjaxQuickDelete.nominateForDeletionWrap();');
	},
	nominateForDeletionWrap: function () {
		this.isChem = false;
		this.nominateForDeletion();
	},
	nominateForDeletionChem: function () {
		this.isChem = true;
		this.dailyLogPageChem = "Commons:WikiProject Chemistry/Deletion requests";
		this.nominateForDeletion();
	},
	listRequestSubpage: function () {
		var page = {};
		page.title = this.dailyLogPage;
		page.text = "\n{{" + this.requestPage + "}}\n";
		page.watchlist = 'nochange';
		page.editType = 'appendtext';

		if (this.isChem) {
			var pageChem = {
				title: this.dailyLogPageChem,
				text: "{{" + this.requestPage + "}}\n",
				watchlist: 'nochange',
				editType: 'prependtext'
			};
			this.savePage(pageChem, "Listing [[" + this.requestPage + "]]", 'cdummy');
		}

		this.showProgress(this.i18n.listingNomination);
		this.isChem = false;
		this.savePage(page, "Listing [[" + this.requestPage + "]]", 'nextTask');
	},
	cdummy: function () {}
};

if (mw.config.get('wgNamespaceNumber') === 6)
	mw.loader.using('ext.gadget.AjaxQuickDelete', function () {
		$(function () {
			// merge the content into AjaxQuickDelete-Object; returnvalue is the merged object but AjaxQuickDelete is also modified
			// $.extend( [ deep ], target, object1, [ objectN ] )
			$.extend(true, AjaxQuickDelete, AjaxQDChemFix);
			AjaxQuickDelete.installChemFix();
			try {
				delete window.AjaxQDChemFix; // Destroy this object
			} catch (ex) {
				window.AjaxQDChemFix = {};
			}
		});
	});

// enable [[MediaWiki:Gadget-DelReqHandler.js]] for [[Commons:WikiProject Chemistry/Deletion requests]]
if (mw.config.get('wgPageName').indexOf('Commons:WikiProject_Chemistry/Deletion_requests') !== -1 && mw.config.get('wgAction') === 'view' && document.URL.search(/[?&]oldid=/) === -1) {
	$(function () {
		if (-1 !== $.inArray('sysop', mw.config.get('wgUserGroups'))) {
			mw.loader.using('ext.gadget.DelReqHandler', function () {
				if ('object' === typeof DelReqHandler)
					DelReqHandler.parse(); // only activate if admin and DelReqHandler loaded
			});
		}
	});
}

// </nowiki>