User:OH&S/wikia.js

importArticles({   type: "script",    articles: [        'u:dev:MediaWiki:MassCategorization/code.js',        'u:dev:MediaWiki:MassEdit/code.js',        'u:dev:MediaWiki:AjaxBatchDelete.js',        'u:dev:MediaWiki:AjaxBatchUndelete.js',        'u:dev:MediaWiki:FastOldImageDelete/code.js',        'u:dev:MediaWiki:ViewDeleted/code.js',        'u:dev:MediaWiki:AdminDashboard JS-Button/code.js',        'u:dev:MediaWiki:AvatarLink.js',        'u:dev:MediaWiki:QuickDiff/code.js',        'u:dev:MediaWiki:CategoryRenameAuto-update/code.js',        'u:dev:MediaWiki:DupImageList/code.js',        'u:dev:MediaWiki:FindAndReplace/code.js',        'u:dev:MediaWiki:CodeQuickLinks/code.js',        'u:dev:MediaWiki:ProtectionIcons.js',        'u:dev:MediaWiki:ImportJS-Plus.js',        'u:dev:MediaWiki:SandboxLink/code.js',        'u:dev:MediaWiki:SandboxTab/code.js',        'u:dev:MediaWiki:RailWAM/code.js', 'u:dev:MediaWiki:UsefulDropdown/code.js', 'u:dev:MediaWiki:RCStats.js', 'u:dev:MediaWiki:ToggleSideBar/code.js', 'u:dev:MediaWiki:BackToTopButton/code.js', 'u:dev:MediaWiki:TabKeyInserter/code.js' ] });

/** * Simple script to queue run of WikiTextSyntaxHighlighter for source mode editor * * @author Kamil Koterba  */ (function ( window, $ ) {		'use strict';

var WE = window.WikiaEditor = window.WikiaEditor || (new window.Observable), WikiTextSyntaxHighlighter;

WE.plugins.syntaxhighlighterqueueinit = $.createClass(WE.plugin, {

init: function { this.editor.on('mode', this.proxy(this.initSyntaxHighlighting)); this.editor.on('editorReady', this.proxy(this.initSyntaxHighlighting));

require(['WikiTextSyntaxHighlighter'], this.proxy(function (syntaxHighlighter) { WikiTextSyntaxHighlighter = syntaxHighlighter;

this.initSyntaxHighlighting; }));			},

initConfig: function { var config;

if (window.wgIsDarkTheme) { config = this.initDarkThemeColors; } else { config = this.initLightThemeColors; }

return config; },

initSyntaxHighlighting: function { if (WikiTextSyntaxHighlighter) { if (this.editor.mode === 'source' && this.editor.ready ) { var textarea = this.editor.getEditbox[0], config = this.initConfig;

WikiTextSyntaxHighlighter.init(textarea, config); } else { WikiTextSyntaxHighlighter.reset; }				}			},

initDarkThemeColors: function { return { boldOrItalicColor: '#44466d', commentColor: '#4d1a19', entityColor: '#474d23', externalLinkColor: '#244d491', headingColor: '#44466d', hrColor: '#44466d', listOrIndentColor: '#4d1a19', parameterColor: '#66331e', signatureColor: '#66331e', tagColor: '#662946', tableColor: '#5e5129', templateColor: '#5e5129', wikilinkColor: '#245477' };			},

initLightThemeColors: function { return { boldOrItalicColor: '#e4e5f3', commentColor: '#f8dbda', entityColor: '#e8ebda', externalLinkColor: '#dbeceb', headingColor: '#e4e5f3', hrColor: '#e4e5f3', listOrIndentColor: '#f8dbda', parameterColor: '#f5e0d8', signatureColor: '#f5e0d8', tagColor: '#f6dde9', tableColor: '#f0ebdb', templateColor: '#f0ebdb', wikilinkColor: '#E3D9F6' };			}		});

})( this, jQuery );

/** * Wikitext Syntax highlighter * http://www.mediawiki.org/wiki/User:Remember_the_dot/Syntax_highlighter * @author mw:User:Remember_the_dot */

