Jump to content

MediaWiki:Gadget-XFDcloser.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.
/*  _______________________________________________________________________________
 * |                                                                               |
 * |                     === WARNING: GLOBAL GADGET FILE ===                       |
 * |                   Changes to this page affect many users.                     |
 * |  Please discuss changes on the talk page or on [[WT:Gadget]] before editing.  |
 * |_______________________________________________________________________________|
 * 
 * Built from source code at GitHub repository [https://github.com/wikimedia-gadgets/xfdcloser]
 * All changes should be made in the repository, otherwise they will be lost.
 * 
 * To update this script from github, you must have a local repository set up. Then
 * follow the instructions at [https://github.com/wikimedia-gadgets/xfdcloser/blob/master/README.md]
 * 
 * XFDcloser: close deletion discussions at XfD venues, including actions to implement closes; see [[WP:XFDC]]
 * Author: Evad37
 * Licencing and attribution: [[WP:XFDC#Licencing and attribution]]
 */
/* jshint esversion: 5, esnext:false, laxbreak: true, undef: true, eqnull: true, maxerr: 3000 */
/* globals console, document, window, $, mw, OO */
/* <nowiki> */
(function(){
	// Check if on a non-existent article/file/portal (to unlink backlinks)
	var isNonexistentPage = mw.config.get("wgArticleId") === 0;
	var isUnlinkableNamespace = [
		0, // Article
		6, // File
		100 // Portal 
	].indexOf(mw.config.get("wgNamespaceNumber")) !== -1;
	var isUnlinkablePage = isNonexistentPage && isUnlinkableNamespace;
	
	// Check for edit, history, diff, or oldid mode
	if ( !isUnlinkablePage && /(?:\?|&)(?:action|diff|oldid)=/.test(window.location.href) ) {
		return;
	}

	// XFDcloser options
	var options;
	try {
		options = JSON.parse(mw.user.options.get("userjs-xfdc")) || {};
	} catch(e) {
		options = {};
	}

	// Check if on an XfD page
	var xfdpage_regex = /(Articles_for_deletion\/|Miscellany_for_deletion|User:Cyberbot_I\/AfD's_requiring_attention|Wikipedia:WikiProject_Deletion_sorting\/(?!(Flat|Compact)$)|(Categories|Files|Templates|Redirects)_for_discussion(?!\/(Working|Holding_cell|Speedy)))(?!\/?(?:Administrator_instructions|Common_outcomes)$)/;
	var isXfdPage = xfdpage_regex.test(mw.config.get("wgPageName"));

	// Load for XfD pages as well as unlinkable pages 
	var shouldLoadScript = isXfdPage || isUnlinkablePage;
	if ( !shouldLoadScript ) {
		return;
	}
	mw.loader.load( options && options.beta ? "ext.gadget.XFDcloser-core-beta" : "ext.gadget.XFDcloser-core");
})();
/* </nowiki> */