User:Web SourceContent/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.
/*global mw, $, importScript*/
/*jshint curly:false, scripturl:true, strict:true */

var ns = mw.config.get('wgNamespaceNumber'), //  global [[Bugzilla:33837]] <nowiki>
	ul = mw.config.get('wgUserLanguage'),
	pn = mw.config.get('wgPageName'),
	un = mw.config.get('wgUserName'),
	ac = mw.config.get('wgAction'),
	ti = mw.config.get('wgTitle'),
	cun = "", // (optional) CUSTOM username
	convertToSVGTypes = "geology, meteorology, road sign, text logo",
	GlobalReplaceDefaultReason = '',
	ext, bSVG,
	AjaxDeleteExtraButtons = [];

window.delReqGlobalUsage = 1; // AQD DelReqHandler
window.largerGallery = 1.25;
if (ns === 14 && ti === "Media requiring renaming" ) // [[:Category:Media requiring renaming]]
	window.largerGalleryZoom = 1;

function prefillDupe(e) { // hack for AjaxDeleteExtraButtons duplicate
"use strict";
	if (!e) return;
	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('MediaWiki:ExCommons.js');  // - copy files to individual Wikis before deleting them on Commons
	
	//importScript('User:Sreejithk2000/JustReplace.js');
	importScript('User:Perhelion/JustReplace+.js');
	importScript('User:Perhelion/cleanup.js'); // File desc. cleanup
	//importScript('User:Magog the Ogre/cleanup.js'); // File desc. cleanup
	//importScript('User:Rillke/bigChunkedUpload.js'); // [[Help:Chunked upload]]
	
	importScript('User:Rillke/LicenseReview.js');
	
	/*// AQD prefill move values
	if (!$('#AjaxRenameLink').length) // AQD prefill move values
		$('#mw-content-text').after($('<div>', {
				id: 'AjaxRenameLink',
				style: 'visibility:hidden'
			}).append([
					$('<span>', {
						id: 'AjaxRenameDestination',
						text: "OOjs UI icon "
					}),
					$('<span>', {
						id: 'AjaxRenameReason',
						text: "[[COM:MOVE#cite_ref-2|move criteria #2]] (+more meaningful)"
					})
				]));*/
	
	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';
	}
	
	// [[Help:QuickDelete]]
	//To watch user talk pages, to which you add tags
	window.AjaxDeleteWatchUserTalk = true;
	//To watch file pages, to which you add tags
	window.AjaxDeleteWatchFile = true;
	// adding more buttons :
	AjaxDeleteExtraButtons.push( {
	    'label': 'Copyvio (www)',
	    'tag': '{'+'{copyvio|1=[[COM:NETCOPYRIGHT|Copyright violation]], found elsewhere on the web and unlikely to be own work: [https://www.google.com/searchbyimage?image_url={{filepath:{'+'{subst:BASEPAGENAME}}}} google search]}}',
	    'img_summary': 'speedy deletion: possible copyvio',
	    'talk_tag': '{'+'{subst:copyvionote|1=%FILE%}}',
	    'talk_summary': 'Notification of possible copyright violation for %FILE%'
    }, /*{ //notice talk_tag and talk_summary must be '' (void string) if uploader must not be notified
		'label' : 'Duplicate',
		'tag' : '{{duplicate|1=%PARAMETER%|user=%USER%}}',
		'img_summary' : 'Tagging as duplicate of [[File:%PARAMETER%]]', // FIXME!?: $.trim(%PARAMETER%).replace(/^(?:File|Image)\:/, '')
		'talk_tag' : '{{subst:Speedynote|1=%FILE%|2={{subst:int:File-exists-duplicate|}} [[:File:%PARAMETER%]].}}',
		'talk_summary' : 'Duplicate notification',
		'prompt_text' : 'Which file is this a duplicate of?',
		optin_notify: 1
		},  */
	{ //notice talk_tag and talk_summary must be '' (void string) if uploader must not be notified
		'label' : 'Speedy',
		'tag' : '{{Speedydelete|1=%PARAMETER%}}',
		'img_summary' : 'Tagging as speedy delete because: %PARAMETER%',
		'talk_tag' : '{{subst:Speedynote|1=%FILE%|2=%PARAMETER%}}',
		'talk_summary' : 'Speedy notification',
		'prompt_text' : 'Speedy: why ? MUST PREVENT UPLOADER'
	}, {
		'label' : 'Wrong License',
		'tag' : '{{wl|1=%PARAMETER%}}',
		'img_summary' : 'Tagging as wrongly licensed because: %PARAMETER%',
		'talk_tag' : '{{subst:Wrong license note|2=%PARAMETER%|1=%FILE%}}',
		'talk_summary' : 'Notification of possible wrong license',
		'prompt_text' : 'Incorrect license: reason?'
	}, {
		'label' : 'Thumbnail',
		'tag' : '{{Thumbnail}}',
		'img_summary' : 'Tagging as thumbnail',
		'talk_tag' : '{{subst:Do not upload thumbnails|1=%FILE%}}',
		'talk_summary' : 'Thumb note',
		'prompt_text' : 'Please re-upload the full resolution version?',
		optin_notify: 1
	}, {
		'label' : 'Watermark',
		'tag' : '{{Watermark|1=}}',
		'img_summary' : 'This file contains a watermark that should be removed',
		'talk_tag' : '{{subst:No watermarks|1=:%FILE%}}',
		'talk_summary' : 'Watermarks note',
		'prompt_text' : 'Please remove Watermarks?',
		optin_notify: 1
	} );

	// [[MediaWiki:Gadget-AjaxQuickDelete.js]]
	$.when(mw.loader.using('mediawiki.util'), $.ready).done(function () {
    "use strict";
		$(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);
	});

	// make editing and adding descriptions easier
	// importScript('User:MarkTraceur/editDescriptions.js'); too beta
} // Files only end
else if (ns === -1) {
	//importScript('User:Whym/lockrollback.js');
	$(".mw-rollback-link a").hide();

	switch (mw.config.get("wgCanonicalSpecialPageName")) {
    case "Search":
		mw.loader.load( "https://de.wikipedia.org/w/index.php?title=MediaWiki:Gadget-DeepCat.js&action=raw&ctype=text/javascript" );
		break;
    case "Contributions": // Admin only
		mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Writ_Keeper/Scripts/massRevdel.js&action=raw&ctype=text/javascript');
		importScript('User:~riley/MRollback.js');
		break;
    case "RecentChanges":
		importScript('User:Krinkle/SplitRC2.js');
		//importScript('User:Pokéfan95/RecentChanges-wo-userrights.js');
		//importScript('User:Pokéfan95/RecentChanges-wo-usercreations.js');
		break;
    case "Watchlist":
		importScript('User:Krinkle/Watchlist-wo-usercreations.js');
		//importScript('User:Pokéfan95/Watchlist-wo-userrights.js');
		break;
	}
} 
else if (ns === 2 || ns === 3) {
	importScript('User:~riley/gadgets/SpamUserPage.js'); // Linkback: [[User:Mr. Stradivarius/gadgets/SpamUserPage.js]]
}
else if (ns === 14 && ac === "view") {
	importScript('User:Jheald/wdcat.js');
	importScript('User:Perhelion/massrename.js'); 
}