define('WikiTextSyntaxHighlighter', ['wikia.window', 'wikia.document', 'wikia.log'], function (window, document, log) {	'use strict';

// Variables that are preserved between function calls var highlightSyntaxIfNeededIntervalId, highlightSyntaxInputTimeoutId, initialized = false, lastText, /**		 * @var maxSpanNumber The number of the last span available, * used to tell if creating additional spans is necessary */		maxSpanNumber, syntaxHighlighterConfig, syntaxStyleTextNode, wpTextbox0, wpTextbox1,

assumedBold, assumedItalic, before, css, lastColor, parserLocation, spanNumber, text,

// Regex vars defaultBreakerRegex, headingBreakerRegex, namedExternalLinkBreakerRegex, parameterBreakerRegex, tableBreakerRegex, tagBreakerRegexCache, templateBreakerRegex, wikilinkBreakerRegex, breakerRegexBase;

/* Define context-specific regexes, one for every common token that ends the current context. An attempt has been made to search for the most common syntaxes first, thus maximizing performance. Syntaxes that begin with the same character are searched for at the same time. Supported wiki syntaxes from most common to least common: internal link [http:// named external link] {| table |} http:// bare external link =Heading= * unordered list # ordered list : indent ; small heading horizontal line italic bold three tildes username four tildes signature five tildes timestamp &entity; The tag-matching regex follows the XML standard closely so that users won't feel like they have to escape sequences that MediaWiki will never consider to be tags. Only entities for characters which need to be escaped or cannot be	unambiguously represented in a monospace font are highlighted, such as Greek letters that strongly resemble Latin letters. Use of other entities is discouraged as a matter of style. For the same reasons, numeric entities should be in hexadecimal (giving character codes in decimal only	adds confusion). Newlines are sucked up into ending tokens (including comments, bare	external links, lists, horizontal lines, signatures, entities, etc.) to avoid creating spans with nothing but newlines in them. Flags: g for global search, m for make ^ match the beginning of each line and $ the end of each line */	breakerRegexBase = "\\[(?:\\[|(?:https?:|ftp:)?//|mailto:)|\\{(?:\\{\\{?|\\|)|<(?:[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:\\w\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD-\\.\u00B7\u0300-\u036F\u203F-\u203F-\u2040]*(?=/?>| |\n)|!--[^]*?-->\n*)|(?:https?://|ftp://|mailto:)[^\\s\"<>[\\]{-}]*[^\\s\",\\.:;<>[\\]{-}]\n*|^(?:=|[*#:;]+\n*|-{4,}\n*)|\\\\'\\\\'(?:\\\\')?|~{3,5}\n*|&(?:(?:n(?:bsp|dash)|m(?:dash|inus)|lt|e[mn]sp|thinsp|amp|quot|gt|shy|zwn?j|lrm|rlm|Alpha|Beta|Epsilon|Zeta|Eta|Iota|Kappa|[Mm]u|micro|Nu|[Oo]micron|[Rr]ho|Tau|Upsilon|Chi)|#x[0-9a-fA-F]+);\n*";

function breakerRegexWithPrefix (prefix) { // The stop token has to be at the beginning of the regex so that it takes precedence // over substrings of itself. return new RegExp('(' + prefix + ')\n*|' + breakerRegexBase, 'gm'); }

// Writes text into to-be-created span elements of wpTextbox0 using :before and :after pseudo-elements // both :before and :after are used because using two pseudo-elements per span is significantly faster // than doubling the number of spans required function writeText (text, color) { // No need to use another span if using the same color if (color !== lastColor) { // Whitespace is omitted in the hope of increasing performance css += '\'}#s' + spanNumber; //spans will be created with IDs s0 through sN			if (before) { css += ':before{'; before = false; }			else { css += ':after{'; before = true; ++spanNumber; }			if (color) { // 'background-color' is 6 characters longer than 'background' but the browser processes it faster css += 'background-color:' + color + ';'; }			css += 'content:\''; lastColor = color; }		css += text; }

function highlightSyntax { var startTime, endTime, diffTime, fragment;

if ( typeof CKEDITOR != 'undefined' ) wpTextbox1.value = CKEDITOR.instances.wpTextbox1.getData;

lastText = wpTextbox1.value;

/* Backslashes and apostrophes are CSS-escaped at the beginning and all parsing regexes and functions are designed to match. On the other hand, newlines are not escaped until written so that in the regexes ^ and $ work for both newlines and the beginning or end of the string. */		text = lastText.replace(/['\\]/g, '\\$&') + '\n'; //add a newline to fix scrolling and parsing issues parserLocation = 0; //the location of the parser as it goes through var text

before = true; css = ''; lastColor = undefined; spanNumber = 0;

/* Highlighting bold or italic markup presents a special challenge because the actual MediaWiki parser uses multiple passes to determine which ticks represent start tags and which represent end tags. Because that would be too slow for us here, we instead keep track of		what kinds of unclosed opening ticks have been encountered and use that to make a good guess as to whether the next ticks encountered are an opening tag or a closing tag. The major downsides to this method are that 'apostrophe italic and italic apostrophe' are not highlighted correctly, and bold and italic are both highlighted in the same color. */		assumedBold = false; assumedItalic = false;

// Start! startTime = Date.now; highlightBlock('', defaultBreakerRegex);

// Output the leftovers (if any) to make sure whitespace etc. matches if (parserLocation < text.length) { writeText(text.substring(parserLocation), ''); }

// If highlighting took too long, disable it. endTime = Date.now; diffTime = endTime - startTime;

if (diffTime > syntaxHighlighterConfig.timeout) { resetHighlightSyntax(diffTime); return; }

// Do we have enough span elements to match the generated CSS? // This step isn't included in the above benchmark because it takes a highly variable amount of time if (maxSpanNumber < spanNumber) { fragment = document.createDocumentFragment; do { fragment.appendChild(document.createElement('span')).id = 's' + (++maxSpanNumber); }			while (maxSpanNumber < spanNumber); wpTextbox0.appendChild(fragment); }

/* Finish CSS: move the extra '} from the beginning to the end and CSS- escape newlines. CSS ignores the space after the hex code of the escaped character */ syntaxStyleTextNode.nodeValue = css.substring(2).replace(/\n/g, '\\A ') + '\'}'; }

function resetHighlightSyntax(diffTime) { if (initialized) {

clearInterval(highlightSyntaxIfNeededIntervalId);

wpTextbox1.removeEventListener('keydown', debouncedHighlightSyntax); wpTextbox1.removeEventListener('scroll', syncScrollX); wpTextbox1.removeEventListener('scroll', syncScrollY);

syntaxStyleTextNode.nodeValue = '';

if (diffTime) { log('Syntax highlighting took too long. The maximum allowed ' +					'highlighting time is ' + syntaxHighlighterConfig.timeout +					', and your computer took ' + diffTime + '.'); }		}	}

function highlightBlock (color, breakerRegex) { var match, endIndexOfLastColor, tagEnd, tagName, stopAfter, endIndex;

for (			breakerRegex.lastIndex = parserLocation;			match = breakerRegex.exec(text);			breakerRegex.lastIndex = parserLocation		) { if (match[1]) { // End token found writeText(text.substring(parserLocation, breakerRegex.lastIndex), color); parserLocation = breakerRegex.lastIndex; return; }

endIndexOfLastColor = breakerRegex.lastIndex - match[0].length; // Avoid calling writeText with text == '' to improve performance if (parserLocation < endIndexOfLastColor) { writeText(text.substring(parserLocation, endIndexOfLastColor), color); }

parserLocation = breakerRegex.lastIndex;

// Cases in this switch should be arranged from most common to least common switch (match[0].charAt(0)) { case '[': if (match[0].charAt(1) === '[') { // wikilink writeText('[[', syntaxHighlighterConfig.wikilinkColor || color);						highlightBlock(							syntaxHighlighterConfig.wikilinkColor || color,							wikilinkBreakerRegex						);					}					else {						// named external link						writeText(match[0], syntaxHighlighterConfig.externalLinkColor || color);						highlightBlock(							syntaxHighlighterConfig.externalLinkColor || color,							namedExternalLinkBreakerRegex						);					}					break;				case '{':					if (match[0].charAt(1) === '{') {						if (match[0].length === 3) {							// parameter							writeText('');		tableBreakerRegex = breakerRegexWithPrefix('\\|}');		headingBreakerRegex = breakerRegexWithPrefix('\n');		tagBreakerRegexCache = {};

syntaxHighlighterConfig = config;

/* The highlighter has to run after any other script (such as the		editing toolbar) that reparents wpTextbox1. We make sure that everything else has run by waiting for the page to completely load and then adding a call to the setup function to the end of the event queue, so that the setup function runs after any other triggers set on the load event. */		if (document.readyState === 'complete') { queueSetup(textarea); }		else { $(window).load(queueSetup(textarea)); }	}

return { init: init, reset: resetHighlightSyntax }; });