Jump to content

User:Dlrohrer2003/validate-svg.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* Validate SVG
 * =============================================================================
 * Description: Add a link to an SVG validation service on SVG images in the
 *              file namespace. This is a variation on my CSS validation script:
 *              [[User:Dlrohrer2003/validate-css.js]]
 *              Which is itself inspired by a gadget on the Wikimedia Commons:
 *              [[Commons:MediaWiki:Gadget-CSSValidate.js]]
 *
 *      Author: [[User:Dlrohrer2003]]
 *
 *  Categories: [[Category:Wikipedia scripts]]
 */

mw.loader.using( [ 'mediawiki.util' ], function () {
	'use strict';

	const conf = mw.config.get( [ 'wgNamespaceNumber', 'wgServer', 'wgTitle' ] );

	if ( conf.wgNamespaceNumber === 6 && conf.wgTitle.match( /\.svg$/i ) && !document.getElementById( 'ca-validate-svg' ) ) {

		const svgFileURL = window.location.protocol + conf.wgServer + mw.util.getUrl( 'Special:Filepath/' + conf.wgTitle );

		mw.util.addPortletLink(
			'p-cactions',
			'https://validator.w3.org/check?' + $.param( { doctype: 'Inline', ss: '1', uri: svgFileURL } ),
			'Validate SVG',
			'ca-validate-svg',
			'Validate SVG file',
			'',
			null
		);

	}

});