if (ac === "history") {// Patroller only
	importScript('MediaWiki:PatrolPageRevisions.js');
	mw.loader.using("jquery.confirmable", function () {
		$(".mw-rollback-link a").addClass("reactivate-as-confirmable").confirmable();
	});
}
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hoo_man/smart_rollback.js&action=raw&ctype=text/javascript');

/* Admin only */
if (ns % 2 && $( '.com-edit-request-admin-area' ).length ) importScript( 'MediaWiki:FulfillEditRequest.js' );

// 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');

// Insert a personalized Texttemplate into the Special:Upload edit box.
//  I upload mostly my own work; preload input form; adapted from [[User: Dschwen]]
$(function () {
	"use strict";
	if (pn === 'Special:Upload' && /&uselang=([^&]*)ownwork/.test(location.search)) {
		var re = RegExp.$1;
		//mw.loader.using('moment',function(){
		setTimeout(function () {
			$('#wpUploadDescription').val(
				'=={{int:filedesc}}==\n' +
				'{{Information\n' +
				'|description=\n{{en|1=}}\n' +
				((re) ? '{{' + re + '|1=}}\n' : '') +
				'|date=' + '{{Originaluploaddate|}} {{vectorization}} {{Uploaddate|{{subst:CURRENTYEAR}}-{{subst:CURRENTMONTH}}-{{subst:CURRENTDAY2}}}}\n' + 
				'|source={{own based|…}}\n' +
				//+ moment().format('YYYY-MM-DD') + '}}\n' +
				'|author={{AutVec||' + un + '}}\n' +
				'|permission=\n' +
				'|other_versions=\n' +
				'<gallery widths="100" heights="100" showfilename>\n\n</gallery>\n' +
				'|other fields={{Igen|h|+|s=|u='+ un +'}}\n' +
				'}}\n\n' +
				'=={{int:license-header}}==\n' +
				'{{self|GFDL|cc-by-sa-4.0|author=I, [[User:' + un + '|' + cun + ']]}}');
		}, 100);
		//});
	} else
		$('#n-uploadbtn').children('a').attr('href', '//commons.wikimedia.org/w/index.php?title=Special:Upload&uselang=' +
			((ul === 'en') ? '' : ul) + 'ownwork&uploadformstyle=plain');
	// [[Mediawiki:Edittools]] 	smaller (HACK)
	if (['edit', 'submit'].indexOf(ac) !== -1) {
		// Autocomplete for links and templates, written by [[משתמש:ערן]]
		mw.loader.load('//he.wikipedia.org/w/load.php?modules=ext.gadget.autocomplete', 'text/javascript', false);
	}
});

