Benutzer:Codeispoetry/admin.js

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

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
  • Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
// <pre>
/*global AdminActions, SimpleAjax, UrlParameters, SimpleUI, wgPageName, Join, Form, getBody, wgScript */

if( typeof  UrlParameters === 'undefined') {
	 window.UrlParameters = {};
}
var AdminActions = {

	block: function (reason, heading, user, duration) {

		if (typeof user === 'undefined' || user === null) {
			if (typeof UrlParameters.diff !== 'undefined' || typeof UrlParameters.oldid !== 'undefined') {
				var as = (DOM.get('mw-diff-ntitle2') || DOM.get('mw-revision-info') || DOM.get('mw-revision-info-current')).getElementsByTagName('a');
 				for (var a in as) {
					var match = as[a].getAttributeNode('title').value.match(/[Ss][Pp][Ee][CcZz][Ii][Aa][Ll]:(Sperren|BlockIP)\/([^\/]+)$/);
					if (match !== null && match[2] !== null) {
						user = match[2];
						break;
					}
				}
			} else {
				if (typeof UrlParameters.title !== 'undefined' )
					var lemma = UrlParameters.title.replace(/\+/g, '_');
				else
					var lemma = decodeURIComponent(location.href.match(/\/wiki\/([^#?]+)/)[1]);

				if ( (match = lemma.match (/[Ss]pe[cz]ial:(?:[Bb]eiträge|[Cc]ontributions)(?:\/([^\/]+))?$/) ) !== null) {
					user = (typeof UrlParameters.target !== 'undefined') ? UrlParameters.target.replace(/\+/g, '_') : match[1];
				} else if ( (match = lemma.match (/[Ss]pe[cz]ial:(?:Gelöschte_Beiträge)(?:\/([^\/]+))?$/) ) !== null) {
					user = (typeof UrlParameters.target !== 'undefined') ? UrlParameters.target.replace(/\+/g, '_') : match[1];
				} else if ( (match = lemma.match (/[Ss]pe[cz]ial:(?:[Ss]perren|[Bb]lockIP)(?:\/([^\/]+))?$/) ) !== null) {
					user = (typeof UrlParameters.ip !== 'undefined') ? UrlParameters.ip.replace(/\+/g, '_') : match[1];
				} else if ( (match = lemma.match (/(?:[Bb]enutzer|[Uu]ser)(?:[ _](?:Diskussion|Talk))?:([^\/]+)/) ) !== null) {
					user = match[1];
				}
			}
		}

		function phase2 (request) {
			var form = SimpleAjax.getResponseXML(request).getElementById('blockip');

			if (typeof form == 'undefined') {
				SimpleUI.Box('Benutzer wird gesperrt &hellip; Fehler!', 'admin');
				return;
			}

			if (reason == 'abcxyz') {
				form.wpBlockReason.value = '[[Hilfe:Anmelden#Hinweise_zur_Wahl_des_Benutzernamens|Ungeeigneter Benutzername]]';
				form.wpEmailBan.value = true;
			} else {
				form.wpBlockReason.value = reason;
				if (form.wpBlockAddress.value.search(/\d+\.\d+\.\d+\.\d+/) == -1 && !confirm(form.wpBlockAddress.value + ' wird gesperrt …')) {
					SimpleUI.Box('Benutzer wird gesperrt &hellip; Abgebrochen!', 'admin');
					return;
				}
			}

			if (duration.match(/\d+\s*\w+/) || duration.match(/in(de)?finite/) ) {
				form.wpBlockOther.value = duration;
			} else if (duration.match(/^\s*\d+\s*$/)) {
				form.wpBlockOther.value = duration + ' hours';
			}

			if (SimpleAjax.getResponseXML(request).getElementById('Sperre_vorhanden')) {
				form.wpChangeBlock.value="0";
			}

			var values = Form.serialize(form, 'wpBlock');

			SimpleAjax.post (form.getAttribute('action'), values, function (req) {AdminActions.finalizeApiAction(heading, req);});
		}

		SimpleUI.Box('Benutzer wird gesperrt &hellip;', 'admin');
		SimpleAjax.get ( '/w/index.php?title=Spezial:Sperren/' + encodeURIComponent(user), null, phase2, true);
	},

	deletePage: function (reason, heading, title) {

		if (typeof title === 'undefined') {
			var title = wgPageName;
			if (title === 'Spezial:Linkliste')
					title = (typeof UrlParameters.target !== 'undefined') ? UrlParameters.target.replace(/\+/g, '_') : decodeURIComponent(location.href.match(/\/wiki\/Spezial:Linkliste\/([^#?]+)/)[1]);
		}

		SimpleUI.Box('Seite &bdquo;' + title.replace(/_/g, ' ') + '&rdquo; wird gelöscht &hellip;', 'admin');

		function phase2(request) {
			var token = request.responseXML.getElementsByTagName("page")[0].getAttribute("deletetoken");
			if (!token) {
				if (!request.responseXML.getElementsByTagName("page")[0].getAttribute("length"))
					SimpleUI.Box('Seite &bdquo;' + title.replace(/_/g, ' ') + '&rdquo; wird gelöscht &hellip; Nicht vorhanden!', 'admin');
				else
					SimpleUI.Box('Seite &bdquo;' + title.replace(/_/g, ' ') + '&rdquo; wird gelöscht &hellip; Fehler!', 'admin');
				return;
			}

			SimpleAjax.post ('/w/index.php?action=delete&title=' + encodeURIComponent(title),
					[['wpDeleteReasonList', reason], ['wpEditToken', token]],
					function (req) {AdminActions.finalizeApiAction(heading, req);}, true);
		}

		SimpleAjax.get('/w/api.php?format=xml&action=query&prop=info&intoken=delete&titles=' + encodeURIComponent(title), null, phase2, true);
	},

	nukeDelete: function (reason, headingfunc, title, talk, redir) {

		if (typeof title === 'undefined') {
			var title = wgPageName;
			if (title === 'Spezial:Linkliste')
					title = (typeof UrlParameters.target !== 'undefined') ? UrlParameters.target.replace(/\+/g, '_') : decodeURIComponent(location.href.match(/\/wiki\/Spezial:Linkliste\/([^#?]+)/)[1]);
		}

		if (AdminActions.nuke && ((AdminActions.nuke.done < AdminActions.nuke.files.total) || !AdminActions.nuke.allStarted)) {
			SimpleUI.Box('Es läuft noch ein Nukevorgang!');
			return;
		}

		AdminActions.nuke = new Join(headingfunc, 1);

		AdminActions.deletePage(reason, AdminActions.nuke.check.bind(AdminActions.nuke), title);

		if (talk !== false) {
			AdminActions.nuke.total++;
			AdminActions.deletePage('Vorderseite gelöscht', AdminActions.nuke.check.bind(AdminActions.nuke), talk);
		}

		if (redir === true) {
			var redirs = function (request) {
				var links = getBody(SimpleAjax.getResponseXML(request)).getElementsByTagName('ul')[0];
				if (links != null)
					links = links.getElementsByTagName('li');
				if (links != null) {
					for (var item = 0 ; item < links.length ; ++item) {
						if (!links[item].getElementsByTagName('a'))
							continue;
						var redir = links[item].getElementsByTagName('a')[0].innerHTML;
						AdminActions.nuke.total++;
						AdminActions.deletePage ('Weiterleitungsziel gelöscht', AdminActions.nuke.check.bind(AdminActions.nuke), redir);
					}
				}
				AdminActions.nuke.finalize.bind(AdminActions.nuke)();
			};

			SimpleAjax.get (wgScript + '?title=Spezial:Linkliste/' + encodeURIComponent(title) + '&hidetrans=1&namespace=0&hidelinks=1&hideimages=1', '', redirs, true);
		} else {
			AdminActions.nuke.finalize.bind(AdminActions.nuke)();
		}
	},

	protect: function (reason, heading, title, duration, type, movetype) {

		if (typeof title  == 'undefined' || title == null) {
			var title = wgPageName;
			if (title.search(/Spezial:Linkliste\//) != -1) title = title.replace(/Spezial:Linkliste\//, '');
		}

		if (typeof movetype == 'undefined')
			movetype = type;

		SimpleUI.Box('Seite &bdquo;' + title.replace(/_/g, ' ') + '&rdquo; wird geschützt &hellip;', 'admin');

		function phase2(request) {
			function decodeProtectType (type) {
				if (type == 1) {
					return 'autoconfirmed';
				} else if (type == 2) {
					return 'sysop';
				}
			}
			var token = request.responseXML.getElementsByTagName("page")[0].getAttribute("protecttoken");
			if (!token) {
				if (!request.responseXML.getElementsByTagName('page')[0].getAttribute('length'))
					SimpleUI.Box('Seite &bdquo;' + title.replace(/_/g, ' ') + '&rdquo; wird geschützt &hellip; Nicht vorhanden!', 'admin');
				return;
			}
			SimpleAjax.post ('/w/index.php?action=protect&title=' + encodeURIComponent(title),
					[
						['mwProtect-reason', reason],
						['wpEditToken', token],
						['expires', duration],
						['mwProtect-level-edit', decodeProtectType(type)],
						['mwProtect-level-move', decodeProtectType(movetype)]
					],
					function (req) {AdminActions.finalizeApiAction(heading, req);}, true);
		}
		SimpleAjax.get("/w/api.php?format=xml&action=query&prop=info&intoken=protect&titles=" + title, null, phase2, true);
	},

	addNewUserLogBlock: function() {
		var limit = UrlParameters.limit;
		if (limit > 50 || limit < 1 || typeof limit == 'undefined')
			limit = DOM.fetch(document, "a", "mw-nextlink", 0).innerHTML.match(/\d+/)[0];
		if (limit > 50 || limit < 1)
			return;

		var uls = document.getElementsByTagName("ul");
		for (var i = 0 ; i < uls.length ; i++) {
			var as = uls[i].getElementsByTagName("a");
			if (as.length >= limit * 4) {
				for (var n = 0 ; n < as.length ; n++) {
					if (as[n].childNodes[0].nodeValue == "Sperren") {
						var newlink = document.createElement('a');
						var func = 'AdminActions.block(\'abcxyz\', null, \'' + as[n].title.replace(/Spezial:Sperren\//, '') + '\', \'infinite\');';
						if (typeof lasta !== 'undefined' && lasta.parentNode === as[n].parentNode) {
							func += 'AdminActions.block(\'abcxyz\', null, \'' + lasta.title.replace(/Spezial:Sperren\//, '') + '\', \'infinite\');';
						}
						newlink.setAttribute('onclick', func);
						newlink.style.cursor = 'pointer';
						newlink.appendChild(document.createTextNode('Schnellsperren'));
						as[n].parentNode.insertBefore( newlink, as[n].nextSibling );
						as[n].parentNode.insertBefore( document.createTextNode(' | '), as[n].nextSibling );
						lasta = as[n];
					}
				}
				break;
			}
		}
	},

	finalizeApiAction: function (heading, request) {
		if (heading == null) { // Nischt wurde übergeben – Bau mir eine Box!
			var content_html = request.responseText.match(/<!-- start content -->([\s\S]+)<!-- (end content|NewPP limit report)/m);
			if (!(content_html && SimpleUI.Box(content_html[1], 'admin'))) { // Box bauen, sonst
				if (request.responseXML == null) { // Seiteninhalt ersetzen, und zwar als Text
					var newMatch = request.responseText.match(/(<a\s*name="top"\s*id="top">\s*<\/a>.+)<\/div>\s*<div\s*id="column-one">/);
					if (newMatch)
						document.getElementById('content').innerHTML = newMatch[1];
				}
				else { // oder DOM
					var content = request.responseXML.getElementById('content');
					if (content)
						document.getElementById('content').parentNode.replaceChild(content, document.getElementById('content'));
				}
			}
		}
		else if (typeof heading == 'function') // Eine Funktion wurde übergeben – Ausführen!
			heading(request);
		else if (heading != 0) // Eine URL wurde übergeben – Hinda!
			location.href = heading;
	}
};

if ( ( (UrlParameters.title === 'Spezial:Logbuch') && (UrlParameters.type === 'newusers') ) || (location.href.substring(location.href.indexOf("/wiki/")).search(/Spezial\:Logbuch\/newusers/) != -1) )
		addOnloadHook(AdminActions.addNewUserLogBlock);

// </pre>