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.
//<nowiki>
$( () => {
	'use strict';
	const v = mw.config.get();
	const tagName = 'movearticletousersubpage';
	if (
		v.wgNamespaceNumber === 0 && (
			$( '#ca-move' ).length ||
			$( '.menu__item--page-actions-overflow-move' ).length
		)
	) {
		let buttontext = 'Move to sandbox';
		let buttontitle = "Move to the creator's sub page";
		if ( v.wgUserLanguage === 'sv' ) {
			buttontext = 'Flytta till sandlåda';
			buttontitle = 'Flytta till skaparens användarundersida';
		}
		let portletId = 'p-cactions';
		if ( v.skin === 'minerva' ) {
			portletId = 'p-tb';
		}
		mw.util.addPortletLink(
			portletId,
			'#',
			buttontext,
			'ca-movearticletousersubpage',
			buttontitle
		);
		$( '#ca-movearticletousersubpage' ).click( e => {
			e.preventDefault();
			const api = new mw.Api();
			api.get( {
				prop: 'revisions',
				titles: v.wgPageName,
				rvdir: 'newer',
				rvlimit: 1,
				formatversion: 2
			} ).done( data => {
				let commentout = 'Commenting out article categories';
				let adding = 'Adding';
				let cat = 'Category:Wikipedia:Drafts';
				if ( v.wgContentLanguage === 'sv' ) {
					commentout = 'Kommenterar ut artikelkategorier';
					adding = 'Lägger till';
					cat = 'Kategori:Wikipedia:Utkast';
				}
				const obj = {
					action: 'move',
					from: v.wgPageName,
					noredirect: true
				};
				function editAndMove() {
					api.edit( v.wgPageName, revision => {
						const text = revision.content;
						const regex = /(\[\[[ \x{00A0}]*(?:Category|Kategori)[ \x{00A0}]*:[^\[\]\n]+\]\](?:\s*\[\[[ \x{00A0}]*(?:Category|Kategori)[ \x{00A0}]*:[^\[\]\n]+\]\])*)/g;
						let comment = '';
						if ( regex.test( text ) ) {
							comment = commentout + '. ';
						}
						comment += adding + ' [[' + cat + ']].';
						return ( {
							text: text.replace( regex, '<nowiki>$1</nowiki>' ).replace( /($)/, '\n[[' + cat + ']]$1' ),
							summary: comment,
							assert: 'user',
							nocreate: true
						} );
					} ).done( editres => {
						const creator = data.query.pages[ 0 ].revisions[ 0 ].user;
						obj.to = 'User:' + creator + '/' + v.wgPageName;
						api.postWithToken( 'csrf', obj ).done( () => {
							location.reload();
						} );
					} );
				}
				if (
					data &&
					data.query &&
					data.query.pages &&
					data.query.pages[ 0 ] &&
					data.query.pages[ 0 ].revisions &&
					data.query.pages[ 0 ].revisions[ 0 ] &&
					data.query.pages[ 0 ].revisions[ 0 ].user &&
					data.query.pages[ 0 ].revisions[ 0 ].timestamp &&
					( ( new Date( data.query.pages[ 0 ].revisions[ 0 ].timestamp ) ).getTime() + 1000 * 60 * 60 * 24 * 3 ) > Date.now()
				) {
					api.get( {
						action: 'query',
						list: 'tags',
						tglimit: 'max',
						tgprop: [
							'active',
							'defined',
							'source'
						],
						formatversion: 2
					} ).done( tagsres => {
						const query = tagsres.query;
						function hasTag( tagobj ) {
							return tagobj.name === tagName && tagobj.defined && tagobj.active && tagobj.source.indexOf( 'manual' ) !== -1;
						}
						if ( query ) {
							const tags = query.tags;
							if ( tags && Array.isArray( tags ) ) {
								if ( tags.some( hasTag ) ) {
									obj.tags = tagName;
								}
							}
						}
						editAndMove();
					} ).fail( () => {
						editAndMove();
					} );
				}
			} );
		} );
	}
} );
//</nowiki>