MediaWiki:Common.js

Uit Wikipedia, de vrije encyclopedie

Opmerking: nadat u de wijzigingen hebt gepubliceerd is het wellicht nodig uw browsercache te legen.

  • Firefox / Safari: houd Shift ingedrukt terwijl u op Vernieuwen klikt of druk op Ctrl-F5 of Ctrl-R (⌘-Shift-R op een Mac)
  • Google Chrome: druk op Ctrl-Shift-R (⌘-Shift-R op een Mac)
  • Internet Explorer / Edge: houd Ctrl ingedrukt terwijl u op Vernieuwen klikt of druk op Ctrl-F5
  • Opera: druk op Ctrl-F5.
/*jslint browser: true, continue: true, sloppy: true, vars: true, plusplus: true*/
/*global mw, $, importScript, importStylesheet*/
(function () {

	/**
	 * Laad volglijst script
	 */
	if (mw.config.get('wgCanonicalSpecialPageName') === 'Watchlist') {
		importScript("MediaWiki:Common.js/watchlist.js");
	}

	/**
	 * Extra knopje in de monobook toolbar
	 *
	 * Gebaseerd op [[:en:Wikipedia:Tools/Editing tools]].
	 * Maintainers: [[:en:User:MarkS|User:MarkS]]?, [[:en:User:Voice of All|User:Voice of All]], [[:en:User:R. Koot|User:R. Koot]]
	 */
	if (mw.toolbar) {
		mw.toolbar.addButton({
			'imageFile': '//upload.wikimedia.org/wikipedia/commons/0/04/Button_array.png',
			'speedTip': 'Voeg tabel in',
			'tagOpen': '{| class="wikitable"\n|-\n',
			'tagClose': "\n|}",
			'sampleText': "! kop 1\n! kop 2\n! kop 3\n|-\n| rij 1, cel 1\n| rij 1, cel 2\n| rij 1, cel 3\n|-\n| rij 2, cel 1\n| rij 2, cel 2\n| rij 2, cel 3"
		});
	}

	/**
	 * Uitgelicht in andere talen
	 *
	 * Sterren voor interwikilinks van de [[Wikipedia:Etalage]]-artikelen van andere Wikipedia's.
	 * Zie {{tl|Link FA}}. Overgenomen van [[:de:MediaWiki:Common.js]]
	 *
	 * @maintainer Krinkle
	 */
	function linkFA() {
		var i;

		// links are to replaced in p-lang only
		var pLang = document.getElementById('p-lang');
		if (!pLang) {
			return;
		}
		var lis = pLang.getElementsByTagName('li');
		for (i = 0; i < lis.length; i++) {
			var li = lis[i];
			// extract necessary classname
			var matches = li.className.match( /(?:^| )(interwiki-[^ ]+)(?: |$)/ );
			if ( !matches || matches.length != 2 ) {
				continue;
			}
			var className = matches[1];
			// alleen links met een Link FA-sjabloon
			if (!document.getElementById(className + "-fa") || li.className.indexOf("badge-featuredarticle") !== -1) {
				continue;
			}

			// Extra css-klasse zodat het effect verborgen kan worden met CSS
			li.className += ' FA';

			// Verander titel
			li.title = 'Dit is een etalage-artikel in een andere taal.';
		}
	}
	$(linkFA);

	/**
	 * Goede artikelen in andere talen
	 *
	 * Sterren voor interwikilinks van de 'goede artikelen' van andere Wikipedia's.
	 * Zie {{tl|Link GA}}.
	 *
	 * @maintainer Krinkle
	 */
	function linkGA() {
		var i;

		// links are to replaced in p-lang only
		var pLang = document.getElementById('p-lang');
		if (!pLang) {
			return;
		}
		var lis = pLang.getElementsByTagName('li');
		for (i = 0; i < lis.length; i++) {
			var li = lis[i];
			var matches = li.className.match( /(?:^| )(interwiki-[^ ]+)(?: |$)/ );
			if ( !matches || matches.length != 2 ) {
				continue;
			}
			var className = matches[1];
			// alleen links met een Link GA-sjabloon
			if (!document.getElementById(className + '-ga') || li.className.indexOf("badge-goodarticle") !== -1) {
				continue;
			}

			// Extra css-klasse zodat het effect verborgen kan worden met CSS
			li.className += ' GA';

			// Verander titel
			li.title = 'Dit is een goed artikel in een andere taal.';
		}
	}
	$(linkGA);

	/**
	 * Autotekst in uploadpagina voor bestanden
	 *
	 * Script voor Speciaal:Uploaden
	 * Maintainers: [[:commons:User:Yonidebest]], [[:commons:User:Dschwen]]
	 */
	if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload') {
		importScript('MediaWiki:Upload.js');
	}

	/**
	 * Meerdere sets speciale tekens
	 *
	 * Geeft menu in [[MediaWiki:Edittools]] waarmee meerdere sets speciale
	 * tekens kunnen worden geraadpleegd. Zie ook [[MediaWiki:Onlyifediting.js]]
	 */
	if (mw.config.get('wgAction')  === 'edit' || mw.config.get('wgAction') === 'submit') {
		importScript('MediaWiki:Onlyifediting.js');
	}


	/**
	 * Load withJS & withCSS
	 *
	 * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
	 * @rev 3
	 */
	mw.loader.using( ['mediawiki.util'], function () {
		var extraJS = mw.util.getParamValue( 'withJS' );
		if ( extraJS ) {
			// Disallow some characters in file name
			if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
				importScript( extraJS );
			// Show message after DOM is ready.
			} else {
				$( function() {
					mw.notify( 'Invalid javascript URL; only javascript pages from MediaWiki: space are allowed.', { title: 'Error' } );
				} );
			}
		}
		var extraCSS = mw.util.getParamValue( 'withCSS' );
		if ( extraCSS ) {
			// Disallow some characters in file name
			if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
				importStylesheet( extraCSS );
			// Show message after DOM is ready.
			} else {
				$( function() {
					mw.notify( 'Invalid stylesheet URL; only stylesheet pages from MediaWiki: space are allowed.', { title: 'Error' } );
				} );
			}
		}
	} );

	// Bewerken en overleg bij een afbeelding op Commons linken naar Commons (kopie van de Duitse Wikipedia)

	if (mw.config.get('wgNamespaceNumber') === 6) {
		mw.loader.using(['mediawiki.util']).then(function () {
		$(function () {
			if (window.keepLocalFileTabs) {
				return;
			}
			if (document.getElementById('ca-history')) {
				// Lokale beschrijving aanwezig?
				return;
			}
			if (!$('.sharedUploadNotice').length) {
				// Alleen doen bij afbeeldingen op Commons
				return;
			}

			var path = '//commons.wikimedia.org/wiki/';
			var link, talk, edit;

			// Andere link voor overlegpagina
			// vector uses ca-image_talk
			talk = document.getElementById('ca-talk') || document.getElementById('ca-image_talk');
			if (talk && $(talk).hasClass('new')) {
				link = talk.getElementsByTagName('a')[0];
				link.href = path + 'File_talk:' + mw.util.wikiUrlencode(mw.config.get('wgTitle')) + '?uselang=' + mw.config.get('wgUserLanguage');
				link.className  += ' commonstab';
			}

			// Bewerken link
			edit = document.getElementById('ca-edit') || document.getElementById('ca-viewsource');
			if (edit) {
				link = edit.getElementsByTagName('a')[0];
				link.href = path + 'File:' + mw.util.wikiUrlencode(mw.config.get('wgTitle')) + '?uselang=' + mw.config.get('wgUserLanguage') + '&action=edit';
				link.className  += ' commonstab';
				link.firstChild.nodeValue = 'Bewerken';
			}
		});
		});
	}


	/**
	 * Icons on the top right of the article.
	 * See also CSS
	 *
	 * @source https://www.mediawiki.org/wiki/Snippets/Top_icons
	 * @version 6
	 */
	mw.hook( 'wikipage.content' ).add( function ( $content ) {
		$content.find( '.Top_icon_raw' )
			.removeClass( 'Top_icon_raw' )
			.addClass( 'Top_icon_dynamic' )
			.prependTo( '#firstHeading' );
	} );

	/**
	 * Gebruik 4 tildes zonder '--' voor ondertekening in de (oude) toolbar
	 */
	$(function () {
		$( '#mw-editbutton-signature' )
			.off('click')
			.on('click', function () { window.insertTags( '~~' + '~~' ); } );
	});

	/**
	 * Gebruik 4 tildes zonder '--' voor ondertekening in de uitgebreide werkbalk
	 */
	$(function () {
		$( '#wpTextbox1' ).on( 'wikiEditor-toolbar-buildSection-main', function ( event, section ) {
			if (section.groups.insert.tools.signature) {
				section.groups.insert.tools.signature.action.options.pre = '~~'+'~~';
			}
		});
	});

}());

