Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
/*global UrlParameters, Actions, AdminActions, DOM, EditCommentLength, FeedbackArea, adminflag, deleting, newActionBar, wgPageName, wgTitle, addOnloadHook */
 // <pre>

var NowCommons = {
	KeepParameterName:	'nc_keep',
	TemplateMatch:		/\{\{\s*([Vv]orlage:|[Tt]emplate:)?\s*[Nn](CT?|ow[Cc]ommons)\s*(\|(\s*[^}]+\s*))?\}\}/,

	GleicherName:		false,
	CommonsName:		'',
	Baustein:		null,

	keepTasks: {
		1: {
			caption: 'Behalten',
			desc: 'Entfernt die NowCommons-Vorlage und fügt einen Hinweis hinzu',
			func: function () {
				NowCommons.getCommonsName();
				if (!NowCommons.CommonsName) {
					return;
				}

				var textbox = document.editform.wpTextbox1;
				textbox.value = textbox.value.replace(NowCommons.TemplateMatch,'');

				var commons_text = "[[commons:File:" + NowCommons.CommonsName + "|Commons-Version]] (zur Sicherheit sollte die lokale Kopie behalten werden)";
				var infoversions = new RegExp(/\|Andere[ _]Versionen\s*=/);
				var lizenz = new RegExp("==[^=]*Lizenz[^=]*==");
				if (textbox.value.match(infoversions)) {
					textbox.value = textbox.value.replace(infoversions, "|Andere Versionen = " + commons_text);
				} else if (textbox.value.match(lizenz)) {
					textbox.value = textbox.value.replace(lizenz, "* Andere Versionen: " + commons_text + "\n\n== Lizenz ==");
				} else {
					textbox.value = textbox.value + "* Andere Versionen: " + commons_text;
				}

				document.editform.wpSummary.value = "Diese Datei ist auf Commons nicht sicher, die lokale Kopie sollte behalten werden.";
			}
		},
		2: {
			caption: 'Mängel',
			desc: 'Ersetzt die NowCommons-Vorlage durch NowCommons/Mängel',
			func: function () {
				var textbox = document.editform.wpTextbox1;
				textbox.value = textbox.value.replace(NowCommons.TemplateMatch, "{{NowCommons/Mängel$3}}");
				document.editform.wpSummary.value = "NowCommons/Mängel";
			}
		},
		4: {
			caption: 'Mängel+DÜP',
			desc: 'Ersetzt die NowCommons-Vorlage durch NowCommons/Mängel, ergänzt {{DÜP}}',
			func: function () {
				var textbox = document.editform.wpTextbox1;
				textbox.value = "{{Dateiüberprüfung|Quelle|Urheber|Lizenz|Freigabe}}\n\n" + textbox.value.replace(NowCommons.TemplateMatch, "{{NowCommons/Mängel$3}}");
				document.editform.wpSummary.value = "NowCommons/Mängel, DÜP";
			}
		}
	},

	init: function () {
		var nc_keep = UrlParameters[NowCommons.KeepParameterName];
		if (!nc_keep) {
 			NowCommons.Baustein = DOM.get('Vorlage_NowCommons');
 			if (!NowCommons.Baustein) {
				return;
 			}

			NowCommons.getCommonsName();
			if (!NowCommons.CommonsName) {
				return;
			}

			NowCommons.markProblems();
			NowCommons.addActionLinks();
		} else {
			NowCommons.keepTasks[nc_keep].func.call();
		}
	},

	addActionLinks: function () {

		var normal_link = '/w/index.php?title=' + wgPageName;

		var action_div = newActionBar('NowCommons_Actions');

		// Löschbutton(s) bauen.
		if (typeof adminflag === 'undefined' || adminflag === true) {
			var del_grund =  'Eine identische Datei ist auf Commons [[:commons:File:' + NowCommons.CommonsName + '|verfügbar]]' + (NowCommons.GleicherName ? '.' : ', alle Referenzen wurden ersetzt.');
			if ( EditCommentLength(del_grund) > -55 ) {
				del_grund = del_grund + ' Sämtliche Metainformationen wurden korrekt übertragen.';
			}
			var normal_dellink = normal_link +  '&action=delete&wpReason=' + encodeURIComponent(del_grund);
			var createNormal = false;

			var del_a = document.createElement('a');
			del_a.style.fontWeight = 'bold';
			del_a.style.fontSize = '150%';
			del_a.style.cursor = 'pointer';
			del_a.innerHTML = 'Löschen';
			if ( typeof AdminActions === 'object' && typeof AdminActions.deletePage === 'function' ) { // Codeispoetry-Löschen
				del_a.setAttribute('onclick', 'AdminActions.nukeDelete("' + del_grund + '", function() { nextItem("NowCommons", 6); }, "File:" + wgTitle, ' + (DOM.get('ca-talk').className === 'new' ? 'false' : '"File talk:' + wgTitle + '"') + ');');
				del_a.title = 'Löscht die Datei sofort mit einer passenden Begründung';
				createNormal = true;
			} else if ( typeof deleting === 'function' ) { // DerHexer-Löschen
				del_a.setAttribute('onclick', 'deleting("' + del_grund + '");');
				del_a.title = 'Löscht die Datei sofort mit einer passenden Begründung';
				createNormal = true;
			} else if (typeof Actions === 'object' && typeof Actions.deleteFile === 'function' && typeof FeedbackArea === 'function') { // D-Löschen
				del_a.setAttribute('onclick', 'var feedback = new FeedbackArea(); Actions.deleteFile(feedback, "' + wgPageName + '", "' + del_grund + '", function() { nextItem("NowCommons", 6);});');
				del_a.title = 'Löscht die Datei sofort mit einer passenden Begründung';
				createNormal = true;
			} else {
				del_a.href = normal_dellink;
				del_a.title = 'Löscht die Datei über die normale Mediawiki-Oberfläche';
				createNormal = false;
			}
			action_div.appendChild(del_a);
			action_div.appendChild(document.createTextNode(' '));

			if (createNormal) {
				action_div.addLink('(Langsam)', 'Löscht die Datei über die normale Mediawiki-Oberfläche', normal_dellink);
			}
		}

		for (var key in NowCommons.keepTasks) {
			action_div.addLink(
				NowCommons.keepTasks[key].caption,
				NowCommons.keepTasks[key].desc,
				normal_link + '&action=edit&' + NowCommons.KeepParameterName + '=' + key
			);
		}
		action_div.addLink('Nächstes', 'Springt zur nächsten als NowCommons markierten Datei', '', "nextItem('NowCommons', 6)");

		NowCommons.Baustein.insertBefore(action_div, NowCommons.Baustein.firstChild);
	},

	markProblems: function () {

		var prob_div = document.createElement('div');
		prob_div.style.color = '#ff0000';
		prob_div.style.width = '100%';
		prob_div.style.textAlign = 'center';

		prob_div.id  = 'NowCommons_Problems';
		prob_div.addItem = function (caption, title) {
			var item = document.createElement('span');
			item.innerHTML = caption;
			item.title = title;
			this.appendChild(item);
			this.appendChild(document.createTextNode(' '));
		};

		// Noch verwendete Datei mit anderem Commonsnamen
		if (!NowCommons.GleicherName) {
			if (document.getElementById('mw-imagepage-section-linkstoimage')) {
				prob_div.addItem ('Verwendung', 'Die Datei liegt auf Commons unter einem anderen Namen und wird noch verwendet.');
			} else if (wgAction === 'view' && !document.getElementById('mw-imagepage-nolinkstoimage')) {
				prob_div.addItem ('Verwendung:Bug!', 'Verwendungen konnten nicht bestimmt werden, vermutlich ein Bug im NowCommons-Script.');
			} else if (wgAction === 'edit') {
				prob_div.addItem ('Verwendung?', 'Verwendungen konnten nicht bestimmt werden, da im Vorschaumodus');
			}
		}

		// existierende Diskussionsseite
		if (document.getElementById('ca-talk').className !== 'new') {
			prob_div.addItem ('Disku', 'Eine Diskussionsseite existiert.');
		}

		// NoCommons-Baustein
		if ( document.getElementById('Vorlage_NoCommons') ) {
			prob_div.addItem ('NoCommons', 'Auf der Dateibeschreibungsseite ist ein NoCommons-Hinweis eingebunden');
		}

		// Commons-Version identisch?
		var found = false;
		var lis = DOM.fetch(DOM.get('mw-imagepage-section-duplicates'), 'li');
		if (lis !== null) {
			for (var n = 0 ; n < lis.length ; ++n) {
				var regexp = new RegExp(('http://commons.wikimedia.org/wiki/Image:' + NowCommons.CommonsName).escapeRE().replace(/[_ ]/g, '[_ ]'));
				if (decodeURIComponent(lis[n].getElementsByTagName('a')[0].getAttribute('href')).search(regexp) === 0) {
					found = true;
					break;
				}
			}
		}
		if (lis === null || !found) {
			prob_div.addItem ('Nicht-identisch', 'Die Commonsversion ist nicht vorhanden oder nicht identisch.');
		}

		NowCommons.Baustein.insertBefore(prob_div, NowCommons.Baustein.firstChild);
		NowCommons.Baustein.insertBefore(document.createElement('span'), prob_div.nextSibling); // stupid IE fix.
	},

	getCommonsName: function () {

		if (document.location.toString().match(/action=(edit|submit)/)) {
			NowCommons.CommonsName = document.editform.wpTextbox1.value.match(NowCommons.TemplateMatch)[4];
			if (!NowCommons.CommonsName) {
				NowCommons.CommonsName = wgTitle;
				NowCommons.GleicherName = true;
 			}
		} else {
			var a = DOM.fetch(NowCommons.Baustein, 'A', 'extiw');
			for (var i = 0; i < a.length; i++) {
				if (((a[i].title.search(/^commons:/i) === 0) || (a[i].href && a[i].href.search("http://commons.wikimedia.org/wiki/File:")===0)) && a[i].title !== "commons:Hauptseite") {
					NowCommons.CommonsName = a[i].title.match(/^[Cc]ommons:\s*[Ff]ile\s*:\s*(.+)$/)[1];
					if (a[i].innerHTML.search("dem selben Namen") >= 0) {
						NowCommons.GleicherName = true;
					}
				}
			}
		}
	}
};

addOnloadHook(NowCommons.init);

// </pre>