Hoppa till innehållet

MediaWiki:Gadget-PreventAnonEditing.js

Från Wikipedia

OBS: Efter du har publicerat sidan kan du behöva tömma din webbläsares cache för att se ändringarna.

  • Firefox / Safari: Håll ned Skift och klicka på Uppdatera sidan eller tryck Ctrl-F5 eller Ctrl-R (⌘-R på Mac)
  • Google Chrome: Tryck Ctrl-Skift-R (⌘-Skift-R på Mac)
  • Edge Håll ned Ctrl och klicka på Uppdatera eller tryck Ctrl-F5.
  • Opera: Tryck Ctrl-F5.
if ( mw.user.isAnon() ) {
	$( function() {
		'use strict';
		var msg = 'Edits from unregistered users have temporarily been disabled due to overwhelming vandalism';
		var closetext = 'Close';
		var closetitle = 'Close the dialog window';
		if ( mw.config.get( 'wgUserLanguage' ) === 'sv' ) {
			msg = 'Redigeringar från oinloggade har för tillfället stoppats på grund av omfattande klotter';
			closetext = 'Stäng';
			closetitle = 'Stäng dialogrutan';
		}
		$( '#ca-ve-edit, .mw-editsection-visualeditor' ).off();
		$( '#ca-ve-edit, #ca-edit, .mw-editsection a' ).click( function( e ) {
			e.preventDefault();
			// Creating and opening a simple dialog window.

			// Subclass Dialog class. Note that the OOjs inheritClass() method extends the parent constructor's prototype and static methods and properties to the child constructor.

			function MyDialog( config ) {
				MyDialog.super.call( this, config );
			}
			if ( $( '.oo-ui-window-active' ).length === 0 ) {
				OO.inheritClass( MyDialog, OO.ui.Dialog );

				// Specify a title statically (or, alternatively, with data passed to the opening() method).
				MyDialog.static.name = 'gadgetpreventanoneditingdialog';
				MyDialog.static.title = 'Simple dialog';

				// Customize the initialize() function: This is where to add content to the dialog body and set up event handlers.
				MyDialog.prototype.initialize = function () {
					var str = '<div id="gadget-preventanonediting-container">';
					str += '<p>' + msg + '.</p>';
					str += '<button id="gadget-preventanonediting-close" title="' + closetitle + '">' + closetext + '</button>';
					str += '</div>';
					// Call the parent method
					MyDialog.super.prototype.initialize.call( this );
					// Create and append a layout and some content.
					this.content = new OO.ui.PanelLayout( { padded: true, expanded: false } );
					this.content.$element.append( str );
					this.$body.append( this.content.$element );
				};

				// Use the getTeardownProcess() method to perform actions whenever the dialog is closed.
				// This method provides access to data passed into the window's close() method
				// or the window manager's closeWindow() method.
				MyDialog.prototype.getTeardownProcess = function ( data ) {
					return MyDialog.super.prototype.getTeardownProcess.call( this, data )
					.first( function () {
						// Perform any cleanup as needed
						$( '.oo-ui-windowManager' ).remove();
					}, this );
				};

				// Make the window.
				var myDialog = new MyDialog();

				// Create and append a window manager, which will open and close the window.
				var windowManager = new OO.ui.WindowManager();
				$( 'body' ).append( windowManager.$element );

				// Add the window to the window manager using the addWindows() method.
				windowManager.addWindows( [ myDialog ] );

				// Open the window!
				windowManager.openWindow( myDialog );
				$( '#gadget-preventanonediting-close' ).click( function() {
					myDialog.close();
				} );
			}
		} );
	} );
}