// Link 'kopje toevoegen' bij laatste sectie op overlegpagina's
mw.loader.using( [ 'mediawiki.util' ], function() { $( function() {
	var newSectionLink = $( '#ca-addsection a' );
	if ( newSectionLink.length ) {
		var link = newSectionLink.clone(); //create a copy
		//avoid duplicate accesskey
		link.removeAttr( 'accesskey' ).updateTooltipAccessKeys();
		//'Kopje toevoegen' is met een hoofdletter maar 'bewerk' is met een kleine letter
		var text = link.text();
		link.text(text[0].toLowerCase() + text.substring(1));
		var lastEditsectionLink = $( 'span.mw-editsection:last a:last' );
		lastEditsectionLink.after( link );
		lastEditsectionLink.after( ' | ' ); //see [[MediaWiki:Pipe-separator]]
	}
})});

// A high frequency of errors come from old scripts referencing addPortletLink.
// Consider making this use mw.notify instead to get these users to update (See updateUserScriptWarning in [[:cs:MediaWiki:Common.js]])
// Can be removed when https://global-search.toolforge.org/?q=%5B%5E%5C.%5DaddPortletLink%5C%28&regex=1&namespaces=&title=.*%5C.js has no nl.wikipedia results.
mw.loader.using('mediawiki.util').then(function () {
	mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
});