////////// Cat-A-Lot user preferences //////////
window.catALotPrefs = {
	"watchlist" : "watch",
	"minor" : true,
	"editpages" : true,
	"docleanup" : true,
	"subcatcount" : 50
};

/* MediaWiki:Gadget-markAdmins.js configuration */
window.markAdminCfg = {
	groups: {
		'steward':			{ enabled: 1 },
		'vrt-permissions':		{ enabled: 1 },
		'image-reviewer':	{ enabled: 1 }
	}
};

//vFCProfil/////////////////////////////////////
/////// VISUAL FILE CHANGE CONFIGURATION ///////
///// DO NOT MODIFY BY HAND - FINGERS AWAY! ////
////////////////////////////////////////////////
window.vFC_Profiles = {"SVG":{"editInputs":{"mdDeleteReason":"","mdEditSummary":"→SVG","mdReplacePermission":false,"mdDeleteHeading":"Files in [[:Category:Diagrams in German]] ","mdTalkNote":"Yours sincerely,","mdRRegEx1":true,"mdRVar1":true,"mdMatchText1":"/Category:Charts in English/g","mdReplaceText1":"Category:SVG charts in English","mdRRegEx2":false,"mdRVar2":true,"mdMatchText2":"","mdReplaceText2":"","selPreserve":"secure","alsoPreserve":""},"action":"c_replace","objectMembers":{"queryParams":{"target":"Category:Charts in English","cmdir":"asc","cmsort":"sortkey","cmstartsortkey":"","cmcontinue":"file|57494b49534f555243452028454e2920464952535420313030302056414c49444154494f4e532e504e47|25826615"},"startInput":{"mode":"Category","modeCat":true,"modeUser":false,"modePage":false,"target":"Category:Charts in English","loadThumbs":true,"loadWikitext":true,"startDate":"","startFile":""}},"proceedAt":{"vals":["file|454c454354524f4e4943204348454154494e4720504152454e54532050455243455054494f4e532e504e47|17574410","file|57494b49534f555243452028454e2920464952535420313030302056414c49444154494f4e532e504e47|25826615"],"setVals":["cmcontinue"]},"time":"2015-07-21T16:50:16.750Z"}};
//////////////////////////////////vFCProfilEnd//
//</nowiki>

//catALot///////////////////////////////////////
////////// Cat-a-lot user preferences //////////
window.catALotPrefs = {"redir_category":"Category redirects","watchlist":"nochange","minor":true,"editpages":true,"docleanup":true,"subcatcount":50,"button":true};
////////////////////////////////////catALotEnd//