User:Eckserah/common.js

(function {	if (window.WhatReallyLinksHereLoaded) return;	window.WhatReallyLinksHereLoaded = true;	mw.loader.using( 'mw.Api' ).then(function { var api = new mw.Api; var actualPageLinks = "No Links Found"; var linkBase = location.protocol + '//' + location.host + '/wiki/'; var whatReallyLinksHerePage = "Special:WhatReallyLinksHere"; var processingLinks = false; var numLinks = 0; var lasthash = location.hash; function generateSpecialPage { var WhatReallyLinksHereContainer = $(' ');

var inputBox = $(' '); var searchBoxForm = $(''); var searchBoxInput = $(''); var searchBoxButton = $('<input type="submit" name="fulltext" class="mw-ui-button" style="background-color: #f8f9fa;color: #222222;display: inline-block;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;min-width: 4em;max-width: 28.75em;margin: 0;padding: 0.57142857em 0.9375em;border: 1px solid #a2a9b1;border-radius: 2px;font-family: inherit;font-size: 1em;font-weight: bold;line-height: 1;text-align: center;-webkit-appearance: none;zoom: 1;vertical-align: middle;cursor: pointer;" value="What Really Links Here" />'); searchBoxForm.append(searchBoxInput).append($(' ')).append(searchBoxButton); searchBoxForm.submit(function(e) {               e.preventDefault;                if (processingLinks)                    return;                processingLinks = true;                $('#LoadingInfo').show;                $('#AllWhatLinksHere').html();                var searchText = $('#WhatReallyLinksHereForm').find('input[type=text]').val;                if (searchText !== ) {                	updateTitleHeading('What Really Links Here');                    setTimeout(function { getLinksFromPage(decodeURIComponent(searchText)); }, 200);               } else                 	updateTitleHeading(searchText);                return false;            }); inputBox.append(searchBoxForm); WhatReallyLinksHereContainer.append(inputBox).append($(' '));

var loadingInfoBox = $(''); var center = $(' ').append($(' Loading. Please wait. ')).append($('')); loadingInfoBox.append(center); WhatReallyLinksHereContainer.append(loadingInfoBox); $('#mw-content-text').children.remove; $('#mw-content-text').append(WhatReallyLinksHereContainer); var firstHeadingText = 'What Really Links Here'; if (wgPageName.indexOf('/') != -1) { var subSearchPage = wgPageName.substr(wgPageName.indexOf('/')+1); $('#WhatReallyLinksHereForm').find('input[type=text]').val(subSearchPage); $('#WhatReallyLinksHereForm').submit; firstHeadingText = 'Pages that really link to "' + subSearchPage + '"'; }           updateTitleHeading(firstHeadingText); }       function updateTitleHeading(newText) { $('#firstHeading').text(newText); document.title = newText + ' - The Fallout Wiki'; }		function getLinksFromPage(pageName) { api.get({				action: 'query',				prop: 'linkshere',				format: 'json',				lhshow: '!redirect',				lhlimit: 500,				titles: pageName			}).done(function(e) {				var linkInfos = e.query.pages;		       for (var titleLink in linkInfos) {		        	if (linkInfos[titleLink].linkshere !== undefined) {			            numLinks = linkInfos[titleLink].linkshere.length;			            for (var linkInf in linkInfos[titleLink].linkshere) {			                var linkCheck = checkIfLinksReal(linkInfos[titleLink].linkshere[linkInf],pageName);			            }		        	} else {		        		$('#AllWhatLinksHere').append(actualPageLinks);		        		$('#LoadingInfo').hide;		        	}		        }			}); }		function checkIfLinksReal(pageLinks, basePageName) { api.get({				action: 'parse',				prop: 'wikitext',				format: 'json',				page: pageLinks.title			}).done(function(data) {				if (data.error === undefined) {		           var wikitext = data.parse.wikitext['*'];		            if (findLinkInPage(basePageName, wikitext)) {		                $('#AllWhatLinksHere').append($(' '+pageLinks.title+' '));		                var allLinks = $('#AllWhatLinksHere div').sort(function (a,b) { var aText = $(a).find('a').text; var bText = $(b).find('a').text; if (aText > bText) return 1; if (aText < bText) return -1; return 0; });						$('#AllWhatLinksHere').append(allLinks);		           }		            numLinks = numLinks - 1;		            if (numLinks <= 0) {		            	if ($('#AllWhatLinksHere').find('div').length === 0)		            		$('#AllWhatLinksHere').append(actualPageLinks);		                $('#LoadingInfo').hide;		                processingLinks = false;		            }		        } else {		        	numLinks = numLinks - 1;                    if (numLinks <= 0) {		            	if ($('#AllWhatLinksHere').find('div').length === 0)		            		$('#AllWhatLinksHere').append(actualPageLinks);		                $('#LoadingInfo').hide;		                processingLinks = false;		            }		        	console.log(parseWikiTextUrl+pageLinks.title);		        	console.log(data.error);		        }			}); }		function concatPageLink { return linkBase+whatReallyLinksHerePage+'/'+wgPageName; }		function escapeRegExp(text) { return text.replace(/[-[\]{}*+?.,\\^$|#\s]/g, '\\$&'); }		function findLinkInPage(SearchPageTitle, wikiText) { var modPageTitle = escapeRegExp(SearchPageTitle).replace(/[ _]/g,'[ _]'); //var regexStr = '\\[\\[' + modPageTitle + '*[^\\]]+\\]\\]'; var regexStr = '\\[{2}' + modPageTitle + '[|#\]*.*\\]{2}'; var testReg = new RegExp(regexStr); return testReg.test(wikiText); }		$(document).ready(function {			if (wgPageName.indexOf(whatReallyLinksHerePage) === 0) {				generateSpecialPage;			}           var whatReallyLinksHereElem = $(' ').append($('').text('What really links here'));			var baseLink = $('#WikiaBarWrapper').find('[data-name=whatlinkshere]');			if (baseLink.length > 0) {				baseLink = baseLink.parent;				whatReallyLinksHereElem.insertAfter(baseLink);			} else {				baseLink = $('#WikiaBarWrapper').find('.tools-customize');				whatReallyLinksHereElem.insertBefore(baseLink);            }		}); }); });