User:Gliwi/common.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
var ns = mw.config.get('wgNamespaceNumber'), //<nowiki>

	ti = mw.config.get('wgTitle'),

	GlobalReplaceDefaultReason = '',

	ext, bSVG,

	AjaxDeleteExtraButtons = [];

window.delReqGlobalUsage = 1; // AQD DelReqHandler


function prefillDupe(e) { // hack for AjaxDeleteExtraButtons duplicate

	"use strict";

	if (!e) return;

	mw.loader.using('ext.gadget.AjaxQuickDelete', function () {

		AjaxQuickDelete.insertTagOnPage(

			"{{duplicate|1=%PARAMETER%|user=%USER%}}",

			"Tagging as duplicate of [[File:%PARAMETER%]]",

			'{{subst:Speedynote|1=%FILE%|2={{subst:int:File-exists-duplicate|}} [[:File:%PARAMETER%]].}}',

			'Duplicate notification',

			"Which file is this a duplicate of?",

			"", 1);

		setTimeout(function () { // cleanup prefix / namespace "File:"

			var $t = $('#AjaxQuestion0');

			$t.val($('#mw-imagepage-section-duplicates ul a').eq(0).attr('title')).focusout(function (e) {

				e.preventDefault();

				return $t.val($.trim($t.val()).replace(/^[Ff]ile\:/, ''));

			});

		}, 200);

	});

}

/** Files only **/

if (ns === 6) {

	ext = ti.slice(-3).toUpperCase();

	bSVG = (!ext.indexOf("SVG"));


	importScript('User:Perhelion/JustReplace+.js');

	importScript('User:Perhelion/cleanup.js'); // File desc. cleanup


	if (bSVG) { /** SVG only **/


		// simple SVG edit (beta)

		importScript('User:Rillke/SVGedit.js');


		// W3C-Validator check-link for every SVG (by [[User: Perhelion]] fixed also now for admins); + detailed byte-size

		importScript('User:Perhelion/simpleSVGcheck.js');


		AjaxDeleteExtraButtons.push({

			'label': 'PoorSVG', // TracedSVG

			'tag': '{{PoorSVG|1=%PARAMETER%}}', // Raster file

			'img_summary': 'This SVG contains poor traced elements, please revectorize',

			'talk_tag': '{{subst:TracedSVG/notify|1=%FILE%|2=%PARAMETER%}}',

			'talk_summary': 'Poor SVG note',

			'prompt_text': 'Which file is the original of?',

			optin_notify: 1

		}, {

			'label': 'BadSVG',

			'tag': '{{BadSVG}}',

			'img_summary': 'This file contains raster graphics that should be removed',

			'talk_tag': '{{subst:BadSVG/notification|1=%FILE%}}',

			'talk_summary': 'Bad SVG note',

			'prompt_text': 'Please remove embedded raster graphics?',

			optin_notify: 1

		}, {

			'label': 'SVGbug', // SVGbug

			'tag': '{{SVGbug|1=%PARAMETER%}}', // Raster file

			'img_summary': 'This SVG contains one or more libRSVG bugs',

			'prompt_text': 'Description of the bug or a link?'

		});

	} else {

		AjaxDeleteExtraButtons.push({

			'label': 'ToSVG notify',

			'tag': '{{Convert to SVG|%PARAMETER%}}',

			'img_summary': 'This file should be better a SVG',

			'talk_tag': '{{subst:Please use SVG|1=%FILE%}}',

			'talk_summary': 'Use SVG note',

			'prompt_text': 'Please use SVG insteed of raster graphics. Which type?'

		});

		GlobalReplaceDefaultReason = ext + ' → SVG';

	}


	mw.loader.using('mediawiki.util', function () {

		$(mw.util.addPortletLink('p-tb', null, "Duplicate", 't-dupe', null)).click(prefillDupe);

		// mw.util.addPortletLink('p-cactions', 'https://tools.wmflabs.org/derivative/deri1.php?image=File:' + ti, "derivateFX", 't-derivate', null);

	});


} // Files only end


// SORT CONVERT-TO-SVG TAGS:

if (ns === 14 || (ns === 6 /*&& ["edit", "submit"].indexOf(ac) !== -1*/ && !/SVG/i.test(ti.slice(-3))))

	importScript('User:Perhelion/fixconverttosvg.js');

// </nowiki>