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)
  • Internet Explorer / Edge: Håll ned Ctrl och klicka på Uppdatera eller tryck Ctrl-F5
  • Opera: Tryck Ctrl-F5.
if ( mw.config.get( 'wgNamespaceNumber' ) === 14 ) {
	$( function() {
		'use strict';
		var api = new mw.Api();
		var esc = mw.html.escape;
		var link = mw.util.addPortletLink(
			'p-cactions',
			'#',
			'Rödlänkar',
			'ca-redlinks',
			'Visa icke-existerande sidor som länkas från sidor i den här kategorin'
		);
		$( link ).find( 'a' ).click( function( e ) {
			e.preventDefault();
			var shouldContinue = true;
			var str = '<div>' +
				'<button type="button" id="gadget-redlinks-stop">Stopp</button>' +
				'<button type="button" id="gadget-redlinks-close">Stäng</button>' +
				'<table id="gadget-redlinks-table">' +
					'<caption>Rödlänkar</caption>' +
					'<tbody id="gadget-redlinks-tbody">' +
						'<tr><th>Artikeln</th><th>Länkar till</th></tr>' +
					'</tbody>' +
				'</table>' +
			'</div>';
			// 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 );
			}
			var myDialog;
			var windowManager;
			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 = 'gadgetredlinksdialog';
				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 () {
					// 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 );
					function getPages( start ) {
						var obj = {
							action: 'query',
							list: 'categorymembers',
							cmtitle: mw.config.get( 'wgPageName' ),
							cmtype: 'page',
							cmlimit: 500,
							formatversion: 2
						};
						if ( start ) {
							obj.cmcontinue = start;
						}
						api.get( obj ).done( function( queryres ) {
							var pages = queryres.query.categorymembers.map( function( categorymember ) {
								return categorymember.title;
							} );
							var i = 0;
							function parse() {
								if ( shouldContinue ) {
									setTimeout( function() {
										api.get( {
											action: 'parse',
											page: pages[ i ],
											prop: 'links',
											formatversion: 2
										} ).done( function( parseres ) {
											var redlinkobjects = parseres.parse.links.filter( function( link ) {
												return !link.exists && link.title;
											} );
											var redlinks = redlinkobjects.map( function( redlinkobject ) {
												return redlinkobject.title;
											} );
											var trstrings = redlinks.map( function( redlink ) {
												return '<tr><td><a href="/wiki/' + esc( pages[ i ] ) + '">' + pages[ i ] + '</a></td><td><a href="/wiki/' + esc( redlink ) + '">' + redlink + '</a></td></tr>';
											} );
											var trstring = trstrings.join( '' );
											$( '#gadget-redlinks-tbody' ).append( trstring );
											if ( i === pages.length -1 ) {
												if ( queryres[ 'continue' ] ) {
													if ( queryres[ 'continue' ].cmcontinue ) {
														getPages( queryres[ 'continue' ].cmcontinue );
													}
												} else {
													$( '#gadget-redlinks-stop' ).text( 'Klart!' );
													$( '#gadget-redlinks-stop' ).prop( 'disabled', true ); 
												}
											} else {
												i = i + 1;
												parse();
											}
										} );
									}, 2000 );
								}
							}
							parse();
						} );
					}
					getPages();
					$( '#gadget-redlinks-stop' ).click( function() {
						shouldContinue = false;
					} );
					$( '#gadget-redlinks-close' ).click( function() {
						shouldContinue = false;
						myDialog.close();
					} );
				};
	
				// 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.
				myDialog = new MyDialog( {
					classes: [
						'gadget-redlinks-dialog'
					]
				} );
	
				// Create and append a window manager, which will open and close the window.
				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 );
			}
		} );
	} );
}