Jump to content

सदस्य:अभय नातू/शोधसंहिता.js

विकिपीडिया, मुक्‍त ज्ञानकोशातून

नोंद: साठवून ठेवल्यानंतर बदल पहाण्यासाठी कदाचित तुमच्या ब्राऊजरच्या कॅचेला बायपास करावे लागेल.

  • फ़ायरफ़ॉक्स / सफ़ारी: धरुन ठेवा Shift टिचकी मारताना Reload, किंवा हे दाबताना Ctrl-F5 किंवा Ctrl-R (⌘-R मॅकवर)
  • गुगल क्रोम: दाबा Ctrl-Shift-R (⌘-Shift-R मॅकसाठी)
  • ओपेरा: कडे जा Menu → Settings (ओपेरा → पसंतीक्रम on a Mac) आणि मग गोपनियता आणि सुरक्षा → ब्राउजिंग डाटा काढून टाका → कॅचे छायाचित्रे आणि धारिणी.
/*
 */
(function($, mw)
{
	if (typeof mw !== 'object' || (mw.config.get('wgAction') !== 'edit' && mw.config.get('wgAction') !== 'submit'))
		return;
 
	mw.util.addCSS('#linkCheckerBox table a{padding:.2em 1px}' +
		'#linkCheckerBox table a:hover{background:#0645AD;border-radius:2px;color:#FFF;text-decoration:none}' +
		'#linkCheckerBox tr:hover{background:#DFE7F4}' +
		'#linkCheckerBox td input{-moz-box-sizing:border-box;box-sizing:border-box;width:100%}');
 
	function click(a)
	{
		mw.loader.using('jquery.tablesorter', loadLinkChecker);
	}
	function loadLinkChecker()
	{
		if (window.wikEd && window.wikEd.useWikEd) wikEd.UpdateTextarea();
		var elements = document.forms['editform'].elements;
		var textbox = elements['wpTextbox1'], summary = elements['wpSummary'];
		if (!textbox) return;
 
		var t = textbox.value;
		/* See includes/parser/Parser.php */
		var re = /\bhttps?:\/\/[^\][<>"\x00-\x20\x7F|]*[^\][<>"\x00-\x20\x7F,;\\.:!?)|}]/g;
		var m;
		var a = [];
		while (m = re.exec(t))
		{
			m.number = -1;
			for (var p = m.index; p >= 0; m.number++)
				p = p < m[0].length ? -1 : t.lastIndexOf(m[0], p - m[0].length);
			a.push(m);
		}
 
		var html = '<div id="linkCheckerBox" style="padding:1em 0"><form action="#">' +
			'<div style="clear:both;max-height:23.1em;overflow:auto">' +
			'<table class="wikitable sortable" style="margin:0;width:100%">' +
			'<tr><th width="40%">मूळ</th>';
		if (option('context')) html += '<th width="10%">संदर्भ</th>';
		html += '<th width="10%">निवडा</th>' +
			'<th class="unsortable" width="10%"><acronym title="Archive.org-Links einfach komplett einfügen">बदल</acronym></th>' +
			'<th width="30%">शीर्षक</th></tr>';
		for (var i = 0; i < a.length; i++)
		{
			var tree = createContextTree(t, a[i].index, a[i].index + a[i][0].length);
			if (!tree) continue;
			if (tree.parent && tree.parent.uri) a[i][0] = tree.parent.uri;
			var webarchiv = parseWebarchiv(a[i][0]);
			var uri = webarchiv && webarchiv.url || a[i][0];
			html += '<tr class="uri' + i;
			if (tree.parent)
			{
				if (/^(?:Toter|Dead) Link$/i.test(tree.parent.type) ||
					findParameter(tree.parent.parameters, 'offline', '\\S.*') >= 0)
					html += ' hintergrundfarbe8';
				else if (tree.archive)
					html += ' hintergrundfarbe5';
			}
			html += '"><td><a class="goto" data-number="' + a[i].number + '" data-uri="' + uri +
				'" href="' + uri + '" title="Gehe zu' + (a[i].i > 0 ?
				'm ' + (a[i].i + 1) + '. Vorkommen dieses Weblinks' : ' diesem Weblink') + '">↓</a> ';
			var dirs = uri.split(/(^[^\/?]+\/+[^\/?]+\/*|\?[^?]+|[^\/?]+\/*)/);
			if (dirs.length <= 0) dirs = [uri];
			for (var d = 0; d < dirs.length; d++)
			{
				if (!dirs[d]) continue;
				var href = dirs.slice(0, d + 1).join('');
				html += '<a href="' + mw.html.escape(href) + '" target="_blank">';
				if (dirs[d].length > 3 && href.indexOf('?') >= 0)
					html += mw.html.escape(dirs[d].charAt(0)) + '…';
				else
					html += mw.html.escape(dirs[d].replace(/^(?:\w+:\/+|www\.)*/, '').replace(/#...+/, '#…')).replace(/\B_\B/g, '_<wbr>');
				html += '</a>';
			}
			var context = '', text = tree.text || '', node = tree.parent;
			while (node)
			{
				if (context) context = ' → ' + context;
				context = (node.type === 'LINK' ? 'Link' : node.type === 'REF' ? 'Ref.' :
					node.type.replace(/^Infobox.*/, 'Infobox')) + context;
				if (!text) text = node.text || '';
				node = node.parent;
			}
			var site = uri.replace(/^[^\/]*\/+(?:www\.)?/i, '').replace(/\/.*$/, '');
			var euquery = uri.replace(/[^\/]+$/, '').replace(/^[^\/]*\/+/, '').replace(/^www\./i, '*.');
			html += '</td>';
			if (option('context')) html += '<td>' + context + '</td>';
			html += '<td data-sort-value="0">' +
				'<a href="' + mw.html.escape(option('search').replace(/%s/g, 'site:' +
					encodeURIComponent(site + (text ? ' ' + text : '')))) + '" target="_blank"' +
				' title="आंतरजाल शोध">शोध</a>&nbsp;' +
				'<a href="http://wayback.archive.org/web/*/' + uri + '" target="_blank"' +
				' title="वेबॅक मशिनचे विदागार">वेबॅक</a>&nbsp;' +
				'<a href="http://www.webcitation.org/query.php?url=' + uri + '" target="_blank"' +
				' title="वेबसायटेशन">वेबसाय.</a>&nbsp;' +
				'<a class="exturlusage" href="/wiki/Special:LinkSearch/' + euquery + '" target="_blank"' +
				' title="या संकेतस्थळावरुन आलेले विकिपीडियातील संदर्भ">विकि</a>' +
				'</td><td><input name="r' + i + '" type="url" value="';
			if (webarchiv && webarchiv.url)
				html += webarchiv.archive;
			else if (/^\w+:\/+[^\/]+\.\w+$/.test(a[i][0]))
				html += a[i][0] + '/';
			else if (/<!--[^>]*-->/.test(a[i][0]))
				html += a[i][0].replace(/<!--[^>]*-->/g, '');
			html += '"></td><td data-sort-value="' + mw.html.escape(text.replace(/^[^\w\xC0-\u1FFF]+/, '')) +
				'"><input name="t' + i + '" type="text" value="' + mw.html.escape(text.replace(/\s+/g, ' ')) + '"></td></tr>';
 
			if (euquery && a.length <= option('autoLimit'))
				(function(i)
				{
					$.ajax('//de.wikipedia.org/w/api.php?action=query&format=xml&list=exturlusage&euprop=&euquery=' + euquery, {
						dataType: 'html',
						error: function(o, s, e) { alert(e); },
						success: function(data, s, o)
						{
							var c = data.indexOf('euoffset') > 0 ? '10+' :
								Math.round((data.indexOf('/exturlusage') - 47) / 6);
							if (typeof c === 'string' || c > 0)
							{
								var a = $('.uri' + i + ' .exturlusage');
								a.text(c);
								a.parent().attr('data-sort-value', typeof c === 'number' ? c : 10);
							}
						}
					});
				})(i);
		}
		html += '</table></div>' +
			'<div class="buttons"><input type="submit" value="बदल लागू करा"> ' +
			'<a class="cancel" href="#">रद्द करा</a>' +
			' | <a class="pref" href="#">मांडणी</a>' +
			'</div></form>' +
			'<form action="#" class="pref" style="display:none"><fieldset><legend>Einstellungen</legend>' +
			'<input id="prefContext" type="checkbox" value="1"' + (option('context') ? ' checked="checked"' : '') + '>' +
			'<label for="prefContext">Kontextinformationen für die Fundstellen anzeigen</label><br />' +
			'Websuchmaschine: <input id="prefSearch" size="40" type="text" value="' + mw.html.escape(option('search')) + '"><br />' +
			'Obergrenze für die Anzeige der Verwendungshäufigkeit: ' +
			'<input id="prefAutoLimit" min="0" size="4" type="number" value="' + mw.html.escape(option('autoLimit')) + '"> Weblinks im Artikel<br />' +
			//'Automatische Ersetzungen (z.&nbsp;B. <code>www.alt.de/ www.neu.de/</code>):<br /><textarea rows="5"></textarea>' +
			'<input type="submit" value="Einstellungen speichern"> ' +
			'<a class="cancel" href="#">Abbrechen</a>' +
			'</fieldset></form>' +
			'</div>';
		$('#editform').before(html);
		var t = $('#linkCheckerBox table');
		if (t.tablesorter) t.tablesorter();
		$('#linkCheckerBox a.goto').on('click', function()
		{
			if (window.wikEd && window.wikEd.useWikEd) wikEd.UpdateTextarea();
			var t = textbox.value;
			var p = -1;
			for (var n = this.getAttribute('data-number'); n >= 0; n--)
				p = t.indexOf(this.getAttribute('data-uri'), p + 1);
			if (p < 0) return false;
			textbox.focus();
			if (typeof textbox.selectionStart === 'number')
			{
				textbox.selectionStart = p;
				textbox.selectionEnd = p + this.getAttribute('data-uri').length;
			}
			else if (typeof textbox.selection === 'object')
			{
				var range = textbox.selection.createRange();
				range.move('character', p);
				range.moveEnd('character', this.getAttribute('data-uri').length);
			}
			return false;
		});
		$('#linkCheckerBox form:first-child').on('submit', function()
		{
			if (window.wikEd && window.wikEd.useWikEd) wikEd.UpdateTextarea();
			var t = textbox.value;
			var count = 0;
			for (var i = a.length; i--; )
			{
				var p = -a[i][0].length;
				for (var n = a[i].number; n >= 0; n--)
					p = t.indexOf(a[i][0], p + a[i][0].length);
				if (p < 0) continue;
				if (!this.elements['r' + i]) continue;
				var r = this.elements['r' + i].value.replace(/^\s+|\s+$/g, '') || a[i][0];
				var text = this.elements['t' + i].value.replace(/^\s+|\s+$/g, '');
 
				var tree = createContextTree(t, p, p + a[i][0].length), node = tree;
				if (!tree) continue;
				if (tree.archive && r && r !== a[i][0]) tree.archive = false;
				var archive = tree.archive || parseWebarchiv(r);
 
				if (node.parent.type === 'Waybackarchiv' || node.parent.type === 'WBA' ||
					(/^(?:Toter|Dead) Link$/i.test(node.parent.type) && r !== a[i][0]))
					node = node.parent;
				if (archive)
				{
					if (/^(?:Internetquelle|Cite (?:web|news))$/.test(node.parent.type))
					{
						node = node.parent;
						var de = node.type === 'Internetquelle';
						deleteParameter(node.parameters, ['offline',
							/* Drop misspelled parameters */
							'archivurl', 'archivdate', 'archivdatum', 'archive-url', 'archive-date', 'archive-datum',
							'archvieurl', 'archviedate', 'web-archiv', 'webarchiv',
							'https?:\\/\\/[^=|]*']);
						putParameter(node.parameters, node.parameter || 'url', archive.url || a[i][0], 0);
						putParameter(node.parameters, de ? 'titel' : 'title', text, 1);
						var where = de ? ['url', 'titel', 'titelerg', 'werk', 'seiten', 'datum', 'archiv-url'] :
							['url', 'title', 'accessdate', 'last', 'first', 'authorlink', 'coauthors',
							'date', 'format', 'work', 'publisher', 'pages', 'language', 'archiveurl'];
						putParameter(node.parameters, de ? 'archiv-url' : 'archiveurl', archive.archive || '', where);
						putParameter(node.parameters, de ? 'archiv-datum' : 'archivedate', archive.date || '', where);
						r = node.parameters.join('');
					}
					else
					{
						if (node.parent.type === 'LINK' || node.parent.type === 'Webarchiv')
							node = node.parent;
						r = '{{Webarchiv | url=' + (archive.url || a[i][0]) + ' | ' + (archive.id
							? 'webciteID=' + archive.id : archive.is
							? 'archive-is=' + archive.is
							: 'wayback=' + archive.timestamp) + ' | text=' + text + '}}';
					}
				}
				else if (/^(?:Internetquelle|Cite (?:web|news))$/.test(node.parent.type))
				{
					node = node.parent;
					var de = node.type === 'Internetquelle';
					deleteParameter(node.parameters, ['archiv-url', 'archiv-datum', 'archiveurl', 'archivedate',
						/* Drop misspelled parameters */
						'archivurl', 'archivdate', 'archivdatum', 'archive-url', 'archive-date', 'archive-datum',
						'archvieurl', 'archviedate', 'web-archiv', 'webarchiv',
						'https?:\\/\\/[^=|]*']);
					if (r !== a[i][0]) deleteParameter(node.parameters, 'offline');
					putParameter(node.parameters, node.parameter || 'url', r, 0);
					putParameter(node.parameters, de ? 'titel' : 'title', text, 1);
					r = node.parameters.join('');
				}
				else if (node.parent.type === 'LINK' || node.parent.type === 'Webarchiv' ||
					(text && (!node.parent || node.parent.type === 'REF')))
				{
					r = '[' + r + (text ? ' ' + text : '') + ']';
					if (node.parent && node.parent.type !== 'REF') node = node.parent;
				}
				if (r === t.slice(node.start, node.end)) continue;
				t = t.slice(0, node.start) + r + t.slice(node.end);
				count++;
			}
			textbox.focus();
			if (t !== textbox.value)
			{
				var s = textbox.scrollTop, s0 = textbox.selectionStart, s1 = textbox.selectionEnd;
				textbox.value = t;
				textbox.selectionStart = s0, textbox.selectionEnd = s1, textbox.scrollTop = s;
 
				s = summary.value, s0 = s.length;
				s = s.replace(/^\s+|\s+$/g, '');
				if (/\d+\W*Weblinks?\s+geändert$/.test(s))
				{
					s = s.replace(/(\d)+\W*(?=Weblinks?\s+geändert$)/,
						function($0, $1) { return Math.max($1, count) + '+ '; });
				}
				else
				{
					if (/[^!,./:;?]$/.test(s)) s += ';';
					if (/\S$/.test(s)) s += ' ';
					s += ' संपादनासाठी [[सदस्य:संतोष दहिवळ/शोध संहीता.js|शोध संहीता]] वापरली';
				}
				summary.value = s, summary.selectionStart = s0, summary.selectionEnd = s.length;
			}
			$('#linkCheckerBox').remove();
			if (window.wikEd && window.wikEd.useWikEd) wikEd.UpdateFrame();
			return false;
		});
		$('#linkCheckerBox .buttons a.cancel').on('click', function()
		{
			$('#linkCheckerBox').remove();
			return false;
		});
		$('#linkCheckerBox a.pref').on('click', function()
		{
			$('#linkCheckerBox form.pref').show();
			$('#linkCheckerBox .buttons').hide();
			return false;
		});
		$('#linkCheckerBox .pref').on('submit', function()
		{
			option('autoLimit', $('#prefAutoLimit')[0].value);
			option('context', $('#prefContext')[0].checked);
			option('search', $('#prefSearch')[0].value);
			$('#linkCheckerBox form.pref').hide();
			$('#linkCheckerBox .buttons').show();
			return false;
		});
		$('#linkCheckerBox .pref a.cancel').on('click', function()
		{
			$('#linkCheckerBox form.pref').hide();
			$('#linkCheckerBox .buttons').show();
			return false;
		});
		return false;
	}
	function createContextTree(t, uriStart, uriEnd)
	{
		var tree = { type: 'URI', start: uriStart, end: uriEnd }, node = tree;
		while (node && node.type !== 'REF')
		{
			node.parent = findParent(t, node.start, node.end);
			node = node.parent;
		}
		if (tree.parent.parameters)
		{
			var m = /\|\s*archiv[e-]url\s*=\s*(https?:\/\/[^\s|}]+)/.exec(t.slice(tree.parent.start, tree.parent.end));
			if (m)
			{
				/* Bei Vorlagen mit zwei Weblinks den Archivlink nicht als eigenständig behandeln */
				if (tree.parent.start + m.index + m[0].length - m[1].length !== tree.start) return false;
				/* Archivlink statt dessen als Parameter beim Originallink mitführen */
				tree.archive = parseWebarchiv(m[1]) || { archive: m[1] };
			}
			else if (tree.parent.type === 'Webarchiv')
			{
				if (m = /\|\s*wayback\s*=\s*([\d*]+)/.exec(t.slice(tree.parent.start, tree.parent.end)))
					tree.archive = { timestamp: m[1] };
				else if (m = /\|\s*webciteID\s*=\s*(\w+)/.exec(t.slice(tree.parent.start, tree.parent.end)))
					tree.archive = { id: m[1] };
				else if (m = /\|\s*archive-is\s*=\s*([^\s{|}]+)/.exec(t.slice(tree.parent.start, tree.parent.end)))
					tree.archive = { is: m[1] };
				else if (m = /^[^|]*\|\s*([\d*]+)/.exec(t.slice(tree.parent.start, tree.parent.end)))
					tree.archive = { timestamp: m[1] };
			}
		}
		return tree;
	}
	function findParent(t, parsedStart, parsedEnd)
	{
		var i = parsedStart, skipSquare = 0, skipCurly = 0, parameter = undefined;
		while (--i >= 0)
		{
			if (t.charAt(i) === '|' && skipCurly <= 0 && !parameter && parameter !== false)
			{
				var a = /^\s*([^={|}]*?)\s*=\s*$/.exec(t.slice(i + 1, parsedStart));
				parameter = a ? a[1] : false;
			}
			else if (t.charAt(i) === '}') skipCurly++;
			else if (t.charAt(i) === '{' && skipCurly-- <= 0)
			{
				i--;
				/* Schachtelung am Anfang ist geklärt, am Ende noch nicht */
				var a = /^\{\s*([^{|}]*?)\s*\|/.exec(t.slice(i + 1, parsedStart));
				var b = /^(?:[^{}]|\{+[^{}]*\}\})*\}\}/.exec(t.slice(parsedEnd));
				if (!a || !b) return false;
				var node = {
					type: a[1].charAt(0).toUpperCase() + a[1].slice(1).replace(/_/g, ' '),
					start: i, end: parsedEnd + b[0].length, parameter: parameter,
					parameters: (t.slice(i, parsedEnd) + b[0]).split(/(\|(?:[^{|}]|\{+[^{}]*\}\})*)/)
				};
				if (!node.text && (a = /\|\s*(?:Text|Titel|Title)\s*=\s*((?:[^{|}]|\{+[^{}]*\}\})*?)\s*[|}]/i.exec(t.slice(node.start, node.end))))
					node.text = a[1];
				if (!node.text && node.type === 'Webarchiv' && node.parameters.length > 5 &&
					(a = /^\|\s*([^=]*?)\s*$/.exec(node.parameters[5])))
					node.text = a[1];
				return node;
			}
			else if (t.charAt(i) === ']') skipSquare++;
			else if (t.charAt(i) === '[' && skipSquare-- <= 0)
			{
				var a = /^\s*$/.test(t.slice(i + 1, parsedStart));
				/* Einfache Schachtelung akzeptieren, aber sofort verwerfen */
				var b = /^((?:<!--[^>]*-->|[^\s[\]])*)(?:\s+((?:[^[\]]|\[\[[^[\]]*\]\])*))?\]/.exec(t.slice(parsedEnd));
				if (!a || !b) return false;
				return { type: 'LINK', start: i, end: parsedEnd + b[0].length,
					uri: t.slice(parsedStart, parsedEnd + b[1].length),
					text: b[2] ? b[2].replace(/[[\]]+/g, '') : '' };
			}
			else if (t.charAt(i) === '\n' && skipCurly <= 0)
			{
				var a = /^\* *$/.test(t.slice(i + 1, parsedStart));
				var b = /^ +([^\r\n<>[\]{|}]*[^\s<>[\]{|}])/.exec(t.slice(parsedEnd));
				if (a && b)
				{
					var t = b[1].replace(/^[\s:–-]+/, '');
					if (t) return { type: 'LINK', start: parsedStart, end: parsedEnd + b[0].length, text: t };
				}
			}
			else if (t.charAt(i) === '<')
			{
				var a = /^ref\b[^<>]*>[^<>]*$/.test(t.slice(i + 1, parsedStart));
				var b = /^[^<>]*<\/ref\s*>/.exec(t.slice(parsedEnd));
				if (!a || !b) return false;
				return { type: 'REF', start: i, end: parsedEnd + b[0].length };
			}
		}
		return false;
	}
	function parseWebarchiv(uri)
	{
		return parseWayback(uri) || parseWebCite(uri) || parseArchiveIs(uri);
	}
	function parseWayback(uri)
	{
		var m = /\barchive\.org\b.*(\b(\d{4})(\d\d)(\d\d)\d{6}|\/\*)\/(\S*)/i.exec(uri);
		if (!m)
			return false;
		if (m[2] && (m[2] < 1970 || m[2] > new Date().getFullYear() || m[3] < 1 || m[3] > 12 || m[4] < 1 || m[4] > 31))
			return false;
		var t = m[2] ? m[1] : '*';
		var url = /^\w+:\/\//.test(m[5]) ? m[5] : m[5].replace(/^(?:http:)?\/*/, 'http://');
		return { archive: 'http://web.archive.org/web/' + t + '/' + url,
			url: url, timestamp: t, date: m[2] ? m[2] + '-' + m[3] + '-' + m[4] : '' };
	}
	function parseWebCite(uri)
	{
		var m = /\bwebcitation\.org\/(.*\bid=(\d+)|\w+$)/i.exec(uri);
		if (!m)
			return false;
		var id = m[2] ? m[2] : m[1];
		return { archive: 'http://www.webcitation.org/' + id, id: id };
	}
	function parseArchiveIs(uri)
	{
		var m;
		if (m = /\barchive\.is\/((\d{4})\W*(\d\d)\W*(\d\d)\S*)\/(https?:\/\/\S+)/.exec(uri))
			return { archive: uri, is: m[1].replace(/\D+/g, ''), url: m[5], date: m[2] + '-' + m[3] + '-' + m[4] };
		if (m = /\barchive\.is\/(\S+)/.exec(uri))
			return { archive: uri, is: m[1] };
		return false;
	}
	function findParameter(a, name, value)
	{
		var r = -1;
		if (!a) return r;
		var re = new RegExp('^\\s*\\|\\s*' + name + '\\s*=' + (value ? '\\s*' + value + '\\s*$' : ''));
		for (var i = a.length; i--; )
		{
			if (re.test(a[i]))
				if (r < 0) r = i;
				/* Drop duplicate parameters */
				else a[i] = '';
		}
		return r;
	}
	function putParameter(a, name, value, where)
	{
		value = (value || '').replace(/\$/g, '$$$$');
		var i = findParameter(a, name);
		if (i >= 0)
		{
			if (value)
				a[i] = a[i].replace(/^([^=]*=\s*)(?:[^{}]|\{+[^{}]*\}\})*?(\s*\}*)$/, '$1' + value + '$2');
			return a;
		}
		var p = where;
		if (typeof p !== 'number')
		{
			var p = a.length - 1;
			if (where)
			{
				var re = new RegExp('^\\|\\s*(?:' + where.join('|') + ')\\s*=');
				for (var i = a.length; i--; ) if (re.test(a[i])) { p = i; break; }
			}
		}
		name = name.replace(/\$/g, '$$$$');
		if (p <= 0)
			a[p] = a[p].replace(/(\s*)$/, ' | ' + name + '=' + value + '$1');
		else
			a[p] = a[p].replace(/^((\|\s*)[\s\S]*?(\s*))(\}*)$/, '$1$2' + name + '=' + value + '$3$4');
		return a;
	}
	function deleteParameter(a, name)
	{
		var re = new RegExp('^\\|\\s*(?:' + (typeof name === 'string' ? name : name.join('|')) + ')\\s*=[^|]*(?=\\}\\}$|$)');
		for (var i = a.length; i--; )
			a[i] = a[i].replace(re, '');
		return a;
	}
	function option(key, value)
	{
		var a = 'weblinkChecker' + key[0].toUpperCase() + key.slice(1);
		if (typeof value === 'boolean') value = value ? '1' : '';
		if (typeof value !== 'undefined' && localStorage)
			localStorage[a] = value;
		value = localStorage && localStorage[a];
		if (typeof value === 'undefined') value = window[a];
		switch (key.toLowerCase())
		{
			case 'autolimit': value = value || 8; break;
			case 'search': value = value || 'http://duckduckgo.com/?q=%s'; break;
		}
		return '' + value;
	}
 
	if (typeof $ === 'function' && mw.user.options.get('usebetatoolbar'))
	{
		mw.loader.using('ext.wikiEditor', function()
		{
			$(document).ready(function()
			{
				$('#wpTextbox1').wikiEditor('addToToolbar', {
					'section': 'main',
					'group': 'insert',
					'tools': {
						'weblinkChecker': {
							'label': 'Weblink-Helfer',
							'type': 'button',
							'icon': '//upload.wikimedia.org/wikipedia/commons/thumb/7/72/Crystal_wp.png/22px-Crystal_wp.png',
							'action': {
								'type': 'callback',
								'execute': function() { return click(this); }
							}
						}
					}
				});
			});
		});
	}
	else if (typeof $ === 'function' && mw.user.options.get('showtoolbar'))
	{
		mw.loader.using('mediawiki.action.edit', function()
		{
			mw.toolbar.addButton('//upload.wikimedia.org/wikipedia/commons/thumb/7/72/Crystal_wp.png/22px-Crystal_wp.png',
				'Weblink-Helfer', '', '', '', 'mw-customeditbutton-weblinkChecker');
			$(function()
			{
				$('#mw-customeditbutton-weblinkChecker').click(function() { return click(this); });
			});
		});
	}
	else if (typeof hookEvent === 'function')
	{
		hookEvent('load', function()
		{
			/* Notfalls als Link unter dem Bearbeitungsfenster */
			var e = document.getElementById('editform');
			if (!e) return;
			e = e.getElementsByTagName('SPAN');
			for (var i = e.length; i--; )
				if (e[i].className === 'editHelp')
				{
					var a = document.createElement('A');
					a.href = '#';
					a.onclick = function() { return click(this); }
					a.appendChild(document.createTextNode('Weblink-Helfer'));
					e[i].appendChild(document.createTextNode(' | '));
					e[i].appendChild(a);
					break;
				}
		});
	}
})(jQuery, mediaWiki);