User:Dlrohrer2003/validate-svg.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Dlrohrer2003/validate-svg. |
/* 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
);
}
});