User:Gone Postal/takenon.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.
// Original Flickrreview script written by [[User:Patstuart]]
// Rewritten and extended by [[User:ZooFari]] 
// Special thanks to [[User:Krinkle]] and [[User:DieBuche]] for assistance
// See talk page for documentation
// <nowiki>
mw.loader.load('mediawiki.util');

$ = jQuery;
$(document).ready(function(){
// if (console.log) console.log('User:ZooFari/licensereviewer.js is obsolete, please see [[Commons:License review]] current installation.');
// LRP
window.TakenOn = function () {
	var noChanges=document.editform.wpTextbox1.value,
		searchDate1a = document.editform.wpTextbox1.value.indexOf('{{taken on|'),
		searchDate1b = document.editform.wpTextbox1.value.indexOf('{{Taken on|'),
		searchDate2a = document.editform.wpTextbox1.value.indexOf('{{according to EXIF data|'),
		searchDate2b = document.editform.wpTextbox1.value.indexOf('{{According to EXIF data|'),
		searchDate2c = document.editform.wpTextbox1.value.indexOf('{{according to Exif data|'),
		searchDate2d = document.editform.wpTextbox1.value.indexOf('{{According to Exif data|'),
		searchDate3a = document.editform.wpTextbox1.value.indexOf('{{date|'),
		searchDate3b = document.editform.wpTextbox1.value.indexOf('{{Date|');
	if(searchDate1a !== -1 || searchDate1b !== -1)
	{
		var country = '';
		country = prompt("Country:", "");
		if(country===null)
		{
			return;
		}
		document.editform.wpTextbox1.value = document.editform.wpTextbox1.value
			//.replace(/\{\{taken on\|cat=no\|([^}]*)\}\}/gi, '{{taken on|$1|location='+country+'}}')
			//.replace(/\{\{taken on\|([^}]*)\|cat=no\}\}/gi, '{{taken on|$1|location='+country+'}}')
			.replace(/\{\{taken on\|([^}]*)\}\}/gi, '{{taken on|$1|location='+country+'}}')
			.replace(/\{\{own\}\}/gi, '{{own photo}}')
			.replace(new RegExp('\\[\\[Category:'+country+' photographs taken on \\d\\d\\d\\d-\\d\\d-\\d\\d\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:([^ ]+ )?\\d\\d\\d\\d ('+country+' )?photographs\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:Photographs taken on \\d\\d\\d\\d-\\d\\d-\\d\\d\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:\\d\\d\\d\\d in '+country+'\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:\\d\\d\\d\\d\\]\\]'), '')
			.replace(/(==Summary==)|(== Summary ==)/g, '=={{int:filedesc}}==').replace(/(==Licensing==)|(== Licensing ==)/g, '=={{int:license-header}}==');
		document.editform.wpSummary.value = '{{[[Template:taken on|taken on]]|location='+country+'}}';
		document.editform.wpMinoredit.checked = false;
		
		document.editform.submit();
	}
	else if(searchDate2a !== -1 || searchDate2b !== -1 || searchDate2c !== -1 || searchDate2d !== -1)
	{
		var country = '';
		country = prompt("Country:", "");
		if(country===null)
		{
			return;
		}
		document.editform.wpTextbox1.value = document.editform.wpTextbox1.value
			.replace(/\{\{according to EXIF data\|([^}]*)\}\}/gi, '{{according to Exif data|$1|location='+country+'}}')
			.replace(/\{\{own\}\}/gi, '{{own photo}}')
			.replace(new RegExp('\\[\\[Category:'+country+' photographs taken on \\d\\d\\d\\d-\\d\\d-\\d\\d\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:([^ ]+ )?\\d\\d\\d\\d ('+country+' )?photographs\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:Photographs taken on \\d\\d\\d\\d-\\d\\d-\\d\\d\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:\\d\\d\\d\\d in '+country+'\\]\\]'), '')
			.replace(/(==Summary==)|(== Summary ==)/g, '=={{int:filedesc}}==').replace(/(==Licensing==)|(== Licensing ==)/g, '=={{int:license-header}}==');
		document.editform.wpSummary.value = '{{[[Template:taken on|taken on]]|location='+country+'}}';
		document.editform.wpMinoredit.checked = false;
		
		document.editform.submit();
	}
	else if(searchDate3a !== -1 || searchDate3b !== -1)
	{
		var country = '';
		country = prompt("Country:", "");
		if(country===null)
		{
			return;
		}
		document.editform.wpTextbox1.value = document.editform.wpTextbox1.value
			.replace(/\{\{date\|([^}\|]+)\|([^}\|]+)\|([^}\|]+)\}\}/gi, '{{taken on|$1-$2-$3|location='+country+'}}')
			.replace(/\{\{date\|([^}\|]+)\|([^}\|]+)\}\}/gi, '{{taken in|$1-$2|location='+country+'}}')
			.replace(/\{\{date\|([^}\|]+)\}\}/gi, '{{taken in|$1|location='+country+'}}')
			.replace(/\{\{own\}\}/gi, '{{own photo}}')
			.replace(new RegExp('\\[\\[Category:'+country+' photographs taken on \\d\\d\\d\\d-\\d\\d-\\d\\d\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:([^ ]+ )?\\d\\d\\d\\d ('+country+' )?photographs\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:Photographs taken on \\d\\d\\d\\d-\\d\\d-\\d\\d\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:\\d\\d\\d\\d in '+country+'\\]\\]'), '')
			.replace(/(==Summary==)|(== Summary ==)/g, '=={{int:filedesc}}==').replace(/(==Licensing==)|(== Licensing ==)/g, '=={{int:license-header}}==');
		document.editform.wpSummary.value = '{{[[Template:taken on|taken on]]|location='+country+'}}';
		document.editform.wpMinoredit.checked = false;
		
		document.editform.submit();
	}
	else // just parse out |date=
	{
		var country = '';
		country = prompt("Country:", "");
		if(country===null)
		{
			return;
		}
		document.editform.wpTextbox1.value = document.editform.wpTextbox1.value
			.replace(/(([ \t]*\|[ \t]*[Dd]ate[ \t]*=[ \t]*)(.*))/, '$2{{taken on|$3|location='+country+'}}')
			.replace(/{{[Oo]wn}}/g, '{{own photo}}')
			.replace(new RegExp('\\[\\[Category:'+country+' photographs taken on \\d\\d\\d\\d-\\d\\d-\\d\\d\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:([^ ]+ )?\\d\\d\\d\\d ('+country+' )?photographs\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:Photographs taken on \\d\\d\\d\\d-\\d\\d-\\d\\d\\]\\]'), '')
			.replace(new RegExp('\\[\\[Category:\\d\\d\\d\\d in '+country+'\\]\\]'), '')
			.replace(/(==Summary==)|(== Summary ==)/g, '=={{int:filedesc}}==').replace(/(==Licensing==)|(== Licensing ==)/g, '=={{int:license-header}}==');
		document.editform.wpSummary.value = '{{[[Template:taken on|taken on]]|location='+country+'}}';
		document.editform.wpMinoredit.checked = false;
		
		document.editform.submit();
	}
};

