MediaWiki:Gadget-DisableEditLink.js

From Yugipedia
Jump to: navigation, search

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: hold down Ctrl and click the Refresh or Reload button. Firefox: hold down ⇧ Shift while clicking Reload (or press Ctrl+⇧ Shift+R). Google Chrome and Safari users can just click the Reload button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.

/**
 * Disable page edit link (archive).
 * Only for "Forum", "User" and any talk page namesapces.
 *
 * Disables the edit tab/button on discussion pages to stop
 * people bumping old forum threads or editing archive pages.
 * Page can still be edited by going via the edit tab
 * on the history etc, or by typing the edit address manually.
 *
 * Original idea by User:Spang, from Uncyclopedia.
 * Completely re-desgined by Becasita.
 * @author Spang, Becasita
 * @contact [[User talk:Becasita]]
 */
( function _gadgetDisableEditLink( $, mw, console ) {
	"use strict";

	var LAST_LOG = '13:43, 22 August 2018 (UTC)';

	var DisableEditLink = {
		config: mw.config.get( [
			'wgNamespaceNumber',
			'wgUserGroups'
		] ),

		$button: $( '#ca-edit' ).find( 'a' ),

		archive: function() {
			DisableEditLink.$button
				.html( 'Archived' )
			;

			// For admins, apply only the above changes. For regular users:
			if ( !~DisableEditLink.config.wgUserGroups.indexOf( 'sysop' ) ) {
				DisableEditLink.$button
					.removeAttr( 'href' )
					.removeAttr( 'title' )
					.addClass( 'archived-edit-link' )
				;
			}

			// Also remove the small `[edit]` on MW titles:
			$( '.mw-editsection' ).remove();
		},

		isArchivablePage: function() {
			return (
				// For "Forum" and "User" namespaces:
				~[ 110, 2 ].indexOf( DisableEditLink.config.wgNamespaceNumber )
				||
				// For any talk page:
				DisableEditLink.config.wgNamespaceNumber % 2
			);
		},

		init: function() {
			if (
				// Indeed to be archived:
				$( '#archived-edit-link' ).length
				&&
				// Archivable page:
				DisableEditLink.isArchivablePage()
			) {
				DisableEditLink.archive();
			}
		}
	};

	$( DisableEditLink.init );

	console.log( '[Gadget] DisableEditLink last updated at', LAST_LOG );

} )( window.jQuery, window.mediaWiki, window.console );