MediaWiki:RemoveWatermarktemplate.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.
// <nowiki>
/*
  Quick helper script for removing {{watermark}}. Called via a special link in [[Template:BotMoveToCommons]].

  Original author of Catcheck.js: [[User:Lupo]], September 2008
  Derived from [[MediaWiki:Botcheck.js]]
  License: Quadruple licensed GFDL, GPL, LGPL and Creative Commons Attribution 3.0 (CC-BY-3.0)
  
  Choose whichever license of these you like best :-)
*/

/*global $:false, wgNamespaceNumber:false, wgAction:false*/
/*jshint curly:false*/
if (mw.config.get('wgNamespaceNumber') === 6 && mw.config.get('wgAction') === 'edit') {
	$(document).ready(function () {
		'use strict';

		var text = document.getElementById ('wpTextbox1');
		if (!text) return;
		// Remove "Watermark" tag
		text.value = text.value.replace (/\{\{\s*(?:(?:remove |image)?water ?m[ae]rk(?:ed)?|wmr)\s*\}\}\n*/ig, "");

		// Remove any whitespace from beginning and end
		text.value = $.trim( text.value || "" );

		// Set edit summary
		var add = "Removing [[Template:Watermark|{{Watermark}}]]";
		var summary = document.getElementById ('wpSummary');
		if (!summary) return;
		var val = $.trim( summary.value || "" );
		if (val.indexOf(add) !== -1) return;
		summary.value = (val.length === 0) ? add : val + " " + add;
		try {
			document.editform.wpMinoredit.checked = true;
			document.editform.wpDiff.click();
		} catch (e) {
			// one of elements doesnt exist
		}
	});
}
// </nowiki>