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 maxNumProcessingAtOnce = 250; var numLinks = 0; var totalLinks = 0; var currNumProcessing = 0; var lasthash = location.hash; var mainLinkArea = '#AllWhatLinksHere'; var RedirectArea = '#AllRedirectArea'; var hasRedirects = false; var linkData = { links: [], Redirects: [] }; function generateSpecialPage { var WhatReallyLinksHereContainer = $(' ');

var inputBox = $(' '); inputBox.append($(' ').append($(' ')).append($(' ')).append($(' ')).append($(' ')).append($(' '))); 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($(' ').append(searchBoxInput).append($(' ')).append(searchBoxButton)); var filterForm = $(' ').append(searchBoxInput.clone.prop('name','filter').prop('id','FilterTxt').css('width','300px')).append($(' ')).append(searchBoxButton.clone.prop('type','button').prop('name','filter').prop('id','FilterBtn').val('Link Text Filter').css('margin-top','5px')).append(searchBoxButton.clone.prop('type','button').prop('name','clearfilter').prop('id','ClearFilterBtn').val('Clear Filter').css({'margin-top':'5px','margin-left':'3px'})); filterForm.append($(' ')).append($(' ').append($(' ')).append($(' ').text('No Display Text'))); filterForm.append($(' ').append($(' ')).append($(' ').text('Partial Match'))); searchBoxForm.append(filterForm); searchBoxForm.submit(function(e) {               e.preventDefault;                if (processingLinks)                    return;                processingLinks = true;                $('#LoadingInfo').show;                $(mainLinkArea).html();                $(RedirectArea).html();                var searchText = $('#WhatReallyLinksHereForm').find('#searchBox').val;                if (searchText !== '') {                	updateTitleHeading('What Really Links Here');                    setTimeout(function { getLinksFromPage(decodeURIComponent(searchText), '', false); }, 200);               } else                 	updateTitleHeading(searchText);                return false;            }); searchBoxForm.find('#FilterBtn').click(function(e) {               var inputInfo = $('#FilterTxt').val;                if (inputInfo !== '') {                    highlightFilters(inputInfo);                }            }); searchBoxForm.find('#ClearFilterBtn').click(function(e) {           	$('#FilterCount').text();                $('.filterHighlights').css('background-color',).removeClass('filterHighlights');            }); inputBox.append(searchBoxForm); WhatReallyLinksHereContainer.append(inputBox).append($(' ')).append($(' '));

var loadingInfoBox = $(''); var center = $(' ').append($(' Loading. Please wait. 0/0 Done ')).append($('')); loadingInfoBox.append(center); WhatReallyLinksHereContainer.append(loadingInfoBox); $('#mw-content-text').children.remove; $('#mw-content-text').append(WhatReallyLinksHereContainer); var firstHeadingText = 'What Really Links Here'; if (mw.config.get("wgPageName").indexOf('/') != -1) { var subSearchPage = wgPageName.substr(wgPageName.indexOf('/')+1); if (subSearchPage !== '') { $('#WhatReallyLinksHereForm').find('#searchBox').val(subSearchPage); $('#WhatReallyLinksHereForm').submit; firstHeadingText = 'Pages that really link to "' + subSearchPage + '"'; }           }            updateTitleHeading(firstHeadingText); }       function highlightFilters(filterText) { $('.filterHighlights').css('background-color','').removeClass('filterHighlights'); var filterCount = 0; if (linkData.links.length > 0) { $.each(linkData.links, function(link) {                   for (var i = 0; i < linkData.links[link].arr.length; i++) {                        if (linkData.links[link].arr[i].indexOf('|') > -1) {                            var linkText = linkData.links[link].arr[i].substr(linkData.links[link].arr[i].indexOf('|')+1);                            linkText = linkText.substr(0,linkText.indexOf(']'));                            if (linkText.toLowerCase.indexOf(filterText) > -1) {                            	filterCount++;                                $('#'+linkData.links[link].id).addClass('filterHighlights').css('background-color','#5ff765');                            }                        } else {                        	$('#'+linkData.links[link].id).addClass('filterHighlights').css('background-color','#FFC107');                        }                    }                }); }           if (linkData.Redirects.length > 0) { $.each(linkData.Redirects, function(link) {                   for (var i = 0; i < linkData.Redirects[link].arr.length; i++) {                        if (linkData.Redirects[link].arr[i].indexOf('|') > -1) {                            var linkText = linkData.Redirects[link].arr[i].substr(linkData.Redirects[link].arr[i].indexOf('|')+1);                            linkText = linkText.substr(0,linkText.indexOf(']'));                            if (linkText.toLowerCase.indexOf(filterText) > -1) {                            	filterCount++;                                $('#'+linkData.Redirects[link].id).addClass('filterHighlights').css('background-color','#5ff765');                            }                        }                    }                }); }           $('#FilterCount').text(filterCount+' Matches from filters.'); }       function updateTitleHeading(newText) { $('#firstHeading').text(newText); document.title = newText + ' - The Fallout Wiki'; }		function getLinksFromPage(pageName, lhContinue, isRedirectPage) { if (lhContinue === undefined) lhContinue = ''; api.get({				action: 'query',				prop: 'linkshere',				format: 'json',				//lhshow: 'redirect|!redirect',				lhlimit: 500,				titles: pageName,				lhcontinue: lhContinue			}).done(function(e) {				linkData = { links: [], Redirects: [] };				$('#LinkCount').html();				$('#RedirectCount').html();				$('#FilterCount').html('');				if (e.continue !== undefined)					getLinksFromPage(pageName, e.continue.lhcontinue, isRedirectPage);				var linkInfos = e.query.pages;		       for (var titleLink in linkInfos) {		        	if (linkInfos[titleLink].linkshere !== undefined) {			            numLinks += linkInfos[titleLink].linkshere.length;			            totalLinks += linkInfos[titleLink].linkshere.length;			            for (var linkInf in linkInfos[titleLink].linkshere) {			            	if (linkInfos[titleLink].linkshere[linkInf].redirect !== undefined) {                                numLinks -= 1; if (!hasRedirects) { $(RedirectArea).append(' Redirects: '); hasRedirects = true; }			           		$(RedirectArea).append(' '+linkInfos[titleLink].linkshere[linkInf].title+'  '); getLinksFromPage(linkInfos[titleLink].linkshere[linkInf].title, '', true); } else checkIfLinksReal(linkInfos[titleLink].linkshere[linkInf], pageName, isRedirectPage); }		       	} else { if (!isRedirectPage) { $('#LinkCount').html('0 Page Links Found'); $(mainLinkArea).append(actualPageLinks); $('#LoadingInfo').hide; $('#LoadingInfo').find('#RecordInfo').text('0/0 Records Done.'); processingLinks = false; }		       	}		        }			});		}		function checkIfLinksReal(pageLinks, basePageName, IsRedirectPage) {			if (currNumProcessing >= maxNumProcessingAtOnce)			{				setTimeout(function { checkIfLinksReal(pageLinks,basePageName, IsRedirectPage) }, 100);				return;			}			currNumProcessing += 1;			api.get({ action: 'parse', prop: 'wikitext', format: 'json', page: pageLinks.title }).done(function(data) { if (data.error === undefined) { var wikitext = data.parse.wikitext['*']; var pageLinkArr = findLinkInPage(basePageName, wikitext); if (pageLinkArr !== null) { var linkDataID = stripRegExp(basePageName)+'_'+stripRegExp(pageLinks.title); var checkContainer = mainLinkArea; var ContainerID = ' id="'+linkDataID+'"'; if (IsRedirectPage) checkContainer = '#'+stripRegExp(basePageName); if (IsRedirectPage) { linkData.Redirects[linkData.Redirects.length] = { id: linkDataID, arr: pageLinkArr}; } else linkData.links[linkData.links.length] = { id: linkDataID, arr: pageLinkArr}; $(checkContainer).append($('(Edit) '+pageLinks.title+' ')); var allLinks = $(checkContainer+' div').sort(function (a,b) { 		               	var aText = $(a).find('a.pageLink').text;		                	var bText = $(b).find('a.pageLink').text;							if (aText > bText)								return 1;							if (aText < bText)								return -1;							return 0;						}); $(checkContainer).append(allLinks); }		           numLinks -= 1; currNumProcessing -= 1; $('#LoadingInfo').find('#RecordInfo').text((totalLinks-numLinks).toString+'/'+totalLinks.toString+ ' Records Done.'); if (numLinks <= 0) { if ($(mainLinkArea).children('div').length === 0 && $(RedirectArea).children('div').length === 0) $(mainLinkArea).append(actualPageLinks); if ($(RedirectArea).children('div').length > 0) $(RedirectArea).children('div').children('div').each(function(i, e) {                               if ($(e).children('div').length === 0)                                    $(e).append(actualPageLinks);                            }); $('#LoadingInfo').hide; $('#LoadingInfo').find('#RecordInfo').text('0/0 Records Done.'); $('#LinkCount').text(linkData.links.length+' page links found.'); $('#RedirectCount').text(linkData.Redirects.length+' from redirects.'); totalLinks = 0; processingLinks = false; }		       } else { numLinks -= 1; currNumProcessing -= 1; if (numLinks <= 0) { if ($(mainLinkArea).children('div').length === 0 && $(RedirectArea).children('div').length === 0) $(mainLinkArea).append(actualPageLinks); if ($(RedirectArea).children('div').length > 0) $(RedirectArea).children('div').children('div').each(function(i, e) {                               if ($(e).children('div').length === 0)                                    $(e).append(actualPageLinks);                            }); $('#LoadingInfo').hide; $('#LoadingInfo').find('#RecordInfo').text('0/0 Records Done.'); $('#LinkCount').text(linkData.links.length+' page links found.'); $('#RedirectCount').text(linkData.Redirects.length+' from redirects.'); totalLinks = 0; 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 stripRegExp(text) {			var text1 = text.replace('!','Excla');		  return text1.replace(/[-[\]{}*+?.,\\^$|&#\s'":\/]/g, '');		}		function findLinkInPage(SearchPageTitle, wikiText) {		    var modPageTitle = escapeRegExp(SearchPageTitle).replace(/\\*[ _]/g,'[ _]');		    //var regexStr = '\\[\\[' + modPageTitle + '*[^\\]]+\\]\\]';		    //debugger;		    var regexStr = '\\[{2}' + modPageTitle + '([#\\|](([^\\]]|\\](?=[^\\]]))*))?\\]{2}';		    var testReg = new RegExp(regexStr, 'g');            var matches = wikiText.match(testReg);		    return matches;		}		$(document).ready(function {			//try {				//console.log("Start the WhatReallyLinksHere link page processor and link creator."); if (wgPageName.indexOf(whatReallyLinksHerePage) === 0) { //console.log("WhatReallyLinksHere Special page processor"); generateSpecialPage; }	           var whatReallyLinksHereElem = $(' ').append($('').text('What really links here')); var baseLink = $('#WikiaBarWrapper').find('[data-name=whatlinkshere]'); //console.log("WhatLinksHere tool check. Count: "+baseLink.length); if (baseLink.length > 0) { //console.log("WhatLinksHere tool link found. Getting parent object."); baseLink = baseLink.parent; //console.log("Appending WhatReallyLinksHere tool link to parent of WhatLinksHere"); whatReallyLinksHereElem.insertAfter(baseLink); } else { //console.log("WhatLinksHere tool link not found. Getting My Tools menu link."); baseLink = $('#WikiaBarWrapper').find('.tools-customize'); //console.log("Appending WhatReallyLinksHere tool link after My Tools menu link."); whatReallyLinksHereElem.insertBefore(baseLink); }			//} catch (e) { //console.log("WhatReallyLinksHere exception found."); //console.log(e); //}		});	}); });*/ /** * Custom profile masthead tags * * Documentation:  * * @author Rappy * @author Cqm */

/* jshint bitwise:true, camelcase:true, curly:true, eqeqeq:true, latedef:true, maxdepth:3, maxlen:120, newcap:true, noarg:true, noempty:true, nonew:true, onevar:true, plusplus:false, quotmark:single, undef:true, unused:true, strict:true, trailing:true,

asi:false, boss:false, debug:false, eqnull:false, evil:false, expr:false, lastsemic:false, loopfunc:false, moz:false, proto:false, scripturl:false,

browser:true, devel:false, jquery:true

/*global mediaWiki */

(function ($, mw) {   'use strict';	debugger;    var conf = mw.config.get([ 'debug', 'profileUserName', 'wgCanonicalNamespace', 'wgTitle' ]),

// variable to not hide existing tags noHideTags = !!((window.dev || {}).profileTags || {}).noHideTags; if (conf.wgCanonicalNamespace === 'User' && conf.wgTitle.indexOf('/') < 0) { conf.profileUserName = conf.wgTitle; }   if (conf.wgCanonicalNamespace === 'MediaWiki' && conf.wgTitle === 'ProfileTags') { var content = $('#mw-content-text .mw-parser-output'); if (!content.length) { return; }       var pre = $(' ', {            text: content.text.trim        }); content.replaceWith(pre); } else if (!conf.profileUserName) { return; }

/**    * Hide tags from the user profile masthead. *    * @todo enable ability conditionally remove tags *    * @param $masthead {jquery.object} A reference to the user profile masthead. */   function hideTags($masthead) { var $tags = $masthead.find('[class*="tag"]'); // whitelist of which tags not to remove // noRemove = ['staff', 'soap', 'council', 'authenticated', 'helper'];

/*       // this tests if the tag is one of the tags not to remove // however, there's nothing reliable to hook off at the moment // so this is commented out until that's done $tags.each(function {            var $this = $(this),

noRemove.forEach(function (tag) {               if (!$this.hasClass(tag)) {                    $this.remove;                }            }); });       */

// @todo remove when above code goes live $tags.remove; }

/**    * Get a class to add to the user tag. *    * @param tag {string} The text of the user tag. * @return {string} A string representing the tag's class. */   function getTagClass(tag) { var tagClass = 'tag-' + tag.toLowerCase.replace(/\s/g, '_'); return tagClass; }

/**    * Get a user tag with a link within. *    * @param $span {jquery.object} A reference to the user tag. * @param tag {string} The user tag to turn into a link. * @return {jquery.object} The linked user tag. */   function getLinkTag($span, tag) { var re = /\[\[(.+?)\|(.+?)\]\]/, match = re.exec(tag), href = mw.util.getUrl(match[1]), text = match[2], $a = $('') .attr('href', href) .css('color', 'inherit') .text(text);

$span.addClass(getTagClass(tag)).append($a); return $span; }

/**    * Add a user's tags to their profile masthead. *    * @param tags {array} The tags to add to the user masthead. */   function addProfileTags(tags) { var $masthead = $('.user-identity-box .user-identity-header__attributes'), linkTestRe = /\[\[.+?\|.+?\]\]/;

if (!noHideTags) { hideTags($masthead); }

tags.forEach(function (tag) {           var $span = $(' ').addClass('user-identity-header__tag');

if (linkTestRe.test(tag)) { $span = getLinkTag($span, tag); } else { $span.addClass(getTagClass(tag)).text(tag); }

// add a space because otherwise the padding isn't right // when existing tags aren't hidden $masthead.append($span, ' '); });       mw.hook('dev.profile-tags').fire;    }

/**    * Get the user tag configuration for a user. */   function getUserTags { var params = { action: 'raw', title: 'MediaWiki:ProfileTags' };

// get uncached page in debug mode if (conf.debug) { params.maxage = 0; params.smaxage = 0; }

$.get(mw.util.wikiScript, params, function(data) {

if (!data.length) { return; }

if (/^!nohide/.test(data)) { noHideTags = true; }

// syntax: // $username | $tag1, $tag2, $tag3

var escapeRegExp = mw.util.escapeRegExp||(mw.RegExp||{}).escape, user = escapeRegExp(conf.profileUserName), re = new RegExp('(?:^|\\n)\\s*' + user + '\\s*\\|\\s*(.*?)\\s*(?:\\n|$)'), match = re.exec(data), tags;

if (match === null) { return; }

tags = match[1].split(/\s*,\s*/);

if (tags.length) { addProfileTags(tags); }       });    }

/**    * Check for the correct environment and load the required dependencies. */   function init { var __init = function { if ($('.user-identity-box').length) { getUserTags; } else { setTimeout(__init, 500); }       };        __init; }

// wait for site RL module to load to ensure config is picked up correctly mw.loader.using(['mediawiki.util', 'site']).then(init); }(jQuery, mediaWiki));