window.addFunction = function(functionNameString, buttonDisplayName, checkNameSpaceFlag, whereAdd) {
	if ( mw.config.get('wgNamespaceNumber') !== checkNameSpaceFlag && mw.config.get('wgPageName') !== "Commons:Sandbox" ) {
		return;
	}

	if ( getParamValue('functionName') == functionNameString) {
			eval(functionNameString+"(true)");
			mw.loader.using([], function () {
				mw.notify($('<span>User:ZooFari/licensereviewer.js is obsolete, please see <a href="/wiki/Commons:License_review">Commons:License review</a> for current installation.</span>'), {
					title: 'Deprecation warning!',
					type: 'warn'
				});
			});
	}

	var href;
	if ( mw.config.get('wgAction') == 'edit' ){ 
		href = "javascript:" + functionNameString + "(true)";
	} else {
		href = mw.config.get('wgScript') + "?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&functionName=" + functionNameString;
	}
	
	if (whereAdd == 'top') {
		mw.util.addPortletLink('p-cactions', href, buttonDisplayName);
	} else if (whereAdd == 'toolbox') {
		mw.util.addPortletLink('p-tb', href, buttonDisplayName);
	}
	// [link]
	var targets = $('div.LR');
	if(targets.length === 0) return true;
	
	targets[0].style.textAlign = 'center';

		var passlink = mw.config.get('wgScript')+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+"&action=edit&functionName=LicenseReviewChange";
	
		targets[0].innerHTML = '[<a href="'+passlink+'">change license</a>]';
		return true;
	//
};


// jQuery UI is not loaded on all pages yet:
if (jQuery.ui == undefined) {
	$.getScript(mw.config.get('wgServer') + '/w/extensions/UsabilityInitiative/css/vector/jquery-ui-1.7.2.css');
	$.getScript(mw.config.get('wgServer') + '/w/extensions/UsabilityInitiative/js/js2stopgap/jui.combined.min.js', function(){
		addFunction("TakenOn", "Taken On", 6, "top");
	});
} else {
	addFunction("TakenOn", "Taken On", 6, "top");
}

});
// </nowiki>