User:PetraMagna/popups.js: Difference between revisions

From Blue Archive Wiki
Jump to navigation Jump to search
Content added Content deleted
(Created page with "→‎https://en.wikipedia.org/wiki/Wikipedia:Tools/Navigation_popups: mw.loader.impl(function() { return ["ext.gadget.Navigation_popups@1dhpx", function($, jQuery, require, module) { $(function() { var pg = { api: {}, re: {}, ns: {}, string: {}, wiki: {}, user: {}, misc: {}, option: {}, optionDefault: {},...")
 
mNo edit summary
Line 1: Line 1:
/*https://en.wikipedia.org/wiki/Wikipedia:Tools/Navigation_popups*/
/*https://en.wikipedia.org/wiki/Wikipedia:Tools/Navigation_popups*/
mw.loader.impl(function() {
$(function () {
//////////////////////////////////////////////////
return ["ext.gadget.Navigation_popups@1dhpx", function($, jQuery, require, module) {
// Globals
$(function() {
//
var pg = {

api: {},
// Trying to shove as many of these as possible into the pg (popup globals) object
re: {},
var pg = {
ns: {},
api: {}, // MediaWiki API requests
string: {},
re: {}, // regexps
wiki: {},
ns: {}, // namespaces
user: {},
string: {}, // translatable strings
misc: {},
wiki: {}, // local site info
option: {},
user: {}, // current user info
optionDefault: {},
misc: {}, // YUCK PHOOEY
flag: {},
option: {}, // options, see newOption etc
cache: {},
optionDefault: {}, // default option values
structures: {},
flag: {}, // misc flags
timer: {},
cache: {}, // page and image cache
counter: {},
structures: {}, // navlink structures
current: {},
timer: {}, // all sorts of timers (too damn many)
fn: {},
counter: {}, // .. and all sorts of counters
endoflist: null,
current: {}, // state info
};
fn: {}, // functions
if (window.pg && !(window.pg instanceof HTMLElement)) {
endoflist: null,
return;
};
}

window.pg = pg;
/* Bail if the gadget/script is being loaded twice */
function setupTooltips(container, remove, force, popData) {
/* An element with id "pg" would add a window.pg property, ignore such property */
log('setupTooltips, container=' + container + ', remove=' + remove);
if (window.pg && !(window.pg instanceof HTMLElement)) {
if (!container) {
return;
if (getValueOf('popupOnEditSelection') && document && document.editform && document.editform.wpTextbox1) {
}
document.editform.wpTextbox1.onmouseup = doSelectionPopup;

}
/* Export to global context */
container = defaultPopupsContainer();
window.pg = pg;
}

if (!remove && !force && container.ranSetupTooltipsAlready) {
/// Local Variables: ///
return;
/// mode:c ///
}
/// End: ///
container.ranSetupTooltipsAlready = !remove;
// ENDFILE: main.js
var anchors;

anchors = container.getElementsByTagName('A');
// STARTFILE: actions.js
setupTooltipsLoop(anchors, 0, 250, 100, remove, popData);
function setupTooltips(container, remove, force, popData) {
}
log('setupTooltips, container=' + container + ', remove=' + remove);
function defaultPopupsContainer() {
if (!container) {
if (getValueOf('popupOnlyArticleLinks')) {
// the main initial call
return (document.querySelector('.skin-vector-2022 .vector-body') || document.getElementById('mw_content') || document.getElementById('content') || document.getElementById('article') || document);
if (
}
getValueOf('popupOnEditSelection') &&
return document;
document &&
}
document.editform &&
function setupTooltipsLoop(anchors, begin, howmany, sleep, remove, popData) {
document.editform.wpTextbox1
log(simplePrintf('setupTooltipsLoop(%s,%s,%s,%s,%s)', arguments));
) {
var finish = begin + howmany;
document.editform.wpTextbox1.onmouseup = doSelectionPopup;
var loopend = Math.min(finish, anchors.length);
}
var j = loopend - begin;
// article/content is a structure-dependent thing
log('setupTooltips: anchors.length=' + anchors.length + ', begin=' + begin + ', howmany=' + howmany + ', loopend=' + loopend + ', remove=' + remove);
container = defaultPopupsContainer();
var doTooltip = remove ? removeTooltip : addTooltip;
}
if (j > 0) {

do {
if (!remove && !force && container.ranSetupTooltipsAlready) {
var a = anchors[loopend - j];
return;
if (typeof a === 'undefined' || !a || !a.href) {
}
log('got null anchor at index ' + loopend - j);
container.ranSetupTooltipsAlready = !remove;
continue;

}
var anchors;
doTooltip(a, popData);
anchors = container.getElementsByTagName('A');
} while (--j);
setupTooltipsLoop(anchors, 0, 250, 100, remove, popData);
}
}
if (finish < anchors.length) {

setTimeout(function() {
function defaultPopupsContainer() {
setupTooltipsLoop(anchors, finish, howmany, sleep, remove, popData);
if (getValueOf('popupOnlyArticleLinks')) {
}, sleep);
return (
} else {
document.querySelector('.skin-vector-2022 .vector-body') ||
if (!remove && !getValueOf('popupTocLinks')) {
document.getElementById('mw_content') ||
rmTocTooltips();
document.getElementById('content') ||
}
document.getElementById('article') ||
pg.flag.finishedLoading = true;
document
}
);
}
}
function rmTocTooltips() {
return document;
var toc = document.getElementById('toc');
}
if (toc) {

var tocLinks = toc.getElementsByTagName('A');
function setupTooltipsLoop(anchors, begin, howmany, sleep, remove, popData) {
var tocLen = tocLinks.length;
log(simplePrintf('setupTooltipsLoop(%s,%s,%s,%s,%s)', arguments));
for (var j = 0; j < tocLen; ++j) {
var finish = begin + howmany;
removeTooltip(tocLinks[j], true);
var loopend = Math.min(finish, anchors.length);
}
var j = loopend - begin;
}
log(
}
'setupTooltips: anchors.length=' +
function addTooltip(a, popData) {
anchors.length +
if (!isPopupLink(a)) {
', begin=' +
return;
begin +
}
', howmany=' +
a.onmouseover = mouseOverWikiLink;
howmany +
a.onmouseout = mouseOutWikiLink;
', loopend=' +
a.onmousedown = killPopup;
loopend +
a.hasPopup = true;
', remove=' +
a.popData = popData;
remove
}
);
function removeTooltip(a) {
var doTooltip = remove ? removeTooltip : addTooltip;
if (!a.hasPopup) {
// try a faster (?) loop construct
return;
if (j > 0) {
}
do {
a.onmouseover = null;
var a = anchors[loopend - j];
a.onmouseout = null;
if (typeof a === 'undefined' || !a || !a.href) {
if (a.originalTitle) {
log('got null anchor at index ' + loopend - j);
a.title = a.originalTitle;
continue;
}
}
a.hasPopup = false;
doTooltip(a, popData);
}
} while (--j);
function removeTitle(a) {
}
if (!a.originalTitle) {
if (finish < anchors.length) {
a.originalTitle = a.title;
setTimeout(function () {
}
setupTooltipsLoop(anchors, finish, howmany, sleep, remove, popData);
a.title = '';
}, sleep);
}
} else {
function restoreTitle(a) {
if (!remove && !getValueOf('popupTocLinks')) {
if (a.title || !a.originalTitle) {
rmTocTooltips();
return;
}
}
pg.flag.finishedLoading = true;
a.title = a.originalTitle;
}
}
}
function registerHooks(np) {

var popupMaxWidth = getValueOf('popupMaxWidth');
// eliminate popups from the TOC
if (typeof popupMaxWidth === 'number') {
// This also kills any onclick stuff that used to be going on in the toc
var setMaxWidth = function() {
function rmTocTooltips() {
np.mainDiv.style.maxWidth = popupMaxWidth + 'px';
var toc = document.getElementById('toc');
np.maxWidth = popupMaxWidth;
if (toc) {
};
var tocLinks = toc.getElementsByTagName('A');
np.addHook(setMaxWidth, 'unhide', 'before');
var tocLen = tocLinks.length;
}
for (var j = 0; j < tocLen; ++j) {
np.addHook(addPopupShortcuts, 'unhide', 'after');
removeTooltip(tocLinks[j], true);
np.addHook(rmPopupShortcuts, 'hide', 'before');
}
}
}
function removeModifierKeyHandler(a) {
}
document.removeEventListener('keydown', a.modifierKeyHandler, false);

document.removeEventListener('keyup', a.modifierKeyHandler, false);
function addTooltip(a, popData) {
}
if (!isPopupLink(a)) {
function mouseOverWikiLink(evt) {
return;
if (!evt && window.event) {
}
evt = window.event;
a.onmouseover = mouseOverWikiLink;
}
a.onmouseout = mouseOutWikiLink;
if (getValueOf('popupModifier')) {
a.onmousedown = killPopup;
var action = getValueOf('popupModifierAction');
a.hasPopup = true;
var key = action == 'disable' ? 'keyup' : 'keydown';
a.popData = popData;
var a = this;
}
a.modifierKeyHandler = function(evt) {

mouseOverWikiLink2(a, evt);
function removeTooltip(a) {
}
if (!a.hasPopup) {
;
return;
document.addEventListener(key, a.modifierKeyHandler, false);
}
}
a.onmouseover = null;
return mouseOverWikiLink2(this, evt);
a.onmouseout = null;
}
if (a.originalTitle) {
function footnoteTarget(a) {
a.title = a.originalTitle;
var aTitle = Title.fromAnchor(a);
}
var anch = aTitle.anchor;
a.hasPopup = false;
if (!/^(cite_note-|_note-|endnote)/.test(anch)) {
}
return false;

}
function removeTitle(a) {
var lTitle = Title.fromURL(location.href);
if (!a.originalTitle) {
if (lTitle.toString(true) !== aTitle.toString(true)) {
a.originalTitle = a.title;
return false;
}
}
a.title = '';
var el = document.getElementById(anch);
}
while (el && typeof el.nodeName === 'string') {

var nt = el.nodeName.toLowerCase();
function restoreTitle(a) {
if (nt === 'li') {
if (a.title || !a.originalTitle) {
return el;
return;
} else if (nt === 'body') {
}
return false;
a.title = a.originalTitle;
} else if (el.parentNode) {
}
el = el.parentNode;

} else {
function registerHooks(np) {
return false;
var popupMaxWidth = getValueOf('popupMaxWidth');
}

}
if (typeof popupMaxWidth === 'number') {
return false;
var setMaxWidth = function () {
}
np.mainDiv.style.maxWidth = popupMaxWidth + 'px';
function footnotePreview(x, navpop) {
np.maxWidth = popupMaxWidth;
setPopupHTML('<hr />' + x.innerHTML, 'popupPreview', navpop.idNumber);
};
}
np.addHook(setMaxWidth, 'unhide', 'before');
function modifierPressed(evt) {
}
var mod = getValueOf('popupModifier');
np.addHook(addPopupShortcuts, 'unhide', 'after');
if (!mod) {
np.addHook(rmPopupShortcuts, 'hide', 'before');
return false;
}
}

if (!evt && window.event) {
function removeModifierKeyHandler(a) {
evt = window.event;
//remove listeners for modifier key if any that were added in mouseOverWikiLink
}
document.removeEventListener('keydown', a.modifierKeyHandler, false);
return evt && mod && evt[mod.toLowerCase() + 'Key'];
document.removeEventListener('keyup', a.modifierKeyHandler, false);
}
}
function isCorrectModifier(a, evt) {

if (!getValueOf('popupModifier')) {
function mouseOverWikiLink(evt) {
return true;
if (!evt && window.event) {
}
evt = window.event;
var action = getValueOf('popupModifierAction');
}
return ((action == 'enable' && modifierPressed(evt)) || (action == 'disable' && !modifierPressed(evt)));

}
// if the modifier is needed, listen for it,
function mouseOverWikiLink2(a, evt) {
// we will remove the listener when we mouseout of this link or kill popup.
if (!isCorrectModifier(a, evt)) {
if (getValueOf('popupModifier')) {
return;
// if popupModifierAction = enable, we should popup when the modifier is pressed
}
// if popupModifierAction = disable, we should popup unless the modifier is pressed
if (getValueOf('removeTitles')) {
var action = getValueOf('popupModifierAction');
removeTitle(a);
var key = action == 'disable' ? 'keyup' : 'keydown';
}
var a = this;
if (a == pg.current.link && a.navpopup && a.navpopup.isVisible()) {
a.modifierKeyHandler = function (evt) {
return;
mouseOverWikiLink2(a, evt);
}
};
pg.current.link = a;
document.addEventListener(key, a.modifierKeyHandler, false);
if (getValueOf('simplePopups') && !pg.option.popupStructure) {
}
setDefault('popupStructure', 'original');

}
return mouseOverWikiLink2(this, evt);
var article = new Title().fromAnchor(a);
}
pg.current.article = article;

if (!a.navpopup) {
/**
a.navpopup = newNavpopup(a, article);
* Gets the references list item that the provided footnote link targets. This
pg.current.linksHash[a.href] = a.navpopup;
* is typically a li element within the ol.references element inside the reflist.
pg.current.links.push(a);
* @param {Element} a - A footnote link.
}
* @returns {Element|boolean} The targeted element, or false if one can't be found.
if (a.navpopup.pending === null || a.navpopup.pending !== 0) {
*/
simplePopupContent(a, article);
function footnoteTarget(a) {
}
var aTitle = Title.fromAnchor(a);
a.navpopup.showSoonIfStable(a.navpopup.delay);
// We want ".3A" rather than "%3A" or "?" here, so use the anchor property directly
clearInterval(pg.timer.checkPopupPosition);
var anch = aTitle.anchor;
pg.timer.checkPopupPosition = setInterval(checkPopupPosition, 600);
if (!/^(cite_note-|_note-|endnote)/.test(anch)) {
if (getValueOf('simplePopups')) {
return false;
if (getValueOf('popupPreviewButton') && !a.simpleNoMore) {
}
var d = document.createElement('div');

d.className = 'popupPreviewButtonDiv';
var lTitle = Title.fromURL(location.href);
var s = document.createElement('span');
if (lTitle.toString(true) !== aTitle.toString(true)) {
d.appendChild(s);
return false;
s.className = 'popupPreviewButton';
}
s['on' + getValueOf('popupPreviewButtonEvent')] = function() {

a.simpleNoMore = true;
var el = document.getElementById(anch);
d.style.display = 'none';
while (el && typeof el.nodeName === 'string') {
nonsimplePopupContent(a, article);
var nt = el.nodeName.toLowerCase();
}
if (nt === 'li') {
;
return el;
s.innerHTML = popupString('show preview');
} else if (nt === 'body') {
setPopupHTML(d, 'popupPreview', a.navpopup.idNumber);
return false;
}
} else if (el.parentNode) {
}
el = el.parentNode;
if (a.navpopup.pending !== 0) {
} else {
nonsimplePopupContent(a, article);
return false;
}
}
}
}
function simplePopupContent(a, article) {
return false;
a.navpopup.hasPopupMenu = false;
}
a.navpopup.setInnerHTML(popupHTML(a));

fillEmptySpans({
function footnotePreview(x, navpop) {
navpopup: a.navpopup
setPopupHTML('<hr />' + x.innerHTML, 'popupPreview', navpop.idNumber);
});
}
if (getValueOf('popupDraggable')) {

var dragHandle = getValueOf('popupDragHandle') || null;
function modifierPressed(evt) {
if (dragHandle && dragHandle != 'all') {
var mod = getValueOf('popupModifier');
dragHandle += a.navpopup.idNumber;
if (!mod) {
}
return false;
setTimeout(function() {
}
a.navpopup.makeDraggable(dragHandle);

}, 150);
if (!evt && window.event) {
}
evt = window.event;
if (getValueOf('popupRedlinkRemoval') && a.className == 'new') {
}
setPopupHTML('<br>' + popupRedlinkHTML(article), 'popupRedlink', a.navpopup.idNumber);

}
return evt && mod && evt[mod.toLowerCase() + 'Key'];
}
}
function debugData(navpopup) {

if (getValueOf('popupDebugging') && navpopup.idNumber) {
// Checks if the correct modifier pressed/unpressed if needed
setPopupHTML('idNumber=' + navpopup.idNumber + ', pending=' + navpopup.pending, 'popupError', navpopup.idNumber);
function isCorrectModifier(a, evt) {
}
if (!getValueOf('popupModifier')) {
}
return true;
function newNavpopup(a, article) {
}
var navpopup = new Navpopup();
// if popupModifierAction = enable, we should popup when the modifier is pressed
navpopup.fuzz = 5;
// if popupModifierAction = disable, we should popup unless the modifier is pressed
navpopup.delay = getValueOf('popupDelay') * 1000;
var action = getValueOf('popupModifierAction');
navpopup.idNumber = ++pg.idNumber;
return (
navpopup.parentAnchor = a;
(action == 'enable' && modifierPressed(evt)) || (action == 'disable' && !modifierPressed(evt))
navpopup.parentPopup = a.popData && a.popData.owner;
);
navpopup.article = article;
}
registerHooks(navpopup);

return navpopup;
function mouseOverWikiLink2(a, evt) {
}
if (!isCorrectModifier(a, evt)) {
function shouldShowNonSimple(a) {
return;
return !getValueOf('simplePopups') || a.simpleNoMore;
}
}
if (getValueOf('removeTitles')) {
function shouldShow(a, option) {
removeTitle(a);
if (shouldShowNonSimple(a)) {
}
return getValueOf(option);
if (a == pg.current.link && a.navpopup && a.navpopup.isVisible()) {
} else {
return;
return typeof window[option] != 'undefined' && window[option];
}
}
pg.current.link = a;
}

function nonsimplePopupContent(a, article) {
if (getValueOf('simplePopups') && !pg.option.popupStructure) {
var diff = null
// reset *default value* of popupStructure
, history = null;
setDefault('popupStructure', 'original');
var params = parseParams(a.href);
}
var oldid = typeof params.oldid == 'undefined' ? null : params.oldid;

if (shouldShow(a, 'popupPreviewDiffs')) {
var article = new Title().fromAnchor(a);
diff = params.diff;
// set global variable (ugh) to hold article (wikipage)
}
pg.current.article = article;
if (shouldShow(a, 'popupPreviewHistory')) {

history = params.action == 'history';
if (!a.navpopup) {
}
a.navpopup.pending = 0;
a.navpopup = newNavpopup(a, article);
pg.current.linksHash[a.href] = a.navpopup;
var referenceElement = footnoteTarget(a);
pg.current.links.push(a);
if (referenceElement) {
}
footnotePreview(referenceElement, a.navpopup);
if (a.navpopup.pending === null || a.navpopup.pending !== 0) {
} else if (diff || diff === 0) {
// either fresh popups or those with unfinshed business are redone from scratch
loadDiff(article, oldid, diff, a.navpopup);
simplePopupContent(a, article);
} else if (history) {
}
loadAPIPreview('history', article, a.navpopup);
a.navpopup.showSoonIfStable(a.navpopup.delay);
} else if (shouldShowNonSimple(a) && pg.re.contribs.test(a.href)) {

loadAPIPreview('contribs', article, a.navpopup);
clearInterval(pg.timer.checkPopupPosition);
} else if (shouldShowNonSimple(a) && pg.re.backlinks.test(a.href)) {
pg.timer.checkPopupPosition = setInterval(checkPopupPosition, 600);
loadAPIPreview('backlinks', article, a.navpopup);

} else if (article.namespaceId() == pg.nsImageId && (shouldShow(a, 'imagePopupsForImages') || !anchorContainsImage(a))) {
if (getValueOf('simplePopups')) {
loadAPIPreview('imagepagepreview', article, a.navpopup);
if (getValueOf('popupPreviewButton') && !a.simpleNoMore) {
loadImage(article, a.navpopup);
var d = document.createElement('div');
} else {
d.className = 'popupPreviewButtonDiv';
if (article.namespaceId() == pg.nsCategoryId && shouldShow(a, 'popupCategoryMembers')) {
var s = document.createElement('span');
loadAPIPreview('category', article, a.navpopup);
d.appendChild(s);
} else if ((article.namespaceId() == pg.nsUserId || article.namespaceId() == pg.nsUsertalkId) && shouldShow(a, 'popupUserInfo')) {
s.className = 'popupPreviewButton';
loadAPIPreview('userinfo', article, a.navpopup);
s['on' + getValueOf('popupPreviewButtonEvent')] = function () {
}
a.simpleNoMore = true;
if (shouldShowNonSimple(a)) {
d.style.display = 'none';
startArticlePreview(article, oldid, a.navpopup);
nonsimplePopupContent(a, article);
}
};
}
s.innerHTML = popupString('show preview');
}
setPopupHTML(d, 'popupPreview', a.navpopup.idNumber);
function pendingNavpopTask(navpop) {
}
if (navpop && navpop.pending === null) {
}
navpop.pending = 0;

}
if (a.navpopup.pending !== 0) {
++navpop.pending;
nonsimplePopupContent(a, article);
debugData(navpop);
}
}
}
function completedNavpopTask(navpop) {

if (navpop && navpop.pending) {
// simplePopupContent: the content that do not require additional download
--navpop.pending;
// (it is shown even when simplePopups is true)
}
function simplePopupContent(a, article) {
debugData(navpop);
/* FIXME hack */ a.navpopup.hasPopupMenu = false;
}
a.navpopup.setInnerHTML(popupHTML(a));
function startArticlePreview(article, oldid, navpop) {
fillEmptySpans({ navpopup: a.navpopup });
navpop.redir = 0;

loadPreview(article, oldid, navpop);
if (getValueOf('popupDraggable')) {
}
var dragHandle = getValueOf('popupDragHandle') || null;
function loadPreview(article, oldid, navpop) {
if (dragHandle && dragHandle != 'all') {
if (!navpop.redir) {
dragHandle += a.navpopup.idNumber;
navpop.originalArticle = article;
}
}
setTimeout(function () {
article.oldid = oldid;
a.navpopup.makeDraggable(dragHandle);
loadAPIPreview('revision', article, navpop);
}, 150);
}
}
function loadPreviewFromRedir(redirMatch, navpop) {

var target = new Title().fromWikiText(redirMatch[2]);
if (getValueOf('popupRedlinkRemoval') && a.className == 'new') {
if (navpop.article.anchor) {
setPopupHTML('<br>' + popupRedlinkHTML(article), 'popupRedlink', a.navpopup.idNumber);
target.anchor = navpop.article.anchor;
}
}
}
navpop.redir++;

navpop.redirTarget = target;
function debugData(navpopup) {
var warnRedir = redirLink(target, navpop.article);
if (getValueOf('popupDebugging') && navpopup.idNumber) {
setPopupHTML(warnRedir, 'popupWarnRedir', navpop.idNumber);
setPopupHTML(
navpop.article = target;
'idNumber=' + navpopup.idNumber + ', pending=' + navpopup.pending,
fillEmptySpans({
'popupError',
redir: true,
navpopup.idNumber
redirTarget: target,
);
navpopup: navpop
}
});
}
return loadPreview(target, null, navpop);

}
function insertPreview(download) {
function newNavpopup(a, article) {
var navpopup = new Navpopup();
if (!download.owner) {
navpopup.fuzz = 5;
return;
navpopup.delay = getValueOf('popupDelay') * 1000;
}
// increment global counter now
var redirMatch = pg.re.redirect.exec(download.data);
navpopup.idNumber = ++pg.idNumber;
if (download.owner.redir === 0 && redirMatch) {
navpopup.parentAnchor = a;
loadPreviewFromRedir(redirMatch, download.owner);
navpopup.parentPopup = a.popData && a.popData.owner;
return;
navpopup.article = article;
}
registerHooks(navpopup);
if (download.owner.visible || !getValueOf('popupLazyPreviews')) {
return navpopup;
insertPreviewNow(download);
}
} else {

var id = download.owner.redir ? 'PREVIEW_REDIR_HOOK' : 'PREVIEW_HOOK';
// Should we show nonsimple context?
download.owner.addHook(function() {
// If simplePopups is set to true, then we do not show nonsimple context,
insertPreviewNow(download);
// but if a bottom "show preview" was clicked we do show nonsimple context
return true;
function shouldShowNonSimple(a) {
}, 'unhide', 'after', id);
return !getValueOf('simplePopups') || a.simpleNoMore;
}
}
}

function insertPreviewNow(download) {
// Should we show nonsimple context govern by the option (e.g. popupUserInfo)?
if (!download.owner) {
// If the user explicitly asked for nonsimple context by setting the option to true,
return;
// then we show it even in nonsimple mode.
}
function shouldShow(a, option) {
var wikiText = download.data;
if (shouldShowNonSimple(a)) {
var navpop = download.owner;
return getValueOf(option);
var art = navpop.redirTarget || navpop.originalArticle;
} else {
makeFixDabs(wikiText, navpop);
return typeof window[option] != 'undefined' && window[option];
if (getValueOf('popupSummaryData')) {
}
getPageInfo(wikiText, download);
}
setPopupTrailer(getPageInfo(wikiText, download), navpop.idNumber);

}
function nonsimplePopupContent(a, article) {
var imagePage = '';
var diff = null,
if (art.namespaceId() == pg.nsImageId) {
history = null;
imagePage = art.toString();
var params = parseParams(a.href);
} else {
var oldid = typeof params.oldid == 'undefined' ? null : params.oldid;
imagePage = getValidImageFromWikiText(wikiText);
if (shouldShow(a, 'popupPreviewDiffs')) {
}
diff = params.diff;
if (imagePage) {
}
loadImage(Title.fromWikiText(imagePage), navpop);
if (shouldShow(a, 'popupPreviewHistory')) {
}
history = params.action == 'history';
if (getValueOf('popupPreviews')) {
}
insertArticlePreview(download, art, navpop);
a.navpopup.pending = 0;
}
var referenceElement = footnoteTarget(a);
}
if (referenceElement) {
function insertArticlePreview(download, art, navpop) {
footnotePreview(referenceElement, a.navpopup);
if (download && typeof download.data == typeof '') {
} else if (diff || diff === 0) {
if (art.namespaceId() == pg.nsTemplateId && getValueOf('popupPreviewRawTemplates')) {
loadDiff(article, oldid, diff, a.navpopup);
var h = '<hr /><span style="font-family: monospace;">' + download.data.entify().split('\\n').join('<br />\\n') + '</span>';
} else if (history) {
setPopupHTML(h, 'popupPreview', navpop.idNumber);
loadAPIPreview('history', article, a.navpopup);
} else {
} else if (shouldShowNonSimple(a) && pg.re.contribs.test(a.href)) {
var p = prepPreviewmaker(download.data, art, navpop);
loadAPIPreview('contribs', article, a.navpopup);
p.showPreview();
} else if (shouldShowNonSimple(a) && pg.re.backlinks.test(a.href)) {
}
loadAPIPreview('backlinks', article, a.navpopup);
}
} else if (
}
// FIXME should be able to get all preview combinations with options
function prepPreviewmaker(data, article, navpop) {
article.namespaceId() == pg.nsImageId &&
var d = anchorize(data, article.anchorString());
(shouldShow(a, 'imagePopupsForImages') || !anchorContainsImage(a))
var urlBase = joinPath([pg.wiki.articlebase, article.urlString()]);
) {
var p = new Previewmaker(d,urlBase,navpop);
loadAPIPreview('imagepagepreview', article, a.navpopup);
return p;
loadImage(article, a.navpopup);
}
} else {
function anchorize(d, anch) {
if (article.namespaceId() == pg.nsCategoryId && shouldShow(a, 'popupCategoryMembers')) {
if (!anch) {
loadAPIPreview('category', article, a.navpopup);
return d;
} else if (
}
(article.namespaceId() == pg.nsUserId || article.namespaceId() == pg.nsUsertalkId) &&
var anchRe = RegExp('(?:=+\\s*' + literalizeRegex(anch).replace(/[_ ]/g, '[_ ]') + '\\s*=+|\\{\\{\\s*' + getValueOf('popupAnchorRegexp') + '\\s*(?:\\|[^|}]*)*?\\s*' + literalizeRegex(anch) + '\\s*(?:\\|[^}]*)?}})');
shouldShow(a, 'popupUserInfo')
var match = d.match(anchRe);
) {
if (match && match.length > 0 && match[0]) {
loadAPIPreview('userinfo', article, a.navpopup);
return d.substring(d.indexOf(match[0]));
}
}
if (shouldShowNonSimple(a)) {
var lines = d.split('\n');
startArticlePreview(article, oldid, a.navpopup);
for (var i = 0; i < lines.length; ++i) {
}
lines[i] = lines[i].replace(RegExp('[[]{2}([^|\\]]*?[|])?(.*?)[\\]]{2}', 'g'), '$2').replace(/'''([^'])/g, '$1').replace(RegExp("''([^'])", 'g'), '$1');
}
if (lines[i].match(anchRe)) {
}
return d.split('\n').slice(i).join('\n').replace(RegExp('^[^=]*'), '');

}
function pendingNavpopTask(navpop) {
}
if (navpop && navpop.pending === null) {
return d;
navpop.pending = 0;
}
}
function killPopup() {
++navpop.pending;
removeModifierKeyHandler(this);
debugData(navpop);
if (getValueOf('popupShortcutKeys')) {
}
rmPopupShortcuts();

}
function completedNavpopTask(navpop) {
if (!pg) {
if (navpop && navpop.pending) {
return;
--navpop.pending;
}
}
if (pg.current.link && pg.current.link.navpopup) {
debugData(navpop);
pg.current.link.navpopup.banish();
}
}

pg.current.link = null;
function startArticlePreview(article, oldid, navpop) {
abortAllDownloads();
navpop.redir = 0;
if (pg.timer.checkPopupPosition) {
loadPreview(article, oldid, navpop);
clearInterval(pg.timer.checkPopupPosition);
}
pg.timer.checkPopupPosition = null;

}
function loadPreview(article, oldid, navpop) {
return true;
if (!navpop.redir) {
}
navpop.originalArticle = article;
function Drag() {
}
this.startCondition = null;
article.oldid = oldid;
this.endHook = null;
loadAPIPreview('revision', article, navpop);
}
}
Drag.prototype.fixE = function(e) {

if (typeof e == 'undefined') {
function loadPreviewFromRedir(redirMatch, navpop) {
e = window.event;
// redirMatch is a regex match
}
var target = new Title().fromWikiText(redirMatch[2]);
if (typeof e.layerX == 'undefined') {
// overwrite (or add) anchor from original target
e.layerX = e.offsetX;
// mediawiki does overwrite; eg [[User:Lupin/foo3#Done]]
}
if (navpop.article.anchor) {
if (typeof e.layerY == 'undefined') {
target.anchor = navpop.article.anchor;
e.layerY = e.offsetY;
}
}
navpop.redir++;
return e;
navpop.redirTarget = target;
}
var warnRedir = redirLink(target, navpop.article);
;
setPopupHTML(warnRedir, 'popupWarnRedir', navpop.idNumber);
Drag.prototype.init = function(o, oRoot) {
navpop.article = target;
var dragObj = this;
fillEmptySpans({ redir: true, redirTarget: target, navpopup: navpop });
this.obj = o;
return loadPreview(target, null, navpop);
o.onmousedown = function(e) {
}
dragObj.start.apply(dragObj, [e]);

}
function insertPreview(download) {
;
if (!download.owner) {
o.dragging = false;
return;
o.popups_draggable = true;
}
o.hmode = true;

o.vmode = true;
var redirMatch = pg.re.redirect.exec(download.data);
o.root = oRoot ? oRoot : o;
if (download.owner.redir === 0 && redirMatch) {
if (isNaN(parseInt(o.root.style.left, 10))) {
loadPreviewFromRedir(redirMatch, download.owner);
o.root.style.left = '0px';
return;
}
}
if (isNaN(parseInt(o.root.style.top, 10))) {

o.root.style.top = '0px';
if (download.owner.visible || !getValueOf('popupLazyPreviews')) {
}
insertPreviewNow(download);
o.root.onthisStart = function() {}
} else {
;
var id = download.owner.redir ? 'PREVIEW_REDIR_HOOK' : 'PREVIEW_HOOK';
o.root.onthisEnd = function() {}
download.owner.addHook(
;
function () {
o.root.onthis = function() {}
insertPreviewNow(download);
;
return true;
}
},
;
'unhide',
Drag.prototype.start = function(e) {
'after',
var o = this.obj;
id
e = this.fixE(e);
);
if (this.startCondition && !this.startCondition(e)) {
}
return;
}
}

var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom, 10);
function insertPreviewNow(download) {
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right, 10);
if (!download.owner) {
o.root.onthisStart(x, y);
return;
o.lastMouseX = e.clientX;
}
o.lastMouseY = e.clientY;
var wikiText = download.data;
var dragObj = this;
var navpop = download.owner;
o.onmousemoveDefault = document.onmousemove;
var art = navpop.redirTarget || navpop.originalArticle;
o.dragging = true;

document.onmousemove = function(e) {
makeFixDabs(wikiText, navpop);
dragObj.drag.apply(dragObj, [e]);
if (getValueOf('popupSummaryData')) {
}
getPageInfo(wikiText, download);
;
setPopupTrailer(getPageInfo(wikiText, download), navpop.idNumber);
document.onmouseup = function(e) {
}
dragObj.end.apply(dragObj, [e]);

}
var imagePage = '';
;
if (art.namespaceId() == pg.nsImageId) {
return false;
imagePage = art.toString();
}
} else {
;
imagePage = getValidImageFromWikiText(wikiText);
Drag.prototype.drag = function(e) {
}
e = this.fixE(e);
if (imagePage) {
var o = this.obj;
loadImage(Title.fromWikiText(imagePage), navpop);
var ey = e.clientY;
}
var ex = e.clientX;

var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom, 10);
if (getValueOf('popupPreviews')) {
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right, 10);
insertArticlePreview(download, art, navpop);
var nx, ny;
}
nx = x + (ex - o.lastMouseX) * (o.hmode ? 1 : -1);
}
ny = y + (ey - o.lastMouseY) * (o.vmode ? 1 : -1);

this.obj.root.style[o.hmode ? 'left' : 'right'] = nx + 'px';
function insertArticlePreview(download, art, navpop) {
this.obj.root.style[o.vmode ? 'top' : 'bottom'] = ny + 'px';
if (download && typeof download.data == typeof '') {
this.obj.lastMouseX = ex;
if (art.namespaceId() == pg.nsTemplateId && getValueOf('popupPreviewRawTemplates')) {
this.obj.lastMouseY = ey;
// FIXME compare/consolidate with diff escaping code for wikitext
this.obj.root.onthis(nx, ny);
var h =
return false;
'<hr /><span style="font-family: monospace;">' +
}
download.data.entify().split('\\n').join('<br />\\n') +
;
'</span>';
Drag.prototype.end = function() {
setPopupHTML(h, 'popupPreview', navpop.idNumber);
document.onmousemove = this.obj.onmousemoveDefault;
} else {
document.onmouseup = null;
var p = prepPreviewmaker(download.data, art, navpop);
this.obj.dragging = false;
p.showPreview();
if (this.endHook) {
}
this.endHook(parseInt(this.obj.root.style[this.obj.hmode ? 'left' : 'right'], 10), parseInt(this.obj.root.style[this.obj.vmode ? 'top' : 'bottom'], 10));
}
}
}
}

;
function prepPreviewmaker(data, article, navpop) {
pg.structures.original = {};
// deal with tricksy anchors
pg.structures.original.popupLayout = function() {
var d = anchorize(data, article.anchorString());
return ['popupError', 'popupImage', 'popupTopLinks', 'popupTitle', 'popupUserData', 'popupData', 'popupOtherLinks', 'popupRedir', ['popupWarnRedir', 'popupRedirTopLinks', 'popupRedirTitle', 'popupRedirData', 'popupRedirOtherLinks', ], 'popupMiscTools', ['popupRedlink'], 'popupPrePreviewSep', 'popupPreview', 'popupSecondPreview', 'popupPreviewMore', 'popupPostPreview', 'popupFixDab', ];
var urlBase = joinPath([pg.wiki.articlebase, article.urlString()]);
}
var p = new Previewmaker(d, urlBase, navpop);
;
return p;
pg.structures.original.popupRedirSpans = function() {
}
return ['popupRedir', 'popupWarnRedir', 'popupRedirTopLinks', 'popupRedirTitle', 'popupRedirData', 'popupRedirOtherLinks', ];

}
// Try to imitate the way mediawiki generates HTML anchors from section titles
;
function anchorize(d, anch) {
pg.structures.original.popupTitle = function(x) {
if (!anch) {
log('defaultstructure.popupTitle');
return d;
if (!getValueOf('popupNavLinks')) {
}
return navlinkStringToHTML('<b><<mainlink>></b>', x.article, x.params);
var anchRe = RegExp(
}
'(?:=+\\s*' +
return '';
literalizeRegex(anch).replace(/[_ ]/g, '[_ ]') +
}
'\\s*=+|\\{\\{\\s*' +
;
getValueOf('popupAnchorRegexp') +
pg.structures.original.popupTopLinks = function(x) {
'\\s*(?:\\|[^|}]*)*?\\s*' +
log('defaultstructure.popupTopLinks');
literalizeRegex(anch) +
if (getValueOf('popupNavLinks')) {
'\\s*(?:\\|[^}]*)?}})'
return navLinksHTML(x.article, x.hint, x.params);
);
}
var match = d.match(anchRe);
return '';
if (match && match.length > 0 && match[0]) {
}
return d.substring(d.indexOf(match[0]));
;
}
pg.structures.original.popupImage = function(x) {

log('original.popupImage, x.article=' + x.article + ', x.navpop.idNumber=' + x.navpop.idNumber);
// now try to deal with == foo [[bar|baz]] boom == -> #foo_baz_boom
return imageHTML(x.article, x.navpop.idNumber);
var lines = d.split('\n');
}
for (var i = 0; i < lines.length; ++i) {
;
lines[i] = lines[i]
pg.structures.original.popupRedirTitle = pg.structures.original.popupTitle;
.replace(RegExp('[[]{2}([^|\\]]*?[|])?(.*?)[\\]]{2}', 'g'), '$2')
pg.structures.original.popupRedirTopLinks = pg.structures.original.popupTopLinks;
.replace(/'''([^'])/g, '$1')
function copyStructure(oldStructure, newStructure) {
.replace(RegExp("''([^'])", 'g'), '$1');
pg.structures[newStructure] = {};
if (lines[i].match(anchRe)) {
for (var prop in pg.structures[oldStructure]) {
return d.split('\n').slice(i).join('\n').replace(RegExp('^[^=]*'), '');
pg.structures[newStructure][prop] = pg.structures[oldStructure][prop];
}
}
}
}
return d;
copyStructure('original', 'nostalgia');
}
pg.structures.nostalgia.popupTopLinks = function(x) {

var str = '';
function killPopup() {
str += '<b><<mainlink|shortcut= >></b>';
removeModifierKeyHandler(this);
str += 'if(user){<br><<contribs|shortcut=c>>';
if (getValueOf('popupShortcutKeys')) {
str += 'if(wikimedia){*<<count|shortcut=#>>}';
rmPopupShortcuts();
str += 'if(ipuser){}else{*<<email|shortcut=E>>}if(admin){*<<block|shortcut=b>>}}';
}
var editstr = '<<edit|shortcut=e>>';
if (!pg) {
var editOldidStr = 'if(oldid){<<editOld|shortcut=e>>|<<revert|shortcut=v|rv>>|<<edit|cur>>}else{' + editstr + '}';
return;
var historystr = '<<history|shortcut=h>>';
}
var watchstr = '<<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>>';
if (pg.current.link && pg.current.link.navpopup) {
str += '<br>if(talk){' + editOldidStr + '|<<new|shortcut=+>>' + '*' + historystr + '*' + watchstr + '*' + '<b><<article|shortcut=a>></b>|<<editArticle|edit>>' + '}else{' + editOldidStr + '*' + historystr + '*' + watchstr + '*' + '<b><<talk|shortcut=t>></b>|<<editTalk|edit>>|<<newTalk|shortcut=+|new>>}';
pg.current.link.navpopup.banish();
str += '<br><<whatLinksHere|shortcut=l>>*<<relatedChanges|shortcut=r>>';
}
str += 'if(admin){<br>}else{*}<<move|shortcut=m>>';
pg.current.link = null;
str += 'if(admin){*<<unprotect|unprotectShort>>|<<protect|shortcut=p>>*' + '<<undelete|undeleteShort>>|<<delete|shortcut=d>>}';
abortAllDownloads();
return navlinkStringToHTML(str, x.article, x.params);
if (pg.timer.checkPopupPosition) {
}
clearInterval(pg.timer.checkPopupPosition);
;
pg.timer.checkPopupPosition = null;
pg.structures.nostalgia.popupRedirTopLinks = pg.structures.nostalgia.popupTopLinks;
}
copyStructure('original', 'fancy');
return true; // preserve default action
pg.structures.fancy.popupTitle = function(x) {
}
return navlinkStringToHTML('<font size=+0><<mainlink>></font>', x.article, x.params);
// ENDFILE: actions.js
}

;
// STARTFILE: domdrag.js
pg.structures.fancy.popupTopLinks = function(x) {
/**
var hist = '<<history|shortcut=h|hist>>|<<lastEdit|shortcut=/|last>>|<<editors|shortcut=E|eds>>';
@fileoverview
var watch = '<<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>>';
The {@link Drag} object, which enables objects to be dragged around.
var move = '<<move|shortcut=m|move>>';

return navlinkStringToHTML('if(talk){' + '<<edit|shortcut=e>>|<<new|shortcut=+|+>>*' + hist + '*' + '<<article|shortcut=a>>|<<editArticle|edit>>' + '*' + watch + '*' + move + '}else{<<edit|shortcut=e>>*' + hist + '*<<talk|shortcut=t|>>|<<editTalk|edit>>|<<newTalk|shortcut=+|new>>' + '*' + watch + '*' + move + '}<br>', x.article, x.params);
<pre>
}
*************************************************
;
dom-drag.js
pg.structures.fancy.popupOtherLinks = function(x) {
09.25.2001
var admin = '<<unprotect|unprotectShort>>|<<protect|shortcut=p>>*<<undelete|undeleteShort>>|<<delete|shortcut=d|del>>';
www.youngpup.net
var user = '<<contribs|shortcut=c>>if(wikimedia){|<<count|shortcut=#|#>>}';
**************************************************
user += 'if(ipuser){|<<arin>>}else{*<<email|shortcut=E|' + popupString('email') + '>>}if(admin){*<<block|shortcut=b>>}';
10.28.2001 - fixed minor bug where events
var normal = '<<whatLinksHere|shortcut=l|links here>>*<<relatedChanges|shortcut=r|related>>';
sometimes fired off the handle, not the root.
return navlinkStringToHTML('<br>if(user){' + user + '*}if(admin){' + admin + 'if(user){<br>}else{*}}' + normal, x.article, x.params);
*************************************************
}
Pared down, some hooks added by [[User:Lupin]]
;

pg.structures.fancy.popupRedirTitle = pg.structures.fancy.popupTitle;
Copyright Aaron Boodman.
pg.structures.fancy.popupRedirTopLinks = pg.structures.fancy.popupTopLinks;
Saying stupid things daily since March 2001.
pg.structures.fancy.popupRedirOtherLinks = pg.structures.fancy.popupOtherLinks;
</pre>
copyStructure('fancy', 'fancy2');
*/
pg.structures.fancy2.popupTopLinks = function(x) {

return '<br>' + pg.structures.fancy.popupTopLinks(x).replace(RegExp('<br>$', 'i'), '');
/**
}
* Creates a new Drag object. This is used to make various DOM elements draggable.
;
* @constructor
pg.structures.fancy2.popupLayout = function() {
*/
return ['popupError', 'popupImage', 'popupTitle', 'popupUserData', 'popupData', 'popupTopLinks', 'popupOtherLinks', 'popupRedir', ['popupWarnRedir', 'popupRedirTopLinks', 'popupRedirTitle', 'popupRedirData', 'popupRedirOtherLinks', ], 'popupMiscTools', ['popupRedlink'], 'popupPrePreviewSep', 'popupPreview', 'popupSecondPreview', 'popupPreviewMore', 'popupPostPreview', 'popupFixDab', ];
function Drag() {
}
/**
;
* Condition to determine whether or not to drag. This function should take one parameter,
copyStructure('original', 'menus');
* an Event. To disable this, set it to <code>null</code>.
pg.structures.menus.popupLayout = function() {
* @type {Function}
return ['popupError', 'popupImage', 'popupTopLinks', 'popupTitle', 'popupOtherLinks', 'popupRedir', ['popupWarnRedir', 'popupRedirTopLinks', 'popupRedirTitle', 'popupRedirData', 'popupRedirOtherLinks', ], 'popupUserData', 'popupData', 'popupMiscTools', ['popupRedlink'], 'popupPrePreviewSep', 'popupPreview', 'popupSecondPreview', 'popupPreviewMore', 'popupPostPreview', 'popupFixDab', ];
*/
}
this.startCondition = null;
;

pg.structures.menus.popupTopLinks = function(x, shorter) {
/**
var s = [];
* Hook to be run when the drag finishes. This is passed the final coordinates of the
var dropclass = 'popup_drop';
* dragged object (two integers, x and y). To disables this, set it to <code>null</code>.
var enddiv = '</div>';
* @type {Function}
var hist = '<<history|shortcut=h>>';
*/
if (!shorter) {
this.endHook = null;
hist = '<menurow>' + hist + '|<<historyfeed|rss>>|<<editors|shortcut=E>></menurow>';
}
}

var lastedit = '<<lastEdit|shortcut=/|show last edit>>';
/**
var thank = 'if(diff){<<thank|send thanks>>}';
* Gets an event in a cross-browser manner.
var jsHistory = '<<lastContrib|last set of edits>><<sinceMe|changes since mine>>';
* @param {Event} e
var linkshere = '<<whatLinksHere|shortcut=l|what links here>>';
* @private
var related = '<<relatedChanges|shortcut=r|related changes>>';
*/
var search = '<menurow><<search|shortcut=s>>if(wikimedia){|<<globalsearch|shortcut=g|global>>}' + '|<<google|shortcut=G|web>></menurow>';
Drag.prototype.fixE = function (e) {
var watch = '<menurow><<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>></menurow>';
if (typeof e == 'undefined') {
var protect = '<menurow><<unprotect|unprotectShort>>|' + '<<protect|shortcut=p>>|<<protectlog|log>></menurow>';
e = window.event;
var del = '<menurow><<undelete|undeleteShort>>|<<delete|shortcut=d>>|' + '<<deletelog|log>></menurow>';
}
var move = '<<move|shortcut=m|move page>>';
if (typeof e.layerX == 'undefined') {
var nullPurge = '<menurow><<nullEdit|shortcut=n|null edit>>|<<purge|shortcut=P>></menurow>';
e.layerX = e.offsetX;
var viewOptions = '<menurow><<view|shortcut=v>>|<<render|shortcut=S>>|<<raw>></menurow>';
}
var editRow = 'if(oldid){' + '<menurow><<edit|shortcut=e>>|<<editOld|shortcut=e|this&nbsp;revision>></menurow>' + '<menurow><<revert|shortcut=v>>|<<undo>></menurow>' + '}else{<<edit|shortcut=e>>}';
if (typeof e.layerY == 'undefined') {
var markPatrolled = 'if(rcid){<<markpatrolled|mark patrolled>>}';
e.layerY = e.offsetY;
var newTopic = 'if(talk){<<new|shortcut=+|new topic>>}';
}
var protectDelete = 'if(admin){' + protect + del + '}';
return e;
if (getValueOf('popupActionsMenu')) {
};
s.push('<<mainlink>>*' + menuTitle(dropclass, 'actions'));

} else {
/**
s.push('<div class="' + dropclass + '">' + '<<mainlink>>');
* Initialises the Drag instance by telling it which object you want to be draggable, and what
}
* you want to drag it by.
s.push('<menu>');
* @param {DOMElement} o The "handle" by which <code>oRoot</code> is dragged.
s.push(editRow + markPatrolled + newTopic + hist + lastedit + thank);
* @param {DOMElement} oRoot The object which moves when <code>o</code> is dragged, or <code>o</code> if omitted.
if (!shorter) {
*/
s.push(jsHistory);
Drag.prototype.init = function (o, oRoot) {
}
var dragObj = this;
s.push(move + linkshere + related);
this.obj = o;
if (!shorter) {
o.onmousedown = function (e) {
s.push(nullPurge + search);
dragObj.start.apply(dragObj, [e]);
}
};
if (!shorter) {
o.dragging = false;
s.push(viewOptions);
o.popups_draggable = true;
}
o.hmode = true;
s.push('<hr />' + watch + protectDelete);
o.vmode = true;
s.push('<hr />' + 'if(talk){<<article|shortcut=a|view article>><<editArticle|edit article>>}' + 'else{<<talk|shortcut=t|talk page>><<editTalk|edit talk>>' + '<<newTalk|shortcut=+|new topic>>}</menu>' + enddiv);

var email = '<<email|shortcut=E|email user>>';
o.root = oRoot ? oRoot : o;
var contribs = 'if(wikimedia){<menurow>}<<contribs|shortcut=c|contributions>>if(wikimedia){</menurow>}' + 'if(admin){<menurow><<deletedContribs>></menurow>}';

s.push('if(user){*' + menuTitle(dropclass, 'user'));
if (isNaN(parseInt(o.root.style.left, 10))) {
s.push('<menu>');
o.root.style.left = '0px';
s.push('<menurow><<userPage|shortcut=u|user&nbsp;page>>|<<userSpace|space>></menurow>');
}
s.push('<<userTalk|shortcut=t|user talk>><<editUserTalk|edit user talk>>' + '<<newUserTalk|shortcut=+|leave comment>>');
if (isNaN(parseInt(o.root.style.top, 10))) {
if (!shorter) {
o.root.style.top = '0px';
s.push('if(ipuser){<<arin>>}else{' + email + '}');
}
} else {

s.push('if(ipuser){}else{' + email + '}');
o.root.onthisStart = function () {};
}
o.root.onthisEnd = function () {};
s.push('<hr />' + contribs + '<<userlog|shortcut=L|user log>>');
o.root.onthis = function () {};
s.push('if(wikimedia){<<count|shortcut=#|edit counter>>}');
};
s.push('if(admin){<menurow><<unblock|unblockShort>>|<<block|shortcut=b|block user>></menurow>}');

s.push('<<blocklog|shortcut=B|block log>>');
/**
s.push('</menu>' + enddiv + '}');
* Starts the drag.
if (getValueOf('popupSetupMenu') && !x.navpop.hasPopupMenu) {
* @private
x.navpop.hasPopupMenu = true;
* @param {Event} e
s.push('*' + menuTitle(dropclass, 'popupsMenu') + '<menu>');
*/
s.push('<<togglePreviews|toggle previews>>');
Drag.prototype.start = function (e) {
s.push('<<purgePopups|reset>>');
var o = this.obj; // = this;
s.push('<<disablePopups|disable>>');
e = this.fixE(e);
s.push('</menu>' + enddiv);
if (this.startCondition && !this.startCondition(e)) {
}
return;
return navlinkStringToHTML(s.join(''), x.article, x.params);
}
}
var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom, 10);
;
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right, 10);
function menuTitle(dropclass, s) {
o.root.onthisStart(x, y);
var text = popupString(s);

var len = text.length;
o.lastMouseX = e.clientX;
return '<div class="' + dropclass + '" style="--navpop-m-len:' + len + 'ch">' + '<a href="#" noPopup=1>' + text + '</a>';
o.lastMouseY = e.clientY;
}

pg.structures.menus.popupRedirTitle = pg.structures.menus.popupTitle;
var dragObj = this;
pg.structures.menus.popupRedirTopLinks = pg.structures.menus.popupTopLinks;
o.onmousemoveDefault = document.onmousemove;
copyStructure('menus', 'shortmenus');
o.dragging = true;
pg.structures.shortmenus.popupTopLinks = function(x) {
document.onmousemove = function (e) {
return pg.structures.menus.popupTopLinks(x, true);
dragObj.drag.apply(dragObj, [e]);
}
};
;
document.onmouseup = function (e) {
pg.structures.shortmenus.popupRedirTopLinks = pg.structures.shortmenus.popupTopLinks;
dragObj.end.apply(dragObj, [e]);
pg.structures.lite = {};
};
pg.structures.lite.popupLayout = function() {
return false;
return ['popupTitle', 'popupPreview'];
};
}

;
/**
pg.structures.lite.popupTitle = function(x) {
* Does the drag.
log(x.article + ': structures.lite.popupTitle');
* @param {Event} e
return '<div><span class="popup_mainlink"><b>' + x.article.toString() + '</b></span></div>';
* @private
}
*/
;
function substitute(data, cmdBody) {
Drag.prototype.drag = function (e) {
e = this.fixE(e);
var fromRe = RegExp(cmdBody.from, cmdBody.flags);
var o = this.obj;
return data.replace(fromRe, cmdBody.to);

}
var ey = e.clientY;
function execCmds(data, cmdList) {
var ex = e.clientX;
for (var i = 0; i < cmdList.length; ++i) {
var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom, 10);
data = cmdList[i].action(data, cmdList[i]);
var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right, 10);
}
var nx, ny;
return data;

}
nx = x + (ex - o.lastMouseX) * (o.hmode ? 1 : -1);
function parseCmd(str) {
ny = y + (ey - o.lastMouseY) * (o.vmode ? 1 : -1);
if (!str.length) {

return [];
this.obj.root.style[o.hmode ? 'left' : 'right'] = nx + 'px';
}
this.obj.root.style[o.vmode ? 'top' : 'bottom'] = ny + 'px';
var p = false;
this.obj.lastMouseX = ex;
switch (str.charAt(0)) {
this.obj.lastMouseY = ey;
case 's':

p = parseSubstitute(str);
this.obj.root.onthis(nx, ny);
break;
return false;
default:
};
return false;

}
/**
if (p) {
* Ends the drag.
return [p].concat(parseCmd(p.remainder));
* @private
}
*/
return false;
Drag.prototype.end = function () {
}
document.onmousemove = this.obj.onmousemoveDefault;
function unEscape(str, sep) {
document.onmouseup = null;
return str.split('\\\\').join('\\').split('\\' + sep).join(sep).split('\\n').join('\n');
this.obj.dragging = false;
}
if (this.endHook) {
function parseSubstitute(str) {
this.endHook(
var from, to, flags, tmp;
parseInt(this.obj.root.style[this.obj.hmode ? 'left' : 'right'], 10),
if (str.length < 4) {
parseInt(this.obj.root.style[this.obj.vmode ? 'top' : 'bottom'], 10)
return false;
);
}
}
var sep = str.charAt(1);
};
str = str.substring(2);
// ENDFILE: domdrag.js
tmp = skipOver(str, sep);

if (tmp) {
// STARTFILE: structures.js
from = tmp.segment;
pg.structures.original = {};
str = tmp.remainder;
pg.structures.original.popupLayout = function () {
} else {
return false;
return [
'popupError',
}
'popupImage',
tmp = skipOver(str, sep);
'popupTopLinks',
if (tmp) {
'popupTitle',
to = tmp.segment;
'popupUserData',
str = tmp.remainder;
'popupData',
} else {
'popupOtherLinks',
return false;
'popupRedir',
}
[
flags = '';
'popupWarnRedir',
if (str.length) {
'popupRedirTopLinks',
tmp = skipOver(str, ';') || skipToEnd(str, ';');
'popupRedirTitle',
if (tmp) {
'popupRedirData',
flags = tmp.segment;
'popupRedirOtherLinks',
str = tmp.remainder;
],
}
'popupMiscTools',
}
['popupRedlink'],
return {
'popupPrePreviewSep',
action: substitute,
'popupPreview',
from: from,
'popupSecondPreview',
to: to,
'popupPreviewMore',
flags: flags,
'popupPostPreview',
remainder: str,
'popupFixDab',
};
];
}
};
function skipOver(str, sep) {
pg.structures.original.popupRedirSpans = function () {
var endSegment = findNext(str, sep);
return [
if (endSegment < 0) {
'popupRedir',
return false;
'popupWarnRedir',
}
'popupRedirTopLinks',
var segment = unEscape(str.substring(0, endSegment), sep);
'popupRedirTitle',
return {
'popupRedirData',
segment: segment,
'popupRedirOtherLinks',
remainder: str.substring(endSegment + 1)
];
};
};
}
pg.structures.original.popupTitle = function (x) {
function skipToEnd(str, sep) {
log('defaultstructure.popupTitle');
return {
if (!getValueOf('popupNavLinks')) {
segment: str,
return navlinkStringToHTML('<b><<mainlink>></b>', x.article, x.params);
remainder: ''
}
};
return '';
}
};
function findNext(str, ch) {
pg.structures.original.popupTopLinks = function (x) {
for (var i = 0; i < str.length; ++i) {
log('defaultstructure.popupTopLinks');
if (str.charAt(i) == '\\') {
if (getValueOf('popupNavLinks')) {
i += 2;
return navLinksHTML(x.article, x.hint, x.params);
}
}
if (str.charAt(i) == ch) {
return i;
return '';
};
}
pg.structures.original.popupImage = function (x) {
}
log('original.popupImage, x.article=' + x.article + ', x.navpop.idNumber=' + x.navpop.idNumber);
return -1;
return imageHTML(x.article, x.navpop.idNumber);
}
};
function setCheckbox(param, box) {
pg.structures.original.popupRedirTitle = pg.structures.original.popupTitle;
var val = mw.util.getParamValue(param);
pg.structures.original.popupRedirTopLinks = pg.structures.original.popupTopLinks;
if (val) {

switch (val) {
function copyStructure(oldStructure, newStructure) {
case '1':
pg.structures[newStructure] = {};
case 'yes':
for (var prop in pg.structures[oldStructure]) {
case 'true':
pg.structures[newStructure][prop] = pg.structures[oldStructure][prop];
box.checked = true;
}
break;
}
case '0':

case 'no':
copyStructure('original', 'nostalgia');
case 'false':
pg.structures.nostalgia.popupTopLinks = function (x) {
box.checked = false;
var str = '';
}
str += '<b><<mainlink|shortcut= >></b>';
}

}
// user links
function autoEdit() {
// contribs - log - count - email - block
setupPopups(function() {
// count only if applicable; block only if popupAdminLinks
if (mw.util.getParamValue('autoimpl') !== popupString('autoedit_version')) {
str += 'if(user){<br><<contribs|shortcut=c>>';
return false;
str += 'if(wikimedia){*<<count|shortcut=#>>}';
}
str += 'if(ipuser){}else{*<<email|shortcut=E>>}if(admin){*<<block|shortcut=b>>}}';
if (mw.util.getParamValue('autowatchlist') && mw.util.getParamValue('actoken') === autoClickToken()) {

pg.fn.modifyWatchlist(mw.util.getParamValue('title'), mw.util.getParamValue('action'));
// editing links
}
// talkpage -> edit|new - history - un|watch - article|edit
if (!document.editform) {
// other page -> edit - history - un|watch - talk|edit|new
return false;
var editstr = '<<edit|shortcut=e>>';
}
var editOldidStr =
if (autoEdit.alreadyRan) {
'if(oldid){<<editOld|shortcut=e>>|<<revert|shortcut=v|rv>>|<<edit|cur>>}else{' +
return false;
editstr +
}
'}';
autoEdit.alreadyRan = true;
var historystr = '<<history|shortcut=h>>';
var cmdString = mw.util.getParamValue('autoedit');
var watchstr = '<<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>>';
if (cmdString) {

try {
str +=
var editbox = document.editform.wpTextbox1;
'<br>if(talk){' +
var cmdList = parseCmd(cmdString);
editOldidStr +
var input = editbox.value;
'|<<new|shortcut=+>>' +
var output = execCmds(input, cmdList);
'*' +
editbox.value = output;
historystr +
} catch (dang) {
'*' +
return;
watchstr +
}
'*' +
if (typeof wikEdUseWikEd != 'undefined') {
'<b><<article|shortcut=a>></b>|<<editArticle|edit>>' +
if (wikEdUseWikEd === true) {
'}else{' + // not a talk page
WikEdUpdateFrame();
editOldidStr +
}
'*' +
}
historystr +
}
'*' +
setCheckbox('autominor', document.editform.wpMinoredit);
watchstr +
setCheckbox('autowatch', document.editform.wpWatchthis);
'*' +
var rvid = mw.util.getParamValue('autorv');
'<b><<talk|shortcut=t>></b>|<<editTalk|edit>>|<<newTalk|shortcut=+|new>>}';
if (rvid) {

var url = pg.wiki.apiwikibase + '?action=query&format=json&formatversion=2&prop=revisions&revids=' + rvid;
// misc links
startDownload(url, null, autoEdit2);
str += '<br><<whatLinksHere|shortcut=l>>*<<relatedChanges|shortcut=r>>';
} else {
str += 'if(admin){<br>}else{*}<<move|shortcut=m>>';
autoEdit2();

}
// admin links
});
str +=
}
'if(admin){*<<unprotect|unprotectShort>>|<<protect|shortcut=p>>*' +
function autoEdit2(d) {
'<<undelete|undeleteShort>>|<<delete|shortcut=d>>}';
var summary = mw.util.getParamValue('autosummary');
return navlinkStringToHTML(str, x.article, x.params);
var summaryprompt = mw.util.getParamValue('autosummaryprompt');
};
var summarynotice = '';
pg.structures.nostalgia.popupRedirTopLinks = pg.structures.nostalgia.popupTopLinks;
if (d && d.data && mw.util.getParamValue('autorv')) {

var s = getRvSummary(summary, d.data);
/** -- fancy -- **/
if (s === false) {
copyStructure('original', 'fancy');
summaryprompt = true;
pg.structures.fancy.popupTitle = function (x) {
summarynotice = popupString('Failed to get revision information, please edit manually.\n\n');
return navlinkStringToHTML('<font size=+0><<mainlink>></font>', x.article, x.params);
summary = simplePrintf(summary, [mw.util.getParamValue('autorv'), '(unknown)', '(unknown)', ]);
};
} else {
pg.structures.fancy.popupTopLinks = function (x) {
summary = s;
var hist =
}
'<<history|shortcut=h|hist>>|<<lastEdit|shortcut=/|last>>|<<editors|shortcut=E|eds>>';
}
var watch = '<<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>>';
if (summaryprompt) {
var move = '<<move|shortcut=m|move>>';
var txt = summarynotice + popupString('Enter a non-empty edit summary or press cancel to abort');
return navlinkStringToHTML(
var response = prompt(txt, summary);
'if(talk){' +
if (response) {
'<<edit|shortcut=e>>|<<new|shortcut=+|+>>*' +
summary = response;
hist +
} else {
'*' +
return;
'<<article|shortcut=a>>|<<editArticle|edit>>' +
}
'*' +
}
watch +
if (summary) {
'*' +
document.editform.wpSummary.value = summary;
move +
}
'}else{<<edit|shortcut=e>>*' +
setTimeout(autoEdit3, 100);
hist +
}
'*<<talk|shortcut=t|>>|<<editTalk|edit>>|<<newTalk|shortcut=+|new>>' +
function autoClickToken() {
'*' +
return mw.user.sessionId();
watch +
}
'*' +
function autoEdit3() {
move +
if (mw.util.getParamValue('actoken') != autoClickToken()) {
'}<br>',
return;
x.article,
}
x.params
var btn = mw.util.getParamValue('autoclick');
);
if (btn) {
};
if (document.editform && document.editform[btn]) {
pg.structures.fancy.popupOtherLinks = function (x) {
var button = document.editform[btn];
var admin =
var msg = tprintf('The %s button has been automatically clicked. Please wait for the next page to load.', [button.value]);
'<<unprotect|unprotectShort>>|<<protect|shortcut=p>>*<<undelete|undeleteShort>>|<<delete|shortcut=d|del>>';
bannerMessage(msg);
var user = '<<contribs|shortcut=c>>if(wikimedia){|<<count|shortcut=#|#>>}';
document.title = '(' + document.title + ')';
user +=
button.click();
'if(ipuser){|<<arin>>}else{*<<email|shortcut=E|' +
} else {
popupString('email') +
alert(tprintf('Could not find button %s. Please check the settings in your javascript file.', [btn, ]));
'>>}if(admin){*<<block|shortcut=b>>}';
}

}
var normal = '<<whatLinksHere|shortcut=l|links here>>*<<relatedChanges|shortcut=r|related>>';
}
return navlinkStringToHTML(
function bannerMessage(s) {
'<br>if(user){' + user + '*}if(admin){' + admin + 'if(user){<br>}else{*}}' + normal,
var headings = document.getElementsByTagName('h1');
x.article,
if (headings) {
x.params
var div = document.createElement('div');
);
div.innerHTML = '<font size=+1><b>' + pg.escapeQuotesHTML(s) + '</b></font>';
};
headings[0].parentNode.insertBefore(div, headings[0]);
pg.structures.fancy.popupRedirTitle = pg.structures.fancy.popupTitle;
}
pg.structures.fancy.popupRedirTopLinks = pg.structures.fancy.popupTopLinks;
}
pg.structures.fancy.popupRedirOtherLinks = pg.structures.fancy.popupOtherLinks;
function getRvSummary(template, json) {

try {
/** -- fancy2 -- **/
var o = getJsObj(json);
// hack for [[User:MacGyverMagic]]
var edit = anyChild(o.query.pages).revisions[0];
copyStructure('fancy', 'fancy2');
var timestamp = edit.timestamp.split(/[A-Z]/g).join(' ').replace(/^ *| *$/g, '');
pg.structures.fancy2.popupTopLinks = function (x) {
return simplePrintf(template, [edit.revid, timestamp, edit.userhidden ? '(hidden)' : edit.user, ]);
// hack out the <br> at the end and put one at the beginning
} catch (badness) {
return '<br>' + pg.structures.fancy.popupTopLinks(x).replace(RegExp('<br>$', 'i'), '');
return false;
};
}
pg.structures.fancy2.popupLayout = function () {
}
// move toplinks to after the title
function Downloader(url) {
return [
if (typeof XMLHttpRequest != 'undefined') {
'popupError',
this.http = new XMLHttpRequest();
'popupImage',
}
'popupTitle',
this.url = url;
'popupUserData',
this.id = null;
'popupData',
this.lastModified = null;
'popupTopLinks',
this.callbackFunction = null;
'popupOtherLinks',
this.onFailure = null;
'popupRedir',
this.aborted = false;
[
this.method = 'GET';
'popupWarnRedir',
this.async = true;
'popupRedirTopLinks',
}
'popupRedirTitle',
new Downloader();
'popupRedirData',
Downloader.prototype.send = function(x) {
'popupRedirOtherLinks',
if (!this.http) {
],
return null;
'popupMiscTools',
}
['popupRedlink'],
return this.http.send(x);
'popupPrePreviewSep',
}
'popupPreview',
;
'popupSecondPreview',
Downloader.prototype.abort = function() {
'popupPreviewMore',
if (!this.http) {
'popupPostPreview',
return null;
'popupFixDab',
}
];
this.aborted = true;
};
return this.http.abort();

}
/** -- menus -- **/
;
copyStructure('original', 'menus');
Downloader.prototype.getData = function() {
pg.structures.menus.popupLayout = function () {
if (!this.http) {
return null;
return [
'popupError',
}
'popupImage',
return this.http.responseText;
'popupTopLinks',
}
'popupTitle',
;
'popupOtherLinks',
Downloader.prototype.setTarget = function() {
'popupRedir',
if (!this.http) {
[
return null;
'popupWarnRedir',
}
'popupRedirTopLinks',
this.http.open(this.method, this.url, this.async);
'popupRedirTitle',
this.http.setRequestHeader('Api-User-Agent', pg.api.userAgent);
'popupRedirData',
}
'popupRedirOtherLinks',
;
],
Downloader.prototype.getReadyState = function() {
'popupUserData',
if (!this.http) {
'popupData',
return null;
'popupMiscTools',
}
['popupRedlink'],
return this.http.readyState;
'popupPrePreviewSep',
}
'popupPreview',
;
'popupSecondPreview',
pg.misc.downloadsInProgress = {};
'popupPreviewMore',
Downloader.prototype.start = function() {
'popupPostPreview',
if (!this.http) {
'popupFixDab',
return;
];
}
};
pg.misc.downloadsInProgress[this.id] = this;

this.http.send(null);
pg.structures.menus.popupTopLinks = function (x, shorter) {
}
// FIXME maybe this stuff should be cached
;
var s = [];
Downloader.prototype.getLastModifiedDate = function() {
var dropclass = 'popup_drop';
if (!this.http) {
var enddiv = '</div>';
return null;
var hist = '<<history|shortcut=h>>';
}
if (!shorter) {
var lastmod = null;
hist = '<menurow>' + hist + '|<<historyfeed|rss>>|<<editors|shortcut=E>></menurow>';
try {
}
lastmod = this.http.getResponseHeader('Last-Modified');
var lastedit = '<<lastEdit|shortcut=/|show last edit>>';
} catch (err) {}
var thank = 'if(diff){<<thank|send thanks>>}';
if (lastmod) {
var jsHistory = '<<lastContrib|last set of edits>><<sinceMe|changes since mine>>';
return new Date(lastmod);
var linkshere = '<<whatLinksHere|shortcut=l|what links here>>';
}
var related = '<<relatedChanges|shortcut=r|related changes>>';
return null;
var search =
}
'<menurow><<search|shortcut=s>>if(wikimedia){|<<globalsearch|shortcut=g|global>>}' +
;
'|<<google|shortcut=G|web>></menurow>';
Downloader.prototype.setCallback = function(f) {
var watch = '<menurow><<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>></menurow>';
if (!this.http) {
var protect =
return;
'<menurow><<unprotect|unprotectShort>>|' +
}
'<<protect|shortcut=p>>|<<protectlog|log>></menurow>';
this.http.onreadystatechange = f;
var del =
}
'<menurow><<undelete|undeleteShort>>|<<delete|shortcut=d>>|' + '<<deletelog|log>></menurow>';
;
var move = '<<move|shortcut=m|move page>>';
Downloader.prototype.getStatus = function() {
var nullPurge = '<menurow><<nullEdit|shortcut=n|null edit>>|<<purge|shortcut=P>></menurow>';
if (!this.http) {
var viewOptions = '<menurow><<view|shortcut=v>>|<<render|shortcut=S>>|<<raw>></menurow>';
return null;
var editRow =
}
'if(oldid){' +
return this.http.status;
'<menurow><<edit|shortcut=e>>|<<editOld|shortcut=e|this&nbsp;revision>></menurow>' +
}
'<menurow><<revert|shortcut=v>>|<<undo>></menurow>' +
;
'}else{<<edit|shortcut=e>>}';
function newDownload(url, id, callback, onfailure) {
var markPatrolled = 'if(rcid){<<markpatrolled|mark patrolled>>}';
var d = new Downloader(url);
var newTopic = 'if(talk){<<new|shortcut=+|new topic>>}';
if (!d.http) {
var protectDelete = 'if(admin){' + protect + del + '}';
return 'ohdear';

}
if (getValueOf('popupActionsMenu')) {
d.id = id;
s.push('<<mainlink>>*' + menuTitle(dropclass, 'actions'));
d.setTarget();
} else {
if (!onfailure) {
s.push('<div class="' + dropclass + '">' + '<<mainlink>>');
onfailure = 2;
}
}
s.push('<menu>');
var f = function() {
s.push(editRow + markPatrolled + newTopic + hist + lastedit + thank);
if (d.getReadyState() == 4) {
if (!shorter) {
delete pg.misc.downloadsInProgress[this.id];
s.push(jsHistory);
try {
}
if (d.getStatus() == 200) {
s.push(move + linkshere + related);
d.data = d.getData();
if (!shorter) {
d.lastModified = d.getLastModifiedDate();
s.push(nullPurge + search);
callback(d);
}
} else if (typeof onfailure == typeof 1) {
if (!shorter) {
if (onfailure > 0) {
s.push(viewOptions);
newDownload(url, id, callback, onfailure - 1);
}
}
s.push('<hr />' + watch + protectDelete);
} else if (typeof onfailure === 'function') {
s.push(
onfailure(d, url, id, callback);
'<hr />' +
}
'if(talk){<<article|shortcut=a|view article>><<editArticle|edit article>>}' +
} catch (somerr) {}
'else{<<talk|shortcut=t|talk page>><<editTalk|edit talk>>' +
}
'<<newTalk|shortcut=+|new topic>>}</menu>' +
};
enddiv
d.setCallback(f);
);
return d;

}
// user menu starts here
function fakeDownload(url, id, callback, data, lastModified, owner) {
var email = '<<email|shortcut=E|email user>>';
var d = newDownload(url, callback);
var contribs =
d.owner = owner;
'if(wikimedia){<menurow>}<<contribs|shortcut=c|contributions>>if(wikimedia){</menurow>}' +
d.id = id;
'if(admin){<menurow><<deletedContribs>></menurow>}';
d.data = data;

d.lastModified = lastModified;
s.push('if(user){*' + menuTitle(dropclass, 'user'));
return callback(d);
s.push('<menu>');
}
s.push('<menurow><<userPage|shortcut=u|user&nbsp;page>>|<<userSpace|space>></menurow>');
function startDownload(url, id, callback) {
s.push(
var d = newDownload(url, id, callback);
'<<userTalk|shortcut=t|user talk>><<editUserTalk|edit user talk>>' +
if (typeof d == typeof '') {
'<<newUserTalk|shortcut=+|leave comment>>'
return d;
);
}
if (!shorter) {
d.start();
s.push('if(ipuser){<<arin>>}else{' + email + '}');
return d;
} else {
}
s.push('if(ipuser){}else{' + email + '}');
function abortAllDownloads() {
}
for (var x in pg.misc.downloadsInProgress) {
s.push('<hr />' + contribs + '<<userlog|shortcut=L|user log>>');
try {
s.push('if(wikimedia){<<count|shortcut=#|edit counter>>}');
pg.misc.downloadsInProgress[x].aborted = true;
s.push(
pg.misc.downloadsInProgress[x].abort();
'if(admin){<menurow><<unblock|unblockShort>>|<<block|shortcut=b|block user>></menurow>}'
delete pg.misc.downloadsInProgress[x];
);
} catch (e) {}
s.push('<<blocklog|shortcut=B|block log>>');
}
s.push('</menu>' + enddiv + '}');
}

var Insta = {};
// popups menu starts here
function setupLivePreview() {
if (getValueOf('popupSetupMenu') && !x.navpop.hasPopupMenu /* FIXME: hack */) {
Insta.conf = {
x.navpop.hasPopupMenu = true;
baseUrl: '',
s.push('*' + menuTitle(dropclass, 'popupsMenu') + '<menu>');
user: {},
s.push('<<togglePreviews|toggle previews>>');
wiki: {
s.push('<<purgePopups|reset>>');
lang: pg.wiki.lang,
s.push('<<disablePopups|disable>>');
interwiki: pg.wiki.interwiki,
s.push('</menu>' + enddiv);
default_thumb_width: 180,
}
},
return navlinkStringToHTML(s.join(''), x.article, x.params);
paths: {
};
articles: pg.wiki.articlePath + '/',

math: '/math/',
function menuTitle(dropclass, s) {
images: '//upload.wikimedia.org/wikipedia/en/',
var text = popupString(s); // i18n
images_fallback: '//upload.wikimedia.org/wikipedia/commons/',
var len = text.length;
},
return '<div class="' + dropclass + '" style="--navpop-m-len:' + len + 'ch">' + '<a href="#" noPopup=1>' + text + '</a>';
locale: {
}
user: mw.config.get('wgFormattedNamespaces')[pg.nsUserId],

image: mw.config.get('wgFormattedNamespaces')[pg.nsImageId],
pg.structures.menus.popupRedirTitle = pg.structures.menus.popupTitle;
category: mw.config.get('wgFormattedNamespaces')[pg.nsCategoryId],
pg.structures.menus.popupRedirTopLinks = pg.structures.menus.popupTopLinks;
months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', ],

},
copyStructure('menus', 'shortmenus');
};
pg.structures.shortmenus.popupTopLinks = function (x) {
Insta.conf.user.name = Insta.conf.user.name || 'Wikipedian';
return pg.structures.menus.popupTopLinks(x, true);
Insta.conf.user.signature = '[[' + Insta.conf.locale.user + ':' + Insta.conf.user.name + '|' + Insta.conf.user.name + ']]';
};
Insta.BLOCK_IMAGE = new RegExp('^\\[\\[(?:File|Image|' + Insta.conf.locale.image + '):.*?\\|.*?(?:frame|thumbnail|thumb|none|right|left|center)','i');
pg.structures.shortmenus.popupRedirTopLinks = pg.structures.shortmenus.popupTopLinks;
}

Insta.dump = function(from, to) {
pg.structures.lite = {};
if (typeof from == 'string') {
pg.structures.lite.popupLayout = function () {
from = document.getElementById(from);
return ['popupTitle', 'popupPreview'];
}
};
if (typeof to == 'string') {
pg.structures.lite.popupTitle = function (x) {
to = document.getElementById(to);
log(x.article + ': structures.lite.popupTitle');
}
//return navlinkStringToHTML('<b><<mainlink>></b>',x.article,x.params);
to.innerHTML = this.convert(from.value);
return '<div><span class="popup_mainlink"><b>' + x.article.toString() + '</b></span></div>';
}
};
;
// ENDFILE: structures.js
Insta.convert = function(wiki) {

var ll = typeof wiki == 'string' ? wiki.replace(/\r/g, '').split(/\n/) : wiki, o = '', p = 0, r;
// STARTFILE: autoedit.js
function remain() {
function substitute(data, cmdBody) {
return ll.length;
// alert('sub\nfrom: '+cmdBody.from+'\nto: '+cmdBody.to+'\nflags: '+cmdBody.flags);
}
var fromRe = RegExp(cmdBody.from, cmdBody.flags);
function sh() {
return data.replace(fromRe, cmdBody.to);
return ll.shift();
}
}

function ps(s) {
function execCmds(data, cmdList) {
o += s;
for (var i = 0; i < cmdList.length; ++i) {
}
data = cmdList[i].action(data, cmdList[i]);
function f() {
}
var i = 1, a = arguments, f = a[0], o = '', c, p;
return data;
for (; i < a.length; i++) {
}
if ((p = f.indexOf('?')) + 1) {

i -= c = f.charAt(p + 1) == '?' ? 1 : 0;
function parseCmd(str) {
o += f.substring(0, p) + (c ? '?' : a[i]);
// returns a list of commands
f = f.substr(p + 1 + c);
if (!str.length) {
} else {
return [];
break;
}
}
var p = false;
}
switch (str.charAt(0)) {
return o + f;
case 's':
}
p = parseSubstitute(str);
function html_entities(s) {
break;
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
default:
}
return false;
function htmlescape_text(s) {
}
return s.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/:/g, '&#58;').replace(/\[/g, '&#91;').replace(/]/g, '&#93;');
if (p) {
}
return [p].concat(parseCmd(p.remainder));
function htmlescape_attr(s) {
}
return htmlescape_text(s).replace(/'/g, '&#39;').replace(/"/g, '&quot;');
return false;
}
}
function str_imatch(a, b) {

for (var i = 0, l = Math.min(a.length, b.length); i < l; i++) {
// FIXME: Only used once here, confusing with native (and more widely-used) unescape, should probably be replaced
if (a.charAt(i) != b.charAt(i)) {
// Then again, unescape is semi-soft-deprecated, so we should look into replacing that too
break;
function unEscape(str, sep) {
}
return str
}
.split('\\\\')
return i;
.join('\\')
}
.split('\\' + sep)
function compareLineStringOrReg(c) {
.join(sep)
return typeof c == 'string' ? ll[0] && ll[0].substr(0, c.length) == c : (r = ll[0] && ll[0].match(c));
.split('\\n')
}
.join('\n');
function compareLineString(c) {
}
return ll[0] == c;

}
function charAtPoint(p) {
function parseSubstitute(str) {
// takes a string like s/a/b/flags;othercmds and parses it
return ll[0].charAt(p);

}
var from, to, flags, tmp;
function endl(s) {

ps(s);
if (str.length < 4) {
sh();
return false;
}
}
function parse_list() {
var sep = str.charAt(1);
var prev = '';
str = str.substring(2);
while (remain() && compareLineStringOrReg(/^([*#:;]+)(.*)$/)) {

var l_match = r;
tmp = skipOver(str, sep);
sh();
if (tmp) {
var ipos = str_imatch(prev, l_match[1]);
from = tmp.segment;
for (var prevPos = prev.length - 1; prevPos >= ipos; prevPos--) {
str = tmp.remainder;
var pi = prev.charAt(prevPos);
} else {
if (pi == '*') {
return false;
ps('</ul>');
}
} else if (pi == '#') {

ps('</ol>');
tmp = skipOver(str, sep);
} else if ($.inArray(l_match[1].charAt(prevPos), ['', '*', '#'])) {
if (tmp) {
ps('</dl>');
to = tmp.segment;
}
str = tmp.remainder;
}
} else {
for (var matchPos = ipos; matchPos < l_match[1].length; matchPos++) {
return false;
var li = l_match[1].charAt(matchPos);
}
if (li == '*') {

ps('<ul>');
flags = '';
} else if (li == '#') {
if (str.length) {
ps('<ol>');
tmp = skipOver(str, ';') || skipToEnd(str, ';');
} else if ($.inArray(prev.charAt(matchPos), ['', '*', '#'])) {
if (tmp) {
ps('<dl>');
flags = tmp.segment;
}
str = tmp.remainder;
}
}
switch (l_match[1].charAt(l_match[1].length - 1)) {
}
case '*':

case '#':
return {
ps('<li>' + parse_inline_nowiki(l_match[2]));
action: substitute,
break;
from: from,
case ';':
to: to,
ps('<dt>');
flags: flags,
var dt_match = l_match[2].match(/(.*?)(:.*?)$/);
remainder: str,
if (dt_match) {
};
ps(parse_inline_nowiki(dt_match[1]));
}
ll.unshift(dt_match[2]);

} else {
function skipOver(str, sep) {
ps(parse_inline_nowiki(l_match[2]));
var endSegment = findNext(str, sep);
}
if (endSegment < 0) {
break;
return false;
case ':':
}
ps('<dd>' + parse_inline_nowiki(l_match[2]));
var segment = unEscape(str.substring(0, endSegment), sep);
}
return { segment: segment, remainder: str.substring(endSegment + 1) };
prev = l_match[1];
}
}

for (var i = prev.length - 1; i >= 0; i--) {
/*eslint-disable*/
ps(f('</?>', prev.charAt(i) == '*' ? 'ul' : prev.charAt(i) == '#' ? 'ol' : 'dl'));
function skipToEnd(str, sep) {
}
return { segment: str, remainder: '' };
}
}
function parse_table() {
/*eslint-enable */
endl(f('<table>', compareLineStringOrReg(/^\{\|( .*)$/) ? r[1] : ''));

for (; remain(); ) {
function findNext(str, ch) {
if (compareLineStringOrReg('|')) {
for (var i = 0; i < str.length; ++i) {
switch (charAtPoint(1)) {
if (str.charAt(i) == '\\') {
case '}':
i += 2;
endl('</table>');
}
return;
if (str.charAt(i) == ch) {
case '-':
return i;
endl(f('<tr>', compareLineStringOrReg(/\|-*(.*)/)[1]));
}
break;
}
default:
return -1;
parse_table_data();
}
}

} else if (compareLineStringOrReg('!')) {
function setCheckbox(param, box) {
parse_table_data();
var val = mw.util.getParamValue(param);
} else {
if (val) {
sh();
switch (val) {
}
case '1':
}
case 'yes':
}
case 'true':
function parse_table_data() {
box.checked = true;
var td_line, match_i;
break;
var td_match = sh().match(/^(\|\+|\||!)((?:([^[|]*?)\|(?!\|))?(.*))$/);
case '0':
if (td_match[1] == '|+') {
case 'no':
ps('<caption');
case 'false':
} else {
box.checked = false;
ps('<t' + (td_match[1] == '|' ? 'd' : 'h'));
}
}
}
if (typeof td_match[3] != 'undefined') {
}
match_i = 4;

} else {
function autoEdit() {
match_i = 2;
setupPopups(function () {
}
if (mw.util.getParamValue('autoimpl') !== popupString('autoedit_version')) {
ps('>');
return false;
if (td_match[1] != '|+') {
}
td_line = td_match[match_i].split(td_match[1] == '|' ? '||' : /(?:\|\||!!)/);
if (
ps(parse_inline_nowiki(td_line.shift()));
mw.util.getParamValue('autowatchlist') &&
while (td_line.length) {
mw.util.getParamValue('actoken') === autoClickToken()
ll.unshift(td_match[1] + td_line.pop());
) {
}
pg.fn.modifyWatchlist(mw.util.getParamValue('title'), mw.util.getParamValue('action'));
} else {
}
ps(parse_inline_nowiki(td_match[match_i]));
if (!document.editform) {
}
return false;
var tc = 0
}
, td = [];
if (autoEdit.alreadyRan) {
while (remain()) {
return false;
td.push(sh());
}
if (compareLineStringOrReg('|')) {
autoEdit.alreadyRan = true;
if (!tc) {
var cmdString = mw.util.getParamValue('autoedit');
break;
if (cmdString) {
} else if (charAtPoint(1) == '}') {
try {
tc--;
var editbox = document.editform.wpTextbox1;
}
var cmdList = parseCmd(cmdString);
} else if (!tc && compareLineStringOrReg('!')) {
var input = editbox.value;
break;
var output = execCmds(input, cmdList);
} else if (compareLineStringOrReg('{|')) {
editbox.value = output;
tc++;
} catch (dang) {
}
return;
}
}
if (td.length) {
// wikEd user script compatibility
ps(Insta.convert(td));
if (typeof wikEdUseWikEd != 'undefined') {
}
if (wikEdUseWikEd === true) {
}
WikEdUpdateFrame();
function parse_pre() {
}
ps('<pre>');
}
do {
}
endl(parse_inline_nowiki(ll[0].substring(1)) + '\n');
setCheckbox('autominor', document.editform.wpMinoredit);
} while (remain() && compareLineStringOrReg(' '));
setCheckbox('autowatch', document.editform.wpWatchthis);
ps('</pre>');

}
var rvid = mw.util.getParamValue('autorv');
function parse_block_image() {
if (rvid) {
ps(parse_image(sh()));
var url =
}
pg.wiki.apiwikibase +
function parse_image(str) {
'?action=query&format=json&formatversion=2&prop=revisions&revids=' +
var tag = str.substring(str.indexOf(':') + 1, str.length - 2);
rvid;
var width;
startDownload(url, null, autoEdit2);
var attr = [], filename, caption = '';
} else {
var thumb = 0
autoEdit2();
, frame = 0
}
, center = 0;
});
var align = '';
}
if (tag.match(/\|/)) {

var nesting = 0;
function autoEdit2(d) {
var last_attr;
var summary = mw.util.getParamValue('autosummary');
for (var i = tag.length - 1; i > 0; i--) {
var summaryprompt = mw.util.getParamValue('autosummaryprompt');
if (tag.charAt(i) == '|' && !nesting) {
var summarynotice = '';
last_attr = tag.substr(i + 1);
if (d && d.data && mw.util.getParamValue('autorv')) {
tag = tag.substring(0, i);
var s = getRvSummary(summary, d.data);
break;
if (s === false) {
} else {
summaryprompt = true;
switch (tag.substr(i - 1, 2)) {
summarynotice = popupString(
case ']]':
'Failed to get revision information, please edit manually.\n\n'
nesting++;
);
i--;
summary = simplePrintf(summary, [
break;
mw.util.getParamValue('autorv'),
case '[[':
'(unknown)',
nesting--;
'(unknown)',
i--;
]);
}
} else {
}
summary = s;
}
}
attr = tag.split(/\s*\|\s*/);
}
attr.push(last_attr);
if (summaryprompt) {
filename = attr.shift();
var txt =
var w_match;
summarynotice + popupString('Enter a non-empty edit summary or press cancel to abort');
for (; attr.length; attr.shift()) {
var response = prompt(txt, summary);
w_match = attr[0].match(/^(\d*)(?:[px]*\d*)?px$/);
if (response) {
if (w_match) {
summary = response;
width = w_match[1];
} else {
} else {
return;
switch (attr[0]) {
}
case 'thumb':
}
case 'thumbnail':
if (summary) {
thumb = true;
document.editform.wpSummary.value = summary;
frame = true;
}
break;
// Attempt to avoid possible premature clicking of the save button
case 'frame':
// (maybe delays in updates to the DOM are to blame?? or a red herring)
frame = true;
setTimeout(autoEdit3, 100);
break;
}
case 'none':

case 'right':
function autoClickToken() {
case 'left':
return mw.user.sessionId();
center = false;
}
align = attr[0];

break;
function autoEdit3() {
case 'center':
if (mw.util.getParamValue('actoken') != autoClickToken()) {
center = true;
return;
align = 'none';
}
break;

default:
var btn = mw.util.getParamValue('autoclick');
if (attr.length == 1) {
if (btn) {
caption = attr[0];
if (document.editform && document.editform[btn]) {
}
var button = document.editform[btn];
}
var msg = tprintf(
}
'The %s button has been automatically clicked. Please wait for the next page to load.',
}
[button.value]
} else {
);
filename = tag;
bannerMessage(msg);
}
document.title = '(' + document.title + ')';
return '';
button.click();
}
} else {
function parse_inline_nowiki(str) {
alert(
var start, lastend = 0;
tprintf('Could not find button %s. Please check the settings in your javascript file.', [
var substart = 0, nestlev = 0, open, close, subloop;
btn,
var html = '';
])
while ((start = str.indexOf('<nowiki>', substart)) != -1) {
);
html += parse_inline_wiki(str.substring(lastend, start));
}
start += 8;
}
substart = start;
}
subloop = true;

do {
function bannerMessage(s) {
open = str.indexOf('<nowiki>', substart);
var headings = document.getElementsByTagName('h1');
close = str.indexOf('</nowiki>', substart);
if (headings) {
if (close <= open || open == -1) {
var div = document.createElement('div');
if (close == -1) {
div.innerHTML = '<font size=+1><b>' + pg.escapeQuotesHTML(s) + '</b></font>';
return html + html_entities(str.substr(start));
headings[0].parentNode.insertBefore(div, headings[0]);
}
}
substart = close + 9;
}
if (nestlev) {

nestlev--;
function getRvSummary(template, json) {
} else {
try {
lastend = substart;
var o = getJsObj(json);
html += html_entities(str.substring(start, lastend - 9));
var edit = anyChild(o.query.pages).revisions[0];
subloop = false;
var timestamp = edit.timestamp
}
.split(/[A-Z]/g)
} else {
.join(' ')
substart = open + 8;
.replace(/^ *| *$/g, '');
nestlev++;
return simplePrintf(template, [
}
edit.revid,
} while (subloop);
timestamp,
}
edit.userhidden ? '(hidden)' : edit.user,
return html + parse_inline_wiki(str.substr(lastend));
]);
}
} catch (badness) {
function parse_inline_images(str) {
return false;
var start, substart = 0, nestlev = 0;
}
var loop, close, open, wiki, html;
}
while ((start = str.indexOf('[[', substart)) != -1) {

if (str.substr(start + 2).match(RegExp('^(Image|File|' + Insta.conf.locale.image + '):', 'i'))) {
// ENDFILE: autoedit.js
loop = true;

substart = start;
// STARTFILE: downloader.js
do {
/**
substart += 2;
* @fileoverview
close = str.indexOf(']]', substart);
* {@link Downloader}, a xmlhttprequest wrapper, and helper functions.
open = str.indexOf('[[', substart);
*/
if (close <= open || open == -1) {

if (close == -1) {
/**
return str;
* Creates a new Downloader
}
* @constructor
substart = close;
* @class The Downloader class. Create a new instance of this class to download stuff.
if (nestlev) {
* @param {String} url The url to download. This can be omitted and supplied later.
nestlev--;
*/
} else {
function Downloader(url) {
wiki = str.substring(start, close + 2);
if (typeof XMLHttpRequest != 'undefined') {
html = parse_image(wiki);
this.http = new XMLHttpRequest();
str = str.replace(wiki, html);
}
substart = start + html.length;

loop = false;
/**
}
* The url to download
} else {
* @type {string}
substart = open;
*/
nestlev++;
this.url = url;
}

} while (loop);
/**
} else {
* A universally unique ID number
break;
* @type {number}
}
*/
}
this.id = null;
return str;

}
/**
function parse_inline_formatting(str) {
* Modification date, to be culled from the incoming headers
var em, st, i, li, o = '';
* @type Date
while ((i = str.indexOf("''", li)) + 1) {
* @private
o += str.substring(li, i);
*/
li = i + 2;
this.lastModified = null;
if (str.charAt(i + 2) == "'") {

li++;
/**
st = !st;
* What to do when the download completes successfully
o += st ? '<strong>' : '</strong>';
* @type {Function}
} else {
* @private
em = !em;
*/
o += em ? '<em>' : '</em>';
this.callbackFunction = null;
}

}
/**
return o + str.substr(li);
* What to do on failure
}
* @type {Function}
function parse_inline_wiki(str) {
* @private
str = parse_inline_images(str);
*/
str = str.replace(/<(?:)math>(.*?)<\/math>/gi, '');
this.onFailure = null;
var date = new Date();

var minutes = date.getUTCMinutes();
/**
if (minutes < 10) {
* Flag set on <code>abort</code>
minutes = '0' + minutes;
* @type {boolean}
}
*/
date = f('?:?, ? ? ? (UTC)', date.getUTCHours(), minutes, date.getUTCDate(), Insta.conf.locale.months[date.getUTCMonth()], date.getUTCFullYear());
this.aborted = false;
str = str.replace(/~{5}(?!~)/g, date).replace(/~{4}(?!~)/g, Insta.conf.user.name + ' ' + date).replace(/~{3}(?!~)/g, Insta.conf.user.name).replace(RegExp('\\[\\[:((?:' + Insta.conf.locale.category + '|Image|File|' + Insta.conf.locale.image + '|' + Insta.conf.wiki.interwiki + '):[^|]*?)\\]\\](\\w*)', 'gi'), function($0, $1, $2) {

return f("<a href='?'>?</a>", Insta.conf.paths.articles + htmlescape_attr($1), htmlescape_text($1) + htmlescape_text($2));
/**
}).replace(RegExp('\\[\\[(?:' + Insta.conf.locale.category + '|' + Insta.conf.wiki.interwiki + '):.*?\\]\\]', 'gi'), '').replace(RegExp('\\[\\[:((?:' + Insta.conf.locale.category + '|Image|File|' + Insta.conf.locale.image + '|' + Insta.conf.wiki.interwiki + '):.*?)\\|([^\\]]+?)\\]\\](\\w*)', 'gi'), function($0, $1, $2, $3) {
* HTTP method. See https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html for
return f("<a href='?'>?</a>", Insta.conf.paths.articles + htmlescape_attr($1), htmlescape_text($2) + htmlescape_text($3));
* possibilities.
}).replace(/\[\[(\/[^|]*?)\]\]/g, function($0, $1) {
* @type {string}
return f("<a href='?'>?</a>", Insta.conf.baseUrl + htmlescape_attr($1), htmlescape_text($1));
*/
}).replace(/\[\[(\/.*?)\|(.+?)\]\]/g, function($0, $1, $2) {
this.method = 'GET';
return f("<a href='?'>?</a>", Insta.conf.baseUrl + htmlescape_attr($1), htmlescape_text($2));
/**
}).replace(/\[\[([^[|]*?)\]\](\w*)/g, function($0, $1, $2) {
Async flag.
return f("<a href='?'>?</a>", Insta.conf.paths.articles + htmlescape_attr($1), htmlescape_text($1) + htmlescape_text($2));
@type {boolean}
}).replace(/\[\[([^[]*?)\|([^\]]+?)\]\](\w*)/g, function($0, $1, $2, $3) {
*/
return f("<a href='?'>?</a>", Insta.conf.paths.articles + htmlescape_attr($1), htmlescape_text($2) + htmlescape_text($3));
this.async = true;
}).replace(/\[\[([^\]]*?:)?(.*?)( *\(.*?\))?\|\]\]/g, function($0, $1, $2, $3) {
}
return f("<a href='?'>?</a>", Insta.conf.paths.articles + htmlescape_attr($1) + htmlescape_attr($2) + htmlescape_attr($3), htmlescape_text($2));

}).replace(/\[(https?|news|ftp|mailto|gopher|irc):(\/*)([^\]]*?) (.*?)\]/g, function($0, $1, $2, $3, $4) {
new Downloader();
return f("<a class='external' href='?:?'>?</a>", htmlescape_attr($1), htmlescape_attr($2) + htmlescape_attr($3), htmlescape_text($4));

}).replace(/\[http:\/\/(.*?)\]/g, function($0, $1) {
/** Submits the http request. */
return f("<a class='external' href='http://?'>[#]</a>", htmlescape_attr($1));
Downloader.prototype.send = function (x) {
}).replace(/\[(news|ftp|mailto|gopher|irc):(\/*)(.*?)\]/g, function($0, $1, $2, $3) {
if (!this.http) {
return f("<a class='external' href='?:?'>?:?</a>", htmlescape_attr($1), htmlescape_attr($2) + htmlescape_attr($3), htmlescape_text($1), htmlescape_text($2) + htmlescape_text($3));
return null;
}).replace(/(^| )(https?|news|ftp|mailto|gopher|irc):(\/*)([^ $]*[^.,!?;: $])/g, function($0, $1, $2, $3, $4) {
}
return f("?<a class='external' href='?:?'>?:?</a>", htmlescape_text($1), htmlescape_attr($2), htmlescape_attr($3) + htmlescape_attr($4), htmlescape_text($2), htmlescape_text($3) + htmlescape_text($4));
return this.http.send(x);
}).replace('__NOTOC__', '').replace('__NOINDEX__', '').replace('__INDEX__', '').replace('__NOEDITSECTION__', '');
};
return parse_inline_formatting(str);

}
/** Aborts the download, setting the <code>aborted</code> field to true. */
for (; remain(); ) {
Downloader.prototype.abort = function () {
if (compareLineStringOrReg(/^(={1,6})(.*)\1(.*)$/)) {
if (!this.http) {
p = 0;
return null;
endl(f('<h?>?</h?>?', r[1].length, parse_inline_nowiki(r[2]), r[1].length, r[3]));
}
} else if (compareLineStringOrReg(/^[*#:;]/)) {
this.aborted = true;
p = 0;
return this.http.abort();
parse_list();
};
} else if (compareLineStringOrReg(' ')) {

p = 0;
/** Returns the downloaded data. */
parse_pre();
Downloader.prototype.getData = function () {
} else if (compareLineStringOrReg('{|')) {
if (!this.http) {
p = 0;
return null;
parse_table();
}
} else if (compareLineStringOrReg(/^----+$/)) {
return this.http.responseText;
p = 0;
};
endl('<hr />');

} else if (compareLineStringOrReg(Insta.BLOCK_IMAGE)) {
/** Prepares the download. */
p = 0;
Downloader.prototype.setTarget = function () {
parse_block_image();
if (!this.http) {
} else {
return null;
if (compareLineString('')) {
}
p = remain() > 1 && ll[1] === '';
this.http.open(this.method, this.url, this.async);
if (p) {
this.http.setRequestHeader('Api-User-Agent', pg.api.userAgent);
endl('<p><br>');
};
}

} else {
/** Gets the state of the download. */
if (!p) {
Downloader.prototype.getReadyState = function () {
ps('<p>');
if (!this.http) {
p = 1;
return null;
}
}
ps(parse_inline_nowiki(ll[0]) + ' ');
return this.http.readyState;
}
};
sh();

}
pg.misc.downloadsInProgress = {};
}

return o;
/**
}
* Starts the download.
;
* Note that setTarget {@link Downloader#setTarget} must be run first
function wiki2html(txt, baseurl) {
*/
Insta.conf.baseUrl = baseurl;
Downloader.prototype.start = function () {
return Insta.convert(txt);
if (!this.http) {
}
return;
function popupFilterPageSize(data) {
}
return formatBytes(data.length);
pg.misc.downloadsInProgress[this.id] = this;
}
this.http.send(null);
function popupFilterCountLinks(data) {
};
var num = countLinks(data);

return String(num) + '&nbsp;' + (num != 1 ? popupString('wikiLinks') : popupString('wikiLink'));
/**
}
* Gets the 'Last-Modified' date from the download headers.
function popupFilterCountImages(data) {
* Should be run after the download completes.
var num = countImages(data);
* Returns <code>null</code> on failure.
return String(num) + '&nbsp;' + (num != 1 ? popupString('images') : popupString('image'));
* @return {Date}
}
*/
function popupFilterCountCategories(data) {
Downloader.prototype.getLastModifiedDate = function () {
var num = countCategories(data);
if (!this.http) {
return (String(num) + '&nbsp;' + (num != 1 ? popupString('categories') : popupString('category')));
return null;
}
}
function popupFilterLastModified(data, download) {
var lastmod = download.lastModified;
var lastmod = null;
try {
var now = new Date();
lastmod = this.http.getResponseHeader('Last-Modified');
var age = now - lastmod;
} catch (err) {}
if (lastmod && getValueOf('popupLastModified')) {
if (lastmod) {
return tprintf('%s old', [formatAge(age)]).replace(RegExp(' ', 'g'), '&nbsp;');
return new Date(lastmod);
}
}
return '';
return null;
}
};
function popupFilterWikibaseItem(data, download) {

return download.wikibaseItem ? tprintf('<a href="%s">%s</a>', [download.wikibaseRepo.replace(/\$1/g, download.wikibaseItem), download.wikibaseItem, ]) : '';
/**
}
function formatAge(age) {
* Sets the callback function.
* @param {Function} f callback function, called as <code>f(this)</code> on success
var a = 0 + age
*/
, aa = a;
Downloader.prototype.setCallback = function (f) {
var seclen = 1000;
if (!this.http) {
var minlen = 60 * seclen;
return;
var hourlen = 60 * minlen;
}
var daylen = 24 * hourlen;
this.http.onreadystatechange = f;
var weeklen = 7 * daylen;
};
var numweeks = (a - (a % weeklen)) / weeklen;

a = a - numweeks * weeklen;
Downloader.prototype.getStatus = function () {
var sweeks = addunit(numweeks, 'week');
if (!this.http) {
var numdays = (a - (a % daylen)) / daylen;
return null;
a = a - numdays * daylen;
}
var sdays = addunit(numdays, 'day');
return this.http.status;
var numhours = (a - (a % hourlen)) / hourlen;
};
a = a - numhours * hourlen;

var shours = addunit(numhours, 'hour');
//////////////////////////////////////////////////
var nummins = (a - (a % minlen)) / minlen;
// helper functions
a = a - nummins * minlen;

var smins = addunit(nummins, 'minute');
/**
var numsecs = (a - (a % seclen)) / seclen;
* Creates a new {@link Downloader} and prepares it for action.
a = a - numsecs * seclen;
* @param {String} url The url to download
var ssecs = addunit(numsecs, 'second');
* @param {number} id The ID of the {@link Downloader} object
if (aa > 4 * weeklen) {
* @param {Function} callback The callback function invoked on success
return sweeks;
* @return {String/Downloader} the {@link Downloader} object created, or 'ohdear' if an unsupported browser
}
*/
if (aa > weeklen) {
function newDownload(url, id, callback, onfailure) {
return sweeks + ' ' + sdays;
var d = new Downloader(url);
}
if (aa > daylen) {
if (!d.http) {
return 'ohdear';
return sdays + ' ' + shours;
}
}
d.id = id;
if (aa > 6 * hourlen) {
d.setTarget();
return shours;
if (!onfailure) {
}
onfailure = 2;
if (aa > hourlen) {
}
return shours + ' ' + smins;
var f = function () {
}
if (d.getReadyState() == 4) {
if (aa > 10 * minlen) {
delete pg.misc.downloadsInProgress[this.id];
return smins;
try {
}
if (d.getStatus() == 200) {
if (aa > minlen) {
d.data = d.getData();
return smins + ' ' + ssecs;
d.lastModified = d.getLastModifiedDate();
}
callback(d);
return ssecs;
} else if (typeof onfailure == typeof 1) {
}
if (onfailure > 0) {
function addunit(num, str) {
// retry
return String(num) + ' ' + (num != 1 ? popupString(str + 's') : popupString(str));
newDownload(url, id, callback, onfailure - 1);
}
}
function runPopupFilters(list, data, download) {
} else if (typeof onfailure === 'function') {
var ret = [];
onfailure(d, url, id, callback);
for (var i = 0; i < list.length; ++i) {
}
if (list[i] && typeof list[i] == 'function') {
} catch (somerr) {
var s = list[i](data, download, download.owner.article);
/* ignore it */
if (s) {
}
ret.push(s);
}
}
};
}
d.setCallback(f);
}
return ret;
return d;
}
}
/**
function getPageInfo(data, download) {
* Simulates a download from cached data.
if (!data || data.length === 0) {
* The supplied data is put into a {@link Downloader} as if it had downloaded it.
return popupString('Empty page');
* @param {String} url The url.
}
* @param {number} id The ID.
var popupFilters = getValueOf('popupFilters') || [];
* @param {Function} callback The callback, which is invoked immediately as <code>callback(d)</code>,
var extraPopupFilters = getValueOf('extraPopupFilters') || [];
* where <code>d</code> is the new {@link Downloader}.
var pageInfoArray = runPopupFilters(popupFilters.concat(extraPopupFilters), data, download);
* @param {String} data The (cached) data.
var pageInfo = pageInfoArray.join(', ');
* @param {Date} lastModified The (cached) last modified date.
if (pageInfo !== '') {
*/
pageInfo = upcaseFirst(pageInfo);
function fakeDownload(url, id, callback, data, lastModified, owner) {
}
var d = newDownload(url, callback);
return pageInfo;
d.owner = owner;
}
d.id = id;
function countLinks(wikiText) {
d.data = data;
return wikiText.split('[[').length - 1;
d.lastModified = lastModified;
}
return callback(d);
function countImages(wikiText) {
}
return (wikiText.parenSplit(pg.re.image).length - 1) / (pg.re.imageBracketCount + 1);

}
/**
function countCategories(wikiText) {
* Starts a download.
return (wikiText.parenSplit(pg.re.category).length - 1) / (pg.re.categoryBracketCount + 1);
* @param {String} url The url to download
}
* @param {number} id The ID of the {@link Downloader} object
function popupFilterStubDetect(data, download, article) {
* @param {Function} callback The callback function invoked on success
var counts = stubCount(data, article);
* @return {String/Downloader} the {@link Downloader} object created, or 'ohdear' if an unsupported browser
if (counts.real) {
*/
return popupString('stub');
function startDownload(url, id, callback) {
}
var d = newDownload(url, id, callback);
if (counts.sect) {
if (typeof d == typeof '') {
return popupString('section stub');
return d;
}
}
return '';
d.start();
}
return d;
function popupFilterDisambigDetect(data, download, article) {
}
if (!getValueOf('popupAllDabsStubs') && article.namespace()) {

return '';
/**
}
* Aborts all downloads which have been started.
return isDisambig(data, article) ? popupString('disambig') : '';
*/
}
function formatBytes(num) {
function abortAllDownloads() {
for (var x in pg.misc.downloadsInProgress) {
return num > 949 ? Math.round(num / 100) / 10 + popupString('kB') : num + '&nbsp;' + popupString('bytes');
try {
}
pg.misc.downloadsInProgress[x].aborted = true;
function Stringwrapper() {
pg.misc.downloadsInProgress[x].abort();
this.indexOf = function(x) {
delete pg.misc.downloadsInProgress[x];
return this.toString().indexOf(x);
} catch (e) {}
}
}
;
}
this.toString = function() {
// ENDFILE: downloader.js
return this.value;

}
// STARTFILE: livepreview.js
;
// TODO: location is often not correct (eg relative links in previews)
this.parenSplit = function(x) {
// NOTE: removed md5 and image and math parsing. was broken, lots of bytes.
return this.toString().parenSplit(x);
/**
}
* InstaView - a Mediawiki to HTML converter in JavaScript
;
* Version 0.6.1
this.substring = function(x, y) {
* Copyright (C) Pedro Fayolle 2005-2006
if (typeof y == 'undefined') {
* https://en.wikipedia.org/wiki/User:Pilaf
return this.toString().substring(x);
* Distributed under the BSD license
}
*
return this.toString().substring(x, y);
* Changelog:
}
*
;
* 0.6.1
this.split = function(x) {
* - Fixed problem caused by \r characters
return this.toString().split(x);
* - Improved inline formatting parser
}
*
;
* 0.6
this.replace = function(x, y) {
* - Changed name to InstaView
return this.toString().replace(x, y);
* - Some major code reorganizations and factored out some common functions
}
* - Handled conversion of relative links (i.e. [[/foo]])
;
* - Fixed misrendering of adjacent definition list items
}
* - Fixed bug in table headings handling
function Title(val) {
* - Changed date format in signatures to reflect Mediawiki's
this.value = null;
* - Fixed handling of [[:Image:...]]
this.anchor = '';
* - Updated MD5 function (hopefully it will work with UTF-8)
this.setUtf(val);
* - Fixed bug in handling of links inside images
}
*
Title.prototype = new Stringwrapper();
* To do:
Title.prototype.toString = function(omitAnchor) {
* - Better support for math tags
return this.value + (!omitAnchor && this.anchor ? '#' + this.anchorString() : '');
* - Full support for <nowiki>
}
* - Parser-based (as opposed to RegExp-based) inline wikicode handling (make it one-pass and
;
* bullet-proof)
Title.prototype.anchorString = function() {
* - Support for templates (through AJAX)
if (!this.anchor) {
* - Support for coloured links (AJAX)
return '';
*/
}

var split = this.anchor.parenSplit(/((?:[.][0-9A-F]{2})+)/);
var Insta = {};
var len = split.length;

var value;
function setupLivePreview() {
for (var j = 1; j < len; j += 2) {
// options
value = split[j].split('.').join('%');
Insta.conf = {
try {
baseUrl: '',
value = decodeURIComponent(value);

} catch (e) {}
user: {},
split[j] = value.split('_').join(' ');

}
wiki: {
return split.join('');
lang: pg.wiki.lang,
}
interwiki: pg.wiki.interwiki,
;
default_thumb_width: 180,
Title.prototype.urlAnchor = function() {
},
var split = this.anchor.parenSplit('/((?:[%][0-9A-F]{2})+)/');

var len = split.length;
paths: {
for (var j = 1; j < len; j += 2) {
articles: pg.wiki.articlePath + '/',
split[j] = split[j].split('%').join('.');
// Only used for Insta previews with images. (not in popups)
}
math: '/math/',
return split.join('');
images: '//upload.wikimedia.org/wikipedia/en/', // FIXME getImageUrlStart(pg.wiki.hostname),
}
images_fallback: '//upload.wikimedia.org/wikipedia/commons/',
;
},
Title.prototype.anchorFromUtf = function(str) {

this.anchor = encodeURIComponent(str.split(' ').join('_')).split('%3A').join(':').split("'").join('%27').split('%').join('.');
locale: {
}
user: mw.config.get('wgFormattedNamespaces')[pg.nsUserId],
;
image: mw.config.get('wgFormattedNamespaces')[pg.nsImageId],
Title.fromURL = function(h) {
category: mw.config.get('wgFormattedNamespaces')[pg.nsCategoryId],
return new Title().fromURL(h);
// shouldn't be used in popup previews, i think
}
months: [
;
'Jan',
Title.prototype.fromURL = function(h) {
'Feb',
if (typeof h != 'string') {
'Mar',
this.value = null;
'Apr',
return this;
'May',
}
'Jun',
var splitted = h.split('?');
'Jul',
splitted[0] = splitted[0].split('&').join('%26');
'Aug',
h = splitted.join('?');
'Sep',
var contribs = pg.re.contribs.exec(h);
'Oct',
if (contribs) {
'Nov',
if (contribs[1] == 'title=') {
'Dec',
contribs[3] = contribs[3].split('+').join(' ');
],
}
},
var u = new Title(contribs[3]);
};
this.setUtf(this.decodeNasties(mw.config.get('wgFormattedNamespaces')[pg.nsUserId] + ':' + u.stripNamespace()));

return this;
// options with default values or backreferences
}
Insta.conf.user.name = Insta.conf.user.name || 'Wikipedian';
var email = pg.re.email.exec(h);
Insta.conf.user.signature =
if (email) {
'[[' +
this.setUtf(this.decodeNasties(mw.config.get('wgFormattedNamespaces')[pg.nsUserId] + ':' + new Title(email[3]).stripNamespace()));
Insta.conf.locale.user +
return this;
':' +
}
Insta.conf.user.name +
var backlinks = pg.re.backlinks.exec(h);
'|' +
if (backlinks) {
Insta.conf.user.name +
this.setUtf(this.decodeNasties(new Title(backlinks[3])));
']]';
return this;
//Insta.conf.paths.images = '//upload.wikimedia.org/wikipedia/' + Insta.conf.wiki.lang + '/';
}

var specialdiff = pg.re.specialdiff.exec(h);
// define constants
if (specialdiff) {
Insta.BLOCK_IMAGE = new RegExp(
this.setUtf(this.decodeNasties(new Title(mw.config.get('wgFormattedNamespaces')[pg.nsSpecialId] + ':Diff')));
'^\\[\\[(?:File|Image|' +
return this;
Insta.conf.locale.image +
}
'):.*?\\|.*?(?:frame|thumbnail|thumb|none|right|left|center)',
var m = pg.re.main.exec(h);
'i'
if (m === null) {
);
this.value = null;
}
} else {

var fromBotInterface = /[?](.+[&])?title=/.test(h);
Insta.dump = function (from, to) {
if (fromBotInterface) {
if (typeof from == 'string') {
m[2] = m[2].split('+').join('_');
from = document.getElementById(from);
}
}
var extracted = m[2] + (m[3] ? '#' + m[3] : '');
if (typeof to == 'string') {
if (pg.flag.isSafari && /%25[0-9A-Fa-f]{2}/.test(extracted)) {
to = document.getElementById(to);
this.setUtf(decodeURIComponent(unescape(extracted)));
}
} else {
to.innerHTML = this.convert(from.value);
this.setUtf(this.decodeNasties(extracted));
};
}

}
Insta.convert = function (wiki) {
return this;
var ll = typeof wiki == 'string' ? wiki.replace(/\r/g, '').split(/\n/) : wiki, // lines of wikicode
}
o = '', // output
;
p = 0, // para flag
Title.prototype.decodeNasties = function(txt) {
r; // result of passing a regexp to compareLineStringOrReg()
try {

var ret = decodeURI(this.decodeEscapes(txt));
// some shorthands
ret = ret.replace(/[_ ]*$/, '');
function remain() {
return ret;
return ll.length;
} catch (e) {
}
return txt;
function sh() {
}
return ll.shift();
}
} // shift
;
function ps(s) {
Title.prototype.decodeEscapes = function(txt) {
o += s;
var split = txt.parenSplit(/((?:[%][0-9A-Fa-f]{2})+)/);
} // push
var len = split.length;

if (len === 1) {
// similar to C's printf, uses ? as placeholders, ?? to escape question marks
return split[0].replace(/%(?![0-9a-fA-F][0-9a-fA-F])/g, '%25');
function f() {
}
var i = 1,
for (var i = 1; i < len; i = i + 2) {
a = arguments,
split[i] = decodeURIComponent(split[i]);
f = a[0],
}
o = '',
return split.join('');
c,
}
p;
;
for (; i < a.length; i++) {
Title.fromAnchor = function(a) {
if ((p = f.indexOf('?')) + 1) {
return new Title().fromAnchor(a);
// allow character escaping
}
;
i -= c = f.charAt(p + 1) == '?' ? 1 : 0;
o += f.substring(0, p) + (c ? '?' : a[i]);
Title.prototype.fromAnchor = function(a) {
f = f.substr(p + 1 + c);
if (!a) {
} else {
this.value = null;
break;
return this;
}
}
}
return this.fromURL(a.href);
return o + f;
}
}
;

Title.fromWikiText = function(txt) {
function html_entities(s) {
return new Title().fromWikiText(txt);
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
}
;

Title.prototype.fromWikiText = function(txt) {
// Wiki text parsing to html is a nightmare.
txt = myDecodeURI(txt);
// The below functions deliberately don't escape the ampersand since this would make it more
this.setUtf(txt);
// difficult, and we don't absolutely need to for how we need it. This means that any
return this;
// unescaped ampersands in wikitext will remain unescaped and can cause invalid HTML.
}
// Browsers should all be able to handle it though. We also escape significant wikimarkup
;
// characters to prevent further matching on the processed text.
Title.prototype.hintValue = function() {
function htmlescape_text(s) {
if (!this.value) {
return '';
return s
.replace(/</g, '&lt;')
}
.replace(/>/g, '&gt;')
return safeDecodeURI(this.value);
.replace(/:/g, '&#58;')
}
.replace(/\[/g, '&#91;')
;
.replace(/]/g, '&#93;');
Title.prototype.toUserName = function(withNs) {
}
if (this.namespaceId() != pg.nsUserId && this.namespaceId() != pg.nsUsertalkId) {
function htmlescape_attr(s) {
this.value = null;
return htmlescape_text(s).replace(/'/g, '&#39;').replace(/"/g, '&quot;');
return;
}
}

this.value = (withNs ? mw.config.get('wgFormattedNamespaces')[pg.nsUserId] + ':' : '') + this.stripNamespace().split('/')[0];
// return the first non matching character position between two strings
}
function str_imatch(a, b) {
;
for (var i = 0, l = Math.min(a.length, b.length); i < l; i++) {
Title.prototype.userName = function(withNs) {
if (a.charAt(i) != b.charAt(i)) {
var t = new Title(this.value);
break;
t.toUserName(withNs);
}
if (t.value) {
}
return t;
return i;
}
}
return null;

}
// compare current line against a string or regexp
;
// if passed a string it will compare only the first string.length characters
Title.prototype.toTalkPage = function() {
// if passed a regexp the result is stored in r
if (this.value === null) {
function compareLineStringOrReg(c) {
return null;
return typeof c == 'string'
}
? ll[0] && ll[0].substr(0, c.length) == c
var namespaceId = this.namespaceId();
: (r = ll[0] && ll[0].match(c));
if (namespaceId >= 0 && namespaceId % 2 === 0) {
}
var localizedNamespace = mw.config.get('wgFormattedNamespaces')[namespaceId + 1];

if (typeof localizedNamespace !== 'undefined') {
function compareLineString(c) {
if (localizedNamespace === '') {
return ll[0] == c;
this.value = this.stripNamespace();
} // compare current line against a string
} else {
function charAtPoint(p) {
this.value = localizedNamespace.split(' ').join('_') + ':' + this.stripNamespace();
return ll[0].charAt(p);
}
} // return char at pos p
return this.value;

}
function endl(s) {
}
ps(s);
this.value = null;
sh();
return null;
}
}

;
function parse_list() {
Title.prototype.namespace = function() {
var prev = '';
return mw.config.get('wgFormattedNamespaces')[this.namespaceId()];

}
while (remain() && compareLineStringOrReg(/^([*#:;]+)(.*)$/)) {
;
var l_match = r;
Title.prototype.namespaceId = function() {

var n = this.value.indexOf(':');
sh();
if (n < 0) {

return 0;
var ipos = str_imatch(prev, l_match[1]);
}

var namespaceId = mw.config.get('wgNamespaceIds')[this.value.substring(0, n).split(' ').join('_').toLowerCase()];
// close uncontinued lists
if (typeof namespaceId == 'undefined') {
for (var prevPos = prev.length - 1; prevPos >= ipos; prevPos--) {
return 0;
var pi = prev.charAt(prevPos);
}

return namespaceId;
if (pi == '*') {
}
ps('</ul>');
;
} else if (pi == '#') {
Title.prototype.talkPage = function() {
ps('</ol>');
var t = new Title(this.value);
}
t.toTalkPage();
if (t.value) {
// close a dl only if the new item is not a dl item (:, ; or empty)
else if ($.inArray(l_match[1].charAt(prevPos), ['', '*', '#'])) {
return t;
ps('</dl>');
}
}
return null;
}
}

;
// open new lists
Title.prototype.isTalkPage = function() {
for (var matchPos = ipos; matchPos < l_match[1].length; matchPos++) {
if (this.talkPage() === null) {
var li = l_match[1].charAt(matchPos);
return true;

}
if (li == '*') {
return false;
ps('<ul>');
}
} else if (li == '#') {
;
ps('<ol>');
Title.prototype.toArticleFromTalkPage = function() {
}
if (this.value === null) {
return null;
// open a new dl only if the prev item is not a dl item (:, ; or empty)
else if ($.inArray(prev.charAt(matchPos), ['', '*', '#'])) {
}
ps('<dl>');
var namespaceId = this.namespaceId();
}
if (namespaceId >= 0 && namespaceId % 2 == 1) {
}
var localizedNamespace = mw.config.get('wgFormattedNamespaces')[namespaceId - 1];

if (typeof localizedNamespace !== 'undefined') {
switch (l_match[1].charAt(l_match[1].length - 1)) {
if (localizedNamespace === '') {
case '*':
this.value = this.stripNamespace();
case '#':
} else {
ps('<li>' + parse_inline_nowiki(l_match[2]));
this.value = localizedNamespace.split(' ').join('_') + ':' + this.stripNamespace();
break;
}

return this.value;
case ';':
}
ps('<dt>');
}

this.value = null;
var dt_match = l_match[2].match(/(.*?)(:.*?)$/);
return null;

}
// handle ;dt :dd format
;
if (dt_match) {
Title.prototype.articleFromTalkPage = function() {
ps(parse_inline_nowiki(dt_match[1]));
var t = new Title(this.value);
ll.unshift(dt_match[2]);
t.toArticleFromTalkPage();
} else {
if (t.value) {
ps(parse_inline_nowiki(l_match[2]));
return t;
}
}
break;
return null;

}
case ':':
;
ps('<dd>' + parse_inline_nowiki(l_match[2]));
Title.prototype.articleFromTalkOrArticle = function() {
}
var t = new Title(this.value);

if (t.toArticleFromTalkPage()) {
prev = l_match[1];
return t;
}
}

return this;
// close remaining lists
}
;
for (var i = prev.length - 1; i >= 0; i--) {
ps(f('</?>', prev.charAt(i) == '*' ? 'ul' : prev.charAt(i) == '#' ? 'ol' : 'dl'));
Title.prototype.isIpUser = function() {
}
return pg.re.ipUser.test(this.userName());
}
}

;
function parse_table() {
Title.prototype.stripNamespace = function() {
endl(f('<table>', compareLineStringOrReg(/^\{\|( .*)$/) ? r[1] : ''));
var n = this.value.indexOf(':');

if (n < 0) {
for (; remain(); ) {
return this.value;
if (compareLineStringOrReg('|')) {
}
switch (charAtPoint(1)) {
var namespaceId = this.namespaceId();
case '}':
if (namespaceId === pg.nsMainspaceId) {
endl('</table>');
return this.value;
return;
}
case '-':
return this.value.substring(n + 1);
endl(f('<tr>', compareLineStringOrReg(/\|-*(.*)/)[1]));
}
break;
;
default:
Title.prototype.setUtf = function(value) {
parse_table_data();
if (!value) {
}
this.value = '';
} else if (compareLineStringOrReg('!')) {
return;
parse_table_data();
}
} else {
var anch = value.indexOf('#');
sh();
if (anch < 0) {
}
this.value = value.split('_').join(' ');
}
this.anchor = '';
}
return;

}
function parse_table_data() {
this.value = value.substring(0, anch).split('_').join(' ');
var td_line, match_i;
this.anchor = value.substring(anch + 1);

this.ns = null;
// 1: "|+", '|' or '+'
}
// 2: ??
;
// 3: attributes ??
Title.prototype.setUrl = function(urlfrag) {
// TODO: finish commenting this regexp
var anch = urlfrag.indexOf('#');
var td_match = sh().match(/^(\|\+|\||!)((?:([^[|]*?)\|(?!\|))?(.*))$/);
this.value = safeDecodeURI(urlfrag.substring(0, anch));

this.anchor = this.value.substring(anch + 1);
if (td_match[1] == '|+') {
}
ps('<caption');
;
} else {
Title.prototype.append = function(x) {
ps('<t' + (td_match[1] == '|' ? 'd' : 'h'));
this.setUtf(this.value + x);
}
}

;
if (typeof td_match[3] != 'undefined') {
Title.prototype.urlString = function(x) {
//ps(' ' + td_match[3])
if (!x) {
match_i = 4;
x = {};
} else {
}
match_i = 2;
var v = this.toString(true);
}
if (!x.omitAnchor && this.anchor) {

v += '#' + this.urlAnchor();
ps('>');
}

if (!x.keepSpaces) {
if (td_match[1] != '|+') {
v = v.split(' ').join('_');
// use || or !! as a cell separator depending on context
}
// NOTE: when split() is passed a regexp make sure to use non-capturing brackets
return encodeURI(v).split('&').join('%26').split('?').join('%3F').split('+').join('%2B');
td_line = td_match[match_i].split(td_match[1] == '|' ? '||' : /(?:\|\||!!)/);
}

;
ps(parse_inline_nowiki(td_line.shift()));
Title.prototype.removeAnchor = function() {

return new Title(this.toString(true));
while (td_line.length) {
}
ll.unshift(td_match[1] + td_line.pop());
;
}
Title.prototype.toUrl = function() {
} else {
return pg.wiki.titlebase + this.urlString();
ps(parse_inline_nowiki(td_match[match_i]));
}
}
;

function parseParams(url) {
var tc = 0,
var specialDiff = pg.re.specialdiff.exec(url);
td = [];
if (specialDiff) {

var split = specialDiff[1].split('/');
while (remain()) {
if (split.length == 1) {
td.push(sh());
return {
if (compareLineStringOrReg('|')) {
oldid: split[0],
if (!tc) {
diff: 'prev'
break;
};
}
} else if (split.length == 2) {
// we're at the outer-most level (no nested tables), skip to td parse
return {
else if (charAtPoint(1) == '}') {
oldid: split[0],
tc--;
diff: split[1]
}
};
} else if (!tc && compareLineStringOrReg('!')) {
}
break;
}
} else if (compareLineStringOrReg('{|')) {
var ret = {};
tc++;
if (url.indexOf('?') == -1) {
}
return ret;
}
}

url = url.split('#')[0];
if (td.length) {
var s = url.split('?').slice(1).join();
ps(Insta.convert(td));
var t = s.split('&');
}
for (var i = 0; i < t.length; ++i) {
}
var z = t[i].split('=');

z.push(null);
function parse_pre() {
ret[z[0]] = z[1];
ps('<pre>');
}
do {
if (ret.diff && typeof ret.oldid === 'undefined') {
endl(parse_inline_nowiki(ll[0].substring(1)) + '\n');
ret.oldid = 'prev';
} while (remain() && compareLineStringOrReg(' '));
}
ps('</pre>');
if (ret.oldid && (ret.oldid === 'prev' || ret.oldid === 'next' || ret.oldid === 'cur')) {
}
var helper = ret.diff;

ret.diff = ret.oldid;
function parse_block_image() {
ret.oldid = helper;
ps(parse_image(sh()));
}
}
return ret;

}
function myDecodeURI(str) {
function parse_image(str) {
// get what's in between "[[Image:" and "]]"
var ret;
var tag = str.substring(str.indexOf(':') + 1, str.length - 2);
try {
var width;
ret = decodeURI(str.toString());
var attr = [],
} catch (summat) {
filename,
return str;
caption = '';
}
var thumb = 0,
for (var i = 0; i < pg.misc.decodeExtras.length; ++i) {
frame = 0,
var from = pg.misc.decodeExtras[i].from;
center = 0;
var to = pg.misc.decodeExtras[i].to;
var align = '';
ret = ret.split(from).join(to);

}
if (tag.match(/\|/)) {
return ret;
// manage nested links
}
var nesting = 0;
function safeDecodeURI(str) {
var last_attr;
var ret = myDecodeURI(str);
for (var i = tag.length - 1; i > 0; i--) {
return ret || str;
if (tag.charAt(i) == '|' && !nesting) {
}
last_attr = tag.substr(i + 1);
function isDisambig(data, article) {
tag = tag.substring(0, i);
if (!getValueOf('popupAllDabsStubs') && article.namespace()) {
break;
return false;
} else {
}
switch (tag.substr(i - 1, 2)) {
return !article.isTalkPage() && pg.re.disambig.test(data);
case ']]':
}
nesting++;
function stubCount(data, article) {
i--;
if (!getValueOf('popupAllDabsStubs') && article.namespace()) {
break;
return false;
case '[[':
}
nesting--;
var sectStub = 0;
i--;
var realStub = 0;
}
if (pg.re.stub.test(data)) {
}
var s = data.parenSplit(pg.re.stub);
}
for (var i = 1; i < s.length; i = i + 2) {

if (s[i]) {
attr = tag.split(/\s*\|\s*/);
++sectStub;
attr.push(last_attr);
} else {
filename = attr.shift();
++realStub;

}
var w_match;
}

}
for (; attr.length; attr.shift()) {
return {
w_match = attr[0].match(/^(\d*)(?:[px]*\d*)?px$/);
real: realStub,
if (w_match) {
sect: sectStub
width = w_match[1];
};
} else {
}
switch (attr[0]) {
function isValidImageName(str) {
case 'thumb':
return str.indexOf('{') == -1;
case 'thumbnail':
}
thumb = true;
function isInStrippableNamespace(article) {
frame = true;
return article.namespaceId() !== 0;
break;
}
case 'frame':
function isInMainNamespace(article) {
frame = true;
return article.namespaceId() === 0;
break;
}
case 'none':
function anchorContainsImage(a) {
case 'right':
if (a === null) {
case 'left':
return false;
center = false;
}
align = attr[0];
var kids = a.childNodes;
break;
for (var i = 0; i < kids.length; ++i) {
case 'center':
if (kids[i].nodeName == 'IMG') {
center = true;
return true;
align = 'none';
}
break;
}
default:
return false;
if (attr.length == 1) {
}
caption = attr[0];
function isPopupLink(a) {
}
if (!markNopopupSpanLinks.done) {
}
markNopopupSpanLinks();
}
}
}
if (a.inNopopupSpan) {
} else {
return false;
filename = tag;
}
}
if (a.onmousedown || a.getAttribute('nopopup')) {

return false;
return '';
}
}
var h = a.href;

if (h === document.location.href + '#') {
function parse_inline_nowiki(str) {
return false;
var start,
}
lastend = 0;
if (!pg.re.basenames.test(h)) {
var substart = 0,
return false;
nestlev = 0,
}
open,
if (!pg.re.urlNoPopup.test(h)) {
close,
return true;
subloop;
}
var html = '';
return ((pg.re.email.test(h) || pg.re.contribs.test(h) || pg.re.backlinks.test(h) || pg.re.specialdiff.test(h)) && h.indexOf('&limit=') == -1);

}
while ((start = str.indexOf('<nowiki>', substart)) != -1) {
function markNopopupSpanLinks() {
html += parse_inline_wiki(str.substring(lastend, start));
if (!getValueOf('popupOnlyArticleLinks')) {
start += 8;
fixVectorMenuPopups();
substart = start;
}
subloop = true;
var s = $('.nopopups').toArray();
do {
for (var i = 0; i < s.length; ++i) {
open = str.indexOf('<nowiki>', substart);
var as = s[i].getElementsByTagName('a');
close = str.indexOf('</nowiki>', substart);
for (var j = 0; j < as.length; ++j) {
if (close <= open || open == -1) {
as[j].inNopopupSpan = true;
if (close == -1) {
}
return html + html_entities(str.substr(start));
}
}
markNopopupSpanLinks.done = true;
substart = close + 9;
}
if (nestlev) {
function fixVectorMenuPopups() {
nestlev--;
$('nav.vector-menu h3:first a:first').prop('inNopopupSpan', true);
} else {
}
lastend = substart;
function getPageWithCaching(url, onComplete, owner) {
html += html_entities(str.substring(start, lastend - 9));
log('getPageWithCaching, url=' + url);
subloop = false;
var i = findInPageCache(url);
}
var d;
} else {
if (i > -1) {
substart = open + 8;
d = fakeDownload(url, owner.idNumber, onComplete, pg.cache.pages[i].data, pg.cache.pages[i].lastModified, owner);
nestlev++;
} else {
}
d = getPage(url, onComplete, owner);
} while (subloop);
if (d && owner && owner.addDownload) {
}
owner.addDownload(d);

d.owner = owner;
return html + parse_inline_wiki(str.substr(lastend));
}
}
}

}
function parse_inline_images(str) {
function getPage(url, onComplete, owner) {
var start,
log('getPage');
substart = 0,
var callback = function(d) {
nestlev = 0;
if (!d.aborted) {
var loop, close, open, wiki, html;
addPageToCache(d);

onComplete(d);
while ((start = str.indexOf('[[', substart)) != -1) {
}
if (
};
str.substr(start + 2).match(RegExp('^(Image|File|' + Insta.conf.locale.image + '):', 'i'))
return startDownload(url, owner.idNumber, callback);
) {
}
loop = true;
function findInPageCache(url) {
substart = start;
for (var i = 0; i < pg.cache.pages.length; ++i) {
do {
if (url == pg.cache.pages[i].url) {
substart += 2;
return i;
close = str.indexOf(']]', substart);
}
open = str.indexOf('[[', substart);
}
if (close <= open || open == -1) {
return -1;
if (close == -1) {
}
return str;
function addPageToCache(download) {
}
log('addPageToCache ' + download.url);
substart = close;
var page = {
if (nestlev) {
url: download.url,
nestlev--;
data: download.data,
} else {
lastModified: download.lastModified,
wiki = str.substring(start, close + 2);
};
html = parse_image(wiki);
return pg.cache.pages.push(page);
str = str.replace(wiki, html);
}
substart = start + html.length;
if (String('abc'.split(/(b)/)) != 'a,b,c') {
loop = false;
String.prototype.parenSplit = function(re) {
}
re = nonGlobalRegex(re);
} else {
var s = this;
substart = open;
var m = re.exec(s);
nestlev++;
var ret = [];
}
while (m && s) {
} while (loop);
for (var i = 0; i < m.length; ++i) {
} else {
if (typeof m[i] == 'undefined') {
break;
m[i] = '';
}
}
}
}

ret.push(s.substring(0, m.index));
return str;
ret = ret.concat(m.slice(1));
}
s = s.substring(m.index + m[0].length);

m = re.exec(s);
// the output of this function doesn't respect the FILO structure of HTML
}
// but since most browsers can handle it I'll save myself the hassle
ret.push(s);
function parse_inline_formatting(str) {
return ret;
var em,
}
st,
;
i,
} else {
li,
String.prototype.parenSplit = function(re) {
o = '';
return this.split(re);
while ((i = str.indexOf("''", li)) + 1) {
}
o += str.substring(li, i);
;
li = i + 2;
String.prototype.parenSplit.isNative = true;
if (str.charAt(i + 2) == "'") {
}
li++;
function nonGlobalRegex(re) {
st = !st;
var s = re.toString();
o += st ? '<strong>' : '</strong>';
var flags = '';
} else {
for (var j = s.length; s.charAt(j) != '/'; --j) {
em = !em;
if (s.charAt(j) != 'g') {
o += em ? '<em>' : '</em>';
flags += s.charAt(j);
}
}
}
}
return o + str.substr(li);
var t = s.substring(1, j);
}
return RegExp(t, flags);

}
function getJsObj(json) {
function parse_inline_wiki(str) {
str = parse_inline_images(str);
try {

var json_ret = JSON.parse(json);
// math
if (json_ret.warnings) {
str = str.replace(/<(?:)math>(.*?)<\/math>/gi, '');
for (var w = 0; w < json_ret.warnings.length; w++) {

if (json_ret.warnings[w]['*']) {
// Build a Mediawiki-formatted date string
log(json_ret.warnings[w]['*']);
var date = new Date();
} else {
var minutes = date.getUTCMinutes();
log(json_ret.warnings[w].warnings);
if (minutes < 10) {
}
minutes = '0' + minutes;
}
}
} else if (json_ret.error) {
date = f(
errlog(json_ret.error.code + ': ' + json_ret.error.info);
'?:?, ? ? ? (UTC)',
}
date.getUTCHours(),
return json_ret;
minutes,
} catch (someError) {
date.getUTCDate(),
errlog('Something went wrong with getJsObj, json=' + json);
Insta.conf.locale.months[date.getUTCMonth()],
return 1;
date.getUTCFullYear()
}
);
}

function anyChild(obj) {
// text formatting
for (var p in obj) {
str =
return obj[p];
str
}
// signatures
return null;
.replace(/~{5}(?!~)/g, date)
}
.replace(/~{4}(?!~)/g, Insta.conf.user.name + ' ' + date)
function upcaseFirst(str) {
.replace(/~{3}(?!~)/g, Insta.conf.user.name)
if (typeof str != typeof '' || str === '') {
// [[:Category:...]], [[:Image:...]], etc...
return '';
.replace(
}
RegExp(
return str.charAt(0).toUpperCase() + str.substring(1);
'\\[\\[:((?:' +
}
Insta.conf.locale.category +
function findInArray(arr, foo) {
'|Image|File|' +
if (!arr || !arr.length) {
Insta.conf.locale.image +
return -1;
'|' +
}
Insta.conf.wiki.interwiki +
var len = arr.length;
'):[^|]*?)\\]\\](\\w*)',
for (var i = 0; i < len; ++i) {
'gi'
if (arr[i] == foo) {
),
return i;
function ($0, $1, $2) {
}
return f(
}
"<a href='?'>?</a>",
return -1;
Insta.conf.paths.articles + htmlescape_attr($1),
}
htmlescape_text($1) + htmlescape_text($2)
function nextOne(array, value) {
);
var i = findInArray(array, value);
}
if (i < 0) {
)
return null;
// remove straight category and interwiki tags
}
.replace(
return array[i + 1];
RegExp(
}
'\\[\\[(?:' +
function literalizeRegex(str) {
Insta.conf.locale.category +
return mw.util.escapeRegExp(str);
'|' +
}
Insta.conf.wiki.interwiki +
String.prototype.entify = function() {
'):.*?\\]\\]',
return this.split('&').join('&amp;').split('<').join('&lt;').split('>').join('&gt;').split('"').join('&quot;');
'gi'
}
),
;
''
function removeNulls(val) {
)
return val !== null;
// [[:Category:...|Links]], [[:Image:...|Links]], etc...
}
.replace(
function joinPath(list) {
RegExp(
return list.filter(removeNulls).join('/');
'\\[\\[:((?:' +
}
Insta.conf.locale.category +
function simplePrintf(str, subs) {
'|Image|File|' +
if (!str || !subs) {
Insta.conf.locale.image +
return str;
'|' +
}
Insta.conf.wiki.interwiki +
var ret = [];
'):.*?)\\|([^\\]]+?)\\]\\](\\w*)',
var s = str.parenSplit(/(%s|\$[0-9]+)/);
'gi'
var i = 0;
),
do {
function ($0, $1, $2, $3) {
ret.push(s.shift());
return f(
if (!s.length) {
"<a href='?'>?</a>",
break;
Insta.conf.paths.articles + htmlescape_attr($1),
}
htmlescape_text($2) + htmlescape_text($3)
var cmd = s.shift();
);
if (cmd == '%s') {
}
if (i < subs.length) {
)
ret.push(subs[i]);
// [[/Relative links]]
} else {
.replace(/\[\[(\/[^|]*?)\]\]/g, function ($0, $1) {
ret.push(cmd);
return f(
}
"<a href='?'>?</a>",
++i;
Insta.conf.baseUrl + htmlescape_attr($1),
} else {
htmlescape_text($1)
var j = parseInt(cmd.replace('$', ''), 10) - 1;
);
if (j > -1 && j < subs.length) {
})
ret.push(subs[j]);
// [[/Replaced|Relative links]]
} else {
.replace(/\[\[(\/.*?)\|(.+?)\]\]/g, function ($0, $1, $2) {
ret.push(cmd);
return f(
}
"<a href='?'>?</a>",
}
Insta.conf.baseUrl + htmlescape_attr($1),
} while (s.length > 0);
htmlescape_text($2)
return ret.join('');
);
}
})
function isString(x) {
// [[Common links]]
return typeof x === 'string' || x instanceof String;
.replace(/\[\[([^[|]*?)\]\](\w*)/g, function ($0, $1, $2) {
}
return f(
function isNumber(x) {
"<a href='?'>?</a>",
return typeof x === 'number' || x instanceof Number;
Insta.conf.paths.articles + htmlescape_attr($1),
}
htmlescape_text($1) + htmlescape_text($2)
function isRegExp(x) {
);
return x instanceof RegExp;
})
}
// [[Replaced|Links]]
function isArray(x) {
.replace(/\[\[([^[]*?)\|([^\]]+?)\]\](\w*)/g, function ($0, $1, $2, $3) {
return x instanceof Array;
return f(
}
"<a href='?'>?</a>",
function isObject(x) {
Insta.conf.paths.articles + htmlescape_attr($1),
return x instanceof Object;
htmlescape_text($2) + htmlescape_text($3)
}
);
function isFunction(x) {
})
return !isRegExp(x) && (typeof x === 'function' || x instanceof Function);
// [[Stripped:Namespace|Namespace]]
}
.replace(/\[\[([^\]]*?:)?(.*?)( *\(.*?\))?\|\]\]/g, function ($0, $1, $2, $3) {
function repeatString(s, mult) {
return f(
var ret = '';
"<a href='?'>?</a>",
for (var i = 0; i < mult; ++i) {
Insta.conf.paths.articles +
ret += s;
htmlescape_attr($1) +
}
htmlescape_attr($2) +
return ret;
htmlescape_attr($3),
}
htmlescape_text($2)
function zeroFill(s, min) {
);
min = min || 2;
})
var t = s.toString();
// External links
return repeatString('0', min - t.length) + t;
.replace(
}
/\[(https?|news|ftp|mailto|gopher|irc):(\/*)([^\]]*?) (.*?)\]/g,
function map(f, o) {
function ($0, $1, $2, $3, $4) {
if (isArray(o)) {
return f(
return map_array(f, o);
"<a class='external' href='?:?'>?</a>",
}
htmlescape_attr($1),
return map_object(f, o);
htmlescape_attr($2) + htmlescape_attr($3),
}
htmlescape_text($4)
function map_array(f, o) {
);
var ret = [];
}
for (var i = 0; i < o.length; ++i) {
)
ret.push(f(o[i]));
.replace(/\[http:\/\/(.*?)\]/g, function ($0, $1) {
}
return f("<a class='external' href='http://?'>[#]</a>", htmlescape_attr($1));
return ret;
})
}
.replace(/\[(news|ftp|mailto|gopher|irc):(\/*)(.*?)\]/g, function ($0, $1, $2, $3) {
function map_object(f, o) {
return f(
var ret = {};
"<a class='external' href='?:?'>?:?</a>",
for (var i in o) {
htmlescape_attr($1),
ret[o] = f(o[i]);
htmlescape_attr($2) + htmlescape_attr($3),
}
htmlescape_text($1),
return ret;
htmlescape_text($2) + htmlescape_text($3)
}
);
pg.escapeQuotesHTML = function(text) {
})
return text.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
.replace(
}
/(^| )(https?|news|ftp|mailto|gopher|irc):(\/*)([^ $]*[^.,!?;: $])/g,
;
function ($0, $1, $2, $3, $4) {
pg.unescapeQuotesHTML = function(html) {
return f(
var txt = document.createElement('textarea');
"?<a class='external' href='?:?'>?:?</a>",
txt.innerHTML = html;
htmlescape_text($1),
return txt.value;
htmlescape_attr($2),
}
htmlescape_attr($3) + htmlescape_attr($4),
;
htmlescape_text($2),
function retargetDab(newTarget, oldTarget, friendlyCurrentArticleName, titleToEdit) {
htmlescape_text($3) + htmlescape_text($4)
log('retargetDab: newTarget=' + newTarget + ' oldTarget=' + oldTarget);
);
return changeLinkTargetLink({
}
newTarget: newTarget,
)
text: newTarget.split(' ').join('&nbsp;'),
.replace('__NOTOC__', '')
hint: tprintf('disambigHint', [newTarget]),
.replace('__NOINDEX__', '')
summary: simplePrintf(getValueOf('popupFixDabsSummary'), [friendlyCurrentArticleName, newTarget, ]),
.replace('__INDEX__', '')
clickButton: getValueOf('popupDabsAutoClick'),
.replace('__NOEDITSECTION__', '')
minor: true,
;
oldTarget: oldTarget,
return parse_inline_formatting(str);
watch: getValueOf('popupWatchDisambiggedPages'),
}
title: titleToEdit,

});
// begin parsing
}
for (; remain(); ) {
function listLinks(wikitext, oldTarget, titleToEdit) {
if (compareLineStringOrReg(/^(={1,6})(.*)\1(.*)$/)) {
var reg = RegExp('\\[\\[([^|]*?) *(\\||\\]\\])', 'gi');
p = 0;
var ret = [];
endl(f('<h?>?</h?>?', r[1].length, parse_inline_nowiki(r[2]), r[1].length, r[3]));
var splitted = wikitext.parenSplit(reg);
} else if (compareLineStringOrReg(/^[*#:;]/)) {
var omitRegex = RegExp('^[a-z]*:|^[Ss]pecial:|^[Ii]mage|^[Cc]ategory');
p = 0;
var friendlyCurrentArticleName = oldTarget.toString();
parse_list();
var wikPos = getValueOf('popupDabWiktionary');
} else if (compareLineStringOrReg(' ')) {
for (var i = 1; i < splitted.length; i = i + 3) {
p = 0;
if (typeof splitted[i] == typeof 'string' && splitted[i].length > 0 && !omitRegex.test(splitted[i])) {
parse_pre();
ret.push(retargetDab(splitted[i], oldTarget, friendlyCurrentArticleName, titleToEdit));
} else if (compareLineStringOrReg('{|')) {
}
p = 0;
}
parse_table();
ret = rmDupesFromSortedList(ret.sort());
} else if (compareLineStringOrReg(/^----+$/)) {
if (wikPos) {
p = 0;
var wikTarget = 'wiktionary:' + friendlyCurrentArticleName.replace(RegExp('^(.+)\\s+[(][^)]+[)]\\s*$'), '$1');
endl('<hr />');
var meth;
} else if (compareLineStringOrReg(Insta.BLOCK_IMAGE)) {
if (wikPos.toLowerCase() == 'first') {
p = 0;
meth = 'unshift';
parse_block_image();
} else {
} else {
meth = 'push';
// handle paragraphs
}
if (compareLineString('')) {
ret[meth](retargetDab(wikTarget, oldTarget, friendlyCurrentArticleName, titleToEdit));
p = remain() > 1 && ll[1] === '';
}
if (p) {
ret.push(changeLinkTargetLink({
endl('<p><br>');
newTarget: null,
}
text: popupString('remove this link').split(' ').join('&nbsp;'),
} else {
hint: popupString('remove all links to this disambig page from this article'),
if (!p) {
clickButton: getValueOf('popupDabsAutoClick'),
ps('<p>');
oldTarget: oldTarget,
p = 1;
summary: simplePrintf(getValueOf('popupRmDabLinkSummary'), [friendlyCurrentArticleName]),
}
watch: getValueOf('popupWatchDisambiggedPages'),
ps(parse_inline_nowiki(ll[0]) + ' ');
title: titleToEdit,
}
}));

return ret;
sh();
}
}
function rmDupesFromSortedList(list) {
}
var ret = [];

for (var i = 0; i < list.length; ++i) {
return o;
if (ret.length === 0 || list[i] != ret[ret.length - 1]) {
};
ret.push(list[i]);

}
function wiki2html(txt, baseurl) {
}
Insta.conf.baseUrl = baseurl;
return ret;
return Insta.convert(txt);
}
}
function makeFixDab(data, navpop) {
// ENDFILE: livepreview.js
var titleToEdit = navpop.parentPopup && navpop.parentPopup.article.toString();

var list = listLinks(data, navpop.originalArticle, titleToEdit);
// STARTFILE: pageinfo.js
if (list.length === 0) {
function popupFilterPageSize(data) {
log('listLinks returned empty list');
return formatBytes(data.length);
return null;
}
}

var html = '<hr />' + popupString('Click to disambiguate this link to:') + '<br>';
function popupFilterCountLinks(data) {
html += list.join(', ');
var num = countLinks(data);
return html;
return String(num) + '&nbsp;' + (num != 1 ? popupString('wikiLinks') : popupString('wikiLink'));
}
}
function makeFixDabs(wikiText, navpop) {

if (getValueOf('popupFixDabs') && isDisambig(wikiText, navpop.article) && Title.fromURL(location.href).namespaceId() != pg.nsSpecialId && navpop.article.talkPage()) {
function popupFilterCountImages(data) {
setPopupHTML(makeFixDab(wikiText, navpop), 'popupFixDab', navpop.idNumber);
var num = countImages(data);
}
return String(num) + '&nbsp;' + (num != 1 ? popupString('images') : popupString('image'));
}
}
function popupRedlinkHTML(article) {

return changeLinkTargetLink({
function popupFilterCountCategories(data) {
newTarget: null,
var num = countCategories(data);
text: popupString('remove this link').split(' ').join('&nbsp;'),
return (
hint: popupString('remove all links to this page from this article'),
String(num) + '&nbsp;' + (num != 1 ? popupString('categories') : popupString('category'))
clickButton: getValueOf('popupRedlinkAutoClick'),
);
oldTarget: article.toString(),
}
summary: simplePrintf(getValueOf('popupRedlinkSummary'), [article.toString()]),

});
function popupFilterLastModified(data, download) {
}
var lastmod = download.lastModified;
function setPopupHTML(str, elementId, popupId, onSuccess, append) {
var now = new Date();
if (typeof popupId === 'undefined') {
var age = now - lastmod;
popupId = pg.idNumber;
if (lastmod && getValueOf('popupLastModified')) {
}
return tprintf('%s old', [formatAge(age)]).replace(RegExp(' ', 'g'), '&nbsp;');
var popupElement = document.getElementById(elementId + popupId);
}
if (popupElement) {
return '';
if (!append) {
}
popupElement.innerHTML = '';

}
function popupFilterWikibaseItem(data, download) {
if (isString(str)) {
return download.wikibaseItem
popupElement.innerHTML += str;
? tprintf('<a href="%s">%s</a>', [
} else {
download.wikibaseRepo.replace(/\$1/g, download.wikibaseItem),
popupElement.appendChild(str);
download.wikibaseItem,
}
])
if (onSuccess) {
: '';
onSuccess();
}
}

setTimeout(checkPopupPosition, 100);
function formatAge(age) {
return true;
// coerce into a number
} else {
var a = 0 + age,
setTimeout(function() {
aa = a;
setPopupHTML(str, elementId, popupId, onSuccess);

}, 600);
var seclen = 1000;
}
var minlen = 60 * seclen;
return null;
var hourlen = 60 * minlen;
}
var daylen = 24 * hourlen;
function setPopupTrailer(str, id) {
var weeklen = 7 * daylen;
return setPopupHTML(str, 'popupData', id);

}
var numweeks = (a - (a % weeklen)) / weeklen;
function fillEmptySpans(args) {
a = a - numweeks * weeklen;
var redir = true;
var sweeks = addunit(numweeks, 'week');
var rcid;
var numdays = (a - (a % daylen)) / daylen;
if (typeof args != 'object' || typeof args.redir == 'undefined' || !args.redir) {
a = a - numdays * daylen;
redir = false;
var sdays = addunit(numdays, 'day');
}
var numhours = (a - (a % hourlen)) / hourlen;
var a = args.navpopup.parentAnchor;
a = a - numhours * hourlen;
var article, hint = null, oldid = null, params = {};
var shours = addunit(numhours, 'hour');
if (redir && typeof args.redirTarget == typeof {}) {
var nummins = (a - (a % minlen)) / minlen;
article = args.redirTarget;
a = a - nummins * minlen;
} else {
var smins = addunit(nummins, 'minute');
article = new Title().fromAnchor(a);
var numsecs = (a - (a % seclen)) / seclen;
hint = a.originalTitle || article.hintValue();
a = a - numsecs * seclen;
params = parseParams(a.href);
var ssecs = addunit(numsecs, 'second');
oldid = getValueOf('popupHistoricalLinks') ? params.oldid : null;

rcid = params.rcid;
if (aa > 4 * weeklen) {
}
return sweeks;
var x = {
}
article: article,
if (aa > weeklen) {
hint: hint,
return sweeks + ' ' + sdays;
oldid: oldid,
}
rcid: rcid,
if (aa > daylen) {
navpop: args.navpopup,
return sdays + ' ' + shours;
params: params,
}
};
if (aa > 6 * hourlen) {
var structure = pg.structures[getValueOf('popupStructure')];
return shours;
if (typeof structure != 'object') {
}
setPopupHTML('popupError', 'Unknown structure (this should never happen): ' + pg.option.popupStructure, args.navpopup.idNumber);
if (aa > hourlen) {
return;
return shours + ' ' + smins;
}
}
var spans = flatten(pg.misc.layout);
if (aa > 10 * minlen) {
var numspans = spans.length;
return smins;
var redirs = pg.misc.redirSpans;
}
for (var i = 0; i < numspans; ++i) {
if (aa > minlen) {
var found = redirs && redirs.indexOf(spans[i]) !== -1;
return smins + ' ' + ssecs;
if ((found && !redir) || (!found && redir)) {
}
continue;
return ssecs;
}
}
var structurefn = structure[spans[i]];

if (structurefn === undefined) {
function addunit(num, str) {
continue;
return String(num) + ' ' + (num != 1 ? popupString(str + 's') : popupString(str));
}
}
var setfn = setPopupHTML;

if (getValueOf('popupActiveNavlinks') && (spans[i].indexOf('popupTopLinks') === 0 || spans[i].indexOf('popupRedirTopLinks') === 0)) {
function runPopupFilters(list, data, download) {
setfn = setPopupTipsAndHTML;
var ret = [];
}
for (var i = 0; i < list.length; ++i) {
switch (typeof structurefn) {
case 'function':
if (list[i] && typeof list[i] == 'function') {
var s = list[i](data, download, download.owner.article);
log('running ' + spans[i] + '({article:' + x.article + ', hint:' + x.hint + ', oldid: ' + x.oldid + '})');
if (s) {
setfn(structurefn(x), spans[i], args.navpopup.idNumber);
ret.push(s);
break;
}
case 'string':
}
setfn(structurefn, spans[i], args.navpopup.idNumber);
}
break;
return ret;
default:
}
errlog('unknown thing with label ' + spans[i] + ' (span index was ' + i + ')');

break;
function getPageInfo(data, download) {
}
if (!data || data.length === 0) {
}
return popupString('Empty page');
}
}
function flatten(list, start) {

var ret = [];
var popupFilters = getValueOf('popupFilters') || [];
if (typeof start == 'undefined') {
var extraPopupFilters = getValueOf('extraPopupFilters') || [];
start = 0;
var pageInfoArray = runPopupFilters(popupFilters.concat(extraPopupFilters), data, download);
}

for (var i = start; i < list.length; ++i) {
var pageInfo = pageInfoArray.join(', ');
if (typeof list[i] == typeof []) {
if (pageInfo !== '') {
return ret.concat(flatten(list[i])).concat(flatten(list, i + 1));
pageInfo = upcaseFirst(pageInfo);
} else {
}
ret.push(list[i]);
return pageInfo;
}
}
}

return ret;
// this could be improved!
}
function popupHTML(a) {
function countLinks(wikiText) {
return wikiText.split('[[').length - 1;
getValueOf('popupStructure');
}
var structure = pg.structures[pg.option.popupStructure];

if (typeof structure != 'object') {
// if N = # matches, n = # brackets, then
pg.option.popupStructure = pg.optionDefault.popupStructure;
// String.parenSplit(regex) intersperses the N+1 split elements
return popupHTML(a);
// with Nn other elements. So total length is
}
// L= N+1 + Nn = N(n+1)+1. So N=(L-1)/(n+1).
if (typeof structure.popupLayout != 'function') {

return 'Bad layout';
function countImages(wikiText) {
}
return (wikiText.parenSplit(pg.re.image).length - 1) / (pg.re.imageBracketCount + 1);
pg.misc.layout = structure.popupLayout();
}
if (typeof structure.popupRedirSpans === 'function') {

pg.misc.redirSpans = structure.popupRedirSpans();
function countCategories(wikiText) {
} else {
return (wikiText.parenSplit(pg.re.category).length - 1) / (pg.re.categoryBracketCount + 1);
pg.misc.redirSpans = [];
}
}

return makeEmptySpans(pg.misc.layout, a.navpopup);
function popupFilterStubDetect(data, download, article) {
}
var counts = stubCount(data, article);
function makeEmptySpans(list, navpop) {
if (counts.real) {
var ret = '';
return popupString('stub');
for (var i = 0; i < list.length; ++i) {
}
if (typeof list[i] == typeof '') {
if (counts.sect) {
ret += emptySpanHTML(list[i], navpop.idNumber, 'div');
return popupString('section stub');
} else if (typeof list[i] == typeof [] && list[i].length > 0) {
}
ret = ret.parenSplit(RegExp('(</[^>]*?>$)')).join(makeEmptySpans(list[i], navpop));
return '';
} else if (typeof list[i] == typeof {} && list[i].nodeType) {
}
ret += emptySpanHTML(list[i].name, navpop.idNumber, list[i].nodeType);

}
function popupFilterDisambigDetect(data, download, article) {
}
if (!getValueOf('popupAllDabsStubs') && article.namespace()) {
return ret;
return '';
}
}
function emptySpanHTML(name, id, tag, classname) {
return isDisambig(data, article) ? popupString('disambig') : '';
tag = tag || 'span';
}
if (!classname) {

classname = emptySpanHTML.classAliases[name];
function formatBytes(num) {
}
return num > 949
classname = classname || name;
? Math.round(num / 100) / 10 + popupString('kB')
if (name == getValueOf('popupDragHandle')) {
: num + '&nbsp;' + popupString('bytes');
classname += ' popupDragHandle';
}
}
// ENDFILE: pageinfo.js
return simplePrintf('<%s id="%s" class="%s"></%s>', [tag, name + id, classname, tag]);

}
// STARTFILE: titles.js
emptySpanHTML.classAliases = {
/**
popupSecondPreview: 'popupPreview'
* @fileoverview Defines the {@link Title} class, and associated crufty functions.
};

function imageHTML(article, idNumber) {
* <code>Title</code> deals with article titles and their various
return simplePrintf('<a id="popupImageLink$1">' + '<img align="right" valign="top" id="popupImg$1" style="display: none;"></img>' + '</a>', [idNumber]);
* forms. {@link Stringwrapper} is the parent class of
}
* <code>Title</code>, which exists simply to make things a little
function popTipsSoonFn(id, when, popData) {
* neater.
if (!when) {
*/
when = 250;

}
/**
var popTips = function() {
* Creates a new Stringwrapper.
setupTooltips(document.getElementById(id), false, true, popData);
* @constructor
};

return function() {
* @class the Stringwrapper class. This base class is not really
setTimeout(popTips, when, popData);
* useful on its own; it just wraps various common string operations.
}
*/
;
function Stringwrapper() {
}
/**
function setPopupTipsAndHTML(html, divname, idnumber, popData) {
* Wrapper for this.toString().indexOf()
setPopupHTML(html, divname, idnumber, getValueOf('popupSubpopups') ? popTipsSoonFn(divname + idnumber, null, popData) : null);
* @param {String} x
}
* @type {number}
function fuzzyCursorOffMenus(x, y, fuzz, parent) {
*/
if (!parent) {
this.indexOf = function (x) {
return null;
return this.toString().indexOf(x);
}
};
var uls = parent.getElementsByTagName('ul');
/**
for (var i = 0; i < uls.length; ++i) {
* Returns this.value.
if (uls[i].className == 'popup_menu') {
* @type {string}
if (uls[i].offsetWidth > 0) {
*/
return false;
this.toString = function () {
}
return this.value;
}
};
}
/**
return true;
* Wrapper for {@link String#parenSplit} applied to this.toString()
}
* @param {RegExp} x
function checkPopupPosition() {
* @type {Array}
if (pg.current.link && pg.current.link.navpopup) {
*/
pg.current.link.navpopup.limitHorizontalPosition();
this.parenSplit = function (x) {
}
return this.toString().parenSplit(x);
}
};
function mouseOutWikiLink() {
/**
var a = this;
* Wrapper for this.toString().substring()
removeModifierKeyHandler(a);
* @param {String} x
if (a.navpopup === null || typeof a.navpopup === 'undefined') {
* @param {String} y (optional)
return;
* @type {string}
}
*/
if (!a.navpopup.isVisible()) {
this.substring = function (x, y) {
a.navpopup.banish();
if (typeof y == 'undefined') {
return;
return this.toString().substring(x);
}
}
restoreTitle(a);
return this.toString().substring(x, y);
Navpopup.tracker.addHook(posCheckerHook(a.navpopup));
};
}
/**
function posCheckerHook(navpop) {
* Wrapper for this.toString().split()
return function() {
* @param {String} x
if (!navpop.isVisible()) {
* @type {Array}
return true;
*/
}
this.split = function (x) {
if (Navpopup.tracker.dirty) {
return this.toString().split(x);
return false;
};
}
/**
var x = Navpopup.tracker.x
* Wrapper for this.toString().replace()
, y = Navpopup.tracker.y;
* @param {String} x
var mouseOverNavpop = navpop.isWithin(x, y, navpop.fuzz, navpop.mainDiv) || !fuzzyCursorOffMenus(x, y, navpop.fuzz, navpop.mainDiv);
* @param {String} y
var t = getValueOf('popupHideDelay');
* @type {string}
if (t) {
*/
t = t * 1000;
this.replace = function (x, y) {
}
return this.toString().replace(x, y);
if (!t) {
};
if (!mouseOverNavpop) {
}
if (navpop.parentAnchor) {

restoreTitle(navpop.parentAnchor);
/**
}
* Creates a new <code>Title</code>.
navpop.banish();
* @constructor
return true;
*
}
* @class The Title class. Holds article titles and converts them into
return false;
* various forms. Also deals with anchors, by which we mean the bits
}
* of the article URL after a # character, representing locations
var d = Number(new Date());
* within an article.
if (!navpop.mouseLeavingTime) {
*
navpop.mouseLeavingTime = d;
* @param {String} value The initial value to assign to the
return false;
* article. This must be the canonical title (see {@link
}
* Title#value}. Omit this in the constructor and use another function
if (mouseOverNavpop) {
* to set the title if this is unavailable.
navpop.mouseLeavingTime = null;
*/
return false;
function Title(val) {
}
/**
if (d - navpop.mouseLeavingTime > t) {
* The canonical article title. This must be in UTF-8 with no
navpop.mouseLeavingTime = null;
* entities, escaping or nasties. Also, underscores should be
navpop.banish();
* replaced with spaces.
return true;
* @type {string}
}
* @private
return false;
*/
}
this.value = null;
;

}
/**
function runStopPopupTimer(navpop) {
* The canonical form of the anchor. This should be exactly as
if (!navpop.stopPopupTimer) {
* it appears in the URL, i.e. with the .C3.0A bits in.
navpop.stopPopupTimer = setInterval(posCheckerHook(navpop), 500);
* @type {string}
navpop.addHook(function() {
*/
clearInterval(navpop.stopPopupTimer);
this.anchor = '';
}, 'hide', 'before');

}
this.setUtf(val);
}
}
function Previewmaker(wikiText, baseUrl, owner) {
Title.prototype = new Stringwrapper();
this.originalData = wikiText;
/**
this.baseUrl = baseUrl;
* Returns the canonical representation of the article title, optionally without anchor.
this.owner = owner;
* @param {boolean} omitAnchor
this.maxCharacters = getValueOf('popupMaxPreviewCharacters');
* @fixme Decide specs for anchor
this.maxSentences = getValueOf('popupMaxPreviewSentences');
* @return String The article title and the anchor.
this.setData();
*/
}
Previewmaker.prototype.setData = function() {
Title.prototype.toString = function (omitAnchor) {
return this.value + (!omitAnchor && this.anchor ? '#' + this.anchorString() : '');
var maxSize = Math.max(10000, 2 * this.maxCharacters);
};
this.data = this.originalData.substring(0, maxSize);
Title.prototype.anchorString = function () {
}
if (!this.anchor) {
;
return '';
Previewmaker.prototype.killComments = function() {
}
this.data = this.data.replace(RegExp('^<!--[^$]*?-->\\n|\\n<!--[^$]*?-->(?=\\n)|<!--[^$]*?-->', 'g'), '');
var split = this.anchor.parenSplit(/((?:[.][0-9A-F]{2})+)/);
}
var len = split.length;
;
var value;
Previewmaker.prototype.killDivs = function() {
for (var j = 1; j < len; j += 2) {
this.data = this.data.replace(RegExp('< *div[^>]* *>[\\s\\S]*?< */ *div *>', 'gi'), '');
// FIXME s/decodeURI/decodeURIComponent/g ?
}
value = split[j].split('.').join('%');
;
try {
Previewmaker.prototype.killGalleries = function() {
value = decodeURIComponent(value);
this.data = this.data.replace(RegExp('< *gallery[^>]* *>[\\s\\S]*?< */ *gallery *>', 'gi'), '');
} catch (e) {
}
// cannot decode
;
}
Previewmaker.prototype.kill = function(opening, closing, subopening, subclosing, repl) {
split[j] = value.split('_').join(' ');
var oldk = this.data;
}
var k = this.killStuff(this.data, opening, closing, subopening, subclosing, repl);
return split.join('');
while (k.length < oldk.length) {
};
oldk = k;
Title.prototype.urlAnchor = function () {
k = this.killStuff(k, opening, closing, subopening, subclosing, repl);
var split = this.anchor.parenSplit('/((?:[%][0-9A-F]{2})+)/');
}
var len = split.length;
this.data = k;
}
for (var j = 1; j < len; j += 2) {
split[j] = split[j].split('%').join('.');
;
}
Previewmaker.prototype.killStuff = function(txt, opening, closing, subopening, subclosing, repl) {
return split.join('');
var op = this.makeRegexp(opening);
};
var cl = this.makeRegexp(closing, '^');
Title.prototype.anchorFromUtf = function (str) {
var sb = subopening ? this.makeRegexp(subopening, '^') : null;
this.anchor = encodeURIComponent(str.split(' ').join('_'))
var sc = subclosing ? this.makeRegexp(subclosing, '^') : cl;
.split('%3A')
if (!op || !cl) {
.join(':')
alert('Navigation Popups error: op or cl is null! something is wrong.');
.split("'")
return;
.join('%27')
}
.split('%')
if (!op.test(txt)) {
.join('.');
return txt;
};
}
Title.fromURL = function (h) {
var ret = '';
return new Title().fromURL(h);
var opResult = op.exec(txt);
};
ret = txt.substring(0, opResult.index);
Title.prototype.fromURL = function (h) {
txt = txt.substring(opResult.index + opResult[0].length);
if (typeof h != 'string') {
var depth = 1;
this.value = null;
while (txt.length > 0) {
return this;
var removal = 0;
}
if (depth == 1 && cl.test(txt)) {

depth--;
// NOTE : playing with decodeURI, encodeURI, escape, unescape,
removal = cl.exec(txt)[0].length;
// we seem to be able to replicate the IE borked encoding
} else if (depth > 1 && sc.test(txt)) {

depth--;
// IE doesn't do this new-fangled utf-8 thing.
removal = sc.exec(txt)[0].length;
// and it's worse than that.
} else if (sb && sb.test(txt)) {
// IE seems to treat the query string differently to the rest of the url
depth++;
// the query is treated as bona-fide utf8, but the first bit of the url is pissed around with
removal = sb.exec(txt)[0].length;

}
// we fix up & for all browsers, just in case.
if (!removal) {
var splitted = h.split('?');
removal = 1;
splitted[0] = splitted[0].split('&').join('%26');
}

txt = txt.substring(removal);
h = splitted.join('?');
if (depth === 0) {

break;
var contribs = pg.re.contribs.exec(h);
}
if (contribs) {
}
if (contribs[1] == 'title=') {
return ret + (repl || '') + txt;
contribs[3] = contribs[3].split('+').join(' ');
}
}
;
var u = new Title(contribs[3]);
Previewmaker.prototype.makeRegexp = function(x, prefix, suffix) {
this.setUtf(
prefix = prefix || '';
this.decodeNasties(
suffix = suffix || '';
mw.config.get('wgFormattedNamespaces')[pg.nsUserId] + ':' + u.stripNamespace()
var reStr = '';
)
var flags = '';
);
if (isString(x)) {
return this;
reStr = prefix + literalizeRegex(x) + suffix;
}
} else if (isRegExp(x)) {

var s = x.toString().substring(1);
var email = pg.re.email.exec(h);
var sp = s.split('/');
if (email) {
flags = sp[sp.length - 1];
this.setUtf(
sp[sp.length - 1] = '';
this.decodeNasties(
s = sp.join('/');
mw.config.get('wgFormattedNamespaces')[pg.nsUserId] +
s = s.substring(0, s.length - 1);
':' +
reStr = prefix + s + suffix;
new Title(email[3]).stripNamespace()
} else {
)
log('makeRegexp failed');
);
}
return this;
log('makeRegexp: got reStr=' + reStr + ', flags=' + flags);
}
return RegExp(reStr, flags);

}
var backlinks = pg.re.backlinks.exec(h);
;
if (backlinks) {
Previewmaker.prototype.killBoxTemplates = function() {
this.setUtf(this.decodeNasties(new Title(backlinks[3])));
this.kill(RegExp('[{][{][^{}\\s|]*?(float|box)[_ ](begin|start)', 'i'), /[}][}]\s*/, '{{');
return this;
this.kill(RegExp('[{][{][^{}\\s|]*?(infobox|elementbox|frame)[_ ]', 'i'), /[}][}]\s*/, '{{');
}
}

;
//A dummy title object for a Special:Diff link.
Previewmaker.prototype.killTemplates = function() {
var specialdiff = pg.re.specialdiff.exec(h);
this.kill('{{', '}}', '{', '}', ' ');
if (specialdiff) {
}
this.setUtf(
;
this.decodeNasties(
Previewmaker.prototype.killTables = function() {
new Title(mw.config.get('wgFormattedNamespaces')[pg.nsSpecialId] + ':Diff')
this.kill('{|', /[|]}\s*/, '{|');
)
this.kill(/<table.*?>/i, /<\/table.*?>/i, /<table.*?>/i);
);
this.data = this.data.replace(RegExp('^[|].*$', 'mg'), '');
return this;
}
}
;

Previewmaker.prototype.killImages = function() {
// no more special cases to check --
var forbiddenNamespaceAliases = [];
// hopefully it's not a disguised user-related or specially treated special page
jQuery.each(mw.config.get('wgNamespaceIds'), function(_localizedNamespaceLc, _namespaceId) {
// Includes references
if (_namespaceId != pg.nsImageId && _namespaceId != pg.nsCategoryId) {
var m = pg.re.main.exec(h);
return;
if (m === null) {
}
this.value = null;
forbiddenNamespaceAliases.push(_localizedNamespaceLc.split(' ').join('[ _]'));
} else {
});
var fromBotInterface = /[?](.+[&])?title=/.test(h);
this.kill(RegExp('[[][[]\\s*(' + forbiddenNamespaceAliases.join('|') + ')\\s*:', 'i'), /\]\]\s*/, '[', ']');
if (fromBotInterface) {
}
m[2] = m[2].split('+').join('_');
;
}
Previewmaker.prototype.killHTML = function() {
var extracted = m[2] + (m[3] ? '#' + m[3] : '');
this.kill(/<ref\b[^/>]*?>/i, /<\/ref>/i);
if (pg.flag.isSafari && /%25[0-9A-Fa-f]{2}/.test(extracted)) {
this.data = this.data.replace(RegExp('(^|\\n) *<.*', 'g'), '\n');
// Fix Safari issue
var splitted = this.data.parenSplit(/(<[\w\W]*?(?:>|$|(?=<)))/);
// Safari sometimes encodes % as %25 in UTF-8 encoded strings like %E5%A3 -> %25E5%25A3.
var len = splitted.length;
this.setUtf(decodeURIComponent(unescape(extracted)));
for (var i = 1; i < len; i = i + 2) {
} else {
switch (splitted[i]) {
this.setUtf(this.decodeNasties(extracted));
case '<nowiki>':
}
case '</nowiki>':
}
case '<blockquote>':
return this;
case '</blockquote>':
};
break;
Title.prototype.decodeNasties = function (txt) {
default:
// myDecodeURI uses decodeExtras, which removes _,
splitted[i] = '';
// thus ruining citations previews, which are formated as "cite_note-1"
}
try {
}
var ret = decodeURI(this.decodeEscapes(txt));
this.data = splitted.join('');
ret = ret.replace(/[_ ]*$/, '');
}
return ret;
;
} catch (e) {
Previewmaker.prototype.killChunks = function() {
return txt; // cannot decode
var italicChunkRegex = new RegExp("((^|\\n)\\s*:*\\s*''[^']([^']|'''|'[^']){20}(.|\\n[^\\n])*''[.!?\\s]*\\n)+",'g');
}
this.data = this.data.replace(italicChunkRegex, '\n');
};
}
// Decode valid %-encodings, otherwise escape them
;
Previewmaker.prototype.mopup = function() {
Title.prototype.decodeEscapes = function (txt) {
var split = txt.parenSplit(/((?:[%][0-9A-Fa-f]{2})+)/);
this.data = this.data.replace(RegExp('^-{4,}', 'mg'), '');
var len = split.length;
this.data = this.data.replace(RegExp('(^|\\n) *:[^\\n]*', 'g'), '');
// No %-encoded items found, so replace the literal %
this.data = this.data.replace(RegExp('^__[A-Z_]*__ *$', 'gmi'), '');
if (len === 1) {
}
return split[0].replace(/%(?![0-9a-fA-F][0-9a-fA-F])/g, '%25');
;
}
Previewmaker.prototype.firstBit = function() {
var d = this.data;
for (var i = 1; i < len; i = i + 2) {
split[i] = decodeURIComponent(split[i]);
if (getValueOf('popupPreviewCutHeadings')) {
}
this.data = this.data.replace(RegExp('\\s*(==+[^=]*==+)\\s*', 'g'), '\n\n$1 ');
return split.join('');
this.data = this.data.replace(RegExp('([:;]) *\\n{2,}', 'g'), '$1\n');
};
this.data = this.data.replace(RegExp('^[\\s\\n]*'), '');
Title.fromAnchor = function (a) {
var stuff = RegExp('^([^\\n]|\\n[^\\n\\s])*').exec(this.data);
return new Title().fromAnchor(a);
if (stuff) {
};
d = stuff[0];
Title.prototype.fromAnchor = function (a) {
}
if (!a) {
if (!getValueOf('popupPreviewFirstParOnly')) {
this.value = null;
d = this.data;
return this;
}
}
d = d.replace(RegExp('(==+[^=]*==+)\\s*', 'g'), '$1\n\n');
return this.fromURL(a.href);
}
};
d = d.parenSplit(RegExp('([!?.]+["' + "'" + ']*\\s)', 'g'));
Title.fromWikiText = function (txt) {
d[0] = d[0].replace(RegExp('^\\s*'), '');
return new Title().fromWikiText(txt);
var notSentenceEnds = RegExp('([^.][a-z][.] *[a-z]|etc|sic|Dr|Mr|Mrs|Ms|St|no|op|cit|\\[[^\\]]*|\\s[A-Zvclm])$', 'i');
};
d = this.fixSentenceEnds(d, notSentenceEnds);
Title.prototype.fromWikiText = function (txt) {
this.fullLength = d.join('').length;
// FIXME - testing needed
var n = this.maxSentences;
txt = myDecodeURI(txt);
var dd = this.firstSentences(d, n);
this.setUtf(txt);
do {
return this;
dd = this.firstSentences(d, n);
};
--n;
Title.prototype.hintValue = function () {
} while (dd.length > this.maxCharacters && n !== 0);
if (!this.value) {
this.data = dd;
return '';
}
}
;
return safeDecodeURI(this.value);
Previewmaker.prototype.fixSentenceEnds = function(strs, reg) {
};
for (var i = 0; i < strs.length - 2; ++i) {
Title.prototype.toUserName = function (withNs) {
if (reg.test(strs[i])) {
if (this.namespaceId() != pg.nsUserId && this.namespaceId() != pg.nsUsertalkId) {
var a = [];
this.value = null;
for (var j = 0; j < strs.length; ++j) {
return;
if (j < i) {
}
a[j] = strs[j];
this.value =
}
(withNs ? mw.config.get('wgFormattedNamespaces')[pg.nsUserId] + ':' : '') +
if (j == i) {
this.stripNamespace().split('/')[0];
a[i] = strs[i] + strs[i + 1] + strs[i + 2];
};
}
Title.prototype.userName = function (withNs) {
if (j > i + 2) {
var t = new Title(this.value);
a[j - 2] = strs[j];
t.toUserName(withNs);
}
if (t.value) {
}
return t;
return this.fixSentenceEnds(a, reg);
}
}
return null;
}
};
return strs;
Title.prototype.toTalkPage = function () {
}
// convert article to a talk page, or if we can't, return null
;
// In other words: return null if this ALREADY IS a talk page
Previewmaker.prototype.firstSentences = function(strs, howmany) {
// and return the corresponding talk page otherwise
var t = strs.slice(0, 2 * howmany);
//
return t.join('');
// Per https://www.mediawiki.org/wiki/Manual:Namespace#Subject_and_talk_namespaces
}
// * All discussion namespaces have odd-integer indices
;
// * The discussion namespace index for a specific namespace with index n is n + 1
Previewmaker.prototype.killBadWhitespace = function() {
if (this.value === null) {
this.data = this.data.replace(RegExp("^ *'+ *$", 'gm'), '');
return null;
}
}
;

Previewmaker.prototype.makePreview = function() {
if (this.owner.article.namespaceId() != pg.nsTemplateId && this.owner.article.namespaceId() != pg.nsImageId) {
var namespaceId = this.namespaceId();
if (namespaceId >= 0 && namespaceId % 2 === 0) {
this.killComments();
//non-special and subject namespace
this.killDivs();
var localizedNamespace = mw.config.get('wgFormattedNamespaces')[namespaceId + 1];
this.killGalleries();
if (typeof localizedNamespace !== 'undefined') {
this.killBoxTemplates();
if (localizedNamespace === '') {
if (getValueOf('popupPreviewKillTemplates')) {
this.value = this.stripNamespace();
this.killTemplates();
} else {
} else {
this.value = localizedNamespace.split(' ').join('_') + ':' + this.stripNamespace();
this.killMultilineTemplates();
}
}
return this.value;
this.killTables();
}
this.killImages();
}
this.killHTML();

this.killChunks();
this.value = null;
this.mopup();
return null;
this.firstBit();
};
this.killBadWhitespace();
// Return canonical, localized namespace
} else {
Title.prototype.namespace = function () {
this.killHTML();
return mw.config.get('wgFormattedNamespaces')[this.namespaceId()];
}
};
this.html = wiki2html(this.data, this.baseUrl);
Title.prototype.namespaceId = function () {
this.fixHTML();
this.stripLongTemplates();
var n = this.value.indexOf(':');
if (n < 0) {
}
return 0;
;
} //mainspace
Previewmaker.prototype.esWiki2HtmlPart = function(data) {
var namespaceId =
var reLinks = /(?:\[\[([^|\]]*)(?:\|([^|\]]*))*]]([a-z]*))/gi;
mw.config.get('wgNamespaceIds')[
reLinks.lastIndex = 0;
this.value.substring(0, n).split(' ').join('_').toLowerCase()
var match;
];
var result = '';
if (typeof namespaceId == 'undefined') {
var postfixIndex = 0;
return 0;
while ((match = reLinks.exec(data))) {
} //mainspace
result += pg.escapeQuotesHTML(data.substring(postfixIndex, match.index)) + '<a href="' + Insta.conf.paths.articles + pg.escapeQuotesHTML(match[1]) + '">' + pg.escapeQuotesHTML((match[2] ? match[2] : match[1]) + match[3]) + '</a>';
return namespaceId;
postfixIndex = reLinks.lastIndex;
};
}
Title.prototype.talkPage = function () {
result += pg.escapeQuotesHTML(data.substring(postfixIndex));
var t = new Title(this.value);
return result;
t.toTalkPage();
}
if (t.value) {
;
return t;
Previewmaker.prototype.editSummaryPreview = function() {
}
var reAes = /\/\* *(.*?) *\*\//g;
return null;
reAes.lastIndex = 0;
};
var match;
Title.prototype.isTalkPage = function () {
match = reAes.exec(this.data);
if (this.talkPage() === null) {
if (match) {
return true;
var prefix = this.data.substring(0, match.index - 1);
}
var section = match[1];
return false;
var postfix = this.data.substring(reAes.lastIndex);
};
var start = "<span class='autocomment'>";
Title.prototype.toArticleFromTalkPage = function () {
var end = '</span>';
//largely copy/paste from toTalkPage above.
if (prefix.length > 0) {
if (this.value === null) {
start = this.esWiki2HtmlPart(prefix) + ' ' + start + '- ';
return null;
}
}
if (postfix.length > 0) {

end = ': ' + end + this.esWiki2HtmlPart(postfix);
var namespaceId = this.namespaceId();
}
if (namespaceId >= 0 && namespaceId % 2 == 1) {
var t = new Title().fromURL(this.baseUrl);
//non-special and talk namespace
t.anchorFromUtf(section);
var localizedNamespace = mw.config.get('wgFormattedNamespaces')[namespaceId - 1];
var sectionLink = Insta.conf.paths.articles + pg.escapeQuotesHTML(t.toString(true)) + '#' + pg.escapeQuotesHTML(t.anchor);
if (typeof localizedNamespace !== 'undefined') {
return (start + '<a href="' + sectionLink + '">&rarr;</a> ' + pg.escapeQuotesHTML(section) + end);
if (localizedNamespace === '') {
}
this.value = this.stripNamespace();
return this.esWiki2HtmlPart(this.data);
} else {
}
this.value = localizedNamespace.split(' ').join('_') + ':' + this.stripNamespace();
;
}
function previewSteps(txt) {
return this.value;
try {
}
txt = txt || document.editform.wpTextbox1.value;
}
} catch (err) {

if (pg.cache.pages.length > 0) {
this.value = null;
txt = pg.cache.pages[pg.cache.pages.length - 1].data;
return null;
} else {
};
alert('provide text or use an edit page');
Title.prototype.articleFromTalkPage = function () {
}
var t = new Title(this.value);
}
t.toArticleFromTalkPage();
txt = txt.substring(0, 10000);
if (t.value) {
var base = pg.wiki.articlebase + Title.fromURL(document.location.href).urlString();
return t;
var p = new Previewmaker(txt,base,pg.current.link.navpopup);
}
if (this.owner.article.namespaceId() != pg.nsTemplateId) {
return null;
p.killComments();
};
if (!confirm('done killComments(). Continue?\n---\n' + p.data)) {
Title.prototype.articleFromTalkOrArticle = function () {
return;
var t = new Title(this.value);
}
if (t.toArticleFromTalkPage()) {
p.killDivs();
return t;
if (!confirm('done killDivs(). Continue?\n---\n' + p.data)) {
}
return;
return this;
}
};
p.killGalleries();
Title.prototype.isIpUser = function () {
if (!confirm('done killGalleries(). Continue?\n---\n' + p.data)) {
return pg.re.ipUser.test(this.userName());
return;
};
}
Title.prototype.stripNamespace = function () {
p.killBoxTemplates();
// returns a string, not a Title
if (!confirm('done killBoxTemplates(). Continue?\n---\n' + p.data)) {
var n = this.value.indexOf(':');
return;
if (n < 0) {
}
return this.value;
if (getValueOf('popupPreviewKillTemplates')) {
}
p.killTemplates();
var namespaceId = this.namespaceId();
if (!confirm('done killTemplates(). Continue?\n---\n' + p.data)) {
if (namespaceId === pg.nsMainspaceId) {
return;
return this.value;
}
}
} else {
return this.value.substring(n + 1);
p.killMultilineTemplates();
};
if (!confirm('done killMultilineTemplates(). Continue?\n---\n' + p.data)) {
Title.prototype.setUtf = function (value) {
return;
if (!value) {
}
this.value = '';
}
return;
p.killTables();
}
if (!confirm('done killTables(). Continue?\n---\n' + p.data)) {
var anch = value.indexOf('#');
return;
if (anch < 0) {
}
this.value = value.split('_').join(' ');
p.killImages();
this.anchor = '';
if (!confirm('done killImages(). Continue?\n---\n' + p.data)) {
return;
return;
}
}
this.value = value.substring(0, anch).split('_').join(' ');
p.killHTML();
this.anchor = value.substring(anch + 1);
if (!confirm('done killHTML(). Continue?\n---\n' + p.data)) {
this.ns = null; // wait until namespace() is called
return;
};
}
Title.prototype.setUrl = function (urlfrag) {
p.killChunks();
var anch = urlfrag.indexOf('#');
if (!confirm('done killChunks(). Continue?\n---\n' + p.data)) {
this.value = safeDecodeURI(urlfrag.substring(0, anch));
return;
this.anchor = this.value.substring(anch + 1);
}
};
p.mopup();
Title.prototype.append = function (x) {
if (!confirm('done mopup(). Continue?\n---\n' + p.data)) {
this.setUtf(this.value + x);
return;
};
}
Title.prototype.urlString = function (x) {
p.firstBit();
if (!x) {
if (!confirm('done firstBit(). Continue?\n---\n' + p.data)) {
x = {};
return;
}
}
var v = this.toString(true);
p.killBadWhitespace();
if (!x.omitAnchor && this.anchor) {
if (!confirm('done killBadWhitespace(). Continue?\n---\n' + p.data)) {
v += '#' + this.urlAnchor();
return;
}
}
if (!x.keepSpaces) {
}
v = v.split(' ').join('_');
p.html = wiki2html(p.data, base);
}
p.fixHTML();
return encodeURI(v).split('&').join('%26').split('?').join('%3F').split('+').join('%2B');
if (!confirm('done fixHTML(). Continue?\n---\n' + p.html)) {
};
return;
Title.prototype.removeAnchor = function () {
}
return new Title(this.toString(true));
p.stripLongTemplates();
};
if (!confirm('done stripLongTemplates(). Continue?\n---\n' + p.html)) {
Title.prototype.toUrl = function () {
return;
return pg.wiki.titlebase + this.urlString();
}
};
alert('finished preview - end result follows.\n---\n' + p.html);

}
function parseParams(url) {
Previewmaker.prototype.fixHTML = function() {
var specialDiff = pg.re.specialdiff.exec(url);
if (!this.html) {
if (specialDiff) {
return;
var split = specialDiff[1].split('/');
}
if (split.length == 1) {
var ret = this.html;
return { oldid: split[0], diff: 'prev' };
ret = ret.replace(RegExp('(<a href="' + pg.wiki.articlePath + '/[^"]*)[?](.*?")', 'g'), '$1%3F$2');
} else if (split.length == 2) {
ret = ret.replace(RegExp("(<a href='" + pg.wiki.articlePath + "/[^']*)[?](.*?')", 'g'), '$1%3F$2');
return { oldid: split[0], diff: split[1] };
this.html = ret;
}
}
}
;

Previewmaker.prototype.showPreview = function() {
var ret = {};
this.makePreview();
if (url.indexOf('?') == -1) {
if (typeof this.html != typeof '') {
return ret;
return;
}
}
url = url.split('#')[0];
if (RegExp('^\\s*$').test(this.html)) {
var s = url.split('?').slice(1).join();
return;
var t = s.split('&');
}
for (var i = 0; i < t.length; ++i) {
setPopupHTML('<hr />', 'popupPrePreviewSep', this.owner.idNumber);
var z = t[i].split('=');
setPopupTipsAndHTML(this.html, 'popupPreview', this.owner.idNumber, {
z.push(null);
owner: this.owner,
ret[z[0]] = z[1];
});
}
var more = this.fullLength > this.data.length ? this.moreLink() : '';
//Diff revision with no oldid is interpreted as a diff to the previous revision by MediaWiki
setPopupHTML(more, 'popupPreviewMore', this.owner.idNumber);
if (ret.diff && typeof ret.oldid === 'undefined') {
}
ret.oldid = 'prev';
;
}
Previewmaker.prototype.moreLink = function() {
//Documentation seems to say something different, but oldid can also accept prev/next, and
var a = document.createElement('a');
//Echo is emitting such URLs. Simple fixup during parameter decoding:
a.className = 'popupMoreLink';
if (ret.oldid && (ret.oldid === 'prev' || ret.oldid === 'next' || ret.oldid === 'cur')) {
a.innerHTML = popupString('more...');
var helper = ret.diff;
var savedThis = this;
ret.diff = ret.oldid;
a.onclick = function() {
ret.oldid = helper;
savedThis.maxCharacters += 2000;
}
savedThis.maxSentences += 20;
return ret;
savedThis.setData();
}
savedThis.showPreview();

}
// (a) myDecodeURI (first standard decodeURI, then pg.re.urlNoPopup)
;
// (b) change spaces to underscores
return a;
// (c) encodeURI (just the straight one, no pg.re.urlNoPopup)
}

;
function myDecodeURI(str) {
Previewmaker.prototype.stripLongTemplates = function() {
var ret;
this.html = this.html.replace(RegExp('^.{0,1000}[{][{][^}]*?(<(p|br)( /)?>\\s*){2,}([^{}]*?[}][}])?', 'gi'), '');
// FIXME decodeURIComponent??
this.html = this.html.split('\n').join(' ');
try {
this.html = this.html.replace(RegExp('[{][{][^}]*<pre>[^}]*[}][}]', 'gi'), '');
ret = decodeURI(str.toString());
}
} catch (summat) {
;
return str;
Previewmaker.prototype.killMultilineTemplates = function() {
}
this.kill('{{{', '}}}');
for (var i = 0; i < pg.misc.decodeExtras.length; ++i) {
this.kill(RegExp('\\s*[{][{][^{}]*\\n'), '}}', '{{');
var from = pg.misc.decodeExtras[i].from;
}
var to = pg.misc.decodeExtras[i].to;
;
ret = ret.split(from).join(to);
function loadAPIPreview(queryType, article, navpop) {
}
var art = new Title(article).urlString();
return ret;
var url = pg.wiki.apiwikibase + '?format=json&formatversion=2&action=query&';
}
var htmlGenerator = function() {

alert('invalid html generator');
function safeDecodeURI(str) {
};
var ret = myDecodeURI(str);
var usernameart = '';
return ret || str;
switch (queryType) {
}
case 'history':

url += 'titles=' + art + '&prop=revisions&rvlimit=' + getValueOf('popupHistoryPreviewLimit');
///////////
htmlGenerator = APIhistoryPreviewHTML;
// TESTS //
break;
///////////
case 'category':

url += 'list=categorymembers&cmtitle=' + art;
function isDisambig(data, article) {
htmlGenerator = APIcategoryPreviewHTML;
if (!getValueOf('popupAllDabsStubs') && article.namespace()) {
break;
return false;
case 'userinfo':
}
var username = new Title(article).userName();
return !article.isTalkPage() && pg.re.disambig.test(data);
usernameart = encodeURIComponent(username);
}
if (pg.re.ipUser.test(username)) {

url += 'list=blocks&bkprop=range|restrictions&bkip=' + usernameart;
function stubCount(data, article) {
} else {
if (!getValueOf('popupAllDabsStubs') && article.namespace()) {
url += 'list=users|usercontribs&usprop=blockinfo|groups|editcount|registration|gender&ususers=' + usernameart + '&meta=globaluserinfo&guiprop=groups|unattached&guiuser=' + usernameart + '&uclimit=1&ucprop=timestamp&ucuser=' + usernameart;
return false;
}
}
htmlGenerator = APIuserInfoPreviewHTML;
var sectStub = 0;
break;
var realStub = 0;
case 'contribs':
if (pg.re.stub.test(data)) {
usernameart = encodeURIComponent(new Title(article).userName());
var s = data.parenSplit(pg.re.stub);
url += 'list=usercontribs&ucuser=' + usernameart + '&uclimit=' + getValueOf('popupContribsPreviewLimit');
for (var i = 1; i < s.length; i = i + 2) {
htmlGenerator = APIcontribsPreviewHTML;
if (s[i]) {
break;
++sectStub;
case 'imagepagepreview':
} else {
var trail = '';
++realStub;
if (getValueOf('popupImageLinks')) {
}
trail = '&list=imageusage&iutitle=' + art;
}
}
}
url += 'titles=' + art + '&prop=revisions|imageinfo&rvslots=main&rvprop=content' + trail;
return { real: realStub, sect: sectStub };
htmlGenerator = APIimagepagePreviewHTML;
}
break;

case 'backlinks':
function isValidImageName(str) {
url += 'list=backlinks&bltitle=' + art;
// extend as needed...
htmlGenerator = APIbacklinksPreviewHTML;
return str.indexOf('{') == -1;
break;
}
case 'revision':

if (article.oldid) {
function isInStrippableNamespace(article) {
url += 'revids=' + article.oldid;
// Does the namespace allow subpages
} else {
// Note, would be better if we had access to wgNamespacesWithSubpages
url += 'titles=' + article.removeAnchor().urlString();
return article.namespaceId() !== 0;
}
}
url += '&prop=revisions|pageprops|info|images|categories&meta=wikibase&rvslots=main&rvprop=ids|timestamp|flags|comment|user|content&cllimit=max&imlimit=max';

htmlGenerator = APIrevisionPreviewHTML;
function isInMainNamespace(article) {
break;
return article.namespaceId() === 0;
}
}
pendingNavpopTask(navpop);

var callback = function(d) {
function anchorContainsImage(a) {
log('callback of API functions was hit');
// iterate over children of anchor a
if (queryType === 'userinfo') {
// see if any are images
fetchUserGroupNames(d.data).then(function() {
if (a === null) {
showAPIPreview(queryType, htmlGenerator(article, d, navpop), navpop.idNumber, navpop, d);
return false;
});
}
return;
var kids = a.childNodes;
}
for (var i = 0; i < kids.length; ++i) {
showAPIPreview(queryType, htmlGenerator(article, d, navpop), navpop.idNumber, navpop, d);
if (kids[i].nodeName == 'IMG') {
};
return true;
var go = function() {
}
getPageWithCaching(url, callback, navpop);
}
return true;
return false;
};
}
if (navpop.visible || !getValueOf('popupLazyDownloads')) {
function isPopupLink(a) {
go();
// NB for performance reasons, TOC links generally return true
} else {
// they should be stripped out later
navpop.addHook(go, 'unhide', 'before', 'DOWNLOAD_' + queryType + '_QUERY_DATA');

}
if (!markNopopupSpanLinks.done) {
}
markNopopupSpanLinks();
function linkList(list) {
}
list.sort(function(x, y) {
if (a.inNopopupSpan) {
return x == y ? 0 : x < y ? -1 : 1;
return false;
});
}
var buf = [];

for (var i = 0; i < list.length; ++i) {
// FIXME is this faster inline?
buf.push(wikiLink({
if (a.onmousedown || a.getAttribute('nopopup')) {
article: new Title(list[i]),
return false;
text: list[i].split(' ').join('&nbsp;'),
}
action: 'view',
var h = a.href;
}));
if (h === document.location.href + '#') {
}
return buf.join(', ');
return false;
}
}
if (!pg.re.basenames.test(h)) {
function getTimeOffset() {
return false;
var tz = mw.user.options.get('timecorrection');
}
if (tz) {
if (!pg.re.urlNoPopup.test(h)) {
if (tz.indexOf('|') > -1) {
return true;
return parseInt(tz.split('|')[1], 10);
}
}
return (
}
(pg.re.email.test(h) ||
return 0;
pg.re.contribs.test(h) ||
}
pg.re.backlinks.test(h) ||
function getTimeZone() {
pg.re.specialdiff.test(h)) &&
if (!pg.user.timeZone) {
h.indexOf('&limit=') == -1
var tz = mw.user.options.get('timecorrection');
);
pg.user.timeZone = 'UTC';
}
if (tz) {

var tzComponents = tz.split('|');
function markNopopupSpanLinks() {
if (tzComponents.length === 3 && tzComponents[0] === 'ZoneInfo') {
if (!getValueOf('popupOnlyArticleLinks')) {
pg.user.timeZone = tzComponents[2];
fixVectorMenuPopups();
} else {
}
errlog('Unexpected timezone information: ' + tz);

}
var s = $('.nopopups').toArray();
}
for (var i = 0; i < s.length; ++i) {
}
var as = s[i].getElementsByTagName('a');
return pg.user.timeZone;
}
for (var j = 0; j < as.length; ++j) {
as[j].inNopopupSpan = true;
function useTimeOffset() {
}
if (typeof Intl.DateTimeFormat.prototype.formatToParts === 'undefined') {
}
return true;

}
markNopopupSpanLinks.done = true;
var tz = mw.user.options.get('timecorrection');
}
if (tz && tz.indexOf('ZoneInfo|') === -1) {

return true;
function fixVectorMenuPopups() {
}
$('nav.vector-menu h3:first a:first').prop('inNopopupSpan', true);
return false;
}
}
// ENDFILE: titles.js
function getLocales() {

if (!pg.user.locales) {
// STARTFILE: getpage.js
var userLanguage = document.querySelector('html').getAttribute('lang');
//////////////////////////////////////////////////
if (getValueOf('popupLocale')) {
// Wiki-specific downloading
userLanguage = getValueOf('popupLocale');
//
} else if (userLanguage === 'en') {

if (getMWDateFormat() === 'mdy') {
// Schematic for a getWiki call
userLanguage = 'en-US';
//
} else {
userLanguage = 'en-GB';
// getPageWithCaching
// |
}
// false | true
}
// getPage<-[findPictureInCache]->-onComplete(a fake download)
pg.user.locales = Intl.DateTimeFormat.supportedLocalesOf([userLanguage, navigator.language]);
// \.
}
// (async)->addPageToCache(download)->-onComplete(download)
return pg.user.locales;

}
// check cache to see if page exists
function getMWDateFormat() {

return mw.user.options.get('date');
function getPageWithCaching(url, onComplete, owner) {
}
log('getPageWithCaching, url=' + url);
function editPreviewTable(article, h, reallyContribs) {
var i = findInPageCache(url);
var html = ['<table>'];
var d;
var day = null;
if (i > -1) {
var curart = article;
d = fakeDownload(
var page = null;
url,
var makeFirstColumnLinks;
owner.idNumber,
if (reallyContribs) {
onComplete,
makeFirstColumnLinks = function(currentRevision) {
pg.cache.pages[i].data,
var result = '(';
pg.cache.pages[i].lastModified,
result += '<a href="' + pg.wiki.titlebase + new Title(currentRevision.title).urlString() + '&diff=prev' + '&oldid=' + currentRevision.revid + '">' + popupString('diff') + '</a>';
owner
result += '&nbsp;|&nbsp;';
);
result += '<a href="' + pg.wiki.titlebase + new Title(currentRevision.title).urlString() + '&action=history">' + popupString('hist') + '</a>';
} else {
result += ')';
d = getPage(url, onComplete, owner);
return result;
if (d && owner && owner.addDownload) {
}
owner.addDownload(d);
;
d.owner = owner;
} else {
}
var firstRevid = h[0].revid;
}
makeFirstColumnLinks = function(currentRevision) {
}
var result = '(';

result += '<a href="' + pg.wiki.titlebase + new Title(curart).urlString() + '&diff=' + firstRevid + '&oldid=' + currentRevision.revid + '">' + popupString('cur') + '</a>';
function getPage(url, onComplete, owner) {
result += '&nbsp;|&nbsp;';
log('getPage');
result += '<a href="' + pg.wiki.titlebase + new Title(curart).urlString() + '&diff=prev&oldid=' + currentRevision.revid + '">' + popupString('last') + '</a>';
var callback = function (d) {
result += ')';
if (!d.aborted) {
return result;
addPageToCache(d);
}
onComplete(d);
;
}
}
};
for (var i = 0; i < h.length; ++i) {
return startDownload(url, owner.idNumber, callback);
if (reallyContribs) {
}
page = h[i].title;

curart = new Title(page);
function findInPageCache(url) {
}
for (var i = 0; i < pg.cache.pages.length; ++i) {
var minor = h[i].minor ? '<b>m </b>' : '';
if (url == pg.cache.pages[i].url) {
var editDate = new Date(h[i].timestamp);
return i;
var thisDay = formattedDate(editDate);
}
var thisTime = formattedTime(editDate);
}
if (thisDay == day) {
return -1;
thisDay = '';
}
} else {

day = thisDay;
function addPageToCache(download) {
}
log('addPageToCache ' + download.url);
if (thisDay) {
var page = {
html.push('<tr><td colspan=3><span class="popup_history_date">' + thisDay + '</span></td></tr>');
url: download.url,
}
data: download.data,
html.push('<tr class="popup_history_row_' + (i % 2 ? 'odd' : 'even') + '">');
lastModified: download.lastModified,
html.push('<td>' + makeFirstColumnLinks(h[i]) + '</td>');
};
html.push('<td>' + '<a href="' + pg.wiki.titlebase + new Title(curart).urlString() + '&oldid=' + h[i].revid + '">' + thisTime + '</a></td>');
return pg.cache.pages.push(page);
var col3url = ''
}
, col3txt = '';
// ENDFILE: getpage.js
if (!reallyContribs) {

var user = h[i].user;
// STARTFILE: parensplit.js
if (!h[i].userhidden) {
//////////////////////////////////////////////////
if (pg.re.ipUser.test(user)) {
// parenSplit
col3url = pg.wiki.titlebase + mw.config.get('wgFormattedNamespaces')[pg.nsSpecialId] + ':Contributions&target=' + new Title(user).urlString();

} else {
// String.prototype.parenSplit should do what ECMAscript says String.prototype.split does,
col3url = pg.wiki.titlebase + mw.config.get('wgFormattedNamespaces')[pg.nsUserId] + ':' + new Title(user).urlString();
// interspersing paren matches (regex capturing groups) between the split elements.
}
// i.e. 'abc'.split(/(b)/)) should return ['a','b','c'], not ['a','c']
col3txt = pg.escapeQuotesHTML(user);

} else {
if (String('abc'.split(/(b)/)) != 'a,b,c') {
col3url = getValueOf('popupRevDelUrl');
// broken String.split, e.g. konq, IE < 10
col3txt = pg.escapeQuotesHTML(popupString('revdel'));
String.prototype.parenSplit = function (re) {
}
re = nonGlobalRegex(re);
} else {
var s = this;
col3url = pg.wiki.titlebase + curart.urlString();
var m = re.exec(s);
col3txt = pg.escapeQuotesHTML(page);
var ret = [];
}
while (m && s) {
html.push('<td>' + (reallyContribs ? minor : '') + '<a href="' + col3url + '">' + col3txt + '</a></td>');
// without the following loop, we have
var comment = '';
// 'ab'.parenSplit(/a|(b)/) != 'ab'.split(/a|(b)/)
var c = h[i].comment || (typeof h[i].slots !== 'undefined' ? h[i].slots.main.content : null);
if (c) {
for (var i = 0; i < m.length; ++i) {
if (typeof m[i] == 'undefined') {
comment = new Previewmaker(c,new Title(curart).toUrl()).editSummaryPreview();
m[i] = '';
} else if (h[i].commenthidden) {
}
comment = popupString('revdel');
}
}
ret.push(s.substring(0, m.index));
html.push('<td>' + (!reallyContribs ? minor : '') + comment + '</td>');
ret = ret.concat(m.slice(1));
html.push('</tr>');
s = s.substring(m.index + m[0].length);
html = [html.join('')];
m = re.exec(s);
}
}
html.push('</table>');
ret.push(s);
return html.join('');
return ret;
}
};
function adjustDate(d, offset) {
} else {
var o = offset * 60 * 1000;
String.prototype.parenSplit = function (re) {
return new Date(Number(d) + o);
return this.split(re);
}
};
function convertTimeZone(date, timeZone) {
String.prototype.parenSplit.isNative = true;
return new Date(date.toLocaleString('en-US', {
}
timeZone: timeZone

}));
function nonGlobalRegex(re) {
}
var s = re.toString();
function formattedDateTime(date) {
var flags = '';
if (useTimeOffset()) {
for (var j = s.length; s.charAt(j) != '/'; --j) {
return formattedDate(date) + ' ' + formattedTime(date);
if (s.charAt(j) != 'g') {
}
flags += s.charAt(j);
if (getMWDateFormat() === 'ISO 8601') {
}
var d2 = convertTimeZone(date, getTimeZone());
}
return (map(zeroFill, [d2.getFullYear(), d2.getMonth() + 1, d2.getDate()]).join('-') + 'T' + map(zeroFill, [d2.getHours(), d2.getMinutes(), d2.getSeconds()]).join(':'));
var t = s.substring(1, j);
}
return RegExp(t, flags);
var options = getValueOf('popupDateTimeFormatterOptions');
}
options['timeZone'] = getTimeZone();
// ENDFILE: parensplit.js
return date.toLocaleString(getLocales(), options);

}
// STARTFILE: tools.js
function formattedDate(date) {
// IE madness with encoding
if (useTimeOffset()) {
// ========================
var d2 = adjustDate(date, getTimeOffset());
//
return map(zeroFill, [d2.getUTCFullYear(), d2.getUTCMonth() + 1, d2.getUTCDate()]).join('-');
// suppose throughout that the page is in utf8, like wikipedia
}
//
if (getMWDateFormat() === 'ISO 8601') {
// if a is an anchor DOM element and a.href should consist of
var d2 = convertTimeZone(date, getTimeZone());
//
return map(zeroFill, [d2.getFullYear(), d2.getMonth() + 1, d2.getDate()]).join('-');
// http://host.name.here/wiki/foo?bar=baz
}
//
var options = getValueOf('popupDateFormatterOptions');
// then IE gives foo as "latin1-encoded" utf8; we have foo = decode_utf8(decodeURI(foo_ie))
options['timeZone'] = getTimeZone();
// but IE gives bar=baz correctly as plain utf8
return date.toLocaleDateString(getLocales(), options);
//
}
// ---------------------------------
function formattedTime(date) {
//
if (useTimeOffset()) {
// IE's xmlhttp doesn't understand utf8 urls. Have to use encodeURI here.
var d2 = adjustDate(date, getTimeOffset());
//
return map(zeroFill, [d2.getUTCHours(), d2.getUTCMinutes(), d2.getUTCSeconds()]).join(':');
// ---------------------------------
}
//
if (getMWDateFormat() === 'ISO 8601') {
// summat else
var d2 = convertTimeZone(date, getTimeZone());

return map(zeroFill, [d2.getHours(), d2.getMinutes(), d2.getSeconds()]).join(':');
// Source: http://aktuell.de.selfhtml.org/artikel/javascript/utf8b64/utf8.htm
}

var options = getValueOf('popupTimeFormatterOptions');
function getJsObj(json) {
options['timeZone'] = getTimeZone();
try {
return date.toLocaleTimeString(getLocales(), options);
var json_ret = JSON.parse(json);
}
if (json_ret.warnings) {
function fetchUserGroupNames(userinfoResponse) {
for (var w = 0; w < json_ret.warnings.length; w++) {
var queryObj = getJsObj(userinfoResponse).query;
if (json_ret.warnings[w]['*']) {
var user = anyChild(queryObj.users);
log(json_ret.warnings[w]['*']);
var messages = [];
} else {
if (user.groups) {
log(json_ret.warnings[w].warnings);
user.groups.forEach(function(groupName) {
}
if (['*', 'user', 'autoconfirmed', 'extendedconfirmed', 'named'].indexOf(groupName) === -1) {
}
messages.push('group-' + groupName + '-member');
} else if (json_ret.error) {
}
errlog(json_ret.error.code + ': ' + json_ret.error.info);
});
}
}
return json_ret;
if (queryObj.globaluserinfo && queryObj.globaluserinfo.groups) {
} catch (someError) {
queryObj.globaluserinfo.groups.forEach(function(groupName) {
errlog('Something went wrong with getJsObj, json=' + json);
messages.push('group-' + groupName + '-member');
return 1;
});
}
}
}
return getMwApi().loadMessagesIfMissing(messages);

}
function anyChild(obj) {
function showAPIPreview(queryType, html, id, navpop, download) {
for (var p in obj) {
var target = 'popupPreview';
return obj[p];
completedNavpopTask(navpop);
}
switch (queryType) {
return null;
case 'imagelinks':
}
case 'category':

target = 'popupPostPreview';
function upcaseFirst(str) {
break;
if (typeof str != typeof '' || str === '') {
case 'userinfo':
return '';
target = 'popupUserData';
}
break;
return str.charAt(0).toUpperCase() + str.substring(1);
case 'revision':
}
insertPreview(download);

return;
function findInArray(arr, foo) {
}
if (!arr || !arr.length) {
setPopupTipsAndHTML(html, target, id);
return -1;
}
}
function APIrevisionPreviewHTML(article, download) {
var len = arr.length;
try {
for (var i = 0; i < len; ++i) {
var jsObj = getJsObj(download.data);
if (arr[i] == foo) {
var page = anyChild(jsObj.query.pages);
return i;
if (page.missing) {
}
download.owner = null;
}
return;
return -1;
}
}
var content = page && page.revisions && page.revisions[0] && page.revisions[0].slots && page.revisions[0].slots.main && page.revisions[0].slots.main.contentmodel === 'wikitext' ? page.revisions[0].slots.main.content : null;

if (typeof content === 'string') {
/* eslint-disable no-unused-vars */
download.data = content;
function nextOne(array, value) {
download.lastModified = new Date(page.revisions[0].timestamp);
// NB if the array has two consecutive entries equal
}
// then this will loop on successive calls
if (page.pageprops.wikibase_item) {
var i = findInArray(array, value);
download.wikibaseItem = page.pageprops.wikibase_item;
if (i < 0) {
download.wikibaseRepo = jsObj.query.wikibase.repo.url.base + jsObj.query.wikibase.repo.url.articlepath;
return null;
}
}
} catch (someError) {
return array[i + 1];
return 'Revision preview failed :(';
}
}
/* eslint-enable no-unused-vars */
}

function APIbacklinksPreviewHTML(article, download) {
function literalizeRegex(str) {
try {
return mw.util.escapeRegExp(str);
var jsObj = getJsObj(download.data);
}
var list = jsObj.query.backlinks;

var html = [];
String.prototype.entify = function () {
if (!list) {
//var shy='&shy;';
return popupString('No backlinks found');
return this.split('&')
}
.join('&amp;')
for (var i = 0; i < list.length; i++) {
.split('<')
var t = new Title(list[i].title);
.join('&lt;')
html.push('<a href="' + pg.wiki.titlebase + t.urlString() + '">' + t.toString().entify() + '</a>');
.split('>')
}
.join('&gt;' /*+shy*/)
html = html.join(', ');
.split('"')
if (jsObj['continue'] && jsObj['continue'].blcontinue) {
.join('&quot;');
html += popupString(' and more');
};
}

return html;
// Array filter function
} catch (someError) {
function removeNulls(val) {
return 'backlinksPreviewHTML went wonky';
return val !== null;
}
}
}

pg.fn.APIsharedImagePagePreviewHTML = function APIsharedImagePagePreviewHTML(obj) {
function joinPath(list) {
log('APIsharedImagePagePreviewHTML');
return list.filter(removeNulls).join('/');
var popupid = obj.requestid;
}
if (obj.query && obj.query.pages) {

var page = anyChild(obj.query.pages);
function simplePrintf(str, subs) {
var content = page && page.revisions && page.revisions[0] && page.revisions[0].slots && page.revisions[0].slots.main && page.revisions[0].slots.main.contentmodel === 'wikitext' ? page.revisions[0].slots.main.content : null;
if (!str || !subs) {
if (typeof content === 'string' && pg && pg.current && pg.current.link && pg.current.link.navpopup) {
return str;
var p = new Previewmaker(content,pg.current.link.navpopup.article,pg.current.link.navpopup);
}
p.makePreview();
var ret = [];
setPopupHTML(p.html, 'popupSecondPreview', popupid);
var s = str.parenSplit(/(%s|\$[0-9]+)/);
}
var i = 0;
}
do {
}
ret.push(s.shift());
;
if (!s.length) {
function APIimagepagePreviewHTML(article, download, navpop) {
break;
try {
}
var jsObj = getJsObj(download.data);
var cmd = s.shift();
var page = anyChild(jsObj.query.pages);
if (cmd == '%s') {
var content = page && page.revisions && page.revisions[0] && page.revisions[0].slots && page.revisions[0].slots.main && page.revisions[0].slots.main.contentmodel === 'wikitext' ? page.revisions[0].slots.main.content : null;
if (i < subs.length) {
var ret = '';
ret.push(subs[i]);
var alt = '';
} else {
try {
ret.push(cmd);
alt = navpop.parentAnchor.childNodes[0].alt;
}
} catch (e) {}
++i;
if (alt) {
} else {
ret = ret + '<hr /><b>' + popupString('Alt text:') + '</b> ' + pg.escapeQuotesHTML(alt);
var j = parseInt(cmd.replace('$', ''), 10) - 1;
}
if (j > -1 && j < subs.length) {
if (typeof content === 'string') {
ret.push(subs[j]);
var p = prepPreviewmaker(content, article, navpop);
} else {
p.makePreview();
ret.push(cmd);
if (p.html) {
}
ret += '<hr />' + p.html;
}
}
} while (s.length > 0);
if (getValueOf('popupSummaryData')) {
return ret.join('');
var info = getPageInfo(content, download);
}
log(info);

setPopupTrailer(info, navpop.idNumber);
/* eslint-disable no-unused-vars */
}
function isString(x) {
}
return typeof x === 'string' || x instanceof String;
if (page && page.imagerepository == 'shared') {
}
var art = new Title(article);

var encart = encodeURIComponent('File:' + art.stripNamespace());
function isNumber(x) {
var shared_url = pg.wiki.apicommonsbase + '?format=json&formatversion=2' + '&callback=pg.fn.APIsharedImagePagePreviewHTML' + '&requestid=' + navpop.idNumber + '&action=query&prop=revisions&rvslots=main&rvprop=content&titles=' + encart;
return typeof x === 'number' || x instanceof Number;
ret = ret + '<hr />' + popupString('Image from Commons') + ': <a href="' + pg.wiki.commonsbase + '?title=' + encart + '">' + popupString('Description page') + '</a>';
}
mw.loader.load(shared_url);

}
function isRegExp(x) {
showAPIPreview('imagelinks', APIimagelinksPreviewHTML(article, download), navpop.idNumber, download);
return x instanceof RegExp;
return ret;
}
} catch (someError) {

return 'API imagepage preview failed :(';
function isArray(x) {
}
return x instanceof Array;
}
}
function APIimagelinksPreviewHTML(article, download) {

try {
function isObject(x) {
var jsobj = getJsObj(download.data);
return x instanceof Object;
var list = jsobj.query.imageusage;
}
if (list) {

var ret = [];
function isFunction(x) {
for (var i = 0; i < list.length; i++) {
return !isRegExp(x) && (typeof x === 'function' || x instanceof Function);
ret.push(list[i].title);
}
}
/* eslint-enable no-unused-vars */
if (ret.length === 0) {

return popupString('No image links found');
function repeatString(s, mult) {
}
var ret = '';
return '<h2>' + popupString('File links') + '</h2>' + linkList(ret);
} else {
for (var i = 0; i < mult; ++i) {
ret += s;
return popupString('No image links found');
}
}
return ret;
} catch (someError) {
}
return 'Image links preview generation failed :(';

}
function zeroFill(s, min) {
}
min = min || 2;
function APIcategoryPreviewHTML(article, download) {
var t = s.toString();
try {
return repeatString('0', min - t.length) + t;
var jsobj = getJsObj(download.data);
}
var list = jsobj.query.categorymembers;

var ret = [];
function map(f, o) {
for (var p = 0; p < list.length; p++) {
if (isArray(o)) {
ret.push(list[p].title);
return map_array(f, o);
}
}
if (ret.length === 0) {
return map_object(f, o);
return popupString('Empty category');
}
}
function map_array(f, o) {
ret = '<h2>' + tprintf('Category members (%s shown)', [ret.length]) + '</h2>' + linkList(ret);
var ret = [];
if (jsobj['continue'] && jsobj['continue'].cmcontinue) {
for (var i = 0; i < o.length; ++i) {
ret += popupString(' and more');
ret.push(f(o[i]));
}
}
return ret;
return ret;
} catch (someError) {
}
return 'Category preview failed :(';
function map_object(f, o) {
}
var ret = {};
}
for (var i in o) {
function APIuserInfoPreviewHTML(article, download) {
var ret = [];
ret[o] = f(o[i]);
}
var queryobj = {};
return ret;
try {
}
queryobj = getJsObj(download.data).query;

} catch (someError) {
pg.escapeQuotesHTML = function (text) {
return 'Userinfo preview failed :(';
return text
}
.replace(/&/g, '&amp;')
var user = anyChild(queryobj.users);
.replace(/"/g, '&quot;')
if (user) {
.replace(/</g, '&lt;')
var globaluserinfo = queryobj.globaluserinfo;
.replace(/>/g, '&gt;');
if (user.invalid === '') {
};
ret.push(popupString('Invalid user'));

} else if (user.missing === '') {
pg.unescapeQuotesHTML = function (html) {
ret.push(popupString('Not a registered username'));
// From https://stackoverflow.com/a/7394787
}
// This seems to be implemented correctly on all major browsers now, so we
if (user.blockedby) {
// don't have to make our own function.
if (user.blockpartial) {
var txt = document.createElement('textarea');
ret.push('<b>' + popupString('Has blocks') + '</b>');
txt.innerHTML = html;
} else {
return txt.value;
ret.push('<b>' + popupString('BLOCKED') + '</b>');
};
}

}
// ENDFILE: tools.js
if (globaluserinfo && ('locked'in globaluserinfo || 'hidden'in globaluserinfo)) {

var lockedSulAccountIsAttachedToThis = true;
// STARTFILE: dab.js
for (var i = 0; globaluserinfo.unattached && i < globaluserinfo.unattached.length; i++) {
//////////////////////////////////////////////////
if (globaluserinfo.unattached[i].wiki === mw.config.get('wgDBname')) {
// Dab-fixing code
lockedSulAccountIsAttachedToThis = false;
//
break;

}
function retargetDab(newTarget, oldTarget, friendlyCurrentArticleName, titleToEdit) {
}
log('retargetDab: newTarget=' + newTarget + ' oldTarget=' + oldTarget);
if (lockedSulAccountIsAttachedToThis) {
return changeLinkTargetLink({
if ('locked'in globaluserinfo) {
newTarget: newTarget,
ret.push('<b><i>' + popupString('LOCKED') + '</i></b>');
text: newTarget.split(' ').join('&nbsp;'),
}
hint: tprintf('disambigHint', [newTarget]),
if ('hidden'in globaluserinfo) {
summary: simplePrintf(getValueOf('popupFixDabsSummary'), [
ret.push('<b><i>' + popupString('HIDDEN') + '</i></b>');
friendlyCurrentArticleName,
}
newTarget,
}
]),
}
clickButton: getValueOf('popupDabsAutoClick'),
if (getValueOf('popupShowGender') && user.gender) {
minor: true,
switch (user.gender) {
oldTarget: oldTarget,
case 'male':
watch: getValueOf('popupWatchDisambiggedPages'),
ret.push(popupString('he/him') + ' · ');
title: titleToEdit,
break;
});
case 'female':
}
ret.push(popupString('she/her') + ' · ');

break;
function listLinks(wikitext, oldTarget, titleToEdit) {
}
// mediawiki strips trailing spaces, so we do the same
}
// testcase: https://en.wikipedia.org/w/index.php?title=Radial&oldid=97365633
if (user.groups) {
var reg = RegExp('\\[\\[([^|]*?) *(\\||\\]\\])', 'gi');
user.groups.forEach(function(groupName) {
var ret = [];
if (['*', 'user', 'autoconfirmed', 'extendedconfirmed', 'named'].indexOf(groupName) === -1) {
var splitted = wikitext.parenSplit(reg);
ret.push(pg.escapeQuotesHTML(mw.message('group-' + groupName + '-member', user.gender).text()));
// ^[a-z]+ should match interwiki links, hopefully (case-insensitive)
}
// and ^[a-z]* should match those and [[:Category...]] style links too
});
var omitRegex = RegExp('^[a-z]*:|^[Ss]pecial:|^[Ii]mage|^[Cc]ategory');
}
var friendlyCurrentArticleName = oldTarget.toString();
if (globaluserinfo && globaluserinfo.groups) {
var wikPos = getValueOf('popupDabWiktionary');
globaluserinfo.groups.forEach(function(groupName) {

ret.push('<i>' + pg.escapeQuotesHTML(mw.message('group-' + groupName + '-member', user.gender).text()) + '</i>');
});
for (var i = 1; i < splitted.length; i = i + 3) {
if (
}
typeof splitted[i] == typeof 'string' &&
if (user.registration) {
splitted[i].length > 0 &&
ret.push(pg.escapeQuotesHTML((user.editcount ? user.editcount : '0') + popupString(' edits since: ') + (user.registration ? formattedDate(new Date(user.registration)) : '')));
!omitRegex.test(splitted[i])
}
) {
}
ret.push(retargetDab(splitted[i], oldTarget, friendlyCurrentArticleName, titleToEdit));
if (queryobj.usercontribs && queryobj.usercontribs.length) {
} /* if */
ret.push(popupString('last edit on ') + formattedDate(new Date(queryobj.usercontribs[0].timestamp)));
} /* for loop */
}

if (queryobj.blocks) {
ret = rmDupesFromSortedList(ret.sort());
ret.push(popupString('IP user'));

for (var l = 0; l < queryobj.blocks.length; l++) {
if (wikPos) {
var rbstr = queryobj.blocks[l].rangestart === queryobj.blocks[l].rangeend ? 'BLOCK' : 'RANGEBLOCK';
var wikTarget =
rbstr = !Array.isArray(queryobj.blocks[l].restrictions) ? 'Has ' + rbstr.toLowerCase() + 's' : rbstr + 'ED';
'wiktionary:' +
ret.push('<b>' + popupString(rbstr) + '</b>');
friendlyCurrentArticleName.replace(RegExp('^(.+)\\s+[(][^)]+[)]\\s*$'), '$1');
}

}
var meth;
for (var m = 0; m < ret.length - 1; m++) {
if (wikPos.toLowerCase() == 'first') {
if (ret[m].length > 3 && ret[m].substring(ret[m].length - 3) === ' · ') {
meth = 'unshift';
ret[m] = ret[m] + ret[m + 1];
} else {
ret.splice(m + 1, 1);
meth = 'push';
m--;
}
}

}
ret[meth](retargetDab(wikTarget, oldTarget, friendlyCurrentArticleName, titleToEdit));
ret = '<hr />' + ret.join(', ');
}
return ret;

}
ret.push(
function APIcontribsPreviewHTML(article, download, navpop) {
changeLinkTargetLink({
return APIhistoryPreviewHTML(article, download, navpop, true);
newTarget: null,
}
text: popupString('remove this link').split(' ').join('&nbsp;'),
function APIhistoryPreviewHTML(article, download, navpop, reallyContribs) {
hint: popupString('remove all links to this disambig page from this article'),
try {
clickButton: getValueOf('popupDabsAutoClick'),
var jsobj = getJsObj(download.data);
oldTarget: oldTarget,
var edits = [];
summary: simplePrintf(getValueOf('popupRmDabLinkSummary'), [friendlyCurrentArticleName]),
if (reallyContribs) {
watch: getValueOf('popupWatchDisambiggedPages'),
edits = jsobj.query.usercontribs;
title: titleToEdit,
} else {
})
edits = anyChild(jsobj.query.pages).revisions;
);
}
return ret;
var ret = editPreviewTable(article, edits, reallyContribs);
}
return ret;

} catch (someError) {
function rmDupesFromSortedList(list) {
return 'History preview failed :-(';
var ret = [];
}
}
for (var i = 0; i < list.length; ++i) {
if (ret.length === 0 || list[i] != ret[ret.length - 1]) {
function setupDebugging() {
ret.push(list[i]);
if (window.popupDebug) {
}
window.log = function(x) {
}
window.console.log(x);
return ret;
}
}
;

window.errlog = function(x) {
function makeFixDab(data, navpop) {
window.console.error(x);
// grab title from parent popup if there is one; default exists in changeLinkTargetLink
}
var titleToEdit = navpop.parentPopup && navpop.parentPopup.article.toString();
;
var list = listLinks(data, navpop.originalArticle, titleToEdit);
log('Initializing logger');
if (list.length === 0) {
} else {
log('listLinks returned empty list');
window.log = function() {}
return null;
;
}
window.errlog = function() {}
var html = '<hr />' + popupString('Click to disambiguate this link to:') + '<br>';
;
html += list.join(', ');
}
return html;
}
}
function loadImage(image, navpop) {

if (typeof image.stripNamespace != 'function') {
function makeFixDabs(wikiText, navpop) {
alert('loadImages bad');
if (
}
if (!getValueOf('popupImages')) {
getValueOf('popupFixDabs') &&
isDisambig(wikiText, navpop.article) &&
return;
Title.fromURL(location.href).namespaceId() != pg.nsSpecialId &&
}
navpop.article.talkPage()
if (!isValidImageName(image)) {
) {
return false;
setPopupHTML(makeFixDab(wikiText, navpop), 'popupFixDab', navpop.idNumber);
}
}
var art = image.urlString();
}
var url = pg.wiki.apiwikibase + '?format=json&formatversion=2&action=query';

url += '&prop=imageinfo&iiprop=url|mime&iiurlwidth=' + getValueOf('popupImageSizeLarge');
function popupRedlinkHTML(article) {
url += '&titles=' + art;
return changeLinkTargetLink({
pendingNavpopTask(navpop);
newTarget: null,
var callback = function(d) {
text: popupString('remove this link').split(' ').join('&nbsp;'),
popupsInsertImage(navpop.idNumber, navpop, d);
hint: popupString('remove all links to this page from this article'),
};
clickButton: getValueOf('popupRedlinkAutoClick'),
var go = function() {
oldTarget: article.toString(),
getPageWithCaching(url, callback, navpop);
summary: simplePrintf(getValueOf('popupRedlinkSummary'), [article.toString()]),
return true;
});
};
}
if (navpop.visible || !getValueOf('popupLazyDownloads')) {
// ENDFILE: dab.js
go();

} else {
// STARTFILE: htmloutput.js
navpop.addHook(go, 'unhide', 'after', 'DOWNLOAD_IMAGE_QUERY_DATA');

}
// this has to use a timer loop as we don't know if the DOM element exists when we want to set the text
}
function setPopupHTML(str, elementId, popupId, onSuccess, append) {
function popupsInsertImage(id, navpop, download) {
if (typeof popupId === 'undefined') {
log('popupsInsertImage');
//console.error('popupId is not defined in setPopupHTML, html='+str.substring(0,100));
var imageinfo;
popupId = pg.idNumber;
try {
}
var jsObj = getJsObj(download.data);

var imagepage = anyChild(jsObj.query.pages);
var popupElement = document.getElementById(elementId + popupId);
if (typeof imagepage.imageinfo === 'undefined') {
if (popupElement) {
return;
if (!append) {
}
popupElement.innerHTML = '';
imageinfo = imagepage.imageinfo[0];
}
} catch (someError) {
if (isString(str)) {
log('popupsInsertImage failed :(');
popupElement.innerHTML += str;
return;
} else {
}
popupElement.appendChild(str);
var popupImage = document.getElementById('popupImg' + id);
}
if (!popupImage) {
if (onSuccess) {
log('could not find insertion point for image');
onSuccess();
return;
}
}
setTimeout(checkPopupPosition, 100);
popupImage.width = getValueOf('popupImageSize');
return true;
popupImage.style.display = 'inline';
} else {
if (imageinfo.thumburl) {
// call this function again in a little while...
popupImage.src = imageinfo.thumburl;
setTimeout(function () {
} else if (imageinfo.mime.indexOf('image') === 0) {
setPopupHTML(str, elementId, popupId, onSuccess);
popupImage.src = imageinfo.url;
}, 600);
log('a thumb could not be found, using original image');
}
} else {
return null;
log("fullsize imagethumb, but not sure if it's an image");
}
}

var a = document.getElementById('popupImageLink' + id);
function setPopupTrailer(str, id) {
if (a === null) {
return setPopupHTML(str, 'popupData', id);
return null;
}
}

switch (getValueOf('popupThumbAction')) {
// args.navpopup is mandatory
case 'imagepage':
// optional: args.redir, args.redirTarget
if (pg.current.article.namespaceId() != pg.nsImageId) {
// FIXME: ye gods, this is ugly stuff
a.href = imageinfo.descriptionurl;
function fillEmptySpans(args) {
popTipsSoonFn('popupImage' + id)();
// if redir is present and true then redirTarget is mandatory
break;
var redir = true;
}
var rcid;
case 'sizetoggle':
if (typeof args != 'object' || typeof args.redir == 'undefined' || !args.redir) {
a.onclick = toggleSize;
redir = false;
a.title = popupString('Toggle image size');
}
return;
var a = args.navpopup.parentAnchor;
case 'linkfull':

a.href = imageinfo.url;
var article,
a.title = popupString('Open full-size image');
hint = null,
return;
oldid = null,
}
params = {};
}
if (redir && typeof args.redirTarget == typeof {}) {
function toggleSize() {
article = args.redirTarget;
var imgContainer = this;
//hint=article.hintValue();
if (!imgContainer) {
} else {
alert('imgContainer is null :/');
article = new Title().fromAnchor(a);
return;
hint = a.originalTitle || article.hintValue();
}
params = parseParams(a.href);
var img = imgContainer.firstChild;
oldid = getValueOf('popupHistoricalLinks') ? params.oldid : null;
if (!img) {
rcid = params.rcid;
alert('img is null :/');
}
return;
var x = {
}
article: article,
if (!img.style.width || img.style.width === '') {
hint: hint,
img.style.width = '100%';
oldid: oldid,
} else {
rcid: rcid,
img.style.width = '';
navpop: args.navpopup,
}
params: params,
}
};
function getValidImageFromWikiText(wikiText) {

var matched = null;
var structure = pg.structures[getValueOf('popupStructure')];
var match;
if (typeof structure != 'object') {
var t = removeMatchesUnless(wikiText, RegExp('(<!--[\\s\\S]*?-->)'), 1, RegExp('^<!--[^[]*popup', 'i'));
setPopupHTML(
while ((match = pg.re.image.exec(t))) {
'popupError',
var m = match[2] || match[6];
'Unknown structure (this should never happen): ' + pg.option.popupStructure,
if (isValidImageName(m)) {
args.navpopup.idNumber
matched = m;
);
break;
return;
}
}
}
var spans = flatten(pg.misc.layout);
pg.re.image.lastIndex = 0;
var numspans = spans.length;
if (!matched) {
var redirs = pg.misc.redirSpans;
return null;

}
for (var i = 0; i < numspans; ++i) {
return mw.config.get('wgFormattedNamespaces')[pg.nsImageId] + ':' + upcaseFirst(matched);
var found = redirs && redirs.indexOf(spans[i]) !== -1;
}
//log('redir='+redir+', found='+found+', spans[i]='+spans[i]);
function removeMatchesUnless(str, re1, parencount, re2) {
if ((found && !redir) || (!found && redir)) {
var split = str.parenSplit(re1);
//log('skipping this set of the loop');
var c = parencount + 1;
continue;
for (var i = 0; i < split.length; ++i) {
}
if (i % c === 0 || re2.test(split[i])) {
var structurefn = structure[spans[i]];
continue;
if (structurefn === undefined) {
}
// nothing to do for this structure part
split[i] = '';
continue;
}
}
return split.join('');
var setfn = setPopupHTML;
}
if (
function setNamespaces() {
getValueOf('popupActiveNavlinks') &&
pg.nsSpecialId = -1;
(spans[i].indexOf('popupTopLinks') === 0 || spans[i].indexOf('popupRedirTopLinks') === 0)
pg.nsMainspaceId = 0;
) {
pg.nsImageId = 6;
setfn = setPopupTipsAndHTML;
pg.nsUserId = 2;
}
pg.nsUsertalkId = 3;
switch (typeof structurefn) {
pg.nsCategoryId = 14;
case 'function':
pg.nsTemplateId = 10;
log(
}
'running ' +
function setRedirs() {
spans[i] +
var r = 'redirect';
'({article:' +
var R = 'REDIRECT';
x.article +
var redirLists = {
', hint:' +
ar: [R, 'تحويل'],
x.hint +
be: [r, 'перанакіраваньне'],
', oldid: ' +
bg: [r, 'пренасочване', 'виж'],
x.oldid +
bs: [r, 'Preusmjeri', 'preusmjeri', 'PREUSMJERI'],
'})'
bn: [R, 'পুনর্নির্দেশ'],
);
cs: [R, 'PŘESMĚRUJ'],
setfn(structurefn(x), spans[i], args.navpopup.idNumber);
cy: [r, 'ail-cyfeirio'],
break;
de: [R, 'WEITERLEITUNG'],
case 'string':
el: [R, 'ΑΝΑΚΑΤΕΥΘΥΝΣΗ'],
setfn(structurefn, spans[i], args.navpopup.idNumber);
eo: [R, 'ALIDIREKTU', 'ALIDIREKTI'],
break;
es: [R, 'REDIRECCIÓN'],
default:
et: [r, 'suuna'],
errlog('unknown thing with label ' + spans[i] + ' (span index was ' + i + ')');
ga: [r, 'athsheoladh'],
break;
gl: [r, 'REDIRECCIÓN', 'REDIRECIONAMENTO'],
}
he: [R, 'הפניה'],
}
hu: [R, 'ÁTIRÁNYÍTÁS'],
}
is: [r, 'tilvísun', 'TILVÍSUN'],

it: [R, 'RINVIA', 'Rinvia'],
// flatten an array
ja: [R, '転送'],
function flatten(list, start) {
mk: [r, 'пренасочување', 'види'],
var ret = [];
nds: [r, 'wiederleiden'],
if (typeof start == 'undefined') {
'nds-nl': [R, 'DEURVERWIEZING', 'DUURVERWIEZING'],
start = 0;
nl: [R, 'DOORVERWIJZING'],
}
nn: [r, 'omdiriger'],
for (var i = start; i < list.length; ++i) {
pl: [R, 'PATRZ', 'PRZEKIERUJ', 'TAM'],
if (typeof list[i] == typeof []) {
pt: [R, 'redir'],
return ret.concat(flatten(list[i])).concat(flatten(list, i + 1));
ru: [R, 'ПЕРЕНАПРАВЛЕНИЕ', 'ПЕРЕНАПР'],
} else {
sk: [r, 'presmeruj'],
ret.push(list[i]);
sr: [r, 'Преусмери', 'преусмери', 'ПРЕУСМЕРИ', 'Preusmeri', 'preusmeri', 'PREUSMERI'],
}
tr: [R, 'YÖNLENDİRME', 'yönlendirme', 'YÖNLENDİR', 'yönlendir'],
}
tt: [R, 'yünältü', 'перенаправление', 'перенапр'],
return ret;
uk: [R, 'ПЕРЕНАПРАВЛЕННЯ', 'ПЕРЕНАПР'],
}
vi: [r, 'đổi'],

yi: [R, 'ווייטערפירן'],
// Generate html for whole popup
zh: [R, '重定向'],
function popupHTML(a) {
};
getValueOf('popupStructure');
var redirList = redirLists[pg.wiki.lang] || [r, R];
var structure = pg.structures[pg.option.popupStructure];
pg.re.redirect = RegExp('^\\s*[#](' + redirList.join('|') + ').*?\\[{2}([^\\|\\]]*)(|[^\\]]*)?\\]{2}\\s*(.*)', 'i');
if (typeof structure != 'object') {
}
//return 'Unknown structure: '+pg.option.popupStructure;
function setInterwiki() {
// override user choice
if (pg.wiki.wikimedia) {
pg.option.popupStructure = pg.optionDefault.popupStructure;
pg.wiki.interwiki = 'aa|ab|ace|af|ak|als|am|an|ang|ar|arc|arz|as|ast|av|ay|az|ba|bar|bat-smg|bcl|be|be-x-old|bg|bh|bi|bjn|bm|bn|bo|bpy|br|bs|bug|bxr|ca|cbk-zam|cdo|ce|ceb|ch|cho|chr|chy|ckb|co|cr|crh|cs|csb|cu|cv|cy|da|de|diq|dsb|dv|dz|ee|el|eml|en|eo|es|et|eu|ext|fa|ff|fi|fiu-vro|fj|fo|fr|frp|frr|fur|fy|ga|gag|gan|gd|gl|glk|gn|got|gu|gv|ha|hak|haw|he|hi|hif|ho|hr|hsb|ht|hu|hy|hz|ia|id|ie|ig|ii|ik|ilo|io|is|it|iu|ja|jbo|jv|ka|kaa|kab|kbd|kg|ki|kj|kk|kl|km|kn|ko|koi|kr|krc|ks|ksh|ku|kv|kw|ky|la|lad|lb|lbe|lg|li|lij|lmo|ln|lo|lt|ltg|lv|map-bms|mdf|mg|mh|mhr|mi|mk|ml|mn|mo|mr|mrj|ms|mt|mus|mwl|my|myv|mzn|na|nah|nap|nds|nds-nl|ne|new|ng|nl|nn|no|nov|nrm|nv|ny|oc|om|or|os|pa|pag|pam|pap|pcd|pdc|pfl|pi|pih|pl|pms|pnb|pnt|ps|pt|qu|rm|rmy|rn|ro|roa-rup|roa-tara|ru|rue|rw|sa|sah|sc|scn|sco|sd|se|sg|sh|si|simple|sk|sl|sm|sn|so|sq|sr|srn|ss|st|stq|su|sv|sw|szl|ta|te|tet|tg|th|ti|tk|tl|tn|to|tpi|tr|ts|tt|tum|tw|ty|udm|ug|uk|ur|uz|ve|vec|vi|vls|vo|wa|war|wo|wuu|xal|xh|yi|yo|za|zea|zh|zh-classical|zh-min-nan|zh-yue|zu';
return popupHTML(a);
pg.re.interwiki = RegExp('^' + pg.wiki.interwiki + ':');
}
} else {
if (typeof structure.popupLayout != 'function') {
pg.wiki.interwiki = null;
return 'Bad layout';
pg.re.interwiki = RegExp('^$');
}
}
pg.misc.layout = structure.popupLayout();
}
if (typeof structure.popupRedirSpans === 'function') {
function nsRe(namespaceId) {
pg.misc.redirSpans = structure.popupRedirSpans();
var imageNamespaceVariants = [];
} else {
jQuery.each(mw.config.get('wgNamespaceIds'), function(_localizedNamespaceLc, _namespaceId) {
pg.misc.redirSpans = [];
if (_namespaceId != namespaceId) {
}
return;
return makeEmptySpans(pg.misc.layout, a.navpopup);
}
}
_localizedNamespaceLc = upcaseFirst(_localizedNamespaceLc);

imageNamespaceVariants.push(mw.util.escapeRegExp(_localizedNamespaceLc).split(' ').join('[ _]'));
function makeEmptySpans(list, navpop) {
imageNamespaceVariants.push(mw.util.escapeRegExp(encodeURI(_localizedNamespaceLc)));
var ret = '';
});
for (var i = 0; i < list.length; ++i) {
return '(?:' + imageNamespaceVariants.join('|') + ')';
if (typeof list[i] == typeof '') {
}
ret += emptySpanHTML(list[i], navpop.idNumber, 'div');
function nsReImage() {
} else if (typeof list[i] == typeof [] && list[i].length > 0) {
return nsRe(pg.nsImageId);
ret = ret.parenSplit(RegExp('(</[^>]*?>$)')).join(makeEmptySpans(list[i], navpop));
}
} else if (typeof list[i] == typeof {} && list[i].nodeType) {
function getEditboxSelection() {
ret += emptySpanHTML(list[i].name, navpop.idNumber, list[i].nodeType);
var editbox;
}
try {
}
editbox = document.editform.wpTextbox1;
return ret;
} catch (dang) {
}
return;

}
function emptySpanHTML(name, id, tag, classname) {
if (document.selection) {
tag = tag || 'span';
return document.selection.createRange().text;
if (!classname) {
}
classname = emptySpanHTML.classAliases[name];
var selStart = editbox.selectionStart;
}
var selEnd = editbox.selectionEnd;
classname = classname || name;
return editbox.value.substring(selStart, selEnd);
if (name == getValueOf('popupDragHandle')) {
}
classname += ' popupDragHandle';
function doSelectionPopup() {
}
var sel = getEditboxSelection();
return simplePrintf('<%s id="%s" class="%s"></%s>', [tag, name + id, classname, tag]);
var open = sel.indexOf('[[');
}
var pipe = sel.indexOf('|');
emptySpanHTML.classAliases = { popupSecondPreview: 'popupPreview' };
var close = sel.indexOf(']]');

if (open == -1 || (pipe == -1 && close == -1)) {
// generate html for popup image
return;
// <a id="popupImageLinkn"><img id="popupImagen">
}
// where n=idNumber
if ((pipe != -1 && open > pipe) || (close != -1 && open > close)) {
function imageHTML(article, idNumber) {
return;
return simplePrintf(
}
'<a id="popupImageLink$1">' +
var article = new Title(sel.substring(open + 2, pipe < 0 ? close : pipe));
'<img align="right" valign="top" id="popupImg$1" style="display: none;"></img>' +
if (getValueOf('popupOnEditSelection') == 'boxpreview') {
'</a>',
return doSeparateSelectionPopup(sel, article);
[idNumber]
}
);
if (close > 0 && sel.substring(close + 2).indexOf('[[') >= 0) {
}
return;

}
function popTipsSoonFn(id, when, popData) {
var a = document.createElement('a');
if (!when) {
a.href = pg.wiki.titlebase + article.urlString();
when = 250;
mouseOverWikiLink2(a);
}
if (a.navpopup) {
var popTips = function () {
a.navpopup.addHook(function() {
setupTooltips(document.getElementById(id), false, true, popData);
runStopPopupTimer(a.navpopup);
};
}, 'unhide', 'after');
return function () {
}
setTimeout(popTips, when, popData);
}
};
function doSeparateSelectionPopup(str, article) {
}
var div = document.getElementById('selectionPreview');

if (!div) {
function setPopupTipsAndHTML(html, divname, idnumber, popData) {
div = document.createElement('div');
setPopupHTML(
div.id = 'selectionPreview';
html,
try {
divname,
var box = document.editform.wpTextbox1;
idnumber,
box.parentNode.insertBefore(div, box);
getValueOf('popupSubpopups') ? popTipsSoonFn(divname + idnumber, null, popData) : null
} catch (error) {
);
return;
}
}
// ENDFILE: htmloutput.js
}

var p = prepPreviewmaker(str, article, newNavpopup(document.createElement('a'), article));
// STARTFILE: mouseout.js
p.makePreview();
//////////////////////////////////////////////////
if (p.html) {
// fuzzy checks
div.innerHTML = p.html;

}
function fuzzyCursorOffMenus(x, y, fuzz, parent) {
div.ranSetupTooltipsAlready = false;
if (!parent) {
popTipsSoonFn('selectionPreview')();
return null;
}
}
function Mousetracker() {
var uls = parent.getElementsByTagName('ul');
this.loopDelay = 400;
for (var i = 0; i < uls.length; ++i) {
this.timer = null;
if (uls[i].className == 'popup_menu') {
this.active = false;
if (uls[i].offsetWidth > 0) {
this.dirty = true;
return false;
this.hooks = [];
}
}
} // else {document.title+='.';}
Mousetracker.prototype.addHook = function(f) {
}
this.hooks.push(f);
return true;
}
}
;

Mousetracker.prototype.runHooks = function() {
function checkPopupPosition() {
if (!this.hooks || !this.hooks.length) {
// stop the popup running off the right of the screen
return;
// FIXME avoid pg.current.link
}
if (pg.current.link && pg.current.link.navpopup) {
var remove = false;
pg.current.link.navpopup.limitHorizontalPosition();
var removeObj = {};
}
var x = this.x
}
, y = this.y

, len = this.hooks.length;
function mouseOutWikiLink() {
for (var i = 0; i < len; ++i) {
//console ('mouseOutWikiLink');
if (this.hooks[i](x, y) === true) {
var a = this;
remove = true;

removeObj[i] = true;
removeModifierKeyHandler(a);
}

}
if (a.navpopup === null || typeof a.navpopup === 'undefined') {
if (remove) {
return;
this.removeHooks(removeObj);
}
}
if (!a.navpopup.isVisible()) {
}
a.navpopup.banish();
;
return;
Mousetracker.prototype.removeHooks = function(removeObj) {
}
var newHooks = [];
restoreTitle(a);
var len = this.hooks.length;
Navpopup.tracker.addHook(posCheckerHook(a.navpopup));
for (var i = 0; i < len; ++i) {
}
if (!removeObj[i]) {

newHooks.push(this.hooks[i]);
function posCheckerHook(navpop) {
}
return function () {
}
if (!navpop.isVisible()) {
this.hooks = newHooks;
return true; /* remove this hook */
}
}
;
if (Navpopup.tracker.dirty) {
Mousetracker.prototype.track = function(e) {
return false;
e = e || window.event;
}
var x, y;
var x = Navpopup.tracker.x,
if (e) {
y = Navpopup.tracker.y;
if (e.pageX) {
var mouseOverNavpop =
x = e.pageX;
navpop.isWithin(x, y, navpop.fuzz, navpop.mainDiv) ||
y = e.pageY;
!fuzzyCursorOffMenus(x, y, navpop.fuzz, navpop.mainDiv);
} else if (typeof e.clientX != 'undefined') {

var left, top, docElt = document.documentElement;
// FIXME it'd be prettier to do this internal to the Navpopup objects
if (docElt) {
var t = getValueOf('popupHideDelay');
left = docElt.scrollLeft;
if (t) {
}
t = t * 1000;
left = left || document.body.scrollLeft || document.scrollLeft || 0;
}
if (docElt) {
if (!t) {
top = docElt.scrollTop;
if (!mouseOverNavpop) {
}
if (navpop.parentAnchor) {
top = top || document.body.scrollTop || document.scrollTop || 0;
restoreTitle(navpop.parentAnchor);
x = e.clientX + left;
}
y = e.clientY + top;
navpop.banish();
} else {
return true; /* remove this hook */
return;
}
}
return false;
this.setPosition(x, y);
}
}
// we have a hide delay set
}
var d = Number(new Date());
;
if (!navpop.mouseLeavingTime) {
Mousetracker.prototype.setPosition = function(x, y) {
navpop.mouseLeavingTime = d;
this.x = x;
return false;
this.y = y;
}
if (this.dirty || this.hooks.length === 0) {
if (mouseOverNavpop) {
this.dirty = false;
navpop.mouseLeavingTime = null;
return;
return false;
}
}
if (typeof this.lastHook_x != 'number') {
if (d - navpop.mouseLeavingTime > t) {
this.lastHook_x = -100;
navpop.mouseLeavingTime = null;
this.lastHook_y = -100;
navpop.banish();
}
return true; /* remove this hook */
var diff = (this.lastHook_x - x) * (this.lastHook_y - y);
}
diff = diff >= 0 ? diff : -diff;
return false;
if (diff > 1) {
};
this.lastHook_x = x;
}
this.lastHook_y = y;

if (this.dirty) {
function runStopPopupTimer(navpop) {
this.dirty = false;
// at this point, we should have left the link but remain within the popup
} else {
// so we call this function again until we leave the popup.
this.runHooks();
if (!navpop.stopPopupTimer) {
}
navpop.stopPopupTimer = setInterval(posCheckerHook(navpop), 500);
}
navpop.addHook(
}
function () {
;
clearInterval(navpop.stopPopupTimer);
Mousetracker.prototype.enable = function() {
},
if (this.active) {
'hide',
return;
'before'
}
);
this.active = true;
}
this.savedHandler = document.onmousemove;
}
var savedThis = this;
// ENDFILE: mouseout.js
document.onmousemove = function(e) {

savedThis.track.apply(savedThis, [e]);
// STARTFILE: previewmaker.js
}
/**
;
* @fileoverview
if (this.loopDelay) {
* Defines the {@link Previewmaker} object, which generates short previews from wiki markup.
this.timer = setInterval(function() {
*/
savedThis.runHooks();

}, this.loopDelay);
/**
}
* Creates a new Previewmaker
}
* @constructor
;
* @class The Previewmaker class. Use an instance of this to generate short previews from Wikitext.
Mousetracker.prototype.disable = function() {
* @param {String} wikiText The Wikitext source of the page we wish to preview.
if (!this.active) {
* @param {String} baseUrl The url we should prepend when creating relative urls.
return;
* @param {Navpopup} owner The navpop associated to this preview generator
}
*/
if (typeof this.savedHandler === 'function') {
function Previewmaker(wikiText, baseUrl, owner) {
document.onmousemove = this.savedHandler;
/** The wikitext which is manipulated to generate the preview. */
} else {
this.originalData = wikiText;
delete document.onmousemove;
this.baseUrl = baseUrl;
}
this.owner = owner;
if (this.timer) {

clearInterval(this.timer);
this.maxCharacters = getValueOf('popupMaxPreviewCharacters');
}
this.maxSentences = getValueOf('popupMaxPreviewSentences');
this.active = false;

}
this.setData();
;
}
function Navpopup() {

this.uid = Navpopup.uid++;
Previewmaker.prototype.setData = function () {
this.visible = false;
var maxSize = Math.max(10000, 2 * this.maxCharacters);
this.noshow = false;
this.data = this.originalData.substring(0, maxSize);
this.hooks = {
};
create: [],

unhide: [],
/**
hide: [],
* Remove HTML comments
};
* @private
this.hookIds = {};
*/
this.downloads = [];
Previewmaker.prototype.killComments = function () {
this.pending = null;
// this also kills one trailing newline, eg [[diamyo]]
this.fuzz = 5;
this.data = this.data.replace(
this.constrained = true;
RegExp('^<!--[^$]*?-->\\n|\\n<!--[^$]*?-->(?=\\n)|<!--[^$]*?-->', 'g'),
this.width = 0;
''
this.height = 0;
);
this.mainDiv = null;
};
this.createMainDiv();

}
/**
Navpopup.uid = 0;
* @private
Navpopup.prototype.isVisible = function() {
*/
return this.visible;
Previewmaker.prototype.killDivs = function () {
}
// say goodbye, divs (can be nested, so use * not *?)
;
this.data = this.data.replace(RegExp('< *div[^>]* *>[\\s\\S]*?< */ *div *>', 'gi'), '');
Navpopup.prototype.reposition = function(x, y, noLimitHor) {
};
log('reposition(' + x + ',' + y + ',' + noLimitHor + ')');

if (typeof x != 'undefined' && x !== null) {
/**
this.left = x;
* @private
}
*/
if (typeof y != 'undefined' && y !== null) {
Previewmaker.prototype.killGalleries = function () {
this.top = y;
this.data = this.data.replace(RegExp('< *gallery[^>]* *>[\\s\\S]*?< */ *gallery *>', 'gi'), '');
}
};
if (typeof this.left != 'undefined' && typeof this.top != 'undefined') {

this.mainDiv.style.left = this.left + 'px';
/**
this.mainDiv.style.top = this.top + 'px';
* @private
}
*/
if (!noLimitHor) {
Previewmaker.prototype.kill = function (opening, closing, subopening, subclosing, repl) {
this.limitHorizontalPosition();
var oldk = this.data;
}
var k = this.killStuff(this.data, opening, closing, subopening, subclosing, repl);
}
while (k.length < oldk.length) {
;
oldk = k;
Navpopup.prototype.limitHorizontalPosition = function() {
k = this.killStuff(k, opening, closing, subopening, subclosing, repl);
if (!this.constrained || this.tooWide) {
}
return;
this.data = k;
}
};
this.updateDimensions();

var x = this.left;
/**
var w = this.width;
* @private
var cWidth = document.body.clientWidth;
*/
if (x + w >= cWidth || (x > 0 && this.maxWidth && this.width < this.maxWidth && this.height > this.width && x > cWidth - this.maxWidth)) {
Previewmaker.prototype.killStuff = function (
this.mainDiv.style.left = '-10000px';
txt,
this.mainDiv.style.width = this.maxWidth + 'px';
opening,
var naturalWidth = parseInt(this.mainDiv.offsetWidth, 10);
closing,
var newLeft = cWidth - naturalWidth - 1;
subopening,
if (newLeft < 0) {
subclosing,
newLeft = 0;
repl
this.tooWide = true;
) {
}
var op = this.makeRegexp(opening);
log('limitHorizontalPosition: moving to (' + newLeft + ',' + this.top + ');' + ' naturalWidth=' + naturalWidth + ', clientWidth=' + cWidth);
this.reposition(newLeft, null, true);
var cl = this.makeRegexp(closing, '^');
var sb = subopening ? this.makeRegexp(subopening, '^') : null;
}
var sc = subclosing ? this.makeRegexp(subclosing, '^') : cl;
}
if (!op || !cl) {
;
alert('Navigation Popups error: op or cl is null! something is wrong.');
Navpopup.highest = 1000;
return;
Navpopup.prototype.raise = function() {
}
this.mainDiv.style.zIndex = Navpopup.highest + 1;
if (!op.test(txt)) {
++Navpopup.highest;
return txt;
}
}
;
var ret = '';
Navpopup.prototype.show = function() {
var opResult = op.exec(txt);
if (this.noshow) {
ret = txt.substring(0, opResult.index);
return;
txt = txt.substring(opResult.index + opResult[0].length);
}
var depth = 1;
this.reposition();
while (txt.length > 0) {
this.raise();
var removal = 0;
this.unhide();
if (depth == 1 && cl.test(txt)) {
}
depth--;
;
removal = cl.exec(txt)[0].length;
Navpopup.prototype.showSoonIfStable = function(time) {
} else if (depth > 1 && sc.test(txt)) {
log('showSoonIfStable, time=' + time);
depth--;
if (this.visible) {
removal = sc.exec(txt)[0].length;
return;
} else if (sb && sb.test(txt)) {
}
depth++;
this.noshow = false;
removal = sb.exec(txt)[0].length;
this.stable_x = -10000;
}
this.stable_y = -10000;
if (!removal) {
var stableShow = function() {
removal = 1;
log('stableShow called');
}
var new_x = Navpopup.tracker.x
txt = txt.substring(removal);
, new_y = Navpopup.tracker.y;
if (depth === 0) {
var dx = savedThis.stable_x - new_x
break;
, dy = savedThis.stable_y - new_y;
}
var fuzz2 = 0;
}
if (dx * dx <= fuzz2 && dy * dy <= fuzz2) {
return ret + (repl || '') + txt;
log('mouse is stable');
};
clearInterval(savedThis.showSoonStableTimer);

savedThis.reposition.apply(savedThis, [new_x + 2, new_y + 2]);
/**
savedThis.show.apply(savedThis, []);
* @private
savedThis.limitHorizontalPosition.apply(savedThis, []);
*/
return;
Previewmaker.prototype.makeRegexp = function (x, prefix, suffix) {
}
prefix = prefix || '';
savedThis.stable_x = new_x;
suffix = suffix || '';
savedThis.stable_y = new_y;
var reStr = '';
};
var savedThis = this;
var flags = '';
if (isString(x)) {
this.showSoonStableTimer = setInterval(stableShow, time / 2);
reStr = prefix + literalizeRegex(x) + suffix;
}
} else if (isRegExp(x)) {
;
var s = x.toString().substring(1);
Navpopup.prototype.banish = function() {
var sp = s.split('/');
log('banish called');
flags = sp[sp.length - 1];
this.noshow = true;
sp[sp.length - 1] = '';
if (this.showSoonStableTimer) {
s = sp.join('/');
log('clearing showSoonStableTimer');
s = s.substring(0, s.length - 1);
clearInterval(this.showSoonStableTimer);
reStr = prefix + s + suffix;
}
} else {
this.hide();
log('makeRegexp failed');
}
}
;

Navpopup.prototype.runHooks = function(key, when) {
log('makeRegexp: got reStr=' + reStr + ', flags=' + flags);
if (!this.hooks[key]) {
return RegExp(reStr, flags);
return;
};
}

var keyHooks = this.hooks[key];
/**
var len = keyHooks.length;
* @private
for (var i = 0; i < len; ++i) {
*/
if (keyHooks[i] && keyHooks[i].when == when) {
Previewmaker.prototype.killBoxTemplates = function () {
if (keyHooks[i].hook.apply(this, [])) {
// taxobox removal... in fact, there's a saudiprincebox_begin, so let's be more general
if (keyHooks[i].hookId) {
// also, have float_begin, ... float_end
delete this.hookIds[keyHooks[i].hookId];
this.kill(RegExp('[{][{][^{}\\s|]*?(float|box)[_ ](begin|start)', 'i'), /[}][}]\s*/, '{{');
}

keyHooks[i] = null;
// infoboxes etc
}
// from [[User:Zyxw/popups.js]]: kill frames too
}
this.kill(RegExp('[{][{][^{}\\s|]*?(infobox|elementbox|frame)[_ ]', 'i'), /[}][}]\s*/, '{{');
}
};
}

;
/**
Navpopup.prototype.addHook = function(hook, key, when, uid) {
* @private
when = when || 'after';
*/
if (!this.hooks[key]) {
Previewmaker.prototype.killTemplates = function () {
return;
this.kill('{{', '}}', '{', '}', ' ');
}
};
var hookId = null;

if (uid) {
/**
hookId = [key, when, uid].join('|');
* @private
if (this.hookIds[hookId]) {
*/
return;
Previewmaker.prototype.killTables = function () {
}
// tables are bad, too
this.hookIds[hookId] = true;
// this can be slow, but it's an inprovement over a browser hang
}
// torture test: [[Comparison_of_Intel_Central_Processing_Units]]
this.hooks[key].push({
this.kill('{|', /[|]}\s*/, '{|');
hook: hook,
this.kill(/<table.*?>/i, /<\/table.*?>/i, /<table.*?>/i);
when: when,
// remove lines starting with a pipe for the hell of it (?)
hookId: hookId
this.data = this.data.replace(RegExp('^[|].*$', 'mg'), '');
});
};
}

;
/**
Navpopup.prototype.createMainDiv = function() {
* @private
if (this.mainDiv) {
*/
return;
Previewmaker.prototype.killImages = function () {
}
var forbiddenNamespaceAliases = [];
this.runHooks('create', 'before');
jQuery.each(mw.config.get('wgNamespaceIds'), function (_localizedNamespaceLc, _namespaceId) {
var mainDiv = document.createElement('div');
if (_namespaceId != pg.nsImageId && _namespaceId != pg.nsCategoryId) {
var savedThis = this;
return;
mainDiv.onclick = function(e) {
}
savedThis.onclickHandler(e);
forbiddenNamespaceAliases.push(_localizedNamespaceLc.split(' ').join('[ _]')); //todo: escape regexp fragments!
}
});
;

mainDiv.className = this.className ? this.className : 'navpopup_maindiv';
// images and categories are a nono
mainDiv.id = mainDiv.className + this.uid;
this.kill(
mainDiv.style.position = 'absolute';
RegExp('[[][[]\\s*(' + forbiddenNamespaceAliases.join('|') + ')\\s*:', 'i'),
mainDiv.style.minWidth = '350px';
/\]\]\s*/,
mainDiv.style.display = 'none';
'[',
mainDiv.className = 'navpopup';
']'
mainDiv.navpopup = this;
);
this.mainDiv = mainDiv;
};
document.body.appendChild(mainDiv);

this.runHooks('create', 'after');
/**
}
* @private
;
*/
Navpopup.prototype.onclickHandler = function() {
Previewmaker.prototype.killHTML = function () {
this.raise();
// kill <ref ...>...</ref>
}
this.kill(/<ref\b[^/>]*?>/i, /<\/ref>/i);
;

Navpopup.prototype.makeDraggable = function(handleName) {
// let's also delete entire lines starting with <. it's worth a try.
if (!this.mainDiv) {
this.data = this.data.replace(RegExp('(^|\\n) *<.*', 'g'), '\n');
this.createMainDiv();

}
// and those pesky html tags, but not <nowiki> or <blockquote>
var drag = new Drag();
var splitted = this.data.parenSplit(/(<[\w\W]*?(?:>|$|(?=<)))/);
if (!handleName) {
var len = splitted.length;
drag.startCondition = function(e) {
try {
for (var i = 1; i < len; i = i + 2) {
switch (splitted[i]) {
if (!e.shiftKey) {
case '<nowiki>':
return false;
case '</nowiki>':
}
case '<blockquote>':
} catch (err) {
case '</blockquote>':
return false;
break;
}
default:
return true;
splitted[i] = '';
}
}
;
}
}
this.data = splitted.join('');
var dragHandle;
};
if (handleName) {

dragHandle = document.getElementById(handleName);
/**
}
* @private
if (!dragHandle) {
*/
dragHandle = this.mainDiv;
Previewmaker.prototype.killChunks = function () {
}
// heuristics alert
var np = this;
// chunks of italic text? you crazy, man?
drag.endHook = function(x, y) {
var italicChunkRegex = new RegExp(
Navpopup.tracker.dirty = true;
"((^|\\n)\\s*:*\\s*''[^']([^']|'''|'[^']){20}(.|\\n[^\\n])*''[.!?\\s]*\\n)+",
np.reposition(x, y);
'g'
}
);
;
// keep stuff separated, though, so stick in \n (fixes [[Union Jack]]?
drag.init(dragHandle, this.mainDiv);
this.data = this.data.replace(italicChunkRegex, '\n');
}
};
;

Navpopup.prototype.hide = function() {
/**
this.runHooks('hide', 'before');
* @private
this.abortDownloads();
*/
if (typeof this.visible != 'undefined' && this.visible) {
Previewmaker.prototype.mopup = function () {
this.mainDiv.style.display = 'none';
// we simply *can't* be doing with horizontal rules right now
this.visible = false;
this.data = this.data.replace(RegExp('^-{4,}', 'mg'), '');
}

this.runHooks('hide', 'after');
// no indented lines
}
this.data = this.data.replace(RegExp('(^|\\n) *:[^\\n]*', 'g'), '');
;

Navpopup.prototype.unhide = function() {
// replace __TOC__, __NOTOC__ and whatever else there is
this.runHooks('unhide', 'before');
// this'll probably do
if (typeof this.visible != 'undefined' && !this.visible) {
this.data = this.data.replace(RegExp('^__[A-Z_]*__ *$', 'gmi'), '');
this.mainDiv.style.display = 'inline';
};
this.visible = true;

}
/**
this.runHooks('unhide', 'after');
* @private
}
*/
;
Navpopup.prototype.setInnerHTML = function(html) {
Previewmaker.prototype.firstBit = function () {
// dont't be givin' me no subsequent paragraphs, you hear me?
this.mainDiv.innerHTML = html;
/// first we "normalize" section headings, removing whitespace after, adding before
}
var d = this.data;
;

Navpopup.prototype.updateDimensions = function() {
if (getValueOf('popupPreviewCutHeadings')) {
this.width = parseInt(this.mainDiv.offsetWidth, 10);
this.data = this.data.replace(RegExp('\\s*(==+[^=]*==+)\\s*', 'g'), '\n\n$1 ');
this.height = parseInt(this.mainDiv.offsetHeight, 10);
/// then we want to get rid of paragraph breaks whose text ends badly
}
this.data = this.data.replace(RegExp('([:;]) *\\n{2,}', 'g'), '$1\n');
;

Navpopup.prototype.isWithin = function(x, y) {
this.data = this.data.replace(RegExp('^[\\s\\n]*'), '');
if (!this.visible) {
var stuff = RegExp('^([^\\n]|\\n[^\\n\\s])*').exec(this.data);
return false;
if (stuff) {
}
d = stuff[0];
this.updateDimensions();
}
var fuzz = this.fuzz || 0;
if (!getValueOf('popupPreviewFirstParOnly')) {
return (x + fuzz >= this.left && x - fuzz <= this.left + this.width && y + fuzz >= this.top && y - fuzz <= this.top + this.height);
d = this.data;
}
}
;

Navpopup.prototype.addDownload = function(download) {
/// now put \n\n after sections so that bullets and numbered lists work
if (!download) {
d = d.replace(RegExp('(==+[^=]*==+)\\s*', 'g'), '$1\n\n');
return;
}
}

this.downloads.push(download);
// Split sentences. Superfluous sentences are RIGHT OUT.
}
// note: exactly 1 set of parens here needed to make the slice work
;
d = d.parenSplit(RegExp('([!?.]+["' + "'" + ']*\\s)', 'g'));
Navpopup.prototype.abortDownloads = function() {
// leading space is bad, mmkay?
for (var i = 0; i < this.downloads.length; ++i) {
d[0] = d[0].replace(RegExp('^\\s*'), '');
var d = this.downloads[i];

if (d && d.abort) {
var notSentenceEnds = RegExp(
d.abort();
'([^.][a-z][.] *[a-z]|etc|sic|Dr|Mr|Mrs|Ms|St|no|op|cit|\\[[^\\]]*|\\s[A-Zvclm])$',
}
'i'
}
);
this.downloads = [];
d = this.fixSentenceEnds(d, notSentenceEnds);
}

;
this.fullLength = d.join('').length;
Navpopup.tracker = new Mousetracker();
var n = this.maxSentences;
function delFmt(x) {
var dd = this.firstSentences(d, n);
if (!x.length) {

return '';
do {
}
dd = this.firstSentences(d, n);
return "<del class='popupDiff'>" + x.join('') + '</del>';
--n;
}
} while (dd.length > this.maxCharacters && n !== 0);
function insFmt(x) {

if (!x.length) {
this.data = dd;
return '';
};
}

return "<ins class='popupDiff'>" + x.join('') + '</ins>';
/**
}
* @private
function countCrossings(a, b, i, eject) {
*/
if (!b[i].row && b[i].row !== 0) {
Previewmaker.prototype.fixSentenceEnds = function (strs, reg) {
return -1;
// take an array of strings, strs
}
// join strs[i] to strs[i+1] & strs[i+2] if strs[i] matches regex reg
var count = 0;

for (var j = 0; j < a.length; ++j) {
for (var i = 0; i < strs.length - 2; ++i) {
if (!a[j].row && a[j].row !== 0) {
if (reg.test(strs[i])) {
continue;
var a = [];
}
for (var j = 0; j < strs.length; ++j) {
if ((j - b[i].row) * (i - a[j].row) > 0) {
if (j < i) {
if (eject) {
a[j] = strs[j];
return true;
}
}
if (j == i) {
count++;
a[i] = strs[i] + strs[i + 1] + strs[i + 2];
}
}
}
if (j > i + 2) {
return count;
a[j - 2] = strs[j];
}
}
function shortenDiffString(str, context) {
}
var re = RegExp('(<del[\\s\\S]*?</del>|<ins[\\s\\S]*?</ins>)');
return this.fixSentenceEnds(a, reg);
var splitted = str.parenSplit(re);
}
var ret = [''];
}
for (var i = 0; i < splitted.length; i += 2) {
return strs;
if (splitted[i].length < 2 * context) {
};
ret[ret.length - 1] += splitted[i];

if (i + 1 < splitted.length) {
/**
ret[ret.length - 1] += splitted[i + 1];
* @private
}
*/
continue;
Previewmaker.prototype.firstSentences = function (strs, howmany) {
} else {
var t = strs.slice(0, 2 * howmany);
if (i > 0) {
return t.join('');
ret[ret.length - 1] += splitted[i].substring(0, context);
};
}

if (i + 1 < splitted.length) {
/**
ret.push(splitted[i].substring(splitted[i].length - context) + splitted[i + 1]);
* @private
}
*/
}
Previewmaker.prototype.killBadWhitespace = function () {
}
// also cleans up isolated '''', eg [[Suntory Sungoliath]]
while (ret.length > 0 && !ret[0]) {
this.data = this.data.replace(RegExp("^ *'+ *$", 'gm'), '');
ret = ret.slice(1);
};
}

return ret;
/**
}
* Runs the various methods to generate the preview.
function diffString(o, n, simpleSplit) {
* The preview is stored in the <code>html</html> field.
var splitRe = RegExp('([[]{2}|[\\]]{2}|[{]{2,3}|[}]{2,3}|[|]|=|<|>|[*:]+|\\s|\\b)');
* @private
var out, i, oSplitted, nSplitted;
*/
if (simpleSplit) {
Previewmaker.prototype.makePreview = function () {
oSplitted = o.split(/\b/);
if (
nSplitted = n.split(/\b/);
this.owner.article.namespaceId() != pg.nsTemplateId &&
} else {
this.owner.article.namespaceId() != pg.nsImageId
oSplitted = o.parenSplit(splitRe);
) {
nSplitted = n.parenSplit(splitRe);
this.killComments();
}
this.killDivs();
for (i = 0; i < oSplitted.length; ++i) {
this.killGalleries();
oSplitted[i] = oSplitted[i].entify();
this.killBoxTemplates();
}

for (i = 0; i < nSplitted.length; ++i) {
if (getValueOf('popupPreviewKillTemplates')) {
nSplitted[i] = nSplitted[i].entify();
this.killTemplates();
}
} else {
out = diff(oSplitted, nSplitted);
this.killMultilineTemplates();
var str = '';
}
var acc = [];
this.killTables();
var maxOutputPair = 0;
this.killImages();
for (i = 0; i < out.n.length; ++i) {
this.killHTML();
if (out.n[i].paired) {
this.killChunks();
if (maxOutputPair > out.n[i].row) {
this.mopup();
out.o[out.n[i].row] = out.o[out.n[i].row].text;

out.n[i] = out.n[i].text;
this.firstBit();
}
this.killBadWhitespace();
if (maxOutputPair < out.n[i].row) {
} else {
maxOutputPair = out.n[i].row;
this.killHTML();
}
}
}
this.html = wiki2html(this.data, this.baseUrl); // needs livepreview
}
this.fixHTML();
for (i = 0; i < out.o.length && !out.o[i].paired; ++i) {
this.stripLongTemplates();
acc.push(out.o[i]);
};
}

str += delFmt(acc);
/**
acc = [];
* @private
for (i = 0; i < out.n.length; ++i) {
*/
while (i < out.n.length && !out.n[i].paired) {
Previewmaker.prototype.esWiki2HtmlPart = function (data) {
acc.push(out.n[i++]);
var reLinks = /(?:\[\[([^|\]]*)(?:\|([^|\]]*))*]]([a-z]*))/gi; //match a wikilink
}
reLinks.lastIndex = 0; //reset regex
str += insFmt(acc);

acc = [];
var match;
if (i < out.n.length) {
var result = '';
str += out.n[i].text;
var postfixIndex = 0;
var m = out.n[i].row + 1;
while ((match = reLinks.exec(data))) {
while (m < out.o.length && !out.o[m].paired) {
//match all wikilinks
acc.push(out.o[m++]);
//FIXME: the way that link is built here isn't perfect. It is clickable, but popups preview won't recognize it in some cases.
}
result +=
str += delFmt(acc);
pg.escapeQuotesHTML(data.substring(postfixIndex, match.index)) +
acc = [];
'<a href="' +
}
Insta.conf.paths.articles +
}
pg.escapeQuotesHTML(match[1]) +
return str;
'">' +
}
pg.escapeQuotesHTML((match[2] ? match[2] : match[1]) + match[3]) +
var jsReservedProperties = RegExp('^(constructor|prototype|__((define|lookup)[GS]etter)__' + '|eval|hasOwnProperty|propertyIsEnumerable' + '|to(Source|String|LocaleString)|(un)?watch|valueOf)$');
'</a>';
function diffBugAlert(word) {
postfixIndex = reLinks.lastIndex;
if (!diffBugAlert.list[word]) {
}
diffBugAlert.list[word] = 1;
//append the rest
alert('Bad word: ' + word + '\n\nPlease report this bug.');
result += pg.escapeQuotesHTML(data.substring(postfixIndex));
}

}
return result;
diffBugAlert.list = {};
};
function makeDiffHashtable(src) {
Previewmaker.prototype.editSummaryPreview = function () {
var ret = {};
var reAes = /\/\* *(.*?) *\*\//g; //match the first section marker
for (var i = 0; i < src.length; i++) {
reAes.lastIndex = 0; //reset regex
if (jsReservedProperties.test(src[i])) {

src[i] += '<!-- -->';
var match;
}

if (!ret[src[i]]) {
match = reAes.exec(this.data);
ret[src[i]] = [];
if (match) {
}
//we have a section link. Split it, process it, combine it.
try {
var prefix = this.data.substring(0, match.index - 1);
ret[src[i]].push(i);
var section = match[1];
} catch (err) {
var postfix = this.data.substring(reAes.lastIndex);
diffBugAlert(src[i]);

}
var start = "<span class='autocomment'>";
}
var end = '</span>';
return ret;
if (prefix.length > 0) {
}
start = this.esWiki2HtmlPart(prefix) + ' ' + start + '- ';
function diff(o, n) {
}
var ns = makeDiffHashtable(n);
if (postfix.length > 0) {
var os = makeDiffHashtable(o);
end = ': ' + end + this.esWiki2HtmlPart(postfix);
var i;
}
for (i in ns) {

if (ns[i].length == 1 && os[i] && os[i].length == 1) {
var t = new Title().fromURL(this.baseUrl);
n[ns[i][0]] = {
t.anchorFromUtf(section);
text: n[ns[i][0]],
var sectionLink =
row: os[i][0],
Insta.conf.paths.articles +
paired: true
pg.escapeQuotesHTML(t.toString(true)) +
};
'#' +
o[os[i][0]] = {
pg.escapeQuotesHTML(t.anchor);
text: o[os[i][0]],
return (
row: ns[i][0],
start + '<a href="' + sectionLink + '">&rarr;</a> ' + pg.escapeQuotesHTML(section) + end
paired: true
);
};
}
}

}
//else there's no section link, htmlify the whole thing.
for (i = 0; i < n.length - 1; i++) {
return this.esWiki2HtmlPart(this.data);
if (n[i].paired && !n[i + 1].paired && n[i].row + 1 < o.length && !o[n[i].row + 1].paired && n[i + 1] == o[n[i].row + 1]) {
};
n[i + 1] = {

text: n[i + 1],
/** Test function for debugging preview problems one step at a time. */
row: n[i].row + 1,
/*eslint-disable */
paired: true
function previewSteps(txt) {
};
try {
o[n[i].row + 1] = {
txt = txt || document.editform.wpTextbox1.value;
text: o[n[i].row + 1],
} catch (err) {
row: i + 1,
if (pg.cache.pages.length > 0) {
paired: true
txt = pg.cache.pages[pg.cache.pages.length - 1].data;
};
} else {
}
alert('provide text or use an edit page');
}
}
for (i = n.length - 1; i > 0; i--) {
}
if (n[i].paired && !n[i - 1].paired && n[i].row > 0 && !o[n[i].row - 1].paired && n[i - 1] == o[n[i].row - 1]) {
txt = txt.substring(0, 10000);
n[i - 1] = {
var base = pg.wiki.articlebase + Title.fromURL(document.location.href).urlString();
text: n[i - 1],
var p = new Previewmaker(txt, base, pg.current.link.navpopup);
row: n[i].row - 1,
if (this.owner.article.namespaceId() != pg.nsTemplateId) {
paired: true
p.killComments();
};
if (!confirm('done killComments(). Continue?\n---\n' + p.data)) {
o[n[i].row - 1] = {
return;
text: o[n[i].row - 1],
}
row: i - 1,
p.killDivs();
paired: true
if (!confirm('done killDivs(). Continue?\n---\n' + p.data)) {
};
return;
}
}
}
p.killGalleries();
return {
if (!confirm('done killGalleries(). Continue?\n---\n' + p.data)) {
o: o,
return;
n: n
}
};
p.killBoxTemplates();
}
if (!confirm('done killBoxTemplates(). Continue?\n---\n' + p.data)) {
function setSiteInfo() {
return;
if (window.popupLocalDebug) {
}
pg.wiki.hostname = 'en.wikipedia.org';

} else {
if (getValueOf('popupPreviewKillTemplates')) {
pg.wiki.hostname = location.hostname;
p.killTemplates();
}
if (!confirm('done killTemplates(). Continue?\n---\n' + p.data)) {
pg.wiki.wikimedia = RegExp('(wiki([pm]edia|source|books|news|quote|versity|species|voyage|data)|metawiki|wiktionary|mediawiki)[.]org').test(pg.wiki.hostname);
return;
pg.wiki.wikia = RegExp('[.]wikia[.]com$', 'i').test(pg.wiki.hostname);
}
pg.wiki.isLocal = RegExp('^localhost').test(pg.wiki.hostname);
} else {
pg.wiki.commons = pg.wiki.wikimedia && pg.wiki.hostname != 'commons.wikimedia.org' ? 'commons.wikimedia.org' : null;
p.killMultilineTemplates();
pg.wiki.lang = mw.config.get('wgContentLanguage');
if (!confirm('done killMultilineTemplates(). Continue?\n---\n' + p.data)) {
var port = location.port ? ':' + location.port : '';
return;
pg.wiki.sitebase = pg.wiki.hostname + port;
}
}
}
function setUserInfo() {

var params = {
p.killTables();
action: 'query',
if (!confirm('done killTables(). Continue?\n---\n' + p.data)) {
list: 'users',
return;
ususers: mw.config.get('wgUserName'),
}
usprop: 'rights',
p.killImages();
};
if (!confirm('done killImages(). Continue?\n---\n' + p.data)) {
pg.user.canReview = false;
return;
if (getValueOf('popupReview')) {
}
getMwApi().get(params).done(function(data) {
p.killHTML();
var rights = data.query.users[0].rights;
if (!confirm('done killHTML(). Continue?\n---\n' + p.data)) {
pg.user.canReview = rights.indexOf('review') !== -1;
return;
});
}
}
p.killChunks();
}
if (!confirm('done killChunks(). Continue?\n---\n' + p.data)) {
function fetchSpecialPageNames() {
return;
var params = {
}
action: 'query',
p.mopup();
meta: 'siteinfo',
if (!confirm('done mopup(). Continue?\n---\n' + p.data)) {
siprop: 'specialpagealiases',
return;
formatversion: 2,
}
uselang: 'content',

maxage: 3600,
p.firstBit();
};
if (!confirm('done firstBit(). Continue?\n---\n' + p.data)) {
return getMwApi().get(params).then(function(data) {
return;
pg.wiki.specialpagealiases = data.query.specialpagealiases;
}
});
p.killBadWhitespace();
}
if (!confirm('done killBadWhitespace(). Continue?\n---\n' + p.data)) {
function setTitleBase() {
return;
var protocol = window.popupLocalDebug ? 'http:' : location.protocol;
}
pg.wiki.articlePath = mw.config.get('wgArticlePath').replace(/\/\$1/, '');
}
pg.wiki.botInterfacePath = mw.config.get('wgScript');

pg.wiki.APIPath = mw.config.get('wgScriptPath') + '/api.php';
p.html = wiki2html(p.data, base); // needs livepreview
var titletail = pg.wiki.botInterfacePath + '?title=';
p.fixHTML();
pg.wiki.titlebase = protocol + '//' + pg.wiki.sitebase + titletail;
if (!confirm('done fixHTML(). Continue?\n---\n' + p.html)) {
pg.wiki.wikibase = protocol + '//' + pg.wiki.sitebase + pg.wiki.botInterfacePath;
return;
pg.wiki.apiwikibase = protocol + '//' + pg.wiki.sitebase + pg.wiki.APIPath;
}
pg.wiki.articlebase = protocol + '//' + pg.wiki.sitebase + pg.wiki.articlePath;
p.stripLongTemplates();
pg.wiki.commonsbase = protocol + '//' + pg.wiki.commons + pg.wiki.botInterfacePath;
if (!confirm('done stripLongTemplates(). Continue?\n---\n' + p.html)) {
pg.wiki.apicommonsbase = protocol + '//' + pg.wiki.commons + pg.wiki.APIPath;
return;
pg.re.basenames = RegExp('^(' + map(literalizeRegex, [pg.wiki.titlebase, pg.wiki.articlebase, ]).join('|') + ')');
}
}
alert('finished preview - end result follows.\n---\n' + p.html);
function setMainRegex() {
}
var reStart = '[^:]*://';
/*eslint-enable */
var preTitles = literalizeRegex(mw.config.get('wgScriptPath')) + '/(?:index[.]php|wiki[.]phtml)[?]title=';

preTitles += '|' + literalizeRegex(pg.wiki.articlePath + '/');
/**
var reEnd = '(' + preTitles + ')([^&?#]*)[^#]*(?:#(.+))?';
* Works around livepreview bugs.
pg.re.main = RegExp(reStart + literalizeRegex(pg.wiki.sitebase) + reEnd);
* @private
}
*/
function buildSpecialPageGroup(specialPageObj) {
Previewmaker.prototype.fixHTML = function () {
var variants = [];
if (!this.html) {
variants.push(mw.util.escapeRegExp(specialPageObj['realname']));
return;
variants.push(mw.util.escapeRegExp(encodeURI(specialPageObj['realname'])));
}
specialPageObj.aliases.forEach(function(alias) {

variants.push(mw.util.escapeRegExp(alias));
var ret = this.html;
variants.push(mw.util.escapeRegExp(encodeURI(alias)));

});
// fix question marks in wiki links
return variants.join('|');
// maybe this'll break some stuff :-(
}
ret = ret.replace(
function setRegexps() {
RegExp('(<a href="' + pg.wiki.articlePath + '/[^"]*)[?](.*?")', 'g'),
setMainRegex();
'$1%3F$2'
var sp = nsRe(pg.nsSpecialId);
);
pg.re.urlNoPopup = RegExp('((title=|/)' + sp + '(?:%3A|:)|section=[0-9]|^#$)');
ret = ret.replace(
pg.wiki.specialpagealiases.forEach(function(specialpage) {
RegExp("(<a href='" + pg.wiki.articlePath + "/[^']*)[?](.*?')", 'g'),
if (specialpage.realname === 'Contributions') {
'$1%3F$2'
pg.re.contribs = RegExp('(title=|/)' + sp + '(?:%3A|:)(?:' + buildSpecialPageGroup(specialpage) + ')' + '(&target=|/|/' + nsRe(pg.nsUserId) + ':)(.*)', 'i');
);
} else if (specialpage.realname === 'Diff') {
// FIXME fix up % too
pg.re.specialdiff = RegExp('/' + sp + '(?:%3A|:)(?:' + buildSpecialPageGroup(specialpage) + ')' + '/([^?#]*)', 'i');

} else if (specialpage.realname === 'Emailuser') {
this.html = ret;
pg.re.email = RegExp('(title=|/)' + sp + '(?:%3A|:)(?:' + buildSpecialPageGroup(specialpage) + ')' + '(&target=|/|/(?:' + nsRe(pg.nsUserId) + ':)?)(.*)', 'i');
};
} else if (specialpage.realname === 'Whatlinkshere') {

pg.re.backlinks = RegExp('(title=|/)' + sp + '(?:%3A|:)(?:' + buildSpecialPageGroup(specialpage) + ')' + '(&target=|/)([^&]*)', 'i');
/**
}
* Generates the preview and displays it in the current popup.
});

var im = nsReImage();
* Does nothing if the generated preview is invalid or consists of whitespace only.
pg.re.image = RegExp('(^|\\[\\[)' + im + ': *([^|\\]]*[^|\\] ])' + '([^0-9\\]]*([0-9]+) *px)?|(?:\\n *[|]?|[|]) *' + '(' + getValueOf('popupImageVarsRegexp') + ')' + ' *= *(?:\\[\\[ *)?(?:' + im + ':)?' + '([^|]*?)(?:\\]\\])? *[|]? *\\n', 'img');
* Also activates wikilinks in the preview for subpopups if the popupSubpopups option is true.
pg.re.imageBracketCount = 6;
*/
pg.re.category = RegExp('\\[\\[' + nsRe(pg.nsCategoryId) + ': *([^|\\]]*[^|\\] ]) *', 'i');
Previewmaker.prototype.showPreview = function () {
pg.re.categoryBracketCount = 1;
this.makePreview();
pg.re.ipUser = RegExp('^' + '(?::(?::|(?::[0-9A-Fa-f]{1,4}){1,7})|[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4}){0,6}::|[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4}){7})' + '|(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}' + '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]))$');
if (typeof this.html != typeof '') {
pg.re.stub = RegExp(getValueOf('popupStubRegexp'), 'im');
return;
pg.re.disambig = RegExp(getValueOf('popupDabRegexp'), 'im');
}
pg.re.oldid = RegExp('[?&]oldid=([^&]*)');
if (RegExp('^\\s*$').test(this.html)) {
pg.re.diff = RegExp('[?&]diff=([^&]*)');
return;
}
}
function setupCache() {
setPopupHTML('<hr />', 'popupPrePreviewSep', this.owner.idNumber);
pg.cache.pages = [];
setPopupTipsAndHTML(this.html, 'popupPreview', this.owner.idNumber, {
}
owner: this.owner,
function setMisc() {
});
pg.current.link = null;
var more = this.fullLength > this.data.length ? this.moreLink() : '';
pg.current.links = [];
setPopupHTML(more, 'popupPreviewMore', this.owner.idNumber);
pg.current.linksHash = {};
};
setupCache();

pg.timer.checkPopupPosition = null;
/**
pg.counter.loop = 0;
* @private
pg.idNumber = 0;
*/
pg.misc.decodeExtras = [{
Previewmaker.prototype.moreLink = function () {
from: '%2C',
var a = document.createElement('a');
to: ','
a.className = 'popupMoreLink';
}, {
a.innerHTML = popupString('more...');
from: '_',
var savedThis = this;
to: ' '
a.onclick = function () {
}, {
savedThis.maxCharacters += 2000;
from: '%24',
savedThis.maxSentences += 20;
to: '$'
savedThis.setData();
}, {
savedThis.showPreview();
from: '%26',
};
to: '&'
return a;
}, ];
};
}

function getMwApi() {
/**
if (!pg.api.client) {
* @private
pg.api.userAgent = 'Navigation popups/1.0 (' + mw.config.get('wgServerName') + ')';
*/
pg.api.client = new mw.Api({
Previewmaker.prototype.stripLongTemplates = function () {
ajax: {
// operates on the HTML!
headers: {
this.html = this.html.replace(
'Api-User-Agent': pg.api.userAgent,
RegExp('^.{0,1000}[{][{][^}]*?(<(p|br)( /)?>\\s*){2,}([^{}]*?[}][}])?', 'gi'),
},
''
},
);
});
this.html = this.html.split('\n').join(' '); // workaround for <pre> templates
}
this.html = this.html.replace(RegExp('[{][{][^}]*<pre>[^}]*[}][}]', 'gi'), '');
return pg.api.client;
};
}

function setupPopups(callback) {
/**
if (setupPopups.completed) {
* @private
if (typeof callback === 'function') {
*/
callback();
Previewmaker.prototype.killMultilineTemplates = function () {
}
this.kill('{{{', '}}}');
return;
this.kill(RegExp('\\s*[{][{][^{}]*\\n'), '}}', '{{');
}
};
mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.user', 'user.options', 'mediawiki.jqueryMsg', ]).then(fetchSpecialPageNames).then(function() {
// ENDFILE: previewmaker.js
setupDebugging();

setSiteInfo();
// STARTFILE: querypreview.js
setTitleBase();
function loadAPIPreview(queryType, article, navpop) {
setOptions();
var art = new Title(article).urlString();
setUserInfo();
var url = pg.wiki.apiwikibase + '?format=json&formatversion=2&action=query&';
setNamespaces();
var htmlGenerator = function (/*a, d*/) {
setInterwiki();
alert('invalid html generator');
setRegexps();
};
setRedirs();
var usernameart = '';
setMisc();
switch (queryType) {
setupLivePreview();
case 'history':
setupTooltips();
url +=
log('In setupPopups(), just called setupTooltips()');
'titles=' + art + '&prop=revisions&rvlimit=' + getValueOf('popupHistoryPreviewLimit');
Navpopup.tracker.enable();
htmlGenerator = APIhistoryPreviewHTML;
setupPopups.completed = true;
break;
if (typeof callback === 'function') {
case 'category':
callback();
url += 'list=categorymembers&cmtitle=' + art;
}
htmlGenerator = APIcategoryPreviewHTML;
});
break;
}
case 'userinfo':
function defaultNavlinkSpec() {
var username = new Title(article).userName();
var str = '';
usernameart = encodeURIComponent(username);
str += '<b><<mainlink|shortcut= >></b>';
if (pg.re.ipUser.test(username)) {
if (getValueOf('popupLastEditLink')) {
url += 'list=blocks&bkprop=range|restrictions&bkip=' + usernameart;
str += '*<<lastEdit|shortcut=/>>|<<lastContrib>>|<<sinceMe>>if(oldid){|<<oldEdit>>|<<diffCur>>}';
} else {
}
url +=
str += 'if(user){<br><<contribs|shortcut=c>>*<<userlog|shortcut=L|log>>';
'list=users|usercontribs&usprop=blockinfo|groups|editcount|registration|gender&ususers=' +
str += 'if(ipuser){*<<arin>>}if(wikimedia){*<<count|shortcut=#>>}';
usernameart +
str += 'if(ipuser){}else{*<<email|shortcut=E>>}if(admin){*<<block|shortcut=b>>|<<blocklog|log>>}}';
'&meta=globaluserinfo&guiprop=groups|unattached&guiuser=' +
var editstr = '<<edit|shortcut=e>>';
usernameart +
var editOldidStr = 'if(oldid){<<editOld|shortcut=e>>|<<revert|shortcut=v|rv>>|<<edit|cur>>}else{' + editstr + '}';
'&uclimit=1&ucprop=timestamp&ucuser=' +
var historystr = '<<history|shortcut=h>>|<<editors|shortcut=E|>>';
usernameart;
var watchstr = '<<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>>';
}
str += '<br>if(talk){' + editOldidStr + '|<<new|shortcut=+>>' + '*' + historystr + '*' + watchstr + '*' + '<b><<article|shortcut=a>></b>|<<editArticle|edit>>' + '}else{' + editOldidStr + '*' + historystr + '*' + watchstr + '*' + '<b><<talk|shortcut=t>></b>|<<editTalk|edit>>|<<newTalk|shortcut=+|new>>}';
htmlGenerator = APIuserInfoPreviewHTML;
str += '<br><<whatLinksHere|shortcut=l>>*<<relatedChanges|shortcut=r>>*<<move|shortcut=m>>';
break;
str += 'if(admin){<br><<unprotect|unprotectShort>>|<<protect|shortcut=p>>|<<protectlog|log>>*' + '<<undelete|undeleteShort>>|<<delete|shortcut=d>>|<<deletelog|log>>}';
case 'contribs':
return str;
usernameart = encodeURIComponent(new Title(article).userName());
}
url +=
function navLinksHTML(article, hint, params) {
'list=usercontribs&ucuser=' +
var str = '<span class="popupNavLinks">' + defaultNavlinkSpec() + '</span>';
usernameart +
return navlinkStringToHTML(str, article, params);
'&uclimit=' +
}
getValueOf('popupContribsPreviewLimit');
function expandConditionalNavlinkString(s, article, z, recursionCount) {
htmlGenerator = APIcontribsPreviewHTML;
var oldid = z.oldid
break;
, rcid = z.rcid
case 'imagepagepreview':
, diff = z.diff;
var trail = '';
if (typeof recursionCount != typeof 0) {
if (getValueOf('popupImageLinks')) {
recursionCount = 0;
trail = '&list=imageusage&iutitle=' + art;
}
}
var conditionalSplitRegex = RegExp('(;?\\s*if\\s*\\(\\s*([\\w]*)\\s*\\)\\s*\\{([^{}]*)\\}(\\s*else\\s*\\{([^{}]*?)\\}|))', 'i');
url += 'titles=' + art + '&prop=revisions|imageinfo&rvslots=main&rvprop=content' + trail;
var splitted = s.parenSplit(conditionalSplitRegex);
htmlGenerator = APIimagepagePreviewHTML;
var numParens = 5;
break;
var ret = splitted[0];
case 'backlinks':
for (var i = 1; i < splitted.length; i = i + numParens + 1) {
url += 'list=backlinks&bltitle=' + art;
var testString = splitted[i + 2 - 1];
htmlGenerator = APIbacklinksPreviewHTML;
var trueString = splitted[i + 3 - 1];
break;
var falseString = splitted[i + 5 - 1];
case 'revision':
if (typeof falseString == 'undefined' || !falseString) {
if (article.oldid) {
falseString = '';
url += 'revids=' + article.oldid;
}
} else {
var testResult = null;
url += 'titles=' + article.removeAnchor().urlString();
switch (testString) {
}
case 'user':
url +=
testResult = !!article.userName();
'&prop=revisions|pageprops|info|images|categories&meta=wikibase&rvslots=main&rvprop=ids|timestamp|flags|comment|user|content&cllimit=max&imlimit=max';
break;
htmlGenerator = APIrevisionPreviewHTML;
case 'talk':
break;
testResult = !article.talkPage();
}
break;
pendingNavpopTask(navpop);
case 'admin':
var callback = function (d) {
testResult = !!getValueOf('popupAdminLinks');
log('callback of API functions was hit');
break;
if (queryType === 'userinfo') {
case 'oldid':
// We need to do another API request
testResult = !!(typeof oldid != 'undefined' && oldid);
fetchUserGroupNames(d.data).then(function () {
break;
showAPIPreview(queryType, htmlGenerator(article, d, navpop), navpop.idNumber, navpop, d);
case 'rcid':
});
testResult = !!(typeof rcid != 'undefined' && rcid);
return;
break;
}
case 'ipuser':
showAPIPreview(queryType, htmlGenerator(article, d, navpop), navpop.idNumber, navpop, d);
testResult = !!article.isIpUser();
};
break;
var go = function () {
case 'mainspace_en':
getPageWithCaching(url, callback, navpop);
testResult = isInMainNamespace(article) && pg.wiki.hostname == 'en.wikipedia.org';
return true;
break;
};
case 'wikimedia':

testResult = !!pg.wiki.wikimedia;
if (navpop.visible || !getValueOf('popupLazyDownloads')) {
break;
go();
case 'diff':
} else {
testResult = !!(typeof diff != 'undefined' && diff);
navpop.addHook(go, 'unhide', 'before', 'DOWNLOAD_' + queryType + '_QUERY_DATA');
break;
}
}
}
switch (testResult) {

case null:
function linkList(list) {
ret += splitted[i];
list.sort(function (x, y) {
break;
case true:
return x == y ? 0 : x < y ? -1 : 1;
});
ret += trueString;
var buf = [];
break;
for (var i = 0; i < list.length; ++i) {
case false:
buf.push(
ret += falseString;
wikiLink({
break;
article: new Title(list[i]),
}
text: list[i].split(' ').join('&nbsp;'),
ret += splitted[i + numParens];
action: 'view',
}
})
if (conditionalSplitRegex.test(ret) && recursionCount < 10) {
);
return expandConditionalNavlinkString(ret, article, z, recursionCount + 1);
}
}
return buf.join(', ');
return ret;
}
}

function navlinkStringToArray(s, article, params) {
function getTimeOffset() {
s = expandConditionalNavlinkString(s, article, params);
var tz = mw.user.options.get('timecorrection');
var splitted = s.parenSplit(RegExp('<<(.*?)>>'));

var ret = [];
if (tz) {
for (var i = 0; i < splitted.length; ++i) {
if (tz.indexOf('|') > -1) {
if (i % 2) {
// New format
var t = new navlinkTag();
return parseInt(tz.split('|')[1], 10);
var ss = splitted[i].split('|');
}
t.id = ss[0];
}
for (var j = 1; j < ss.length; ++j) {
return 0;
var sss = ss[j].split('=');
}
if (sss.length > 1) {

t[sss[0]] = sss[1];
function getTimeZone() {
} else {
if (!pg.user.timeZone) {
t.text = popupString(sss[0]);
var tz = mw.user.options.get('timecorrection');
}
pg.user.timeZone = 'UTC';
}

t.article = article;
if (tz) {
var oldid = params.oldid
var tzComponents = tz.split('|');
, rcid = params.rcid
if (tzComponents.length === 3 && tzComponents[0] === 'ZoneInfo') {
, diff = params.diff;
pg.user.timeZone = tzComponents[2];
if (typeof oldid !== 'undefined' && oldid !== null) {
} else {
t.oldid = oldid;
errlog('Unexpected timezone information: ' + tz);
}
}
if (typeof rcid !== 'undefined' && rcid !== null) {
}
t.rcid = rcid;
}
}
return pg.user.timeZone;
if (typeof diff !== 'undefined' && diff !== null) {
}
t.diff = diff;

}
/**
if (!t.text && t.id !== 'mainlink') {
* Should we use an offset or can we use proper timezones
t.text = popupString(t.id);
*/
}
function useTimeOffset() {
ret.push(t);
if (typeof Intl.DateTimeFormat.prototype.formatToParts === 'undefined') {
} else {
// IE 11
ret.push(splitted[i]);
return true;
}
}
}
var tz = mw.user.options.get('timecorrection');
return ret;
if (tz && tz.indexOf('ZoneInfo|') === -1) {
}
// System| Default system time, default for users who didn't configure timezone
function navlinkSubstituteHTML(s) {
// Offset| Manual defined offset by user
return s.split('*').join(getValueOf('popupNavLinkSeparator')).split('<menurow>').join('<li class="popup_menu_row">').split('</menurow>').join('</li>').split('<menu>').join('<ul class="popup_menu">').split('</menu>').join('</ul>');
return true;
}
}
function navlinkDepth(magic, s) {
return false;
return s.split('<' + magic + '>').length - s.split('</' + magic + '>').length;
}
}

function navlinkStringToHTML(s, article, params) {
/**
var p = navlinkStringToArray(s, article, params);
* Array of locales for the purpose of javascript locale based formatting
var html = '';
* Filters down to those supported by the browser. Empty [] === System's default locale
var menudepth = 0;
*/
var menurowdepth = 0;
function getLocales() {
for (var i = 0; i < p.length; ++i) {
if (!pg.user.locales) {
if (typeof p[i] == typeof '') {
var userLanguage = document.querySelector('html').getAttribute('lang'); // make sure we have HTML locale
html += navlinkSubstituteHTML(p[i]);
if (getValueOf('popupLocale')) {
menudepth += navlinkDepth('menu', p[i]);
userLanguage = getValueOf('popupLocale');
menurowdepth += navlinkDepth('menurow', p[i]);
} else if (typeof p[i].type != 'undefined' && p[i].type == 'navlinkTag') {
} else if (userLanguage === 'en') {
// en.wp tends to treat this as international english / unspecified
if (menudepth > 0 && menurowdepth === 0) {
// but we have more specific settings in user options
html += '<li class="popup_menu_item">' + p[i].html() + '</li>';
if (getMWDateFormat() === 'mdy') {
} else {
userLanguage = 'en-US';
html += p[i].html();
} else {
}
userLanguage = 'en-GB';
}
}
}
}
return html;
pg.user.locales = Intl.DateTimeFormat.supportedLocalesOf([userLanguage, navigator.language]);
}
}
function navlinkTag() {
return pg.user.locales;
this.type = 'navlinkTag';
}
}

navlinkTag.prototype.html = function() {
/**
this.getNewWin();
* Retrieve configured MW date format for this user
this.getPrintFunction();
* These can be
var html = '';
* default
var opening, closing;
* dmy: time, dmy
var tagType = 'span';
* mdy: time, mdy
if (!tagType) {
* ymd: time, ymd
opening = '';
* dmyt: dmy, time
closing = '';
* dmyts: dmy, time + seconds
} else {
* ISO 8601: YYYY-MM-DDThh:mm:ss (local time)
opening = '<' + tagType + ' class="popup_' + this.id + '">';
*
closing = '</' + tagType + '>';
* This isn't too useful for us, as JS doesn't have formatters to match these private specifiers
}
*/
if (typeof this.print != 'function') {
function getMWDateFormat() {
errlog('Oh dear - invalid print function for a navlinkTag, id=' + this.id);
return mw.user.options.get('date');
} else {
}
html = this.print(this);

if (typeof html != typeof '') {
/**
html = '';
* Creates a HTML table that's shown in the history and user-contribs popups.
} else if (typeof this.shortcut != 'undefined') {
* @param {Object[]} h - a list of revisions, returned from the API
html = addPopupShortcut(html, this.shortcut);
* @param {boolean} reallyContribs - true only if we're displaying user contributions
}
*/
}
function editPreviewTable(article, h, reallyContribs) {
return opening + html + closing;
var html = ['<table>'];
}
var day = null;
;
var curart = article;
navlinkTag.prototype.getNewWin = function() {
var page = null;
getValueOf('popupLinksNewWindow');

if (typeof pg.option.popupLinksNewWindow[this.id] === 'undefined') {
var makeFirstColumnLinks;
this.newWin = null;
if (reallyContribs) {
}
// We're showing user contributions, so make (diff | hist) links
this.newWin = pg.option.popupLinksNewWindow[this.id];
makeFirstColumnLinks = function (currentRevision) {
}
var result = '(';
;
result +=
navlinkTag.prototype.getPrintFunction = function() {
'<a href="' +
if (typeof this.id != typeof '' || typeof this.article != typeof {}) {
pg.wiki.titlebase +
return;
new Title(currentRevision.title).urlString() +
}
'&diff=prev' +
this.noPopup = 1;
'&oldid=' +
switch (this.id) {
currentRevision.revid +
case 'contribs':
'">' +
case 'history':
popupString('diff') +
case 'whatLinksHere':
'</a>';
case 'userPage':
result += '&nbsp;|&nbsp;';
case 'monobook':
result +=
case 'userTalk':
'<a href="' +
case 'talk':
pg.wiki.titlebase +
case 'article':
new Title(currentRevision.title).urlString() +
case 'lastEdit':
'&action=history">' +
this.noPopup = null;
popupString('hist') +
}
'</a>';
switch (this.id) {
result += ')';
case 'email':
return result;
case 'contribs':
};
case 'block':
} else {
case 'unblock':
// It's a regular history page, so make (cur | last) links
case 'userlog':
var firstRevid = h[0].revid;
case 'userSpace':
makeFirstColumnLinks = function (currentRevision) {
case 'deletedContribs':
var result = '(';
this.article = this.article.userName();
result +=
}
'<a href="' +
switch (this.id) {
pg.wiki.titlebase +
case 'userTalk':
new Title(curart).urlString() +
case 'newUserTalk':
'&diff=' +
case 'editUserTalk':
firstRevid +
case 'userPage':
'&oldid=' +
case 'monobook':
currentRevision.revid +
case 'editMonobook':
'">' +
case 'blocklog':
popupString('cur') +
this.article = this.article.userName(true);
'</a>';
case 'pagelog':
result += '&nbsp;|&nbsp;';
case 'deletelog':
result +=
case 'protectlog':
'<a href="' +
delete this.oldid;
pg.wiki.titlebase +
}
new Title(curart).urlString() +
if (this.id == 'editMonobook' || this.id == 'monobook') {
'&diff=prev&oldid=' +
this.article.append('/monobook.js');
currentRevision.revid +
}
'">' +
if (this.id != 'mainlink') {
popupString('last') +
this.article = this.article.removeAnchor();
'</a>';
}
result += ')';
switch (this.id) {
return result;
case 'undelete':
};
this.print = specialLink;
}
this.specialpage = 'Undelete';

this.sep = '/';
for (var i = 0; i < h.length; ++i) {
break;
if (reallyContribs) {
case 'whatLinksHere':
page = h[i].title;
this.print = specialLink;
curart = new Title(page);
this.specialpage = 'Whatlinkshere';
}
break;
var minor = h[i].minor ? '<b>m </b>' : '';
case 'relatedChanges':
var editDate = new Date(h[i].timestamp);
this.print = specialLink;
var thisDay = formattedDate(editDate);
this.specialpage = 'Recentchangeslinked';
var thisTime = formattedTime(editDate);
break;
if (thisDay == day) {
case 'move':
thisDay = '';
this.print = specialLink;
} else {
this.specialpage = 'Movepage';
day = thisDay;
break;
}
case 'contribs':
if (thisDay) {
this.print = specialLink;
html.push(
this.specialpage = 'Contributions';
'<tr><td colspan=3><span class="popup_history_date">' + thisDay + '</span></td></tr>'
break;
);
case 'deletedContribs':
}
this.print = specialLink;
html.push('<tr class="popup_history_row_' + (i % 2 ? 'odd' : 'even') + '">');
this.specialpage = 'Deletedcontributions';
html.push('<td>' + makeFirstColumnLinks(h[i]) + '</td>');
break;
html.push(
case 'email':
'<td>' +
this.print = specialLink;
'<a href="' +
this.specialpage = 'EmailUser';
pg.wiki.titlebase +
this.sep = '/';
new Title(curart).urlString() +
break;
'&oldid=' +
case 'block':
h[i].revid +
this.print = specialLink;
'">' +
this.specialpage = 'Blockip';
thisTime +
this.sep = '&ip=';
'</a></td>'
break;
);
case 'unblock':
var col3url = '',
this.print = specialLink;
col3txt = '';
this.specialpage = 'Ipblocklist';
if (!reallyContribs) {
this.sep = '&action=unblock&ip=';
var user = h[i].user;
break;
if (!h[i].userhidden) {
case 'userlog':
if (pg.re.ipUser.test(user)) {
this.print = specialLink;
col3url =
this.specialpage = 'Log';
pg.wiki.titlebase +
this.sep = '&user=';
mw.config.get('wgFormattedNamespaces')[pg.nsSpecialId] +
break;
':Contributions&target=' +
case 'blocklog':
new Title(user).urlString();
this.print = specialLink;
} else {
this.specialpage = 'Log';
col3url =
this.sep = '&type=block&page=';
pg.wiki.titlebase +
break;
mw.config.get('wgFormattedNamespaces')[pg.nsUserId] +
case 'pagelog':
':' +
this.print = specialLink;
new Title(user).urlString();
this.specialpage = 'Log';
}
this.sep = '&page=';
col3txt = pg.escapeQuotesHTML(user);
break;
} else {
case 'protectlog':
col3url = getValueOf('popupRevDelUrl');
this.print = specialLink;
col3txt = pg.escapeQuotesHTML(popupString('revdel'));
this.specialpage = 'Log';
}
this.sep = '&type=protect&page=';
} else {
break;
col3url = pg.wiki.titlebase + curart.urlString();
case 'deletelog':
col3txt = pg.escapeQuotesHTML(page);
this.print = specialLink;
}
this.specialpage = 'Log';
html.push(
this.sep = '&type=delete&page=';
'<td>' +
break;
(reallyContribs ? minor : '') +
case 'userSpace':
'<a href="' +
this.print = specialLink;
col3url +
this.specialpage = 'PrefixIndex';
'">' +
this.sep = '&namespace=2&prefix=';
col3txt +
break;
'</a></td>'
case 'search':
);
this.print = specialLink;
var comment = '';
this.specialpage = 'Search';
var c = h[i].comment || ( typeof h[i].slots !== 'undefined' ? h[i].slots.main.content : null );
this.sep = '&fulltext=Search&search=';
if (c) {
break;
comment = new Previewmaker(c, new Title(curart).toUrl()).editSummaryPreview();
case 'thank':
} else if (h[i].commenthidden) {
this.print = specialLink;
comment = popupString('revdel');
this.specialpage = 'Thanks';
}
this.sep = '/';
html.push('<td>' + (!reallyContribs ? minor : '') + comment + '</td>');
this.article.value = this.diff !== 'prev' ? this.diff : this.oldid;
html.push('</tr>');
break;
html = [html.join('')];
case 'unwatch':
}
case 'watch':
html.push('</table>');
this.print = magicWatchLink;
return html.join('');
this.action = this.id + '&autowatchlist=1&autoimpl=' + popupString('autoedit_version') + '&actoken=' + autoClickToken();
}
break;

case 'history':
function adjustDate(d, offset) {
case 'historyfeed':
// offset is in minutes
case 'unprotect':
var o = offset * 60 * 1000;
case 'protect':
return new Date(Number(d) + o);
this.print = wikiLink;
}
this.action = this.id;

break;
/**
case 'delete':
* This relies on the Date parser understanding en-US dates,
this.print = wikiLink;
* which is pretty safe assumption, but not perfect.
this.action = 'delete';
*/
if (this.article.namespaceId() == pg.nsImageId) {
function convertTimeZone(date, timeZone) {
var img = this.article.stripNamespace();
return new Date(date.toLocaleString('en-US', { timeZone: timeZone }));
this.action += '&image=' + img;
}
}

break;
function formattedDateTime(date) {
case 'markpatrolled':
// fallback for IE11 and unknown timezones
case 'edit':
if (useTimeOffset()) {
delete this.oldid;
return formattedDate(date) + ' ' + formattedTime(date);
case 'view':
}
case 'purge':

case 'render':
if (getMWDateFormat() === 'ISO 8601') {
this.print = wikiLink;
var d2 = convertTimeZone(date, getTimeZone());
this.action = this.id;
return (
break;
map(zeroFill, [d2.getFullYear(), d2.getMonth() + 1, d2.getDate()]).join('-') +
case 'raw':
'T' +
this.print = wikiLink;
map(zeroFill, [d2.getHours(), d2.getMinutes(), d2.getSeconds()]).join(':')
this.action = 'raw';
);
break;
}
case 'new':

this.print = wikiLink;
var options = getValueOf('popupDateTimeFormatterOptions');
this.action = 'edit&section=new';
options['timeZone'] = getTimeZone();
break;
return date.toLocaleString(getLocales(), options);
case 'mainlink':
}
if (typeof this.text == 'undefined') {

this.text = this.article.toString().entify();
function formattedDate(date) {
}
// fallback for IE11 and unknown timezones
if (getValueOf('popupSimplifyMainLink') && isInStrippableNamespace(this.article)) {
if (useTimeOffset()) {
var s = this.text.split('/');
// we adjust the UTC time, so we print the adjusted UTC, but not really UTC values
this.text = s[s.length - 1];
var d2 = adjustDate(date, getTimeOffset());
if (this.text === '' && s.length > 1) {
return map(zeroFill, [d2.getUTCFullYear(), d2.getUTCMonth() + 1, d2.getUTCDate()]).join('-');
this.text = s[s.length - 2];
}
}

}
if (getMWDateFormat() === 'ISO 8601') {
this.print = titledWikiLink;
var d2 = convertTimeZone(date, getTimeZone());
if (typeof this.title === 'undefined' && pg.current.link && typeof pg.current.link.href !== 'undefined') {
return map(zeroFill, [d2.getFullYear(), d2.getMonth() + 1, d2.getDate()]).join('-');
this.title = safeDecodeURI(pg.current.link.originalTitle ? pg.current.link.originalTitle : this.article);
}
if (typeof this.oldid !== 'undefined' && this.oldid) {

this.title = tprintf('Revision %s of %s', [this.oldid, this.title]);
var options = getValueOf('popupDateFormatterOptions');
}
options['timeZone'] = getTimeZone();
}
return date.toLocaleDateString(getLocales(), options);
this.action = 'view';
}
break;

case 'userPage':
function formattedTime(date) {
case 'article':
// fallback for IE11 and unknown timezones
case 'monobook':
if (useTimeOffset()) {
case 'editMonobook':
// we adjust the UTC time, so we print the adjusted UTC, but not really UTC values
case 'editArticle':
var d2 = adjustDate(date, getTimeOffset());
delete this.oldid;
return map(zeroFill, [d2.getUTCHours(), d2.getUTCMinutes(), d2.getUTCSeconds()]).join(':');
this.article = this.article.articleFromTalkOrArticle();
}
this.print = wikiLink;

if (this.id.indexOf('edit') === 0) {
if (getMWDateFormat() === 'ISO 8601') {
this.action = 'edit';
var d2 = convertTimeZone(date, getTimeZone());
} else {
return map(zeroFill, [d2.getHours(), d2.getMinutes(), d2.getSeconds()]).join(':');
this.action = 'view';
}
}

break;
var options = getValueOf('popupTimeFormatterOptions');
case 'userTalk':
options['timeZone'] = getTimeZone();
case 'talk':
return date.toLocaleTimeString(getLocales(), options);
this.article = this.article.talkPage();
}
delete this.oldid;

this.print = wikiLink;
// Get the proper groupnames for the technicalgroups
this.action = 'view';
function fetchUserGroupNames(userinfoResponse) {
break;
var queryObj = getJsObj(userinfoResponse).query;
case 'arin':
var user = anyChild(queryObj.users);
this.print = arinLink;
var messages = [];
break;
if (user.groups) {
case 'count':
user.groups.forEach(function (groupName) {
this.print = editCounterLink;
if (['*', 'user', 'autoconfirmed', 'extendedconfirmed', 'named'].indexOf(groupName) === -1) {
break;
messages.push('group-' + groupName + '-member');
case 'google':
}
this.print = googleLink;
});
break;
}
case 'editors':
if (queryObj.globaluserinfo && queryObj.globaluserinfo.groups) {
this.print = editorListLink;
queryObj.globaluserinfo.groups.forEach(function (groupName) {
break;
messages.push('group-' + groupName + '-member');
case 'globalsearch':
});
this.print = globalSearchLink;
}
break;
return getMwApi().loadMessagesIfMissing(messages);
case 'lastEdit':
}
this.print = titledDiffLink;

this.title = popupString('Show the last edit');
function showAPIPreview(queryType, html, id, navpop, download) {
this.from = 'prev';
// DJ: done
this.to = 'cur';
var target = 'popupPreview';
break;
completedNavpopTask(navpop);
case 'oldEdit':

this.print = titledDiffLink;
switch (queryType) {
this.title = popupString('Show the edit made to get revision') + ' ' + this.oldid;
case 'imagelinks':
this.from = 'prev';
case 'category':
this.to = this.oldid;
target = 'popupPostPreview';
break;
break;
case 'editOld':
case 'userinfo':
this.print = wikiLink;
target = 'popupUserData';
this.action = 'edit';
break;
break;
case 'undo':
case 'revision':
insertPreview(download);
this.print = wikiLink;
return;
this.action = 'edit&undo=';
}
break;
setPopupTipsAndHTML(html, target, id);
case 'revert':
}
this.print = wikiLink;

this.action = 'revert';
function APIrevisionPreviewHTML(article, download) {
break;
try {
case 'nullEdit':
var jsObj = getJsObj(download.data);
this.print = wikiLink;
var page = anyChild(jsObj.query.pages);
this.action = 'nullEdit';
if (page.missing) {
break;
// TODO we need to fix this proper later on
case 'diffCur':
download.owner = null;
this.print = titledDiffLink;
return;
this.title = tprintf('Show changes since revision %s', [this.oldid]);
}
this.from = this.oldid;
var content =
this.to = 'cur';
page && page.revisions && page.revisions[0] &&
break;
page.revisions[0].slots && page.revisions[0].slots.main &&
case 'editUserTalk':
page.revisions[0].slots.main.contentmodel === 'wikitext'
case 'editTalk':
? page.revisions[0].slots.main.content
delete this.oldid;
: null;
this.article = this.article.talkPage();
if (typeof content === 'string') {
this.action = 'edit';
download.data = content;
this.print = wikiLink;
download.lastModified = new Date(page.revisions[0].timestamp);
break;
}
case 'newUserTalk':
if (page.pageprops.wikibase_item) {
case 'newTalk':
download.wikibaseItem = page.pageprops.wikibase_item;
this.article = this.article.talkPage();
download.wikibaseRepo = jsObj.query.wikibase.repo.url.base
this.action = 'edit&section=new';
+ jsObj.query.wikibase.repo.url.articlepath;
this.print = wikiLink;
}
break;
} catch (someError) {
case 'lastContrib':
return 'Revision preview failed :(';
case 'sinceMe':
}
this.print = magicHistoryLink;
}
break;

case 'togglePreviews':
function APIbacklinksPreviewHTML(article, download /*, navpop*/) {
this.text = popupString(pg.option.simplePopups ? 'enable previews' : 'disable previews');
try {
case 'disablePopups':
var jsObj = getJsObj(download.data);
case 'purgePopups':
var list = jsObj.query.backlinks;
this.print = popupMenuLink;

break;
var html = [];
default:
if (!list) {
this.print = function() {
return popupString('No backlinks found');
return 'Unknown navlink type: ' + String(this.id);
}
}
for (var i = 0; i < list.length; i++) {
;
var t = new Title(list[i].title);
}
html.push(
}
'<a href="' + pg.wiki.titlebase + t.urlString() + '">' + t.toString().entify() + '</a>'
;
);
function popupHandleKeypress(evt) {
}
var keyCode = window.event ? window.event.keyCode : evt.keyCode ? evt.keyCode : evt.which;
html = html.join(', ');
if (!keyCode || !pg.current.link || !pg.current.link.navpopup) {
if (jsObj['continue'] && jsObj['continue'].blcontinue) {
return;
html += popupString(' and more');
}
}
if (keyCode == 27) {
return html;
killPopup();
} catch (someError) {
return false;
return 'backlinksPreviewHTML went wonky';
}
}
var letter = String.fromCharCode(keyCode);
}
var links = pg.current.link.navpopup.mainDiv.getElementsByTagName('A');

var startLink = 0;
pg.fn.APIsharedImagePagePreviewHTML = function APIsharedImagePagePreviewHTML(obj) {
var i, j;
log('APIsharedImagePagePreviewHTML');
if (popupHandleKeypress.lastPopupLinkSelected) {
var popupid = obj.requestid;
for (i = 0; i < links.length; ++i) {
if (obj.query && obj.query.pages) {
if (links[i] == popupHandleKeypress.lastPopupLinkSelected) {
var page = anyChild(obj.query.pages);
startLink = i;
var content =
}
page && page.revisions && page.revisions[0] &&
}
page.revisions[0].slots && page.revisions[0].slots.main &&
}
page.revisions[0].slots.main.contentmodel === 'wikitext'
for (j = 0; j < links.length; ++j) {
? page.revisions[0].slots.main.content
i = (startLink + j + 1) % links.length;
: null;
if (links[i].getAttribute('popupkey') == letter) {
if (
if (evt && evt.preventDefault) {
typeof content === 'string' &&
evt.preventDefault();
pg &&
}
pg.current &&
links[i].focus();
pg.current.link &&
popupHandleKeypress.lastPopupLinkSelected = links[i];
pg.current.link.navpopup
return false;
) {
}
/* Not entirely safe, but the best we can do */
}
var p = new Previewmaker(
if (document.oldPopupOnkeypress) {
content,
return document.oldPopupOnkeypress(evt);
pg.current.link.navpopup.article,
}
pg.current.link.navpopup
return true;
);
}
p.makePreview();
function addPopupShortcuts() {
setPopupHTML(p.html, 'popupSecondPreview', popupid);
if (document.onkeypress != popupHandleKeypress) {
}
document.oldPopupOnkeypress = document.onkeypress;
}
}
};
document.onkeypress = popupHandleKeypress;

}
function APIimagepagePreviewHTML(article, download, navpop) {
function rmPopupShortcuts() {
try {
popupHandleKeypress.lastPopupLinkSelected = null;
var jsObj = getJsObj(download.data);
try {
var page = anyChild(jsObj.query.pages);
if (document.oldPopupOnkeypress && document.oldPopupOnkeypress == popupHandleKeypress) {
var content =
document.onkeypress = null;
page && page.revisions && page.revisions[0] &&
return;
page.revisions[0].slots && page.revisions[0].slots.main &&
}
page.revisions[0].slots.main.contentmodel === 'wikitext'
document.onkeypress = document.oldPopupOnkeypress;
? page.revisions[0].slots.main.content
} catch (nasties) {}
: null;
}
var ret = '';
function addLinkProperty(html, property) {
var i = html.indexOf('>');
var alt = '';
try {
if (i < 0) {
alt = navpop.parentAnchor.childNodes[0].alt;
return html;
} catch (e) {}
}
if (alt) {
return html.substring(0, i) + ' ' + property + html.substring(i);
ret = ret + '<hr /><b>' + popupString('Alt text:') + '</b> ' + pg.escapeQuotesHTML(alt);
}
}
function addPopupShortcut(html, key) {
if (typeof content === 'string') {
if (!getValueOf('popupShortcutKeys')) {
var p = prepPreviewmaker(content, article, navpop);
return html;
p.makePreview();
}
if (p.html) {
var ret = addLinkProperty(html, 'popupkey="' + key + '"');
ret += '<hr />' + p.html;
if (key == ' ') {
}
key = popupString('spacebar');
if (getValueOf('popupSummaryData')) {
}
var info = getPageInfo(content, download);
return ret.replace(RegExp('^(.*?)(title=")(.*?)(".*)$', 'i'), '$1$2$3 [' + key + ']$4');
log(info);
}
setPopupTrailer(info, navpop.idNumber);
function loadDiff(article, oldid, diff, navpop) {
}
navpop.diffData = {
}
oldRev: {},
if (page && page.imagerepository == 'shared') {
newRev: {}
var art = new Title(article);
};
var encart = encodeURIComponent('File:' + art.stripNamespace());
mw.loader.using('mediawiki.api').then(function() {
var shared_url =
var api = getMwApi();
pg.wiki.apicommonsbase +
var params = {
'?format=json&formatversion=2' +
action: 'compare',
'&callback=pg.fn.APIsharedImagePagePreviewHTML' +
prop: 'ids|title',
'&requestid=' +
};
navpop.idNumber +
params.fromtitle = article.toString();
'&action=query&prop=revisions&rvslots=main&rvprop=content&titles=' +
switch (diff) {
encart;
case 'cur':

switch (oldid) {
ret =
case null:
ret +
case '':
'<hr />' +
case 'prev':
popupString('Image from Commons') +
params.torelative = 'prev';
': <a href="' +
break;
pg.wiki.commonsbase +
default:
'?title=' +
params.fromrev = oldid;
encart +
params.torelative = 'cur';
'">' +
break;
popupString('Description page') +
}
'</a>';
break;
mw.loader.load(shared_url);
case 'prev':
}
if (oldid && oldid !== 'cur') {
showAPIPreview(
params.fromrev = oldid;
'imagelinks',
}
APIimagelinksPreviewHTML(article, download),
params.torelative = 'prev';
navpop.idNumber,
break;
download
case 'next':
);
params.fromrev = oldid || 0;
return ret;
params.torelative = 'next';
} catch (someError) {
break;
return 'API imagepage preview failed :(';
default:
}
params.fromrev = oldid || 0;
}
params.torev = diff || 0;

break;
function APIimagelinksPreviewHTML(article, download) {
}
try {
api.get(params).then(function(data) {
var jsobj = getJsObj(download.data);
navpop.diffData.oldRev.revid = data.compare.fromrevid;
var list = jsobj.query.imageusage;
navpop.diffData.newRev.revid = data.compare.torevid;
if (list) {
addReviewLink(navpop, 'popupMiscTools');
var ret = [];
var go = function() {
for (var i = 0; i < list.length; i++) {
pendingNavpopTask(navpop);
ret.push(list[i].title);
var url = pg.wiki.apiwikibase + '?format=json&formatversion=2&action=query&';
}
url += 'revids=' + navpop.diffData.oldRev.revid + '|' + navpop.diffData.newRev.revid;
if (ret.length === 0) {
url += '&prop=revisions&rvslots=main&rvprop=ids|timestamp|content';
return popupString('No image links found');
getPageWithCaching(url, doneDiff, navpop);
}
return true;
return '<h2>' + popupString('File links') + '</h2>' + linkList(ret);
};
} else {
if (navpop.visible || !getValueOf('popupLazyDownloads')) {
return popupString('No image links found');
go();
}
} else {
} catch (someError) {
navpop.addHook(go, 'unhide', 'before', 'DOWNLOAD_DIFFS');
return 'Image links preview generation failed :(';
}
}
});
}
});

}
function addReviewLink(navpop, target) {
function APIcategoryPreviewHTML(article, download) {
try {
if (!pg.user.canReview) {
var jsobj = getJsObj(download.data);
return;
var list = jsobj.query.categorymembers;
}
var ret = [];
if (navpop.diffData.newRev.revid <= navpop.diffData.oldRev.revid) {
for (var p = 0; p < list.length; p++) {
return;
ret.push(list[p].title);
}
}
var params = {
if (ret.length === 0) {
action: 'query',
return popupString('Empty category');
prop: 'info|flagged',
}
revids: navpop.diffData.oldRev.revid,
ret = '<h2>' + tprintf('Category members (%s shown)', [ret.length]) + '</h2>' + linkList(ret);
formatversion: 2,
if (jsobj['continue'] && jsobj['continue'].cmcontinue) {
};
ret += popupString(' and more');
getMwApi().get(params).then(function(data) {
}
var stable_revid = (data.query.pages[0].flagged && data.query.pages[0].flagged.stable_revid) || 0;
return ret;
if (stable_revid == navpop.diffData.oldRev.revid) {
} catch (someError) {
var a = document.createElement('a');
return 'Category preview failed :(';
a.innerHTML = popupString('mark patrolled');
}
a.title = popupString('markpatrolledHint');
}
a.onclick = function() {

var params = {
function APIuserInfoPreviewHTML(article, download) {
action: 'review',
var ret = [];
revid: navpop.diffData.newRev.revid,
var queryobj = {};
comment: tprintf('defaultpopupReviewedSummary', [navpop.diffData.oldRev.revid, navpop.diffData.newRev.revid, ]),
try {
};
queryobj = getJsObj(download.data).query;
getMwApi().postWithToken('csrf', params).done(function() {
} catch (someError) {
a.style.display = 'none';
return 'Userinfo preview failed :(';
}).fail(function() {
}
alert(popupString('Could not marked this edit as patrolled'));

});
var user = anyChild(queryobj.users);
}
if (user) {
;
var globaluserinfo = queryobj.globaluserinfo;
setPopupHTML(a, target, navpop.idNumber, null, true);
if (user.invalid === '') {
}
ret.push(popupString('Invalid user'));
});
} else if (user.missing === '') {
}
ret.push(popupString('Not a registered username'));
function doneDiff(download) {
}
if (!download.owner || !download.owner.diffData) {
if (user.blockedby) {
return;
if (user.blockpartial) {
}
ret.push('<b>' + popupString('Has blocks') + '</b>');
var navpop = download.owner;
} else {
completedNavpopTask(navpop);
ret.push('<b>' + popupString('BLOCKED') + '</b>');
var pages, revisions = [];
}
try {
}
pages = getJsObj(download.data).query.pages;
if (globaluserinfo && ('locked' in globaluserinfo || 'hidden' in globaluserinfo)) {
for (var i = 0; i < pages.length; i++) {
var lockedSulAccountIsAttachedToThis = true;
revisions = revisions.concat(pages[i].revisions);
for (var i = 0; globaluserinfo.unattached && i < globaluserinfo.unattached.length; i++) {
}
if (globaluserinfo.unattached[i].wiki === mw.config.get('wgDBname')) {
for (i = 0; i < revisions.length; i++) {
lockedSulAccountIsAttachedToThis = false;
if (revisions[i].revid == navpop.diffData.oldRev.revid) {
break;
navpop.diffData.oldRev.revision = revisions[i];
}
} else if (revisions[i].revid == navpop.diffData.newRev.revid) {
}
navpop.diffData.newRev.revision = revisions[i];
if (lockedSulAccountIsAttachedToThis) {
}
if ('locked' in globaluserinfo) {
}
ret.push('<b><i>' + popupString('LOCKED') + '</i></b>');
} catch (someError) {
}
errlog('Could not get diff');
if ('hidden' in globaluserinfo) {
}
ret.push('<b><i>' + popupString('HIDDEN') + '</i></b>');
insertDiff(navpop);
}
}
}
function rmBoringLines(a, b, context) {
}
if (typeof context == 'undefined') {
if (getValueOf('popupShowGender') && user.gender) {
context = 2;
switch (user.gender) {
}
case 'male':
var aa = []
ret.push(popupString('he/him') + ' · ');
, aaa = [];
break;
var bb = []
case 'female':
, bbb = [];
ret.push(popupString('she/her') + ' · ');
var i, j;
break;
for (i = 0; i < a.length; ++i) {
}
if (!a[i].paired) {
}
aa[i] = 1;
if (user.groups) {
} else if (countCrossings(b, a, i, true)) {
user.groups.forEach(function (groupName) {
aa[i] = 1;
if (['*', 'user', 'autoconfirmed', 'extendedconfirmed', 'named'].indexOf(groupName) === -1) {
bb[a[i].row] = 1;
ret.push(
}
pg.escapeQuotesHTML(mw.message('group-' + groupName + '-member', user.gender).text())
}
);
for (i = 0; i < b.length; ++i) {
}
if (bb[i] == 1) {
});
continue;
}
}
if (globaluserinfo && globaluserinfo.groups) {
if (!b[i].paired) {
globaluserinfo.groups.forEach(function (groupName) {
bb[i] = 1;
ret.push(
}
'<i>' +
}
pg.escapeQuotesHTML(
for (i = 0; i < b.length; ++i) {
mw.message('group-' + groupName + '-member', user.gender).text()
if (bb[i] == 1) {
) +
for (j = Math.max(0, i - context); j < Math.min(b.length, i + context); ++j) {
'</i>'
if (!bb[j]) {
);
bb[j] = 1;
});
aa[b[j].row] = 0.5;
}
}
if (user.registration) {
}
ret.push(
}
pg.escapeQuotesHTML(
}
(user.editcount ? user.editcount : '0') +
for (i = 0; i < a.length; ++i) {
popupString(' edits since: ') +
if (aa[i] == 1) {
(user.registration ? formattedDate(new Date(user.registration)) : '')
for (j = Math.max(0, i - context); j < Math.min(a.length, i + context); ++j) {
)
if (!aa[j]) {
);
aa[j] = 1;
}
bb[a[j].row] = 0.5;
}
}

}
if (queryobj.usercontribs && queryobj.usercontribs.length) {
}
ret.push(
}
popupString('last edit on ') + formattedDate(new Date(queryobj.usercontribs[0].timestamp))
for (i = 0; i < bb.length; ++i) {
);
if (bb[i] > 0) {
}
if (b[i].paired) {

bbb.push(b[i].text);
if (queryobj.blocks) {
} else {
ret.push(popupString('IP user')); //we only request list=blocks for IPs
bbb.push(b[i]);
for (var l = 0; l < queryobj.blocks.length; l++) {
}
var rbstr =
}
queryobj.blocks[l].rangestart === queryobj.blocks[l].rangeend ? 'BLOCK' : 'RANGEBLOCK';
}
rbstr = !Array.isArray(queryobj.blocks[l].restrictions)
for (i = 0; i < aa.length; ++i) {
? 'Has ' + rbstr.toLowerCase() + 's'
if (aa[i] > 0) {
: rbstr + 'ED';
if (a[i].paired) {
ret.push('<b>' + popupString(rbstr) + '</b>');
aaa.push(a[i].text);
}
} else {
}
aaa.push(a[i]);

}
}
// if any element of ret ends with ' · ', merge it with the next element to avoid
// the .join(', ') call inserting a comma after it
}
return {
for (var m = 0; m < ret.length - 1; m++) {
if (ret[m].length > 3 && ret[m].substring(ret[m].length - 3) === ' · ') {
a: aaa,
ret[m] = ret[m] + ret[m + 1];
b: bbb
ret.splice(m + 1, 1); // delete element at index m+1
};
m--;
}
}
function stripOuterCommonLines(a, b, context) {
}
var i = 0;

while (i < a.length && i < b.length && a[i] == b[i]) {
ret = '<hr />' + ret.join(', ');
++i;
return ret;
}
}
var j = a.length - 1;

var k = b.length - 1;
function APIcontribsPreviewHTML(article, download, navpop) {
while (j >= 0 && k >= 0 && a[j] == b[k]) {
return APIhistoryPreviewHTML(article, download, navpop, true);
--j;
}
--k;

}
function APIhistoryPreviewHTML(article, download, navpop, reallyContribs) {
return {
try {
a: a.slice(Math.max(0, i - 1 - context), Math.min(a.length + 1, j + context + 1)),
var jsobj = getJsObj(download.data);
b: b.slice(Math.max(0, i - 1 - context), Math.min(b.length + 1, k + context + 1)),
var edits = [];
};
if (reallyContribs) {
}
edits = jsobj.query.usercontribs;
function insertDiff(navpop) {
} else {
var oldlines = navpop.diffData.oldRev.revision.slots.main.content.split('\n');
edits = anyChild(jsobj.query.pages).revisions;
var newlines = navpop.diffData.newRev.revision.slots.main.content.split('\n');
}
var inner = stripOuterCommonLines(oldlines, newlines, getValueOf('popupDiffContextLines'));

oldlines = inner.a;
var ret = editPreviewTable(article, edits, reallyContribs);
newlines = inner.b;
return ret;
var truncated = false;
} catch (someError) {
getValueOf('popupDiffMaxLines');
return 'History preview failed :-(';
if (oldlines.length > pg.option.popupDiffMaxLines || newlines.length > pg.option.popupDiffMaxLines) {
}
truncated = true;
}
inner = stripOuterCommonLines(oldlines.slice(0, pg.option.popupDiffMaxLines), newlines.slice(0, pg.option.popupDiffMaxLines), pg.option.popupDiffContextLines);

oldlines = inner.a;
// ENDFILE: querypreview.js
newlines = inner.b;

}
// STARTFILE: debug.js
var lineDiff = diff(oldlines, newlines);
////////////////////////////////////////////////////////////////////
var lines2 = rmBoringLines(lineDiff.o, lineDiff.n);
// Debugging functions
var oldlines2 = lines2.a;
////////////////////////////////////////////////////////////////////
var newlines2 = lines2.b;

var simpleSplit = !String.prototype.parenSplit.isNative;
function setupDebugging() {
var html = '<hr />';
if (window.popupDebug) {
if (getValueOf('popupDiffDates')) {
// popupDebug is set from .version
html += diffDatesTable(navpop);
window.log = function (x) {
html += '<hr />';
//if(gMsg!='')gMsg += '\n'; gMsg+=time() + ' ' + x; };
}
window.console.log(x);
html += shortenDiffString(diffString(oldlines2.join('\n'), newlines2.join('\n'), simpleSplit), getValueOf('popupDiffContextCharacters')).join('<hr />');
};
setPopupTipsAndHTML(html.split('\n').join('<br>') + (truncated ? '<hr /><b>' + popupString('Diff truncated for performance reasons') + '</b>' : ''), 'popupPreview', navpop.idNumber);
window.errlog = function (x) {
}
window.console.error(x);
function diffDatesTable(navpop) {
};
var html = '<table class="popup_diff_dates">';
log('Initializing logger');
html += diffDatesTableRow(navpop.diffData.newRev.revision, tprintf('New revision'));
} else {
html += diffDatesTableRow(navpop.diffData.oldRev.revision, tprintf('Old revision'));
window.log = function () {};
html += '</table>';
window.errlog = function () {};
return html;
}
}
}
function diffDatesTableRow(revision, label) {
// ENDFILE: debug.js
var txt = '';

var lastModifiedDate = new Date(revision.timestamp);
// STARTFILE: images.js
txt = formattedDateTime(lastModifiedDate);

var revlink = generalLink({
// load image of type Title.
url: mw.config.get('wgScript') + '?oldid=' + revision.revid,
function loadImage(image, navpop) {
text: label,
if (typeof image.stripNamespace != 'function') {
title: label,
alert('loadImages bad');
});
}
return simplePrintf('<tr><td>%s</td><td>%s</td></tr>', [revlink, txt]);
// API call to retrieve image info.
}

function titledDiffLink(l) {
if (!getValueOf('popupImages')) {
return titledWikiLink({
return;
article: l.article,
}
action: l.to + '&oldid=' + l.from,
if (!isValidImageName(image)) {
newWin: l.newWin,
return false;
noPopup: l.noPopup,
}
text: l.text,

title: l.title,
var art = image.urlString();
actionName: 'diff',

});
var url = pg.wiki.apiwikibase + '?format=json&formatversion=2&action=query';
}
url += '&prop=imageinfo&iiprop=url|mime&iiurlwidth=' + getValueOf('popupImageSizeLarge');
function wikiLink(l) {
url += '&titles=' + art;
if (!(typeof l.article == typeof {} && typeof l.action == typeof '' && typeof l.text == typeof '')) {

return null;
pendingNavpopTask(navpop);
}
var callback = function (d) {
if (typeof l.oldid == 'undefined') {
popupsInsertImage(navpop.idNumber, navpop, d);
l.oldid = null;
};
}
var go = function () {
var savedOldid = l.oldid;
getPageWithCaching(url, callback, navpop);
if (!/^(edit|view|revert|render)$|^raw/.test(l.action)) {
return true;
l.oldid = null;
};
}
if (navpop.visible || !getValueOf('popupLazyDownloads')) {
var hint = popupString(l.action + 'Hint');
go();
var oldidData = [l.oldid, safeDecodeURI(l.article)];
} else {
var revisionString = tprintf('revision %s of %s', oldidData);
navpop.addHook(go, 'unhide', 'after', 'DOWNLOAD_IMAGE_QUERY_DATA');
log('revisionString=' + revisionString);
}
switch (l.action) {
}
case 'edit&section=new':

hint = popupString('newSectionHint');
function popupsInsertImage(id, navpop, download) {
break;
log('popupsInsertImage');
case 'edit&undo=':
var imageinfo;
if (l.diff && l.diff != 'prev' && savedOldid) {
try {
l.action += l.diff + '&undoafter=' + savedOldid;
var jsObj = getJsObj(download.data);
} else if (savedOldid) {
var imagepage = anyChild(jsObj.query.pages);
l.action += savedOldid;
if (typeof imagepage.imageinfo === 'undefined') {
}
return;
hint = popupString('undoHint');
}
break;
imageinfo = imagepage.imageinfo[0];
case 'raw&ctype=text/css':
} catch (someError) {
hint = popupString('rawHint');
log('popupsInsertImage failed :(');
break;
return;
case 'revert':
}
var p = parseParams(pg.current.link.href);

l.action = 'edit&autoclick=wpSave&actoken=' + autoClickToken() + '&autoimpl=' + popupString('autoedit_version') + '&autosummary=' + revertSummary(l.oldid, p.diff);
var popupImage = document.getElementById('popupImg' + id);
if (p.diff == 'prev') {
if (!popupImage) {
l.action += '&direction=prev';
log('could not find insertion point for image');
revisionString = tprintf('the revision prior to revision %s of %s', oldidData);
return;
}
}
if (getValueOf('popupRevertSummaryPrompt')) {

l.action += '&autosummaryprompt=true';
popupImage.width = getValueOf('popupImageSize');
}
popupImage.style.display = 'inline';
if (getValueOf('popupMinorReverts')) {

l.action += '&autominor=true';
// Set the source for the image.
}
if (imageinfo.thumburl) {
log('revisionString is now ' + revisionString);
popupImage.src = imageinfo.thumburl;
break;
} else if (imageinfo.mime.indexOf('image') === 0) {
case 'nullEdit':
popupImage.src = imageinfo.url;
l.action = 'edit&autoclick=wpSave&actoken=' + autoClickToken() + '&autoimpl=' + popupString('autoedit_version') + '&autosummary=null';
log('a thumb could not be found, using original image');
break;
} else {
case 'historyfeed':
log("fullsize imagethumb, but not sure if it's an image");
l.action = 'history&feed=rss';
}
break;

case 'markpatrolled':
var a = document.getElementById('popupImageLink' + id);
l.action = 'markpatrolled&rcid=' + l.rcid;
if (a === null) {
}
return null;
if (hint) {
}
if (l.oldid) {

hint = simplePrintf(hint, [revisionString]);
// Determine the action of the surrouding imagelink.
} else {
switch (getValueOf('popupThumbAction')) {
hint = simplePrintf(hint, [safeDecodeURI(l.article)]);
case 'imagepage':
}
if (pg.current.article.namespaceId() != pg.nsImageId) {
} else {
a.href = imageinfo.descriptionurl;
hint = safeDecodeURI(l.article + '&action=' + l.action) + l.oldid ? '&oldid=' + l.oldid : '';
// FIXME: unreliable pg.idNumber
}
popTipsSoonFn('popupImage' + id)();
return titledWikiLink({
break;
article: l.article,
}
action: l.action,
/* falls through */
text: l.text,
case 'sizetoggle':
newWin: l.newWin,
a.onclick = toggleSize;
title: hint,
a.title = popupString('Toggle image size');
oldid: l.oldid,
return;
noPopup: l.noPopup,
case 'linkfull':
onclick: l.onclick,
a.href = imageinfo.url;
});
a.title = popupString('Open full-size image');
}
return;
function revertSummary(oldid, diff) {
}
var ret = '';
}
if (diff == 'prev') {

ret = getValueOf('popupQueriedRevertToPreviousSummary');
// Toggles the image between inline small and navpop fullwidth.
} else {
// It's the same image, no actual sizechange occurs, only display width.
ret = getValueOf('popupQueriedRevertSummary');
function toggleSize() {
}
var imgContainer = this;
return ret + '&autorv=' + oldid;
if (!imgContainer) {
}
alert('imgContainer is null :/');
function titledWikiLink(l) {
return;
if (typeof l.article == 'undefined' || typeof l.action == 'undefined') {
}
errlog('got undefined article or action in titledWikiLink');
var img = imgContainer.firstChild;
return null;
if (!img) {
}
alert('img is null :/');
var base = pg.wiki.titlebase + l.article.urlString();
return;
var url = base;
}
if (typeof l.actionName == 'undefined' || !l.actionName) {

l.actionName = 'action';
if (!img.style.width || img.style.width === '') {
}
img.style.width = '100%';
if (l.action != 'view') {
} else {
url = base + '&' + l.actionName + '=' + l.action;
img.style.width = '';
}
}
if (typeof l.oldid != 'undefined' && l.oldid) {
}
url += '&oldid=' + l.oldid;

}
// Returns one title of an image from wikiText.
var cssClass = pg.misc.defaultNavlinkClassname;
function getValidImageFromWikiText(wikiText) {
if (typeof l.className != 'undefined' && l.className) {
// nb in pg.re.image we're interested in the second bracketed expression
cssClass = l.className;
// this may change if the regex changes :-(
}
//var match=pg.re.image.exec(wikiText);
return generalNavLink({
var matched = null;
url: url,
var match;
newWin: l.newWin,
// strip html comments, used by evil bots :-(
title: typeof l.title != 'undefined' ? l.title : null,
var t = removeMatchesUnless(
text: typeof l.text != 'undefined' ? l.text : null,
wikiText,
className: cssClass,
RegExp('(<!--[\\s\\S]*?-->)'),
noPopup: l.noPopup,
1,
onclick: l.onclick,
RegExp('^<!--[^[]*popup', 'i')
});
);
}

pg.fn.getLastContrib = function getLastContrib(wikipage, newWin) {
while ((match = pg.re.image.exec(t))) {
getHistoryInfo(wikipage, function(x) {
// now find a sane image name - exclude templates by seeking {
processLastContribInfo(x, {
var m = match[2] || match[6];
page: wikipage,
if (isValidImageName(m)) {
newWin: newWin
matched = m;
});
break;
});
}
}
}
;
pg.re.image.lastIndex = 0;
function processLastContribInfo(info, stuff) {
if (!matched) {
if (!info.edits || !info.edits.length) {
return null;
alert('Popups: an odd thing happened. Please retry.');
}
return;
return mw.config.get('wgFormattedNamespaces')[pg.nsImageId] + ':' + upcaseFirst(matched);
}
}
if (!info.firstNewEditor) {

alert(tprintf('Only found one editor: %s made %s edits', [info.edits[0].editor, info.edits.length, ]));
function removeMatchesUnless(str, re1, parencount, re2) {
return;
var split = str.parenSplit(re1);
}
var c = parencount + 1;
var newUrl = pg.wiki.titlebase + new Title(stuff.page).urlString() + '&diff=cur&oldid=' + info.firstNewEditor.oldid;
for (var i = 0; i < split.length; ++i) {
displayUrl(newUrl, stuff.newWin);
if (i % c === 0 || re2.test(split[i])) {
}
continue;
pg.fn.getDiffSinceMyEdit = function getDiffSinceMyEdit(wikipage, newWin) {
}
getHistoryInfo(wikipage, function(x) {
split[i] = '';
processDiffSinceMyEdit(x, {
}
page: wikipage,
return split.join('');
newWin: newWin
}
});

});
// ENDFILE: images.js
}

;
// STARTFILE: namespaces.js
function processDiffSinceMyEdit(info, stuff) {
// Set up namespaces and other non-strings.js localization
if (!info.edits || !info.edits.length) {
// (currently that means redirs too)
alert('Popups: something fishy happened. Please try again.');

return;
function setNamespaces() {
}
pg.nsSpecialId = -1;
var friendlyName = stuff.page.split('_').join(' ');
pg.nsMainspaceId = 0;
if (!info.myLastEdit) {
pg.nsImageId = 6;
alert(tprintf("Couldn't find an edit by %s\nin the last %s edits to\n%s", [info.userName, getValueOf('popupHistoryLimit'), friendlyName, ]));
pg.nsUserId = 2;
return;
pg.nsUsertalkId = 3;
}
pg.nsCategoryId = 14;
if (info.myLastEdit.index === 0) {
pg.nsTemplateId = 10;
alert(tprintf('%s seems to be the last editor to the page %s', [info.userName, friendlyName]));
}
return;

}
function setRedirs() {
var newUrl = pg.wiki.titlebase + new Title(stuff.page).urlString() + '&diff=cur&oldid=' + info.myLastEdit.oldid;
var r = 'redirect';
displayUrl(newUrl, stuff.newWin);
var R = 'REDIRECT';
}
var redirLists = {
function displayUrl(url, newWin) {
ar: [R, 'تحويل'],
if (newWin) {
be: [r, 'перанакіраваньне'],
window.open(url);
bg: [r, 'пренасочване', 'виж'],
} else {
bs: [r, 'Preusmjeri', 'preusmjeri', 'PREUSMJERI'],
document.location = url;
bn: [R, 'পুনর্নির্দেশ'],
}
cs: [R, 'PŘESMĚRUJ'],
}
cy: [r, 'ail-cyfeirio'],
pg.fn.purgePopups = function purgePopups() {
de: [R, 'WEITERLEITUNG'],
processAllPopups(true);
el: [R, 'ΑΝΑΚΑΤΕΥΘΥΝΣΗ'],
setupCache();
eo: [R, 'ALIDIREKTU', 'ALIDIREKTI'],
pg.option = {};
es: [R, 'REDIRECCIÓN'],
abortAllDownloads();
et: [r, 'suuna'],
}
ga: [r, 'athsheoladh'],
;
gl: [r, 'REDIRECCIÓN', 'REDIRECIONAMENTO'],
function processAllPopups(nullify, banish) {
he: [R, 'הפניה'],
for (var i = 0; pg.current.links && i < pg.current.links.length; ++i) {
hu: [R, 'ÁTIRÁNYÍTÁS'],
if (!pg.current.links[i].navpopup) {
is: [r, 'tilvísun', 'TILVÍSUN'],
continue;
it: [R, 'RINVIA', 'Rinvia'],
}
ja: [R, '転送'],
if (nullify || banish) {
mk: [r, 'пренасочување', 'види'],
pg.current.links[i].navpopup.banish();
nds: [r, 'wiederleiden'],
}
'nds-nl': [R, 'DEURVERWIEZING', 'DUURVERWIEZING'],
pg.current.links[i].simpleNoMore = false;
nl: [R, 'DOORVERWIJZING'],
if (nullify) {
nn: [r, 'omdiriger'],
pg.current.links[i].navpopup = null;
pl: [R, 'PATRZ', 'PRZEKIERUJ', 'TAM'],
}
pt: [R, 'redir'],
}
ru: [R, 'ПЕРЕНАПРАВЛЕНИЕ', 'ПЕРЕНАПР'],
}
sk: [r, 'presmeruj'],
pg.fn.disablePopups = function disablePopups() {
sr: [r, 'Преусмери', 'преусмери', 'ПРЕУСМЕРИ', 'Preusmeri', 'preusmeri', 'PREUSMERI'],
processAllPopups(false, true);
tr: [R, 'YÖNLENDİRME', 'yönlendirme', 'YÖNLENDİR', 'yönlendir'],
setupTooltips(null, true);
tt: [R, 'yünältü', 'перенаправление', 'перенапр'],
}
uk: [R, 'ПЕРЕНАПРАВЛЕННЯ', 'ПЕРЕНАПР'],
;
vi: [r, 'đổi'],
pg.fn.togglePreviews = function togglePreviews() {
yi: [R, 'ווייטערפירן'],
processAllPopups(true, true);
zh: [R, '重定向'], // no comma
pg.option.simplePopups = !pg.option.simplePopups;
};
abortAllDownloads();
var redirList = redirLists[pg.wiki.lang] || [r, R];
}
// Mediawiki is very tolerant about what comes after the #redirect at the start
;
pg.re.redirect = RegExp(
function magicWatchLink(l) {
'^\\s*[#](' + redirList.join('|') + ').*?\\[{2}([^\\|\\]]*)(|[^\\]]*)?\\]{2}\\s*(.*)',
l.onclick = simplePrintf("pg.fn.modifyWatchlist('%s','%s');return false;", [l.article.toString(true).split('\\').join('\\\\').split("'").join("\\'"), this.id, ]);
'i'
return wikiLink(l);
);
}
}
pg.fn.modifyWatchlist = function modifyWatchlist(title, action) {

var reqData = {
function setInterwiki() {
action: 'watch',
if (pg.wiki.wikimedia) {
formatversion: 2,
// From https://meta.wikimedia.org/wiki/List_of_Wikipedias
titles: title,
//en.wikipedia.org/w/api.php?action=sitematrix&format=json&smtype=language&smlangprop=code&formatversion=2
uselang: mw.config.get('wgUserLanguage'),
pg.wiki.interwiki =
};
'aa|ab|ace|af|ak|als|am|an|ang|ar|arc|arz|as|ast|av|ay|az|ba|bar|bat-smg|bcl|be|be-x-old|bg|bh|bi|bjn|bm|bn|bo|bpy|br|bs|bug|bxr|ca|cbk-zam|cdo|ce|ceb|ch|cho|chr|chy|ckb|co|cr|crh|cs|csb|cu|cv|cy|da|de|diq|dsb|dv|dz|ee|el|eml|en|eo|es|et|eu|ext|fa|ff|fi|fiu-vro|fj|fo|fr|frp|frr|fur|fy|ga|gag|gan|gd|gl|glk|gn|got|gu|gv|ha|hak|haw|he|hi|hif|ho|hr|hsb|ht|hu|hy|hz|ia|id|ie|ig|ii|ik|ilo|io|is|it|iu|ja|jbo|jv|ka|kaa|kab|kbd|kg|ki|kj|kk|kl|km|kn|ko|koi|kr|krc|ks|ksh|ku|kv|kw|ky|la|lad|lb|lbe|lg|li|lij|lmo|ln|lo|lt|ltg|lv|map-bms|mdf|mg|mh|mhr|mi|mk|ml|mn|mo|mr|mrj|ms|mt|mus|mwl|my|myv|mzn|na|nah|nap|nds|nds-nl|ne|new|ng|nl|nn|no|nov|nrm|nv|ny|oc|om|or|os|pa|pag|pam|pap|pcd|pdc|pfl|pi|pih|pl|pms|pnb|pnt|ps|pt|qu|rm|rmy|rn|ro|roa-rup|roa-tara|ru|rue|rw|sa|sah|sc|scn|sco|sd|se|sg|sh|si|simple|sk|sl|sm|sn|so|sq|sr|srn|ss|st|stq|su|sv|sw|szl|ta|te|tet|tg|th|ti|tk|tl|tn|to|tpi|tr|ts|tt|tum|tw|ty|udm|ug|uk|ur|uz|ve|vec|vi|vls|vo|wa|war|wo|wuu|xal|xh|yi|yo|za|zea|zh|zh-classical|zh-min-nan|zh-yue|zu';
if (action === 'unwatch') {
pg.re.interwiki = RegExp('^' + pg.wiki.interwiki + ':');
reqData.unwatch = true;
} else {
}
pg.wiki.interwiki = null;
var mwTitle = mw.Title.newFromText(title);
pg.re.interwiki = RegExp('^$');
var messageName;
}
if (mwTitle && mwTitle.getNamespaceId() > 0 && mwTitle.getNamespaceId() % 2 === 1) {
}
messageName = action === 'watch' ? 'addedwatchtext-talk' : 'removedwatchtext-talk';

} else {
// return a regexp pattern matching all variants to write the given namespace
messageName = action === 'watch' ? 'addedwatchtext' : 'removedwatchtext';
function nsRe(namespaceId) {
}
var imageNamespaceVariants = [];
$.when(getMwApi().postWithToken('watch', reqData), getMwApi().loadMessagesIfMissing([messageName])).done(function() {
jQuery.each(mw.config.get('wgNamespaceIds'), function (_localizedNamespaceLc, _namespaceId) {
mw.notify(mw.message(messageName, title).parseDom());
if (_namespaceId != namespaceId) {
});
return;
}
}
;
_localizedNamespaceLc = upcaseFirst(_localizedNamespaceLc);
function magicHistoryLink(l) {
imageNamespaceVariants.push(
var jsUrl = ''
mw.util.escapeRegExp(_localizedNamespaceLc).split(' ').join('[ _]')
, title = ''
);
, onClick = '';
imageNamespaceVariants.push(mw.util.escapeRegExp(encodeURI(_localizedNamespaceLc)));
switch (l.id) {
});
case 'lastContrib':

onClick = simplePrintf("pg.fn.getLastContrib('%s',%s)", [l.article.toString(true).split('\\').join('\\\\').split("'").join("\\'"), l.newWin, ]);
return '(?:' + imageNamespaceVariants.join('|') + ')';
title = popupString('lastContribHint');
}
break;

case 'sinceMe':
function nsReImage() {
onClick = simplePrintf("pg.fn.getDiffSinceMyEdit('%s',%s)", [l.article.toString(true).split('\\').join('\\\\').split("'").join("\\'"), l.newWin, ]);
return nsRe(pg.nsImageId);
title = popupString('sinceMeHint');
}
break;
// ENDFILE: namespaces.js
}

jsUrl = 'javascript:' + onClick;
// STARTFILE: selpop.js
onClick += ';return false;';
function getEditboxSelection() {
return generalNavLink({
// see http://www.webgurusforum.com/8/12/0
url: jsUrl,
var editbox;
newWin: false,
try {
title: title,
editbox = document.editform.wpTextbox1;
text: l.text,
} catch (dang) {
noPopup: l.noPopup,
return;
onclick: onClick,
}
});
// IE, Opera
}
if (document.selection) {
function popupMenuLink(l) {
return document.selection.createRange().text;
var jsUrl = simplePrintf('javascript:pg.fn.%s()', [l.id]);
}
var title = popupString(simplePrintf('%sHint', [l.id]));
// Mozilla
var onClick = simplePrintf('pg.fn.%s();return false;', [l.id]);
var selStart = editbox.selectionStart;
return generalNavLink({
var selEnd = editbox.selectionEnd;
url: jsUrl,
return editbox.value.substring(selStart, selEnd);
newWin: false,
}
title: title,

text: l.text,
function doSelectionPopup() {
noPopup: l.noPopup,
// popup if the selection looks like [[foo|anything afterwards at all
onclick: onClick,
// or [[foo|bar]]text without ']]'
});
// or [[foo|bar]]
}
var sel = getEditboxSelection();
function specialLink(l) {
var open = sel.indexOf('[[');
if (typeof l.specialpage == 'undefined' || !l.specialpage) {
var pipe = sel.indexOf('|');
return null;
var close = sel.indexOf(']]');
}
if (open == -1 || (pipe == -1 && close == -1)) {
var base = pg.wiki.titlebase + mw.config.get('wgFormattedNamespaces')[pg.nsSpecialId] + ':' + l.specialpage;
return;
if (typeof l.sep == 'undefined' || l.sep === null) {
}
l.sep = '&target=';
}
if ((pipe != -1 && open > pipe) || (close != -1 && open > close)) {
return;
var article = l.article.urlString({
}
keepSpaces: l.specialpage == 'Search',
var article = new Title(sel.substring(open + 2, pipe < 0 ? close : pipe));
});
if (getValueOf('popupOnEditSelection') == 'boxpreview') {
var hint = popupString(l.specialpage + 'Hint');
return doSeparateSelectionPopup(sel, article);
switch (l.specialpage) {
}
case 'Log':
if (close > 0 && sel.substring(close + 2).indexOf('[[') >= 0) {
switch (l.sep) {
return;
case '&user=':
}
hint = popupString('userLogHint');
var a = document.createElement('a');
break;
a.href = pg.wiki.titlebase + article.urlString();
case '&type=block&page=':
mouseOverWikiLink2(a);
hint = popupString('blockLogHint');
if (a.navpopup) {
break;
a.navpopup.addHook(
case '&page=':
function () {
hint = popupString('pageLogHint');
runStopPopupTimer(a.navpopup);
break;
},
case '&type=protect&page=':
'unhide',
hint = popupString('protectLogHint');
'after'
break;
);
case '&type=delete&page=':
}
hint = popupString('deleteLogHint');
}
break;

default:
function doSeparateSelectionPopup(str, article) {
log('Unknown log type, sep=' + l.sep);
var div = document.getElementById('selectionPreview');
hint = 'Missing hint (FIXME)';
if (!div) {
}
div = document.createElement('div');
break;
div.id = 'selectionPreview';
case 'PrefixIndex':
try {
article += '/';
var box = document.editform.wpTextbox1;
break;
box.parentNode.insertBefore(div, box);
}
} catch (error) {
if (hint) {
return;
hint = simplePrintf(hint, [safeDecodeURI(l.article)]);
}
} else {
}
hint = safeDecodeURI(l.specialpage + ':' + l.article);
var p = prepPreviewmaker(str, article, newNavpopup(document.createElement('a'), article));
}
p.makePreview();
var url = base + l.sep + article;
if (p.html) {
return generalNavLink({
div.innerHTML = p.html;
url: url,
}
title: hint,
div.ranSetupTooltipsAlready = false;
text: l.text,
popTipsSoonFn('selectionPreview')();
newWin: l.newWin,
}
noPopup: l.noPopup,
// ENDFILE: selpop.js
});

}
// STARTFILE: navpopup.js
function generalLink(link) {
/**
if (typeof link.url == 'undefined') {
* @fileoverview Defines two classes: {@link Navpopup} and {@link Mousetracker}.
return null;
*
}
* <code>Navpopup</code> describes popups: when they appear, where, what
var elem = document.createElement('a');
* they look like and so on.
elem.href = link.url;
*
elem.title = link.title;
* <code>Mousetracker</code> "captures" the mouse using
elem.setAttribute('onclick', link.onclick);
* <code>document.onmousemove</code>.
if (link.noPopup) {
*/
elem.setAttribute('noPopup', '1');

}
/**
var newWin;
* Creates a new Mousetracker.
if (typeof link.newWin == 'undefined' || link.newWin === null) {
* @constructor
newWin = getValueOf('popupNewWindows');
* @class The Mousetracker class. This monitors mouse movements and manages associated hooks.
} else {
*/
newWin = link.newWin;
function Mousetracker() {
}
/**
if (newWin) {
* Interval to regularly run the hooks anyway, in milliseconds.
elem.target = '_blank';
* @type {number}
}
*/
if (link.className) {
this.loopDelay = 400;
elem.className = link.className;

}
/**
elem.innerText = pg.unescapeQuotesHTML(link.text);
* Timer for the loop.
return elem.outerHTML;
* @type Timer
}
*/
function appendParamsToLink(linkstr, params) {
this.timer = null;
var sp = linkstr.parenSplit(RegExp('(href="[^"]+?)"', 'i'));

if (sp.length < 2) {
/**
return null;
* Flag - are we switched on?
}
* @type {boolean}
var ret = sp.shift() + sp.shift();
*/
ret += '&' + params + '"';
this.active = false;
ret += sp.join('');

return ret;
/**
}
* Flag - are we probably inaccurate, i.e. not reflecting the actual mouse position?
function changeLinkTargetLink(x) {
*/
if (x.newTarget) {
this.dirty = true;
log('changeLinkTargetLink: newTarget=' + x.newTarget);

}
/**
if (x.oldTarget !== decodeURIComponent(x.oldTarget)) {
* Array of hook functions.
log('This might be an input problem: ' + x.oldTarget);
* @private
}
* @type {Array}
var cA = mw.util.escapeRegExp(x.oldTarget);
*/
var chs = cA.charAt(0).toUpperCase();
this.hooks = [];
chs = '[' + chs + chs.toLowerCase() + ']';
}
var currentArticleRegexBit = chs + cA.substring(1);

currentArticleRegexBit = currentArticleRegexBit.split(RegExp('(?:[_ ]+|%20)', 'g')).join('(?:[_ ]+|%20)').split('\\(').join('(?:%28|\\()').split('\\)').join('(?:%29|\\))');
/**
currentArticleRegexBit = '\\s*(' + currentArticleRegexBit + '(?:#[^\\[\\|]*)?)\\s*';
* Adds a hook, to be called when we get events.
var title = x.title || mw.config.get('wgPageName').split('_').join(' ');
* @param {Function} f A function which is called as
var lk = titledWikiLink({
* <code>f(x,y)</code>. It should return <code>true</code> when it
article: new Title(title),
* wants to be removed, and <code>false</code> otherwise.
newWin: x.newWin,
*/
action: 'edit',
Mousetracker.prototype.addHook = function (f) {
text: x.text,
this.hooks.push(f);
title: x.hint,
};
className: 'popup_change_title_link',

});
/**
var cmd = '';
* Runs hooks, passing them the x
if (x.newTarget) {
* and y coords of the mouse. Hook functions that return true are
var t = x.newTarget;
* passed to {@link Mousetracker#removeHooks} for removal.
var s = mw.util.escapeRegExp(x.newTarget);
* @private
if (x.alsoChangeLabel) {
*/
cmd += 's~\\[\\[' + currentArticleRegexBit + '\\]\\]~[[' + t + ']]~g;';
Mousetracker.prototype.runHooks = function () {
cmd += 's~\\[\\[' + currentArticleRegexBit + '[|]~[[' + t + '|~g;';
if (!this.hooks || !this.hooks.length) {
cmd += 's~\\[\\[' + s + '\\|' + s + '\\]\\]~[[' + t + ']]~g';
return;
} else {
}
cmd += 's~\\[\\[' + currentArticleRegexBit + '\\]\\]~[[' + t + '|$1]]~g;';
//log('Mousetracker.runHooks; we got some hooks to run');
cmd += 's~\\[\\[' + currentArticleRegexBit + '[|]~[[' + t + '|~g;';
var remove = false;
cmd += 's~\\[\\[' + s + '\\|' + s + '\\]\\]~[[' + t + ']]~g';
var removeObj = {};
}
// this method gets called a LOT -
} else {
// pre-cache some variables
cmd += 's~\\[\\[' + currentArticleRegexBit + '\\]\\]~$1~g;';
var x = this.x,
cmd += 's~\\[\\[' + currentArticleRegexBit + '[|](.*?)\\]\\]~$2~g';
y = this.y,
}
len = this.hooks.length;
cmd = 'autoedit=' + encodeURIComponent(cmd);

cmd += '&autoclick=' + encodeURIComponent(x.clickButton) + '&actoken=' + encodeURIComponent(autoClickToken());
for (var i = 0; i < len; ++i) {
cmd += x.minor === null ? '' : '&autominor=' + encodeURIComponent(x.minor);
//~ run the hook function, and remove it if it returns true
cmd += x.watch === null ? '' : '&autowatch=' + encodeURIComponent(x.watch);
if (this.hooks[i](x, y) === true) {
cmd += '&autosummary=' + encodeURIComponent(x.summary);
remove = true;
cmd += '&autoimpl=' + encodeURIComponent(popupString('autoedit_version'));
removeObj[i] = true;
return appendParamsToLink(lk, cmd);
}
}
}
function redirLink(redirMatch, article) {
if (remove) {
var ret = '';
this.removeHooks(removeObj);
if (getValueOf('popupAppendRedirNavLinks') && getValueOf('popupNavLinks')) {
}
ret += '<hr />';
};
if (getValueOf('popupFixRedirs') && typeof autoEdit != 'undefined' && autoEdit) {

ret += popupString('Redirects to: (Fix ');
/**
log('redirLink: newTarget=' + redirMatch);
* Removes hooks.
ret += addPopupShortcut(changeLinkTargetLink({
* @private
newTarget: redirMatch,
* @param {Object} removeObj An object whose keys are the index
text: popupString('target'),
* numbers of functions for removal, with values that evaluate to true
hint: popupString('Fix this redirect, changing just the link target'),
*/
summary: simplePrintf(getValueOf('popupFixRedirsSummary'), [article.toString(), redirMatch, ]),
Mousetracker.prototype.removeHooks = function (removeObj) {
oldTarget: article.toString(),
var newHooks = [];
clickButton: getValueOf('popupRedirAutoClick'),
var len = this.hooks.length;
minor: true,
for (var i = 0; i < len; ++i) {
watch: getValueOf('popupWatchRedirredPages'),
if (!removeObj[i]) {
}), 'R');
newHooks.push(this.hooks[i]);
ret += popupString(' or ');
}
ret += addPopupShortcut(changeLinkTargetLink({
}
newTarget: redirMatch,
this.hooks = newHooks;
text: popupString('target & label'),
};
hint: popupString('Fix this redirect, changing the link target and label'),

summary: simplePrintf(getValueOf('popupFixRedirsSummary'), [article.toString(), redirMatch, ]),
/**
oldTarget: article.toString(),
* Event handler for mouse wiggles.
clickButton: getValueOf('popupRedirAutoClick'),
* We simply grab the event, set x and y and run the hooks.
minor: true,
* This makes the cpu all hot and bothered :-(
watch: getValueOf('popupWatchRedirredPages'),
* @private
alsoChangeLabel: true,
* @param {Event} e Mousemove event
}), 'R');
*/
ret += popupString(')');
Mousetracker.prototype.track = function (e) {
} else {
//~ Apparently this is needed in IE.
ret += popupString('Redirects') + popupString(' to ');
e = e || window.event;
}
var x, y;
return ret;
if (e) {
} else {
if (e.pageX) {
return ('<br> ' + popupString('Redirects') + popupString(' to ') + titledWikiLink({
x = e.pageX;
article: new Title().fromWikiText(redirMatch),
y = e.pageY;
action: 'view',
} else if (typeof e.clientX != 'undefined') {
text: safeDecodeURI(redirMatch),
var left,
title: popupString('Bypass redirect'),
top,
}));
docElt = document.documentElement;
}

}
if (docElt) {
function arinLink(l) {
left = docElt.scrollLeft;
if (!saneLinkCheck(l)) {
}
return
left = left || document.body.scrollLeft || document.scrollLeft || 0;
null;

}
if (docElt) {
if (!l.article.isIpUser() || !pg.wiki.wikimedia) {
top = docElt.scrollTop;
return null;
}
}
top = top || document.body.scrollTop || document.scrollTop || 0;
var uN = l.article.userName();

return generalNavLink({
x = e.clientX + left;
url: 'http://ws.arin.net/cgi-bin/whois.pl?queryinput=' + encodeURIComponent(uN),
y = e.clientY + top;
newWin: l.newWin,
} else {
title: tprintf('Look up %s in ARIN whois database', [uN]),
return;
text: l.text,
}
noPopup: 1,
this.setPosition(x, y);
});
}
}
};
function toolDbName(cookieStyle) {

var ret = mw.config.get('wgDBname');
/**
if (!cookieStyle) {
* Sets the x and y coordinates stored and takes appropriate action,
ret += '_p';
* running hooks as appropriate.
}
* @param {number} x, y Screen coordinates to set
return ret;
*/
}
Mousetracker.prototype.setPosition = function (x, y) {
function saneLinkCheck(l) {
this.x = x;
if (typeof l.article != typeof {} || typeof l.text != typeof '') {
this.y = y;
return false;
if (this.dirty || this.hooks.length === 0) {
}
this.dirty = false;
return true;
return;
}
}
function editCounterLink(l) {
if (typeof this.lastHook_x != 'number') {
if (!saneLinkCheck(l)) {
this.lastHook_x = -100;
return null;
this.lastHook_y = -100;
}
}
if (!pg.wiki.wikimedia) {
var diff = (this.lastHook_x - x) * (this.lastHook_y - y);
return null;
}
diff = diff >= 0 ? diff : -diff;
if (diff > 1) {
var uN = l.article.userName();
this.lastHook_x = x;
var tool = getValueOf('popupEditCounterTool');
this.lastHook_y = y;
var url;
if (this.dirty) {
var defaultToolUrl = 'https://xtools.wmflabs.org/ec?user=$1&project=$2.$3&uselang=' + mw.config.get('wgUserLanguage');
this.dirty = false;
switch (tool) {
} else {
case 'custom':
this.runHooks();
url = simplePrintf(getValueOf('popupEditCounterUrl'), [encodeURIComponent(uN), toolDbName(), ]);
}
break;
}
case 'soxred':
};
case 'kate':

case 'interiot':
/**
case 'supercount':
* Sets things in motion, unless they are already that is, registering an event handler on
default:
* <code>document.onmousemove</code>. A half-hearted attempt is made to preserve the old event
var theWiki = pg.wiki.hostname.split('.');
* handler if there is one.
url = simplePrintf(defaultToolUrl, [encodeURIComponent(uN), theWiki[0], theWiki[1]]);
*/
}
Mousetracker.prototype.enable = function () {
return generalNavLink({
if (this.active) {
url: url,
return;
title: tprintf('editCounterLinkHint', [uN]),
}
newWin: l.newWin,
this.active = true;
text: l.text,
//~ Save the current handler for mousemove events. This isn't too
noPopup: 1,
//~ robust, of course.
});
this.savedHandler = document.onmousemove;
}
//~ Gotta save @tt{this} again for the closure, and use apply for
function globalSearchLink(l) {
//~ the member function.
if (!saneLinkCheck(l)) {
var savedThis = this;
return null;
document.onmousemove = function (e) {
}
savedThis.track.apply(savedThis, [e]);
var base = 'https://global-search.toolforge.org/?uselang=' + mw.config.get('wgUserLanguage') + '&q=';
};
var article = l.article.urlString({
if (this.loopDelay) {
keepSpaces: true
this.timer = setInterval(function () {
});
//log('loop delay in mousetracker is working');
return generalNavLink({
savedThis.runHooks();
url: base + article,
}, this.loopDelay);
newWin: l.newWin,
}
title: tprintf('globalSearchHint', [safeDecodeURI(l.article)]),
};
text: l.text,

noPopup: 1,
/**
});
* Disables the tracker, removing the event handler.
}
*/
function googleLink(l) {
Mousetracker.prototype.disable = function () {
if (!saneLinkCheck(l)) {
if (!this.active) {
return null;
return;
}
}
var base = 'https://www.google.com/search?q=';
if (typeof this.savedHandler === 'function') {
var article = l.article.urlString({
document.onmousemove = this.savedHandler;
keepSpaces: true
} else {
});
delete document.onmousemove;
return generalNavLink({
}
url: base + '%22' + article + '%22',
if (this.timer) {
newWin: l.newWin,
clearInterval(this.timer);
title: tprintf('googleSearchHint', [safeDecodeURI(l.article)]),
}
text: l.text,
this.active = false;
noPopup: 1,
};
});

}
/**
function editorListLink(l) {
* Creates a new Navpopup.
if (!saneLinkCheck(l)) {
* Gets a UID for the popup and
return null;
* @param init Contructor object. If <code>init.draggable</code> is true or absent, the popup becomes draggable.
}
* @constructor
var article = l.article.articleFromTalkPage() || l.article;
* @class The Navpopup class. This generates popup hints, and does some management of them.
var url = 'https://xtools.wmflabs.org/articleinfo/' + encodeURI(pg.wiki.hostname) + '/' + article.urlString() + '?uselang=' + mw.config.get('wgUserLanguage');
*/
return generalNavLink({
function Navpopup(/*init*/) {
url: url,
//alert('new Navpopup(init)');
title: tprintf('editorListHint', [article]),

newWin: l.newWin,
/**
text: l.text,
* UID for each Navpopup instance.
noPopup: 1,
* Read-only.
});
* @type {number}
}
*/
function generalNavLink(l) {
this.uid = Navpopup.uid++;
l.className = l.className === null ? 'popupNavLink' : l.className;

return generalLink(l);
/**
}
* Read-only flag for current visibility of the popup.
function getHistoryInfo(wikipage, whatNext) {
* @type {boolean}
log('getHistoryInfo');
* @private
getHistory(wikipage, whatNext ? function(d) {
*/
whatNext(processHistory(d));
this.visible = false;
}

: processHistory);
/** Flag to be set when we want to cancel a previous request to
}
* show the popup in a little while.
function getHistory(wikipage, onComplete) {
* @private
log('getHistory');
* @type {boolean}
var url = pg.wiki.apiwikibase + '?format=json&formatversion=2&action=query&prop=revisions&titles=' + new Title(wikipage).urlString() + '&rvlimit=' + getValueOf('popupHistoryLimit');
*/
log('getHistory: url=' + url);
this.noshow = false;
return startDownload(url, pg.idNumber + 'history', onComplete);

}
/** Categorised list of hooks.
function processHistory(download) {
* @see #runHooks
var jsobj = getJsObj(download.data);
* @see #addHook
try {
* @private
var revisions = anyChild(jsobj.query.pages).revisions;
* @type {Object}
var edits = [];
*/
for (var i = 0; i < revisions.length; ++i) {
this.hooks = {
edits.push({
create: [],
oldid: revisions[i].revid,
unhide: [],
editor: revisions[i].user
hide: [],
});
};
}

log('processed ' + edits.length + ' edits');
/**
return finishProcessHistory(edits, mw.config.get('wgUserName'));
* list of unique IDs of hook functions, to avoid duplicates
} catch (someError) {
* @private
log('Something went wrong with JSON business');
*/
return finishProcessHistory([]);
this.hookIds = {};
}

}
/** List of downloads associated with the popup.
function finishProcessHistory(edits, userName) {
* @private
var histInfo = {};
* @type {Array}
histInfo.edits = edits;
*/
histInfo.userName = userName;
this.downloads = [];
for (var i = 0; i < edits.length; ++i) {

if (typeof histInfo.myLastEdit === 'undefined' && userName && edits[i].editor == userName) {
/**
histInfo.myLastEdit = {
* Number of uncompleted downloads.
index: i,
* @type {number}
oldid: edits[i].oldid,
*/
previd: i === 0 ? null : edits[i - 1].oldid,
this.pending = null;
};

}
/**
if (typeof histInfo.firstNewEditor === 'undefined' && edits[i].editor != edits[0].editor) {
* Tolerance in pixels when detecting whether the mouse has left the popup.
histInfo.firstNewEditor = {
* @type {number}
index: i,
*/
oldid: edits[i].oldid,
this.fuzz = 5;
previd: i === 0 ? null : edits[i - 1].oldid,

};
/**
}
* Flag to toggle running {@link #limitHorizontalPosition} to regulate the popup's position.
}
* @type {boolean}
return histInfo;
*/
}
this.constrained = true;
function defaultize(x) {

if (pg.option[x] === null || typeof pg.option[x] == 'undefined') {
/**
if (typeof window[x] != 'undefined') {
* The popup width in pixels.
pg.option[x] = window[x];
* @private
} else {
* @type {number}
pg.option[x] = pg.optionDefault[x];
*/
}
this.width = 0;
}

}
/**
function newOption(x, def) {
* The popup width in pixels.
pg.optionDefault[x] = def;
* @private
}
* @type {number}
function setDefault(x, def) {
*/
return newOption(x, def);
this.height = 0;
}

function getValueOf(varName) {
/**
defaultize(varName);
* The main content DIV element.
return pg.option[varName];
* @type HTMLDivElement
}
*/
function useDefaultOptions() {
this.mainDiv = null;
for (var p in pg.optionDefault) {
this.createMainDiv();
pg.option[p] = pg.optionDefault[p];

if (typeof window[p] != 'undefined') {
// if (!init || typeof init.popups_draggable=='undefined' || init.popups_draggable) {
delete window[p];
// this.makeDraggable(true);
}
// }
}
}
}

function setOptions() {
/**
var userIsSysop = false;
* A UID for each Navpopup. This constructor property is just a counter.
if (mw.config.get('wgUserGroups')) {
* @type {number}
for (var g = 0; g < mw.config.get('wgUserGroups').length; ++g) {
* @private
if (mw.config.get('wgUserGroups')[g] == 'sysop') {
*/
userIsSysop = true;
Navpopup.uid = 0;
}

}
/**
}
* Retrieves the {@link #visible} attribute, indicating whether the popup is currently visible.
newOption('popupDelay', 0.5);
* @type {boolean}
newOption('popupHideDelay', 0.5);
*/
newOption('simplePopups', false);
Navpopup.prototype.isVisible = function () {
newOption('popupStructure', 'shortmenus');
return this.visible;
newOption('popupActionsMenu', true);
};
newOption('popupSetupMenu', true);

newOption('popupAdminLinks', userIsSysop);
/**
newOption('popupShortcutKeys', false);
* Repositions popup using CSS style.
newOption('popupHistoricalLinks', true);
* @private
newOption('popupOnlyArticleLinks', true);
* @param {number} x x-coordinate (px)
newOption('removeTitles', true);
* @param {number} y y-coordinate (px)
newOption('popupMaxWidth', 350);
* @param {boolean} noLimitHor Don't call {@link #limitHorizontalPosition}
newOption('popupSimplifyMainLink', true);
*/
newOption('popupAppendRedirNavLinks', true);
Navpopup.prototype.reposition = function (x, y, noLimitHor) {
newOption('popupTocLinks', false);
log('reposition(' + x + ',' + y + ',' + noLimitHor + ')');
newOption('popupSubpopups', true);
if (typeof x != 'undefined' && x !== null) {
newOption('popupDragHandle', false);
this.left = x;
newOption('popupLazyPreviews', true);
}
newOption('popupLazyDownloads', true);
if (typeof y != 'undefined' && y !== null) {
newOption('popupAllDabsStubs', false);
this.top = y;
newOption('popupDebugging', false);
}
newOption('popupActiveNavlinks', true);
if (typeof this.left != 'undefined' && typeof this.top != 'undefined') {
newOption('popupModifier', false);
this.mainDiv.style.left = this.left + 'px';
newOption('popupModifierAction', 'enable');
this.mainDiv.style.top = this.top + 'px';
newOption('popupDraggable', true);
}
newOption('popupReview', false);
if (!noLimitHor) {
newOption('popupLocale', false);
this.limitHorizontalPosition();
newOption('popupDateTimeFormatterOptions', {
}
year: 'numeric',
//console.log('navpop'+this.uid+' - (left,top)=(' + this.left + ',' + this.top + '), css=('
month: 'long',
//+ this.mainDiv.style.left + ',' + this.mainDiv.style.top + ')');
day: 'numeric',
};
hour12: false,

hour: '2-digit',
/**
minute: '2-digit',
* Prevents popups from being in silly locations. Hopefully.
second: '2-digit',
* Should not be run if {@link #constrained} is true.
});
* @private
newOption('popupDateFormatterOptions', {
*/
year: 'numeric',
Navpopup.prototype.limitHorizontalPosition = function () {
month: 'long',
if (!this.constrained || this.tooWide) {
day: 'numeric',
return;
});
}
newOption('popupTimeFormatterOptions', {
this.updateDimensions();
hour12: false,
var x = this.left;
hour: '2-digit',
var w = this.width;
minute: '2-digit',
var cWidth = document.body.clientWidth;
second: '2-digit',

});
// log('limitHorizontalPosition: x='+x+
newOption('popupImages', true);
// ', this.left=' + this.left +
newOption('imagePopupsForImages', true);
// ', this.width=' + this.width +
newOption('popupNeverGetThumbs', false);
// ', cWidth=' + cWidth);
newOption('popupThumbAction', 'imagepage');

newOption('popupImageSize', 60);
if (
newOption('popupImageSizeLarge', 200);
x + w >= cWidth ||
newOption('popupFixRedirs', false);
(x > 0 &&
newOption('popupRedirAutoClick', 'wpDiff');
this.maxWidth &&
newOption('popupFixDabs', false);
this.width < this.maxWidth &&
newOption('popupDabsAutoClick', 'wpDiff');
this.height > this.width &&
newOption('popupRevertSummaryPrompt', false);
x > cWidth - this.maxWidth)
newOption('popupMinorReverts', false);
) {
newOption('popupRedlinkRemoval', false);
// This is a very nasty hack. There has to be a better way!
newOption('popupRedlinkAutoClick', 'wpDiff');
// We find the "natural" width of the div by positioning it at the far left
newOption('popupWatchDisambiggedPages', null);
// then reset it so that it should be flush right (well, nearly)
newOption('popupWatchRedirredPages', null);
this.mainDiv.style.left = '-10000px';
newOption('popupDabWiktionary', 'last');
this.mainDiv.style.width = this.maxWidth + 'px';
newOption('popupNavLinks', true);
var naturalWidth = parseInt(this.mainDiv.offsetWidth, 10);
newOption('popupNavLinkSeparator', ' &sdot; ');
var newLeft = cWidth - naturalWidth - 1;
newOption('popupLastEditLink', true);
if (newLeft < 0) {
newOption('popupEditCounterTool', 'supercount');
newLeft = 0;
newOption('popupEditCounterUrl', '');
this.tooWide = true;
newOption('popupPreviews', true);
} // still unstable for really wide popups?
newOption('popupSummaryData', true);
log(
newOption('popupMaxPreviewSentences', 5);
'limitHorizontalPosition: moving to (' +
newOption('popupMaxPreviewCharacters', 600);
newLeft +
newOption('popupLastModified', true);
',' +
newOption('popupPreviewKillTemplates', true);
this.top +
newOption('popupPreviewRawTemplates', true);
');' +
newOption('popupPreviewFirstParOnly', true);
' naturalWidth=' +
newOption('popupPreviewCutHeadings', true);
naturalWidth +
newOption('popupPreviewButton', false);
', clientWidth=' +
newOption('popupPreviewButtonEvent', 'click');
cWidth
newOption('popupPreviewDiffs', true);
);
newOption('popupDiffMaxLines', 100);
this.reposition(newLeft, null, true);
newOption('popupDiffContextLines', 2);
}
newOption('popupDiffContextCharacters', 40);
};
newOption('popupDiffDates', true);

newOption('popupDiffDatePrinter', 'toLocaleString');
/**
newOption('popupReviewedSummary', popupString('defaultpopupReviewedSummary'));
* Counter indicating the z-order of the "highest" popup.
newOption('popupFixDabsSummary', popupString('defaultpopupFixDabsSummary'));
* We start the z-index at 1000 so that popups are above everything
newOption('popupExtendedRevertSummary', popupString('defaultpopupExtendedRevertSummary'));
* else on the screen.
newOption('popupRevertSummary', popupString('defaultpopupRevertSummary'));
* @private
newOption('popupRevertToPreviousSummary', popupString('defaultpopupRevertToPreviousSummary'));
* @type {number}
newOption('popupQueriedRevertSummary', popupString('defaultpopupQueriedRevertSummary'));
*/
newOption('popupQueriedRevertToPreviousSummary', popupString('defaultpopupQueriedRevertToPreviousSummary'));
Navpopup.highest = 1000;
newOption('popupFixRedirsSummary', popupString('defaultpopupFixRedirsSummary'));

newOption('popupRedlinkSummary', popupString('defaultpopupRedlinkSummary'));
/**
newOption('popupRmDabLinkSummary', popupString('defaultpopupRmDabLinkSummary'));
* Brings popup to the top of the z-order.
newOption('popupHistoryLimit', 50);
* We increment the {@link #highest} property of the contructor here.
newOption('popupFilters', [popupFilterStubDetect, popupFilterDisambigDetect, popupFilterPageSize, popupFilterCountLinks, popupFilterCountImages, popupFilterCountCategories, popupFilterLastModified, popupFilterWikibaseItem, ]);
* @private
newOption('extraPopupFilters', []);
*/
newOption('popupOnEditSelection', 'cursor');
Navpopup.prototype.raise = function () {
newOption('popupPreviewHistory', true);
this.mainDiv.style.zIndex = Navpopup.highest + 1;
newOption('popupImageLinks', true);
++Navpopup.highest;
newOption('popupCategoryMembers', true);
};
newOption('popupUserInfo', true);

newOption('popupHistoryPreviewLimit', 25);
/**
newOption('popupContribsPreviewLimit', 25);
* Shows the popup provided {@link #noshow} is not true.
newOption('popupRevDelUrl', '//en.wikipedia.org/wiki/Wikipedia:Revision_deletion');
* Updates the position, brings the popup to the top of the z-order and unhides it.
newOption('popupShowGender', true);
*/
newOption('popupNewWindows', false);
Navpopup.prototype.show = function () {
newOption('popupLinksNewWindow', {
//document.title+='s';
lastContrib: true,
if (this.noshow) {
sinceMe: true
return;
});
}
newOption('popupDabRegexp', 'disambiguation\\}\\}|\\{\\{\\s*(d(ab|isamb(ig(uation)?)?)|(((geo|hn|road?|school|number)dis)|[234][lc][acw]|(road|ship)index))\\s*(\\|[^}]*)?\\}\\}|is a .*disambiguation.*page');
//document.title+='t';
newOption('popupAnchorRegexp', 'anchors?');
this.reposition();
newOption('popupStubRegexp', '(sect)?stub[}][}]|This .*-related article is a .*stub');
this.raise();
newOption('popupImageVarsRegexp', 'image|image_(?:file|skyline|name|flag|seal)|cover|badge|logo');
this.unhide();
}
};
pg.string = {

article: 'article',
/**
category: 'category',
* Checks to see if the mouse pointer has
categories: 'categories',
* stabilised (checking every <code>time</code>/2 milliseconds) and runs the
image: 'image',
* {@link #show} method if it has.
images: 'images',
* @param {number} time The minimum time (ms) before the popup may be shown.
stub: 'stub',
*/
'section stub': 'section stub',
Navpopup.prototype.showSoonIfStable = function (time) {
'Empty page': 'Empty page',
log('showSoonIfStable, time=' + time);
kB: 'kB',
if (this.visible) {
bytes: 'bytes',
return;
day: 'day',
}
days: 'days',
this.noshow = false;
hour: 'hour',

hours: 'hours',
//~ initialize these variables so that we never run @tt{show} after
minute: 'minute',
//~ just half the time
minutes: 'minutes',
this.stable_x = -10000;
second: 'second',
this.stable_y = -10000;
seconds: 'seconds',

week: 'week',
var stableShow = function () {
weeks: 'weeks',
log('stableShow called');
search: 'search',
var new_x = Navpopup.tracker.x,
SearchHint: 'Find English Wikipedia articles containing %s',
new_y = Navpopup.tracker.y;
web: 'web',
var dx = savedThis.stable_x - new_x,
global: 'global',
dy = savedThis.stable_y - new_y;
globalSearchHint: 'Search across Wikipedias in different languages for %s',
var fuzz2 = 0; // savedThis.fuzz * savedThis.fuzz;
googleSearchHint: 'Google for %s',
//document.title += '[' + [savedThis.stable_x,new_x, savedThis.stable_y,new_y, dx, dy, fuzz2].join(',') + '] ';
actions: 'actions',
if (dx * dx <= fuzz2 && dy * dy <= fuzz2) {
popupsMenu: 'popups',
log('mouse is stable');
togglePreviewsHint: 'Toggle preview generation in popups on this page',
clearInterval(savedThis.showSoonStableTimer);
'enable previews': 'enable previews',
savedThis.reposition.apply(savedThis, [new_x + 2, new_y + 2]);
'disable previews': 'disable previews',
savedThis.show.apply(savedThis, []);
'toggle previews': 'toggle previews',
savedThis.limitHorizontalPosition.apply(savedThis, []);
'show preview': 'show preview',
return;
reset: 'reset',
}
'more...': 'more...',
savedThis.stable_x = new_x;
disable: 'disable popups',
savedThis.stable_y = new_y;
disablePopupsHint: 'Disable popups on this page. Reload page to re-enable.',
};
historyfeedHint: 'RSS feed of recent changes to this page',
var savedThis = this;
purgePopupsHint: 'Reset popups, clearing all cached popup data.',
this.showSoonStableTimer = setInterval(stableShow, time / 2);
PopupsHint: 'Reset popups, clearing all cached popup data.',
};
spacebar: 'space',

view: 'view',
/**
'view article': 'view article',
* Sets the {@link #noshow} flag and hides the popup. This should be called
viewHint: 'Go to %s',
* when the mouse leaves the link before
talk: 'talk',
* (or after) it's actually been displayed.
'talk page': 'talk page',
*/
'this&nbsp;revision': 'this&nbsp;revision',
Navpopup.prototype.banish = function () {
'revision %s of %s': 'revision %s of %s',
log('banish called');
'Revision %s of %s': 'Revision %s of %s',
// hide and prevent showing with showSoon in the future
'the revision prior to revision %s of %s': 'the revision prior to revision %s of %s',
this.noshow = true;
'Toggle image size': 'Click to toggle image size',
if (this.showSoonStableTimer) {
del: 'del',
log('clearing showSoonStableTimer');
delete: 'delete',
clearInterval(this.showSoonStableTimer);
deleteHint: 'Delete %s',
}
undeleteShort: 'un',
this.hide();
UndeleteHint: 'Show the deletion history for %s',
};
protect: 'protect',

protectHint: 'Restrict editing rights to %s',
/**
unprotectShort: 'un',
* Runs hooks added with {@link #addHook}.
unprotectHint: 'Allow %s to be edited by anyone again',
* @private
'send thanks': 'send thanks',
* @param {String} key Key name of the {@link #hooks} array - one of 'create', 'unhide', 'hide'
ThanksHint: 'Send a thank you notification to this user',
* @param {String} when Controls exactly when the hook is run: either 'before' or 'after'
move: 'move',
*/
'move page': 'move page',
Navpopup.prototype.runHooks = function (key, when) {
MovepageHint: 'Change the title of %s',
if (!this.hooks[key]) {
edit: 'edit',
return;
'edit article': 'edit article',
}
editHint: 'Change the content of %s',
var keyHooks = this.hooks[key];
'edit talk': 'edit talk',
var len = keyHooks.length;
new: 'new',
for (var i = 0; i < len; ++i) {
'new topic': 'new topic',
if (keyHooks[i] && keyHooks[i].when == when) {
newSectionHint: 'Start a new section on %s',
if (keyHooks[i].hook.apply(this, [])) {
'null edit': 'null edit',
// remove the hook
nullEditHint: 'Submit an edit to %s, making no changes ',
if (keyHooks[i].hookId) {
hist: 'hist',
delete this.hookIds[keyHooks[i].hookId];
history: 'history',
}
historyHint: 'List the changes made to %s',
keyHooks[i] = null;
last: 'prev',
}
lastEdit: 'lastEdit',
}
'mark patrolled': 'mark patrolled',
}
markpatrolledHint: 'Mark this edit as patrolled',
};
'Could not marked this edit as patrolled': 'Could not marked this edit as patrolled',

'show last edit': 'most recent edit',
/**
'Show the last edit': 'Show the effects of the most recent change',
* Adds a hook to the popup. Hook functions are run with <code>this</code> set to refer to the
lastContrib: 'lastContrib',
* Navpopup instance, and no arguments.
'last set of edits': 'latest edits',
* @param {Function} hook The hook function. Functions that return true are deleted.
lastContribHint: 'Show the net effect of changes made by the last editor',
* @param {String} key Key name of the {@link #hooks} array - one of 'create', 'unhide', 'hide'
cur: 'cur',
* @param {String} when Controls exactly when the hook is run: either 'before' or 'after'
diffCur: 'diffCur',
* @param {String} uid A truthy string identifying the hook function; if it matches another hook
'Show changes since revision %s': 'Show changes since revision %s',
* in this position, it won't be added again.
'%s old': '%s old',
*/
oldEdit: 'oldEdit',
Navpopup.prototype.addHook = function (hook, key, when, uid) {
purge: 'purge',
when = when || 'after';
purgeHint: 'Demand a fresh copy of %s',
if (!this.hooks[key]) {
raw: 'source',
return;
rawHint: 'Download the source of %s',
}
render: 'simple',
// if uid is specified, don't add duplicates
renderHint: 'Show a plain HTML version of %s',
var hookId = null;
'Show the edit made to get revision': 'Show the edit made to get revision',
if (uid) {
sinceMe: 'sinceMe',
hookId = [key, when, uid].join('|');
'changes since mine': 'diff my edit',
if (this.hookIds[hookId]) {
sinceMeHint: 'Show changes since my last edit',
return;
"Couldn't find an edit by %s\nin the last %s edits to\n%s": "Couldn't find an edit by %s\nin the last %s edits to\n%s",
}
eds: 'eds',
this.hookIds[hookId] = true;
editors: 'editors',
}
editorListHint: 'List the users who have edited %s',
this.hooks[key].push({ hook: hook, when: when, hookId: hookId });
related: 'related',
};
relatedChanges: 'relatedChanges',

'related changes': 'related changes',
/**
RecentchangeslinkedHint: 'Show changes in articles related to %s',
* Creates the main DIV element, which contains all the actual popup content.
editOld: 'editOld',
* Runs hooks with key 'create'.
rv: 'rv',
* @private
revert: 'revert',
*/
revertHint: 'Revert to %s',
Navpopup.prototype.createMainDiv = function () {
defaultpopupReviewedSummary: 'Accepted by reviewing the [[Special:diff/%s/%s|difference]] between this version and previously accepted version using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
if (this.mainDiv) {
defaultpopupRedlinkSummary: 'Removing link to empty page [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
return;
defaultpopupFixDabsSummary: 'Disambiguate [[%s]] to [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
}
defaultpopupFixRedirsSummary: 'Redirect bypass from [[%s]] to [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
this.runHooks('create', 'before');
defaultpopupExtendedRevertSummary: 'Revert to revision dated %s by %s, oldid %s using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
var mainDiv = document.createElement('div');
defaultpopupRevertToPreviousSummary: 'Revert to the revision prior to revision %s using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',

defaultpopupRevertSummary: 'Revert to revision %s using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
var savedThis = this;
defaultpopupQueriedRevertToPreviousSummary: 'Revert to the revision prior to revision $1 dated $2 by $3 using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
mainDiv.onclick = function (e) {
defaultpopupQueriedRevertSummary: 'Revert to revision $1 dated $2 by $3 using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
savedThis.onclickHandler(e);
defaultpopupRmDabLinkSummary: 'Remove link to dab page [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
};
Redirects: 'Redirects',
mainDiv.className = this.className ? this.className : 'navpopup_maindiv';
' to ': ' to ',
mainDiv.id = mainDiv.className + this.uid;
'Bypass redirect': 'Bypass redirect',

'Fix this redirect': 'Fix this redirect',
mainDiv.style.position = 'absolute';
disambig: 'disambig',
mainDiv.style.minWidth = '350px';
disambigHint: 'Disambiguate this link to [[%s]]',
mainDiv.style.display = 'none';
'Click to disambiguate this link to:': 'Click to disambiguate this link to:',
mainDiv.className = 'navpopup';
'remove this link': 'remove this link',

'remove all links to this page from this article': 'remove all links to this page from this article',
// easy access to javascript object through DOM functions
'remove all links to this disambig page from this article': 'remove all links to this disambig page from this article',
mainDiv.navpopup = this;
mainlink: 'mainlink',

wikiLink: 'wikiLink',
this.mainDiv = mainDiv;
wikiLinks: 'wikiLinks',
document.body.appendChild(mainDiv);
'links here': 'links here',
this.runHooks('create', 'after');
whatLinksHere: 'whatLinksHere',
};
'what links here': 'what links here',

WhatlinkshereHint: 'List the pages that are hyperlinked to %s',
/**
unwatchShort: 'un',
* Calls the {@link #raise} method.
watchThingy: 'watch',
* @private
watchHint: 'Add %s to my watchlist',
*/
unwatchHint: 'Remove %s from my watchlist',
Navpopup.prototype.onclickHandler = function (/*e*/) {
'Only found one editor: %s made %s edits': 'Only found one editor: %s made %s edits',
this.raise();
'%s seems to be the last editor to the page %s': '%s seems to be the last editor to the page %s',
};
rss: 'rss',

'Diff truncated for performance reasons': 'Diff truncated for performance reasons',
/**
'Old revision': 'Old revision',
* Makes the popup draggable, using a {@link Drag} object.
'New revision': 'New revision',
* @private
'Something went wrong :-(': 'Something went wrong :-(',
*/
'Empty revision, maybe non-existent': 'Empty revision, maybe non-existent',
Navpopup.prototype.makeDraggable = function (handleName) {
'Unknown date': 'Unknown date',
if (!this.mainDiv) {
'Empty category': 'Empty category',
this.createMainDiv();
'Category members (%s shown)': 'Category members (%s shown)',
}
'No image links found': 'No image links found',
var drag = new Drag();
'File links': 'File links',
if (!handleName) {
'No image found': 'No image found',
drag.startCondition = function (e) {
'Image from Commons': 'Image from Commons',
try {
'Description page': 'Description page',
if (!e.shiftKey) {
'Alt text:': 'Alt text:',
return false;
revdel: 'Hidden revision',
}
user: 'user',
} catch (err) {
'user&nbsp;page': 'user&nbsp;page',
return false;
'user talk': 'user talk',
}
'edit user talk': 'edit user talk',
return true;
'leave comment': 'leave comment',
};
email: 'email',
}
'email user': 'email user',
var dragHandle;
EmailuserHint: 'Send an email to %s',
if (handleName) {
space: 'space',
dragHandle = document.getElementById(handleName);
PrefixIndexHint: 'Show pages in the userspace of %s',
}
count: 'count',
if (!dragHandle) {
'edit counter': 'edit counter',
dragHandle = this.mainDiv;
editCounterLinkHint: 'Count the contributions made by %s',
}
contribs: 'contribs',
var np = this;
contributions: 'contributions',
drag.endHook = function (x, y) {
deletedContribs: 'deleted contributions',
Navpopup.tracker.dirty = true;
DeletedcontributionsHint: 'List deleted edits made by %s',
np.reposition(x, y);
ContributionsHint: 'List the contributions made by %s',
};
log: 'log',
drag.init(dragHandle, this.mainDiv);
'user log': 'user log',
};
userLogHint: "Show %s's user log",

arin: 'ARIN lookup',
/**
'Look up %s in ARIN whois database': 'Look up %s in the ARIN whois database',
* Hides the popup using CSS. Runs hooks with key 'hide'.
unblockShort: 'un',
* Sets {@link #visible} appropriately.
block: 'block',
* {@link #banish} should be called externally instead of this method.
'block user': 'block user',
* @private
IpblocklistHint: 'Unblock %s',
*/
BlockipHint: 'Prevent %s from editing',
Navpopup.prototype.hide = function () {
'block log': 'block log',
this.runHooks('hide', 'before');
blockLogHint: 'Show the block log for %s',
this.abortDownloads();
protectLogHint: 'Show the protection log for %s',
if (typeof this.visible != 'undefined' && this.visible) {
pageLogHint: 'Show the page log for %s',
this.mainDiv.style.display = 'none';
deleteLogHint: 'Show the deletion log for %s',
this.visible = false;
'Invalid %s %s': 'The option %s is invalid: %s',
}
'No backlinks found': 'No backlinks found',
this.runHooks('hide', 'after');
' and more': ' and more',
};
undo: 'undo',

undoHint: 'undo this edit',
/**
'Download preview data': 'Download preview data',
* Shows the popup using CSS. Runs hooks with key 'unhide'.
'Invalid or IP user': 'Invalid or IP user',
* Sets {@link #visible} appropriately. {@link #show} should be called externally instead of this method.
'Not a registered username': 'Not a registered username',
* @private
BLOCKED: 'BLOCKED',
*/
'Has blocks': 'Has blocks',
Navpopup.prototype.unhide = function () {
' edits since: ': ' edits since: ',
this.runHooks('unhide', 'before');
'last edit on ': 'last edit on ',
if (typeof this.visible != 'undefined' && !this.visible) {
'he/him': 'he/him',
this.mainDiv.style.display = 'inline';
'she/her': 'she/her',
this.visible = true;
'Enter a non-empty edit summary or press cancel to abort': 'Enter a non-empty edit summary or press cancel to abort',
}
'Failed to get revision information, please edit manually.\n\n': 'Failed to get revision information, please edit manually.\n\n',
this.runHooks('unhide', 'after');
'The %s button has been automatically clicked. Please wait for the next page to load.': 'The %s button has been automatically clicked. Please wait for the next page to load.',
};
'Could not find button %s. Please check the settings in your javascript file.': 'Could not find button %s. Please check the settings in your javascript file.',

'Open full-size image': 'Open full-size image',
/**
zxy: 'zxy',
* Sets the <code>innerHTML</code> attribute of the main div containing the popup content.
autoedit_version: 'np20140416',
* @param {String} html The HTML to set.
};
*/
function popupString(str) {
Navpopup.prototype.setInnerHTML = function (html) {
if (typeof popupStrings != 'undefined' && popupStrings && popupStrings[str]) {
this.mainDiv.innerHTML = html;
return popupStrings[str];
};
}

if (pg.string[str]) {
/**
return pg.string[str];
* Updates the {@link #width} and {@link #height} attributes with the CSS properties.
}
* @private
return str;
*/
}
Navpopup.prototype.updateDimensions = function () {
function tprintf(str, subs) {
this.width = parseInt(this.mainDiv.offsetWidth, 10);
if (typeof subs != typeof []) {
this.height = parseInt(this.mainDiv.offsetHeight, 10);
subs = [subs];
};
}

return simplePrintf(popupString(str), subs);
/**
}
* Checks if the point (x,y) is within {@link #fuzz} of the
if (document.readyState == 'complete') {
* {@link #mainDiv}.
autoEdit();
* @param {number} x x-coordinate (px)
} else {
* @param {number} y y-coordinate (px)
$(window).on('load', autoEdit);
* @type {boolean}
}
*/
(function() {
Navpopup.prototype.isWithin = function (x, y) {
var once = true;
//~ If we're not even visible, no point should be considered as
function dynamicContentHandler($content) {
//~ being within the popup.
if ($content.attr('id') == 'mw-content-text') {
if (!this.visible) {
if (once) {
return false;
once = false;
}
return;
this.updateDimensions();
}
var fuzz = this.fuzz || 0;
}
//~ Use a simple box metric here.
function registerHooksForVisibleNavpops() {
return (
for (var i = 0; pg.current.links && i < pg.current.links.length; ++i) {
x + fuzz >= this.left &&
var navpop = pg.current.links[i].navpopup;
x - fuzz <= this.left + this.width &&
if (!navpop || !navpop.isVisible()) {
y + fuzz >= this.top &&
continue;
y - fuzz <= this.top + this.height
}
);
Navpopup.tracker.addHook(posCheckerHook(navpop));
};
}

}
/**
function doIt() {
* Adds a download to {@link #downloads}.
registerHooksForVisibleNavpops();
* @param {Downloader} download
$content.each(function() {
*/
this.ranSetupTooltipsAlready = false;
Navpopup.prototype.addDownload = function (download) {
setupTooltips(this);
if (!download) {
});
return;
}
}
setupPopups(doIt);
this.downloads.push(download);
}
};
mw.hook('wikipage.content').add(dynamicContentHandler);

mw.hook('ext.echo.overlay.beforeShowingOverlay').add(function($overlay) {
/**
dynamicContentHandler($overlay.find('.mw-echo-state'));
* Aborts the downloads listed in {@link #downloads}.
});
* @see Downloader#abort
}
*/
)();
Navpopup.prototype.abortDownloads = function () {
});
for (var i = 0; i < this.downloads.length; ++i) {
}
var d = this.downloads[i];
, {
if (d && d.abort) {
"css": [".popupMoreLink{display:block;text-align:right;cursor:pointer}ins.popupDiff{background:#afe}del.popupDiff{background:#ffe6e6}#selectionPreview{border:2px solid #ddd;background-color:#eef;padding:6px}.navpopup{border:1px solid #bbb;background-color:#fff;padding:10px;padding-bottom:5px;font-size:11px;box-shadow:0 3px 8px rgba(50,50,50,0.35);word-wrap:break-word}.navpopup hr{color:#aaa !important;background-color:#aaa !important} .popupDrag{background-color:#ffbe20;height:5px;margin-top:-5px;margin-bottom:5px}.popupDragHandle{cursor:move;position:relative} .popup_menu{display:none;position:absolute;left:0;margin:0;margin-top:1.4em;line-height:1.25em;top:0;z-index:2;width:10em;background:white;border:1px solid grey;padding:0 !important;margin-left:-6px;border-width:1px 1px 1px 6px}.popup_menu li{ list-style:none;margin:0;padding:0}.popup_menu a{display:block;padding:3px;color:#555}.popup_menu_row a{display:inline-block}.popup_menu_row{color:#aaa}.popup_drop{display:inline;position:relative}.popup_drop a,.popup_drop a:visited{padding:3px;margin:0;font-weight:bold;color:#0645ad}.popup_drop:hover .popup_menu,.popup_drop .popup_menu:hover{display:inline;background:white;padding:2px;color:#555}.popup_drop:hover{background:#ccf;color:#44f} .popup_menu a:hover{background:grey;color:#fff;text-decoration:none}.popup_mainlink{font-size:140%;font-weight:bold}.popup_mainlink a{color:#000}a.popup_change_title_link{color:#152}.popup_diff_dates{font-style:italic;background:none}.popup_menu_item a{display:block}.popup_history_row_even{background:#eee}.popup_history_date{font-weight:bold;font-size:120%}.popup_history_row_odd,.popup_history_row_even{display:flex}.popup_history_row_even td:nth-child(3),.popup_history_row_odd td:nth-child(3){flex:3;word-break:break-word}.popup_history_row_even td:nth-child(4),.popup_history_row_odd td:nth-child(4){flex:7;word-break:break-word}.popup_history_row_even \u003E td:not(:last-child),.popup_history_row_odd \u003E td:not(:last-child){margin-right:2px} .popupPreview a.extiw,.popupPreview a.extiw:active{color:#36b;background:none;padding:0}.popupPreview .external{color:#36b} .popupPreview .plainlinks a{background:none !important;padding:0 !important} .popup_menu:hover{box-shadow:0 0 5px 5px rgba(179,179,255,0.3) } .popup_menu::before{content:'';display:block;position:absolute;height:1.5em;top:-1.4em;left:-1.2em;width:calc(2 * var(--navpop-m-len,6ch));transform:perspective(1px) rotateX(1deg)} .popup_menu::before{z-index:1}.popup_menu li{position:relative;z-index:2} .popup_menu li::before{content:'';display:block;position:absolute;top:0;height:calc(100% + .5em);left:-1.7em;width:1.7em}.popup_menu li::after{content:'';display:block;position:absolute;top:0;height:calc(100% + .5em);left:calc(10em - 1px); width:1em}"]
d.abort();
}];
}
}
this.downloads = [];
};

/**
* A {@link Mousetracker} instance which is a property of the constructor (pseudo-global).
*/
Navpopup.tracker = new Mousetracker();
// ENDFILE: navpopup.js

// STARTFILE: diff.js
/*
* Javascript Diff Algorithm
* By John Resig (http://ejohn.org/) and [[:en:User:Lupin]]
*
* More Info:
* http://ejohn.org/projects/javascript-diff-algorithm/
*/

function delFmt(x) {
if (!x.length) {
return '';
}
return "<del class='popupDiff'>" + x.join('') + '</del>';
}

function insFmt(x) {
if (!x.length) {
return '';
}
return "<ins class='popupDiff'>" + x.join('') + '</ins>';
}

function countCrossings(a, b, i, eject) {
// count the crossings on the edge starting at b[i]
if (!b[i].row && b[i].row !== 0) {
return -1;
}
var count = 0;
for (var j = 0; j < a.length; ++j) {
if (!a[j].row && a[j].row !== 0) {
continue;
}
if ((j - b[i].row) * (i - a[j].row) > 0) {
if (eject) {
return true;
}
count++;
}
}
return count;
}

function shortenDiffString(str, context) {
var re = RegExp('(<del[\\s\\S]*?</del>|<ins[\\s\\S]*?</ins>)');
var splitted = str.parenSplit(re);
var ret = [''];
for (var i = 0; i < splitted.length; i += 2) {
if (splitted[i].length < 2 * context) {
ret[ret.length - 1] += splitted[i];
if (i + 1 < splitted.length) {
ret[ret.length - 1] += splitted[i + 1];
}
continue;
} else {
if (i > 0) {
ret[ret.length - 1] += splitted[i].substring(0, context);
}
if (i + 1 < splitted.length) {
ret.push(splitted[i].substring(splitted[i].length - context) + splitted[i + 1]);
}
}
}
while (ret.length > 0 && !ret[0]) {
ret = ret.slice(1);
}
return ret;
}

function diffString(o, n, simpleSplit) {
var splitRe = RegExp('([[]{2}|[\\]]{2}|[{]{2,3}|[}]{2,3}|[|]|=|<|>|[*:]+|\\s|\\b)');

// We need to split the strings o and n first, and entify() the parts
// individually, so that the HTML entities are never cut apart. (AxelBoldt)
var out, i, oSplitted, nSplitted;
if (simpleSplit) {
oSplitted = o.split(/\b/);
nSplitted = n.split(/\b/);
} else {
oSplitted = o.parenSplit(splitRe);
nSplitted = n.parenSplit(splitRe);
}
for (i = 0; i < oSplitted.length; ++i) {
oSplitted[i] = oSplitted[i].entify();
}
for (i = 0; i < nSplitted.length; ++i) {
nSplitted[i] = nSplitted[i].entify();
}

out = diff(oSplitted, nSplitted);
var str = '';
var acc = []; // accumulator for prettier output

// crossing pairings -- eg 'A B' vs 'B A' -- cause problems, so let's iron them out
// this doesn't always do things optimally but it should be fast enough
var maxOutputPair = 0;
for (i = 0; i < out.n.length; ++i) {
if (out.n[i].paired) {
if (maxOutputPair > out.n[i].row) {
// tangle - delete pairing
out.o[out.n[i].row] = out.o[out.n[i].row].text;
out.n[i] = out.n[i].text;
}
if (maxOutputPair < out.n[i].row) {
maxOutputPair = out.n[i].row;
}
}
}

// output the stuff preceding the first paired old line
for (i = 0; i < out.o.length && !out.o[i].paired; ++i) {
acc.push(out.o[i]);
}
str += delFmt(acc);
acc = [];

// main loop
for (i = 0; i < out.n.length; ++i) {
// output unpaired new "lines"
while (i < out.n.length && !out.n[i].paired) {
acc.push(out.n[i++]);
}
str += insFmt(acc);
acc = [];
if (i < out.n.length) {
// this new "line" is paired with the (out.n[i].row)th old "line"
str += out.n[i].text;
// output unpaired old rows starting after this new line's partner
var m = out.n[i].row + 1;
while (m < out.o.length && !out.o[m].paired) {
acc.push(out.o[m++]);
}
str += delFmt(acc);
acc = [];
}
}
return str;
}

// see http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object
// FIXME: use obj.hasOwnProperty instead of this kludge!
var jsReservedProperties = RegExp(
'^(constructor|prototype|__((define|lookup)[GS]etter)__' +
'|eval|hasOwnProperty|propertyIsEnumerable' +
'|to(Source|String|LocaleString)|(un)?watch|valueOf)$'
);

function diffBugAlert(word) {
if (!diffBugAlert.list[word]) {
diffBugAlert.list[word] = 1;
alert('Bad word: ' + word + '\n\nPlease report this bug.');
}
}

diffBugAlert.list = {};

function makeDiffHashtable(src) {
var ret = {};
for (var i = 0; i < src.length; i++) {
if (jsReservedProperties.test(src[i])) {
src[i] += '<!-- -->';
}
if (!ret[src[i]]) {
ret[src[i]] = [];
}
try {
ret[src[i]].push(i);
} catch (err) {
diffBugAlert(src[i]);
}
}
return ret;
}

function diff(o, n) {
// pass 1: make hashtable ns with new rows as keys
var ns = makeDiffHashtable(n);

// pass 2: make hashtable os with old rows as keys
var os = makeDiffHashtable(o);

// pass 3: pair unique new rows and matching unique old rows
var i;
for (i in ns) {
if (ns[i].length == 1 && os[i] && os[i].length == 1) {
n[ns[i][0]] = { text: n[ns[i][0]], row: os[i][0], paired: true };
o[os[i][0]] = { text: o[os[i][0]], row: ns[i][0], paired: true };
}
}

// pass 4: pair matching rows immediately following paired rows (not necessarily unique)
for (i = 0; i < n.length - 1; i++) {
if (
n[i].paired &&
!n[i + 1].paired &&
n[i].row + 1 < o.length &&
!o[n[i].row + 1].paired &&
n[i + 1] == o[n[i].row + 1]
) {
n[i + 1] = { text: n[i + 1], row: n[i].row + 1, paired: true };
o[n[i].row + 1] = { text: o[n[i].row + 1], row: i + 1, paired: true };
}
}

// pass 5: pair matching rows immediately preceding paired rows (not necessarily unique)
for (i = n.length - 1; i > 0; i--) {
if (
n[i].paired &&
!n[i - 1].paired &&
n[i].row > 0 &&
!o[n[i].row - 1].paired &&
n[i - 1] == o[n[i].row - 1]
) {
n[i - 1] = { text: n[i - 1], row: n[i].row - 1, paired: true };
o[n[i].row - 1] = { text: o[n[i].row - 1], row: i - 1, paired: true };
}
}

return { o: o, n: n };
}
// ENDFILE: diff.js

// STARTFILE: init.js
function setSiteInfo() {
if (window.popupLocalDebug) {
pg.wiki.hostname = 'en.wikipedia.org';
} else {
pg.wiki.hostname = location.hostname; // use in preference to location.hostname for flexibility (?)
}
pg.wiki.wikimedia = RegExp(
'(wiki([pm]edia|source|books|news|quote|versity|species|voyage|data)|metawiki|wiktionary|mediawiki)[.]org'
).test(pg.wiki.hostname);
pg.wiki.wikia = RegExp('[.]wikia[.]com$', 'i').test(pg.wiki.hostname);
pg.wiki.isLocal = RegExp('^localhost').test(pg.wiki.hostname);
pg.wiki.commons =
pg.wiki.wikimedia && pg.wiki.hostname != 'commons.wikimedia.org'
? 'commons.wikimedia.org'
: null;
pg.wiki.lang = mw.config.get('wgContentLanguage');
var port = location.port ? ':' + location.port : '';
pg.wiki.sitebase = pg.wiki.hostname + port;
}

function setUserInfo() {
var params = {
action: 'query',
list: 'users',
ususers: mw.config.get('wgUserName'),
usprop: 'rights',
};

pg.user.canReview = false;
if (getValueOf('popupReview')) {
getMwApi()
.get(params)
.done(function (data) {
var rights = data.query.users[0].rights;
pg.user.canReview = rights.indexOf('review') !== -1; // TODO: Should it be a getValueOf('ReviewRight') ?
});
}
}

function fetchSpecialPageNames() {
var params = {
action: 'query',
meta: 'siteinfo',
siprop: 'specialpagealiases',
formatversion: 2,
// cache for an hour
uselang: 'content',
maxage: 3600,
};
return getMwApi()
.get(params)
.then(function (data) {
pg.wiki.specialpagealiases = data.query.specialpagealiases;
});
}

function setTitleBase() {
var protocol = window.popupLocalDebug ? 'http:' : location.protocol;
pg.wiki.articlePath = mw.config.get('wgArticlePath').replace(/\/\$1/, ''); // as in http://some.thing.com/wiki/Article
pg.wiki.botInterfacePath = mw.config.get('wgScript');
pg.wiki.APIPath = mw.config.get('wgScriptPath') + '/api.php';
// default mediawiki setting is paths like http://some.thing.com/articlePath/index.php?title=foo

var titletail = pg.wiki.botInterfacePath + '?title=';
//var titletail2 = joinPath([pg.wiki.botInterfacePath, 'wiki.phtml?title=']);

// other sites may need to add code here to set titletail depending on how their urls work

pg.wiki.titlebase = protocol + '//' + pg.wiki.sitebase + titletail;
//pg.wiki.titlebase2 = protocol + '//' + joinPath([pg.wiki.sitebase, titletail2]);
pg.wiki.wikibase = protocol + '//' + pg.wiki.sitebase + pg.wiki.botInterfacePath;
pg.wiki.apiwikibase = protocol + '//' + pg.wiki.sitebase + pg.wiki.APIPath;
pg.wiki.articlebase = protocol + '//' + pg.wiki.sitebase + pg.wiki.articlePath;
pg.wiki.commonsbase = protocol + '//' + pg.wiki.commons + pg.wiki.botInterfacePath;
pg.wiki.apicommonsbase = protocol + '//' + pg.wiki.commons + pg.wiki.APIPath;
pg.re.basenames = RegExp(
'^(' +
map(literalizeRegex, [
pg.wiki.titlebase, //pg.wiki.titlebase2,
pg.wiki.articlebase,
]).join('|') +
')'
);
}

//////////////////////////////////////////////////
// Global regexps

function setMainRegex() {
var reStart = '[^:]*://';
var preTitles =
literalizeRegex(mw.config.get('wgScriptPath')) + '/(?:index[.]php|wiki[.]phtml)[?]title=';
preTitles += '|' + literalizeRegex(pg.wiki.articlePath + '/');

var reEnd = '(' + preTitles + ')([^&?#]*)[^#]*(?:#(.+))?';
pg.re.main = RegExp(reStart + literalizeRegex(pg.wiki.sitebase) + reEnd);
}

function buildSpecialPageGroup(specialPageObj) {
var variants = [];
variants.push(mw.util.escapeRegExp(specialPageObj['realname']));
variants.push(mw.util.escapeRegExp(encodeURI(specialPageObj['realname'])));
specialPageObj.aliases.forEach(function (alias) {
variants.push(mw.util.escapeRegExp(alias));
variants.push(mw.util.escapeRegExp(encodeURI(alias)));
});
return variants.join('|');
}

function setRegexps() {
setMainRegex();
var sp = nsRe(pg.nsSpecialId);
pg.re.urlNoPopup = RegExp('((title=|/)' + sp + '(?:%3A|:)|section=[0-9]|^#$)');

pg.wiki.specialpagealiases.forEach(function (specialpage) {
if (specialpage.realname === 'Contributions') {
pg.re.contribs = RegExp(
'(title=|/)' +
sp +
'(?:%3A|:)(?:' +
buildSpecialPageGroup(specialpage) +
')' +
'(&target=|/|/' +
nsRe(pg.nsUserId) +
':)(.*)',
'i'
);
} else if (specialpage.realname === 'Diff') {
pg.re.specialdiff = RegExp(
'/' + sp + '(?:%3A|:)(?:' + buildSpecialPageGroup(specialpage) + ')' + '/([^?#]*)',
'i'
);
} else if (specialpage.realname === 'Emailuser') {
pg.re.email = RegExp(
'(title=|/)' +
sp +
'(?:%3A|:)(?:' +
buildSpecialPageGroup(specialpage) +
')' +
'(&target=|/|/(?:' +
nsRe(pg.nsUserId) +
':)?)(.*)',
'i'
);
} else if (specialpage.realname === 'Whatlinkshere') {
pg.re.backlinks = RegExp(
'(title=|/)' +
sp +
'(?:%3A|:)(?:' +
buildSpecialPageGroup(specialpage) +
')' +
'(&target=|/)([^&]*)',
'i'
);
}
});

var im = nsReImage();
// note: tries to get images in infobox templates too, e.g. movie pages, album pages etc
// (^|\[\[)image: *([^|\]]*[^|\] ]) *
// (^|\[\[)image: *([^|\]]*[^|\] ])([^0-9\]]*([0-9]+) *px)?
// $4 = 120 as in 120px
pg.re.image = RegExp(
'(^|\\[\\[)' +
im +
': *([^|\\]]*[^|\\] ])' +
'([^0-9\\]]*([0-9]+) *px)?|(?:\\n *[|]?|[|]) *' +
'(' +
getValueOf('popupImageVarsRegexp') +
')' +
' *= *(?:\\[\\[ *)?(?:' +
im +
':)?' +
'([^|]*?)(?:\\]\\])? *[|]? *\\n',
'img'
);
pg.re.imageBracketCount = 6;

pg.re.category = RegExp('\\[\\[' + nsRe(pg.nsCategoryId) + ': *([^|\\]]*[^|\\] ]) *', 'i');
pg.re.categoryBracketCount = 1;

pg.re.ipUser = RegExp(
'^' +
// IPv6
'(?::(?::|(?::[0-9A-Fa-f]{1,4}){1,7})|[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4}){0,6}::|[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4}){7})' +
// IPv4
'|(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}' +
'(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]))$'
);

pg.re.stub = RegExp(getValueOf('popupStubRegexp'), 'im');
pg.re.disambig = RegExp(getValueOf('popupDabRegexp'), 'im');

// FIXME replace with general parameter parsing function, this is daft
pg.re.oldid = RegExp('[?&]oldid=([^&]*)');
pg.re.diff = RegExp('[?&]diff=([^&]*)');
}

//////////////////////////////////////////////////
// miscellany

function setupCache() {
// page caching
pg.cache.pages = [];
}

function setMisc() {
pg.current.link = null;
pg.current.links = [];
pg.current.linksHash = {};

setupCache();

pg.timer.checkPopupPosition = null;
pg.counter.loop = 0;

// ids change with each popup: popupImage0, popupImage1 etc
pg.idNumber = 0;

// for myDecodeURI
pg.misc.decodeExtras = [
{ from: '%2C', to: ',' },
{ from: '_', to: ' ' },
{ from: '%24', to: '$' },
{ from: '%26', to: '&' }, // no ,
];
}

function getMwApi() {
if (!pg.api.client) {
pg.api.userAgent = 'Navigation popups/1.0 (' + mw.config.get('wgServerName') + ')';
pg.api.client = new mw.Api({
ajax: {
headers: {
'Api-User-Agent': pg.api.userAgent,
},
},
});
}
return pg.api.client;
}

// We need a callback since this might end up asynchronous because of
// the mw.loader.using() call.
function setupPopups(callback) {
if (setupPopups.completed) {
if (typeof callback === 'function') {
callback();
}
return;
}
// These dependencies should alse be enforced from the gadget,
// but not everyone loads this as a gadget, so double check
mw.loader
.using([
'mediawiki.util',
'mediawiki.api',
'mediawiki.user',
'user.options',
'mediawiki.jqueryMsg',
])
.then(fetchSpecialPageNames)
.then(function () {
// NB translatable strings should be set up first (strings.js)
// basics
setupDebugging();
setSiteInfo();
setTitleBase();
setOptions(); // see options.js
setUserInfo();

// namespaces etc
setNamespaces();
setInterwiki();

// regexps
setRegexps();
setRedirs();

// other stuff
setMisc();
setupLivePreview();

// main deal here
setupTooltips();
log('In setupPopups(), just called setupTooltips()');
Navpopup.tracker.enable();

setupPopups.completed = true;
if (typeof callback === 'function') {
callback();
}
});
}
// ENDFILE: init.js

// STARTFILE: navlinks.js
//////////////////////////////////////////////////
// navlinks... let the fun begin
//

function defaultNavlinkSpec() {
var str = '';
str += '<b><<mainlink|shortcut= >></b>';
if (getValueOf('popupLastEditLink')) {
str +=
'*<<lastEdit|shortcut=/>>|<<lastContrib>>|<<sinceMe>>if(oldid){|<<oldEdit>>|<<diffCur>>}';
}

// user links
// contribs - log - count - email - block
// count only if applicable; block only if popupAdminLinks
str += 'if(user){<br><<contribs|shortcut=c>>*<<userlog|shortcut=L|log>>';
str += 'if(ipuser){*<<arin>>}if(wikimedia){*<<count|shortcut=#>>}';
str +=
'if(ipuser){}else{*<<email|shortcut=E>>}if(admin){*<<block|shortcut=b>>|<<blocklog|log>>}}';

// editing links
// talkpage -> edit|new - history - un|watch - article|edit
// other page -> edit - history - un|watch - talk|edit|new
var editstr = '<<edit|shortcut=e>>';
var editOldidStr =
'if(oldid){<<editOld|shortcut=e>>|<<revert|shortcut=v|rv>>|<<edit|cur>>}else{' +
editstr +
'}';
var historystr = '<<history|shortcut=h>>|<<editors|shortcut=E|>>';
var watchstr = '<<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>>';

str +=
'<br>if(talk){' +
editOldidStr +
'|<<new|shortcut=+>>' +
'*' +
historystr +
'*' +
watchstr +
'*' +
'<b><<article|shortcut=a>></b>|<<editArticle|edit>>' +
'}else{' + // not a talk page
editOldidStr +
'*' +
historystr +
'*' +
watchstr +
'*' +
'<b><<talk|shortcut=t>></b>|<<editTalk|edit>>|<<newTalk|shortcut=+|new>>}';

// misc links
str += '<br><<whatLinksHere|shortcut=l>>*<<relatedChanges|shortcut=r>>*<<move|shortcut=m>>';

// admin links
str +=
'if(admin){<br><<unprotect|unprotectShort>>|<<protect|shortcut=p>>|<<protectlog|log>>*' +
'<<undelete|undeleteShort>>|<<delete|shortcut=d>>|<<deletelog|log>>}';
return str;
}

function navLinksHTML(article, hint, params) {
//oldid, rcid) {
var str = '<span class="popupNavLinks">' + defaultNavlinkSpec() + '</span>';
// BAM
return navlinkStringToHTML(str, article, params);
}

function expandConditionalNavlinkString(s, article, z, recursionCount) {
var oldid = z.oldid,
rcid = z.rcid,
diff = z.diff;
// nested conditionals (up to 10 deep) are ok, hopefully! (work from the inside out)
if (typeof recursionCount != typeof 0) {
recursionCount = 0;
}
var conditionalSplitRegex = RegExp(
//(1 if \\( (2 2) \\) {(3 3)} (4 else {(5 5)} 4)1)
'(;?\\s*if\\s*\\(\\s*([\\w]*)\\s*\\)\\s*\\{([^{}]*)\\}(\\s*else\\s*\\{([^{}]*?)\\}|))',
'i'
);
var splitted = s.parenSplit(conditionalSplitRegex);
// $1: whole conditional
// $2: test condition
// $3: true expansion
// $4: else clause (possibly empty)
// $5: false expansion (possibly null)
var numParens = 5;
var ret = splitted[0];
for (var i = 1; i < splitted.length; i = i + numParens + 1) {
var testString = splitted[i + 2 - 1];
var trueString = splitted[i + 3 - 1];
var falseString = splitted[i + 5 - 1];
if (typeof falseString == 'undefined' || !falseString) {
falseString = '';
}
var testResult = null;

switch (testString) {
case 'user':
testResult = !!article.userName();
break;
case 'talk':
testResult = !article.talkPage(); // talkPage converts _articles_ to talkPages
break;
case 'admin':
testResult = !!getValueOf('popupAdminLinks');
break;
case 'oldid':
testResult = !!(typeof oldid != 'undefined' && oldid);
break;
case 'rcid':
testResult = !!(typeof rcid != 'undefined' && rcid);
break;
case 'ipuser':
testResult = !!article.isIpUser();
break;
case 'mainspace_en':
testResult = isInMainNamespace(article) && pg.wiki.hostname == 'en.wikipedia.org';
break;
case 'wikimedia':
testResult = !!pg.wiki.wikimedia;
break;
case 'diff':
testResult = !!(typeof diff != 'undefined' && diff);
break;
}

switch (testResult) {
case null:
ret += splitted[i];
break;
case true:
ret += trueString;
break;
case false:
ret += falseString;
break;
}

// append non-conditional string
ret += splitted[i + numParens];
}
if (conditionalSplitRegex.test(ret) && recursionCount < 10) {
return expandConditionalNavlinkString(ret, article, z, recursionCount + 1);
}
return ret;
}

function navlinkStringToArray(s, article, params) {
s = expandConditionalNavlinkString(s, article, params);
var splitted = s.parenSplit(RegExp('<<(.*?)>>'));
var ret = [];
for (var i = 0; i < splitted.length; ++i) {
if (i % 2) {
// i odd, so s is a tag
var t = new navlinkTag();
var ss = splitted[i].split('|');
t.id = ss[0];
for (var j = 1; j < ss.length; ++j) {
var sss = ss[j].split('=');
if (sss.length > 1) {
t[sss[0]] = sss[1];
} else {
// no assignment (no "="), so treat this as a title (overwriting the last one)
t.text = popupString(sss[0]);
}
}
t.article = article;
var oldid = params.oldid,
rcid = params.rcid,
diff = params.diff;
if (typeof oldid !== 'undefined' && oldid !== null) {
t.oldid = oldid;
}
if (typeof rcid !== 'undefined' && rcid !== null) {
t.rcid = rcid;
}
if (typeof diff !== 'undefined' && diff !== null) {
t.diff = diff;
}
if (!t.text && t.id !== 'mainlink') {
t.text = popupString(t.id);
}
ret.push(t);
} else {
// plain HTML
ret.push(splitted[i]);
}
}
return ret;
}

function navlinkSubstituteHTML(s) {
return s
.split('*')
.join(getValueOf('popupNavLinkSeparator'))
.split('<menurow>')
.join('<li class="popup_menu_row">')
.split('</menurow>')
.join('</li>')
.split('<menu>')
.join('<ul class="popup_menu">')
.split('</menu>')
.join('</ul>');
}

function navlinkDepth(magic, s) {
return s.split('<' + magic + '>').length - s.split('</' + magic + '>').length;
}

// navlinkString: * becomes the separator
// <<foo|bar=baz|fubar>> becomes a foo-link with attribute bar='baz'
// and visible text 'fubar'
// if(test){...} and if(test){...}else{...} work too (nested ok)

function navlinkStringToHTML(s, article, params) {
//limitAlert(navlinkStringToHTML, 5, 'navlinkStringToHTML\n' + article + '\n' + (typeof article));
var p = navlinkStringToArray(s, article, params);
var html = '';
var menudepth = 0; // nested menus not currently allowed, but doesn't do any harm to code for it
var menurowdepth = 0;
for (var i = 0; i < p.length; ++i) {
if (typeof p[i] == typeof '') {
html += navlinkSubstituteHTML(p[i]);
menudepth += navlinkDepth('menu', p[i]);
menurowdepth += navlinkDepth('menurow', p[i]);
// if (menudepth === 0) {
// tagType='span';
// } else if (menurowdepth === 0) {
// tagType='li';
// } else {
// tagType = null;
// }
} else if (typeof p[i].type != 'undefined' && p[i].type == 'navlinkTag') {
if (menudepth > 0 && menurowdepth === 0) {
html += '<li class="popup_menu_item">' + p[i].html() + '</li>';
} else {
html += p[i].html();
}
}
}
return html;
}

function navlinkTag() {
this.type = 'navlinkTag';
}

navlinkTag.prototype.html = function () {
this.getNewWin();
this.getPrintFunction();
var html = '';
var opening, closing;
var tagType = 'span';
if (!tagType) {
opening = '';
closing = '';
} else {
opening = '<' + tagType + ' class="popup_' + this.id + '">';
closing = '</' + tagType + '>';
}
if (typeof this.print != 'function') {
errlog('Oh dear - invalid print function for a navlinkTag, id=' + this.id);
} else {
html = this.print(this);
if (typeof html != typeof '') {
html = '';
} else if (typeof this.shortcut != 'undefined') {
html = addPopupShortcut(html, this.shortcut);
}
}
return opening + html + closing;
};

navlinkTag.prototype.getNewWin = function () {
getValueOf('popupLinksNewWindow');
if (typeof pg.option.popupLinksNewWindow[this.id] === 'undefined') {
this.newWin = null;
}
this.newWin = pg.option.popupLinksNewWindow[this.id];
};

navlinkTag.prototype.getPrintFunction = function () {
//think about this some more
// this.id and this.article should already be defined
if (typeof this.id != typeof '' || typeof this.article != typeof {}) {
return;
}

this.noPopup = 1;
switch (this.id) {
case 'contribs':
case 'history':
case 'whatLinksHere':
case 'userPage':
case 'monobook':
case 'userTalk':
case 'talk':
case 'article':
case 'lastEdit':
this.noPopup = null;
}
switch (this.id) {
case 'email':
case 'contribs':
case 'block':
case 'unblock':
case 'userlog':
case 'userSpace':
case 'deletedContribs':
this.article = this.article.userName();
}

switch (this.id) {
case 'userTalk':
case 'newUserTalk':
case 'editUserTalk':
case 'userPage':
case 'monobook':
case 'editMonobook':
case 'blocklog':
this.article = this.article.userName(true);
/* fall through */
case 'pagelog':
case 'deletelog':
case 'protectlog':
delete this.oldid;
}

if (this.id == 'editMonobook' || this.id == 'monobook') {
this.article.append('/monobook.js');
}

if (this.id != 'mainlink') {
// FIXME anchor handling should be done differently with Title object
this.article = this.article.removeAnchor();
// if (typeof this.text=='undefined') this.text=popupString(this.id);
}

switch (this.id) {
case 'undelete':
this.print = specialLink;
this.specialpage = 'Undelete';
this.sep = '/';
break;
case 'whatLinksHere':
this.print = specialLink;
this.specialpage = 'Whatlinkshere';
break;
case 'relatedChanges':
this.print = specialLink;
this.specialpage = 'Recentchangeslinked';
break;
case 'move':
this.print = specialLink;
this.specialpage = 'Movepage';
break;
case 'contribs':
this.print = specialLink;
this.specialpage = 'Contributions';
break;
case 'deletedContribs':
this.print = specialLink;
this.specialpage = 'Deletedcontributions';
break;
case 'email':
this.print = specialLink;
this.specialpage = 'EmailUser';
this.sep = '/';
break;
case 'block':
this.print = specialLink;
this.specialpage = 'Blockip';
this.sep = '&ip=';
break;
case 'unblock':
this.print = specialLink;
this.specialpage = 'Ipblocklist';
this.sep = '&action=unblock&ip=';
break;
case 'userlog':
this.print = specialLink;
this.specialpage = 'Log';
this.sep = '&user=';
break;
case 'blocklog':
this.print = specialLink;
this.specialpage = 'Log';
this.sep = '&type=block&page=';
break;
case 'pagelog':
this.print = specialLink;
this.specialpage = 'Log';
this.sep = '&page=';
break;
case 'protectlog':
this.print = specialLink;
this.specialpage = 'Log';
this.sep = '&type=protect&page=';
break;
case 'deletelog':
this.print = specialLink;
this.specialpage = 'Log';
this.sep = '&type=delete&page=';
break;
case 'userSpace':
this.print = specialLink;
this.specialpage = 'PrefixIndex';
this.sep = '&namespace=2&prefix=';
break;
case 'search':
this.print = specialLink;
this.specialpage = 'Search';
this.sep = '&fulltext=Search&search=';
break;
case 'thank':
this.print = specialLink;
this.specialpage = 'Thanks';
this.sep = '/';
this.article.value = this.diff !== 'prev' ? this.diff : this.oldid;
break;
case 'unwatch':
case 'watch':
this.print = magicWatchLink;
this.action =
this.id +
'&autowatchlist=1&autoimpl=' +
popupString('autoedit_version') +
'&actoken=' +
autoClickToken();
break;
case 'history':
case 'historyfeed':
case 'unprotect':
case 'protect':
this.print = wikiLink;
this.action = this.id;
break;

case 'delete':
this.print = wikiLink;
this.action = 'delete';
if (this.article.namespaceId() == pg.nsImageId) {
var img = this.article.stripNamespace();
this.action += '&image=' + img;
}
break;

case 'markpatrolled':
case 'edit': // editOld should keep the oldid, but edit should not.
delete this.oldid;
/* fall through */
case 'view':
case 'purge':
case 'render':
this.print = wikiLink;
this.action = this.id;
break;
case 'raw':
this.print = wikiLink;
this.action = 'raw';
break;
case 'new':
this.print = wikiLink;
this.action = 'edit&section=new';
break;
case 'mainlink':
if (typeof this.text == 'undefined') {
this.text = this.article.toString().entify();
}
if (getValueOf('popupSimplifyMainLink') && isInStrippableNamespace(this.article)) {
// only show the /subpage part of the title text
var s = this.text.split('/');
this.text = s[s.length - 1];
if (this.text === '' && s.length > 1) {
this.text = s[s.length - 2];
}
}
this.print = titledWikiLink;
if (
typeof this.title === 'undefined' &&
pg.current.link &&
typeof pg.current.link.href !== 'undefined'
) {
this.title = safeDecodeURI(
pg.current.link.originalTitle ? pg.current.link.originalTitle : this.article
);
if (typeof this.oldid !== 'undefined' && this.oldid) {
this.title = tprintf('Revision %s of %s', [this.oldid, this.title]);
}
}
this.action = 'view';
break;
case 'userPage':
case 'article':
case 'monobook':
case 'editMonobook':
case 'editArticle':
delete this.oldid;
//alert(this.id+'\n'+this.article + '\n'+ typeof this.article);
this.article = this.article.articleFromTalkOrArticle();
//alert(this.id+'\n'+this.article + '\n'+ typeof this.article);
this.print = wikiLink;
if (this.id.indexOf('edit') === 0) {
this.action = 'edit';
} else {
this.action = 'view';
}
break;
case 'userTalk':
case 'talk':
this.article = this.article.talkPage();
delete this.oldid;
this.print = wikiLink;
this.action = 'view';
break;
case 'arin':
this.print = arinLink;
break;
case 'count':
this.print = editCounterLink;
break;
case 'google':
this.print = googleLink;
break;
case 'editors':
this.print = editorListLink;
break;
case 'globalsearch':
this.print = globalSearchLink;
break;
case 'lastEdit':
this.print = titledDiffLink;
this.title = popupString('Show the last edit');
this.from = 'prev';
this.to = 'cur';
break;
case 'oldEdit':
this.print = titledDiffLink;
this.title = popupString('Show the edit made to get revision') + ' ' + this.oldid;
this.from = 'prev';
this.to = this.oldid;
break;
case 'editOld':
this.print = wikiLink;
this.action = 'edit';
break;
case 'undo':
this.print = wikiLink;
this.action = 'edit&undo=';
break;
case 'revert':
this.print = wikiLink;
this.action = 'revert';
break;
case 'nullEdit':
this.print = wikiLink;
this.action = 'nullEdit';
break;
case 'diffCur':
this.print = titledDiffLink;
this.title = tprintf('Show changes since revision %s', [this.oldid]);
this.from = this.oldid;
this.to = 'cur';
break;
case 'editUserTalk':
case 'editTalk':
delete this.oldid;
this.article = this.article.talkPage();
this.action = 'edit';
this.print = wikiLink;
break;
case 'newUserTalk':
case 'newTalk':
this.article = this.article.talkPage();
this.action = 'edit&section=new';
this.print = wikiLink;
break;
case 'lastContrib':
case 'sinceMe':
this.print = magicHistoryLink;
break;
case 'togglePreviews':
this.text = popupString(pg.option.simplePopups ? 'enable previews' : 'disable previews');
/* fall through */
case 'disablePopups':
case 'purgePopups':
this.print = popupMenuLink;
break;
default:
this.print = function () {
return 'Unknown navlink type: ' + String(this.id);
};
}
};
//
// end navlinks
//////////////////////////////////////////////////
// ENDFILE: navlinks.js

// STARTFILE: shortcutkeys.js
function popupHandleKeypress(evt) {
var keyCode = window.event ? window.event.keyCode : evt.keyCode ? evt.keyCode : evt.which;
if (!keyCode || !pg.current.link || !pg.current.link.navpopup) {
return;
}
if (keyCode == 27) {
// escape
killPopup();
return false; // swallow keypress
}

var letter = String.fromCharCode(keyCode);
var links = pg.current.link.navpopup.mainDiv.getElementsByTagName('A');
var startLink = 0;
var i, j;

if (popupHandleKeypress.lastPopupLinkSelected) {
for (i = 0; i < links.length; ++i) {
if (links[i] == popupHandleKeypress.lastPopupLinkSelected) {
startLink = i;
}
}
}
for (j = 0; j < links.length; ++j) {
i = (startLink + j + 1) % links.length;
if (links[i].getAttribute('popupkey') == letter) {
if (evt && evt.preventDefault) {
evt.preventDefault();
}
links[i].focus();
popupHandleKeypress.lastPopupLinkSelected = links[i];
return false; // swallow keypress
}
}

// pass keypress on
if (document.oldPopupOnkeypress) {
return document.oldPopupOnkeypress(evt);
}
return true;
}

function addPopupShortcuts() {
if (document.onkeypress != popupHandleKeypress) {
document.oldPopupOnkeypress = document.onkeypress;
}
document.onkeypress = popupHandleKeypress;
}

function rmPopupShortcuts() {
popupHandleKeypress.lastPopupLinkSelected = null;
try {
if (document.oldPopupOnkeypress && document.oldPopupOnkeypress == popupHandleKeypress) {
// panic
document.onkeypress = null; //function () {};
return;
}
document.onkeypress = document.oldPopupOnkeypress;
} catch (nasties) {
/* IE goes here */
}
}

function addLinkProperty(html, property) {
// take "<a href=...>...</a> and add a property
// not sophisticated at all, easily broken
var i = html.indexOf('>');
if (i < 0) {
return html;
}
return html.substring(0, i) + ' ' + property + html.substring(i);
}

function addPopupShortcut(html, key) {
if (!getValueOf('popupShortcutKeys')) {
return html;
}
var ret = addLinkProperty(html, 'popupkey="' + key + '"');
if (key == ' ') {
key = popupString('spacebar');
}
return ret.replace(RegExp('^(.*?)(title=")(.*?)(".*)$', 'i'), '$1$2$3 [' + key + ']$4');
}
// ENDFILE: shortcutkeys.js

// STARTFILE: diffpreview.js
/**
* Load diff data.
*
* lets jump through hoops to find the rev ids we need to retrieve
*
* @param {Title} article
* @param {String} oldid
* @param {String} diff
* @param {Navpopup} navpop
*/
function loadDiff(article, oldid, diff, navpop) {
navpop.diffData = { oldRev: {}, newRev: {} };
mw.loader.using('mediawiki.api').then(function () {
var api = getMwApi();
var params = {
action: 'compare',
prop: 'ids|title',
};
params.fromtitle = article.toString();

switch (diff) {
case 'cur':
switch (oldid) {
case null:
case '':
case 'prev':
// this can only work if we have the title
// cur -> prev
params.torelative = 'prev';
break;
default:
params.fromrev = oldid;
params.torelative = 'cur';
break;
}
break;
case 'prev':
if (oldid && oldid !== 'cur') {
params.fromrev = oldid;
}
params.torelative = 'prev';
break;
case 'next':
params.fromrev = oldid || 0;
params.torelative = 'next';
break;
default:
params.fromrev = oldid || 0;
params.torev = diff || 0;
break;
}

api.get(params).then(function (data) {
navpop.diffData.oldRev.revid = data.compare.fromrevid;
navpop.diffData.newRev.revid = data.compare.torevid;

addReviewLink(navpop, 'popupMiscTools');

var go = function () {
pendingNavpopTask(navpop);
var url = pg.wiki.apiwikibase + '?format=json&formatversion=2&action=query&';

url += 'revids=' + navpop.diffData.oldRev.revid + '|' + navpop.diffData.newRev.revid;
url += '&prop=revisions&rvslots=main&rvprop=ids|timestamp|content';

getPageWithCaching(url, doneDiff, navpop);

return true; // remove hook once run
};
if (navpop.visible || !getValueOf('popupLazyDownloads')) {
go();
} else {
navpop.addHook(go, 'unhide', 'before', 'DOWNLOAD_DIFFS');
}
});
});
}

// Put a "mark patrolled" link to an element target
// TODO: Allow patrol a revision, as well as a diff
function addReviewLink(navpop, target) {
if (!pg.user.canReview) {
return;
}
// If 'newRev' is older than 'oldRev' than it could be confusing, so we do not show the review link.
if (navpop.diffData.newRev.revid <= navpop.diffData.oldRev.revid) {
return;
}
var params = {
action: 'query',
prop: 'info|flagged',
revids: navpop.diffData.oldRev.revid,
formatversion: 2,
};
getMwApi()
.get(params)
.then(function (data) {
var stable_revid =
(data.query.pages[0].flagged && data.query.pages[0].flagged.stable_revid) || 0;
// The diff can be reviewed if the old version is the last reviewed version
// TODO: Other possible conditions that we may want to implement instead of this one:
// * old version is patrolled and the new version is not patrolled
// * old version is patrolled and the new version is more recent than the last reviewed version
if (stable_revid == navpop.diffData.oldRev.revid) {
var a = document.createElement('a');
a.innerHTML = popupString('mark patrolled');
a.title = popupString('markpatrolledHint');
a.onclick = function () {
var params = {
action: 'review',
revid: navpop.diffData.newRev.revid,
comment: tprintf('defaultpopupReviewedSummary', [
navpop.diffData.oldRev.revid,
navpop.diffData.newRev.revid,
]),
};
getMwApi()
.postWithToken('csrf', params)
.done(function () {
a.style.display = 'none';
// TODO: Update current page and other already constructed popups
})
.fail(function () {
alert(popupString('Could not marked this edit as patrolled'));
});
};
setPopupHTML(a, target, navpop.idNumber, null, true);
}
});
}

function doneDiff(download) {
if (!download.owner || !download.owner.diffData) {
return;
}
var navpop = download.owner;
completedNavpopTask(navpop);

var pages,
revisions = [];
try {
// Process the downloads
pages = getJsObj(download.data).query.pages;
for (var i = 0; i < pages.length; i++) {
revisions = revisions.concat(pages[i].revisions);
}
for (i = 0; i < revisions.length; i++) {
if (revisions[i].revid == navpop.diffData.oldRev.revid) {
navpop.diffData.oldRev.revision = revisions[i];
} else if (revisions[i].revid == navpop.diffData.newRev.revid) {
navpop.diffData.newRev.revision = revisions[i];
}
}
} catch (someError) {
errlog('Could not get diff');
}

insertDiff(navpop);
}

function rmBoringLines(a, b, context) {
if (typeof context == 'undefined') {
context = 2;
}
// this is fairly slow... i think it's quicker than doing a word-based diff from the off, though
var aa = [],
aaa = [];
var bb = [],
bbb = [];
var i, j;

// first, gather all disconnected nodes in a and all crossing nodes in a and b
for (i = 0; i < a.length; ++i) {
if (!a[i].paired) {
aa[i] = 1;
} else if (countCrossings(b, a, i, true)) {
aa[i] = 1;
bb[a[i].row] = 1;
}
}

// pick up remaining disconnected nodes in b
for (i = 0; i < b.length; ++i) {
if (bb[i] == 1) {
continue;
}
if (!b[i].paired) {
bb[i] = 1;
}
}

// another pass to gather context: we want the neighbours of included nodes which are not
// yet included we have to add in partners of these nodes, but we don't want to add context
// for *those* nodes in the next pass
for (i = 0; i < b.length; ++i) {
if (bb[i] == 1) {
for (j = Math.max(0, i - context); j < Math.min(b.length, i + context); ++j) {
if (!bb[j]) {
bb[j] = 1;
aa[b[j].row] = 0.5;
}
}
}
}

for (i = 0; i < a.length; ++i) {
if (aa[i] == 1) {
for (j = Math.max(0, i - context); j < Math.min(a.length, i + context); ++j) {
if (!aa[j]) {
aa[j] = 1;
bb[a[j].row] = 0.5;
}
}
}
}

for (i = 0; i < bb.length; ++i) {
if (bb[i] > 0) {
// it's a row we need
if (b[i].paired) {
bbb.push(b[i].text);
} // joined; partner should be in aa
else {
bbb.push(b[i]);
}
}
}
for (i = 0; i < aa.length; ++i) {
if (aa[i] > 0) {
// it's a row we need
if (a[i].paired) {
aaa.push(a[i].text);
} // joined; partner should be in aa
else {
aaa.push(a[i]);
}
}
}

return { a: aaa, b: bbb };
}

function stripOuterCommonLines(a, b, context) {
var i = 0;
while (i < a.length && i < b.length && a[i] == b[i]) {
++i;
}
var j = a.length - 1;
var k = b.length - 1;
while (j >= 0 && k >= 0 && a[j] == b[k]) {
--j;
--k;
}

return {
a: a.slice(Math.max(0, i - 1 - context), Math.min(a.length + 1, j + context + 1)),
b: b.slice(Math.max(0, i - 1 - context), Math.min(b.length + 1, k + context + 1)),
};
}

function insertDiff(navpop) {
// for speed reasons, we first do a line-based diff, discard stuff that seems boring, then
// do a word-based diff
// FIXME: sometimes this gives misleading diffs as distant chunks are squashed together
var oldlines = navpop.diffData.oldRev.revision.slots.main.content.split('\n');
var newlines = navpop.diffData.newRev.revision.slots.main.content.split('\n');
var inner = stripOuterCommonLines(oldlines, newlines, getValueOf('popupDiffContextLines'));
oldlines = inner.a;
newlines = inner.b;
var truncated = false;
getValueOf('popupDiffMaxLines');
if (
oldlines.length > pg.option.popupDiffMaxLines ||
newlines.length > pg.option.popupDiffMaxLines
) {
// truncate
truncated = true;
inner = stripOuterCommonLines(
oldlines.slice(0, pg.option.popupDiffMaxLines),
newlines.slice(0, pg.option.popupDiffMaxLines),
pg.option.popupDiffContextLines
);
oldlines = inner.a;
newlines = inner.b;
}

var lineDiff = diff(oldlines, newlines);
var lines2 = rmBoringLines(lineDiff.o, lineDiff.n);
var oldlines2 = lines2.a;
var newlines2 = lines2.b;

var simpleSplit = !String.prototype.parenSplit.isNative;
var html = '<hr />';
if (getValueOf('popupDiffDates')) {
html += diffDatesTable(navpop);
html += '<hr />';
}
html += shortenDiffString(
diffString(oldlines2.join('\n'), newlines2.join('\n'), simpleSplit),
getValueOf('popupDiffContextCharacters')
).join('<hr />');
setPopupTipsAndHTML(
html.split('\n').join('<br>') +
(truncated
? '<hr /><b>' + popupString('Diff truncated for performance reasons') + '</b>'
: ''),
'popupPreview',
navpop.idNumber
);
}

function diffDatesTable(navpop) {
var html = '<table class="popup_diff_dates">';
html += diffDatesTableRow(navpop.diffData.newRev.revision, tprintf('New revision'));
html += diffDatesTableRow(navpop.diffData.oldRev.revision, tprintf('Old revision'));
html += '</table>';
return html;
}
function diffDatesTableRow(revision, label) {
var txt = '';
var lastModifiedDate = new Date(revision.timestamp);

txt = formattedDateTime(lastModifiedDate);

var revlink = generalLink({
url: mw.config.get('wgScript') + '?oldid=' + revision.revid,
text: label,
title: label,
});
return simplePrintf('<tr><td>%s</td><td>%s</td></tr>', [revlink, txt]);
}
// ENDFILE: diffpreview.js

// STARTFILE: links.js
/////////////////////
// LINK GENERATION //
/////////////////////

// titledDiffLink --> titledWikiLink --> generalLink
// wikiLink --> titledWikiLink --> generalLink
// editCounterLink --> generalLink

// TODO Make these functions return Element objects, not just raw HTML strings.

function titledDiffLink(l) {
// article, text, title, from, to) {
return titledWikiLink({
article: l.article,
action: l.to + '&oldid=' + l.from,
newWin: l.newWin,
noPopup: l.noPopup,
text: l.text,
title: l.title,
/* hack: no oldid here */
actionName: 'diff',
});
}

function wikiLink(l) {
//{article:article, action:action, text:text, oldid, newid}) {
if (
!(typeof l.article == typeof {} && typeof l.action == typeof '' && typeof l.text == typeof '')
) {
return null;
}
if (typeof l.oldid == 'undefined') {
l.oldid = null;
}
var savedOldid = l.oldid;
if (!/^(edit|view|revert|render)$|^raw/.test(l.action)) {
l.oldid = null;
}
var hint = popupString(l.action + 'Hint'); // revertHint etc etc etc
var oldidData = [l.oldid, safeDecodeURI(l.article)];
var revisionString = tprintf('revision %s of %s', oldidData);
log('revisionString=' + revisionString);
switch (l.action) {
case 'edit&section=new':
hint = popupString('newSectionHint');
break;
case 'edit&undo=':
if (l.diff && l.diff != 'prev' && savedOldid) {
l.action += l.diff + '&undoafter=' + savedOldid;
} else if (savedOldid) {
l.action += savedOldid;
}
hint = popupString('undoHint');
break;
case 'raw&ctype=text/css':
hint = popupString('rawHint');
break;
case 'revert':
var p = parseParams(pg.current.link.href);
l.action =
'edit&autoclick=wpSave&actoken=' +
autoClickToken() +
'&autoimpl=' +
popupString('autoedit_version') +
'&autosummary=' +
revertSummary(l.oldid, p.diff);
if (p.diff == 'prev') {
l.action += '&direction=prev';
revisionString = tprintf('the revision prior to revision %s of %s', oldidData);
}
if (getValueOf('popupRevertSummaryPrompt')) {
l.action += '&autosummaryprompt=true';
}
if (getValueOf('popupMinorReverts')) {
l.action += '&autominor=true';
}
log('revisionString is now ' + revisionString);
break;
case 'nullEdit':
l.action =
'edit&autoclick=wpSave&actoken=' +
autoClickToken() +
'&autoimpl=' +
popupString('autoedit_version') +
'&autosummary=null';
break;
case 'historyfeed':
l.action = 'history&feed=rss';
break;
case 'markpatrolled':
l.action = 'markpatrolled&rcid=' + l.rcid;
}

if (hint) {
if (l.oldid) {
hint = simplePrintf(hint, [revisionString]);
} else {
hint = simplePrintf(hint, [safeDecodeURI(l.article)]);
}
} else {
hint = safeDecodeURI(l.article + '&action=' + l.action) + l.oldid ? '&oldid=' + l.oldid : '';
}

return titledWikiLink({
article: l.article,
action: l.action,
text: l.text,
newWin: l.newWin,
title: hint,
oldid: l.oldid,
noPopup: l.noPopup,
onclick: l.onclick,
});
}

function revertSummary(oldid, diff) {
var ret = '';
if (diff == 'prev') {
ret = getValueOf('popupQueriedRevertToPreviousSummary');
} else {
ret = getValueOf('popupQueriedRevertSummary');
}
return ret + '&autorv=' + oldid;
}

function titledWikiLink(l) {
// possible properties of argument:
// article, action, text, title, oldid, actionName, className, noPopup
// oldid = null is fine here

// article and action are mandatory args

if (typeof l.article == 'undefined' || typeof l.action == 'undefined') {
errlog('got undefined article or action in titledWikiLink');
return null;
}

var base = pg.wiki.titlebase + l.article.urlString();
var url = base;

if (typeof l.actionName == 'undefined' || !l.actionName) {
l.actionName = 'action';
}

// no need to add &action=view, and this confuses anchors
if (l.action != 'view') {
url = base + '&' + l.actionName + '=' + l.action;
}

if (typeof l.oldid != 'undefined' && l.oldid) {
url += '&oldid=' + l.oldid;
}

var cssClass = pg.misc.defaultNavlinkClassname;
if (typeof l.className != 'undefined' && l.className) {
cssClass = l.className;
}

return generalNavLink({
url: url,
newWin: l.newWin,
title: typeof l.title != 'undefined' ? l.title : null,
text: typeof l.text != 'undefined' ? l.text : null,
className: cssClass,
noPopup: l.noPopup,
onclick: l.onclick,
});
}

pg.fn.getLastContrib = function getLastContrib(wikipage, newWin) {
getHistoryInfo(wikipage, function (x) {
processLastContribInfo(x, { page: wikipage, newWin: newWin });
});
};

function processLastContribInfo(info, stuff) {
if (!info.edits || !info.edits.length) {
alert('Popups: an odd thing happened. Please retry.');
return;
}
if (!info.firstNewEditor) {
alert(
tprintf('Only found one editor: %s made %s edits', [
info.edits[0].editor,
info.edits.length,
])
);
return;
}
var newUrl =
pg.wiki.titlebase +
new Title(stuff.page).urlString() +
'&diff=cur&oldid=' +
info.firstNewEditor.oldid;
displayUrl(newUrl, stuff.newWin);
}

pg.fn.getDiffSinceMyEdit = function getDiffSinceMyEdit(wikipage, newWin) {
getHistoryInfo(wikipage, function (x) {
processDiffSinceMyEdit(x, { page: wikipage, newWin: newWin });
});
};

function processDiffSinceMyEdit(info, stuff) {
if (!info.edits || !info.edits.length) {
alert('Popups: something fishy happened. Please try again.');
return;
}
var friendlyName = stuff.page.split('_').join(' ');
if (!info.myLastEdit) {
alert(
tprintf("Couldn't find an edit by %s\nin the last %s edits to\n%s", [
info.userName,
getValueOf('popupHistoryLimit'),
friendlyName,
])
);
return;
}
if (info.myLastEdit.index === 0) {
alert(
tprintf('%s seems to be the last editor to the page %s', [info.userName, friendlyName])
);
return;
}
var newUrl =
pg.wiki.titlebase +
new Title(stuff.page).urlString() +
'&diff=cur&oldid=' +
info.myLastEdit.oldid;
displayUrl(newUrl, stuff.newWin);
}

function displayUrl(url, newWin) {
if (newWin) {
window.open(url);
} else {
document.location = url;
}
}

pg.fn.purgePopups = function purgePopups() {
processAllPopups(true);
setupCache(); // deletes all cached items (not browser cached, though...)
pg.option = {};
abortAllDownloads();
};

function processAllPopups(nullify, banish) {
for (var i = 0; pg.current.links && i < pg.current.links.length; ++i) {
if (!pg.current.links[i].navpopup) {
continue;
}
if (nullify || banish) {
pg.current.links[i].navpopup.banish();
}
pg.current.links[i].simpleNoMore = false;
if (nullify) {
pg.current.links[i].navpopup = null;
}
}
}

pg.fn.disablePopups = function disablePopups() {
processAllPopups(false, true);
setupTooltips(null, true);
};

pg.fn.togglePreviews = function togglePreviews() {
processAllPopups(true, true);
pg.option.simplePopups = !pg.option.simplePopups;
abortAllDownloads();
};

function magicWatchLink(l) {
//Yuck!! Would require a thorough redesign to add this as a click event though ...
l.onclick = simplePrintf("pg.fn.modifyWatchlist('%s','%s');return false;", [
l.article.toString(true).split('\\').join('\\\\').split("'").join("\\'"),
this.id,
]);
return wikiLink(l);
}

pg.fn.modifyWatchlist = function modifyWatchlist(title, action) {
var reqData = {
action: 'watch',
formatversion: 2,
titles: title,
uselang: mw.config.get('wgUserLanguage'),
};
if (action === 'unwatch') {
reqData.unwatch = true;
}

// Load the Addedwatchtext or Removedwatchtext message and show it
var mwTitle = mw.Title.newFromText(title);
var messageName;
if (mwTitle && mwTitle.getNamespaceId() > 0 && mwTitle.getNamespaceId() % 2 === 1) {
messageName = action === 'watch' ? 'addedwatchtext-talk' : 'removedwatchtext-talk';
} else {
messageName = action === 'watch' ? 'addedwatchtext' : 'removedwatchtext';
}
$.when(
getMwApi().postWithToken('watch', reqData),
getMwApi().loadMessagesIfMissing([messageName])
).done(function () {
mw.notify(mw.message(messageName, title).parseDom());
});
};

function magicHistoryLink(l) {
// FIXME use onclick change href trick to sort this out instead of window.open

var jsUrl = '',
title = '',
onClick = '';
switch (l.id) {
case 'lastContrib':
onClick = simplePrintf("pg.fn.getLastContrib('%s',%s)", [
l.article.toString(true).split('\\').join('\\\\').split("'").join("\\'"),
l.newWin,
]);
title = popupString('lastContribHint');
break;
case 'sinceMe':
onClick = simplePrintf("pg.fn.getDiffSinceMyEdit('%s',%s)", [
l.article.toString(true).split('\\').join('\\\\').split("'").join("\\'"),
l.newWin,
]);
title = popupString('sinceMeHint');
break;
}
jsUrl = 'javascript:' + onClick; // jshint ignore:line
onClick += ';return false;';

return generalNavLink({
url: jsUrl,
newWin: false, // can't have new windows with JS links, I think
title: title,
text: l.text,
noPopup: l.noPopup,
onclick: onClick,
});
}

function popupMenuLink(l) {
var jsUrl = simplePrintf('javascript:pg.fn.%s()', [l.id]); // jshint ignore:line
var title = popupString(simplePrintf('%sHint', [l.id]));
var onClick = simplePrintf('pg.fn.%s();return false;', [l.id]);
return generalNavLink({
url: jsUrl,
newWin: false,
title: title,
text: l.text,
noPopup: l.noPopup,
onclick: onClick,
});
}

function specialLink(l) {
// properties: article, specialpage, text, sep
if (typeof l.specialpage == 'undefined' || !l.specialpage) {
return null;
}
var base =
pg.wiki.titlebase +
mw.config.get('wgFormattedNamespaces')[pg.nsSpecialId] +
':' +
l.specialpage;
if (typeof l.sep == 'undefined' || l.sep === null) {
l.sep = '&target=';
}
var article = l.article.urlString({
keepSpaces: l.specialpage == 'Search',
});
var hint = popupString(l.specialpage + 'Hint');
switch (l.specialpage) {
case 'Log':
switch (l.sep) {
case '&user=':
hint = popupString('userLogHint');
break;
case '&type=block&page=':
hint = popupString('blockLogHint');
break;
case '&page=':
hint = popupString('pageLogHint');
break;
case '&type=protect&page=':
hint = popupString('protectLogHint');
break;
case '&type=delete&page=':
hint = popupString('deleteLogHint');
break;
default:
log('Unknown log type, sep=' + l.sep);
hint = 'Missing hint (FIXME)';
}
break;
case 'PrefixIndex':
article += '/';
break;
}
if (hint) {
hint = simplePrintf(hint, [safeDecodeURI(l.article)]);
} else {
hint = safeDecodeURI(l.specialpage + ':' + l.article);
}

var url = base + l.sep + article;
return generalNavLink({
url: url,
title: hint,
text: l.text,
newWin: l.newWin,
noPopup: l.noPopup,
});
}

/**
* Builds a link from a object representing a link
* @param {object} link
* @param {string} link.url URL
* @param {string} link.text The text to show for a link
* @param {string} link.title Title of the link, this shows up
* when you hover over the link
* @param {boolean} link.newWin Should open in a new Window
* @param {number} link.noPopup Should nest new popups from link (0 or 1)
* @param {string} link.onclick
* @returns {string|null} null if no url is given
*/
function generalLink(link) {
if (typeof link.url == 'undefined') {
return null;
}

var elem = document.createElement( 'a' );

elem.href = link.url;
elem.title = link.title;
// The onclick event adds raw JS in textual form to the HTML.
// TODO: We should look into removing this, and/or auditing what gets sent.
elem.setAttribute( 'onclick', link.onclick );

if ( link.noPopup ) {
elem.setAttribute('noPopup', '1' );
}

var newWin;
if (typeof link.newWin == 'undefined' || link.newWin === null) {
newWin = getValueOf('popupNewWindows');
} else {
newWin = link.newWin;
}
if (newWin) {
elem.target = '_blank';
}
if (link.className) {
elem.className = link.className;
}
elem.innerText = pg.unescapeQuotesHTML(link.text);

return elem.outerHTML;
}

function appendParamsToLink(linkstr, params) {
var sp = linkstr.parenSplit(RegExp('(href="[^"]+?)"', 'i'));
if (sp.length < 2) {
return null;
}
var ret = sp.shift() + sp.shift();
ret += '&' + params + '"';
ret += sp.join('');
return ret;
}

function changeLinkTargetLink(x) {
// newTarget, text, hint, summary, clickButton, minor, title (optional), alsoChangeLabel {
if (x.newTarget) {
log('changeLinkTargetLink: newTarget=' + x.newTarget);
}
if (x.oldTarget !== decodeURIComponent(x.oldTarget)) {
log('This might be an input problem: ' + x.oldTarget);
}

// FIXME: first character of page title as well as namespace should be case insensitive
// eg [[:category:X1]] and [[:Category:X1]] are equivalent
// this'll break if charAt(0) is nasty
var cA = mw.util.escapeRegExp(x.oldTarget);
var chs = cA.charAt(0).toUpperCase();
chs = '[' + chs + chs.toLowerCase() + ']';
var currentArticleRegexBit = chs + cA.substring(1);
currentArticleRegexBit = currentArticleRegexBit
.split(RegExp('(?:[_ ]+|%20)', 'g'))
.join('(?:[_ ]+|%20)')
.split('\\(')
.join('(?:%28|\\()')
.split('\\)')
.join('(?:%29|\\))'); // why does this need to match encoded strings ? links in the document ?
// leading and trailing space should be ignored, and anchor bits optional:
currentArticleRegexBit = '\\s*(' + currentArticleRegexBit + '(?:#[^\\[\\|]*)?)\\s*';
// e.g. Computer (archaic) -> \s*([Cc]omputer[_ ](?:%2528|\()archaic(?:%2528|\)))\s*

// autoedit=s~\[\[([Cc]ad)\]\]~[[Computer-aided%20design|$1]]~g;s~\[\[([Cc]AD)[|]~[[Computer-aided%20design|~g

var title = x.title || mw.config.get('wgPageName').split('_').join(' ');
var lk = titledWikiLink({
article: new Title(title),
newWin: x.newWin,
action: 'edit',
text: x.text,
title: x.hint,
className: 'popup_change_title_link',
});
var cmd = '';
if (x.newTarget) {
// escape '&' and other nasties
var t = x.newTarget;
var s = mw.util.escapeRegExp(x.newTarget);
if (x.alsoChangeLabel) {
cmd += 's~\\[\\[' + currentArticleRegexBit + '\\]\\]~[[' + t + ']]~g;';
cmd += 's~\\[\\[' + currentArticleRegexBit + '[|]~[[' + t + '|~g;';
cmd += 's~\\[\\[' + s + '\\|' + s + '\\]\\]~[[' + t + ']]~g';
} else {
cmd += 's~\\[\\[' + currentArticleRegexBit + '\\]\\]~[[' + t + '|$1]]~g;';
cmd += 's~\\[\\[' + currentArticleRegexBit + '[|]~[[' + t + '|~g;';
cmd += 's~\\[\\[' + s + '\\|' + s + '\\]\\]~[[' + t + ']]~g';
}
} else {
cmd += 's~\\[\\[' + currentArticleRegexBit + '\\]\\]~$1~g;';
cmd += 's~\\[\\[' + currentArticleRegexBit + '[|](.*?)\\]\\]~$2~g';
}
// Build query
cmd = 'autoedit=' + encodeURIComponent(cmd);
cmd +=
'&autoclick=' +
encodeURIComponent(x.clickButton) +
'&actoken=' +
encodeURIComponent(autoClickToken());
cmd += x.minor === null ? '' : '&autominor=' + encodeURIComponent(x.minor);
cmd += x.watch === null ? '' : '&autowatch=' + encodeURIComponent(x.watch);
cmd += '&autosummary=' + encodeURIComponent(x.summary);
cmd += '&autoimpl=' + encodeURIComponent(popupString('autoedit_version'));
return appendParamsToLink(lk, cmd);
}

function redirLink(redirMatch, article) {
// NB redirMatch is in wikiText
var ret = '';

if (getValueOf('popupAppendRedirNavLinks') && getValueOf('popupNavLinks')) {
ret += '<hr />';

if (getValueOf('popupFixRedirs') && typeof autoEdit != 'undefined' && autoEdit) {
ret += popupString('Redirects to: (Fix ');
log('redirLink: newTarget=' + redirMatch);
ret += addPopupShortcut(
changeLinkTargetLink({
newTarget: redirMatch,
text: popupString('target'),
hint: popupString('Fix this redirect, changing just the link target'),
summary: simplePrintf(getValueOf('popupFixRedirsSummary'), [
article.toString(),
redirMatch,
]),
oldTarget: article.toString(),
clickButton: getValueOf('popupRedirAutoClick'),
minor: true,
watch: getValueOf('popupWatchRedirredPages'),
}),
'R'
);
ret += popupString(' or ');
ret += addPopupShortcut(
changeLinkTargetLink({
newTarget: redirMatch,
text: popupString('target & label'),
hint: popupString('Fix this redirect, changing the link target and label'),
summary: simplePrintf(getValueOf('popupFixRedirsSummary'), [
article.toString(),
redirMatch,
]),
oldTarget: article.toString(),
clickButton: getValueOf('popupRedirAutoClick'),
minor: true,
watch: getValueOf('popupWatchRedirredPages'),
alsoChangeLabel: true,
}),
'R'
);
ret += popupString(')');
} else {
ret += popupString('Redirects') + popupString(' to ');
}

return ret;
} else {
return (
'<br> ' +
popupString('Redirects') +
popupString(' to ') +
titledWikiLink({
article: new Title().fromWikiText(redirMatch),
action: 'view' /* FIXME: newWin */,
text: safeDecodeURI(redirMatch),
title: popupString('Bypass redirect'),
})
);
}
}

function arinLink(l) {
if (!saneLinkCheck(l)) {
return null;
}
if (!l.article.isIpUser() || !pg.wiki.wikimedia) {
return null;
}

var uN = l.article.userName();

return generalNavLink({
url: 'http://ws.arin.net/cgi-bin/whois.pl?queryinput=' + encodeURIComponent(uN),
newWin: l.newWin,
title: tprintf('Look up %s in ARIN whois database', [uN]),
text: l.text,
noPopup: 1,
});
}

function toolDbName(cookieStyle) {
var ret = mw.config.get('wgDBname');
if (!cookieStyle) {
ret += '_p';
}
return ret;
}

function saneLinkCheck(l) {
if (typeof l.article != typeof {} || typeof l.text != typeof '') {
return false;
}
return true;
}
function editCounterLink(l) {
if (!saneLinkCheck(l)) {
return null;
}
if (!pg.wiki.wikimedia) {
return null;
}
var uN = l.article.userName();
var tool = getValueOf('popupEditCounterTool');
var url;
var defaultToolUrl = 'https://xtools.wmflabs.org/ec?user=$1&project=$2.$3&uselang=' + mw.config.get('wgUserLanguage');

switch (tool) {
case 'custom':
url = simplePrintf(getValueOf('popupEditCounterUrl'), [
encodeURIComponent(uN),
toolDbName(),
]);
break;
case 'soxred': // no longer available
case 'kate': // no longer available
case 'interiot': // no longer available
/* fall through */
case 'supercount':
default:
var theWiki = pg.wiki.hostname.split('.');
url = simplePrintf(defaultToolUrl, [encodeURIComponent(uN), theWiki[0], theWiki[1]]);
}
return generalNavLink({
url: url,
title: tprintf('editCounterLinkHint', [uN]),
newWin: l.newWin,
text: l.text,
noPopup: 1,
});
}

function globalSearchLink(l) {
if (!saneLinkCheck(l)) {
return null;
}

var base = 'https://global-search.toolforge.org/?uselang=' + mw.config.get('wgUserLanguage') + '&q=';
var article = l.article.urlString({ keepSpaces: true });

return generalNavLink({
url: base + article,
newWin: l.newWin,
title: tprintf('globalSearchHint', [safeDecodeURI(l.article)]),
text: l.text,
noPopup: 1,
});
}

function googleLink(l) {
if (!saneLinkCheck(l)) {
return null;
}

var base = 'https://www.google.com/search?q=';
var article = l.article.urlString({ keepSpaces: true });

return generalNavLink({
url: base + '%22' + article + '%22',
newWin: l.newWin,
title: tprintf('googleSearchHint', [safeDecodeURI(l.article)]),
text: l.text,
noPopup: 1,
});
}

function editorListLink(l) {
if (!saneLinkCheck(l)) {
return null;
}
var article = l.article.articleFromTalkPage() || l.article;
var url =
'https://xtools.wmflabs.org/articleinfo/' +
encodeURI(pg.wiki.hostname) +
'/' +
article.urlString() +
'?uselang=' +
mw.config.get('wgUserLanguage');
return generalNavLink({
url: url,
title: tprintf('editorListHint', [article]),
newWin: l.newWin,
text: l.text,
noPopup: 1,
});
}

function generalNavLink(l) {
l.className = l.className === null ? 'popupNavLink' : l.className;
return generalLink(l);
}

//////////////////////////////////////////////////
// magic history links
//

function getHistoryInfo(wikipage, whatNext) {
log('getHistoryInfo');
getHistory(
wikipage,
whatNext
? function (d) {
whatNext(processHistory(d));
}
: processHistory
);
}

// FIXME eliminate pg.idNumber ... how? :-(

function getHistory(wikipage, onComplete) {
log('getHistory');
var url =
pg.wiki.apiwikibase +
'?format=json&formatversion=2&action=query&prop=revisions&titles=' +
new Title(wikipage).urlString() +
'&rvlimit=' +
getValueOf('popupHistoryLimit');
log('getHistory: url=' + url);
return startDownload(url, pg.idNumber + 'history', onComplete);
}

function processHistory(download) {
var jsobj = getJsObj(download.data);
try {
var revisions = anyChild(jsobj.query.pages).revisions;
var edits = [];
for (var i = 0; i < revisions.length; ++i) {
edits.push({ oldid: revisions[i].revid, editor: revisions[i].user });
}
log('processed ' + edits.length + ' edits');
return finishProcessHistory(edits, mw.config.get('wgUserName'));
} catch (someError) {
log('Something went wrong with JSON business');
return finishProcessHistory([]);
}
}

function finishProcessHistory(edits, userName) {
var histInfo = {};

histInfo.edits = edits;
histInfo.userName = userName;

for (var i = 0; i < edits.length; ++i) {
if (typeof histInfo.myLastEdit === 'undefined' && userName && edits[i].editor == userName) {
histInfo.myLastEdit = {
index: i,
oldid: edits[i].oldid,
previd: i === 0 ? null : edits[i - 1].oldid,
};
}
if (typeof histInfo.firstNewEditor === 'undefined' && edits[i].editor != edits[0].editor) {
histInfo.firstNewEditor = {
index: i,
oldid: edits[i].oldid,
previd: i === 0 ? null : edits[i - 1].oldid,
};
}
}
//pg.misc.historyInfo=histInfo;
return histInfo;
}
// ENDFILE: links.js

// STARTFILE: options.js
//////////////////////////////////////////////////
// options

// check for existing value, else use default
function defaultize(x) {
if (pg.option[x] === null || typeof pg.option[x] == 'undefined') {
if (typeof window[x] != 'undefined') {
pg.option[x] = window[x];
} else {
pg.option[x] = pg.optionDefault[x];
}
}
}

function newOption(x, def) {
pg.optionDefault[x] = def;
}

function setDefault(x, def) {
return newOption(x, def);
}

function getValueOf(varName) {
defaultize(varName);
return pg.option[varName];
}

/*eslint-disable */
function useDefaultOptions() {
// for testing
for (var p in pg.optionDefault) {
pg.option[p] = pg.optionDefault[p];
if (typeof window[p] != 'undefined') {
delete window[p];
}
}
}
/*eslint-enable */

function setOptions() {
// user-settable parameters and defaults
var userIsSysop = false;
if (mw.config.get('wgUserGroups')) {
for (var g = 0; g < mw.config.get('wgUserGroups').length; ++g) {
if (mw.config.get('wgUserGroups')[g] == 'sysop') {
userIsSysop = true;
}
}
}

// Basic options
newOption('popupDelay', 0.5);
newOption('popupHideDelay', 0.5);
newOption('simplePopups', false);
newOption('popupStructure', 'shortmenus'); // see later - default for popupStructure is 'original' if simplePopups is true
newOption('popupActionsMenu', true);
newOption('popupSetupMenu', true);
newOption('popupAdminLinks', userIsSysop);
newOption('popupShortcutKeys', false);
newOption('popupHistoricalLinks', true);
newOption('popupOnlyArticleLinks', true);
newOption('removeTitles', true);
newOption('popupMaxWidth', 350);
newOption('popupSimplifyMainLink', true);
newOption('popupAppendRedirNavLinks', true);
newOption('popupTocLinks', false);
newOption('popupSubpopups', true);
newOption('popupDragHandle', false /* 'popupTopLinks'*/);
newOption('popupLazyPreviews', true);
newOption('popupLazyDownloads', true);
newOption('popupAllDabsStubs', false);
newOption('popupDebugging', false);
newOption('popupActiveNavlinks', true);
newOption('popupModifier', false); // ctrl, shift, alt or meta
newOption('popupModifierAction', 'enable'); // or 'disable'
newOption('popupDraggable', true);
newOption('popupReview', false);
newOption('popupLocale', false);
newOption('popupDateTimeFormatterOptions', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour12: false,
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
});
newOption('popupDateFormatterOptions', {
year: 'numeric',
month: 'long',
day: 'numeric',
});
newOption('popupTimeFormatterOptions', {
hour12: false,
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
});

// images
newOption('popupImages', true);
newOption('imagePopupsForImages', true);
newOption('popupNeverGetThumbs', false);
//newOption('popupImagesToggleSize', true);
newOption('popupThumbAction', 'imagepage'); //'sizetoggle');
newOption('popupImageSize', 60);
newOption('popupImageSizeLarge', 200);

// redirs, dabs, reversion
newOption('popupFixRedirs', false);
newOption('popupRedirAutoClick', 'wpDiff');
newOption('popupFixDabs', false);
newOption('popupDabsAutoClick', 'wpDiff');
newOption('popupRevertSummaryPrompt', false);
newOption('popupMinorReverts', false);
newOption('popupRedlinkRemoval', false);
newOption('popupRedlinkAutoClick', 'wpDiff');
newOption('popupWatchDisambiggedPages', null);
newOption('popupWatchRedirredPages', null);
newOption('popupDabWiktionary', 'last');

// navlinks
newOption('popupNavLinks', true);
newOption('popupNavLinkSeparator', ' &sdot; ');
newOption('popupLastEditLink', true);
newOption('popupEditCounterTool', 'supercount');
newOption('popupEditCounterUrl', '');

// previews etc
newOption('popupPreviews', true);
newOption('popupSummaryData', true);
newOption('popupMaxPreviewSentences', 5);
newOption('popupMaxPreviewCharacters', 600);
newOption('popupLastModified', true);
newOption('popupPreviewKillTemplates', true);
newOption('popupPreviewRawTemplates', true);
newOption('popupPreviewFirstParOnly', true);
newOption('popupPreviewCutHeadings', true);
newOption('popupPreviewButton', false);
newOption('popupPreviewButtonEvent', 'click');

// diffs
newOption('popupPreviewDiffs', true);
newOption('popupDiffMaxLines', 100);
newOption('popupDiffContextLines', 2);
newOption('popupDiffContextCharacters', 40);
newOption('popupDiffDates', true);
newOption('popupDiffDatePrinter', 'toLocaleString'); // no longer in use

// edit summaries. God, these are ugly.
newOption('popupReviewedSummary', popupString('defaultpopupReviewedSummary'));
newOption('popupFixDabsSummary', popupString('defaultpopupFixDabsSummary'));
newOption('popupExtendedRevertSummary', popupString('defaultpopupExtendedRevertSummary'));
newOption('popupRevertSummary', popupString('defaultpopupRevertSummary'));
newOption('popupRevertToPreviousSummary', popupString('defaultpopupRevertToPreviousSummary'));
newOption('popupQueriedRevertSummary', popupString('defaultpopupQueriedRevertSummary'));
newOption(
'popupQueriedRevertToPreviousSummary',
popupString('defaultpopupQueriedRevertToPreviousSummary')
);
newOption('popupFixRedirsSummary', popupString('defaultpopupFixRedirsSummary'));
newOption('popupRedlinkSummary', popupString('defaultpopupRedlinkSummary'));
newOption('popupRmDabLinkSummary', popupString('defaultpopupRmDabLinkSummary'));
// misc
newOption('popupHistoryLimit', 50);
newOption('popupFilters', [
popupFilterStubDetect,
popupFilterDisambigDetect,
popupFilterPageSize,
popupFilterCountLinks,
popupFilterCountImages,
popupFilterCountCategories,
popupFilterLastModified,
popupFilterWikibaseItem,
]);
newOption('extraPopupFilters', []);
newOption('popupOnEditSelection', 'cursor');
newOption('popupPreviewHistory', true);
newOption('popupImageLinks', true);
newOption('popupCategoryMembers', true);
newOption('popupUserInfo', true);
newOption('popupHistoryPreviewLimit', 25);
newOption('popupContribsPreviewLimit', 25);
newOption('popupRevDelUrl', '//en.wikipedia.org/wiki/Wikipedia:Revision_deletion');
newOption('popupShowGender', true);

// new windows
newOption('popupNewWindows', false);
newOption('popupLinksNewWindow', { lastContrib: true, sinceMe: true });

// regexps
newOption(
'popupDabRegexp',
'disambiguation\\}\\}|\\{\\{\\s*(d(ab|isamb(ig(uation)?)?)|(((geo|hn|road?|school|number)dis)|[234][lc][acw]|(road|ship)index))\\s*(\\|[^}]*)?\\}\\}|is a .*disambiguation.*page'
);
newOption('popupAnchorRegexp', 'anchors?'); //how to identify an anchors template
newOption('popupStubRegexp', '(sect)?stub[}][}]|This .*-related article is a .*stub');
newOption(
'popupImageVarsRegexp',
'image|image_(?:file|skyline|name|flag|seal)|cover|badge|logo'
);
}
// ENDFILE: options.js

// STARTFILE: strings.js
//////////////////////////////////////////////////
// Translatable strings
//////////////////////////////////////////////////
//
// See instructions at
// https://en.wikipedia.org/wiki/Wikipedia:Tools/Navigation_popups/Translation

pg.string = {
/////////////////////////////////////
// summary data, searching etc.
/////////////////////////////////////
article: 'article',
category: 'category',
categories: 'categories',
image: 'image',
images: 'images',
stub: 'stub',
'section stub': 'section stub',
'Empty page': 'Empty page',
kB: 'kB',
bytes: 'bytes',
day: 'day',
days: 'days',
hour: 'hour',
hours: 'hours',
minute: 'minute',
minutes: 'minutes',
second: 'second',
seconds: 'seconds',
week: 'week',
weeks: 'weeks',
search: 'search',
SearchHint: 'Find English Wikipedia articles containing %s',
web: 'web',
global: 'global',
globalSearchHint: 'Search across Wikipedias in different languages for %s',
googleSearchHint: 'Google for %s',
/////////////////////////////////////
// article-related actions and info
// (some actions also apply to user pages)
/////////////////////////////////////
actions: 'actions', ///// view articles and view talk
popupsMenu: 'popups',
togglePreviewsHint: 'Toggle preview generation in popups on this page',
'enable previews': 'enable previews',
'disable previews': 'disable previews',
'toggle previews': 'toggle previews',
'show preview': 'show preview',
reset: 'reset',
'more...': 'more...',
disable: 'disable popups',
disablePopupsHint: 'Disable popups on this page. Reload page to re-enable.',
historyfeedHint: 'RSS feed of recent changes to this page',
purgePopupsHint: 'Reset popups, clearing all cached popup data.',
PopupsHint: 'Reset popups, clearing all cached popup data.',
spacebar: 'space',
view: 'view',
'view article': 'view article',
viewHint: 'Go to %s',
talk: 'talk',
'talk page': 'talk page',
'this&nbsp;revision': 'this&nbsp;revision',
'revision %s of %s': 'revision %s of %s',
'Revision %s of %s': 'Revision %s of %s',
'the revision prior to revision %s of %s': 'the revision prior to revision %s of %s',
'Toggle image size': 'Click to toggle image size',
del: 'del', ///// delete, protect, move
delete: 'delete',
deleteHint: 'Delete %s',
undeleteShort: 'un',
UndeleteHint: 'Show the deletion history for %s',
protect: 'protect',
protectHint: 'Restrict editing rights to %s',
unprotectShort: 'un',
unprotectHint: 'Allow %s to be edited by anyone again',
'send thanks': 'send thanks',
ThanksHint: 'Send a thank you notification to this user',
move: 'move',
'move page': 'move page',
MovepageHint: 'Change the title of %s',
edit: 'edit', ///// edit articles and talk
'edit article': 'edit article',
editHint: 'Change the content of %s',
'edit talk': 'edit talk',
new: 'new',
'new topic': 'new topic',
newSectionHint: 'Start a new section on %s',
'null edit': 'null edit',
nullEditHint: 'Submit an edit to %s, making no changes ',
hist: 'hist', ///// history, diffs, editors, related
history: 'history',
historyHint: 'List the changes made to %s',
last: 'prev', // For labelling the previous revision in history pages; the key is "last" for backwards compatibility
lastEdit: 'lastEdit',
'mark patrolled': 'mark patrolled',
markpatrolledHint: 'Mark this edit as patrolled',
'Could not marked this edit as patrolled': 'Could not marked this edit as patrolled',
'show last edit': 'most recent edit',
'Show the last edit': 'Show the effects of the most recent change',
lastContrib: 'lastContrib',
'last set of edits': 'latest edits',
lastContribHint: 'Show the net effect of changes made by the last editor',
cur: 'cur',
diffCur: 'diffCur',
'Show changes since revision %s': 'Show changes since revision %s',
'%s old': '%s old', // as in 4 weeks old
oldEdit: 'oldEdit',
purge: 'purge',
purgeHint: 'Demand a fresh copy of %s',
raw: 'source',
rawHint: 'Download the source of %s',
render: 'simple',
renderHint: 'Show a plain HTML version of %s',
'Show the edit made to get revision': 'Show the edit made to get revision',
sinceMe: 'sinceMe',
'changes since mine': 'diff my edit',
sinceMeHint: 'Show changes since my last edit',
"Couldn't find an edit by %s\nin the last %s edits to\n%s":
"Couldn't find an edit by %s\nin the last %s edits to\n%s",
eds: 'eds',
editors: 'editors',
editorListHint: 'List the users who have edited %s',
related: 'related',
relatedChanges: 'relatedChanges',
'related changes': 'related changes',
RecentchangeslinkedHint: 'Show changes in articles related to %s',
editOld: 'editOld', ///// edit old version, or revert
rv: 'rv',
revert: 'revert',
revertHint: 'Revert to %s',
defaultpopupReviewedSummary:
'Accepted by reviewing the [[Special:diff/%s/%s|difference]] between this version and previously accepted version using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
defaultpopupRedlinkSummary:
'Removing link to empty page [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
defaultpopupFixDabsSummary:
'Disambiguate [[%s]] to [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
defaultpopupFixRedirsSummary:
'Redirect bypass from [[%s]] to [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
defaultpopupExtendedRevertSummary:
'Revert to revision dated %s by %s, oldid %s using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
defaultpopupRevertToPreviousSummary:
'Revert to the revision prior to revision %s using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
defaultpopupRevertSummary:
'Revert to revision %s using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
defaultpopupQueriedRevertToPreviousSummary:
'Revert to the revision prior to revision $1 dated $2 by $3 using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
defaultpopupQueriedRevertSummary:
'Revert to revision $1 dated $2 by $3 using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
defaultpopupRmDabLinkSummary:
'Remove link to dab page [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
Redirects: 'Redirects', // as in Redirects to ...
' to ': ' to ', // as in Redirects to ...
'Bypass redirect': 'Bypass redirect',
'Fix this redirect': 'Fix this redirect',
disambig: 'disambig', ///// add or remove dab etc.
disambigHint: 'Disambiguate this link to [[%s]]',
'Click to disambiguate this link to:': 'Click to disambiguate this link to:',
'remove this link': 'remove this link',
'remove all links to this page from this article':
'remove all links to this page from this article',
'remove all links to this disambig page from this article':
'remove all links to this disambig page from this article',
mainlink: 'mainlink', ///// links, watch, unwatch
wikiLink: 'wikiLink',
wikiLinks: 'wikiLinks',
'links here': 'links here',
whatLinksHere: 'whatLinksHere',
'what links here': 'what links here',
WhatlinkshereHint: 'List the pages that are hyperlinked to %s',
unwatchShort: 'un',
watchThingy: 'watch', // called watchThingy because {}.watch is a function
watchHint: 'Add %s to my watchlist',
unwatchHint: 'Remove %s from my watchlist',
'Only found one editor: %s made %s edits': 'Only found one editor: %s made %s edits',
'%s seems to be the last editor to the page %s':
'%s seems to be the last editor to the page %s',
rss: 'rss',
/////////////////////////////////////
// diff previews
/////////////////////////////////////
'Diff truncated for performance reasons': 'Diff truncated for performance reasons',
'Old revision': 'Old revision',
'New revision': 'New revision',
'Something went wrong :-(': 'Something went wrong :-(',
'Empty revision, maybe non-existent': 'Empty revision, maybe non-existent',
'Unknown date': 'Unknown date',
/////////////////////////////////////
// other special previews
/////////////////////////////////////
'Empty category': 'Empty category',
'Category members (%s shown)': 'Category members (%s shown)',
'No image links found': 'No image links found',
'File links': 'File links',
'No image found': 'No image found',
'Image from Commons': 'Image from Commons',
'Description page': 'Description page',
'Alt text:': 'Alt text:',
revdel: 'Hidden revision',
/////////////////////////////////////
// user-related actions and info
/////////////////////////////////////
user: 'user', ///// user page, talk, email, space
'user&nbsp;page': 'user&nbsp;page',
'user talk': 'user talk',
'edit user talk': 'edit user talk',
'leave comment': 'leave comment',
email: 'email',
'email user': 'email user',
EmailuserHint: 'Send an email to %s',
space: 'space', // short form for userSpace link
PrefixIndexHint: 'Show pages in the userspace of %s',
count: 'count', ///// contributions, log
'edit counter': 'edit counter',
editCounterLinkHint: 'Count the contributions made by %s',
contribs: 'contribs',
contributions: 'contributions',
deletedContribs: 'deleted contributions',
DeletedcontributionsHint: 'List deleted edits made by %s',
ContributionsHint: 'List the contributions made by %s',
log: 'log',
'user log': 'user log',
userLogHint: "Show %s's user log",
arin: 'ARIN lookup', ///// ARIN lookup, block user or IP
'Look up %s in ARIN whois database': 'Look up %s in the ARIN whois database',
unblockShort: 'un',
block: 'block',
'block user': 'block user',
IpblocklistHint: 'Unblock %s',
BlockipHint: 'Prevent %s from editing',
'block log': 'block log',
blockLogHint: 'Show the block log for %s',
protectLogHint: 'Show the protection log for %s',
pageLogHint: 'Show the page log for %s',
deleteLogHint: 'Show the deletion log for %s',
'Invalid %s %s': 'The option %s is invalid: %s',
'No backlinks found': 'No backlinks found',
' and more': ' and more',
undo: 'undo',
undoHint: 'undo this edit',
'Download preview data': 'Download preview data',
'Invalid or IP user': 'Invalid or IP user',
'Not a registered username': 'Not a registered username',
BLOCKED: 'BLOCKED',
'Has blocks': 'Has blocks',
' edits since: ': ' edits since: ',
'last edit on ': 'last edit on ',
'he/him': 'he/him',
'she/her': 'she/her',
/////////////////////////////////////
// Autoediting
/////////////////////////////////////
'Enter a non-empty edit summary or press cancel to abort':
'Enter a non-empty edit summary or press cancel to abort',
'Failed to get revision information, please edit manually.\n\n':
'Failed to get revision information, please edit manually.\n\n',
'The %s button has been automatically clicked. Please wait for the next page to load.':
'The %s button has been automatically clicked. Please wait for the next page to load.',
'Could not find button %s. Please check the settings in your javascript file.':
'Could not find button %s. Please check the settings in your javascript file.',
/////////////////////////////////////
// Popups setup
/////////////////////////////////////
'Open full-size image': 'Open full-size image',
zxy: 'zxy',
autoedit_version: 'np20140416',
};

function popupString(str) {
if (typeof popupStrings != 'undefined' && popupStrings && popupStrings[str]) {
return popupStrings[str];
}
if (pg.string[str]) {
return pg.string[str];
}
return str;
}

function tprintf(str, subs) {
if (typeof subs != typeof []) {
subs = [subs];
}
return simplePrintf(popupString(str), subs);
}

// ENDFILE: strings.js

// STARTFILE: run.js
////////////////////////////////////////////////////////////////////
// Run things
////////////////////////////////////////////////////////////////////

// For some reason popups requires a fully loaded page jQuery.ready(...) causes problems for some.
// The old addOnloadHook did something similar to the below
if (document.readyState == 'complete') {
autoEdit();
}
//will setup popups
else {
$(window).on('load', autoEdit);
}

// Support for MediaWiki's live preview, VisualEditor's saves and Echo's flyout.
(function () {
var once = true;
function dynamicContentHandler($content) {
// Try to detect the hook fired on initial page load and disregard
// it, we already hook to onload (possibly to different parts of
// page - it's configurable) and running twice might be bad. Ugly…
if ($content.attr('id') == 'mw-content-text') {
if (once) {
once = false;
return;
}
}

function registerHooksForVisibleNavpops() {
for (var i = 0; pg.current.links && i < pg.current.links.length; ++i) {
var navpop = pg.current.links[i].navpopup;
if (!navpop || !navpop.isVisible()) {
continue;
}

Navpopup.tracker.addHook(posCheckerHook(navpop));
}
}

function doIt() {
registerHooksForVisibleNavpops();
$content.each(function () {
this.ranSetupTooltipsAlready = false;
setupTooltips(this);
});
}

setupPopups(doIt);
}

// This hook is also fired after page load.
mw.hook('wikipage.content').add(dynamicContentHandler);

mw.hook('ext.echo.overlay.beforeShowingOverlay').add(function ($overlay) {
dynamicContentHandler($overlay.find('.mw-echo-state'));
});
})();
});
});

Revision as of 23:42, 15 December 2023

/*https://en.wikipedia.org/wiki/Wikipedia:Tools/Navigation_popups*/
$(function () {
	//////////////////////////////////////////////////
	// Globals
	//

	// Trying to shove as many of these as possible into the pg (popup globals) object
	var pg = {
		api: {}, // MediaWiki API requests
		re: {}, // regexps
		ns: {}, // namespaces
		string: {}, // translatable strings
		wiki: {}, // local site info
		user: {}, // current user info
		misc: {}, // YUCK PHOOEY
		option: {}, // options, see newOption etc
		optionDefault: {}, // default option values
		flag: {}, // misc flags
		cache: {}, // page and image cache
		structures: {}, // navlink structures
		timer: {}, // all sorts of timers (too damn many)
		counter: {}, // .. and all sorts of counters
		current: {}, // state info
		fn: {}, // functions
		endoflist: null,
	};

	/* Bail if the gadget/script is being loaded twice */
	/* An element with id "pg" would add a window.pg property, ignore such property */
	if (window.pg && !(window.pg instanceof HTMLElement)) {
		return;
	}

	/* Export to global context */
	window.pg = pg;

	/// Local Variables: ///
	/// mode:c ///
	/// End: ///
	// ENDFILE: main.js

	// STARTFILE: actions.js
	function setupTooltips(container, remove, force, popData) {
		log('setupTooltips, container=' + container + ', remove=' + remove);
		if (!container) {
			// the main initial call
			if (
				getValueOf('popupOnEditSelection') &&
				document &&
				document.editform &&
				document.editform.wpTextbox1
			) {
				document.editform.wpTextbox1.onmouseup = doSelectionPopup;
			}
			// article/content is a structure-dependent thing
			container = defaultPopupsContainer();
		}

		if (!remove && !force && container.ranSetupTooltipsAlready) {
			return;
		}
		container.ranSetupTooltipsAlready = !remove;

		var anchors;
		anchors = container.getElementsByTagName('A');
		setupTooltipsLoop(anchors, 0, 250, 100, remove, popData);
	}

	function defaultPopupsContainer() {
		if (getValueOf('popupOnlyArticleLinks')) {
			return (
				document.querySelector('.skin-vector-2022 .vector-body') ||
				document.getElementById('mw_content') ||
				document.getElementById('content') ||
				document.getElementById('article') ||
				document
			);
		}
		return document;
	}

	function setupTooltipsLoop(anchors, begin, howmany, sleep, remove, popData) {
		log(simplePrintf('setupTooltipsLoop(%s,%s,%s,%s,%s)', arguments));
		var finish = begin + howmany;
		var loopend = Math.min(finish, anchors.length);
		var j = loopend - begin;
		log(
			'setupTooltips: anchors.length=' +
				anchors.length +
				', begin=' +
				begin +
				', howmany=' +
				howmany +
				', loopend=' +
				loopend +
				', remove=' +
				remove
		);
		var doTooltip = remove ? removeTooltip : addTooltip;
		// try a faster (?) loop construct
		if (j > 0) {
			do {
				var a = anchors[loopend - j];
				if (typeof a === 'undefined' || !a || !a.href) {
					log('got null anchor at index ' + loopend - j);
					continue;
				}
				doTooltip(a, popData);
			} while (--j);
		}
		if (finish < anchors.length) {
			setTimeout(function () {
				setupTooltipsLoop(anchors, finish, howmany, sleep, remove, popData);
			}, sleep);
		} else {
			if (!remove && !getValueOf('popupTocLinks')) {
				rmTocTooltips();
			}
			pg.flag.finishedLoading = true;
		}
	}

	// eliminate popups from the TOC
	// This also kills any onclick stuff that used to be going on in the toc
	function rmTocTooltips() {
		var toc = document.getElementById('toc');
		if (toc) {
			var tocLinks = toc.getElementsByTagName('A');
			var tocLen = tocLinks.length;
			for (var j = 0; j < tocLen; ++j) {
				removeTooltip(tocLinks[j], true);
			}
		}
	}

	function addTooltip(a, popData) {
		if (!isPopupLink(a)) {
			return;
		}
		a.onmouseover = mouseOverWikiLink;
		a.onmouseout = mouseOutWikiLink;
		a.onmousedown = killPopup;
		a.hasPopup = true;
		a.popData = popData;
	}

	function removeTooltip(a) {
		if (!a.hasPopup) {
			return;
		}
		a.onmouseover = null;
		a.onmouseout = null;
		if (a.originalTitle) {
			a.title = a.originalTitle;
		}
		a.hasPopup = false;
	}

	function removeTitle(a) {
		if (!a.originalTitle) {
			a.originalTitle = a.title;
		}
		a.title = '';
	}

	function restoreTitle(a) {
		if (a.title || !a.originalTitle) {
			return;
		}
		a.title = a.originalTitle;
	}

	function registerHooks(np) {
		var popupMaxWidth = getValueOf('popupMaxWidth');

		if (typeof popupMaxWidth === 'number') {
			var setMaxWidth = function () {
				np.mainDiv.style.maxWidth = popupMaxWidth + 'px';
				np.maxWidth = popupMaxWidth;
			};
			np.addHook(setMaxWidth, 'unhide', 'before');
		}
		np.addHook(addPopupShortcuts, 'unhide', 'after');
		np.addHook(rmPopupShortcuts, 'hide', 'before');
	}

	function removeModifierKeyHandler(a) {
		//remove listeners for modifier key if any that were added in mouseOverWikiLink
		document.removeEventListener('keydown', a.modifierKeyHandler, false);
		document.removeEventListener('keyup', a.modifierKeyHandler, false);
	}

	function mouseOverWikiLink(evt) {
		if (!evt && window.event) {
			evt = window.event;
		}

		// if the modifier is needed, listen for it,
		// we will remove the listener when we mouseout of this link or kill popup.
		if (getValueOf('popupModifier')) {
			// if popupModifierAction = enable, we should popup when the modifier is pressed
			// if popupModifierAction = disable, we should popup unless the modifier is pressed
			var action = getValueOf('popupModifierAction');
			var key = action == 'disable' ? 'keyup' : 'keydown';
			var a = this;
			a.modifierKeyHandler = function (evt) {
				mouseOverWikiLink2(a, evt);
			};
			document.addEventListener(key, a.modifierKeyHandler, false);
		}

		return mouseOverWikiLink2(this, evt);
	}

	/**
	 * Gets the references list item that the provided footnote link targets. This
	 * is typically a li element within the ol.references element inside the reflist.
	 * @param {Element} a - A footnote link.
	 * @returns {Element|boolean} The targeted element, or false if one can't be found.
	 */
	function footnoteTarget(a) {
		var aTitle = Title.fromAnchor(a);
		// We want ".3A" rather than "%3A" or "?" here, so use the anchor property directly
		var anch = aTitle.anchor;
		if (!/^(cite_note-|_note-|endnote)/.test(anch)) {
			return false;
		}

		var lTitle = Title.fromURL(location.href);
		if (lTitle.toString(true) !== aTitle.toString(true)) {
			return false;
		}

		var el = document.getElementById(anch);
		while (el && typeof el.nodeName === 'string') {
			var nt = el.nodeName.toLowerCase();
			if (nt === 'li') {
				return el;
			} else if (nt === 'body') {
				return false;
			} else if (el.parentNode) {
				el = el.parentNode;
			} else {
				return false;
			}
		}
		return false;
	}

	function footnotePreview(x, navpop) {
		setPopupHTML('<hr />' + x.innerHTML, 'popupPreview', navpop.idNumber);
	}

	function modifierPressed(evt) {
		var mod = getValueOf('popupModifier');
		if (!mod) {
			return false;
		}

		if (!evt && window.event) {
			evt = window.event;
		}

		return evt && mod && evt[mod.toLowerCase() + 'Key'];
	}

	// Checks if the correct modifier pressed/unpressed if needed
	function isCorrectModifier(a, evt) {
		if (!getValueOf('popupModifier')) {
			return true;
		}
		// if popupModifierAction = enable, we should popup when the modifier is pressed
		// if popupModifierAction = disable, we should popup unless the modifier is pressed
		var action = getValueOf('popupModifierAction');
		return (
			(action == 'enable' && modifierPressed(evt)) || (action == 'disable' && !modifierPressed(evt))
		);
	}

	function mouseOverWikiLink2(a, evt) {
		if (!isCorrectModifier(a, evt)) {
			return;
		}
		if (getValueOf('removeTitles')) {
			removeTitle(a);
		}
		if (a == pg.current.link && a.navpopup && a.navpopup.isVisible()) {
			return;
		}
		pg.current.link = a;

		if (getValueOf('simplePopups') && !pg.option.popupStructure) {
			// reset *default value* of popupStructure
			setDefault('popupStructure', 'original');
		}

		var article = new Title().fromAnchor(a);
		// set global variable (ugh) to hold article (wikipage)
		pg.current.article = article;

		if (!a.navpopup) {
			a.navpopup = newNavpopup(a, article);
			pg.current.linksHash[a.href] = a.navpopup;
			pg.current.links.push(a);
		}
		if (a.navpopup.pending === null || a.navpopup.pending !== 0) {
			// either fresh popups or those with unfinshed business are redone from scratch
			simplePopupContent(a, article);
		}
		a.navpopup.showSoonIfStable(a.navpopup.delay);

		clearInterval(pg.timer.checkPopupPosition);
		pg.timer.checkPopupPosition = setInterval(checkPopupPosition, 600);

		if (getValueOf('simplePopups')) {
			if (getValueOf('popupPreviewButton') && !a.simpleNoMore) {
				var d = document.createElement('div');
				d.className = 'popupPreviewButtonDiv';
				var s = document.createElement('span');
				d.appendChild(s);
				s.className = 'popupPreviewButton';
				s['on' + getValueOf('popupPreviewButtonEvent')] = function () {
					a.simpleNoMore = true;
					d.style.display = 'none';
					nonsimplePopupContent(a, article);
				};
				s.innerHTML = popupString('show preview');
				setPopupHTML(d, 'popupPreview', a.navpopup.idNumber);
			}
		}

		if (a.navpopup.pending !== 0) {
			nonsimplePopupContent(a, article);
		}
	}

	// simplePopupContent: the content that do not require additional download
	// (it is shown even when simplePopups is true)
	function simplePopupContent(a, article) {
		/* FIXME hack */ a.navpopup.hasPopupMenu = false;
		a.navpopup.setInnerHTML(popupHTML(a));
		fillEmptySpans({ navpopup: a.navpopup });

		if (getValueOf('popupDraggable')) {
			var dragHandle = getValueOf('popupDragHandle') || null;
			if (dragHandle && dragHandle != 'all') {
				dragHandle += a.navpopup.idNumber;
			}
			setTimeout(function () {
				a.navpopup.makeDraggable(dragHandle);
			}, 150);
		}

		if (getValueOf('popupRedlinkRemoval') && a.className == 'new') {
			setPopupHTML('<br>' + popupRedlinkHTML(article), 'popupRedlink', a.navpopup.idNumber);
		}
	}

	function debugData(navpopup) {
		if (getValueOf('popupDebugging') && navpopup.idNumber) {
			setPopupHTML(
				'idNumber=' + navpopup.idNumber + ', pending=' + navpopup.pending,
				'popupError',
				navpopup.idNumber
			);
		}
	}

	function newNavpopup(a, article) {
		var navpopup = new Navpopup();
		navpopup.fuzz = 5;
		navpopup.delay = getValueOf('popupDelay') * 1000;
		// increment global counter now
		navpopup.idNumber = ++pg.idNumber;
		navpopup.parentAnchor = a;
		navpopup.parentPopup = a.popData && a.popData.owner;
		navpopup.article = article;
		registerHooks(navpopup);
		return navpopup;
	}

	// Should we show nonsimple context?
	// If simplePopups is set to true, then we do not show nonsimple context,
	// but if a bottom "show preview" was clicked we do show nonsimple context
	function shouldShowNonSimple(a) {
		return !getValueOf('simplePopups') || a.simpleNoMore;
	}

	// Should we show nonsimple context govern by the option (e.g. popupUserInfo)?
	// If the user explicitly asked for nonsimple context by setting the option to true,
	// then we show it even in nonsimple mode.
	function shouldShow(a, option) {
		if (shouldShowNonSimple(a)) {
			return getValueOf(option);
		} else {
			return typeof window[option] != 'undefined' && window[option];
		}
	}

	function nonsimplePopupContent(a, article) {
		var diff = null,
			history = null;
		var params = parseParams(a.href);
		var oldid = typeof params.oldid == 'undefined' ? null : params.oldid;
		if (shouldShow(a, 'popupPreviewDiffs')) {
			diff = params.diff;
		}
		if (shouldShow(a, 'popupPreviewHistory')) {
			history = params.action == 'history';
		}
		a.navpopup.pending = 0;
		var referenceElement = footnoteTarget(a);
		if (referenceElement) {
			footnotePreview(referenceElement, a.navpopup);
		} else if (diff || diff === 0) {
			loadDiff(article, oldid, diff, a.navpopup);
		} else if (history) {
			loadAPIPreview('history', article, a.navpopup);
		} else if (shouldShowNonSimple(a) && pg.re.contribs.test(a.href)) {
			loadAPIPreview('contribs', article, a.navpopup);
		} else if (shouldShowNonSimple(a) && pg.re.backlinks.test(a.href)) {
			loadAPIPreview('backlinks', article, a.navpopup);
		} else if (
			// FIXME should be able to get all preview combinations with options
			article.namespaceId() == pg.nsImageId &&
			(shouldShow(a, 'imagePopupsForImages') || !anchorContainsImage(a))
		) {
			loadAPIPreview('imagepagepreview', article, a.navpopup);
			loadImage(article, a.navpopup);
		} else {
			if (article.namespaceId() == pg.nsCategoryId && shouldShow(a, 'popupCategoryMembers')) {
				loadAPIPreview('category', article, a.navpopup);
			} else if (
				(article.namespaceId() == pg.nsUserId || article.namespaceId() == pg.nsUsertalkId) &&
				shouldShow(a, 'popupUserInfo')
			) {
				loadAPIPreview('userinfo', article, a.navpopup);
			}
			if (shouldShowNonSimple(a)) {
				startArticlePreview(article, oldid, a.navpopup);
			}
		}
	}

	function pendingNavpopTask(navpop) {
		if (navpop && navpop.pending === null) {
			navpop.pending = 0;
		}
		++navpop.pending;
		debugData(navpop);
	}

	function completedNavpopTask(navpop) {
		if (navpop && navpop.pending) {
			--navpop.pending;
		}
		debugData(navpop);
	}

	function startArticlePreview(article, oldid, navpop) {
		navpop.redir = 0;
		loadPreview(article, oldid, navpop);
	}

	function loadPreview(article, oldid, navpop) {
		if (!navpop.redir) {
			navpop.originalArticle = article;
		}
		article.oldid = oldid;
		loadAPIPreview('revision', article, navpop);
	}

	function loadPreviewFromRedir(redirMatch, navpop) {
		// redirMatch is a regex match
		var target = new Title().fromWikiText(redirMatch[2]);
		// overwrite (or add) anchor from original target
		// mediawiki does overwrite; eg [[User:Lupin/foo3#Done]]
		if (navpop.article.anchor) {
			target.anchor = navpop.article.anchor;
		}
		navpop.redir++;
		navpop.redirTarget = target;
		var warnRedir = redirLink(target, navpop.article);
		setPopupHTML(warnRedir, 'popupWarnRedir', navpop.idNumber);
		navpop.article = target;
		fillEmptySpans({ redir: true, redirTarget: target, navpopup: navpop });
		return loadPreview(target, null, navpop);
	}

	function insertPreview(download) {
		if (!download.owner) {
			return;
		}

		var redirMatch = pg.re.redirect.exec(download.data);
		if (download.owner.redir === 0 && redirMatch) {
			loadPreviewFromRedir(redirMatch, download.owner);
			return;
		}

		if (download.owner.visible || !getValueOf('popupLazyPreviews')) {
			insertPreviewNow(download);
		} else {
			var id = download.owner.redir ? 'PREVIEW_REDIR_HOOK' : 'PREVIEW_HOOK';
			download.owner.addHook(
				function () {
					insertPreviewNow(download);
					return true;
				},
				'unhide',
				'after',
				id
			);
		}
	}

	function insertPreviewNow(download) {
		if (!download.owner) {
			return;
		}
		var wikiText = download.data;
		var navpop = download.owner;
		var art = navpop.redirTarget || navpop.originalArticle;

		makeFixDabs(wikiText, navpop);
		if (getValueOf('popupSummaryData')) {
			getPageInfo(wikiText, download);
			setPopupTrailer(getPageInfo(wikiText, download), navpop.idNumber);
		}

		var imagePage = '';
		if (art.namespaceId() == pg.nsImageId) {
			imagePage = art.toString();
		} else {
			imagePage = getValidImageFromWikiText(wikiText);
		}
		if (imagePage) {
			loadImage(Title.fromWikiText(imagePage), navpop);
		}

		if (getValueOf('popupPreviews')) {
			insertArticlePreview(download, art, navpop);
		}
	}

	function insertArticlePreview(download, art, navpop) {
		if (download && typeof download.data == typeof '') {
			if (art.namespaceId() == pg.nsTemplateId && getValueOf('popupPreviewRawTemplates')) {
				// FIXME compare/consolidate with diff escaping code for wikitext
				var h =
					'<hr /><span style="font-family: monospace;">' +
					download.data.entify().split('\\n').join('<br />\\n') +
					'</span>';
				setPopupHTML(h, 'popupPreview', navpop.idNumber);
			} else {
				var p = prepPreviewmaker(download.data, art, navpop);
				p.showPreview();
			}
		}
	}

	function prepPreviewmaker(data, article, navpop) {
		// deal with tricksy anchors
		var d = anchorize(data, article.anchorString());
		var urlBase = joinPath([pg.wiki.articlebase, article.urlString()]);
		var p = new Previewmaker(d, urlBase, navpop);
		return p;
	}

	// Try to imitate the way mediawiki generates HTML anchors from section titles
	function anchorize(d, anch) {
		if (!anch) {
			return d;
		}
		var anchRe = RegExp(
			'(?:=+\\s*' +
				literalizeRegex(anch).replace(/[_ ]/g, '[_ ]') +
				'\\s*=+|\\{\\{\\s*' +
				getValueOf('popupAnchorRegexp') +
				'\\s*(?:\\|[^|}]*)*?\\s*' +
				literalizeRegex(anch) +
				'\\s*(?:\\|[^}]*)?}})'
		);
		var match = d.match(anchRe);
		if (match && match.length > 0 && match[0]) {
			return d.substring(d.indexOf(match[0]));
		}

		// now try to deal with == foo [[bar|baz]] boom == -> #foo_baz_boom
		var lines = d.split('\n');
		for (var i = 0; i < lines.length; ++i) {
			lines[i] = lines[i]
				.replace(RegExp('[[]{2}([^|\\]]*?[|])?(.*?)[\\]]{2}', 'g'), '$2')
				.replace(/'''([^'])/g, '$1')
				.replace(RegExp("''([^'])", 'g'), '$1');
			if (lines[i].match(anchRe)) {
				return d.split('\n').slice(i).join('\n').replace(RegExp('^[^=]*'), '');
			}
		}
		return d;
	}

	function killPopup() {
		removeModifierKeyHandler(this);
		if (getValueOf('popupShortcutKeys')) {
			rmPopupShortcuts();
		}
		if (!pg) {
			return;
		}
		if (pg.current.link && pg.current.link.navpopup) {
			pg.current.link.navpopup.banish();
		}
		pg.current.link = null;
		abortAllDownloads();
		if (pg.timer.checkPopupPosition) {
			clearInterval(pg.timer.checkPopupPosition);
			pg.timer.checkPopupPosition = null;
		}
		return true; // preserve default action
	}
	// ENDFILE: actions.js

	// STARTFILE: domdrag.js
	/**
	@fileoverview
	The {@link Drag} object, which enables objects to be dragged around.

	<pre>
	*************************************************
	dom-drag.js
	09.25.2001
	www.youngpup.net
	**************************************************
	10.28.2001 - fixed minor bug where events
	sometimes fired off the handle, not the root.
	*************************************************
	Pared down, some hooks added by [[User:Lupin]]

	Copyright Aaron Boodman.
	Saying stupid things daily since March 2001.
	</pre>
	*/

	/**
	 * Creates a new Drag object. This is used to make various DOM elements draggable.
	 * @constructor
	 */
	function Drag() {
		/**
		 * Condition to determine whether or not to drag. This function should take one parameter,
		 * an Event.  To disable this, set it to <code>null</code>.
		 * @type {Function}
		 */
		this.startCondition = null;

		/**
		 * Hook to be run when the drag finishes. This is passed the final coordinates of the
		 * dragged object (two integers, x and y). To disables this, set it to <code>null</code>.
		 * @type {Function}
		 */
		this.endHook = null;
	}

	/**
	 * Gets an event in a cross-browser manner.
	 * @param {Event} e
	 * @private
	 */
	Drag.prototype.fixE = function (e) {
		if (typeof e == 'undefined') {
			e = window.event;
		}
		if (typeof e.layerX == 'undefined') {
			e.layerX = e.offsetX;
		}
		if (typeof e.layerY == 'undefined') {
			e.layerY = e.offsetY;
		}
		return e;
	};

	/**
	 * Initialises the Drag instance by telling it which object you want to be draggable, and what
	 * you want to drag it by.
	 * @param {DOMElement} o The "handle" by which <code>oRoot</code> is dragged.
	 * @param {DOMElement} oRoot The object which moves when <code>o</code> is dragged, or <code>o</code> if omitted.
	 */
	Drag.prototype.init = function (o, oRoot) {
		var dragObj = this;
		this.obj = o;
		o.onmousedown = function (e) {
			dragObj.start.apply(dragObj, [e]);
		};
		o.dragging = false;
		o.popups_draggable = true;
		o.hmode = true;
		o.vmode = true;

		o.root = oRoot ? oRoot : o;

		if (isNaN(parseInt(o.root.style.left, 10))) {
			o.root.style.left = '0px';
		}
		if (isNaN(parseInt(o.root.style.top, 10))) {
			o.root.style.top = '0px';
		}

		o.root.onthisStart = function () {};
		o.root.onthisEnd = function () {};
		o.root.onthis = function () {};
	};

	/**
	 * Starts the drag.
	 * @private
	 * @param {Event} e
	 */
	Drag.prototype.start = function (e) {
		var o = this.obj; // = this;
		e = this.fixE(e);
		if (this.startCondition && !this.startCondition(e)) {
			return;
		}
		var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom, 10);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right, 10);
		o.root.onthisStart(x, y);

		o.lastMouseX = e.clientX;
		o.lastMouseY = e.clientY;

		var dragObj = this;
		o.onmousemoveDefault = document.onmousemove;
		o.dragging = true;
		document.onmousemove = function (e) {
			dragObj.drag.apply(dragObj, [e]);
		};
		document.onmouseup = function (e) {
			dragObj.end.apply(dragObj, [e]);
		};
		return false;
	};

	/**
	 * Does the drag.
	 * @param {Event} e
	 * @private
	 */
	Drag.prototype.drag = function (e) {
		e = this.fixE(e);
		var o = this.obj;

		var ey = e.clientY;
		var ex = e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom, 10);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right, 10);
		var nx, ny;

		nx = x + (ex - o.lastMouseX) * (o.hmode ? 1 : -1);
		ny = y + (ey - o.lastMouseY) * (o.vmode ? 1 : -1);

		this.obj.root.style[o.hmode ? 'left' : 'right'] = nx + 'px';
		this.obj.root.style[o.vmode ? 'top' : 'bottom'] = ny + 'px';
		this.obj.lastMouseX = ex;
		this.obj.lastMouseY = ey;

		this.obj.root.onthis(nx, ny);
		return false;
	};

	/**
	 * Ends the drag.
	 * @private
	 */
	Drag.prototype.end = function () {
		document.onmousemove = this.obj.onmousemoveDefault;
		document.onmouseup = null;
		this.obj.dragging = false;
		if (this.endHook) {
			this.endHook(
				parseInt(this.obj.root.style[this.obj.hmode ? 'left' : 'right'], 10),
				parseInt(this.obj.root.style[this.obj.vmode ? 'top' : 'bottom'], 10)
			);
		}
	};
	// ENDFILE: domdrag.js

	// STARTFILE: structures.js
	pg.structures.original = {};
	pg.structures.original.popupLayout = function () {
		return [
			'popupError',
			'popupImage',
			'popupTopLinks',
			'popupTitle',
			'popupUserData',
			'popupData',
			'popupOtherLinks',
			'popupRedir',
			[
				'popupWarnRedir',
				'popupRedirTopLinks',
				'popupRedirTitle',
				'popupRedirData',
				'popupRedirOtherLinks',
			],
			'popupMiscTools',
			['popupRedlink'],
			'popupPrePreviewSep',
			'popupPreview',
			'popupSecondPreview',
			'popupPreviewMore',
			'popupPostPreview',
			'popupFixDab',
		];
	};
	pg.structures.original.popupRedirSpans = function () {
		return [
			'popupRedir',
			'popupWarnRedir',
			'popupRedirTopLinks',
			'popupRedirTitle',
			'popupRedirData',
			'popupRedirOtherLinks',
		];
	};
	pg.structures.original.popupTitle = function (x) {
		log('defaultstructure.popupTitle');
		if (!getValueOf('popupNavLinks')) {
			return navlinkStringToHTML('<b><<mainlink>></b>', x.article, x.params);
		}
		return '';
	};
	pg.structures.original.popupTopLinks = function (x) {
		log('defaultstructure.popupTopLinks');
		if (getValueOf('popupNavLinks')) {
			return navLinksHTML(x.article, x.hint, x.params);
		}
		return '';
	};
	pg.structures.original.popupImage = function (x) {
		log('original.popupImage, x.article=' + x.article + ', x.navpop.idNumber=' + x.navpop.idNumber);
		return imageHTML(x.article, x.navpop.idNumber);
	};
	pg.structures.original.popupRedirTitle = pg.structures.original.popupTitle;
	pg.structures.original.popupRedirTopLinks = pg.structures.original.popupTopLinks;

	function copyStructure(oldStructure, newStructure) {
		pg.structures[newStructure] = {};
		for (var prop in pg.structures[oldStructure]) {
			pg.structures[newStructure][prop] = pg.structures[oldStructure][prop];
		}
	}

	copyStructure('original', 'nostalgia');
	pg.structures.nostalgia.popupTopLinks = function (x) {
		var str = '';
		str += '<b><<mainlink|shortcut= >></b>';

		// user links
		// contribs - log - count - email - block
		// count only if applicable; block only if popupAdminLinks
		str += 'if(user){<br><<contribs|shortcut=c>>';
		str += 'if(wikimedia){*<<count|shortcut=#>>}';
		str += 'if(ipuser){}else{*<<email|shortcut=E>>}if(admin){*<<block|shortcut=b>>}}';

		// editing links
		// talkpage   -> edit|new - history - un|watch - article|edit
		// other page -> edit - history - un|watch - talk|edit|new
		var editstr = '<<edit|shortcut=e>>';
		var editOldidStr =
			'if(oldid){<<editOld|shortcut=e>>|<<revert|shortcut=v|rv>>|<<edit|cur>>}else{' +
			editstr +
			'}';
		var historystr = '<<history|shortcut=h>>';
		var watchstr = '<<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>>';

		str +=
			'<br>if(talk){' +
			editOldidStr +
			'|<<new|shortcut=+>>' +
			'*' +
			historystr +
			'*' +
			watchstr +
			'*' +
			'<b><<article|shortcut=a>></b>|<<editArticle|edit>>' +
			'}else{' + // not a talk page
			editOldidStr +
			'*' +
			historystr +
			'*' +
			watchstr +
			'*' +
			'<b><<talk|shortcut=t>></b>|<<editTalk|edit>>|<<newTalk|shortcut=+|new>>}';

		// misc links
		str += '<br><<whatLinksHere|shortcut=l>>*<<relatedChanges|shortcut=r>>';
		str += 'if(admin){<br>}else{*}<<move|shortcut=m>>';

		// admin links
		str +=
			'if(admin){*<<unprotect|unprotectShort>>|<<protect|shortcut=p>>*' +
			'<<undelete|undeleteShort>>|<<delete|shortcut=d>>}';
		return navlinkStringToHTML(str, x.article, x.params);
	};
	pg.structures.nostalgia.popupRedirTopLinks = pg.structures.nostalgia.popupTopLinks;

	/** -- fancy -- **/
	copyStructure('original', 'fancy');
	pg.structures.fancy.popupTitle = function (x) {
		return navlinkStringToHTML('<font size=+0><<mainlink>></font>', x.article, x.params);
	};
	pg.structures.fancy.popupTopLinks = function (x) {
		var hist =
			'<<history|shortcut=h|hist>>|<<lastEdit|shortcut=/|last>>|<<editors|shortcut=E|eds>>';
		var watch = '<<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>>';
		var move = '<<move|shortcut=m|move>>';
		return navlinkStringToHTML(
			'if(talk){' +
				'<<edit|shortcut=e>>|<<new|shortcut=+|+>>*' +
				hist +
				'*' +
				'<<article|shortcut=a>>|<<editArticle|edit>>' +
				'*' +
				watch +
				'*' +
				move +
				'}else{<<edit|shortcut=e>>*' +
				hist +
				'*<<talk|shortcut=t|>>|<<editTalk|edit>>|<<newTalk|shortcut=+|new>>' +
				'*' +
				watch +
				'*' +
				move +
				'}<br>',
			x.article,
			x.params
		);
	};
	pg.structures.fancy.popupOtherLinks = function (x) {
		var admin =
			'<<unprotect|unprotectShort>>|<<protect|shortcut=p>>*<<undelete|undeleteShort>>|<<delete|shortcut=d|del>>';
		var user = '<<contribs|shortcut=c>>if(wikimedia){|<<count|shortcut=#|#>>}';
		user +=
			'if(ipuser){|<<arin>>}else{*<<email|shortcut=E|' +
			popupString('email') +
			'>>}if(admin){*<<block|shortcut=b>>}';

		var normal = '<<whatLinksHere|shortcut=l|links here>>*<<relatedChanges|shortcut=r|related>>';
		return navlinkStringToHTML(
			'<br>if(user){' + user + '*}if(admin){' + admin + 'if(user){<br>}else{*}}' + normal,
			x.article,
			x.params
		);
	};
	pg.structures.fancy.popupRedirTitle = pg.structures.fancy.popupTitle;
	pg.structures.fancy.popupRedirTopLinks = pg.structures.fancy.popupTopLinks;
	pg.structures.fancy.popupRedirOtherLinks = pg.structures.fancy.popupOtherLinks;

	/** -- fancy2 -- **/
	// hack for [[User:MacGyverMagic]]
	copyStructure('fancy', 'fancy2');
	pg.structures.fancy2.popupTopLinks = function (x) {
		// hack out the <br> at the end and put one at the beginning
		return '<br>' + pg.structures.fancy.popupTopLinks(x).replace(RegExp('<br>$', 'i'), '');
	};
	pg.structures.fancy2.popupLayout = function () {
		// move toplinks to after the title
		return [
			'popupError',
			'popupImage',
			'popupTitle',
			'popupUserData',
			'popupData',
			'popupTopLinks',
			'popupOtherLinks',
			'popupRedir',
			[
				'popupWarnRedir',
				'popupRedirTopLinks',
				'popupRedirTitle',
				'popupRedirData',
				'popupRedirOtherLinks',
			],
			'popupMiscTools',
			['popupRedlink'],
			'popupPrePreviewSep',
			'popupPreview',
			'popupSecondPreview',
			'popupPreviewMore',
			'popupPostPreview',
			'popupFixDab',
		];
	};

	/** -- menus -- **/
	copyStructure('original', 'menus');
	pg.structures.menus.popupLayout = function () {
		return [
			'popupError',
			'popupImage',
			'popupTopLinks',
			'popupTitle',
			'popupOtherLinks',
			'popupRedir',
			[
				'popupWarnRedir',
				'popupRedirTopLinks',
				'popupRedirTitle',
				'popupRedirData',
				'popupRedirOtherLinks',
			],
			'popupUserData',
			'popupData',
			'popupMiscTools',
			['popupRedlink'],
			'popupPrePreviewSep',
			'popupPreview',
			'popupSecondPreview',
			'popupPreviewMore',
			'popupPostPreview',
			'popupFixDab',
		];
	};

	pg.structures.menus.popupTopLinks = function (x, shorter) {
		// FIXME maybe this stuff should be cached
		var s = [];
		var dropclass = 'popup_drop';
		var enddiv = '</div>';
		var hist = '<<history|shortcut=h>>';
		if (!shorter) {
			hist = '<menurow>' + hist + '|<<historyfeed|rss>>|<<editors|shortcut=E>></menurow>';
		}
		var lastedit = '<<lastEdit|shortcut=/|show last edit>>';
		var thank = 'if(diff){<<thank|send thanks>>}';
		var jsHistory = '<<lastContrib|last set of edits>><<sinceMe|changes since mine>>';
		var linkshere = '<<whatLinksHere|shortcut=l|what links here>>';
		var related = '<<relatedChanges|shortcut=r|related changes>>';
		var search =
			'<menurow><<search|shortcut=s>>if(wikimedia){|<<globalsearch|shortcut=g|global>>}' +
			'|<<google|shortcut=G|web>></menurow>';
		var watch = '<menurow><<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>></menurow>';
		var protect =
			'<menurow><<unprotect|unprotectShort>>|' +
			'<<protect|shortcut=p>>|<<protectlog|log>></menurow>';
		var del =
			'<menurow><<undelete|undeleteShort>>|<<delete|shortcut=d>>|' + '<<deletelog|log>></menurow>';
		var move = '<<move|shortcut=m|move page>>';
		var nullPurge = '<menurow><<nullEdit|shortcut=n|null edit>>|<<purge|shortcut=P>></menurow>';
		var viewOptions = '<menurow><<view|shortcut=v>>|<<render|shortcut=S>>|<<raw>></menurow>';
		var editRow =
			'if(oldid){' +
			'<menurow><<edit|shortcut=e>>|<<editOld|shortcut=e|this&nbsp;revision>></menurow>' +
			'<menurow><<revert|shortcut=v>>|<<undo>></menurow>' +
			'}else{<<edit|shortcut=e>>}';
		var markPatrolled = 'if(rcid){<<markpatrolled|mark patrolled>>}';
		var newTopic = 'if(talk){<<new|shortcut=+|new topic>>}';
		var protectDelete = 'if(admin){' + protect + del + '}';

		if (getValueOf('popupActionsMenu')) {
			s.push('<<mainlink>>*' + menuTitle(dropclass, 'actions'));
		} else {
			s.push('<div class="' + dropclass + '">' + '<<mainlink>>');
		}
		s.push('<menu>');
		s.push(editRow + markPatrolled + newTopic + hist + lastedit + thank);
		if (!shorter) {
			s.push(jsHistory);
		}
		s.push(move + linkshere + related);
		if (!shorter) {
			s.push(nullPurge + search);
		}
		if (!shorter) {
			s.push(viewOptions);
		}
		s.push('<hr />' + watch + protectDelete);
		s.push(
			'<hr />' +
				'if(talk){<<article|shortcut=a|view article>><<editArticle|edit article>>}' +
				'else{<<talk|shortcut=t|talk page>><<editTalk|edit talk>>' +
				'<<newTalk|shortcut=+|new topic>>}</menu>' +
				enddiv
		);

		// user menu starts here
		var email = '<<email|shortcut=E|email user>>';
		var contribs =
			'if(wikimedia){<menurow>}<<contribs|shortcut=c|contributions>>if(wikimedia){</menurow>}' +
			'if(admin){<menurow><<deletedContribs>></menurow>}';

		s.push('if(user){*' + menuTitle(dropclass, 'user'));
		s.push('<menu>');
		s.push('<menurow><<userPage|shortcut=u|user&nbsp;page>>|<<userSpace|space>></menurow>');
		s.push(
			'<<userTalk|shortcut=t|user talk>><<editUserTalk|edit user talk>>' +
				'<<newUserTalk|shortcut=+|leave comment>>'
		);
		if (!shorter) {
			s.push('if(ipuser){<<arin>>}else{' + email + '}');
		} else {
			s.push('if(ipuser){}else{' + email + '}');
		}
		s.push('<hr />' + contribs + '<<userlog|shortcut=L|user log>>');
		s.push('if(wikimedia){<<count|shortcut=#|edit counter>>}');
		s.push(
			'if(admin){<menurow><<unblock|unblockShort>>|<<block|shortcut=b|block user>></menurow>}'
		);
		s.push('<<blocklog|shortcut=B|block log>>');
		s.push('</menu>' + enddiv + '}');

		// popups menu starts here
		if (getValueOf('popupSetupMenu') && !x.navpop.hasPopupMenu /* FIXME: hack */) {
			x.navpop.hasPopupMenu = true;
			s.push('*' + menuTitle(dropclass, 'popupsMenu') + '<menu>');
			s.push('<<togglePreviews|toggle previews>>');
			s.push('<<purgePopups|reset>>');
			s.push('<<disablePopups|disable>>');
			s.push('</menu>' + enddiv);
		}
		return navlinkStringToHTML(s.join(''), x.article, x.params);
	};

	function menuTitle(dropclass, s) {
		var text = popupString(s); // i18n
		var len = text.length;
		return '<div class="' + dropclass + '" style="--navpop-m-len:' + len + 'ch">' + '<a href="#" noPopup=1>' + text + '</a>';
	}

	pg.structures.menus.popupRedirTitle = pg.structures.menus.popupTitle;
	pg.structures.menus.popupRedirTopLinks = pg.structures.menus.popupTopLinks;

	copyStructure('menus', 'shortmenus');
	pg.structures.shortmenus.popupTopLinks = function (x) {
		return pg.structures.menus.popupTopLinks(x, true);
	};
	pg.structures.shortmenus.popupRedirTopLinks = pg.structures.shortmenus.popupTopLinks;

	pg.structures.lite = {};
	pg.structures.lite.popupLayout = function () {
		return ['popupTitle', 'popupPreview'];
	};
	pg.structures.lite.popupTitle = function (x) {
		log(x.article + ': structures.lite.popupTitle');
		//return navlinkStringToHTML('<b><<mainlink>></b>',x.article,x.params);
		return '<div><span class="popup_mainlink"><b>' + x.article.toString() + '</b></span></div>';
	};
	// ENDFILE: structures.js

	// STARTFILE: autoedit.js
	function substitute(data, cmdBody) {
		// alert('sub\nfrom: '+cmdBody.from+'\nto: '+cmdBody.to+'\nflags: '+cmdBody.flags);
		var fromRe = RegExp(cmdBody.from, cmdBody.flags);
		return data.replace(fromRe, cmdBody.to);
	}

	function execCmds(data, cmdList) {
		for (var i = 0; i < cmdList.length; ++i) {
			data = cmdList[i].action(data, cmdList[i]);
		}
		return data;
	}

	function parseCmd(str) {
		// returns a list of commands
		if (!str.length) {
			return [];
		}
		var p = false;
		switch (str.charAt(0)) {
			case 's':
				p = parseSubstitute(str);
				break;
			default:
				return false;
		}
		if (p) {
			return [p].concat(parseCmd(p.remainder));
		}
		return false;
	}

	// FIXME: Only used once here, confusing with native (and more widely-used) unescape, should probably be replaced
	// Then again, unescape is semi-soft-deprecated, so we should look into replacing that too
	function unEscape(str, sep) {
		return str
			.split('\\\\')
			.join('\\')
			.split('\\' + sep)
			.join(sep)
			.split('\\n')
			.join('\n');
	}

	function parseSubstitute(str) {
		// takes a string like s/a/b/flags;othercmds and parses it

		var from, to, flags, tmp;

		if (str.length < 4) {
			return false;
		}
		var sep = str.charAt(1);
		str = str.substring(2);

		tmp = skipOver(str, sep);
		if (tmp) {
			from = tmp.segment;
			str = tmp.remainder;
		} else {
			return false;
		}

		tmp = skipOver(str, sep);
		if (tmp) {
			to = tmp.segment;
			str = tmp.remainder;
		} else {
			return false;
		}

		flags = '';
		if (str.length) {
			tmp = skipOver(str, ';') || skipToEnd(str, ';');
			if (tmp) {
				flags = tmp.segment;
				str = tmp.remainder;
			}
		}

		return {
			action: substitute,
			from: from,
			to: to,
			flags: flags,
			remainder: str,
		};
	}

	function skipOver(str, sep) {
		var endSegment = findNext(str, sep);
		if (endSegment < 0) {
			return false;
		}
		var segment = unEscape(str.substring(0, endSegment), sep);
		return { segment: segment, remainder: str.substring(endSegment + 1) };
	}

	/*eslint-disable*/
	function skipToEnd(str, sep) {
		return { segment: str, remainder: '' };
	}
	/*eslint-enable */

	function findNext(str, ch) {
		for (var i = 0; i < str.length; ++i) {
			if (str.charAt(i) == '\\') {
				i += 2;
			}
			if (str.charAt(i) == ch) {
				return i;
			}
		}
		return -1;
	}

	function setCheckbox(param, box) {
		var val = mw.util.getParamValue(param);
		if (val) {
			switch (val) {
				case '1':
				case 'yes':
				case 'true':
					box.checked = true;
					break;
				case '0':
				case 'no':
				case 'false':
					box.checked = false;
			}
		}
	}

	function autoEdit() {
		setupPopups(function () {
			if (mw.util.getParamValue('autoimpl') !== popupString('autoedit_version')) {
				return false;
			}
			if (
				mw.util.getParamValue('autowatchlist') &&
				mw.util.getParamValue('actoken') === autoClickToken()
			) {
				pg.fn.modifyWatchlist(mw.util.getParamValue('title'), mw.util.getParamValue('action'));
			}
			if (!document.editform) {
				return false;
			}
			if (autoEdit.alreadyRan) {
				return false;
			}
			autoEdit.alreadyRan = true;
			var cmdString = mw.util.getParamValue('autoedit');
			if (cmdString) {
				try {
					var editbox = document.editform.wpTextbox1;
					var cmdList = parseCmd(cmdString);
					var input = editbox.value;
					var output = execCmds(input, cmdList);
					editbox.value = output;
				} catch (dang) {
					return;
				}
				// wikEd user script compatibility
				if (typeof wikEdUseWikEd != 'undefined') {
					if (wikEdUseWikEd === true) {
						WikEdUpdateFrame();
					}
				}
			}
			setCheckbox('autominor', document.editform.wpMinoredit);
			setCheckbox('autowatch', document.editform.wpWatchthis);

			var rvid = mw.util.getParamValue('autorv');
			if (rvid) {
				var url =
					pg.wiki.apiwikibase +
					'?action=query&format=json&formatversion=2&prop=revisions&revids=' +
					rvid;
				startDownload(url, null, autoEdit2);
			} else {
				autoEdit2();
			}
		});
	}

	function autoEdit2(d) {
		var summary = mw.util.getParamValue('autosummary');
		var summaryprompt = mw.util.getParamValue('autosummaryprompt');
		var summarynotice = '';
		if (d && d.data && mw.util.getParamValue('autorv')) {
			var s = getRvSummary(summary, d.data);
			if (s === false) {
				summaryprompt = true;
				summarynotice = popupString(
					'Failed to get revision information, please edit manually.\n\n'
				);
				summary = simplePrintf(summary, [
					mw.util.getParamValue('autorv'),
					'(unknown)',
					'(unknown)',
				]);
			} else {
				summary = s;
			}
		}
		if (summaryprompt) {
			var txt =
				summarynotice + popupString('Enter a non-empty edit summary or press cancel to abort');
			var response = prompt(txt, summary);
			if (response) {
				summary = response;
			} else {
				return;
			}
		}
		if (summary) {
			document.editform.wpSummary.value = summary;
		}
		// Attempt to avoid possible premature clicking of the save button
		// (maybe delays in updates to the DOM are to blame?? or a red herring)
		setTimeout(autoEdit3, 100);
	}

	function autoClickToken() {
		return mw.user.sessionId();
	}

	function autoEdit3() {
		if (mw.util.getParamValue('actoken') != autoClickToken()) {
			return;
		}

		var btn = mw.util.getParamValue('autoclick');
		if (btn) {
			if (document.editform && document.editform[btn]) {
				var button = document.editform[btn];
				var msg = tprintf(
					'The %s button has been automatically clicked. Please wait for the next page to load.',
					[button.value]
				);
				bannerMessage(msg);
				document.title = '(' + document.title + ')';
				button.click();
			} else {
				alert(
					tprintf('Could not find button %s. Please check the settings in your javascript file.', [
						btn,
					])
				);
			}
		}
	}

	function bannerMessage(s) {
		var headings = document.getElementsByTagName('h1');
		if (headings) {
			var div = document.createElement('div');
			div.innerHTML = '<font size=+1><b>' + pg.escapeQuotesHTML(s) + '</b></font>';
			headings[0].parentNode.insertBefore(div, headings[0]);
		}
	}

	function getRvSummary(template, json) {
		try {
			var o = getJsObj(json);
			var edit = anyChild(o.query.pages).revisions[0];
			var timestamp = edit.timestamp
				.split(/[A-Z]/g)
				.join(' ')
				.replace(/^ *| *$/g, '');
			return simplePrintf(template, [
				edit.revid,
				timestamp,
				edit.userhidden ? '(hidden)' : edit.user,
			]);
		} catch (badness) {
			return false;
		}
	}

	// ENDFILE: autoedit.js

	// STARTFILE: downloader.js
	/**
	 * @fileoverview
	 * {@link Downloader}, a xmlhttprequest wrapper, and helper functions.
	 */

	/**
	 * Creates a new Downloader
	 * @constructor
	 * @class The Downloader class. Create a new instance of this class to download stuff.
	 * @param {String} url The url to download. This can be omitted and supplied later.
	 */
	function Downloader(url) {
		if (typeof XMLHttpRequest != 'undefined') {
			this.http = new XMLHttpRequest();
		}

		/**
		 * The url to download
		 * @type {string}
		 */
		this.url = url;

		/**
		 * A universally unique ID number
		 * @type {number}
		 */
		this.id = null;

		/**
		 * Modification date, to be culled from the incoming headers
		 * @type Date
		 * @private
		 */
		this.lastModified = null;

		/**
		 * What to do when the download completes successfully
		 * @type {Function}
		 * @private
		 */
		this.callbackFunction = null;

		/**
		 * What to do on failure
		 * @type {Function}
		 * @private
		 */
		this.onFailure = null;

		/**
		 * Flag set on <code>abort</code>
		 * @type {boolean}
		 */
		this.aborted = false;

		/**
		 * HTTP method. See https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html for
		 * possibilities.
		 * @type {string}
		 */
		this.method = 'GET';
		/**
		Async flag.
		@type {boolean}
	*/
		this.async = true;
	}

	new Downloader();

	/** Submits the http request. */
	Downloader.prototype.send = function (x) {
		if (!this.http) {
			return null;
		}
		return this.http.send(x);
	};

	/** Aborts the download, setting the <code>aborted</code> field to true.  */
	Downloader.prototype.abort = function () {
		if (!this.http) {
			return null;
		}
		this.aborted = true;
		return this.http.abort();
	};

	/** Returns the downloaded data. */
	Downloader.prototype.getData = function () {
		if (!this.http) {
			return null;
		}
		return this.http.responseText;
	};

	/** Prepares the download. */
	Downloader.prototype.setTarget = function () {
		if (!this.http) {
			return null;
		}
		this.http.open(this.method, this.url, this.async);
		this.http.setRequestHeader('Api-User-Agent', pg.api.userAgent);
	};

	/** Gets the state of the download. */
	Downloader.prototype.getReadyState = function () {
		if (!this.http) {
			return null;
		}
		return this.http.readyState;
	};

	pg.misc.downloadsInProgress = {};

	/**
	 * Starts the download.
	 * Note that setTarget {@link Downloader#setTarget} must be run first
	 */
	Downloader.prototype.start = function () {
		if (!this.http) {
			return;
		}
		pg.misc.downloadsInProgress[this.id] = this;
		this.http.send(null);
	};

	/**
	 * Gets the 'Last-Modified' date from the download headers.
	 * Should be run after the download completes.
	 * Returns <code>null</code> on failure.
	 * @return {Date}
	 */
	Downloader.prototype.getLastModifiedDate = function () {
		if (!this.http) {
			return null;
		}
		var lastmod = null;
		try {
			lastmod = this.http.getResponseHeader('Last-Modified');
		} catch (err) {}
		if (lastmod) {
			return new Date(lastmod);
		}
		return null;
	};

	/**
	 * Sets the callback function.
	 * @param {Function} f callback function, called as <code>f(this)</code> on success
	 */
	Downloader.prototype.setCallback = function (f) {
		if (!this.http) {
			return;
		}
		this.http.onreadystatechange = f;
	};

	Downloader.prototype.getStatus = function () {
		if (!this.http) {
			return null;
		}
		return this.http.status;
	};

	//////////////////////////////////////////////////
	// helper functions

	/**
	 * Creates a new {@link Downloader} and prepares it for action.
	 * @param {String} url The url to download
	 * @param {number} id The ID of the {@link Downloader} object
	 * @param {Function} callback The callback function invoked on success
	 * @return {String/Downloader} the {@link Downloader} object created, or 'ohdear' if an unsupported browser
	 */
	function newDownload(url, id, callback, onfailure) {
		var d = new Downloader(url);
		if (!d.http) {
			return 'ohdear';
		}
		d.id = id;
		d.setTarget();
		if (!onfailure) {
			onfailure = 2;
		}
		var f = function () {
			if (d.getReadyState() == 4) {
				delete pg.misc.downloadsInProgress[this.id];
				try {
					if (d.getStatus() == 200) {
						d.data = d.getData();
						d.lastModified = d.getLastModifiedDate();
						callback(d);
					} else if (typeof onfailure == typeof 1) {
						if (onfailure > 0) {
							// retry
							newDownload(url, id, callback, onfailure - 1);
						}
					} else if (typeof onfailure === 'function') {
						onfailure(d, url, id, callback);
					}
				} catch (somerr) {
					/* ignore it */
				}
			}
		};
		d.setCallback(f);
		return d;
	}
	/**
	 * Simulates a download from cached data.
	 * The supplied data is put into a {@link Downloader} as if it had downloaded it.
	 * @param {String} url The url.
	 * @param {number} id The ID.
	 * @param {Function} callback The callback, which is invoked immediately as <code>callback(d)</code>,
	 * where <code>d</code> is the new {@link Downloader}.
	 * @param {String} data The (cached) data.
	 * @param {Date} lastModified The (cached) last modified date.
	 */
	function fakeDownload(url, id, callback, data, lastModified, owner) {
		var d = newDownload(url, callback);
		d.owner = owner;
		d.id = id;
		d.data = data;
		d.lastModified = lastModified;
		return callback(d);
	}

	/**
	 * Starts a download.
	 * @param {String} url The url to download
	 * @param {number} id The ID of the {@link Downloader} object
	 * @param {Function} callback The callback function invoked on success
	 * @return {String/Downloader} the {@link Downloader} object created, or 'ohdear' if an unsupported browser
	 */
	function startDownload(url, id, callback) {
		var d = newDownload(url, id, callback);
		if (typeof d == typeof '') {
			return d;
		}
		d.start();
		return d;
	}

	/**
	 * Aborts all downloads which have been started.
	 */
	function abortAllDownloads() {
		for (var x in pg.misc.downloadsInProgress) {
			try {
				pg.misc.downloadsInProgress[x].aborted = true;
				pg.misc.downloadsInProgress[x].abort();
				delete pg.misc.downloadsInProgress[x];
			} catch (e) {}
		}
	}
	// ENDFILE: downloader.js

	// STARTFILE: livepreview.js
	// TODO: location is often not correct (eg relative links in previews)
	// NOTE: removed md5 and image and math parsing. was broken, lots of bytes.
	/**
	 * InstaView - a Mediawiki to HTML converter in JavaScript
	 * Version 0.6.1
	 * Copyright (C) Pedro Fayolle 2005-2006
	 * https://en.wikipedia.org/wiki/User:Pilaf
	 * Distributed under the BSD license
	 *
	 * Changelog:
	 *
	 * 0.6.1
	 * - Fixed problem caused by \r characters
	 * - Improved inline formatting parser
	 *
	 * 0.6
	 * - Changed name to InstaView
	 * - Some major code reorganizations and factored out some common functions
	 * - Handled conversion of relative links (i.e. [[/foo]])
	 * - Fixed misrendering of adjacent definition list items
	 * - Fixed bug in table headings handling
	 * - Changed date format in signatures to reflect Mediawiki's
	 * - Fixed handling of [[:Image:...]]
	 * - Updated MD5 function (hopefully it will work with UTF-8)
	 * - Fixed bug in handling of links inside images
	 *
	 * To do:
	 * - Better support for math tags
	 * - Full support for <nowiki>
	 * - Parser-based (as opposed to RegExp-based) inline wikicode handling (make it one-pass and
	 *   bullet-proof)
	 * - Support for templates (through AJAX)
	 * - Support for coloured links (AJAX)
	 */

	var Insta = {};

	function setupLivePreview() {
		// options
		Insta.conf = {
			baseUrl: '',

			user: {},

			wiki: {
				lang: pg.wiki.lang,
				interwiki: pg.wiki.interwiki,
				default_thumb_width: 180,
			},

			paths: {
				articles: pg.wiki.articlePath + '/',
				// Only used for Insta previews with images. (not in popups)
				math: '/math/',
				images: '//upload.wikimedia.org/wikipedia/en/', // FIXME getImageUrlStart(pg.wiki.hostname),
				images_fallback: '//upload.wikimedia.org/wikipedia/commons/',
			},

			locale: {
				user: mw.config.get('wgFormattedNamespaces')[pg.nsUserId],
				image: mw.config.get('wgFormattedNamespaces')[pg.nsImageId],
				category: mw.config.get('wgFormattedNamespaces')[pg.nsCategoryId],
				// shouldn't be used in popup previews, i think
				months: [
					'Jan',
					'Feb',
					'Mar',
					'Apr',
					'May',
					'Jun',
					'Jul',
					'Aug',
					'Sep',
					'Oct',
					'Nov',
					'Dec',
				],
			},
		};

		// options with default values or backreferences
		Insta.conf.user.name = Insta.conf.user.name || 'Wikipedian';
		Insta.conf.user.signature =
			'[[' +
			Insta.conf.locale.user +
			':' +
			Insta.conf.user.name +
			'|' +
			Insta.conf.user.name +
			']]';
		//Insta.conf.paths.images = '//upload.wikimedia.org/wikipedia/' + Insta.conf.wiki.lang + '/';

		// define constants
		Insta.BLOCK_IMAGE = new RegExp(
			'^\\[\\[(?:File|Image|' +
				Insta.conf.locale.image +
				'):.*?\\|.*?(?:frame|thumbnail|thumb|none|right|left|center)',
			'i'
		);
	}

	Insta.dump = function (from, to) {
		if (typeof from == 'string') {
			from = document.getElementById(from);
		}
		if (typeof to == 'string') {
			to = document.getElementById(to);
		}
		to.innerHTML = this.convert(from.value);
	};

	Insta.convert = function (wiki) {
		var ll = typeof wiki == 'string' ? wiki.replace(/\r/g, '').split(/\n/) : wiki, // lines of wikicode
			o = '', // output
			p = 0, // para flag
			r; // result of passing a regexp to compareLineStringOrReg()

		// some shorthands
		function remain() {
			return ll.length;
		}
		function sh() {
			return ll.shift();
		} // shift
		function ps(s) {
			o += s;
		} // push

		// similar to C's printf, uses ? as placeholders, ?? to escape question marks
		function f() {
			var i = 1,
				a = arguments,
				f = a[0],
				o = '',
				c,
				p;
			for (; i < a.length; i++) {
				if ((p = f.indexOf('?')) + 1) {
					// allow character escaping
					i -= c = f.charAt(p + 1) == '?' ? 1 : 0;
					o += f.substring(0, p) + (c ? '?' : a[i]);
					f = f.substr(p + 1 + c);
				} else {
					break;
				}
			}
			return o + f;
		}

		function html_entities(s) {
			return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
		}

		// Wiki text parsing to html is a nightmare.
		// The below functions deliberately don't escape the ampersand since this would make it more
		// difficult, and we don't absolutely need to for how we need it. This means that any
		// unescaped ampersands in wikitext will remain unescaped and can cause invalid HTML.
		// Browsers should all be able to handle it though. We also escape significant wikimarkup
		// characters to prevent further matching on the processed text.
		function htmlescape_text(s) {
			return s
				.replace(/</g, '&lt;')
				.replace(/>/g, '&gt;')
				.replace(/:/g, '&#58;')
				.replace(/\[/g, '&#91;')
				.replace(/]/g, '&#93;');
		}
		function htmlescape_attr(s) {
			return htmlescape_text(s).replace(/'/g, '&#39;').replace(/"/g, '&quot;');
		}

		// return the first non matching character position between two strings
		function str_imatch(a, b) {
			for (var i = 0, l = Math.min(a.length, b.length); i < l; i++) {
				if (a.charAt(i) != b.charAt(i)) {
					break;
				}
			}
			return i;
		}

		// compare current line against a string or regexp
		// if passed a string it will compare only the first string.length characters
		// if passed a regexp the result is stored in r
		function compareLineStringOrReg(c) {
			return typeof c == 'string'
				? ll[0] && ll[0].substr(0, c.length) == c
				: (r = ll[0] && ll[0].match(c));
		}

		function compareLineString(c) {
			return ll[0] == c;
		} // compare current line against a string
		function charAtPoint(p) {
			return ll[0].charAt(p);
		} // return char at pos p

		function endl(s) {
			ps(s);
			sh();
		}

		function parse_list() {
			var prev = '';

			while (remain() && compareLineStringOrReg(/^([*#:;]+)(.*)$/)) {
				var l_match = r;

				sh();

				var ipos = str_imatch(prev, l_match[1]);

				// close uncontinued lists
				for (var prevPos = prev.length - 1; prevPos >= ipos; prevPos--) {
					var pi = prev.charAt(prevPos);

					if (pi == '*') {
						ps('</ul>');
					} else if (pi == '#') {
						ps('</ol>');
					}
					// close a dl only if the new item is not a dl item (:, ; or empty)
					else if ($.inArray(l_match[1].charAt(prevPos), ['', '*', '#'])) {
						ps('</dl>');
					}
				}

				// open new lists
				for (var matchPos = ipos; matchPos < l_match[1].length; matchPos++) {
					var li = l_match[1].charAt(matchPos);

					if (li == '*') {
						ps('<ul>');
					} else if (li == '#') {
						ps('<ol>');
					}
					// open a new dl only if the prev item is not a dl item (:, ; or empty)
					else if ($.inArray(prev.charAt(matchPos), ['', '*', '#'])) {
						ps('<dl>');
					}
				}

				switch (l_match[1].charAt(l_match[1].length - 1)) {
					case '*':
					case '#':
						ps('<li>' + parse_inline_nowiki(l_match[2]));
						break;

					case ';':
						ps('<dt>');

						var dt_match = l_match[2].match(/(.*?)(:.*?)$/);

						// handle ;dt :dd format
						if (dt_match) {
							ps(parse_inline_nowiki(dt_match[1]));
							ll.unshift(dt_match[2]);
						} else {
							ps(parse_inline_nowiki(l_match[2]));
						}
						break;

					case ':':
						ps('<dd>' + parse_inline_nowiki(l_match[2]));
				}

				prev = l_match[1];
			}

			// close remaining lists
			for (var i = prev.length - 1; i >= 0; i--) {
				ps(f('</?>', prev.charAt(i) == '*' ? 'ul' : prev.charAt(i) == '#' ? 'ol' : 'dl'));
			}
		}

		function parse_table() {
			endl(f('<table>', compareLineStringOrReg(/^\{\|( .*)$/) ? r[1] : ''));

			for (; remain(); ) {
				if (compareLineStringOrReg('|')) {
					switch (charAtPoint(1)) {
						case '}':
							endl('</table>');
							return;
						case '-':
							endl(f('<tr>', compareLineStringOrReg(/\|-*(.*)/)[1]));
							break;
						default:
							parse_table_data();
					}
				} else if (compareLineStringOrReg('!')) {
					parse_table_data();
				} else {
					sh();
				}
			}
		}

		function parse_table_data() {
			var td_line, match_i;

			// 1: "|+", '|' or '+'
			// 2: ??
			// 3: attributes ??
			// TODO: finish commenting this regexp
			var td_match = sh().match(/^(\|\+|\||!)((?:([^[|]*?)\|(?!\|))?(.*))$/);

			if (td_match[1] == '|+') {
				ps('<caption');
			} else {
				ps('<t' + (td_match[1] == '|' ? 'd' : 'h'));
			}

			if (typeof td_match[3] != 'undefined') {
				//ps(' ' + td_match[3])
				match_i = 4;
			} else {
				match_i = 2;
			}

			ps('>');

			if (td_match[1] != '|+') {
				// use || or !! as a cell separator depending on context
				// NOTE: when split() is passed a regexp make sure to use non-capturing brackets
				td_line = td_match[match_i].split(td_match[1] == '|' ? '||' : /(?:\|\||!!)/);

				ps(parse_inline_nowiki(td_line.shift()));

				while (td_line.length) {
					ll.unshift(td_match[1] + td_line.pop());
				}
			} else {
				ps(parse_inline_nowiki(td_match[match_i]));
			}

			var tc = 0,
				td = [];

			while (remain()) {
				td.push(sh());
				if (compareLineStringOrReg('|')) {
					if (!tc) {
						break;
					}
					// we're at the outer-most level (no nested tables), skip to td parse
					else if (charAtPoint(1) == '}') {
						tc--;
					}
				} else if (!tc && compareLineStringOrReg('!')) {
					break;
				} else if (compareLineStringOrReg('{|')) {
					tc++;
				}
			}

			if (td.length) {
				ps(Insta.convert(td));
			}
		}

		function parse_pre() {
			ps('<pre>');
			do {
				endl(parse_inline_nowiki(ll[0].substring(1)) + '\n');
			} while (remain() && compareLineStringOrReg(' '));
			ps('</pre>');
		}

		function parse_block_image() {
			ps(parse_image(sh()));
		}

		function parse_image(str) {
			// get what's in between "[[Image:" and "]]"
			var tag = str.substring(str.indexOf(':') + 1, str.length - 2);
			var width;
			var attr = [],
				filename,
				caption = '';
			var thumb = 0,
				frame = 0,
				center = 0;
			var align = '';

			if (tag.match(/\|/)) {
				// manage nested links
				var nesting = 0;
				var last_attr;
				for (var i = tag.length - 1; i > 0; i--) {
					if (tag.charAt(i) == '|' && !nesting) {
						last_attr = tag.substr(i + 1);
						tag = tag.substring(0, i);
						break;
					} else {
						switch (tag.substr(i - 1, 2)) {
							case ']]':
								nesting++;
								i--;
								break;
							case '[[':
								nesting--;
								i--;
						}
					}
				}

				attr = tag.split(/\s*\|\s*/);
				attr.push(last_attr);
				filename = attr.shift();

				var w_match;

				for (; attr.length; attr.shift()) {
					w_match = attr[0].match(/^(\d*)(?:[px]*\d*)?px$/);
					if (w_match) {
						width = w_match[1];
					} else {
						switch (attr[0]) {
							case 'thumb':
							case 'thumbnail':
								thumb = true;
								frame = true;
								break;
							case 'frame':
								frame = true;
								break;
							case 'none':
							case 'right':
							case 'left':
								center = false;
								align = attr[0];
								break;
							case 'center':
								center = true;
								align = 'none';
								break;
							default:
								if (attr.length == 1) {
									caption = attr[0];
								}
						}
					}
				}
			} else {
				filename = tag;
			}

			return '';
		}

		function parse_inline_nowiki(str) {
			var start,
				lastend = 0;
			var substart = 0,
				nestlev = 0,
				open,
				close,
				subloop;
			var html = '';

			while ((start = str.indexOf('<nowiki>', substart)) != -1) {
				html += parse_inline_wiki(str.substring(lastend, start));
				start += 8;
				substart = start;
				subloop = true;
				do {
					open = str.indexOf('<nowiki>', substart);
					close = str.indexOf('</nowiki>', substart);
					if (close <= open || open == -1) {
						if (close == -1) {
							return html + html_entities(str.substr(start));
						}
						substart = close + 9;
						if (nestlev) {
							nestlev--;
						} else {
							lastend = substart;
							html += html_entities(str.substring(start, lastend - 9));
							subloop = false;
						}
					} else {
						substart = open + 8;
						nestlev++;
					}
				} while (subloop);
			}

			return html + parse_inline_wiki(str.substr(lastend));
		}

		function parse_inline_images(str) {
			var start,
				substart = 0,
				nestlev = 0;
			var loop, close, open, wiki, html;

			while ((start = str.indexOf('[[', substart)) != -1) {
				if (
					str.substr(start + 2).match(RegExp('^(Image|File|' + Insta.conf.locale.image + '):', 'i'))
				) {
					loop = true;
					substart = start;
					do {
						substart += 2;
						close = str.indexOf(']]', substart);
						open = str.indexOf('[[', substart);
						if (close <= open || open == -1) {
							if (close == -1) {
								return str;
							}
							substart = close;
							if (nestlev) {
								nestlev--;
							} else {
								wiki = str.substring(start, close + 2);
								html = parse_image(wiki);
								str = str.replace(wiki, html);
								substart = start + html.length;
								loop = false;
							}
						} else {
							substart = open;
							nestlev++;
						}
					} while (loop);
				} else {
					break;
				}
			}

			return str;
		}

		// the output of this function doesn't respect the FILO structure of HTML
		// but since most browsers can handle it I'll save myself the hassle
		function parse_inline_formatting(str) {
			var em,
				st,
				i,
				li,
				o = '';
			while ((i = str.indexOf("''", li)) + 1) {
				o += str.substring(li, i);
				li = i + 2;
				if (str.charAt(i + 2) == "'") {
					li++;
					st = !st;
					o += st ? '<strong>' : '</strong>';
				} else {
					em = !em;
					o += em ? '<em>' : '</em>';
				}
			}
			return o + str.substr(li);
		}

		function parse_inline_wiki(str) {
			str = parse_inline_images(str);

			// math
			str = str.replace(/<(?:)math>(.*?)<\/math>/gi, '');

			// Build a Mediawiki-formatted date string
			var date = new Date();
			var minutes = date.getUTCMinutes();
			if (minutes < 10) {
				minutes = '0' + minutes;
			}
			date = f(
				'?:?, ? ? ? (UTC)',
				date.getUTCHours(),
				minutes,
				date.getUTCDate(),
				Insta.conf.locale.months[date.getUTCMonth()],
				date.getUTCFullYear()
			);

			// text formatting
			str =
				str
					// signatures
					.replace(/~{5}(?!~)/g, date)
					.replace(/~{4}(?!~)/g, Insta.conf.user.name + ' ' + date)
					.replace(/~{3}(?!~)/g, Insta.conf.user.name)
					// [[:Category:...]], [[:Image:...]], etc...
					.replace(
						RegExp(
							'\\[\\[:((?:' +
								Insta.conf.locale.category +
								'|Image|File|' +
								Insta.conf.locale.image +
								'|' +
								Insta.conf.wiki.interwiki +
								'):[^|]*?)\\]\\](\\w*)',
							'gi'
						),
						function ($0, $1, $2) {
							return f(
								"<a href='?'>?</a>",
								Insta.conf.paths.articles + htmlescape_attr($1),
								htmlescape_text($1) + htmlescape_text($2)
							);
						}
					)
					// remove straight category and interwiki tags
					.replace(
						RegExp(
							'\\[\\[(?:' +
								Insta.conf.locale.category +
								'|' +
								Insta.conf.wiki.interwiki +
								'):.*?\\]\\]',
							'gi'
						),
						''
					)
					// [[:Category:...|Links]], [[:Image:...|Links]], etc...
					.replace(
						RegExp(
							'\\[\\[:((?:' +
								Insta.conf.locale.category +
								'|Image|File|' +
								Insta.conf.locale.image +
								'|' +
								Insta.conf.wiki.interwiki +
								'):.*?)\\|([^\\]]+?)\\]\\](\\w*)',
							'gi'
						),
						function ($0, $1, $2, $3) {
							return f(
								"<a href='?'>?</a>",
								Insta.conf.paths.articles + htmlescape_attr($1),
								htmlescape_text($2) + htmlescape_text($3)
							);
						}
					)
					// [[/Relative links]]
					.replace(/\[\[(\/[^|]*?)\]\]/g, function ($0, $1) {
						return f(
							"<a href='?'>?</a>",
							Insta.conf.baseUrl + htmlescape_attr($1),
							htmlescape_text($1)
						);
					})
					// [[/Replaced|Relative links]]
					.replace(/\[\[(\/.*?)\|(.+?)\]\]/g, function ($0, $1, $2) {
						return f(
							"<a href='?'>?</a>",
							Insta.conf.baseUrl + htmlescape_attr($1),
							htmlescape_text($2)
						);
					})
					// [[Common links]]
					.replace(/\[\[([^[|]*?)\]\](\w*)/g, function ($0, $1, $2) {
						return f(
							"<a href='?'>?</a>",
							Insta.conf.paths.articles + htmlescape_attr($1),
							htmlescape_text($1) + htmlescape_text($2)
						);
					})
					// [[Replaced|Links]]
					.replace(/\[\[([^[]*?)\|([^\]]+?)\]\](\w*)/g, function ($0, $1, $2, $3) {
						return f(
							"<a href='?'>?</a>",
							Insta.conf.paths.articles + htmlescape_attr($1),
							htmlescape_text($2) + htmlescape_text($3)
						);
					})
					// [[Stripped:Namespace|Namespace]]
					.replace(/\[\[([^\]]*?:)?(.*?)( *\(.*?\))?\|\]\]/g, function ($0, $1, $2, $3) {
						return f(
							"<a href='?'>?</a>",
							Insta.conf.paths.articles +
								htmlescape_attr($1) +
								htmlescape_attr($2) +
								htmlescape_attr($3),
							htmlescape_text($2)
						);
					})
					// External links
					.replace(
						/\[(https?|news|ftp|mailto|gopher|irc):(\/*)([^\]]*?) (.*?)\]/g,
						function ($0, $1, $2, $3, $4) {
							return f(
								"<a class='external' href='?:?'>?</a>",
								htmlescape_attr($1),
								htmlescape_attr($2) + htmlescape_attr($3),
								htmlescape_text($4)
							);
						}
					)
					.replace(/\[http:\/\/(.*?)\]/g, function ($0, $1) {
						return f("<a class='external' href='http://?'>[#]</a>", htmlescape_attr($1));
					})
					.replace(/\[(news|ftp|mailto|gopher|irc):(\/*)(.*?)\]/g, function ($0, $1, $2, $3) {
						return f(
							"<a class='external' href='?:?'>?:?</a>",
							htmlescape_attr($1),
							htmlescape_attr($2) + htmlescape_attr($3),
							htmlescape_text($1),
							htmlescape_text($2) + htmlescape_text($3)
						);
					})
					.replace(
						/(^| )(https?|news|ftp|mailto|gopher|irc):(\/*)([^ $]*[^.,!?;: $])/g,
						function ($0, $1, $2, $3, $4) {
							return f(
								"?<a class='external' href='?:?'>?:?</a>",
								htmlescape_text($1),
								htmlescape_attr($2),
								htmlescape_attr($3) + htmlescape_attr($4),
								htmlescape_text($2),
								htmlescape_text($3) + htmlescape_text($4)
							);
						}
					)
					.replace('__NOTOC__', '')
					.replace('__NOINDEX__', '')
					.replace('__INDEX__', '')
					.replace('__NOEDITSECTION__', '')
			;
			return parse_inline_formatting(str);
		}

		// begin parsing
		for (; remain(); ) {
			if (compareLineStringOrReg(/^(={1,6})(.*)\1(.*)$/)) {
				p = 0;
				endl(f('<h?>?</h?>?', r[1].length, parse_inline_nowiki(r[2]), r[1].length, r[3]));
			} else if (compareLineStringOrReg(/^[*#:;]/)) {
				p = 0;
				parse_list();
			} else if (compareLineStringOrReg(' ')) {
				p = 0;
				parse_pre();
			} else if (compareLineStringOrReg('{|')) {
				p = 0;
				parse_table();
			} else if (compareLineStringOrReg(/^----+$/)) {
				p = 0;
				endl('<hr />');
			} else if (compareLineStringOrReg(Insta.BLOCK_IMAGE)) {
				p = 0;
				parse_block_image();
			} else {
				// handle paragraphs
				if (compareLineString('')) {
					p = remain() > 1 && ll[1] === '';
					if (p) {
						endl('<p><br>');
					}
				} else {
					if (!p) {
						ps('<p>');
						p = 1;
					}
					ps(parse_inline_nowiki(ll[0]) + ' ');
				}

				sh();
			}
		}

		return o;
	};

	function wiki2html(txt, baseurl) {
		Insta.conf.baseUrl = baseurl;
		return Insta.convert(txt);
	}
	// ENDFILE: livepreview.js

	// STARTFILE: pageinfo.js
	function popupFilterPageSize(data) {
		return formatBytes(data.length);
	}

	function popupFilterCountLinks(data) {
		var num = countLinks(data);
		return String(num) + '&nbsp;' + (num != 1 ? popupString('wikiLinks') : popupString('wikiLink'));
	}

	function popupFilterCountImages(data) {
		var num = countImages(data);
		return String(num) + '&nbsp;' + (num != 1 ? popupString('images') : popupString('image'));
	}

	function popupFilterCountCategories(data) {
		var num = countCategories(data);
		return (
			String(num) + '&nbsp;' + (num != 1 ? popupString('categories') : popupString('category'))
		);
	}

	function popupFilterLastModified(data, download) {
		var lastmod = download.lastModified;
		var now = new Date();
		var age = now - lastmod;
		if (lastmod && getValueOf('popupLastModified')) {
			return tprintf('%s old', [formatAge(age)]).replace(RegExp(' ', 'g'), '&nbsp;');
		}
		return '';
	}

	function popupFilterWikibaseItem(data, download) {
		return download.wikibaseItem
			? tprintf('<a href="%s">%s</a>', [
				download.wikibaseRepo.replace(/\$1/g, download.wikibaseItem),
				download.wikibaseItem,
			])
			: '';
	}

	function formatAge(age) {
		// coerce into a number
		var a = 0 + age,
			aa = a;

		var seclen = 1000;
		var minlen = 60 * seclen;
		var hourlen = 60 * minlen;
		var daylen = 24 * hourlen;
		var weeklen = 7 * daylen;

		var numweeks = (a - (a % weeklen)) / weeklen;
		a = a - numweeks * weeklen;
		var sweeks = addunit(numweeks, 'week');
		var numdays = (a - (a % daylen)) / daylen;
		a = a - numdays * daylen;
		var sdays = addunit(numdays, 'day');
		var numhours = (a - (a % hourlen)) / hourlen;
		a = a - numhours * hourlen;
		var shours = addunit(numhours, 'hour');
		var nummins = (a - (a % minlen)) / minlen;
		a = a - nummins * minlen;
		var smins = addunit(nummins, 'minute');
		var numsecs = (a - (a % seclen)) / seclen;
		a = a - numsecs * seclen;
		var ssecs = addunit(numsecs, 'second');

		if (aa > 4 * weeklen) {
			return sweeks;
		}
		if (aa > weeklen) {
			return sweeks + ' ' + sdays;
		}
		if (aa > daylen) {
			return sdays + ' ' + shours;
		}
		if (aa > 6 * hourlen) {
			return shours;
		}
		if (aa > hourlen) {
			return shours + ' ' + smins;
		}
		if (aa > 10 * minlen) {
			return smins;
		}
		if (aa > minlen) {
			return smins + ' ' + ssecs;
		}
		return ssecs;
	}

	function addunit(num, str) {
		return String(num) + ' ' + (num != 1 ? popupString(str + 's') : popupString(str));
	}

	function runPopupFilters(list, data, download) {
		var ret = [];
		for (var i = 0; i < list.length; ++i) {
			if (list[i] && typeof list[i] == 'function') {
				var s = list[i](data, download, download.owner.article);
				if (s) {
					ret.push(s);
				}
			}
		}
		return ret;
	}

	function getPageInfo(data, download) {
		if (!data || data.length === 0) {
			return popupString('Empty page');
		}

		var popupFilters = getValueOf('popupFilters') || [];
		var extraPopupFilters = getValueOf('extraPopupFilters') || [];
		var pageInfoArray = runPopupFilters(popupFilters.concat(extraPopupFilters), data, download);

		var pageInfo = pageInfoArray.join(', ');
		if (pageInfo !== '') {
			pageInfo = upcaseFirst(pageInfo);
		}
		return pageInfo;
	}

	// this could be improved!
	function countLinks(wikiText) {
		return wikiText.split('[[').length - 1;
	}

	// if N = # matches, n = # brackets, then
	// String.parenSplit(regex) intersperses the N+1 split elements
	// with Nn other elements. So total length is
	// L= N+1 + Nn = N(n+1)+1. So N=(L-1)/(n+1).

	function countImages(wikiText) {
		return (wikiText.parenSplit(pg.re.image).length - 1) / (pg.re.imageBracketCount + 1);
	}

	function countCategories(wikiText) {
		return (wikiText.parenSplit(pg.re.category).length - 1) / (pg.re.categoryBracketCount + 1);
	}

	function popupFilterStubDetect(data, download, article) {
		var counts = stubCount(data, article);
		if (counts.real) {
			return popupString('stub');
		}
		if (counts.sect) {
			return popupString('section stub');
		}
		return '';
	}

	function popupFilterDisambigDetect(data, download, article) {
		if (!getValueOf('popupAllDabsStubs') && article.namespace()) {
			return '';
		}
		return isDisambig(data, article) ? popupString('disambig') : '';
	}

	function formatBytes(num) {
		return num > 949
			? Math.round(num / 100) / 10 + popupString('kB')
			: num + '&nbsp;' + popupString('bytes');
	}
	// ENDFILE: pageinfo.js

	// STARTFILE: titles.js
	/**
	 * @fileoverview Defines the {@link Title} class, and associated crufty functions.

	 * <code>Title</code> deals with article titles and their various
	 * forms.  {@link Stringwrapper} is the parent class of
	 * <code>Title</code>, which exists simply to make things a little
	 * neater.
	 */

	/**
	 * Creates a new Stringwrapper.
	 * @constructor

	 * @class the Stringwrapper class. This base class is not really
	 * useful on its own; it just wraps various common string operations.
	 */
	function Stringwrapper() {
		/**
		 * Wrapper for this.toString().indexOf()
		 * @param {String} x
		 * @type {number}
		 */
		this.indexOf = function (x) {
			return this.toString().indexOf(x);
		};
		/**
		 * Returns this.value.
		 * @type {string}
		 */
		this.toString = function () {
			return this.value;
		};
		/**
		 * Wrapper for {@link String#parenSplit} applied to this.toString()
		 * @param {RegExp} x
		 * @type {Array}
		 */
		this.parenSplit = function (x) {
			return this.toString().parenSplit(x);
		};
		/**
		 * Wrapper for this.toString().substring()
		 * @param {String} x
		 * @param {String} y (optional)
		 * @type {string}
		 */
		this.substring = function (x, y) {
			if (typeof y == 'undefined') {
				return this.toString().substring(x);
			}
			return this.toString().substring(x, y);
		};
		/**
		 * Wrapper for this.toString().split()
		 * @param {String} x
		 * @type {Array}
		 */
		this.split = function (x) {
			return this.toString().split(x);
		};
		/**
		 * Wrapper for this.toString().replace()
		 * @param {String} x
		 * @param {String} y
		 * @type {string}
		 */
		this.replace = function (x, y) {
			return this.toString().replace(x, y);
		};
	}

	/**
	 * Creates a new <code>Title</code>.
	 * @constructor
	 *
	 * @class The Title class. Holds article titles and converts them into
	 * various forms. Also deals with anchors, by which we mean the bits
	 * of the article URL after a # character, representing locations
	 * within an article.
	 *
	 * @param {String} value The initial value to assign to the
	 * article. This must be the canonical title (see {@link
	 * Title#value}. Omit this in the constructor and use another function
	 * to set the title if this is unavailable.
	 */
	function Title(val) {
		/**
		 * The canonical article title. This must be in UTF-8 with no
		 * entities, escaping or nasties. Also, underscores should be
		 * replaced with spaces.
		 * @type {string}
		 * @private
		 */
		this.value = null;

		/**
		 * The canonical form of the anchor. This should be exactly as
		 * it appears in the URL, i.e. with the .C3.0A bits in.
		 * @type {string}
		 */
		this.anchor = '';

		this.setUtf(val);
	}
	Title.prototype = new Stringwrapper();
	/**
	 * Returns the canonical representation of the article title, optionally without anchor.
	 * @param {boolean} omitAnchor
	 * @fixme Decide specs for anchor
	 * @return String The article title and the anchor.
	 */
	Title.prototype.toString = function (omitAnchor) {
		return this.value + (!omitAnchor && this.anchor ? '#' + this.anchorString() : '');
	};
	Title.prototype.anchorString = function () {
		if (!this.anchor) {
			return '';
		}
		var split = this.anchor.parenSplit(/((?:[.][0-9A-F]{2})+)/);
		var len = split.length;
		var value;
		for (var j = 1; j < len; j += 2) {
			// FIXME s/decodeURI/decodeURIComponent/g ?
			value = split[j].split('.').join('%');
			try {
				value = decodeURIComponent(value);
			} catch (e) {
				// cannot decode
			}
			split[j] = value.split('_').join(' ');
		}
		return split.join('');
	};
	Title.prototype.urlAnchor = function () {
		var split = this.anchor.parenSplit('/((?:[%][0-9A-F]{2})+)/');
		var len = split.length;
		for (var j = 1; j < len; j += 2) {
			split[j] = split[j].split('%').join('.');
		}
		return split.join('');
	};
	Title.prototype.anchorFromUtf = function (str) {
		this.anchor = encodeURIComponent(str.split(' ').join('_'))
			.split('%3A')
			.join(':')
			.split("'")
			.join('%27')
			.split('%')
			.join('.');
	};
	Title.fromURL = function (h) {
		return new Title().fromURL(h);
	};
	Title.prototype.fromURL = function (h) {
		if (typeof h != 'string') {
			this.value = null;
			return this;
		}

		// NOTE : playing with decodeURI, encodeURI, escape, unescape,
		// we seem to be able to replicate the IE borked encoding

		// IE doesn't do this new-fangled utf-8 thing.
		// and it's worse than that.
		// IE seems to treat the query string differently to the rest of the url
		// the query is treated as bona-fide utf8, but the first bit of the url is pissed around with

		// we fix up & for all browsers, just in case.
		var splitted = h.split('?');
		splitted[0] = splitted[0].split('&').join('%26');

		h = splitted.join('?');

		var contribs = pg.re.contribs.exec(h);
		if (contribs) {
			if (contribs[1] == 'title=') {
				contribs[3] = contribs[3].split('+').join(' ');
			}
			var u = new Title(contribs[3]);
			this.setUtf(
				this.decodeNasties(
					mw.config.get('wgFormattedNamespaces')[pg.nsUserId] + ':' + u.stripNamespace()
				)
			);
			return this;
		}

		var email = pg.re.email.exec(h);
		if (email) {
			this.setUtf(
				this.decodeNasties(
					mw.config.get('wgFormattedNamespaces')[pg.nsUserId] +
						':' +
						new Title(email[3]).stripNamespace()
				)
			);
			return this;
		}

		var backlinks = pg.re.backlinks.exec(h);
		if (backlinks) {
			this.setUtf(this.decodeNasties(new Title(backlinks[3])));
			return this;
		}

		//A dummy title object for a Special:Diff link.
		var specialdiff = pg.re.specialdiff.exec(h);
		if (specialdiff) {
			this.setUtf(
				this.decodeNasties(
					new Title(mw.config.get('wgFormattedNamespaces')[pg.nsSpecialId] + ':Diff')
				)
			);
			return this;
		}

		// no more special cases to check --
		// hopefully it's not a disguised user-related or specially treated special page
		// Includes references
		var m = pg.re.main.exec(h);
		if (m === null) {
			this.value = null;
		} else {
			var fromBotInterface = /[?](.+[&])?title=/.test(h);
			if (fromBotInterface) {
				m[2] = m[2].split('+').join('_');
			}
			var extracted = m[2] + (m[3] ? '#' + m[3] : '');
			if (pg.flag.isSafari && /%25[0-9A-Fa-f]{2}/.test(extracted)) {
				// Fix Safari issue
				// Safari sometimes encodes % as %25 in UTF-8 encoded strings like %E5%A3 -> %25E5%25A3.
				this.setUtf(decodeURIComponent(unescape(extracted)));
			} else {
				this.setUtf(this.decodeNasties(extracted));
			}
		}
		return this;
	};
	Title.prototype.decodeNasties = function (txt) {
		// myDecodeURI uses decodeExtras, which removes _,
		// thus ruining citations previews, which are formated as "cite_note-1"
		try {
			var ret = decodeURI(this.decodeEscapes(txt));
			ret = ret.replace(/[_ ]*$/, '');
			return ret;
		} catch (e) {
			return txt; // cannot decode
		}
	};
	// Decode valid %-encodings, otherwise escape them
	Title.prototype.decodeEscapes = function (txt) {
		var split = txt.parenSplit(/((?:[%][0-9A-Fa-f]{2})+)/);
		var len = split.length;
		// No %-encoded items found, so replace the literal %
		if (len === 1) {
			return split[0].replace(/%(?![0-9a-fA-F][0-9a-fA-F])/g, '%25');
		}
		for (var i = 1; i < len; i = i + 2) {
			split[i] = decodeURIComponent(split[i]);
		}
		return split.join('');
	};
	Title.fromAnchor = function (a) {
		return new Title().fromAnchor(a);
	};
	Title.prototype.fromAnchor = function (a) {
		if (!a) {
			this.value = null;
			return this;
		}
		return this.fromURL(a.href);
	};
	Title.fromWikiText = function (txt) {
		return new Title().fromWikiText(txt);
	};
	Title.prototype.fromWikiText = function (txt) {
		// FIXME - testing needed
		txt = myDecodeURI(txt);
		this.setUtf(txt);
		return this;
	};
	Title.prototype.hintValue = function () {
		if (!this.value) {
			return '';
		}
		return safeDecodeURI(this.value);
	};
	Title.prototype.toUserName = function (withNs) {
		if (this.namespaceId() != pg.nsUserId && this.namespaceId() != pg.nsUsertalkId) {
			this.value = null;
			return;
		}
		this.value =
			(withNs ? mw.config.get('wgFormattedNamespaces')[pg.nsUserId] + ':' : '') +
			this.stripNamespace().split('/')[0];
	};
	Title.prototype.userName = function (withNs) {
		var t = new Title(this.value);
		t.toUserName(withNs);
		if (t.value) {
			return t;
		}
		return null;
	};
	Title.prototype.toTalkPage = function () {
		// convert article to a talk page, or if we can't, return null
		// In other words: return null if this ALREADY IS a talk page
		// and return the corresponding talk page otherwise
		//
		// Per https://www.mediawiki.org/wiki/Manual:Namespace#Subject_and_talk_namespaces
		// * All discussion namespaces have odd-integer indices
		// * The discussion namespace index for a specific namespace with index n is n + 1
		if (this.value === null) {
			return null;
		}

		var namespaceId = this.namespaceId();
		if (namespaceId >= 0 && namespaceId % 2 === 0) {
			//non-special and subject namespace
			var localizedNamespace = mw.config.get('wgFormattedNamespaces')[namespaceId + 1];
			if (typeof localizedNamespace !== 'undefined') {
				if (localizedNamespace === '') {
					this.value = this.stripNamespace();
				} else {
					this.value = localizedNamespace.split(' ').join('_') + ':' + this.stripNamespace();
				}
				return this.value;
			}
		}

		this.value = null;
		return null;
	};
	// Return canonical, localized namespace
	Title.prototype.namespace = function () {
		return mw.config.get('wgFormattedNamespaces')[this.namespaceId()];
	};
	Title.prototype.namespaceId = function () {
		var n = this.value.indexOf(':');
		if (n < 0) {
			return 0;
		} //mainspace
		var namespaceId =
			mw.config.get('wgNamespaceIds')[
				this.value.substring(0, n).split(' ').join('_').toLowerCase()
			];
		if (typeof namespaceId == 'undefined') {
			return 0;
		} //mainspace
		return namespaceId;
	};
	Title.prototype.talkPage = function () {
		var t = new Title(this.value);
		t.toTalkPage();
		if (t.value) {
			return t;
		}
		return null;
	};
	Title.prototype.isTalkPage = function () {
		if (this.talkPage() === null) {
			return true;
		}
		return false;
	};
	Title.prototype.toArticleFromTalkPage = function () {
		//largely copy/paste from toTalkPage above.
		if (this.value === null) {
			return null;
		}

		var namespaceId = this.namespaceId();
		if (namespaceId >= 0 && namespaceId % 2 == 1) {
			//non-special and talk namespace
			var localizedNamespace = mw.config.get('wgFormattedNamespaces')[namespaceId - 1];
			if (typeof localizedNamespace !== 'undefined') {
				if (localizedNamespace === '') {
					this.value = this.stripNamespace();
				} else {
					this.value = localizedNamespace.split(' ').join('_') + ':' + this.stripNamespace();
				}
				return this.value;
			}
		}

		this.value = null;
		return null;
	};
	Title.prototype.articleFromTalkPage = function () {
		var t = new Title(this.value);
		t.toArticleFromTalkPage();
		if (t.value) {
			return t;
		}
		return null;
	};
	Title.prototype.articleFromTalkOrArticle = function () {
		var t = new Title(this.value);
		if (t.toArticleFromTalkPage()) {
			return t;
		}
		return this;
	};
	Title.prototype.isIpUser = function () {
		return pg.re.ipUser.test(this.userName());
	};
	Title.prototype.stripNamespace = function () {
		// returns a string, not a Title
		var n = this.value.indexOf(':');
		if (n < 0) {
			return this.value;
		}
		var namespaceId = this.namespaceId();
		if (namespaceId === pg.nsMainspaceId) {
			return this.value;
		}
		return this.value.substring(n + 1);
	};
	Title.prototype.setUtf = function (value) {
		if (!value) {
			this.value = '';
			return;
		}
		var anch = value.indexOf('#');
		if (anch < 0) {
			this.value = value.split('_').join(' ');
			this.anchor = '';
			return;
		}
		this.value = value.substring(0, anch).split('_').join(' ');
		this.anchor = value.substring(anch + 1);
		this.ns = null; // wait until namespace() is called
	};
	Title.prototype.setUrl = function (urlfrag) {
		var anch = urlfrag.indexOf('#');
		this.value = safeDecodeURI(urlfrag.substring(0, anch));
		this.anchor = this.value.substring(anch + 1);
	};
	Title.prototype.append = function (x) {
		this.setUtf(this.value + x);
	};
	Title.prototype.urlString = function (x) {
		if (!x) {
			x = {};
		}
		var v = this.toString(true);
		if (!x.omitAnchor && this.anchor) {
			v += '#' + this.urlAnchor();
		}
		if (!x.keepSpaces) {
			v = v.split(' ').join('_');
		}
		return encodeURI(v).split('&').join('%26').split('?').join('%3F').split('+').join('%2B');
	};
	Title.prototype.removeAnchor = function () {
		return new Title(this.toString(true));
	};
	Title.prototype.toUrl = function () {
		return pg.wiki.titlebase + this.urlString();
	};

	function parseParams(url) {
		var specialDiff = pg.re.specialdiff.exec(url);
		if (specialDiff) {
			var split = specialDiff[1].split('/');
			if (split.length == 1) {
				return { oldid: split[0], diff: 'prev' };
			} else if (split.length == 2) {
				return { oldid: split[0], diff: split[1] };
			}
		}

		var ret = {};
		if (url.indexOf('?') == -1) {
			return ret;
		}
		url = url.split('#')[0];
		var s = url.split('?').slice(1).join();
		var t = s.split('&');
		for (var i = 0; i < t.length; ++i) {
			var z = t[i].split('=');
			z.push(null);
			ret[z[0]] = z[1];
		}
		//Diff revision with no oldid is interpreted as a diff to the previous revision by MediaWiki
		if (ret.diff && typeof ret.oldid === 'undefined') {
			ret.oldid = 'prev';
		}
		//Documentation seems to say something different, but oldid can also accept prev/next, and
		//Echo is emitting such URLs. Simple fixup during parameter decoding:
		if (ret.oldid && (ret.oldid === 'prev' || ret.oldid === 'next' || ret.oldid === 'cur')) {
			var helper = ret.diff;
			ret.diff = ret.oldid;
			ret.oldid = helper;
		}
		return ret;
	}

	// (a) myDecodeURI (first standard decodeURI, then pg.re.urlNoPopup)
	// (b) change spaces to underscores
	// (c) encodeURI (just the straight one, no pg.re.urlNoPopup)

	function myDecodeURI(str) {
		var ret;
		// FIXME decodeURIComponent??
		try {
			ret = decodeURI(str.toString());
		} catch (summat) {
			return str;
		}
		for (var i = 0; i < pg.misc.decodeExtras.length; ++i) {
			var from = pg.misc.decodeExtras[i].from;
			var to = pg.misc.decodeExtras[i].to;
			ret = ret.split(from).join(to);
		}
		return ret;
	}

	function safeDecodeURI(str) {
		var ret = myDecodeURI(str);
		return ret || str;
	}

	///////////
	// TESTS //
	///////////

	function isDisambig(data, article) {
		if (!getValueOf('popupAllDabsStubs') && article.namespace()) {
			return false;
		}
		return !article.isTalkPage() && pg.re.disambig.test(data);
	}

	function stubCount(data, article) {
		if (!getValueOf('popupAllDabsStubs') && article.namespace()) {
			return false;
		}
		var sectStub = 0;
		var realStub = 0;
		if (pg.re.stub.test(data)) {
			var s = data.parenSplit(pg.re.stub);
			for (var i = 1; i < s.length; i = i + 2) {
				if (s[i]) {
					++sectStub;
				} else {
					++realStub;
				}
			}
		}
		return { real: realStub, sect: sectStub };
	}

	function isValidImageName(str) {
		// extend as needed...
		return str.indexOf('{') == -1;
	}

	function isInStrippableNamespace(article) {
		// Does the namespace allow subpages
		// Note, would be better if we had access to wgNamespacesWithSubpages
		return article.namespaceId() !== 0;
	}

	function isInMainNamespace(article) {
		return article.namespaceId() === 0;
	}

	function anchorContainsImage(a) {
		// iterate over children of anchor a
		// see if any are images
		if (a === null) {
			return false;
		}
		var kids = a.childNodes;
		for (var i = 0; i < kids.length; ++i) {
			if (kids[i].nodeName == 'IMG') {
				return true;
			}
		}
		return false;
	}
	function isPopupLink(a) {
		// NB for performance reasons, TOC links generally return true
		// they should be stripped out later

		if (!markNopopupSpanLinks.done) {
			markNopopupSpanLinks();
		}
		if (a.inNopopupSpan) {
			return false;
		}

		// FIXME is this faster inline?
		if (a.onmousedown || a.getAttribute('nopopup')) {
			return false;
		}
		var h = a.href;
		if (h === document.location.href + '#') {
			return false;
		}
		if (!pg.re.basenames.test(h)) {
			return false;
		}
		if (!pg.re.urlNoPopup.test(h)) {
			return true;
		}
		return (
			(pg.re.email.test(h) ||
				pg.re.contribs.test(h) ||
				pg.re.backlinks.test(h) ||
				pg.re.specialdiff.test(h)) &&
			h.indexOf('&limit=') == -1
		);
	}

	function markNopopupSpanLinks() {
		if (!getValueOf('popupOnlyArticleLinks')) {
			fixVectorMenuPopups();
		}

		var s = $('.nopopups').toArray();
		for (var i = 0; i < s.length; ++i) {
			var as = s[i].getElementsByTagName('a');
			for (var j = 0; j < as.length; ++j) {
				as[j].inNopopupSpan = true;
			}
		}

		markNopopupSpanLinks.done = true;
	}

	function fixVectorMenuPopups() {
		$('nav.vector-menu h3:first a:first').prop('inNopopupSpan', true);
	}
	// ENDFILE: titles.js

	// STARTFILE: getpage.js
	//////////////////////////////////////////////////
	// Wiki-specific downloading
	//

	// Schematic for a getWiki call
	//
	//             getPageWithCaching
	//					|
	//	   false		|		  true
	// getPage<-[findPictureInCache]->-onComplete(a fake download)
	//   \.
	//	 (async)->addPageToCache(download)->-onComplete(download)

	// check cache to see if page exists

	function getPageWithCaching(url, onComplete, owner) {
		log('getPageWithCaching, url=' + url);
		var i = findInPageCache(url);
		var d;
		if (i > -1) {
			d = fakeDownload(
				url,
				owner.idNumber,
				onComplete,
				pg.cache.pages[i].data,
				pg.cache.pages[i].lastModified,
				owner
			);
		} else {
			d = getPage(url, onComplete, owner);
			if (d && owner && owner.addDownload) {
				owner.addDownload(d);
				d.owner = owner;
			}
		}
	}

	function getPage(url, onComplete, owner) {
		log('getPage');
		var callback = function (d) {
			if (!d.aborted) {
				addPageToCache(d);
				onComplete(d);
			}
		};
		return startDownload(url, owner.idNumber, callback);
	}

	function findInPageCache(url) {
		for (var i = 0; i < pg.cache.pages.length; ++i) {
			if (url == pg.cache.pages[i].url) {
				return i;
			}
		}
		return -1;
	}

	function addPageToCache(download) {
		log('addPageToCache ' + download.url);
		var page = {
			url: download.url,
			data: download.data,
			lastModified: download.lastModified,
		};
		return pg.cache.pages.push(page);
	}
	// ENDFILE: getpage.js

	// STARTFILE: parensplit.js
	//////////////////////////////////////////////////
	// parenSplit

	// String.prototype.parenSplit should do what ECMAscript says String.prototype.split does,
	// interspersing paren matches (regex capturing groups) between the split elements.
	// i.e. 'abc'.split(/(b)/)) should return ['a','b','c'], not ['a','c']

	if (String('abc'.split(/(b)/)) != 'a,b,c') {
		// broken String.split, e.g. konq, IE < 10
		String.prototype.parenSplit = function (re) {
			re = nonGlobalRegex(re);
			var s = this;
			var m = re.exec(s);
			var ret = [];
			while (m && s) {
				// without the following loop, we have
				// 'ab'.parenSplit(/a|(b)/) != 'ab'.split(/a|(b)/)
				for (var i = 0; i < m.length; ++i) {
					if (typeof m[i] == 'undefined') {
						m[i] = '';
					}
				}
				ret.push(s.substring(0, m.index));
				ret = ret.concat(m.slice(1));
				s = s.substring(m.index + m[0].length);
				m = re.exec(s);
			}
			ret.push(s);
			return ret;
		};
	} else {
		String.prototype.parenSplit = function (re) {
			return this.split(re);
		};
		String.prototype.parenSplit.isNative = true;
	}

	function nonGlobalRegex(re) {
		var s = re.toString();
		var flags = '';
		for (var j = s.length; s.charAt(j) != '/'; --j) {
			if (s.charAt(j) != 'g') {
				flags += s.charAt(j);
			}
		}
		var t = s.substring(1, j);
		return RegExp(t, flags);
	}
	// ENDFILE: parensplit.js

	// STARTFILE: tools.js
	// IE madness with encoding
	// ========================
	//
	// suppose throughout that the page is in utf8, like wikipedia
	//
	// if a is an anchor DOM element and a.href should consist of
	//
	// http://host.name.here/wiki/foo?bar=baz
	//
	// then IE gives foo as "latin1-encoded" utf8; we have foo = decode_utf8(decodeURI(foo_ie))
	// but IE gives bar=baz correctly as plain utf8
	//
	// ---------------------------------
	//
	// IE's xmlhttp doesn't understand utf8 urls. Have to use encodeURI here.
	//
	// ---------------------------------
	//
	// summat else

	// Source: http://aktuell.de.selfhtml.org/artikel/javascript/utf8b64/utf8.htm

	function getJsObj(json) {
		try {
			var json_ret = JSON.parse(json);
			if (json_ret.warnings) {
				for (var w = 0; w < json_ret.warnings.length; w++) {
					if (json_ret.warnings[w]['*']) {
						log(json_ret.warnings[w]['*']);
					} else {
						log(json_ret.warnings[w].warnings);
					}
				}
			} else if (json_ret.error) {
				errlog(json_ret.error.code + ': ' + json_ret.error.info);
			}
			return json_ret;
		} catch (someError) {
			errlog('Something went wrong with getJsObj, json=' + json);
			return 1;
		}
	}

	function anyChild(obj) {
		for (var p in obj) {
			return obj[p];
		}
		return null;
	}

	function upcaseFirst(str) {
		if (typeof str != typeof '' || str === '') {
			return '';
		}
		return str.charAt(0).toUpperCase() + str.substring(1);
	}

	function findInArray(arr, foo) {
		if (!arr || !arr.length) {
			return -1;
		}
		var len = arr.length;
		for (var i = 0; i < len; ++i) {
			if (arr[i] == foo) {
				return i;
			}
		}
		return -1;
	}

	/* eslint-disable no-unused-vars */
	function nextOne(array, value) {
		// NB if the array has two consecutive entries equal
		//	then this will loop on successive calls
		var i = findInArray(array, value);
		if (i < 0) {
			return null;
		}
		return array[i + 1];
	}
	/* eslint-enable no-unused-vars */

	function literalizeRegex(str) {
		return mw.util.escapeRegExp(str);
	}

	String.prototype.entify = function () {
		//var shy='&shy;';
		return this.split('&')
			.join('&amp;')
			.split('<')
			.join('&lt;')
			.split('>')
			.join('&gt;' /*+shy*/)
			.split('"')
			.join('&quot;');
	};

	// Array filter function
	function removeNulls(val) {
		return val !== null;
	}

	function joinPath(list) {
		return list.filter(removeNulls).join('/');
	}

	function simplePrintf(str, subs) {
		if (!str || !subs) {
			return str;
		}
		var ret = [];
		var s = str.parenSplit(/(%s|\$[0-9]+)/);
		var i = 0;
		do {
			ret.push(s.shift());
			if (!s.length) {
				break;
			}
			var cmd = s.shift();
			if (cmd == '%s') {
				if (i < subs.length) {
					ret.push(subs[i]);
				} else {
					ret.push(cmd);
				}
				++i;
			} else {
				var j = parseInt(cmd.replace('$', ''), 10) - 1;
				if (j > -1 && j < subs.length) {
					ret.push(subs[j]);
				} else {
					ret.push(cmd);
				}
			}
		} while (s.length > 0);
		return ret.join('');
	}

	/* eslint-disable no-unused-vars */
	function isString(x) {
		return typeof x === 'string' || x instanceof String;
	}

	function isNumber(x) {
		return typeof x === 'number' || x instanceof Number;
	}

	function isRegExp(x) {
		return x instanceof RegExp;
	}

	function isArray(x) {
		return x instanceof Array;
	}

	function isObject(x) {
		return x instanceof Object;
	}

	function isFunction(x) {
		return !isRegExp(x) && (typeof x === 'function' || x instanceof Function);
	}
	/* eslint-enable no-unused-vars */

	function repeatString(s, mult) {
		var ret = '';
		for (var i = 0; i < mult; ++i) {
			ret += s;
		}
		return ret;
	}

	function zeroFill(s, min) {
		min = min || 2;
		var t = s.toString();
		return repeatString('0', min - t.length) + t;
	}

	function map(f, o) {
		if (isArray(o)) {
			return map_array(f, o);
		}
		return map_object(f, o);
	}
	function map_array(f, o) {
		var ret = [];
		for (var i = 0; i < o.length; ++i) {
			ret.push(f(o[i]));
		}
		return ret;
	}
	function map_object(f, o) {
		var ret = {};
		for (var i in o) {
			ret[o] = f(o[i]);
		}
		return ret;
	}

	pg.escapeQuotesHTML = function (text) {
		return text
			.replace(/&/g, '&amp;')
			.replace(/"/g, '&quot;')
			.replace(/</g, '&lt;')
			.replace(/>/g, '&gt;');
	};

	pg.unescapeQuotesHTML = function (html) {
		// From https://stackoverflow.com/a/7394787
		// This seems to be implemented correctly on all major browsers now, so we
		// don't have to make our own function.
		var txt = document.createElement('textarea');
		txt.innerHTML = html;
		return txt.value;
	};

	// ENDFILE: tools.js

	// STARTFILE: dab.js
	//////////////////////////////////////////////////
	// Dab-fixing code
	//

	function retargetDab(newTarget, oldTarget, friendlyCurrentArticleName, titleToEdit) {
		log('retargetDab: newTarget=' + newTarget + ' oldTarget=' + oldTarget);
		return changeLinkTargetLink({
			newTarget: newTarget,
			text: newTarget.split(' ').join('&nbsp;'),
			hint: tprintf('disambigHint', [newTarget]),
			summary: simplePrintf(getValueOf('popupFixDabsSummary'), [
				friendlyCurrentArticleName,
				newTarget,
			]),
			clickButton: getValueOf('popupDabsAutoClick'),
			minor: true,
			oldTarget: oldTarget,
			watch: getValueOf('popupWatchDisambiggedPages'),
			title: titleToEdit,
		});
	}

	function listLinks(wikitext, oldTarget, titleToEdit) {
		// mediawiki strips trailing spaces, so we do the same
		// testcase: https://en.wikipedia.org/w/index.php?title=Radial&oldid=97365633
		var reg = RegExp('\\[\\[([^|]*?) *(\\||\\]\\])', 'gi');
		var ret = [];
		var splitted = wikitext.parenSplit(reg);
		// ^[a-z]+ should match interwiki links, hopefully (case-insensitive)
		// and ^[a-z]* should match those and [[:Category...]] style links too
		var omitRegex = RegExp('^[a-z]*:|^[Ss]pecial:|^[Ii]mage|^[Cc]ategory');
		var friendlyCurrentArticleName = oldTarget.toString();
		var wikPos = getValueOf('popupDabWiktionary');

		for (var i = 1; i < splitted.length; i = i + 3) {
			if (
				typeof splitted[i] == typeof 'string' &&
				splitted[i].length > 0 &&
				!omitRegex.test(splitted[i])
			) {
				ret.push(retargetDab(splitted[i], oldTarget, friendlyCurrentArticleName, titleToEdit));
			} /* if */
		} /* for loop */

		ret = rmDupesFromSortedList(ret.sort());

		if (wikPos) {
			var wikTarget =
				'wiktionary:' +
				friendlyCurrentArticleName.replace(RegExp('^(.+)\\s+[(][^)]+[)]\\s*$'), '$1');

			var meth;
			if (wikPos.toLowerCase() == 'first') {
				meth = 'unshift';
			} else {
				meth = 'push';
			}

			ret[meth](retargetDab(wikTarget, oldTarget, friendlyCurrentArticleName, titleToEdit));
		}

		ret.push(
			changeLinkTargetLink({
				newTarget: null,
				text: popupString('remove this link').split(' ').join('&nbsp;'),
				hint: popupString('remove all links to this disambig page from this article'),
				clickButton: getValueOf('popupDabsAutoClick'),
				oldTarget: oldTarget,
				summary: simplePrintf(getValueOf('popupRmDabLinkSummary'), [friendlyCurrentArticleName]),
				watch: getValueOf('popupWatchDisambiggedPages'),
				title: titleToEdit,
			})
		);
		return ret;
	}

	function rmDupesFromSortedList(list) {
		var ret = [];
		for (var i = 0; i < list.length; ++i) {
			if (ret.length === 0 || list[i] != ret[ret.length - 1]) {
				ret.push(list[i]);
			}
		}
		return ret;
	}

	function makeFixDab(data, navpop) {
		// grab title from parent popup if there is one; default exists in changeLinkTargetLink
		var titleToEdit = navpop.parentPopup && navpop.parentPopup.article.toString();
		var list = listLinks(data, navpop.originalArticle, titleToEdit);
		if (list.length === 0) {
			log('listLinks returned empty list');
			return null;
		}
		var html = '<hr />' + popupString('Click to disambiguate this link to:') + '<br>';
		html += list.join(', ');
		return html;
	}

	function makeFixDabs(wikiText, navpop) {
		if (
			getValueOf('popupFixDabs') &&
			isDisambig(wikiText, navpop.article) &&
			Title.fromURL(location.href).namespaceId() != pg.nsSpecialId &&
			navpop.article.talkPage()
		) {
			setPopupHTML(makeFixDab(wikiText, navpop), 'popupFixDab', navpop.idNumber);
		}
	}

	function popupRedlinkHTML(article) {
		return changeLinkTargetLink({
			newTarget: null,
			text: popupString('remove this link').split(' ').join('&nbsp;'),
			hint: popupString('remove all links to this page from this article'),
			clickButton: getValueOf('popupRedlinkAutoClick'),
			oldTarget: article.toString(),
			summary: simplePrintf(getValueOf('popupRedlinkSummary'), [article.toString()]),
		});
	}
	// ENDFILE: dab.js

	// STARTFILE: htmloutput.js

	// this has to use a timer loop as we don't know if the DOM element exists when we want to set the text
	function setPopupHTML(str, elementId, popupId, onSuccess, append) {
		if (typeof popupId === 'undefined') {
			//console.error('popupId is not defined in setPopupHTML, html='+str.substring(0,100));
			popupId = pg.idNumber;
		}

		var popupElement = document.getElementById(elementId + popupId);
		if (popupElement) {
			if (!append) {
				popupElement.innerHTML = '';
			}
			if (isString(str)) {
				popupElement.innerHTML += str;
			} else {
				popupElement.appendChild(str);
			}
			if (onSuccess) {
				onSuccess();
			}
			setTimeout(checkPopupPosition, 100);
			return true;
		} else {
			// call this function again in a little while...
			setTimeout(function () {
				setPopupHTML(str, elementId, popupId, onSuccess);
			}, 600);
		}
		return null;
	}

	function setPopupTrailer(str, id) {
		return setPopupHTML(str, 'popupData', id);
	}

	// args.navpopup is mandatory
	// optional: args.redir, args.redirTarget
	// FIXME: ye gods, this is ugly stuff
	function fillEmptySpans(args) {
		// if redir is present and true then redirTarget is mandatory
		var redir = true;
		var rcid;
		if (typeof args != 'object' || typeof args.redir == 'undefined' || !args.redir) {
			redir = false;
		}
		var a = args.navpopup.parentAnchor;

		var article,
			hint = null,
			oldid = null,
			params = {};
		if (redir && typeof args.redirTarget == typeof {}) {
			article = args.redirTarget;
			//hint=article.hintValue();
		} else {
			article = new Title().fromAnchor(a);
			hint = a.originalTitle || article.hintValue();
			params = parseParams(a.href);
			oldid = getValueOf('popupHistoricalLinks') ? params.oldid : null;
			rcid = params.rcid;
		}
		var x = {
			article: article,
			hint: hint,
			oldid: oldid,
			rcid: rcid,
			navpop: args.navpopup,
			params: params,
		};

		var structure = pg.structures[getValueOf('popupStructure')];
		if (typeof structure != 'object') {
			setPopupHTML(
				'popupError',
				'Unknown structure (this should never happen): ' + pg.option.popupStructure,
				args.navpopup.idNumber
			);
			return;
		}
		var spans = flatten(pg.misc.layout);
		var numspans = spans.length;
		var redirs = pg.misc.redirSpans;

		for (var i = 0; i < numspans; ++i) {
			var found = redirs && redirs.indexOf(spans[i]) !== -1;
			//log('redir='+redir+', found='+found+', spans[i]='+spans[i]);
			if ((found && !redir) || (!found && redir)) {
				//log('skipping this set of the loop');
				continue;
			}
			var structurefn = structure[spans[i]];
			if (structurefn === undefined) {
				// nothing to do for this structure part
				continue;
			}
			var setfn = setPopupHTML;
			if (
				getValueOf('popupActiveNavlinks') &&
				(spans[i].indexOf('popupTopLinks') === 0 || spans[i].indexOf('popupRedirTopLinks') === 0)
			) {
				setfn = setPopupTipsAndHTML;
			}
			switch (typeof structurefn) {
				case 'function':
					log(
						'running ' +
							spans[i] +
							'({article:' +
							x.article +
							', hint:' +
							x.hint +
							', oldid: ' +
							x.oldid +
							'})'
					);
					setfn(structurefn(x), spans[i], args.navpopup.idNumber);
					break;
				case 'string':
					setfn(structurefn, spans[i], args.navpopup.idNumber);
					break;
				default:
					errlog('unknown thing with label ' + spans[i] + ' (span index was ' + i + ')');
					break;
			}
		}
	}

	// flatten an array
	function flatten(list, start) {
		var ret = [];
		if (typeof start == 'undefined') {
			start = 0;
		}
		for (var i = start; i < list.length; ++i) {
			if (typeof list[i] == typeof []) {
				return ret.concat(flatten(list[i])).concat(flatten(list, i + 1));
			} else {
				ret.push(list[i]);
			}
		}
		return ret;
	}

	// Generate html for whole popup
	function popupHTML(a) {
		getValueOf('popupStructure');
		var structure = pg.structures[pg.option.popupStructure];
		if (typeof structure != 'object') {
			//return 'Unknown structure: '+pg.option.popupStructure;
			// override user choice
			pg.option.popupStructure = pg.optionDefault.popupStructure;
			return popupHTML(a);
		}
		if (typeof structure.popupLayout != 'function') {
			return 'Bad layout';
		}
		pg.misc.layout = structure.popupLayout();
		if (typeof structure.popupRedirSpans === 'function') {
			pg.misc.redirSpans = structure.popupRedirSpans();
		} else {
			pg.misc.redirSpans = [];
		}
		return makeEmptySpans(pg.misc.layout, a.navpopup);
	}

	function makeEmptySpans(list, navpop) {
		var ret = '';
		for (var i = 0; i < list.length; ++i) {
			if (typeof list[i] == typeof '') {
				ret += emptySpanHTML(list[i], navpop.idNumber, 'div');
			} else if (typeof list[i] == typeof [] && list[i].length > 0) {
				ret = ret.parenSplit(RegExp('(</[^>]*?>$)')).join(makeEmptySpans(list[i], navpop));
			} else if (typeof list[i] == typeof {} && list[i].nodeType) {
				ret += emptySpanHTML(list[i].name, navpop.idNumber, list[i].nodeType);
			}
		}
		return ret;
	}

	function emptySpanHTML(name, id, tag, classname) {
		tag = tag || 'span';
		if (!classname) {
			classname = emptySpanHTML.classAliases[name];
		}
		classname = classname || name;
		if (name == getValueOf('popupDragHandle')) {
			classname += ' popupDragHandle';
		}
		return simplePrintf('<%s id="%s" class="%s"></%s>', [tag, name + id, classname, tag]);
	}
	emptySpanHTML.classAliases = { popupSecondPreview: 'popupPreview' };

	// generate html for popup image
	// <a id="popupImageLinkn"><img id="popupImagen">
	// where n=idNumber
	function imageHTML(article, idNumber) {
		return simplePrintf(
			'<a id="popupImageLink$1">' +
				'<img align="right" valign="top" id="popupImg$1" style="display: none;"></img>' +
				'</a>',
			[idNumber]
		);
	}

	function popTipsSoonFn(id, when, popData) {
		if (!when) {
			when = 250;
		}
		var popTips = function () {
			setupTooltips(document.getElementById(id), false, true, popData);
		};
		return function () {
			setTimeout(popTips, when, popData);
		};
	}

	function setPopupTipsAndHTML(html, divname, idnumber, popData) {
		setPopupHTML(
			html,
			divname,
			idnumber,
			getValueOf('popupSubpopups') ? popTipsSoonFn(divname + idnumber, null, popData) : null
		);
	}
	// ENDFILE: htmloutput.js

	// STARTFILE: mouseout.js
	//////////////////////////////////////////////////
	// fuzzy checks

	function fuzzyCursorOffMenus(x, y, fuzz, parent) {
		if (!parent) {
			return null;
		}
		var uls = parent.getElementsByTagName('ul');
		for (var i = 0; i < uls.length; ++i) {
			if (uls[i].className == 'popup_menu') {
				if (uls[i].offsetWidth > 0) {
					return false;
				}
			} // else {document.title+='.';}
		}
		return true;
	}

	function checkPopupPosition() {
		// stop the popup running off the right of the screen
		// FIXME avoid pg.current.link
		if (pg.current.link && pg.current.link.navpopup) {
			pg.current.link.navpopup.limitHorizontalPosition();
		}
	}

	function mouseOutWikiLink() {
		//console ('mouseOutWikiLink');
		var a = this;

		removeModifierKeyHandler(a);

		if (a.navpopup === null || typeof a.navpopup === 'undefined') {
			return;
		}
		if (!a.navpopup.isVisible()) {
			a.navpopup.banish();
			return;
		}
		restoreTitle(a);
		Navpopup.tracker.addHook(posCheckerHook(a.navpopup));
	}

	function posCheckerHook(navpop) {
		return function () {
			if (!navpop.isVisible()) {
				return true; /* remove this hook */
			}
			if (Navpopup.tracker.dirty) {
				return false;
			}
			var x = Navpopup.tracker.x,
				y = Navpopup.tracker.y;
			var mouseOverNavpop =
				navpop.isWithin(x, y, navpop.fuzz, navpop.mainDiv) ||
				!fuzzyCursorOffMenus(x, y, navpop.fuzz, navpop.mainDiv);

			// FIXME it'd be prettier to do this internal to the Navpopup objects
			var t = getValueOf('popupHideDelay');
			if (t) {
				t = t * 1000;
			}
			if (!t) {
				if (!mouseOverNavpop) {
					if (navpop.parentAnchor) {
						restoreTitle(navpop.parentAnchor);
					}
					navpop.banish();
					return true; /* remove this hook */
				}
				return false;
			}
			// we have a hide delay set
			var d = Number(new Date());
			if (!navpop.mouseLeavingTime) {
				navpop.mouseLeavingTime = d;
				return false;
			}
			if (mouseOverNavpop) {
				navpop.mouseLeavingTime = null;
				return false;
			}
			if (d - navpop.mouseLeavingTime > t) {
				navpop.mouseLeavingTime = null;
				navpop.banish();
				return true; /* remove this hook */
			}
			return false;
		};
	}

	function runStopPopupTimer(navpop) {
		// at this point, we should have left the link but remain within the popup
		// so we call this function again until we leave the popup.
		if (!navpop.stopPopupTimer) {
			navpop.stopPopupTimer = setInterval(posCheckerHook(navpop), 500);
			navpop.addHook(
				function () {
					clearInterval(navpop.stopPopupTimer);
				},
				'hide',
				'before'
			);
		}
	}
	// ENDFILE: mouseout.js

	// STARTFILE: previewmaker.js
	/**
	 * @fileoverview
	 * Defines the {@link Previewmaker} object, which generates short previews from wiki markup.
	 */

	/**
	 * Creates a new Previewmaker
	 * @constructor
	 * @class The Previewmaker class. Use an instance of this to generate short previews from Wikitext.
	 * @param {String} wikiText The Wikitext source of the page we wish to preview.
	 * @param {String} baseUrl The url we should prepend when creating relative urls.
	 * @param {Navpopup} owner The navpop associated to this preview generator
	 */
	function Previewmaker(wikiText, baseUrl, owner) {
		/** The wikitext which is manipulated to generate the preview. */
		this.originalData = wikiText;
		this.baseUrl = baseUrl;
		this.owner = owner;

		this.maxCharacters = getValueOf('popupMaxPreviewCharacters');
		this.maxSentences = getValueOf('popupMaxPreviewSentences');

		this.setData();
	}

	Previewmaker.prototype.setData = function () {
		var maxSize = Math.max(10000, 2 * this.maxCharacters);
		this.data = this.originalData.substring(0, maxSize);
	};

	/**
	 * Remove HTML comments
	 * @private
	 */
	Previewmaker.prototype.killComments = function () {
		// this also kills one trailing newline, eg [[diamyo]]
		this.data = this.data.replace(
			RegExp('^<!--[^$]*?-->\\n|\\n<!--[^$]*?-->(?=\\n)|<!--[^$]*?-->', 'g'),
			''
		);
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.killDivs = function () {
		// say goodbye, divs (can be nested, so use * not *?)
		this.data = this.data.replace(RegExp('< *div[^>]* *>[\\s\\S]*?< */ *div *>', 'gi'), '');
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.killGalleries = function () {
		this.data = this.data.replace(RegExp('< *gallery[^>]* *>[\\s\\S]*?< */ *gallery *>', 'gi'), '');
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.kill = function (opening, closing, subopening, subclosing, repl) {
		var oldk = this.data;
		var k = this.killStuff(this.data, opening, closing, subopening, subclosing, repl);
		while (k.length < oldk.length) {
			oldk = k;
			k = this.killStuff(k, opening, closing, subopening, subclosing, repl);
		}
		this.data = k;
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.killStuff = function (
		txt,
		opening,
		closing,
		subopening,
		subclosing,
		repl
	) {
		var op = this.makeRegexp(opening);
		var cl = this.makeRegexp(closing, '^');
		var sb = subopening ? this.makeRegexp(subopening, '^') : null;
		var sc = subclosing ? this.makeRegexp(subclosing, '^') : cl;
		if (!op || !cl) {
			alert('Navigation Popups error: op or cl is null! something is wrong.');
			return;
		}
		if (!op.test(txt)) {
			return txt;
		}
		var ret = '';
		var opResult = op.exec(txt);
		ret = txt.substring(0, opResult.index);
		txt = txt.substring(opResult.index + opResult[0].length);
		var depth = 1;
		while (txt.length > 0) {
			var removal = 0;
			if (depth == 1 && cl.test(txt)) {
				depth--;
				removal = cl.exec(txt)[0].length;
			} else if (depth > 1 && sc.test(txt)) {
				depth--;
				removal = sc.exec(txt)[0].length;
			} else if (sb && sb.test(txt)) {
				depth++;
				removal = sb.exec(txt)[0].length;
			}
			if (!removal) {
				removal = 1;
			}
			txt = txt.substring(removal);
			if (depth === 0) {
				break;
			}
		}
		return ret + (repl || '') + txt;
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.makeRegexp = function (x, prefix, suffix) {
		prefix = prefix || '';
		suffix = suffix || '';
		var reStr = '';
		var flags = '';
		if (isString(x)) {
			reStr = prefix + literalizeRegex(x) + suffix;
		} else if (isRegExp(x)) {
			var s = x.toString().substring(1);
			var sp = s.split('/');
			flags = sp[sp.length - 1];
			sp[sp.length - 1] = '';
			s = sp.join('/');
			s = s.substring(0, s.length - 1);
			reStr = prefix + s + suffix;
		} else {
			log('makeRegexp failed');
		}

		log('makeRegexp: got reStr=' + reStr + ', flags=' + flags);
		return RegExp(reStr, flags);
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.killBoxTemplates = function () {
		// taxobox removal... in fact, there's a saudiprincebox_begin, so let's be more general
		// also, have float_begin, ... float_end
		this.kill(RegExp('[{][{][^{}\\s|]*?(float|box)[_ ](begin|start)', 'i'), /[}][}]\s*/, '{{');

		// infoboxes etc
		// from [[User:Zyxw/popups.js]]: kill frames too
		this.kill(RegExp('[{][{][^{}\\s|]*?(infobox|elementbox|frame)[_ ]', 'i'), /[}][}]\s*/, '{{');
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.killTemplates = function () {
		this.kill('{{', '}}', '{', '}', ' ');
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.killTables = function () {
		// tables are bad, too
		// this can be slow, but it's an inprovement over a browser hang
		// torture test: [[Comparison_of_Intel_Central_Processing_Units]]
		this.kill('{|', /[|]}\s*/, '{|');
		this.kill(/<table.*?>/i, /<\/table.*?>/i, /<table.*?>/i);
		// remove lines starting with a pipe for the hell of it (?)
		this.data = this.data.replace(RegExp('^[|].*$', 'mg'), '');
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.killImages = function () {
		var forbiddenNamespaceAliases = [];
		jQuery.each(mw.config.get('wgNamespaceIds'), function (_localizedNamespaceLc, _namespaceId) {
			if (_namespaceId != pg.nsImageId && _namespaceId != pg.nsCategoryId) {
				return;
			}
			forbiddenNamespaceAliases.push(_localizedNamespaceLc.split(' ').join('[ _]')); //todo: escape regexp fragments!
		});

		// images and categories are a nono
		this.kill(
			RegExp('[[][[]\\s*(' + forbiddenNamespaceAliases.join('|') + ')\\s*:', 'i'),
			/\]\]\s*/,
			'[',
			']'
		);
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.killHTML = function () {
		// kill <ref ...>...</ref>
		this.kill(/<ref\b[^/>]*?>/i, /<\/ref>/i);

		// let's also delete entire lines starting with <. it's worth a try.
		this.data = this.data.replace(RegExp('(^|\\n) *<.*', 'g'), '\n');

		// and those pesky html tags, but not <nowiki> or <blockquote>
		var splitted = this.data.parenSplit(/(<[\w\W]*?(?:>|$|(?=<)))/);
		var len = splitted.length;
		for (var i = 1; i < len; i = i + 2) {
			switch (splitted[i]) {
				case '<nowiki>':
				case '</nowiki>':
				case '<blockquote>':
				case '</blockquote>':
					break;
				default:
					splitted[i] = '';
			}
		}
		this.data = splitted.join('');
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.killChunks = function () {
		// heuristics alert
		// chunks of italic text? you crazy, man?
		var italicChunkRegex = new RegExp(
			"((^|\\n)\\s*:*\\s*''[^']([^']|'''|'[^']){20}(.|\\n[^\\n])*''[.!?\\s]*\\n)+",
			'g'
		);
		// keep stuff separated, though, so stick in \n (fixes [[Union Jack]]?
		this.data = this.data.replace(italicChunkRegex, '\n');
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.mopup = function () {
		// we simply *can't* be doing with horizontal rules right now
		this.data = this.data.replace(RegExp('^-{4,}', 'mg'), '');

		// no indented lines
		this.data = this.data.replace(RegExp('(^|\\n) *:[^\\n]*', 'g'), '');

		// replace __TOC__, __NOTOC__ and whatever else there is
		// this'll probably do
		this.data = this.data.replace(RegExp('^__[A-Z_]*__ *$', 'gmi'), '');
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.firstBit = function () {
		// dont't be givin' me no subsequent paragraphs, you hear me?
		/// first we "normalize" section headings, removing whitespace after, adding before
		var d = this.data;

		if (getValueOf('popupPreviewCutHeadings')) {
			this.data = this.data.replace(RegExp('\\s*(==+[^=]*==+)\\s*', 'g'), '\n\n$1 ');
			/// then we want to get rid of paragraph breaks whose text ends badly
			this.data = this.data.replace(RegExp('([:;]) *\\n{2,}', 'g'), '$1\n');

			this.data = this.data.replace(RegExp('^[\\s\\n]*'), '');
			var stuff = RegExp('^([^\\n]|\\n[^\\n\\s])*').exec(this.data);
			if (stuff) {
				d = stuff[0];
			}
			if (!getValueOf('popupPreviewFirstParOnly')) {
				d = this.data;
			}

			/// now put \n\n after sections so that bullets and numbered lists work
			d = d.replace(RegExp('(==+[^=]*==+)\\s*', 'g'), '$1\n\n');
		}

		// Split sentences. Superfluous sentences are RIGHT OUT.
		// note: exactly 1 set of parens here needed to make the slice work
		d = d.parenSplit(RegExp('([!?.]+["' + "'" + ']*\\s)', 'g'));
		// leading space is bad, mmkay?
		d[0] = d[0].replace(RegExp('^\\s*'), '');

		var notSentenceEnds = RegExp(
			'([^.][a-z][.] *[a-z]|etc|sic|Dr|Mr|Mrs|Ms|St|no|op|cit|\\[[^\\]]*|\\s[A-Zvclm])$',
			'i'
		);
		d = this.fixSentenceEnds(d, notSentenceEnds);

		this.fullLength = d.join('').length;
		var n = this.maxSentences;
		var dd = this.firstSentences(d, n);

		do {
			dd = this.firstSentences(d, n);
			--n;
		} while (dd.length > this.maxCharacters && n !== 0);

		this.data = dd;
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.fixSentenceEnds = function (strs, reg) {
		// take an array of strings, strs
		// join strs[i] to strs[i+1] & strs[i+2] if strs[i] matches regex reg

		for (var i = 0; i < strs.length - 2; ++i) {
			if (reg.test(strs[i])) {
				var a = [];
				for (var j = 0; j < strs.length; ++j) {
					if (j < i) {
						a[j] = strs[j];
					}
					if (j == i) {
						a[i] = strs[i] + strs[i + 1] + strs[i + 2];
					}
					if (j > i + 2) {
						a[j - 2] = strs[j];
					}
				}
				return this.fixSentenceEnds(a, reg);
			}
		}
		return strs;
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.firstSentences = function (strs, howmany) {
		var t = strs.slice(0, 2 * howmany);
		return t.join('');
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.killBadWhitespace = function () {
		// also cleans up isolated '''', eg [[Suntory Sungoliath]]
		this.data = this.data.replace(RegExp("^ *'+ *$", 'gm'), '');
	};

	/**
	 * Runs the various methods to generate the preview.
	 * The preview is stored in the <code>html</html> field.
	 * @private
	 */
	Previewmaker.prototype.makePreview = function () {
		if (
			this.owner.article.namespaceId() != pg.nsTemplateId &&
			this.owner.article.namespaceId() != pg.nsImageId
		) {
			this.killComments();
			this.killDivs();
			this.killGalleries();
			this.killBoxTemplates();

			if (getValueOf('popupPreviewKillTemplates')) {
				this.killTemplates();
			} else {
				this.killMultilineTemplates();
			}
			this.killTables();
			this.killImages();
			this.killHTML();
			this.killChunks();
			this.mopup();

			this.firstBit();
			this.killBadWhitespace();
		} else {
			this.killHTML();
		}
		this.html = wiki2html(this.data, this.baseUrl); // needs livepreview
		this.fixHTML();
		this.stripLongTemplates();
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.esWiki2HtmlPart = function (data) {
		var reLinks = /(?:\[\[([^|\]]*)(?:\|([^|\]]*))*]]([a-z]*))/gi; //match a wikilink
		reLinks.lastIndex = 0; //reset regex

		var match;
		var result = '';
		var postfixIndex = 0;
		while ((match = reLinks.exec(data))) {
			//match all wikilinks
			//FIXME: the way that link is built here isn't perfect. It is clickable, but popups preview won't recognize it in some cases.
			result +=
				pg.escapeQuotesHTML(data.substring(postfixIndex, match.index)) +
				'<a href="' +
				Insta.conf.paths.articles +
				pg.escapeQuotesHTML(match[1]) +
				'">' +
				pg.escapeQuotesHTML((match[2] ? match[2] : match[1]) + match[3]) +
				'</a>';
			postfixIndex = reLinks.lastIndex;
		}
		//append the rest
		result += pg.escapeQuotesHTML(data.substring(postfixIndex));

		return result;
	};
	Previewmaker.prototype.editSummaryPreview = function () {
		var reAes = /\/\* *(.*?) *\*\//g; //match the first section marker
		reAes.lastIndex = 0; //reset regex

		var match;

		match = reAes.exec(this.data);
		if (match) {
			//we have a section link. Split it, process it, combine it.
			var prefix = this.data.substring(0, match.index - 1);
			var section = match[1];
			var postfix = this.data.substring(reAes.lastIndex);

			var start = "<span class='autocomment'>";
			var end = '</span>';
			if (prefix.length > 0) {
				start = this.esWiki2HtmlPart(prefix) + ' ' + start + '- ';
			}
			if (postfix.length > 0) {
				end = ': ' + end + this.esWiki2HtmlPart(postfix);
			}

			var t = new Title().fromURL(this.baseUrl);
			t.anchorFromUtf(section);
			var sectionLink =
				Insta.conf.paths.articles +
				pg.escapeQuotesHTML(t.toString(true)) +
				'#' +
				pg.escapeQuotesHTML(t.anchor);
			return (
				start + '<a href="' + sectionLink + '">&rarr;</a> ' + pg.escapeQuotesHTML(section) + end
			);
		}

		//else there's no section link, htmlify the whole thing.
		return this.esWiki2HtmlPart(this.data);
	};

	/** Test function for debugging preview problems one step at a time. */
	/*eslint-disable */
	function previewSteps(txt) {
		try {
			txt = txt || document.editform.wpTextbox1.value;
		} catch (err) {
			if (pg.cache.pages.length > 0) {
				txt = pg.cache.pages[pg.cache.pages.length - 1].data;
			} else {
				alert('provide text or use an edit page');
			}
		}
		txt = txt.substring(0, 10000);
		var base = pg.wiki.articlebase + Title.fromURL(document.location.href).urlString();
		var p = new Previewmaker(txt, base, pg.current.link.navpopup);
		if (this.owner.article.namespaceId() != pg.nsTemplateId) {
			p.killComments();
			if (!confirm('done killComments(). Continue?\n---\n' + p.data)) {
				return;
			}
			p.killDivs();
			if (!confirm('done killDivs(). Continue?\n---\n' + p.data)) {
				return;
			}
			p.killGalleries();
			if (!confirm('done killGalleries(). Continue?\n---\n' + p.data)) {
				return;
			}
			p.killBoxTemplates();
			if (!confirm('done killBoxTemplates(). Continue?\n---\n' + p.data)) {
				return;
			}

			if (getValueOf('popupPreviewKillTemplates')) {
				p.killTemplates();
				if (!confirm('done killTemplates(). Continue?\n---\n' + p.data)) {
					return;
				}
			} else {
				p.killMultilineTemplates();
				if (!confirm('done killMultilineTemplates(). Continue?\n---\n' + p.data)) {
					return;
				}
			}

			p.killTables();
			if (!confirm('done killTables(). Continue?\n---\n' + p.data)) {
				return;
			}
			p.killImages();
			if (!confirm('done killImages(). Continue?\n---\n' + p.data)) {
				return;
			}
			p.killHTML();
			if (!confirm('done killHTML(). Continue?\n---\n' + p.data)) {
				return;
			}
			p.killChunks();
			if (!confirm('done killChunks(). Continue?\n---\n' + p.data)) {
				return;
			}
			p.mopup();
			if (!confirm('done mopup(). Continue?\n---\n' + p.data)) {
				return;
			}

			p.firstBit();
			if (!confirm('done firstBit(). Continue?\n---\n' + p.data)) {
				return;
			}
			p.killBadWhitespace();
			if (!confirm('done killBadWhitespace(). Continue?\n---\n' + p.data)) {
				return;
			}
		}

		p.html = wiki2html(p.data, base); // needs livepreview
		p.fixHTML();
		if (!confirm('done fixHTML(). Continue?\n---\n' + p.html)) {
			return;
		}
		p.stripLongTemplates();
		if (!confirm('done stripLongTemplates(). Continue?\n---\n' + p.html)) {
			return;
		}
		alert('finished preview - end result follows.\n---\n' + p.html);
	}
	/*eslint-enable */

	/**
	 * Works around livepreview bugs.
	 * @private
	 */
	Previewmaker.prototype.fixHTML = function () {
		if (!this.html) {
			return;
		}

		var ret = this.html;

		// fix question marks in wiki links
		// maybe this'll break some stuff :-(
		ret = ret.replace(
			RegExp('(<a href="' + pg.wiki.articlePath + '/[^"]*)[?](.*?")', 'g'),
			'$1%3F$2'
		);
		ret = ret.replace(
			RegExp("(<a href='" + pg.wiki.articlePath + "/[^']*)[?](.*?')", 'g'),
			'$1%3F$2'
		);
		// FIXME fix up % too

		this.html = ret;
	};

	/**
	 * Generates the preview and displays it in the current popup.

	 * Does nothing if the generated preview is invalid or consists of whitespace only.
	 * Also activates wikilinks in the preview for subpopups if the popupSubpopups option is true.
	 */
	Previewmaker.prototype.showPreview = function () {
		this.makePreview();
		if (typeof this.html != typeof '') {
			return;
		}
		if (RegExp('^\\s*$').test(this.html)) {
			return;
		}
		setPopupHTML('<hr />', 'popupPrePreviewSep', this.owner.idNumber);
		setPopupTipsAndHTML(this.html, 'popupPreview', this.owner.idNumber, {
			owner: this.owner,
		});
		var more = this.fullLength > this.data.length ? this.moreLink() : '';
		setPopupHTML(more, 'popupPreviewMore', this.owner.idNumber);
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.moreLink = function () {
		var a = document.createElement('a');
		a.className = 'popupMoreLink';
		a.innerHTML = popupString('more...');
		var savedThis = this;
		a.onclick = function () {
			savedThis.maxCharacters += 2000;
			savedThis.maxSentences += 20;
			savedThis.setData();
			savedThis.showPreview();
		};
		return a;
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.stripLongTemplates = function () {
		// operates on the HTML!
		this.html = this.html.replace(
			RegExp('^.{0,1000}[{][{][^}]*?(<(p|br)( /)?>\\s*){2,}([^{}]*?[}][}])?', 'gi'),
			''
		);
		this.html = this.html.split('\n').join(' '); // workaround for <pre> templates
		this.html = this.html.replace(RegExp('[{][{][^}]*<pre>[^}]*[}][}]', 'gi'), '');
	};

	/**
	 * @private
	 */
	Previewmaker.prototype.killMultilineTemplates = function () {
		this.kill('{{{', '}}}');
		this.kill(RegExp('\\s*[{][{][^{}]*\\n'), '}}', '{{');
	};
	// ENDFILE: previewmaker.js

	// STARTFILE: querypreview.js
	function loadAPIPreview(queryType, article, navpop) {
		var art = new Title(article).urlString();
		var url = pg.wiki.apiwikibase + '?format=json&formatversion=2&action=query&';
		var htmlGenerator = function (/*a, d*/) {
			alert('invalid html generator');
		};
		var usernameart = '';
		switch (queryType) {
			case 'history':
				url +=
					'titles=' + art + '&prop=revisions&rvlimit=' + getValueOf('popupHistoryPreviewLimit');
				htmlGenerator = APIhistoryPreviewHTML;
				break;
			case 'category':
				url += 'list=categorymembers&cmtitle=' + art;
				htmlGenerator = APIcategoryPreviewHTML;
				break;
			case 'userinfo':
				var username = new Title(article).userName();
				usernameart = encodeURIComponent(username);
				if (pg.re.ipUser.test(username)) {
					url += 'list=blocks&bkprop=range|restrictions&bkip=' + usernameart;
				} else {
					url +=
						'list=users|usercontribs&usprop=blockinfo|groups|editcount|registration|gender&ususers=' +
						usernameart +
						'&meta=globaluserinfo&guiprop=groups|unattached&guiuser=' +
						usernameart +
						'&uclimit=1&ucprop=timestamp&ucuser=' +
						usernameart;
				}
				htmlGenerator = APIuserInfoPreviewHTML;
				break;
			case 'contribs':
				usernameart = encodeURIComponent(new Title(article).userName());
				url +=
					'list=usercontribs&ucuser=' +
					usernameart +
					'&uclimit=' +
					getValueOf('popupContribsPreviewLimit');
				htmlGenerator = APIcontribsPreviewHTML;
				break;
			case 'imagepagepreview':
				var trail = '';
				if (getValueOf('popupImageLinks')) {
					trail = '&list=imageusage&iutitle=' + art;
				}
				url += 'titles=' + art + '&prop=revisions|imageinfo&rvslots=main&rvprop=content' + trail;
				htmlGenerator = APIimagepagePreviewHTML;
				break;
			case 'backlinks':
				url += 'list=backlinks&bltitle=' + art;
				htmlGenerator = APIbacklinksPreviewHTML;
				break;
			case 'revision':
				if (article.oldid) {
					url += 'revids=' + article.oldid;
				} else {
					url += 'titles=' + article.removeAnchor().urlString();
				}
				url +=
					'&prop=revisions|pageprops|info|images|categories&meta=wikibase&rvslots=main&rvprop=ids|timestamp|flags|comment|user|content&cllimit=max&imlimit=max';
				htmlGenerator = APIrevisionPreviewHTML;
				break;
		}
		pendingNavpopTask(navpop);
		var callback = function (d) {
			log('callback of API functions was hit');
			if (queryType === 'userinfo') {
				// We need to do another API request
				fetchUserGroupNames(d.data).then(function () {
					showAPIPreview(queryType, htmlGenerator(article, d, navpop), navpop.idNumber, navpop, d);
				});
				return;
			}
			showAPIPreview(queryType, htmlGenerator(article, d, navpop), navpop.idNumber, navpop, d);
		};
		var go = function () {
			getPageWithCaching(url, callback, navpop);
			return true;
		};

		if (navpop.visible || !getValueOf('popupLazyDownloads')) {
			go();
		} else {
			navpop.addHook(go, 'unhide', 'before', 'DOWNLOAD_' + queryType + '_QUERY_DATA');
		}
	}

	function linkList(list) {
		list.sort(function (x, y) {
			return x == y ? 0 : x < y ? -1 : 1;
		});
		var buf = [];
		for (var i = 0; i < list.length; ++i) {
			buf.push(
				wikiLink({
					article: new Title(list[i]),
					text: list[i].split(' ').join('&nbsp;'),
					action: 'view',
				})
			);
		}
		return buf.join(', ');
	}

	function getTimeOffset() {
		var tz = mw.user.options.get('timecorrection');

		if (tz) {
			if (tz.indexOf('|') > -1) {
				// New format
				return parseInt(tz.split('|')[1], 10);
			}
		}
		return 0;
	}

	function getTimeZone() {
		if (!pg.user.timeZone) {
			var tz = mw.user.options.get('timecorrection');
			pg.user.timeZone = 'UTC';

			if (tz) {
				var tzComponents = tz.split('|');
				if (tzComponents.length === 3 && tzComponents[0] === 'ZoneInfo') {
					pg.user.timeZone = tzComponents[2];
				} else {
					errlog('Unexpected timezone information: ' + tz);
				}
			}
		}
		return pg.user.timeZone;
	}

	/**
	 * Should we use an offset or can we use proper timezones
	 */
	function useTimeOffset() {
		if (typeof Intl.DateTimeFormat.prototype.formatToParts === 'undefined') {
			// IE 11
			return true;
		}
		var tz = mw.user.options.get('timecorrection');
		if (tz && tz.indexOf('ZoneInfo|') === -1) {
			// System| Default system time, default for users who didn't configure timezone
			// Offset| Manual defined offset by user
			return true;
		}
		return false;
	}

	/**
	 * Array of locales for the purpose of javascript locale based formatting
	 * Filters down to those supported by the browser. Empty [] === System's default locale
	 */
	function getLocales() {
		if (!pg.user.locales) {
			var userLanguage = document.querySelector('html').getAttribute('lang'); // make sure we have HTML locale
			if (getValueOf('popupLocale')) {
				userLanguage = getValueOf('popupLocale');
			} else if (userLanguage === 'en') {
				// en.wp tends to treat this as international english / unspecified
				// but we have more specific settings in user options
				if (getMWDateFormat() === 'mdy') {
					userLanguage = 'en-US';
				} else {
					userLanguage = 'en-GB';
				}
			}
			pg.user.locales = Intl.DateTimeFormat.supportedLocalesOf([userLanguage, navigator.language]);
		}
		return pg.user.locales;
	}

	/**
	 * Retrieve configured MW date format for this user
	 * These can be
	 * default
	 * dmy: time, dmy
	 * mdy: time, mdy
	 * ymd: time, ymd
	 * dmyt: dmy, time
	 * dmyts: dmy, time + seconds
	 * ISO 8601: YYYY-MM-DDThh:mm:ss (local time)
	 *
	 * This isn't too useful for us, as JS doesn't have formatters to match these private specifiers
	 */
	function getMWDateFormat() {
		return mw.user.options.get('date');
	}

	/**
	 * Creates a HTML table that's shown in the history and user-contribs popups.
	 * @param {Object[]} h - a list of revisions, returned from the API
	 * @param {boolean} reallyContribs - true only if we're displaying user contributions
	 */
	function editPreviewTable(article, h, reallyContribs) {
		var html = ['<table>'];
		var day = null;
		var curart = article;
		var page = null;

		var makeFirstColumnLinks;
		if (reallyContribs) {
			// We're showing user contributions, so make (diff | hist) links
			makeFirstColumnLinks = function (currentRevision) {
				var result = '(';
				result +=
					'<a href="' +
					pg.wiki.titlebase +
					new Title(currentRevision.title).urlString() +
					'&diff=prev' +
					'&oldid=' +
					currentRevision.revid +
					'">' +
					popupString('diff') +
					'</a>';
				result += '&nbsp;|&nbsp;';
				result +=
					'<a href="' +
					pg.wiki.titlebase +
					new Title(currentRevision.title).urlString() +
					'&action=history">' +
					popupString('hist') +
					'</a>';
				result += ')';
				return result;
			};
		} else {
			// It's a regular history page, so make (cur | last) links
			var firstRevid = h[0].revid;
			makeFirstColumnLinks = function (currentRevision) {
				var result = '(';
				result +=
					'<a href="' +
					pg.wiki.titlebase +
					new Title(curart).urlString() +
					'&diff=' +
					firstRevid +
					'&oldid=' +
					currentRevision.revid +
					'">' +
					popupString('cur') +
					'</a>';
				result += '&nbsp;|&nbsp;';
				result +=
					'<a href="' +
					pg.wiki.titlebase +
					new Title(curart).urlString() +
					'&diff=prev&oldid=' +
					currentRevision.revid +
					'">' +
					popupString('last') +
					'</a>';
				result += ')';
				return result;
			};
		}

		for (var i = 0; i < h.length; ++i) {
			if (reallyContribs) {
				page = h[i].title;
				curart = new Title(page);
			}
			var minor = h[i].minor ? '<b>m </b>' : '';
			var editDate = new Date(h[i].timestamp);
			var thisDay = formattedDate(editDate);
			var thisTime = formattedTime(editDate);
			if (thisDay == day) {
				thisDay = '';
			} else {
				day = thisDay;
			}
			if (thisDay) {
				html.push(
					'<tr><td colspan=3><span class="popup_history_date">' + thisDay + '</span></td></tr>'
				);
			}
			html.push('<tr class="popup_history_row_' + (i % 2 ? 'odd' : 'even') + '">');
			html.push('<td>' + makeFirstColumnLinks(h[i]) + '</td>');
			html.push(
				'<td>' +
					'<a href="' +
					pg.wiki.titlebase +
					new Title(curart).urlString() +
					'&oldid=' +
					h[i].revid +
					'">' +
					thisTime +
					'</a></td>'
			);
			var col3url = '',
				col3txt = '';
			if (!reallyContribs) {
				var user = h[i].user;
				if (!h[i].userhidden) {
					if (pg.re.ipUser.test(user)) {
						col3url =
							pg.wiki.titlebase +
							mw.config.get('wgFormattedNamespaces')[pg.nsSpecialId] +
							':Contributions&target=' +
							new Title(user).urlString();
					} else {
						col3url =
							pg.wiki.titlebase +
							mw.config.get('wgFormattedNamespaces')[pg.nsUserId] +
							':' +
							new Title(user).urlString();
					}
					col3txt = pg.escapeQuotesHTML(user);
				} else {
					col3url = getValueOf('popupRevDelUrl');
					col3txt = pg.escapeQuotesHTML(popupString('revdel'));
				}
			} else {
				col3url = pg.wiki.titlebase + curart.urlString();
				col3txt = pg.escapeQuotesHTML(page);
			}
			html.push(
				'<td>' +
					(reallyContribs ? minor : '') +
					'<a href="' +
					col3url +
					'">' +
					col3txt +
					'</a></td>'
			);
			var comment = '';
			var c = h[i].comment || ( typeof h[i].slots !== 'undefined' ? h[i].slots.main.content : null );
			if (c) {
				comment = new Previewmaker(c, new Title(curart).toUrl()).editSummaryPreview();
			} else if (h[i].commenthidden) {
				comment = popupString('revdel');
			}
			html.push('<td>' + (!reallyContribs ? minor : '') + comment + '</td>');
			html.push('</tr>');
			html = [html.join('')];
		}
		html.push('</table>');
		return html.join('');
	}

	function adjustDate(d, offset) {
		// offset is in minutes
		var o = offset * 60 * 1000;
		return new Date(Number(d) + o);
	}

	/**
	 * This relies on the Date parser understanding en-US dates,
	 * which is pretty safe assumption, but not perfect.
	 */
	function convertTimeZone(date, timeZone) {
		return new Date(date.toLocaleString('en-US', { timeZone: timeZone }));
	}

	function formattedDateTime(date) {
		// fallback for IE11 and unknown timezones
		if (useTimeOffset()) {
			return formattedDate(date) + ' ' + formattedTime(date);
		}

		if (getMWDateFormat() === 'ISO 8601') {
			var d2 = convertTimeZone(date, getTimeZone());
			return (
				map(zeroFill, [d2.getFullYear(), d2.getMonth() + 1, d2.getDate()]).join('-') +
				'T' +
				map(zeroFill, [d2.getHours(), d2.getMinutes(), d2.getSeconds()]).join(':')
			);
		}

		var options = getValueOf('popupDateTimeFormatterOptions');
		options['timeZone'] = getTimeZone();
		return date.toLocaleString(getLocales(), options);
	}

	function formattedDate(date) {
		// fallback for IE11 and unknown timezones
		if (useTimeOffset()) {
			// we adjust the UTC time, so we print the adjusted UTC, but not really UTC values
			var d2 = adjustDate(date, getTimeOffset());
			return map(zeroFill, [d2.getUTCFullYear(), d2.getUTCMonth() + 1, d2.getUTCDate()]).join('-');
		}

		if (getMWDateFormat() === 'ISO 8601') {
			var d2 = convertTimeZone(date, getTimeZone());
			return map(zeroFill, [d2.getFullYear(), d2.getMonth() + 1, d2.getDate()]).join('-');
		}

		var options = getValueOf('popupDateFormatterOptions');
		options['timeZone'] = getTimeZone();
		return date.toLocaleDateString(getLocales(), options);
	}

	function formattedTime(date) {
		// fallback for IE11 and unknown timezones
		if (useTimeOffset()) {
			// we adjust the UTC time, so we print the adjusted UTC, but not really UTC values
			var d2 = adjustDate(date, getTimeOffset());
			return map(zeroFill, [d2.getUTCHours(), d2.getUTCMinutes(), d2.getUTCSeconds()]).join(':');
		}

		if (getMWDateFormat() === 'ISO 8601') {
			var d2 = convertTimeZone(date, getTimeZone());
			return map(zeroFill, [d2.getHours(), d2.getMinutes(), d2.getSeconds()]).join(':');
		}

		var options = getValueOf('popupTimeFormatterOptions');
		options['timeZone'] = getTimeZone();
		return date.toLocaleTimeString(getLocales(), options);
	}

	// Get the proper groupnames for the technicalgroups
	function fetchUserGroupNames(userinfoResponse) {
		var queryObj = getJsObj(userinfoResponse).query;
		var user = anyChild(queryObj.users);
		var messages = [];
		if (user.groups) {
			user.groups.forEach(function (groupName) {
				if (['*', 'user', 'autoconfirmed', 'extendedconfirmed', 'named'].indexOf(groupName) === -1) {
					messages.push('group-' + groupName + '-member');
				}
			});
		}
		if (queryObj.globaluserinfo && queryObj.globaluserinfo.groups) {
			queryObj.globaluserinfo.groups.forEach(function (groupName) {
				messages.push('group-' + groupName + '-member');
			});
		}
		return getMwApi().loadMessagesIfMissing(messages);
	}

	function showAPIPreview(queryType, html, id, navpop, download) {
		// DJ: done
		var target = 'popupPreview';
		completedNavpopTask(navpop);

		switch (queryType) {
			case 'imagelinks':
			case 'category':
				target = 'popupPostPreview';
				break;
			case 'userinfo':
				target = 'popupUserData';
				break;
			case 'revision':
				insertPreview(download);
				return;
		}
		setPopupTipsAndHTML(html, target, id);
	}

	function APIrevisionPreviewHTML(article, download) {
		try {
			var jsObj = getJsObj(download.data);
			var page = anyChild(jsObj.query.pages);
			if (page.missing) {
				// TODO we need to fix this proper later on
				download.owner = null;
				return;
			}
			var content =
				page && page.revisions && page.revisions[0] &&
				page.revisions[0].slots && page.revisions[0].slots.main &&
				page.revisions[0].slots.main.contentmodel === 'wikitext'
					? page.revisions[0].slots.main.content
					: null;
			if (typeof content === 'string') {
				download.data = content;
				download.lastModified = new Date(page.revisions[0].timestamp);
			}
			if (page.pageprops.wikibase_item) {
				download.wikibaseItem = page.pageprops.wikibase_item;
				download.wikibaseRepo = jsObj.query.wikibase.repo.url.base
										+ jsObj.query.wikibase.repo.url.articlepath;
			}
		} catch (someError) {
			return 'Revision preview failed :(';
		}
	}

	function APIbacklinksPreviewHTML(article, download /*, navpop*/) {
		try {
			var jsObj = getJsObj(download.data);
			var list = jsObj.query.backlinks;

			var html = [];
			if (!list) {
				return popupString('No backlinks found');
			}
			for (var i = 0; i < list.length; i++) {
				var t = new Title(list[i].title);
				html.push(
					'<a href="' + pg.wiki.titlebase + t.urlString() + '">' + t.toString().entify() + '</a>'
				);
			}
			html = html.join(', ');
			if (jsObj['continue'] && jsObj['continue'].blcontinue) {
				html += popupString(' and more');
			}
			return html;
		} catch (someError) {
			return 'backlinksPreviewHTML went wonky';
		}
	}

	pg.fn.APIsharedImagePagePreviewHTML = function APIsharedImagePagePreviewHTML(obj) {
		log('APIsharedImagePagePreviewHTML');
		var popupid = obj.requestid;
		if (obj.query && obj.query.pages) {
			var page = anyChild(obj.query.pages);
			var content =
				page && page.revisions && page.revisions[0] &&
				page.revisions[0].slots && page.revisions[0].slots.main &&
				page.revisions[0].slots.main.contentmodel === 'wikitext'
					? page.revisions[0].slots.main.content
					: null;
			if (
				typeof content === 'string' &&
				pg &&
				pg.current &&
				pg.current.link &&
				pg.current.link.navpopup
			) {
				/* Not entirely safe, but the best we can do */
				var p = new Previewmaker(
					content,
					pg.current.link.navpopup.article,
					pg.current.link.navpopup
				);
				p.makePreview();
				setPopupHTML(p.html, 'popupSecondPreview', popupid);
			}
		}
	};

	function APIimagepagePreviewHTML(article, download, navpop) {
		try {
			var jsObj = getJsObj(download.data);
			var page = anyChild(jsObj.query.pages);
			var content =
				page && page.revisions && page.revisions[0] &&
				page.revisions[0].slots && page.revisions[0].slots.main &&
				page.revisions[0].slots.main.contentmodel === 'wikitext'
					? page.revisions[0].slots.main.content
					: null;
			var ret = '';
			var alt = '';
			try {
				alt = navpop.parentAnchor.childNodes[0].alt;
			} catch (e) {}
			if (alt) {
				ret = ret + '<hr /><b>' + popupString('Alt text:') + '</b> ' + pg.escapeQuotesHTML(alt);
			}
			if (typeof content === 'string') {
				var p = prepPreviewmaker(content, article, navpop);
				p.makePreview();
				if (p.html) {
					ret += '<hr />' + p.html;
				}
				if (getValueOf('popupSummaryData')) {
					var info = getPageInfo(content, download);
					log(info);
					setPopupTrailer(info, navpop.idNumber);
				}
			}
			if (page && page.imagerepository == 'shared') {
				var art = new Title(article);
				var encart = encodeURIComponent('File:' + art.stripNamespace());
				var shared_url =
					pg.wiki.apicommonsbase +
					'?format=json&formatversion=2' +
					'&callback=pg.fn.APIsharedImagePagePreviewHTML' +
					'&requestid=' +
					navpop.idNumber +
					'&action=query&prop=revisions&rvslots=main&rvprop=content&titles=' +
					encart;

				ret =
					ret +
					'<hr />' +
					popupString('Image from Commons') +
					': <a href="' +
					pg.wiki.commonsbase +
					'?title=' +
					encart +
					'">' +
					popupString('Description page') +
					'</a>';
				mw.loader.load(shared_url);
			}
			showAPIPreview(
				'imagelinks',
				APIimagelinksPreviewHTML(article, download),
				navpop.idNumber,
				download
			);
			return ret;
		} catch (someError) {
			return 'API imagepage preview failed :(';
		}
	}

	function APIimagelinksPreviewHTML(article, download) {
		try {
			var jsobj = getJsObj(download.data);
			var list = jsobj.query.imageusage;
			if (list) {
				var ret = [];
				for (var i = 0; i < list.length; i++) {
					ret.push(list[i].title);
				}
				if (ret.length === 0) {
					return popupString('No image links found');
				}
				return '<h2>' + popupString('File links') + '</h2>' + linkList(ret);
			} else {
				return popupString('No image links found');
			}
		} catch (someError) {
			return 'Image links preview generation failed :(';
		}
	}

	function APIcategoryPreviewHTML(article, download) {
		try {
			var jsobj = getJsObj(download.data);
			var list = jsobj.query.categorymembers;
			var ret = [];
			for (var p = 0; p < list.length; p++) {
				ret.push(list[p].title);
			}
			if (ret.length === 0) {
				return popupString('Empty category');
			}
			ret = '<h2>' + tprintf('Category members (%s shown)', [ret.length]) + '</h2>' + linkList(ret);
			if (jsobj['continue'] && jsobj['continue'].cmcontinue) {
				ret += popupString(' and more');
			}
			return ret;
		} catch (someError) {
			return 'Category preview failed :(';
		}
	}

	function APIuserInfoPreviewHTML(article, download) {
		var ret = [];
		var queryobj = {};
		try {
			queryobj = getJsObj(download.data).query;
		} catch (someError) {
			return 'Userinfo preview failed :(';
		}

		var user = anyChild(queryobj.users);
		if (user) {
			var globaluserinfo = queryobj.globaluserinfo;
			if (user.invalid === '') {
				ret.push(popupString('Invalid user'));
			} else if (user.missing === '') {
				ret.push(popupString('Not a registered username'));
			}
			if (user.blockedby) {
				if (user.blockpartial) {
					ret.push('<b>' + popupString('Has blocks') + '</b>');
				} else {
					ret.push('<b>' + popupString('BLOCKED') + '</b>');
				}
			}
			if (globaluserinfo && ('locked' in globaluserinfo || 'hidden' in globaluserinfo)) {
				var lockedSulAccountIsAttachedToThis = true;
				for (var i = 0; globaluserinfo.unattached && i < globaluserinfo.unattached.length; i++) {
					if (globaluserinfo.unattached[i].wiki === mw.config.get('wgDBname')) {
						lockedSulAccountIsAttachedToThis = false;
						break;
					}
				}
				if (lockedSulAccountIsAttachedToThis) {
					if ('locked' in globaluserinfo) {
						ret.push('<b><i>' + popupString('LOCKED') + '</i></b>');
					}
					if ('hidden' in globaluserinfo) {
						ret.push('<b><i>' + popupString('HIDDEN') + '</i></b>');
					}
				}
			}
			if (getValueOf('popupShowGender') && user.gender) {
				switch (user.gender) {
					case 'male':
						ret.push(popupString('he/him') + ' · ');
						break;
					case 'female':
						ret.push(popupString('she/her') + ' · ');
						break;
				}
			}
			if (user.groups) {
				user.groups.forEach(function (groupName) {
					if (['*', 'user', 'autoconfirmed', 'extendedconfirmed', 'named'].indexOf(groupName) === -1) {
						ret.push(
							pg.escapeQuotesHTML(mw.message('group-' + groupName + '-member', user.gender).text())
						);
					}
				});
			}
			if (globaluserinfo && globaluserinfo.groups) {
				globaluserinfo.groups.forEach(function (groupName) {
					ret.push(
						'<i>' +
							pg.escapeQuotesHTML(
								mw.message('group-' + groupName + '-member', user.gender).text()
							) +
							'</i>'
					);
				});
			}
			if (user.registration) {
				ret.push(
					pg.escapeQuotesHTML(
						(user.editcount ? user.editcount : '0') +
							popupString(' edits since: ') +
							(user.registration ? formattedDate(new Date(user.registration)) : '')
					)
				);
			}
		}

		if (queryobj.usercontribs && queryobj.usercontribs.length) {
			ret.push(
				popupString('last edit on ') + formattedDate(new Date(queryobj.usercontribs[0].timestamp))
			);
		}

		if (queryobj.blocks) {
			ret.push(popupString('IP user')); //we only request list=blocks for IPs
			for (var l = 0; l < queryobj.blocks.length; l++) {
				var rbstr =
					queryobj.blocks[l].rangestart === queryobj.blocks[l].rangeend ? 'BLOCK' : 'RANGEBLOCK';
				rbstr = !Array.isArray(queryobj.blocks[l].restrictions)
					? 'Has ' + rbstr.toLowerCase() + 's'
					: rbstr + 'ED';
				ret.push('<b>' + popupString(rbstr) + '</b>');
			}
		}

		// if any element of ret ends with ' · ', merge it with the next element to avoid
		// the .join(', ') call inserting a comma after it
		for (var m = 0; m < ret.length - 1; m++) {
			if (ret[m].length > 3 && ret[m].substring(ret[m].length - 3) === ' · ') {
				ret[m] = ret[m] + ret[m + 1];
				ret.splice(m + 1, 1); // delete element at index m+1
				m--;
			}
		}

		ret = '<hr />' + ret.join(', ');
		return ret;
	}

	function APIcontribsPreviewHTML(article, download, navpop) {
		return APIhistoryPreviewHTML(article, download, navpop, true);
	}

	function APIhistoryPreviewHTML(article, download, navpop, reallyContribs) {
		try {
			var jsobj = getJsObj(download.data);
			var edits = [];
			if (reallyContribs) {
				edits = jsobj.query.usercontribs;
			} else {
				edits = anyChild(jsobj.query.pages).revisions;
			}

			var ret = editPreviewTable(article, edits, reallyContribs);
			return ret;
		} catch (someError) {
			return 'History preview failed :-(';
		}
	}

	// ENDFILE: querypreview.js

	// STARTFILE: debug.js
	////////////////////////////////////////////////////////////////////
	// Debugging functions
	////////////////////////////////////////////////////////////////////

	function setupDebugging() {
		if (window.popupDebug) {
			// popupDebug is set from .version
			window.log = function (x) {
				//if(gMsg!='')gMsg += '\n'; gMsg+=time() + ' ' + x; };
				window.console.log(x);
			};
			window.errlog = function (x) {
				window.console.error(x);
			};
			log('Initializing logger');
		} else {
			window.log = function () {};
			window.errlog = function () {};
		}
	}
	// ENDFILE: debug.js

	// STARTFILE: images.js

	// load image of type Title.
	function loadImage(image, navpop) {
		if (typeof image.stripNamespace != 'function') {
			alert('loadImages bad');
		}
		// API call to retrieve image info.

		if (!getValueOf('popupImages')) {
			return;
		}
		if (!isValidImageName(image)) {
			return false;
		}

		var art = image.urlString();

		var url = pg.wiki.apiwikibase + '?format=json&formatversion=2&action=query';
		url += '&prop=imageinfo&iiprop=url|mime&iiurlwidth=' + getValueOf('popupImageSizeLarge');
		url += '&titles=' + art;

		pendingNavpopTask(navpop);
		var callback = function (d) {
			popupsInsertImage(navpop.idNumber, navpop, d);
		};
		var go = function () {
			getPageWithCaching(url, callback, navpop);
			return true;
		};
		if (navpop.visible || !getValueOf('popupLazyDownloads')) {
			go();
		} else {
			navpop.addHook(go, 'unhide', 'after', 'DOWNLOAD_IMAGE_QUERY_DATA');
		}
	}

	function popupsInsertImage(id, navpop, download) {
		log('popupsInsertImage');
		var imageinfo;
		try {
			var jsObj = getJsObj(download.data);
			var imagepage = anyChild(jsObj.query.pages);
			if (typeof imagepage.imageinfo === 'undefined') {
				return;
			}
			imageinfo = imagepage.imageinfo[0];
		} catch (someError) {
			log('popupsInsertImage failed :(');
			return;
		}

		var popupImage = document.getElementById('popupImg' + id);
		if (!popupImage) {
			log('could not find insertion point for image');
			return;
		}

		popupImage.width = getValueOf('popupImageSize');
		popupImage.style.display = 'inline';

		// Set the source for the image.
		if (imageinfo.thumburl) {
			popupImage.src = imageinfo.thumburl;
		} else if (imageinfo.mime.indexOf('image') === 0) {
			popupImage.src = imageinfo.url;
			log('a thumb could not be found, using original image');
		} else {
			log("fullsize imagethumb, but not sure if it's an image");
		}

		var a = document.getElementById('popupImageLink' + id);
		if (a === null) {
			return null;
		}

		// Determine the action of the surrouding imagelink.
		switch (getValueOf('popupThumbAction')) {
			case 'imagepage':
				if (pg.current.article.namespaceId() != pg.nsImageId) {
					a.href = imageinfo.descriptionurl;
					// FIXME: unreliable pg.idNumber
					popTipsSoonFn('popupImage' + id)();
					break;
				}
			/* falls through */
			case 'sizetoggle':
				a.onclick = toggleSize;
				a.title = popupString('Toggle image size');
				return;
			case 'linkfull':
				a.href = imageinfo.url;
				a.title = popupString('Open full-size image');
				return;
		}
	}

	// Toggles the image between inline small and navpop fullwidth.
	// It's the same image, no actual sizechange occurs, only display width.
	function toggleSize() {
		var imgContainer = this;
		if (!imgContainer) {
			alert('imgContainer is null :/');
			return;
		}
		var img = imgContainer.firstChild;
		if (!img) {
			alert('img is null :/');
			return;
		}

		if (!img.style.width || img.style.width === '') {
			img.style.width = '100%';
		} else {
			img.style.width = '';
		}
	}

	// Returns one title of an image from wikiText.
	function getValidImageFromWikiText(wikiText) {
		// nb in pg.re.image we're interested in the second bracketed expression
		// this may change if the regex changes :-(
		//var match=pg.re.image.exec(wikiText);
		var matched = null;
		var match;
		// strip html comments, used by evil bots :-(
		var t = removeMatchesUnless(
			wikiText,
			RegExp('(<!--[\\s\\S]*?-->)'),
			1,
			RegExp('^<!--[^[]*popup', 'i')
		);

		while ((match = pg.re.image.exec(t))) {
			// now find a sane image name - exclude templates by seeking {
			var m = match[2] || match[6];
			if (isValidImageName(m)) {
				matched = m;
				break;
			}
		}
		pg.re.image.lastIndex = 0;
		if (!matched) {
			return null;
		}
		return mw.config.get('wgFormattedNamespaces')[pg.nsImageId] + ':' + upcaseFirst(matched);
	}

	function removeMatchesUnless(str, re1, parencount, re2) {
		var split = str.parenSplit(re1);
		var c = parencount + 1;
		for (var i = 0; i < split.length; ++i) {
			if (i % c === 0 || re2.test(split[i])) {
				continue;
			}
			split[i] = '';
		}
		return split.join('');
	}

	// ENDFILE: images.js

	// STARTFILE: namespaces.js
	// Set up namespaces and other non-strings.js localization
	// (currently that means redirs too)

	function setNamespaces() {
		pg.nsSpecialId = -1;
		pg.nsMainspaceId = 0;
		pg.nsImageId = 6;
		pg.nsUserId = 2;
		pg.nsUsertalkId = 3;
		pg.nsCategoryId = 14;
		pg.nsTemplateId = 10;
	}

	function setRedirs() {
		var r = 'redirect';
		var R = 'REDIRECT';
		var redirLists = {
			ar: [R, 'تحويل'],
			be: [r, 'перанакіраваньне'],
			bg: [r, 'пренасочване', 'виж'],
			bs: [r, 'Preusmjeri', 'preusmjeri', 'PREUSMJERI'],
			bn: [R, 'পুনর্নির্দেশ'],
			cs: [R, 'PŘESMĚRUJ'],
			cy: [r, 'ail-cyfeirio'],
			de: [R, 'WEITERLEITUNG'],
			el: [R, 'ΑΝΑΚΑΤΕΥΘΥΝΣΗ'],
			eo: [R, 'ALIDIREKTU', 'ALIDIREKTI'],
			es: [R, 'REDIRECCIÓN'],
			et: [r, 'suuna'],
			ga: [r, 'athsheoladh'],
			gl: [r, 'REDIRECCIÓN', 'REDIRECIONAMENTO'],
			he: [R, 'הפניה'],
			hu: [R, 'ÁTIRÁNYÍTÁS'],
			is: [r, 'tilvísun', 'TILVÍSUN'],
			it: [R, 'RINVIA', 'Rinvia'],
			ja: [R, '転送'],
			mk: [r, 'пренасочување', 'види'],
			nds: [r, 'wiederleiden'],
			'nds-nl': [R, 'DEURVERWIEZING', 'DUURVERWIEZING'],
			nl: [R, 'DOORVERWIJZING'],
			nn: [r, 'omdiriger'],
			pl: [R, 'PATRZ', 'PRZEKIERUJ', 'TAM'],
			pt: [R, 'redir'],
			ru: [R, 'ПЕРЕНАПРАВЛЕНИЕ', 'ПЕРЕНАПР'],
			sk: [r, 'presmeruj'],
			sr: [r, 'Преусмери', 'преусмери', 'ПРЕУСМЕРИ', 'Preusmeri', 'preusmeri', 'PREUSMERI'],
			tr: [R, 'YÖNLENDİRME', 'yönlendirme', 'YÖNLENDİR', 'yönlendir'],
			tt: [R, 'yünältü', 'перенаправление', 'перенапр'],
			uk: [R, 'ПЕРЕНАПРАВЛЕННЯ', 'ПЕРЕНАПР'],
			vi: [r, 'đổi'],
			yi: [R, 'ווייטערפירן'],
			zh: [R, '重定向'], // no comma
		};
		var redirList = redirLists[pg.wiki.lang] || [r, R];
		// Mediawiki is very tolerant about what comes after the #redirect at the start
		pg.re.redirect = RegExp(
			'^\\s*[#](' + redirList.join('|') + ').*?\\[{2}([^\\|\\]]*)(|[^\\]]*)?\\]{2}\\s*(.*)',
			'i'
		);
	}

	function setInterwiki() {
		if (pg.wiki.wikimedia) {
			// From https://meta.wikimedia.org/wiki/List_of_Wikipedias
			//en.wikipedia.org/w/api.php?action=sitematrix&format=json&smtype=language&smlangprop=code&formatversion=2
			pg.wiki.interwiki =
				'aa|ab|ace|af|ak|als|am|an|ang|ar|arc|arz|as|ast|av|ay|az|ba|bar|bat-smg|bcl|be|be-x-old|bg|bh|bi|bjn|bm|bn|bo|bpy|br|bs|bug|bxr|ca|cbk-zam|cdo|ce|ceb|ch|cho|chr|chy|ckb|co|cr|crh|cs|csb|cu|cv|cy|da|de|diq|dsb|dv|dz|ee|el|eml|en|eo|es|et|eu|ext|fa|ff|fi|fiu-vro|fj|fo|fr|frp|frr|fur|fy|ga|gag|gan|gd|gl|glk|gn|got|gu|gv|ha|hak|haw|he|hi|hif|ho|hr|hsb|ht|hu|hy|hz|ia|id|ie|ig|ii|ik|ilo|io|is|it|iu|ja|jbo|jv|ka|kaa|kab|kbd|kg|ki|kj|kk|kl|km|kn|ko|koi|kr|krc|ks|ksh|ku|kv|kw|ky|la|lad|lb|lbe|lg|li|lij|lmo|ln|lo|lt|ltg|lv|map-bms|mdf|mg|mh|mhr|mi|mk|ml|mn|mo|mr|mrj|ms|mt|mus|mwl|my|myv|mzn|na|nah|nap|nds|nds-nl|ne|new|ng|nl|nn|no|nov|nrm|nv|ny|oc|om|or|os|pa|pag|pam|pap|pcd|pdc|pfl|pi|pih|pl|pms|pnb|pnt|ps|pt|qu|rm|rmy|rn|ro|roa-rup|roa-tara|ru|rue|rw|sa|sah|sc|scn|sco|sd|se|sg|sh|si|simple|sk|sl|sm|sn|so|sq|sr|srn|ss|st|stq|su|sv|sw|szl|ta|te|tet|tg|th|ti|tk|tl|tn|to|tpi|tr|ts|tt|tum|tw|ty|udm|ug|uk|ur|uz|ve|vec|vi|vls|vo|wa|war|wo|wuu|xal|xh|yi|yo|za|zea|zh|zh-classical|zh-min-nan|zh-yue|zu';
			pg.re.interwiki = RegExp('^' + pg.wiki.interwiki + ':');
		} else {
			pg.wiki.interwiki = null;
			pg.re.interwiki = RegExp('^$');
		}
	}

	// return a regexp pattern matching all variants to write the given namespace
	function nsRe(namespaceId) {
		var imageNamespaceVariants = [];
		jQuery.each(mw.config.get('wgNamespaceIds'), function (_localizedNamespaceLc, _namespaceId) {
			if (_namespaceId != namespaceId) {
				return;
			}
			_localizedNamespaceLc = upcaseFirst(_localizedNamespaceLc);
			imageNamespaceVariants.push(
				mw.util.escapeRegExp(_localizedNamespaceLc).split(' ').join('[ _]')
			);
			imageNamespaceVariants.push(mw.util.escapeRegExp(encodeURI(_localizedNamespaceLc)));
		});

		return '(?:' + imageNamespaceVariants.join('|') + ')';
	}

	function nsReImage() {
		return nsRe(pg.nsImageId);
	}
	// ENDFILE: namespaces.js

	// STARTFILE: selpop.js
	function getEditboxSelection() {
		// see http://www.webgurusforum.com/8/12/0
		var editbox;
		try {
			editbox = document.editform.wpTextbox1;
		} catch (dang) {
			return;
		}
		// IE, Opera
		if (document.selection) {
			return document.selection.createRange().text;
		}
		// Mozilla
		var selStart = editbox.selectionStart;
		var selEnd = editbox.selectionEnd;
		return editbox.value.substring(selStart, selEnd);
	}

	function doSelectionPopup() {
		// popup if the selection looks like [[foo|anything afterwards at all
		// or [[foo|bar]]text without ']]'
		// or [[foo|bar]]
		var sel = getEditboxSelection();
		var open = sel.indexOf('[[');
		var pipe = sel.indexOf('|');
		var close = sel.indexOf(']]');
		if (open == -1 || (pipe == -1 && close == -1)) {
			return;
		}
		if ((pipe != -1 && open > pipe) || (close != -1 && open > close)) {
			return;
		}
		var article = new Title(sel.substring(open + 2, pipe < 0 ? close : pipe));
		if (getValueOf('popupOnEditSelection') == 'boxpreview') {
			return doSeparateSelectionPopup(sel, article);
		}
		if (close > 0 && sel.substring(close + 2).indexOf('[[') >= 0) {
			return;
		}
		var a = document.createElement('a');
		a.href = pg.wiki.titlebase + article.urlString();
		mouseOverWikiLink2(a);
		if (a.navpopup) {
			a.navpopup.addHook(
				function () {
					runStopPopupTimer(a.navpopup);
				},
				'unhide',
				'after'
			);
		}
	}

	function doSeparateSelectionPopup(str, article) {
		var div = document.getElementById('selectionPreview');
		if (!div) {
			div = document.createElement('div');
			div.id = 'selectionPreview';
			try {
				var box = document.editform.wpTextbox1;
				box.parentNode.insertBefore(div, box);
			} catch (error) {
				return;
			}
		}
		var p = prepPreviewmaker(str, article, newNavpopup(document.createElement('a'), article));
		p.makePreview();
		if (p.html) {
			div.innerHTML = p.html;
		}
		div.ranSetupTooltipsAlready = false;
		popTipsSoonFn('selectionPreview')();
	}
	// ENDFILE: selpop.js

	// STARTFILE: navpopup.js
	/**
	 * @fileoverview  Defines two classes: {@link Navpopup} and {@link Mousetracker}.
	 *
	 * <code>Navpopup</code> describes popups: when they appear, where, what
	 * they look like and so on.
	 *
	 * <code>Mousetracker</code> "captures" the mouse using
	 * <code>document.onmousemove</code>.
	 */

	/**
	 * Creates a new Mousetracker.
	 * @constructor
	 * @class The Mousetracker class. This monitors mouse movements and manages associated hooks.
	 */
	function Mousetracker() {
		/**
		 * Interval to regularly run the hooks anyway, in milliseconds.
		 * @type {number}
		 */
		this.loopDelay = 400;

		/**
		 * Timer for the loop.
		 * @type Timer
		 */
		this.timer = null;

		/**
		 * Flag - are we switched on?
		 * @type {boolean}
		 */
		this.active = false;

		/**
		 * Flag - are we probably inaccurate, i.e. not reflecting the actual mouse position?
		 */
		this.dirty = true;

		/**
		 * Array of hook functions.
		 * @private
		 * @type {Array}
		 */
		this.hooks = [];
	}

	/**
	 * Adds a hook, to be called when we get events.
	 * @param {Function} f A function which is called as
	 * <code>f(x,y)</code>. It should return <code>true</code> when it
	 * wants to be removed, and <code>false</code> otherwise.
	 */
	Mousetracker.prototype.addHook = function (f) {
		this.hooks.push(f);
	};

	/**
	 * Runs hooks, passing them the x
	 * and y coords of the mouse.  Hook functions that return true are
	 * passed to {@link Mousetracker#removeHooks} for removal.
	 * @private
	 */
	Mousetracker.prototype.runHooks = function () {
		if (!this.hooks || !this.hooks.length) {
			return;
		}
		//log('Mousetracker.runHooks; we got some hooks to run');
		var remove = false;
		var removeObj = {};
		// this method gets called a LOT -
		// pre-cache some variables
		var x = this.x,
			y = this.y,
			len = this.hooks.length;

		for (var i = 0; i < len; ++i) {
			//~ run the hook function, and remove it if it returns true
			if (this.hooks[i](x, y) === true) {
				remove = true;
				removeObj[i] = true;
			}
		}
		if (remove) {
			this.removeHooks(removeObj);
		}
	};

	/**
	 * Removes hooks.
	 * @private
	 * @param {Object} removeObj An object whose keys are the index
	 * numbers of functions for removal, with values that evaluate to true
	 */
	Mousetracker.prototype.removeHooks = function (removeObj) {
		var newHooks = [];
		var len = this.hooks.length;
		for (var i = 0; i < len; ++i) {
			if (!removeObj[i]) {
				newHooks.push(this.hooks[i]);
			}
		}
		this.hooks = newHooks;
	};

	/**
	 * Event handler for mouse wiggles.
	 * We simply grab the event, set x and y and run the hooks.
	 * This makes the cpu all hot and bothered :-(
	 * @private
	 * @param {Event} e Mousemove event
	 */
	Mousetracker.prototype.track = function (e) {
		//~ Apparently this is needed in IE.
		e = e || window.event;
		var x, y;
		if (e) {
			if (e.pageX) {
				x = e.pageX;
				y = e.pageY;
			} else if (typeof e.clientX != 'undefined') {
				var left,
					top,
					docElt = document.documentElement;

				if (docElt) {
					left = docElt.scrollLeft;
				}
				left = left || document.body.scrollLeft || document.scrollLeft || 0;

				if (docElt) {
					top = docElt.scrollTop;
				}
				top = top || document.body.scrollTop || document.scrollTop || 0;

				x = e.clientX + left;
				y = e.clientY + top;
			} else {
				return;
			}
			this.setPosition(x, y);
		}
	};

	/**
	 * Sets the x and y coordinates stored and takes appropriate action,
	 * running hooks as appropriate.
	 * @param {number} x, y Screen coordinates to set
	 */
	Mousetracker.prototype.setPosition = function (x, y) {
		this.x = x;
		this.y = y;
		if (this.dirty || this.hooks.length === 0) {
			this.dirty = false;
			return;
		}
		if (typeof this.lastHook_x != 'number') {
			this.lastHook_x = -100;
			this.lastHook_y = -100;
		}
		var diff = (this.lastHook_x - x) * (this.lastHook_y - y);
		diff = diff >= 0 ? diff : -diff;
		if (diff > 1) {
			this.lastHook_x = x;
			this.lastHook_y = y;
			if (this.dirty) {
				this.dirty = false;
			} else {
				this.runHooks();
			}
		}
	};

	/**
	 * Sets things in motion, unless they are already that is, registering an event handler on
	 * <code>document.onmousemove</code>. A half-hearted attempt is made to preserve the old event
	 * handler if there is one.
	 */
	Mousetracker.prototype.enable = function () {
		if (this.active) {
			return;
		}
		this.active = true;
		//~ Save the current handler for mousemove events. This isn't too
		//~ robust, of course.
		this.savedHandler = document.onmousemove;
		//~ Gotta save @tt{this} again for the closure, and use apply for
		//~ the member function.
		var savedThis = this;
		document.onmousemove = function (e) {
			savedThis.track.apply(savedThis, [e]);
		};
		if (this.loopDelay) {
			this.timer = setInterval(function () {
				//log('loop delay in mousetracker is working');
				savedThis.runHooks();
			}, this.loopDelay);
		}
	};

	/**
	 * Disables the tracker, removing the event handler.
	 */
	Mousetracker.prototype.disable = function () {
		if (!this.active) {
			return;
		}
		if (typeof this.savedHandler === 'function') {
			document.onmousemove = this.savedHandler;
		} else {
			delete document.onmousemove;
		}
		if (this.timer) {
			clearInterval(this.timer);
		}
		this.active = false;
	};

	/**
	 * Creates a new Navpopup.
	 * Gets a UID for the popup and
	 * @param init Contructor object. If <code>init.draggable</code> is true or absent, the popup becomes draggable.
	 * @constructor
	 * @class The Navpopup class. This generates popup hints, and does some management of them.
	 */
	function Navpopup(/*init*/) {
		//alert('new Navpopup(init)');

		/**
		 * UID for each Navpopup instance.
		 * Read-only.
		 * @type {number}
		 */
		this.uid = Navpopup.uid++;

		/**
		 * Read-only flag for current visibility of the popup.
		 * @type {boolean}
		 * @private
		 */
		this.visible = false;

		/** Flag to be set when we want to cancel a previous request to
		 * show the popup in a little while.
		 * @private
		 * @type {boolean}
		 */
		this.noshow = false;

		/** Categorised list of hooks.
		 * @see #runHooks
		 * @see #addHook
		 * @private
		 * @type {Object}
		 */
		this.hooks = {
			create: [],
			unhide: [],
			hide: [],
		};

		/**
		 * list of unique IDs of hook functions, to avoid duplicates
		 * @private
		 */
		this.hookIds = {};

		/** List of downloads associated with the popup.
		 * @private
		 * @type {Array}
		 */
		this.downloads = [];

		/**
		 * Number of uncompleted downloads.
		 * @type {number}
		 */
		this.pending = null;

		/**
		 * Tolerance in pixels when detecting whether the mouse has left the popup.
		 * @type {number}
		 */
		this.fuzz = 5;

		/**
		 * Flag to toggle running {@link #limitHorizontalPosition} to regulate the popup's position.
		 * @type {boolean}
		 */
		this.constrained = true;

		/**
		 * The popup width in pixels.
		 * @private
		 * @type {number}
		 */
		this.width = 0;

		/**
		 * The popup width in pixels.
		 * @private
		 * @type {number}
		 */
		this.height = 0;

		/**
		 * The main content DIV element.
		 * @type HTMLDivElement
		 */
		this.mainDiv = null;
		this.createMainDiv();

		//	if (!init || typeof init.popups_draggable=='undefined' || init.popups_draggable) {
		//		this.makeDraggable(true);
		//	}
	}

	/**
	 * A UID for each Navpopup. This constructor property is just a counter.
	 * @type {number}
	 * @private
	 */
	Navpopup.uid = 0;

	/**
	 * Retrieves the {@link #visible} attribute, indicating whether the popup is currently visible.
	 * @type {boolean}
	 */
	Navpopup.prototype.isVisible = function () {
		return this.visible;
	};

	/**
	 * Repositions popup using CSS style.
	 * @private
	 * @param {number} x x-coordinate (px)
	 * @param {number} y y-coordinate (px)
	 * @param {boolean} noLimitHor Don't call {@link #limitHorizontalPosition}
	 */
	Navpopup.prototype.reposition = function (x, y, noLimitHor) {
		log('reposition(' + x + ',' + y + ',' + noLimitHor + ')');
		if (typeof x != 'undefined' && x !== null) {
			this.left = x;
		}
		if (typeof y != 'undefined' && y !== null) {
			this.top = y;
		}
		if (typeof this.left != 'undefined' && typeof this.top != 'undefined') {
			this.mainDiv.style.left = this.left + 'px';
			this.mainDiv.style.top = this.top + 'px';
		}
		if (!noLimitHor) {
			this.limitHorizontalPosition();
		}
		//console.log('navpop'+this.uid+' - (left,top)=(' + this.left + ',' + this.top + '), css=('
		//+ this.mainDiv.style.left + ',' + this.mainDiv.style.top + ')');
	};

	/**
	 * Prevents popups from being in silly locations. Hopefully.
	 * Should not be run if {@link #constrained} is true.
	 * @private
	 */
	Navpopup.prototype.limitHorizontalPosition = function () {
		if (!this.constrained || this.tooWide) {
			return;
		}
		this.updateDimensions();
		var x = this.left;
		var w = this.width;
		var cWidth = document.body.clientWidth;

		//	log('limitHorizontalPosition: x='+x+
		//			', this.left=' + this.left +
		//			', this.width=' + this.width +
		//			', cWidth=' + cWidth);

		if (
			x + w >= cWidth ||
			(x > 0 &&
				this.maxWidth &&
				this.width < this.maxWidth &&
				this.height > this.width &&
				x > cWidth - this.maxWidth)
		) {
			// This is a very nasty hack. There has to be a better way!
			// We find the "natural" width of the div by positioning it at the far left
			// then reset it so that it should be flush right (well, nearly)
			this.mainDiv.style.left = '-10000px';
			this.mainDiv.style.width = this.maxWidth + 'px';
			var naturalWidth = parseInt(this.mainDiv.offsetWidth, 10);
			var newLeft = cWidth - naturalWidth - 1;
			if (newLeft < 0) {
				newLeft = 0;
				this.tooWide = true;
			} // still unstable for really wide popups?
			log(
				'limitHorizontalPosition: moving to (' +
					newLeft +
					',' +
					this.top +
					');' +
					' naturalWidth=' +
					naturalWidth +
					', clientWidth=' +
					cWidth
			);
			this.reposition(newLeft, null, true);
		}
	};

	/**
	 * Counter indicating the z-order of the "highest" popup.
	 * We start the z-index at 1000 so that popups are above everything
	 * else on the screen.
	 * @private
	 * @type {number}
	 */
	Navpopup.highest = 1000;

	/**
	 * Brings popup to the top of the z-order.
	 * We increment the {@link #highest} property of the contructor here.
	 * @private
	 */
	Navpopup.prototype.raise = function () {
		this.mainDiv.style.zIndex = Navpopup.highest + 1;
		++Navpopup.highest;
	};

	/**
	 * Shows the popup provided {@link #noshow} is not true.
	 * Updates the position, brings the popup to the top of the z-order and unhides it.
	 */
	Navpopup.prototype.show = function () {
		//document.title+='s';
		if (this.noshow) {
			return;
		}
		//document.title+='t';
		this.reposition();
		this.raise();
		this.unhide();
	};

	/**
	 * Checks to see if the mouse pointer has
	 * stabilised (checking every <code>time</code>/2 milliseconds) and runs the
	 * {@link #show} method if it has.
	 * @param {number} time The minimum time (ms) before the popup may be shown.
	 */
	Navpopup.prototype.showSoonIfStable = function (time) {
		log('showSoonIfStable, time=' + time);
		if (this.visible) {
			return;
		}
		this.noshow = false;

		//~ initialize these variables so that we never run @tt{show} after
		//~ just half the time
		this.stable_x = -10000;
		this.stable_y = -10000;

		var stableShow = function () {
			log('stableShow called');
			var new_x = Navpopup.tracker.x,
				new_y = Navpopup.tracker.y;
			var dx = savedThis.stable_x - new_x,
				dy = savedThis.stable_y - new_y;
			var fuzz2 = 0; // savedThis.fuzz * savedThis.fuzz;
			//document.title += '[' + [savedThis.stable_x,new_x, savedThis.stable_y,new_y, dx, dy, fuzz2].join(',') + '] ';
			if (dx * dx <= fuzz2 && dy * dy <= fuzz2) {
				log('mouse is stable');
				clearInterval(savedThis.showSoonStableTimer);
				savedThis.reposition.apply(savedThis, [new_x + 2, new_y + 2]);
				savedThis.show.apply(savedThis, []);
				savedThis.limitHorizontalPosition.apply(savedThis, []);
				return;
			}
			savedThis.stable_x = new_x;
			savedThis.stable_y = new_y;
		};
		var savedThis = this;
		this.showSoonStableTimer = setInterval(stableShow, time / 2);
	};

	/**
	 * Sets the {@link #noshow} flag and hides the popup. This should be called
	 * when the mouse leaves the link before
	 * (or after) it's actually been displayed.
	 */
	Navpopup.prototype.banish = function () {
		log('banish called');
		// hide and prevent showing with showSoon in the future
		this.noshow = true;
		if (this.showSoonStableTimer) {
			log('clearing showSoonStableTimer');
			clearInterval(this.showSoonStableTimer);
		}
		this.hide();
	};

	/**
	 * Runs hooks added with {@link #addHook}.
	 * @private
	 * @param {String} key Key name of the {@link #hooks} array - one of 'create', 'unhide', 'hide'
	 * @param {String} when Controls exactly when the hook is run: either 'before' or 'after'
	 */
	Navpopup.prototype.runHooks = function (key, when) {
		if (!this.hooks[key]) {
			return;
		}
		var keyHooks = this.hooks[key];
		var len = keyHooks.length;
		for (var i = 0; i < len; ++i) {
			if (keyHooks[i] && keyHooks[i].when == when) {
				if (keyHooks[i].hook.apply(this, [])) {
					// remove the hook
					if (keyHooks[i].hookId) {
						delete this.hookIds[keyHooks[i].hookId];
					}
					keyHooks[i] = null;
				}
			}
		}
	};

	/**
	 * Adds a hook to the popup. Hook functions are run with <code>this</code> set to refer to the
	 * Navpopup instance, and no arguments.
	 * @param {Function} hook The hook function. Functions that return true are deleted.
	 * @param {String} key Key name of the {@link #hooks} array - one of 'create', 'unhide', 'hide'
	 * @param {String} when Controls exactly when the hook is run: either 'before' or 'after'
	 * @param {String} uid A truthy string identifying the hook function; if it matches another hook
	 * in this position, it won't be added again.
	 */
	Navpopup.prototype.addHook = function (hook, key, when, uid) {
		when = when || 'after';
		if (!this.hooks[key]) {
			return;
		}
		// if uid is specified, don't add duplicates
		var hookId = null;
		if (uid) {
			hookId = [key, when, uid].join('|');
			if (this.hookIds[hookId]) {
				return;
			}
			this.hookIds[hookId] = true;
		}
		this.hooks[key].push({ hook: hook, when: when, hookId: hookId });
	};

	/**
	 * Creates the main DIV element, which contains all the actual popup content.
	 * Runs hooks with key 'create'.
	 * @private
	 */
	Navpopup.prototype.createMainDiv = function () {
		if (this.mainDiv) {
			return;
		}
		this.runHooks('create', 'before');
		var mainDiv = document.createElement('div');

		var savedThis = this;
		mainDiv.onclick = function (e) {
			savedThis.onclickHandler(e);
		};
		mainDiv.className = this.className ? this.className : 'navpopup_maindiv';
		mainDiv.id = mainDiv.className + this.uid;

		mainDiv.style.position = 'absolute';
		mainDiv.style.minWidth = '350px';
		mainDiv.style.display = 'none';
		mainDiv.className = 'navpopup';

		// easy access to javascript object through DOM functions
		mainDiv.navpopup = this;

		this.mainDiv = mainDiv;
		document.body.appendChild(mainDiv);
		this.runHooks('create', 'after');
	};

	/**
	 * Calls the {@link #raise} method.
	 * @private
	 */
	Navpopup.prototype.onclickHandler = function (/*e*/) {
		this.raise();
	};

	/**
	 * Makes the popup draggable, using a {@link Drag} object.
	 * @private
	 */
	Navpopup.prototype.makeDraggable = function (handleName) {
		if (!this.mainDiv) {
			this.createMainDiv();
		}
		var drag = new Drag();
		if (!handleName) {
			drag.startCondition = function (e) {
				try {
					if (!e.shiftKey) {
						return false;
					}
				} catch (err) {
					return false;
				}
				return true;
			};
		}
		var dragHandle;
		if (handleName) {
			dragHandle = document.getElementById(handleName);
		}
		if (!dragHandle) {
			dragHandle = this.mainDiv;
		}
		var np = this;
		drag.endHook = function (x, y) {
			Navpopup.tracker.dirty = true;
			np.reposition(x, y);
		};
		drag.init(dragHandle, this.mainDiv);
	};

	/**
	 * Hides the popup using CSS. Runs hooks with key 'hide'.
	 * Sets {@link #visible} appropriately.
	 * {@link #banish} should be called externally instead of this method.
	 * @private
	 */
	Navpopup.prototype.hide = function () {
		this.runHooks('hide', 'before');
		this.abortDownloads();
		if (typeof this.visible != 'undefined' && this.visible) {
			this.mainDiv.style.display = 'none';
			this.visible = false;
		}
		this.runHooks('hide', 'after');
	};

	/**
	 * Shows the popup using CSS. Runs hooks with key 'unhide'.
	 * Sets {@link #visible} appropriately.   {@link #show} should be called externally instead of this method.
	 * @private
	 */
	Navpopup.prototype.unhide = function () {
		this.runHooks('unhide', 'before');
		if (typeof this.visible != 'undefined' && !this.visible) {
			this.mainDiv.style.display = 'inline';
			this.visible = true;
		}
		this.runHooks('unhide', 'after');
	};

	/**
	 * Sets the <code>innerHTML</code> attribute of the main div containing the popup content.
	 * @param {String} html The HTML to set.
	 */
	Navpopup.prototype.setInnerHTML = function (html) {
		this.mainDiv.innerHTML = html;
	};

	/**
	 * Updates the {@link #width} and {@link #height} attributes with the CSS properties.
	 * @private
	 */
	Navpopup.prototype.updateDimensions = function () {
		this.width = parseInt(this.mainDiv.offsetWidth, 10);
		this.height = parseInt(this.mainDiv.offsetHeight, 10);
	};

	/**
	 * Checks if the point (x,y) is within {@link #fuzz} of the
	 * {@link #mainDiv}.
	 * @param {number} x x-coordinate (px)
	 * @param {number} y y-coordinate (px)
	 * @type {boolean}
	 */
	Navpopup.prototype.isWithin = function (x, y) {
		//~ If we're not even visible, no point should be considered as
		//~ being within the popup.
		if (!this.visible) {
			return false;
		}
		this.updateDimensions();
		var fuzz = this.fuzz || 0;
		//~ Use a simple box metric here.
		return (
			x + fuzz >= this.left &&
			x - fuzz <= this.left + this.width &&
			y + fuzz >= this.top &&
			y - fuzz <= this.top + this.height
		);
	};

	/**
	 * Adds a download to {@link #downloads}.
	 * @param {Downloader} download
	 */
	Navpopup.prototype.addDownload = function (download) {
		if (!download) {
			return;
		}
		this.downloads.push(download);
	};

	/**
	 * Aborts the downloads listed in {@link #downloads}.
	 * @see Downloader#abort
	 */
	Navpopup.prototype.abortDownloads = function () {
		for (var i = 0; i < this.downloads.length; ++i) {
			var d = this.downloads[i];
			if (d && d.abort) {
				d.abort();
			}
		}
		this.downloads = [];
	};

	/**
	 * A {@link Mousetracker} instance which is a property of the constructor (pseudo-global).
	 */
	Navpopup.tracker = new Mousetracker();
	// ENDFILE: navpopup.js

	// STARTFILE: diff.js
	/*
	 * Javascript Diff Algorithm
	 *  By John Resig (http://ejohn.org/) and [[:en:User:Lupin]]
	 *
	 * More Info:
	 *  http://ejohn.org/projects/javascript-diff-algorithm/
	 */

	function delFmt(x) {
		if (!x.length) {
			return '';
		}
		return "<del class='popupDiff'>" + x.join('') + '</del>';
	}

	function insFmt(x) {
		if (!x.length) {
			return '';
		}
		return "<ins class='popupDiff'>" + x.join('') + '</ins>';
	}

	function countCrossings(a, b, i, eject) {
		// count the crossings on the edge starting at b[i]
		if (!b[i].row && b[i].row !== 0) {
			return -1;
		}
		var count = 0;
		for (var j = 0; j < a.length; ++j) {
			if (!a[j].row && a[j].row !== 0) {
				continue;
			}
			if ((j - b[i].row) * (i - a[j].row) > 0) {
				if (eject) {
					return true;
				}
				count++;
			}
		}
		return count;
	}

	function shortenDiffString(str, context) {
		var re = RegExp('(<del[\\s\\S]*?</del>|<ins[\\s\\S]*?</ins>)');
		var splitted = str.parenSplit(re);
		var ret = [''];
		for (var i = 0; i < splitted.length; i += 2) {
			if (splitted[i].length < 2 * context) {
				ret[ret.length - 1] += splitted[i];
				if (i + 1 < splitted.length) {
					ret[ret.length - 1] += splitted[i + 1];
				}
				continue;
			} else {
				if (i > 0) {
					ret[ret.length - 1] += splitted[i].substring(0, context);
				}
				if (i + 1 < splitted.length) {
					ret.push(splitted[i].substring(splitted[i].length - context) + splitted[i + 1]);
				}
			}
		}
		while (ret.length > 0 && !ret[0]) {
			ret = ret.slice(1);
		}
		return ret;
	}

	function diffString(o, n, simpleSplit) {
		var splitRe = RegExp('([[]{2}|[\\]]{2}|[{]{2,3}|[}]{2,3}|[|]|=|<|>|[*:]+|\\s|\\b)');

		//  We need to split the strings o and n first, and entify() the parts
		//  individually, so that the HTML entities are never cut apart. (AxelBoldt)
		var out, i, oSplitted, nSplitted;
		if (simpleSplit) {
			oSplitted = o.split(/\b/);
			nSplitted = n.split(/\b/);
		} else {
			oSplitted = o.parenSplit(splitRe);
			nSplitted = n.parenSplit(splitRe);
		}
		for (i = 0; i < oSplitted.length; ++i) {
			oSplitted[i] = oSplitted[i].entify();
		}
		for (i = 0; i < nSplitted.length; ++i) {
			nSplitted[i] = nSplitted[i].entify();
		}

		out = diff(oSplitted, nSplitted);
		var str = '';
		var acc = []; // accumulator for prettier output

		// crossing pairings -- eg 'A B' vs 'B A' -- cause problems, so let's iron them out
		// this doesn't always do things optimally but it should be fast enough
		var maxOutputPair = 0;
		for (i = 0; i < out.n.length; ++i) {
			if (out.n[i].paired) {
				if (maxOutputPair > out.n[i].row) {
					// tangle - delete pairing
					out.o[out.n[i].row] = out.o[out.n[i].row].text;
					out.n[i] = out.n[i].text;
				}
				if (maxOutputPair < out.n[i].row) {
					maxOutputPair = out.n[i].row;
				}
			}
		}

		// output the stuff preceding the first paired old line
		for (i = 0; i < out.o.length && !out.o[i].paired; ++i) {
			acc.push(out.o[i]);
		}
		str += delFmt(acc);
		acc = [];

		// main loop
		for (i = 0; i < out.n.length; ++i) {
			// output unpaired new "lines"
			while (i < out.n.length && !out.n[i].paired) {
				acc.push(out.n[i++]);
			}
			str += insFmt(acc);
			acc = [];
			if (i < out.n.length) {
				// this new "line" is paired with the (out.n[i].row)th old "line"
				str += out.n[i].text;
				// output unpaired old rows starting after this new line's partner
				var m = out.n[i].row + 1;
				while (m < out.o.length && !out.o[m].paired) {
					acc.push(out.o[m++]);
				}
				str += delFmt(acc);
				acc = [];
			}
		}
		return str;
	}

	// see http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object
	// FIXME: use obj.hasOwnProperty instead of this kludge!
	var jsReservedProperties = RegExp(
		'^(constructor|prototype|__((define|lookup)[GS]etter)__' +
			'|eval|hasOwnProperty|propertyIsEnumerable' +
			'|to(Source|String|LocaleString)|(un)?watch|valueOf)$'
	);

	function diffBugAlert(word) {
		if (!diffBugAlert.list[word]) {
			diffBugAlert.list[word] = 1;
			alert('Bad word: ' + word + '\n\nPlease report this bug.');
		}
	}

	diffBugAlert.list = {};

	function makeDiffHashtable(src) {
		var ret = {};
		for (var i = 0; i < src.length; i++) {
			if (jsReservedProperties.test(src[i])) {
				src[i] += '<!-- -->';
			}
			if (!ret[src[i]]) {
				ret[src[i]] = [];
			}
			try {
				ret[src[i]].push(i);
			} catch (err) {
				diffBugAlert(src[i]);
			}
		}
		return ret;
	}

	function diff(o, n) {
		// pass 1: make hashtable ns with new rows as keys
		var ns = makeDiffHashtable(n);

		// pass 2: make hashtable os with old rows as keys
		var os = makeDiffHashtable(o);

		// pass 3: pair unique new rows and matching unique old rows
		var i;
		for (i in ns) {
			if (ns[i].length == 1 && os[i] && os[i].length == 1) {
				n[ns[i][0]] = { text: n[ns[i][0]], row: os[i][0], paired: true };
				o[os[i][0]] = { text: o[os[i][0]], row: ns[i][0], paired: true };
			}
		}

		// pass 4: pair matching rows immediately following paired rows (not necessarily unique)
		for (i = 0; i < n.length - 1; i++) {
			if (
				n[i].paired &&
				!n[i + 1].paired &&
				n[i].row + 1 < o.length &&
				!o[n[i].row + 1].paired &&
				n[i + 1] == o[n[i].row + 1]
			) {
				n[i + 1] = { text: n[i + 1], row: n[i].row + 1, paired: true };
				o[n[i].row + 1] = { text: o[n[i].row + 1], row: i + 1, paired: true };
			}
		}

		// pass 5: pair matching rows immediately preceding paired rows (not necessarily unique)
		for (i = n.length - 1; i > 0; i--) {
			if (
				n[i].paired &&
				!n[i - 1].paired &&
				n[i].row > 0 &&
				!o[n[i].row - 1].paired &&
				n[i - 1] == o[n[i].row - 1]
			) {
				n[i - 1] = { text: n[i - 1], row: n[i].row - 1, paired: true };
				o[n[i].row - 1] = { text: o[n[i].row - 1], row: i - 1, paired: true };
			}
		}

		return { o: o, n: n };
	}
	// ENDFILE: diff.js

	// STARTFILE: init.js
	function setSiteInfo() {
		if (window.popupLocalDebug) {
			pg.wiki.hostname = 'en.wikipedia.org';
		} else {
			pg.wiki.hostname = location.hostname; // use in preference to location.hostname for flexibility (?)
		}
		pg.wiki.wikimedia = RegExp(
			'(wiki([pm]edia|source|books|news|quote|versity|species|voyage|data)|metawiki|wiktionary|mediawiki)[.]org'
		).test(pg.wiki.hostname);
		pg.wiki.wikia = RegExp('[.]wikia[.]com$', 'i').test(pg.wiki.hostname);
		pg.wiki.isLocal = RegExp('^localhost').test(pg.wiki.hostname);
		pg.wiki.commons =
			pg.wiki.wikimedia && pg.wiki.hostname != 'commons.wikimedia.org'
				? 'commons.wikimedia.org'
				: null;
		pg.wiki.lang = mw.config.get('wgContentLanguage');
		var port = location.port ? ':' + location.port : '';
		pg.wiki.sitebase = pg.wiki.hostname + port;
	}

	function setUserInfo() {
		var params = {
			action: 'query',
			list: 'users',
			ususers: mw.config.get('wgUserName'),
			usprop: 'rights',
		};

		pg.user.canReview = false;
		if (getValueOf('popupReview')) {
			getMwApi()
				.get(params)
				.done(function (data) {
					var rights = data.query.users[0].rights;
					pg.user.canReview = rights.indexOf('review') !== -1; // TODO: Should it be a getValueOf('ReviewRight') ?
				});
		}
	}

	function fetchSpecialPageNames() {
		var params = {
			action: 'query',
			meta: 'siteinfo',
			siprop: 'specialpagealiases',
			formatversion: 2,
			// cache for an hour
			uselang: 'content',
			maxage: 3600,
		};
		return getMwApi()
			.get(params)
			.then(function (data) {
				pg.wiki.specialpagealiases = data.query.specialpagealiases;
			});
	}

	function setTitleBase() {
		var protocol = window.popupLocalDebug ? 'http:' : location.protocol;
		pg.wiki.articlePath = mw.config.get('wgArticlePath').replace(/\/\$1/, ''); // as in http://some.thing.com/wiki/Article
		pg.wiki.botInterfacePath = mw.config.get('wgScript');
		pg.wiki.APIPath = mw.config.get('wgScriptPath') + '/api.php';
		// default mediawiki setting is paths like http://some.thing.com/articlePath/index.php?title=foo

		var titletail = pg.wiki.botInterfacePath + '?title=';
		//var titletail2 = joinPath([pg.wiki.botInterfacePath, 'wiki.phtml?title=']);

		// other sites may need to add code here to set titletail depending on how their urls work

		pg.wiki.titlebase = protocol + '//' + pg.wiki.sitebase + titletail;
		//pg.wiki.titlebase2  = protocol + '//' + joinPath([pg.wiki.sitebase, titletail2]);
		pg.wiki.wikibase = protocol + '//' + pg.wiki.sitebase + pg.wiki.botInterfacePath;
		pg.wiki.apiwikibase = protocol + '//' + pg.wiki.sitebase + pg.wiki.APIPath;
		pg.wiki.articlebase = protocol + '//' + pg.wiki.sitebase + pg.wiki.articlePath;
		pg.wiki.commonsbase = protocol + '//' + pg.wiki.commons + pg.wiki.botInterfacePath;
		pg.wiki.apicommonsbase = protocol + '//' + pg.wiki.commons + pg.wiki.APIPath;
		pg.re.basenames = RegExp(
			'^(' +
				map(literalizeRegex, [
					pg.wiki.titlebase, //pg.wiki.titlebase2,
					pg.wiki.articlebase,
				]).join('|') +
				')'
		);
	}

	//////////////////////////////////////////////////
	// Global regexps

	function setMainRegex() {
		var reStart = '[^:]*://';
		var preTitles =
			literalizeRegex(mw.config.get('wgScriptPath')) + '/(?:index[.]php|wiki[.]phtml)[?]title=';
		preTitles += '|' + literalizeRegex(pg.wiki.articlePath + '/');

		var reEnd = '(' + preTitles + ')([^&?#]*)[^#]*(?:#(.+))?';
		pg.re.main = RegExp(reStart + literalizeRegex(pg.wiki.sitebase) + reEnd);
	}

	function buildSpecialPageGroup(specialPageObj) {
		var variants = [];
		variants.push(mw.util.escapeRegExp(specialPageObj['realname']));
		variants.push(mw.util.escapeRegExp(encodeURI(specialPageObj['realname'])));
		specialPageObj.aliases.forEach(function (alias) {
			variants.push(mw.util.escapeRegExp(alias));
			variants.push(mw.util.escapeRegExp(encodeURI(alias)));
		});
		return variants.join('|');
	}

	function setRegexps() {
		setMainRegex();
		var sp = nsRe(pg.nsSpecialId);
		pg.re.urlNoPopup = RegExp('((title=|/)' + sp + '(?:%3A|:)|section=[0-9]|^#$)');

		pg.wiki.specialpagealiases.forEach(function (specialpage) {
			if (specialpage.realname === 'Contributions') {
				pg.re.contribs = RegExp(
					'(title=|/)' +
						sp +
						'(?:%3A|:)(?:' +
						buildSpecialPageGroup(specialpage) +
						')' +
						'(&target=|/|/' +
						nsRe(pg.nsUserId) +
						':)(.*)',
					'i'
				);
			} else if (specialpage.realname === 'Diff') {
				pg.re.specialdiff = RegExp(
					'/' + sp + '(?:%3A|:)(?:' + buildSpecialPageGroup(specialpage) + ')' + '/([^?#]*)',
					'i'
				);
			} else if (specialpage.realname === 'Emailuser') {
				pg.re.email = RegExp(
					'(title=|/)' +
						sp +
						'(?:%3A|:)(?:' +
						buildSpecialPageGroup(specialpage) +
						')' +
						'(&target=|/|/(?:' +
						nsRe(pg.nsUserId) +
						':)?)(.*)',
					'i'
				);
			} else if (specialpage.realname === 'Whatlinkshere') {
				pg.re.backlinks = RegExp(
					'(title=|/)' +
						sp +
						'(?:%3A|:)(?:' +
						buildSpecialPageGroup(specialpage) +
						')' +
						'(&target=|/)([^&]*)',
					'i'
				);
			}
		});

		var im = nsReImage();
		// note: tries to get images in infobox templates too, e.g. movie pages, album pages etc
		//					  (^|\[\[)image: *([^|\]]*[^|\] ]) *
		//					  (^|\[\[)image: *([^|\]]*[^|\] ])([^0-9\]]*([0-9]+) *px)?
		//														$4 = 120 as in 120px
		pg.re.image = RegExp(
			'(^|\\[\\[)' +
				im +
				': *([^|\\]]*[^|\\] ])' +
				'([^0-9\\]]*([0-9]+) *px)?|(?:\\n *[|]?|[|]) *' +
				'(' +
				getValueOf('popupImageVarsRegexp') +
				')' +
				' *= *(?:\\[\\[ *)?(?:' +
				im +
				':)?' +
				'([^|]*?)(?:\\]\\])? *[|]? *\\n',
			'img'
		);
		pg.re.imageBracketCount = 6;

		pg.re.category = RegExp('\\[\\[' + nsRe(pg.nsCategoryId) + ': *([^|\\]]*[^|\\] ]) *', 'i');
		pg.re.categoryBracketCount = 1;

		pg.re.ipUser = RegExp(
			'^' +
				// IPv6
				'(?::(?::|(?::[0-9A-Fa-f]{1,4}){1,7})|[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4}){0,6}::|[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4}){7})' +
				// IPv4
				'|(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}' +
				'(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]))$'
		);

		pg.re.stub = RegExp(getValueOf('popupStubRegexp'), 'im');
		pg.re.disambig = RegExp(getValueOf('popupDabRegexp'), 'im');

		// FIXME replace with general parameter parsing function, this is daft
		pg.re.oldid = RegExp('[?&]oldid=([^&]*)');
		pg.re.diff = RegExp('[?&]diff=([^&]*)');
	}

	//////////////////////////////////////////////////
	// miscellany

	function setupCache() {
		// page caching
		pg.cache.pages = [];
	}

	function setMisc() {
		pg.current.link = null;
		pg.current.links = [];
		pg.current.linksHash = {};

		setupCache();

		pg.timer.checkPopupPosition = null;
		pg.counter.loop = 0;

		// ids change with each popup: popupImage0, popupImage1 etc
		pg.idNumber = 0;

		// for myDecodeURI
		pg.misc.decodeExtras = [
			{ from: '%2C', to: ',' },
			{ from: '_', to: ' ' },
			{ from: '%24', to: '$' },
			{ from: '%26', to: '&' }, // no ,
		];
	}

	function getMwApi() {
		if (!pg.api.client) {
			pg.api.userAgent = 'Navigation popups/1.0 (' + mw.config.get('wgServerName') + ')';
			pg.api.client = new mw.Api({
				ajax: {
					headers: {
						'Api-User-Agent': pg.api.userAgent,
					},
				},
			});
		}
		return pg.api.client;
	}

	// We need a callback since this might end up asynchronous because of
	// the mw.loader.using() call.
	function setupPopups(callback) {
		if (setupPopups.completed) {
			if (typeof callback === 'function') {
				callback();
			}
			return;
		}
		// These dependencies should alse be enforced from the gadget,
		// but not everyone loads this as a gadget, so double check
		mw.loader
			.using([
				'mediawiki.util',
				'mediawiki.api',
				'mediawiki.user',
				'user.options',
				'mediawiki.jqueryMsg',
			])
			.then(fetchSpecialPageNames)
			.then(function () {
				// NB translatable strings should be set up first (strings.js)
				// basics
				setupDebugging();
				setSiteInfo();
				setTitleBase();
				setOptions(); // see options.js
				setUserInfo();

				// namespaces etc
				setNamespaces();
				setInterwiki();

				// regexps
				setRegexps();
				setRedirs();

				// other stuff
				setMisc();
				setupLivePreview();

				// main deal here
				setupTooltips();
				log('In setupPopups(), just called setupTooltips()');
				Navpopup.tracker.enable();

				setupPopups.completed = true;
				if (typeof callback === 'function') {
					callback();
				}
			});
	}
	// ENDFILE: init.js

	// STARTFILE: navlinks.js
	//////////////////////////////////////////////////
	// navlinks... let the fun begin
	//

	function defaultNavlinkSpec() {
		var str = '';
		str += '<b><<mainlink|shortcut= >></b>';
		if (getValueOf('popupLastEditLink')) {
			str +=
				'*<<lastEdit|shortcut=/>>|<<lastContrib>>|<<sinceMe>>if(oldid){|<<oldEdit>>|<<diffCur>>}';
		}

		// user links
		// contribs - log - count - email - block
		// count only if applicable; block only if popupAdminLinks
		str += 'if(user){<br><<contribs|shortcut=c>>*<<userlog|shortcut=L|log>>';
		str += 'if(ipuser){*<<arin>>}if(wikimedia){*<<count|shortcut=#>>}';
		str +=
			'if(ipuser){}else{*<<email|shortcut=E>>}if(admin){*<<block|shortcut=b>>|<<blocklog|log>>}}';

		// editing links
		// talkpage   -> edit|new - history - un|watch - article|edit
		// other page -> edit - history - un|watch - talk|edit|new
		var editstr = '<<edit|shortcut=e>>';
		var editOldidStr =
			'if(oldid){<<editOld|shortcut=e>>|<<revert|shortcut=v|rv>>|<<edit|cur>>}else{' +
			editstr +
			'}';
		var historystr = '<<history|shortcut=h>>|<<editors|shortcut=E|>>';
		var watchstr = '<<unwatch|unwatchShort>>|<<watch|shortcut=w|watchThingy>>';

		str +=
			'<br>if(talk){' +
			editOldidStr +
			'|<<new|shortcut=+>>' +
			'*' +
			historystr +
			'*' +
			watchstr +
			'*' +
			'<b><<article|shortcut=a>></b>|<<editArticle|edit>>' +
			'}else{' + // not a talk page
			editOldidStr +
			'*' +
			historystr +
			'*' +
			watchstr +
			'*' +
			'<b><<talk|shortcut=t>></b>|<<editTalk|edit>>|<<newTalk|shortcut=+|new>>}';

		// misc links
		str += '<br><<whatLinksHere|shortcut=l>>*<<relatedChanges|shortcut=r>>*<<move|shortcut=m>>';

		// admin links
		str +=
			'if(admin){<br><<unprotect|unprotectShort>>|<<protect|shortcut=p>>|<<protectlog|log>>*' +
			'<<undelete|undeleteShort>>|<<delete|shortcut=d>>|<<deletelog|log>>}';
		return str;
	}

	function navLinksHTML(article, hint, params) {
		//oldid, rcid) {
		var str = '<span class="popupNavLinks">' + defaultNavlinkSpec() + '</span>';
		// BAM
		return navlinkStringToHTML(str, article, params);
	}

	function expandConditionalNavlinkString(s, article, z, recursionCount) {
		var oldid = z.oldid,
			rcid = z.rcid,
			diff = z.diff;
		// nested conditionals (up to 10 deep) are ok, hopefully! (work from the inside out)
		if (typeof recursionCount != typeof 0) {
			recursionCount = 0;
		}
		var conditionalSplitRegex = RegExp(
			//(1	 if	\\(	(2	2)	\\)	  {(3	3)}  (4   else	  {(5	 5)}  4)1)
			'(;?\\s*if\\s*\\(\\s*([\\w]*)\\s*\\)\\s*\\{([^{}]*)\\}(\\s*else\\s*\\{([^{}]*?)\\}|))',
			'i'
		);
		var splitted = s.parenSplit(conditionalSplitRegex);
		// $1: whole conditional
		// $2: test condition
		// $3: true expansion
		// $4: else clause (possibly empty)
		// $5: false expansion (possibly null)
		var numParens = 5;
		var ret = splitted[0];
		for (var i = 1; i < splitted.length; i = i + numParens + 1) {
			var testString = splitted[i + 2 - 1];
			var trueString = splitted[i + 3 - 1];
			var falseString = splitted[i + 5 - 1];
			if (typeof falseString == 'undefined' || !falseString) {
				falseString = '';
			}
			var testResult = null;

			switch (testString) {
				case 'user':
					testResult = !!article.userName();
					break;
				case 'talk':
					testResult = !article.talkPage(); // talkPage converts _articles_ to talkPages
					break;
				case 'admin':
					testResult = !!getValueOf('popupAdminLinks');
					break;
				case 'oldid':
					testResult = !!(typeof oldid != 'undefined' && oldid);
					break;
				case 'rcid':
					testResult = !!(typeof rcid != 'undefined' && rcid);
					break;
				case 'ipuser':
					testResult = !!article.isIpUser();
					break;
				case 'mainspace_en':
					testResult = isInMainNamespace(article) && pg.wiki.hostname == 'en.wikipedia.org';
					break;
				case 'wikimedia':
					testResult = !!pg.wiki.wikimedia;
					break;
				case 'diff':
					testResult = !!(typeof diff != 'undefined' && diff);
					break;
			}

			switch (testResult) {
				case null:
					ret += splitted[i];
					break;
				case true:
					ret += trueString;
					break;
				case false:
					ret += falseString;
					break;
			}

			// append non-conditional string
			ret += splitted[i + numParens];
		}
		if (conditionalSplitRegex.test(ret) && recursionCount < 10) {
			return expandConditionalNavlinkString(ret, article, z, recursionCount + 1);
		}
		return ret;
	}

	function navlinkStringToArray(s, article, params) {
		s = expandConditionalNavlinkString(s, article, params);
		var splitted = s.parenSplit(RegExp('<<(.*?)>>'));
		var ret = [];
		for (var i = 0; i < splitted.length; ++i) {
			if (i % 2) {
				// i odd, so s is a tag
				var t = new navlinkTag();
				var ss = splitted[i].split('|');
				t.id = ss[0];
				for (var j = 1; j < ss.length; ++j) {
					var sss = ss[j].split('=');
					if (sss.length > 1) {
						t[sss[0]] = sss[1];
					} else {
						// no assignment (no "="), so treat this as a title (overwriting the last one)
						t.text = popupString(sss[0]);
					}
				}
				t.article = article;
				var oldid = params.oldid,
					rcid = params.rcid,
					diff = params.diff;
				if (typeof oldid !== 'undefined' && oldid !== null) {
					t.oldid = oldid;
				}
				if (typeof rcid !== 'undefined' && rcid !== null) {
					t.rcid = rcid;
				}
				if (typeof diff !== 'undefined' && diff !== null) {
					t.diff = diff;
				}
				if (!t.text && t.id !== 'mainlink') {
					t.text = popupString(t.id);
				}
				ret.push(t);
			} else {
				// plain HTML
				ret.push(splitted[i]);
			}
		}
		return ret;
	}

	function navlinkSubstituteHTML(s) {
		return s
			.split('*')
			.join(getValueOf('popupNavLinkSeparator'))
			.split('<menurow>')
			.join('<li class="popup_menu_row">')
			.split('</menurow>')
			.join('</li>')
			.split('<menu>')
			.join('<ul class="popup_menu">')
			.split('</menu>')
			.join('</ul>');
	}

	function navlinkDepth(magic, s) {
		return s.split('<' + magic + '>').length - s.split('</' + magic + '>').length;
	}

	// navlinkString: * becomes the separator
	//				<<foo|bar=baz|fubar>> becomes a foo-link with attribute bar='baz'
	//									  and visible text 'fubar'
	//				if(test){...} and if(test){...}else{...} work too (nested ok)

	function navlinkStringToHTML(s, article, params) {
		//limitAlert(navlinkStringToHTML, 5, 'navlinkStringToHTML\n' + article + '\n' + (typeof article));
		var p = navlinkStringToArray(s, article, params);
		var html = '';
		var menudepth = 0; // nested menus not currently allowed, but doesn't do any harm to code for it
		var menurowdepth = 0;
		for (var i = 0; i < p.length; ++i) {
			if (typeof p[i] == typeof '') {
				html += navlinkSubstituteHTML(p[i]);
				menudepth += navlinkDepth('menu', p[i]);
				menurowdepth += navlinkDepth('menurow', p[i]);
				//			if (menudepth === 0) {
				//				tagType='span';
				//			} else if (menurowdepth === 0) {
				//				tagType='li';
				//			} else {
				//				tagType = null;
				//			}
			} else if (typeof p[i].type != 'undefined' && p[i].type == 'navlinkTag') {
				if (menudepth > 0 && menurowdepth === 0) {
					html += '<li class="popup_menu_item">' + p[i].html() + '</li>';
				} else {
					html += p[i].html();
				}
			}
		}
		return html;
	}

	function navlinkTag() {
		this.type = 'navlinkTag';
	}

	navlinkTag.prototype.html = function () {
		this.getNewWin();
		this.getPrintFunction();
		var html = '';
		var opening, closing;
		var tagType = 'span';
		if (!tagType) {
			opening = '';
			closing = '';
		} else {
			opening = '<' + tagType + ' class="popup_' + this.id + '">';
			closing = '</' + tagType + '>';
		}
		if (typeof this.print != 'function') {
			errlog('Oh dear - invalid print function for a navlinkTag, id=' + this.id);
		} else {
			html = this.print(this);
			if (typeof html != typeof '') {
				html = '';
			} else if (typeof this.shortcut != 'undefined') {
				html = addPopupShortcut(html, this.shortcut);
			}
		}
		return opening + html + closing;
	};

	navlinkTag.prototype.getNewWin = function () {
		getValueOf('popupLinksNewWindow');
		if (typeof pg.option.popupLinksNewWindow[this.id] === 'undefined') {
			this.newWin = null;
		}
		this.newWin = pg.option.popupLinksNewWindow[this.id];
	};

	navlinkTag.prototype.getPrintFunction = function () {
		//think about this some more
		// this.id and this.article should already be defined
		if (typeof this.id != typeof '' || typeof this.article != typeof {}) {
			return;
		}

		this.noPopup = 1;
		switch (this.id) {
			case 'contribs':
			case 'history':
			case 'whatLinksHere':
			case 'userPage':
			case 'monobook':
			case 'userTalk':
			case 'talk':
			case 'article':
			case 'lastEdit':
				this.noPopup = null;
		}
		switch (this.id) {
			case 'email':
			case 'contribs':
			case 'block':
			case 'unblock':
			case 'userlog':
			case 'userSpace':
			case 'deletedContribs':
				this.article = this.article.userName();
		}

		switch (this.id) {
			case 'userTalk':
			case 'newUserTalk':
			case 'editUserTalk':
			case 'userPage':
			case 'monobook':
			case 'editMonobook':
			case 'blocklog':
				this.article = this.article.userName(true);
			/* fall through */
			case 'pagelog':
			case 'deletelog':
			case 'protectlog':
				delete this.oldid;
		}

		if (this.id == 'editMonobook' || this.id == 'monobook') {
			this.article.append('/monobook.js');
		}

		if (this.id != 'mainlink') {
			// FIXME anchor handling should be done differently with Title object
			this.article = this.article.removeAnchor();
			// if (typeof this.text=='undefined') this.text=popupString(this.id);
		}

		switch (this.id) {
			case 'undelete':
				this.print = specialLink;
				this.specialpage = 'Undelete';
				this.sep = '/';
				break;
			case 'whatLinksHere':
				this.print = specialLink;
				this.specialpage = 'Whatlinkshere';
				break;
			case 'relatedChanges':
				this.print = specialLink;
				this.specialpage = 'Recentchangeslinked';
				break;
			case 'move':
				this.print = specialLink;
				this.specialpage = 'Movepage';
				break;
			case 'contribs':
				this.print = specialLink;
				this.specialpage = 'Contributions';
				break;
			case 'deletedContribs':
				this.print = specialLink;
				this.specialpage = 'Deletedcontributions';
				break;
			case 'email':
				this.print = specialLink;
				this.specialpage = 'EmailUser';
				this.sep = '/';
				break;
			case 'block':
				this.print = specialLink;
				this.specialpage = 'Blockip';
				this.sep = '&ip=';
				break;
			case 'unblock':
				this.print = specialLink;
				this.specialpage = 'Ipblocklist';
				this.sep = '&action=unblock&ip=';
				break;
			case 'userlog':
				this.print = specialLink;
				this.specialpage = 'Log';
				this.sep = '&user=';
				break;
			case 'blocklog':
				this.print = specialLink;
				this.specialpage = 'Log';
				this.sep = '&type=block&page=';
				break;
			case 'pagelog':
				this.print = specialLink;
				this.specialpage = 'Log';
				this.sep = '&page=';
				break;
			case 'protectlog':
				this.print = specialLink;
				this.specialpage = 'Log';
				this.sep = '&type=protect&page=';
				break;
			case 'deletelog':
				this.print = specialLink;
				this.specialpage = 'Log';
				this.sep = '&type=delete&page=';
				break;
			case 'userSpace':
				this.print = specialLink;
				this.specialpage = 'PrefixIndex';
				this.sep = '&namespace=2&prefix=';
				break;
			case 'search':
				this.print = specialLink;
				this.specialpage = 'Search';
				this.sep = '&fulltext=Search&search=';
				break;
			case 'thank':
				this.print = specialLink;
				this.specialpage = 'Thanks';
				this.sep = '/';
				this.article.value = this.diff !== 'prev' ? this.diff : this.oldid;
				break;
			case 'unwatch':
			case 'watch':
				this.print = magicWatchLink;
				this.action =
					this.id +
					'&autowatchlist=1&autoimpl=' +
					popupString('autoedit_version') +
					'&actoken=' +
					autoClickToken();
				break;
			case 'history':
			case 'historyfeed':
			case 'unprotect':
			case 'protect':
				this.print = wikiLink;
				this.action = this.id;
				break;

			case 'delete':
				this.print = wikiLink;
				this.action = 'delete';
				if (this.article.namespaceId() == pg.nsImageId) {
					var img = this.article.stripNamespace();
					this.action += '&image=' + img;
				}
				break;

			case 'markpatrolled':
			case 'edit': // editOld should keep the oldid, but edit should not.
				delete this.oldid;
			/* fall through */
			case 'view':
			case 'purge':
			case 'render':
				this.print = wikiLink;
				this.action = this.id;
				break;
			case 'raw':
				this.print = wikiLink;
				this.action = 'raw';
				break;
			case 'new':
				this.print = wikiLink;
				this.action = 'edit&section=new';
				break;
			case 'mainlink':
				if (typeof this.text == 'undefined') {
					this.text = this.article.toString().entify();
				}
				if (getValueOf('popupSimplifyMainLink') && isInStrippableNamespace(this.article)) {
					// only show the /subpage part of the title text
					var s = this.text.split('/');
					this.text = s[s.length - 1];
					if (this.text === '' && s.length > 1) {
						this.text = s[s.length - 2];
					}
				}
				this.print = titledWikiLink;
				if (
					typeof this.title === 'undefined' &&
					pg.current.link &&
					typeof pg.current.link.href !== 'undefined'
				) {
					this.title = safeDecodeURI(
						pg.current.link.originalTitle ? pg.current.link.originalTitle : this.article
					);
					if (typeof this.oldid !== 'undefined' && this.oldid) {
						this.title = tprintf('Revision %s of %s', [this.oldid, this.title]);
					}
				}
				this.action = 'view';
				break;
			case 'userPage':
			case 'article':
			case 'monobook':
			case 'editMonobook':
			case 'editArticle':
				delete this.oldid;
				//alert(this.id+'\n'+this.article + '\n'+ typeof this.article);
				this.article = this.article.articleFromTalkOrArticle();
				//alert(this.id+'\n'+this.article + '\n'+ typeof this.article);
				this.print = wikiLink;
				if (this.id.indexOf('edit') === 0) {
					this.action = 'edit';
				} else {
					this.action = 'view';
				}
				break;
			case 'userTalk':
			case 'talk':
				this.article = this.article.talkPage();
				delete this.oldid;
				this.print = wikiLink;
				this.action = 'view';
				break;
			case 'arin':
				this.print = arinLink;
				break;
			case 'count':
				this.print = editCounterLink;
				break;
			case 'google':
				this.print = googleLink;
				break;
			case 'editors':
				this.print = editorListLink;
				break;
			case 'globalsearch':
				this.print = globalSearchLink;
				break;
			case 'lastEdit':
				this.print = titledDiffLink;
				this.title = popupString('Show the last edit');
				this.from = 'prev';
				this.to = 'cur';
				break;
			case 'oldEdit':
				this.print = titledDiffLink;
				this.title = popupString('Show the edit made to get revision') + ' ' + this.oldid;
				this.from = 'prev';
				this.to = this.oldid;
				break;
			case 'editOld':
				this.print = wikiLink;
				this.action = 'edit';
				break;
			case 'undo':
				this.print = wikiLink;
				this.action = 'edit&undo=';
				break;
			case 'revert':
				this.print = wikiLink;
				this.action = 'revert';
				break;
			case 'nullEdit':
				this.print = wikiLink;
				this.action = 'nullEdit';
				break;
			case 'diffCur':
				this.print = titledDiffLink;
				this.title = tprintf('Show changes since revision %s', [this.oldid]);
				this.from = this.oldid;
				this.to = 'cur';
				break;
			case 'editUserTalk':
			case 'editTalk':
				delete this.oldid;
				this.article = this.article.talkPage();
				this.action = 'edit';
				this.print = wikiLink;
				break;
			case 'newUserTalk':
			case 'newTalk':
				this.article = this.article.talkPage();
				this.action = 'edit&section=new';
				this.print = wikiLink;
				break;
			case 'lastContrib':
			case 'sinceMe':
				this.print = magicHistoryLink;
				break;
			case 'togglePreviews':
				this.text = popupString(pg.option.simplePopups ? 'enable previews' : 'disable previews');
			/* fall through */
			case 'disablePopups':
			case 'purgePopups':
				this.print = popupMenuLink;
				break;
			default:
				this.print = function () {
					return 'Unknown navlink type: ' + String(this.id);
				};
		}
	};
	//
	//  end navlinks
	//////////////////////////////////////////////////
	// ENDFILE: navlinks.js

	// STARTFILE: shortcutkeys.js
	function popupHandleKeypress(evt) {
		var keyCode = window.event ? window.event.keyCode : evt.keyCode ? evt.keyCode : evt.which;
		if (!keyCode || !pg.current.link || !pg.current.link.navpopup) {
			return;
		}
		if (keyCode == 27) {
			// escape
			killPopup();
			return false; // swallow keypress
		}

		var letter = String.fromCharCode(keyCode);
		var links = pg.current.link.navpopup.mainDiv.getElementsByTagName('A');
		var startLink = 0;
		var i, j;

		if (popupHandleKeypress.lastPopupLinkSelected) {
			for (i = 0; i < links.length; ++i) {
				if (links[i] == popupHandleKeypress.lastPopupLinkSelected) {
					startLink = i;
				}
			}
		}
		for (j = 0; j < links.length; ++j) {
			i = (startLink + j + 1) % links.length;
			if (links[i].getAttribute('popupkey') == letter) {
				if (evt && evt.preventDefault) {
					evt.preventDefault();
				}
				links[i].focus();
				popupHandleKeypress.lastPopupLinkSelected = links[i];
				return false; // swallow keypress
			}
		}

		// pass keypress on
		if (document.oldPopupOnkeypress) {
			return document.oldPopupOnkeypress(evt);
		}
		return true;
	}

	function addPopupShortcuts() {
		if (document.onkeypress != popupHandleKeypress) {
			document.oldPopupOnkeypress = document.onkeypress;
		}
		document.onkeypress = popupHandleKeypress;
	}

	function rmPopupShortcuts() {
		popupHandleKeypress.lastPopupLinkSelected = null;
		try {
			if (document.oldPopupOnkeypress && document.oldPopupOnkeypress == popupHandleKeypress) {
				// panic
				document.onkeypress = null; //function () {};
				return;
			}
			document.onkeypress = document.oldPopupOnkeypress;
		} catch (nasties) {
			/* IE goes here */
		}
	}

	function addLinkProperty(html, property) {
		// take "<a href=...>...</a> and add a property
		// not sophisticated at all, easily broken
		var i = html.indexOf('>');
		if (i < 0) {
			return html;
		}
		return html.substring(0, i) + ' ' + property + html.substring(i);
	}

	function addPopupShortcut(html, key) {
		if (!getValueOf('popupShortcutKeys')) {
			return html;
		}
		var ret = addLinkProperty(html, 'popupkey="' + key + '"');
		if (key == ' ') {
			key = popupString('spacebar');
		}
		return ret.replace(RegExp('^(.*?)(title=")(.*?)(".*)$', 'i'), '$1$2$3 [' + key + ']$4');
	}
	// ENDFILE: shortcutkeys.js

	// STARTFILE: diffpreview.js
	/**
	 * Load diff data.
	 *
	 * lets jump through hoops to find the rev ids we need to retrieve
	 *
	 * @param {Title} article
	 * @param {String} oldid
	 * @param {String} diff
	 * @param {Navpopup} navpop
	 */
	function loadDiff(article, oldid, diff, navpop) {
		navpop.diffData = { oldRev: {}, newRev: {} };
		mw.loader.using('mediawiki.api').then(function () {
			var api = getMwApi();
			var params = {
				action: 'compare',
				prop: 'ids|title',
			};
			params.fromtitle = article.toString();

			switch (diff) {
				case 'cur':
					switch (oldid) {
						case null:
						case '':
						case 'prev':
							// this can only work if we have the title
							// cur -> prev
							params.torelative = 'prev';
							break;
						default:
							params.fromrev = oldid;
							params.torelative = 'cur';
							break;
					}
					break;
				case 'prev':
					if (oldid && oldid !== 'cur') {
						params.fromrev = oldid;
					}
					params.torelative = 'prev';
					break;
				case 'next':
					params.fromrev = oldid || 0;
					params.torelative = 'next';
					break;
				default:
					params.fromrev = oldid || 0;
					params.torev = diff || 0;
					break;
			}

			api.get(params).then(function (data) {
				navpop.diffData.oldRev.revid = data.compare.fromrevid;
				navpop.diffData.newRev.revid = data.compare.torevid;

				addReviewLink(navpop, 'popupMiscTools');

				var go = function () {
					pendingNavpopTask(navpop);
					var url = pg.wiki.apiwikibase + '?format=json&formatversion=2&action=query&';

					url += 'revids=' + navpop.diffData.oldRev.revid + '|' + navpop.diffData.newRev.revid;
					url += '&prop=revisions&rvslots=main&rvprop=ids|timestamp|content';

					getPageWithCaching(url, doneDiff, navpop);

					return true; // remove hook once run
				};
				if (navpop.visible || !getValueOf('popupLazyDownloads')) {
					go();
				} else {
					navpop.addHook(go, 'unhide', 'before', 'DOWNLOAD_DIFFS');
				}
			});
		});
	}

	// Put a "mark patrolled" link to an element target
	// TODO: Allow patrol a revision, as well as a diff
	function addReviewLink(navpop, target) {
		if (!pg.user.canReview) {
			return;
		}
		// If 'newRev' is older than 'oldRev' than it could be confusing, so we do not show the review link.
		if (navpop.diffData.newRev.revid <= navpop.diffData.oldRev.revid) {
			return;
		}
		var params = {
			action: 'query',
			prop: 'info|flagged',
			revids: navpop.diffData.oldRev.revid,
			formatversion: 2,
		};
		getMwApi()
			.get(params)
			.then(function (data) {
				var stable_revid =
					(data.query.pages[0].flagged && data.query.pages[0].flagged.stable_revid) || 0;
				// The diff can be reviewed if the old version is the last reviewed version
				// TODO: Other possible conditions that we may want to implement instead of this one:
				//  * old version is patrolled and the new version is not patrolled
				//  * old version is patrolled and the new version is more recent than the last reviewed version
				if (stable_revid == navpop.diffData.oldRev.revid) {
					var a = document.createElement('a');
					a.innerHTML = popupString('mark patrolled');
					a.title = popupString('markpatrolledHint');
					a.onclick = function () {
						var params = {
							action: 'review',
							revid: navpop.diffData.newRev.revid,
							comment: tprintf('defaultpopupReviewedSummary', [
								navpop.diffData.oldRev.revid,
								navpop.diffData.newRev.revid,
							]),
						};
						getMwApi()
							.postWithToken('csrf', params)
							.done(function () {
								a.style.display = 'none';
								// TODO: Update current page and other already constructed popups
							})
							.fail(function () {
								alert(popupString('Could not marked this edit as patrolled'));
							});
					};
					setPopupHTML(a, target, navpop.idNumber, null, true);
				}
			});
	}

	function doneDiff(download) {
		if (!download.owner || !download.owner.diffData) {
			return;
		}
		var navpop = download.owner;
		completedNavpopTask(navpop);

		var pages,
			revisions = [];
		try {
			// Process the downloads
			pages = getJsObj(download.data).query.pages;
			for (var i = 0; i < pages.length; i++) {
				revisions = revisions.concat(pages[i].revisions);
			}
			for (i = 0; i < revisions.length; i++) {
				if (revisions[i].revid == navpop.diffData.oldRev.revid) {
					navpop.diffData.oldRev.revision = revisions[i];
				} else if (revisions[i].revid == navpop.diffData.newRev.revid) {
					navpop.diffData.newRev.revision = revisions[i];
				}
			}
		} catch (someError) {
			errlog('Could not get diff');
		}

		insertDiff(navpop);
	}

	function rmBoringLines(a, b, context) {
		if (typeof context == 'undefined') {
			context = 2;
		}
		// this is fairly slow... i think it's quicker than doing a word-based diff from the off, though
		var aa = [],
			aaa = [];
		var bb = [],
			bbb = [];
		var i, j;

		// first, gather all disconnected nodes in a and all crossing nodes in a and b
		for (i = 0; i < a.length; ++i) {
			if (!a[i].paired) {
				aa[i] = 1;
			} else if (countCrossings(b, a, i, true)) {
				aa[i] = 1;
				bb[a[i].row] = 1;
			}
		}

		// pick up remaining disconnected nodes in b
		for (i = 0; i < b.length; ++i) {
			if (bb[i] == 1) {
				continue;
			}
			if (!b[i].paired) {
				bb[i] = 1;
			}
		}

		// another pass to gather context: we want the neighbours of included nodes which are not
		// yet included we have to add in partners of these nodes, but we don't want to add context
		// for *those* nodes in the next pass
		for (i = 0; i < b.length; ++i) {
			if (bb[i] == 1) {
				for (j = Math.max(0, i - context); j < Math.min(b.length, i + context); ++j) {
					if (!bb[j]) {
						bb[j] = 1;
						aa[b[j].row] = 0.5;
					}
				}
			}
		}

		for (i = 0; i < a.length; ++i) {
			if (aa[i] == 1) {
				for (j = Math.max(0, i - context); j < Math.min(a.length, i + context); ++j) {
					if (!aa[j]) {
						aa[j] = 1;
						bb[a[j].row] = 0.5;
					}
				}
			}
		}

		for (i = 0; i < bb.length; ++i) {
			if (bb[i] > 0) {
				// it's a row we need
				if (b[i].paired) {
					bbb.push(b[i].text);
				} // joined; partner should be in aa
				else {
					bbb.push(b[i]);
				}
			}
		}
		for (i = 0; i < aa.length; ++i) {
			if (aa[i] > 0) {
				// it's a row we need
				if (a[i].paired) {
					aaa.push(a[i].text);
				} // joined; partner should be in aa
				else {
					aaa.push(a[i]);
				}
			}
		}

		return { a: aaa, b: bbb };
	}

	function stripOuterCommonLines(a, b, context) {
		var i = 0;
		while (i < a.length && i < b.length && a[i] == b[i]) {
			++i;
		}
		var j = a.length - 1;
		var k = b.length - 1;
		while (j >= 0 && k >= 0 && a[j] == b[k]) {
			--j;
			--k;
		}

		return {
			a: a.slice(Math.max(0, i - 1 - context), Math.min(a.length + 1, j + context + 1)),
			b: b.slice(Math.max(0, i - 1 - context), Math.min(b.length + 1, k + context + 1)),
		};
	}

	function insertDiff(navpop) {
		// for speed reasons, we first do a line-based diff, discard stuff that seems boring, then
		// do a word-based diff
		// FIXME: sometimes this gives misleading diffs as distant chunks are squashed together
		var oldlines = navpop.diffData.oldRev.revision.slots.main.content.split('\n');
		var newlines = navpop.diffData.newRev.revision.slots.main.content.split('\n');
		var inner = stripOuterCommonLines(oldlines, newlines, getValueOf('popupDiffContextLines'));
		oldlines = inner.a;
		newlines = inner.b;
		var truncated = false;
		getValueOf('popupDiffMaxLines');
		if (
			oldlines.length > pg.option.popupDiffMaxLines ||
			newlines.length > pg.option.popupDiffMaxLines
		) {
			// truncate
			truncated = true;
			inner = stripOuterCommonLines(
				oldlines.slice(0, pg.option.popupDiffMaxLines),
				newlines.slice(0, pg.option.popupDiffMaxLines),
				pg.option.popupDiffContextLines
			);
			oldlines = inner.a;
			newlines = inner.b;
		}

		var lineDiff = diff(oldlines, newlines);
		var lines2 = rmBoringLines(lineDiff.o, lineDiff.n);
		var oldlines2 = lines2.a;
		var newlines2 = lines2.b;

		var simpleSplit = !String.prototype.parenSplit.isNative;
		var html = '<hr />';
		if (getValueOf('popupDiffDates')) {
			html += diffDatesTable(navpop);
			html += '<hr />';
		}
		html += shortenDiffString(
			diffString(oldlines2.join('\n'), newlines2.join('\n'), simpleSplit),
			getValueOf('popupDiffContextCharacters')
		).join('<hr />');
		setPopupTipsAndHTML(
			html.split('\n').join('<br>') +
				(truncated
					? '<hr /><b>' + popupString('Diff truncated for performance reasons') + '</b>'
					: ''),
			'popupPreview',
			navpop.idNumber
		);
	}

	function diffDatesTable(navpop) {
		var html = '<table class="popup_diff_dates">';
		html += diffDatesTableRow(navpop.diffData.newRev.revision, tprintf('New revision'));
		html += diffDatesTableRow(navpop.diffData.oldRev.revision, tprintf('Old revision'));
		html += '</table>';
		return html;
	}
	function diffDatesTableRow(revision, label) {
		var txt = '';
		var lastModifiedDate = new Date(revision.timestamp);

		txt = formattedDateTime(lastModifiedDate);

		var revlink = generalLink({
			url: mw.config.get('wgScript') + '?oldid=' + revision.revid,
			text: label,
			title: label,
		});
		return simplePrintf('<tr><td>%s</td><td>%s</td></tr>', [revlink, txt]);
	}
	// ENDFILE: diffpreview.js

	// STARTFILE: links.js
	/////////////////////
	// LINK GENERATION //
	/////////////////////

	// titledDiffLink --> titledWikiLink --> generalLink
	// wikiLink	   --> titledWikiLink --> generalLink
	// editCounterLink --> generalLink

	// TODO Make these functions return Element objects, not just raw HTML strings.

	function titledDiffLink(l) {
		// article, text, title, from, to) {
		return titledWikiLink({
			article: l.article,
			action: l.to + '&oldid=' + l.from,
			newWin: l.newWin,
			noPopup: l.noPopup,
			text: l.text,
			title: l.title,
			/* hack: no oldid here */
			actionName: 'diff',
		});
	}

	function wikiLink(l) {
		//{article:article, action:action, text:text, oldid, newid}) {
		if (
			!(typeof l.article == typeof {} && typeof l.action == typeof '' && typeof l.text == typeof '')
		) {
			return null;
		}
		if (typeof l.oldid == 'undefined') {
			l.oldid = null;
		}
		var savedOldid = l.oldid;
		if (!/^(edit|view|revert|render)$|^raw/.test(l.action)) {
			l.oldid = null;
		}
		var hint = popupString(l.action + 'Hint'); // revertHint etc etc etc
		var oldidData = [l.oldid, safeDecodeURI(l.article)];
		var revisionString = tprintf('revision %s of %s', oldidData);
		log('revisionString=' + revisionString);
		switch (l.action) {
			case 'edit&section=new':
				hint = popupString('newSectionHint');
				break;
			case 'edit&undo=':
				if (l.diff && l.diff != 'prev' && savedOldid) {
					l.action += l.diff + '&undoafter=' + savedOldid;
				} else if (savedOldid) {
					l.action += savedOldid;
				}
				hint = popupString('undoHint');
				break;
			case 'raw&ctype=text/css':
				hint = popupString('rawHint');
				break;
			case 'revert':
				var p = parseParams(pg.current.link.href);
				l.action =
					'edit&autoclick=wpSave&actoken=' +
					autoClickToken() +
					'&autoimpl=' +
					popupString('autoedit_version') +
					'&autosummary=' +
					revertSummary(l.oldid, p.diff);
				if (p.diff == 'prev') {
					l.action += '&direction=prev';
					revisionString = tprintf('the revision prior to revision %s of %s', oldidData);
				}
				if (getValueOf('popupRevertSummaryPrompt')) {
					l.action += '&autosummaryprompt=true';
				}
				if (getValueOf('popupMinorReverts')) {
					l.action += '&autominor=true';
				}
				log('revisionString is now ' + revisionString);
				break;
			case 'nullEdit':
				l.action =
					'edit&autoclick=wpSave&actoken=' +
					autoClickToken() +
					'&autoimpl=' +
					popupString('autoedit_version') +
					'&autosummary=null';
				break;
			case 'historyfeed':
				l.action = 'history&feed=rss';
				break;
			case 'markpatrolled':
				l.action = 'markpatrolled&rcid=' + l.rcid;
		}

		if (hint) {
			if (l.oldid) {
				hint = simplePrintf(hint, [revisionString]);
			} else {
				hint = simplePrintf(hint, [safeDecodeURI(l.article)]);
			}
		} else {
			hint = safeDecodeURI(l.article + '&action=' + l.action) + l.oldid ? '&oldid=' + l.oldid : '';
		}

		return titledWikiLink({
			article: l.article,
			action: l.action,
			text: l.text,
			newWin: l.newWin,
			title: hint,
			oldid: l.oldid,
			noPopup: l.noPopup,
			onclick: l.onclick,
		});
	}

	function revertSummary(oldid, diff) {
		var ret = '';
		if (diff == 'prev') {
			ret = getValueOf('popupQueriedRevertToPreviousSummary');
		} else {
			ret = getValueOf('popupQueriedRevertSummary');
		}
		return ret + '&autorv=' + oldid;
	}

	function titledWikiLink(l) {
		// possible properties of argument:
		// article, action, text, title, oldid, actionName, className, noPopup
		// oldid = null is fine here

		// article and action are mandatory args

		if (typeof l.article == 'undefined' || typeof l.action == 'undefined') {
			errlog('got undefined article or action in titledWikiLink');
			return null;
		}

		var base = pg.wiki.titlebase + l.article.urlString();
		var url = base;

		if (typeof l.actionName == 'undefined' || !l.actionName) {
			l.actionName = 'action';
		}

		// no need to add &action=view, and this confuses anchors
		if (l.action != 'view') {
			url = base + '&' + l.actionName + '=' + l.action;
		}

		if (typeof l.oldid != 'undefined' && l.oldid) {
			url += '&oldid=' + l.oldid;
		}

		var cssClass = pg.misc.defaultNavlinkClassname;
		if (typeof l.className != 'undefined' && l.className) {
			cssClass = l.className;
		}

		return generalNavLink({
			url: url,
			newWin: l.newWin,
			title: typeof l.title != 'undefined' ? l.title : null,
			text: typeof l.text != 'undefined' ? l.text : null,
			className: cssClass,
			noPopup: l.noPopup,
			onclick: l.onclick,
		});
	}

	pg.fn.getLastContrib = function getLastContrib(wikipage, newWin) {
		getHistoryInfo(wikipage, function (x) {
			processLastContribInfo(x, { page: wikipage, newWin: newWin });
		});
	};

	function processLastContribInfo(info, stuff) {
		if (!info.edits || !info.edits.length) {
			alert('Popups: an odd thing happened. Please retry.');
			return;
		}
		if (!info.firstNewEditor) {
			alert(
				tprintf('Only found one editor: %s made %s edits', [
					info.edits[0].editor,
					info.edits.length,
				])
			);
			return;
		}
		var newUrl =
			pg.wiki.titlebase +
			new Title(stuff.page).urlString() +
			'&diff=cur&oldid=' +
			info.firstNewEditor.oldid;
		displayUrl(newUrl, stuff.newWin);
	}

	pg.fn.getDiffSinceMyEdit = function getDiffSinceMyEdit(wikipage, newWin) {
		getHistoryInfo(wikipage, function (x) {
			processDiffSinceMyEdit(x, { page: wikipage, newWin: newWin });
		});
	};

	function processDiffSinceMyEdit(info, stuff) {
		if (!info.edits || !info.edits.length) {
			alert('Popups: something fishy happened. Please try again.');
			return;
		}
		var friendlyName = stuff.page.split('_').join(' ');
		if (!info.myLastEdit) {
			alert(
				tprintf("Couldn't find an edit by %s\nin the last %s edits to\n%s", [
					info.userName,
					getValueOf('popupHistoryLimit'),
					friendlyName,
				])
			);
			return;
		}
		if (info.myLastEdit.index === 0) {
			alert(
				tprintf('%s seems to be the last editor to the page %s', [info.userName, friendlyName])
			);
			return;
		}
		var newUrl =
			pg.wiki.titlebase +
			new Title(stuff.page).urlString() +
			'&diff=cur&oldid=' +
			info.myLastEdit.oldid;
		displayUrl(newUrl, stuff.newWin);
	}

	function displayUrl(url, newWin) {
		if (newWin) {
			window.open(url);
		} else {
			document.location = url;
		}
	}

	pg.fn.purgePopups = function purgePopups() {
		processAllPopups(true);
		setupCache(); // deletes all cached items (not browser cached, though...)
		pg.option = {};
		abortAllDownloads();
	};

	function processAllPopups(nullify, banish) {
		for (var i = 0; pg.current.links && i < pg.current.links.length; ++i) {
			if (!pg.current.links[i].navpopup) {
				continue;
			}
			if (nullify || banish) {
				pg.current.links[i].navpopup.banish();
			}
			pg.current.links[i].simpleNoMore = false;
			if (nullify) {
				pg.current.links[i].navpopup = null;
			}
		}
	}

	pg.fn.disablePopups = function disablePopups() {
		processAllPopups(false, true);
		setupTooltips(null, true);
	};

	pg.fn.togglePreviews = function togglePreviews() {
		processAllPopups(true, true);
		pg.option.simplePopups = !pg.option.simplePopups;
		abortAllDownloads();
	};

	function magicWatchLink(l) {
		//Yuck!! Would require a thorough redesign to add this as a click event though ...
		l.onclick = simplePrintf("pg.fn.modifyWatchlist('%s','%s');return false;", [
			l.article.toString(true).split('\\').join('\\\\').split("'").join("\\'"),
			this.id,
		]);
		return wikiLink(l);
	}

	pg.fn.modifyWatchlist = function modifyWatchlist(title, action) {
		var reqData = {
			action: 'watch',
			formatversion: 2,
			titles: title,
			uselang: mw.config.get('wgUserLanguage'),
		};
		if (action === 'unwatch') {
			reqData.unwatch = true;
		}

		// Load the Addedwatchtext or Removedwatchtext message and show it
		var mwTitle = mw.Title.newFromText(title);
		var messageName;
		if (mwTitle && mwTitle.getNamespaceId() > 0 && mwTitle.getNamespaceId() % 2 === 1) {
			messageName = action === 'watch' ? 'addedwatchtext-talk' : 'removedwatchtext-talk';
		} else {
			messageName = action === 'watch' ? 'addedwatchtext' : 'removedwatchtext';
		}
		$.when(
			getMwApi().postWithToken('watch', reqData),
			getMwApi().loadMessagesIfMissing([messageName])
		).done(function () {
			mw.notify(mw.message(messageName, title).parseDom());
		});
	};

	function magicHistoryLink(l) {
		// FIXME use onclick change href trick to sort this out instead of window.open

		var jsUrl = '',
			title = '',
			onClick = '';
		switch (l.id) {
			case 'lastContrib':
				onClick = simplePrintf("pg.fn.getLastContrib('%s',%s)", [
					l.article.toString(true).split('\\').join('\\\\').split("'").join("\\'"),
					l.newWin,
				]);
				title = popupString('lastContribHint');
				break;
			case 'sinceMe':
				onClick = simplePrintf("pg.fn.getDiffSinceMyEdit('%s',%s)", [
					l.article.toString(true).split('\\').join('\\\\').split("'").join("\\'"),
					l.newWin,
				]);
				title = popupString('sinceMeHint');
				break;
		}
		jsUrl = 'javascript:' + onClick; // jshint ignore:line
		onClick += ';return false;';

		return generalNavLink({
			url: jsUrl,
			newWin: false, // can't have new windows with JS links, I think
			title: title,
			text: l.text,
			noPopup: l.noPopup,
			onclick: onClick,
		});
	}

	function popupMenuLink(l) {
		var jsUrl = simplePrintf('javascript:pg.fn.%s()', [l.id]); // jshint ignore:line
		var title = popupString(simplePrintf('%sHint', [l.id]));
		var onClick = simplePrintf('pg.fn.%s();return false;', [l.id]);
		return generalNavLink({
			url: jsUrl,
			newWin: false,
			title: title,
			text: l.text,
			noPopup: l.noPopup,
			onclick: onClick,
		});
	}

	function specialLink(l) {
		// properties: article, specialpage, text, sep
		if (typeof l.specialpage == 'undefined' || !l.specialpage) {
			return null;
		}
		var base =
			pg.wiki.titlebase +
			mw.config.get('wgFormattedNamespaces')[pg.nsSpecialId] +
			':' +
			l.specialpage;
		if (typeof l.sep == 'undefined' || l.sep === null) {
			l.sep = '&target=';
		}
		var article = l.article.urlString({
			keepSpaces: l.specialpage == 'Search',
		});
		var hint = popupString(l.specialpage + 'Hint');
		switch (l.specialpage) {
			case 'Log':
				switch (l.sep) {
					case '&user=':
						hint = popupString('userLogHint');
						break;
					case '&type=block&page=':
						hint = popupString('blockLogHint');
						break;
					case '&page=':
						hint = popupString('pageLogHint');
						break;
					case '&type=protect&page=':
						hint = popupString('protectLogHint');
						break;
					case '&type=delete&page=':
						hint = popupString('deleteLogHint');
						break;
					default:
						log('Unknown log type, sep=' + l.sep);
						hint = 'Missing hint (FIXME)';
				}
				break;
			case 'PrefixIndex':
				article += '/';
				break;
		}
		if (hint) {
			hint = simplePrintf(hint, [safeDecodeURI(l.article)]);
		} else {
			hint = safeDecodeURI(l.specialpage + ':' + l.article);
		}

		var url = base + l.sep + article;
		return generalNavLink({
			url: url,
			title: hint,
			text: l.text,
			newWin: l.newWin,
			noPopup: l.noPopup,
		});
	}

	/**
	 * Builds a link from a object representing a link
	 * @param {object} link
	 * @param {string} link.url URL
	 * @param {string} link.text The text to show for a link
	 * @param {string} link.title Title of the link, this shows up 
	 * when you hover over the link
	 * @param {boolean} link.newWin Should open in a new Window
	 * @param {number} link.noPopup Should nest new popups from link (0 or 1)
	 * @param {string} link.onclick
	 * @returns {string|null} null if no url is given
	 */
	function generalLink(link) {
		if (typeof link.url == 'undefined') {
			return null;
		}

		var elem = document.createElement( 'a' );

		elem.href = link.url;
		elem.title = link.title;
		// The onclick event adds raw JS in textual form to the HTML.
		// TODO: We should look into removing this, and/or auditing what gets sent.
		elem.setAttribute( 'onclick', link.onclick );

		if ( link.noPopup ) {
			elem.setAttribute('noPopup', '1' );
		}

		var newWin;
		if (typeof link.newWin == 'undefined' || link.newWin === null) {
			newWin = getValueOf('popupNewWindows');
		} else {
			newWin = link.newWin;
		}
		if (newWin) {
			elem.target = '_blank';
		}
		if (link.className) {
			elem.className = link.className;
		}
		elem.innerText = pg.unescapeQuotesHTML(link.text);

		return elem.outerHTML;
	}

	function appendParamsToLink(linkstr, params) {
		var sp = linkstr.parenSplit(RegExp('(href="[^"]+?)"', 'i'));
		if (sp.length < 2) {
			return null;
		}
		var ret = sp.shift() + sp.shift();
		ret += '&' + params + '"';
		ret += sp.join('');
		return ret;
	}

	function changeLinkTargetLink(x) {
		// newTarget, text, hint, summary, clickButton, minor, title (optional), alsoChangeLabel {
		if (x.newTarget) {
			log('changeLinkTargetLink: newTarget=' + x.newTarget);
		}
		if (x.oldTarget !== decodeURIComponent(x.oldTarget)) {
			log('This might be an input problem: ' + x.oldTarget);
		}

		// FIXME: first character of page title as well as namespace should be case insensitive
		// eg [[:category:X1]] and [[:Category:X1]] are equivalent
		// this'll break if charAt(0) is nasty
		var cA = mw.util.escapeRegExp(x.oldTarget);
		var chs = cA.charAt(0).toUpperCase();
		chs = '[' + chs + chs.toLowerCase() + ']';
		var currentArticleRegexBit = chs + cA.substring(1);
		currentArticleRegexBit = currentArticleRegexBit
			.split(RegExp('(?:[_ ]+|%20)', 'g'))
			.join('(?:[_ ]+|%20)')
			.split('\\(')
			.join('(?:%28|\\()')
			.split('\\)')
			.join('(?:%29|\\))'); // why does this need to match encoded strings ? links in the document ?
		// leading and trailing space should be ignored, and anchor bits optional:
		currentArticleRegexBit = '\\s*(' + currentArticleRegexBit + '(?:#[^\\[\\|]*)?)\\s*';
		// e.g. Computer (archaic) -> \s*([Cc]omputer[_ ](?:%2528|\()archaic(?:%2528|\)))\s*

		// autoedit=s~\[\[([Cc]ad)\]\]~[[Computer-aided%20design|$1]]~g;s~\[\[([Cc]AD)[|]~[[Computer-aided%20design|~g

		var title = x.title || mw.config.get('wgPageName').split('_').join(' ');
		var lk = titledWikiLink({
			article: new Title(title),
			newWin: x.newWin,
			action: 'edit',
			text: x.text,
			title: x.hint,
			className: 'popup_change_title_link',
		});
		var cmd = '';
		if (x.newTarget) {
			// escape '&' and other nasties
			var t = x.newTarget;
			var s = mw.util.escapeRegExp(x.newTarget);
			if (x.alsoChangeLabel) {
				cmd += 's~\\[\\[' + currentArticleRegexBit + '\\]\\]~[[' + t + ']]~g;';
				cmd += 's~\\[\\[' + currentArticleRegexBit + '[|]~[[' + t + '|~g;';
				cmd += 's~\\[\\[' + s + '\\|' + s + '\\]\\]~[[' + t + ']]~g';
			} else {
				cmd += 's~\\[\\[' + currentArticleRegexBit + '\\]\\]~[[' + t + '|$1]]~g;';
				cmd += 's~\\[\\[' + currentArticleRegexBit + '[|]~[[' + t + '|~g;';
				cmd += 's~\\[\\[' + s + '\\|' + s + '\\]\\]~[[' + t + ']]~g';
			}
		} else {
			cmd += 's~\\[\\[' + currentArticleRegexBit + '\\]\\]~$1~g;';
			cmd += 's~\\[\\[' + currentArticleRegexBit + '[|](.*?)\\]\\]~$2~g';
		}
		// Build query
		cmd = 'autoedit=' + encodeURIComponent(cmd);
		cmd +=
			'&autoclick=' +
			encodeURIComponent(x.clickButton) +
			'&actoken=' +
			encodeURIComponent(autoClickToken());
		cmd += x.minor === null ? '' : '&autominor=' + encodeURIComponent(x.minor);
		cmd += x.watch === null ? '' : '&autowatch=' + encodeURIComponent(x.watch);
		cmd += '&autosummary=' + encodeURIComponent(x.summary);
		cmd += '&autoimpl=' + encodeURIComponent(popupString('autoedit_version'));
		return appendParamsToLink(lk, cmd);
	}

	function redirLink(redirMatch, article) {
		// NB redirMatch is in wikiText
		var ret = '';

		if (getValueOf('popupAppendRedirNavLinks') && getValueOf('popupNavLinks')) {
			ret += '<hr />';

			if (getValueOf('popupFixRedirs') && typeof autoEdit != 'undefined' && autoEdit) {
				ret += popupString('Redirects to: (Fix ');
				log('redirLink: newTarget=' + redirMatch);
				ret += addPopupShortcut(
					changeLinkTargetLink({
						newTarget: redirMatch,
						text: popupString('target'),
						hint: popupString('Fix this redirect, changing just the link target'),
						summary: simplePrintf(getValueOf('popupFixRedirsSummary'), [
							article.toString(),
							redirMatch,
						]),
						oldTarget: article.toString(),
						clickButton: getValueOf('popupRedirAutoClick'),
						minor: true,
						watch: getValueOf('popupWatchRedirredPages'),
					}),
					'R'
				);
				ret += popupString(' or ');
				ret += addPopupShortcut(
					changeLinkTargetLink({
						newTarget: redirMatch,
						text: popupString('target & label'),
						hint: popupString('Fix this redirect, changing the link target and label'),
						summary: simplePrintf(getValueOf('popupFixRedirsSummary'), [
							article.toString(),
							redirMatch,
						]),
						oldTarget: article.toString(),
						clickButton: getValueOf('popupRedirAutoClick'),
						minor: true,
						watch: getValueOf('popupWatchRedirredPages'),
						alsoChangeLabel: true,
					}),
					'R'
				);
				ret += popupString(')');
			} else {
				ret += popupString('Redirects') + popupString(' to ');
			}

			return ret;
		} else {
			return (
				'<br> ' +
				popupString('Redirects') +
				popupString(' to ') +
				titledWikiLink({
					article: new Title().fromWikiText(redirMatch),
					action: 'view' /* FIXME: newWin */,
					text: safeDecodeURI(redirMatch),
					title: popupString('Bypass redirect'),
				})
			);
		}
	}

	function arinLink(l) {
		if (!saneLinkCheck(l)) {
			return null;
		}
		if (!l.article.isIpUser() || !pg.wiki.wikimedia) {
			return null;
		}

		var uN = l.article.userName();

		return generalNavLink({
			url: 'http://ws.arin.net/cgi-bin/whois.pl?queryinput=' + encodeURIComponent(uN),
			newWin: l.newWin,
			title: tprintf('Look up %s in ARIN whois database', [uN]),
			text: l.text,
			noPopup: 1,
		});
	}

	function toolDbName(cookieStyle) {
		var ret = mw.config.get('wgDBname');
		if (!cookieStyle) {
			ret += '_p';
		}
		return ret;
	}

	function saneLinkCheck(l) {
		if (typeof l.article != typeof {} || typeof l.text != typeof '') {
			return false;
		}
		return true;
	}
	function editCounterLink(l) {
		if (!saneLinkCheck(l)) {
			return null;
		}
		if (!pg.wiki.wikimedia) {
			return null;
		}
		var uN = l.article.userName();
		var tool = getValueOf('popupEditCounterTool');
		var url;
		var defaultToolUrl = 'https://xtools.wmflabs.org/ec?user=$1&project=$2.$3&uselang=' + mw.config.get('wgUserLanguage');

		switch (tool) {
			case 'custom':
				url = simplePrintf(getValueOf('popupEditCounterUrl'), [
					encodeURIComponent(uN),
					toolDbName(),
				]);
				break;
			case 'soxred': // no longer available
			case 'kate': // no longer available
			case 'interiot': // no longer available
			/* fall through */
			case 'supercount':
			default:
				var theWiki = pg.wiki.hostname.split('.');
				url = simplePrintf(defaultToolUrl, [encodeURIComponent(uN), theWiki[0], theWiki[1]]);
		}
		return generalNavLink({
			url: url,
			title: tprintf('editCounterLinkHint', [uN]),
			newWin: l.newWin,
			text: l.text,
			noPopup: 1,
		});
	}

	function globalSearchLink(l) {
		if (!saneLinkCheck(l)) {
			return null;
		}

		var base = 'https://global-search.toolforge.org/?uselang=' + mw.config.get('wgUserLanguage') + '&q=';
		var article = l.article.urlString({ keepSpaces: true });

		return generalNavLink({
			url: base + article,
			newWin: l.newWin,
			title: tprintf('globalSearchHint', [safeDecodeURI(l.article)]),
			text: l.text,
			noPopup: 1,
		});
	}

	function googleLink(l) {
		if (!saneLinkCheck(l)) {
			return null;
		}

		var base = 'https://www.google.com/search?q=';
		var article = l.article.urlString({ keepSpaces: true });

		return generalNavLink({
			url: base + '%22' + article + '%22',
			newWin: l.newWin,
			title: tprintf('googleSearchHint', [safeDecodeURI(l.article)]),
			text: l.text,
			noPopup: 1,
		});
	}

	function editorListLink(l) {
		if (!saneLinkCheck(l)) {
			return null;
		}
		var article = l.article.articleFromTalkPage() || l.article;
		var url =
			'https://xtools.wmflabs.org/articleinfo/' +
			encodeURI(pg.wiki.hostname) +
			'/' +
			article.urlString() +
			'?uselang=' +
			mw.config.get('wgUserLanguage');
		return generalNavLink({
			url: url,
			title: tprintf('editorListHint', [article]),
			newWin: l.newWin,
			text: l.text,
			noPopup: 1,
		});
	}

	function generalNavLink(l) {
		l.className = l.className === null ? 'popupNavLink' : l.className;
		return generalLink(l);
	}

	//////////////////////////////////////////////////
	// magic history links
	//

	function getHistoryInfo(wikipage, whatNext) {
		log('getHistoryInfo');
		getHistory(
			wikipage,
			whatNext
				? function (d) {
					whatNext(processHistory(d));
				  }
				: processHistory
		);
	}

	// FIXME eliminate pg.idNumber ... how? :-(

	function getHistory(wikipage, onComplete) {
		log('getHistory');
		var url =
			pg.wiki.apiwikibase +
			'?format=json&formatversion=2&action=query&prop=revisions&titles=' +
			new Title(wikipage).urlString() +
			'&rvlimit=' +
			getValueOf('popupHistoryLimit');
		log('getHistory: url=' + url);
		return startDownload(url, pg.idNumber + 'history', onComplete);
	}

	function processHistory(download) {
		var jsobj = getJsObj(download.data);
		try {
			var revisions = anyChild(jsobj.query.pages).revisions;
			var edits = [];
			for (var i = 0; i < revisions.length; ++i) {
				edits.push({ oldid: revisions[i].revid, editor: revisions[i].user });
			}
			log('processed ' + edits.length + ' edits');
			return finishProcessHistory(edits, mw.config.get('wgUserName'));
		} catch (someError) {
			log('Something went wrong with JSON business');
			return finishProcessHistory([]);
		}
	}

	function finishProcessHistory(edits, userName) {
		var histInfo = {};

		histInfo.edits = edits;
		histInfo.userName = userName;

		for (var i = 0; i < edits.length; ++i) {
			if (typeof histInfo.myLastEdit === 'undefined' && userName && edits[i].editor == userName) {
				histInfo.myLastEdit = {
					index: i,
					oldid: edits[i].oldid,
					previd: i === 0 ? null : edits[i - 1].oldid,
				};
			}
			if (typeof histInfo.firstNewEditor === 'undefined' && edits[i].editor != edits[0].editor) {
				histInfo.firstNewEditor = {
					index: i,
					oldid: edits[i].oldid,
					previd: i === 0 ? null : edits[i - 1].oldid,
				};
			}
		}
		//pg.misc.historyInfo=histInfo;
		return histInfo;
	}
	// ENDFILE: links.js

	// STARTFILE: options.js
	//////////////////////////////////////////////////
	// options

	// check for existing value, else use default
	function defaultize(x) {
		if (pg.option[x] === null || typeof pg.option[x] == 'undefined') {
			if (typeof window[x] != 'undefined') {
				pg.option[x] = window[x];
			} else {
				pg.option[x] = pg.optionDefault[x];
			}
		}
	}

	function newOption(x, def) {
		pg.optionDefault[x] = def;
	}

	function setDefault(x, def) {
		return newOption(x, def);
	}

	function getValueOf(varName) {
		defaultize(varName);
		return pg.option[varName];
	}

	/*eslint-disable */
	function useDefaultOptions() {
		// for testing
		for (var p in pg.optionDefault) {
			pg.option[p] = pg.optionDefault[p];
			if (typeof window[p] != 'undefined') {
				delete window[p];
			}
		}
	}
	/*eslint-enable */

	function setOptions() {
		// user-settable parameters and defaults
		var userIsSysop = false;
		if (mw.config.get('wgUserGroups')) {
			for (var g = 0; g < mw.config.get('wgUserGroups').length; ++g) {
				if (mw.config.get('wgUserGroups')[g] == 'sysop') {
					userIsSysop = true;
				}
			}
		}

		// Basic options
		newOption('popupDelay', 0.5);
		newOption('popupHideDelay', 0.5);
		newOption('simplePopups', false);
		newOption('popupStructure', 'shortmenus'); // see later - default for popupStructure is 'original' if simplePopups is true
		newOption('popupActionsMenu', true);
		newOption('popupSetupMenu', true);
		newOption('popupAdminLinks', userIsSysop);
		newOption('popupShortcutKeys', false);
		newOption('popupHistoricalLinks', true);
		newOption('popupOnlyArticleLinks', true);
		newOption('removeTitles', true);
		newOption('popupMaxWidth', 350);
		newOption('popupSimplifyMainLink', true);
		newOption('popupAppendRedirNavLinks', true);
		newOption('popupTocLinks', false);
		newOption('popupSubpopups', true);
		newOption('popupDragHandle', false /* 'popupTopLinks'*/);
		newOption('popupLazyPreviews', true);
		newOption('popupLazyDownloads', true);
		newOption('popupAllDabsStubs', false);
		newOption('popupDebugging', false);
		newOption('popupActiveNavlinks', true);
		newOption('popupModifier', false); // ctrl, shift, alt or meta
		newOption('popupModifierAction', 'enable'); // or 'disable'
		newOption('popupDraggable', true);
		newOption('popupReview', false);
		newOption('popupLocale', false);
		newOption('popupDateTimeFormatterOptions', {
			year: 'numeric',
			month: 'long',
			day: 'numeric',
			hour12: false,
			hour: '2-digit',
			minute: '2-digit',
			second: '2-digit',
		});
		newOption('popupDateFormatterOptions', {
			year: 'numeric',
			month: 'long',
			day: 'numeric',
		});
		newOption('popupTimeFormatterOptions', {
			hour12: false,
			hour: '2-digit',
			minute: '2-digit',
			second: '2-digit',
		});

		// images
		newOption('popupImages', true);
		newOption('imagePopupsForImages', true);
		newOption('popupNeverGetThumbs', false);
		//newOption('popupImagesToggleSize',       true);
		newOption('popupThumbAction', 'imagepage'); //'sizetoggle');
		newOption('popupImageSize', 60);
		newOption('popupImageSizeLarge', 200);

		// redirs, dabs, reversion
		newOption('popupFixRedirs', false);
		newOption('popupRedirAutoClick', 'wpDiff');
		newOption('popupFixDabs', false);
		newOption('popupDabsAutoClick', 'wpDiff');
		newOption('popupRevertSummaryPrompt', false);
		newOption('popupMinorReverts', false);
		newOption('popupRedlinkRemoval', false);
		newOption('popupRedlinkAutoClick', 'wpDiff');
		newOption('popupWatchDisambiggedPages', null);
		newOption('popupWatchRedirredPages', null);
		newOption('popupDabWiktionary', 'last');

		// navlinks
		newOption('popupNavLinks', true);
		newOption('popupNavLinkSeparator', ' &sdot; ');
		newOption('popupLastEditLink', true);
		newOption('popupEditCounterTool', 'supercount');
		newOption('popupEditCounterUrl', '');

		// previews etc
		newOption('popupPreviews', true);
		newOption('popupSummaryData', true);
		newOption('popupMaxPreviewSentences', 5);
		newOption('popupMaxPreviewCharacters', 600);
		newOption('popupLastModified', true);
		newOption('popupPreviewKillTemplates', true);
		newOption('popupPreviewRawTemplates', true);
		newOption('popupPreviewFirstParOnly', true);
		newOption('popupPreviewCutHeadings', true);
		newOption('popupPreviewButton', false);
		newOption('popupPreviewButtonEvent', 'click');

		// diffs
		newOption('popupPreviewDiffs', true);
		newOption('popupDiffMaxLines', 100);
		newOption('popupDiffContextLines', 2);
		newOption('popupDiffContextCharacters', 40);
		newOption('popupDiffDates', true);
		newOption('popupDiffDatePrinter', 'toLocaleString'); // no longer in use

		// edit summaries. God, these are ugly.
		newOption('popupReviewedSummary', popupString('defaultpopupReviewedSummary'));
		newOption('popupFixDabsSummary', popupString('defaultpopupFixDabsSummary'));
		newOption('popupExtendedRevertSummary', popupString('defaultpopupExtendedRevertSummary'));
		newOption('popupRevertSummary', popupString('defaultpopupRevertSummary'));
		newOption('popupRevertToPreviousSummary', popupString('defaultpopupRevertToPreviousSummary'));
		newOption('popupQueriedRevertSummary', popupString('defaultpopupQueriedRevertSummary'));
		newOption(
			'popupQueriedRevertToPreviousSummary',
			popupString('defaultpopupQueriedRevertToPreviousSummary')
		);
		newOption('popupFixRedirsSummary', popupString('defaultpopupFixRedirsSummary'));
		newOption('popupRedlinkSummary', popupString('defaultpopupRedlinkSummary'));
		newOption('popupRmDabLinkSummary', popupString('defaultpopupRmDabLinkSummary'));
		// misc
		newOption('popupHistoryLimit', 50);
		newOption('popupFilters', [
			popupFilterStubDetect,
			popupFilterDisambigDetect,
			popupFilterPageSize,
			popupFilterCountLinks,
			popupFilterCountImages,
			popupFilterCountCategories,
			popupFilterLastModified,
			popupFilterWikibaseItem,
		]);
		newOption('extraPopupFilters', []);
		newOption('popupOnEditSelection', 'cursor');
		newOption('popupPreviewHistory', true);
		newOption('popupImageLinks', true);
		newOption('popupCategoryMembers', true);
		newOption('popupUserInfo', true);
		newOption('popupHistoryPreviewLimit', 25);
		newOption('popupContribsPreviewLimit', 25);
		newOption('popupRevDelUrl', '//en.wikipedia.org/wiki/Wikipedia:Revision_deletion');
		newOption('popupShowGender', true);

		// new windows
		newOption('popupNewWindows', false);
		newOption('popupLinksNewWindow', { lastContrib: true, sinceMe: true });

		// regexps
		newOption(
			'popupDabRegexp',
			'disambiguation\\}\\}|\\{\\{\\s*(d(ab|isamb(ig(uation)?)?)|(((geo|hn|road?|school|number)dis)|[234][lc][acw]|(road|ship)index))\\s*(\\|[^}]*)?\\}\\}|is a .*disambiguation.*page'
		);
		newOption('popupAnchorRegexp', 'anchors?'); //how to identify an anchors template
		newOption('popupStubRegexp', '(sect)?stub[}][}]|This .*-related article is a .*stub');
		newOption(
			'popupImageVarsRegexp',
			'image|image_(?:file|skyline|name|flag|seal)|cover|badge|logo'
		);
	}
	// ENDFILE: options.js

	// STARTFILE: strings.js
	//////////////////////////////////////////////////
	// Translatable strings
	//////////////////////////////////////////////////
	//
	// See instructions at
	// https://en.wikipedia.org/wiki/Wikipedia:Tools/Navigation_popups/Translation

	pg.string = {
		/////////////////////////////////////
		// summary data, searching etc.
		/////////////////////////////////////
		article: 'article',
		category: 'category',
		categories: 'categories',
		image: 'image',
		images: 'images',
		stub: 'stub',
		'section stub': 'section stub',
		'Empty page': 'Empty page',
		kB: 'kB',
		bytes: 'bytes',
		day: 'day',
		days: 'days',
		hour: 'hour',
		hours: 'hours',
		minute: 'minute',
		minutes: 'minutes',
		second: 'second',
		seconds: 'seconds',
		week: 'week',
		weeks: 'weeks',
		search: 'search',
		SearchHint: 'Find English Wikipedia articles containing %s',
		web: 'web',
		global: 'global',
		globalSearchHint: 'Search across Wikipedias in different languages for %s',
		googleSearchHint: 'Google for %s',
		/////////////////////////////////////
		// article-related actions and info
		// (some actions also apply to user pages)
		/////////////////////////////////////
		actions: 'actions', ///// view articles and view talk
		popupsMenu: 'popups',
		togglePreviewsHint: 'Toggle preview generation in popups on this page',
		'enable previews': 'enable previews',
		'disable previews': 'disable previews',
		'toggle previews': 'toggle previews',
		'show preview': 'show preview',
		reset: 'reset',
		'more...': 'more...',
		disable: 'disable popups',
		disablePopupsHint: 'Disable popups on this page. Reload page to re-enable.',
		historyfeedHint: 'RSS feed of recent changes to this page',
		purgePopupsHint: 'Reset popups, clearing all cached popup data.',
		PopupsHint: 'Reset popups, clearing all cached popup data.',
		spacebar: 'space',
		view: 'view',
		'view article': 'view article',
		viewHint: 'Go to %s',
		talk: 'talk',
		'talk page': 'talk page',
		'this&nbsp;revision': 'this&nbsp;revision',
		'revision %s of %s': 'revision %s of %s',
		'Revision %s of %s': 'Revision %s of %s',
		'the revision prior to revision %s of %s': 'the revision prior to revision %s of %s',
		'Toggle image size': 'Click to toggle image size',
		del: 'del', ///// delete, protect, move
		delete: 'delete',
		deleteHint: 'Delete %s',
		undeleteShort: 'un',
		UndeleteHint: 'Show the deletion history for %s',
		protect: 'protect',
		protectHint: 'Restrict editing rights to %s',
		unprotectShort: 'un',
		unprotectHint: 'Allow %s to be edited by anyone again',
		'send thanks': 'send thanks',
		ThanksHint: 'Send a thank you notification to this user',
		move: 'move',
		'move page': 'move page',
		MovepageHint: 'Change the title of %s',
		edit: 'edit', ///// edit articles and talk
		'edit article': 'edit article',
		editHint: 'Change the content of %s',
		'edit talk': 'edit talk',
		new: 'new',
		'new topic': 'new topic',
		newSectionHint: 'Start a new section on %s',
		'null edit': 'null edit',
		nullEditHint: 'Submit an edit to %s, making no changes ',
		hist: 'hist', ///// history, diffs, editors, related
		history: 'history',
		historyHint: 'List the changes made to %s',
		last: 'prev', // For labelling the previous revision in history pages; the key is "last" for backwards compatibility
		lastEdit: 'lastEdit',
		'mark patrolled': 'mark patrolled',
		markpatrolledHint: 'Mark this edit as patrolled',
		'Could not marked this edit as patrolled': 'Could not marked this edit as patrolled',
		'show last edit': 'most recent edit',
		'Show the last edit': 'Show the effects of the most recent change',
		lastContrib: 'lastContrib',
		'last set of edits': 'latest edits',
		lastContribHint: 'Show the net effect of changes made by the last editor',
		cur: 'cur',
		diffCur: 'diffCur',
		'Show changes since revision %s': 'Show changes since revision %s',
		'%s old': '%s old', // as in 4 weeks old
		oldEdit: 'oldEdit',
		purge: 'purge',
		purgeHint: 'Demand a fresh copy of %s',
		raw: 'source',
		rawHint: 'Download the source of %s',
		render: 'simple',
		renderHint: 'Show a plain HTML version of %s',
		'Show the edit made to get revision': 'Show the edit made to get revision',
		sinceMe: 'sinceMe',
		'changes since mine': 'diff my edit',
		sinceMeHint: 'Show changes since my last edit',
		"Couldn't find an edit by %s\nin the last %s edits to\n%s":
			"Couldn't find an edit by %s\nin the last %s edits to\n%s",
		eds: 'eds',
		editors: 'editors',
		editorListHint: 'List the users who have edited %s',
		related: 'related',
		relatedChanges: 'relatedChanges',
		'related changes': 'related changes',
		RecentchangeslinkedHint: 'Show changes in articles related to %s',
		editOld: 'editOld', ///// edit old version, or revert
		rv: 'rv',
		revert: 'revert',
		revertHint: 'Revert to %s',
		defaultpopupReviewedSummary:
			'Accepted by reviewing the [[Special:diff/%s/%s|difference]] between this version and previously accepted version using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
		defaultpopupRedlinkSummary:
			'Removing link to empty page [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
		defaultpopupFixDabsSummary:
			'Disambiguate [[%s]] to [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
		defaultpopupFixRedirsSummary:
			'Redirect bypass from [[%s]] to [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
		defaultpopupExtendedRevertSummary:
			'Revert to revision dated %s by %s, oldid %s using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
		defaultpopupRevertToPreviousSummary:
			'Revert to the revision prior to revision %s using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
		defaultpopupRevertSummary:
			'Revert to revision %s using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
		defaultpopupQueriedRevertToPreviousSummary:
			'Revert to the revision prior to revision $1 dated $2 by $3 using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
		defaultpopupQueriedRevertSummary:
			'Revert to revision $1 dated $2 by $3 using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
		defaultpopupRmDabLinkSummary:
			'Remove link to dab page [[%s]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]',
		Redirects: 'Redirects', // as in Redirects to ...
		' to ': ' to ', // as in Redirects to ...
		'Bypass redirect': 'Bypass redirect',
		'Fix this redirect': 'Fix this redirect',
		disambig: 'disambig', ///// add or remove dab etc.
		disambigHint: 'Disambiguate this link to [[%s]]',
		'Click to disambiguate this link to:': 'Click to disambiguate this link to:',
		'remove this link': 'remove this link',
		'remove all links to this page from this article':
			'remove all links to this page from this article',
		'remove all links to this disambig page from this article':
			'remove all links to this disambig page from this article',
		mainlink: 'mainlink', ///// links, watch, unwatch
		wikiLink: 'wikiLink',
		wikiLinks: 'wikiLinks',
		'links here': 'links here',
		whatLinksHere: 'whatLinksHere',
		'what links here': 'what links here',
		WhatlinkshereHint: 'List the pages that are hyperlinked to %s',
		unwatchShort: 'un',
		watchThingy: 'watch', // called watchThingy because {}.watch is a function
		watchHint: 'Add %s to my watchlist',
		unwatchHint: 'Remove %s from my watchlist',
		'Only found one editor: %s made %s edits': 'Only found one editor: %s made %s edits',
		'%s seems to be the last editor to the page %s':
			'%s seems to be the last editor to the page %s',
		rss: 'rss',
		/////////////////////////////////////
		// diff previews
		/////////////////////////////////////
		'Diff truncated for performance reasons': 'Diff truncated for performance reasons',
		'Old revision': 'Old revision',
		'New revision': 'New revision',
		'Something went wrong :-(': 'Something went wrong :-(',
		'Empty revision, maybe non-existent': 'Empty revision, maybe non-existent',
		'Unknown date': 'Unknown date',
		/////////////////////////////////////
		// other special previews
		/////////////////////////////////////
		'Empty category': 'Empty category',
		'Category members (%s shown)': 'Category members (%s shown)',
		'No image links found': 'No image links found',
		'File links': 'File links',
		'No image found': 'No image found',
		'Image from Commons': 'Image from Commons',
		'Description page': 'Description page',
		'Alt text:': 'Alt text:',
		revdel: 'Hidden revision',
		/////////////////////////////////////
		// user-related actions and info
		/////////////////////////////////////
		user: 'user', ///// user page, talk, email, space
		'user&nbsp;page': 'user&nbsp;page',
		'user talk': 'user talk',
		'edit user talk': 'edit user talk',
		'leave comment': 'leave comment',
		email: 'email',
		'email user': 'email user',
		EmailuserHint: 'Send an email to %s',
		space: 'space', // short form for userSpace link
		PrefixIndexHint: 'Show pages in the userspace of %s',
		count: 'count', ///// contributions, log
		'edit counter': 'edit counter',
		editCounterLinkHint: 'Count the contributions made by %s',
		contribs: 'contribs',
		contributions: 'contributions',
		deletedContribs: 'deleted contributions',
		DeletedcontributionsHint: 'List deleted edits made by %s',
		ContributionsHint: 'List the contributions made by %s',
		log: 'log',
		'user log': 'user log',
		userLogHint: "Show %s's user log",
		arin: 'ARIN lookup', ///// ARIN lookup, block user or IP
		'Look up %s in ARIN whois database': 'Look up %s in the ARIN whois database',
		unblockShort: 'un',
		block: 'block',
		'block user': 'block user',
		IpblocklistHint: 'Unblock %s',
		BlockipHint: 'Prevent %s from editing',
		'block log': 'block log',
		blockLogHint: 'Show the block log for %s',
		protectLogHint: 'Show the protection log for %s',
		pageLogHint: 'Show the page log for %s',
		deleteLogHint: 'Show the deletion log for %s',
		'Invalid %s %s': 'The option %s is invalid: %s',
		'No backlinks found': 'No backlinks found',
		' and more': ' and more',
		undo: 'undo',
		undoHint: 'undo this edit',
		'Download preview data': 'Download preview data',
		'Invalid or IP user': 'Invalid or IP user',
		'Not a registered username': 'Not a registered username',
		BLOCKED: 'BLOCKED',
		'Has blocks': 'Has blocks',
		' edits since: ': ' edits since: ',
		'last edit on ': 'last edit on ',
		'he/him': 'he/him',
		'she/her': 'she/her',
		/////////////////////////////////////
		// Autoediting
		/////////////////////////////////////
		'Enter a non-empty edit summary or press cancel to abort':
			'Enter a non-empty edit summary or press cancel to abort',
		'Failed to get revision information, please edit manually.\n\n':
			'Failed to get revision information, please edit manually.\n\n',
		'The %s button has been automatically clicked. Please wait for the next page to load.':
			'The %s button has been automatically clicked. Please wait for the next page to load.',
		'Could not find button %s. Please check the settings in your javascript file.':
			'Could not find button %s. Please check the settings in your javascript file.',
		/////////////////////////////////////
		// Popups setup
		/////////////////////////////////////
		'Open full-size image': 'Open full-size image',
		zxy: 'zxy',
		autoedit_version: 'np20140416',
	};

	function popupString(str) {
		if (typeof popupStrings != 'undefined' && popupStrings && popupStrings[str]) {
			return popupStrings[str];
		}
		if (pg.string[str]) {
			return pg.string[str];
		}
		return str;
	}

	function tprintf(str, subs) {
		if (typeof subs != typeof []) {
			subs = [subs];
		}
		return simplePrintf(popupString(str), subs);
	}

	// ENDFILE: strings.js

	// STARTFILE: run.js
	////////////////////////////////////////////////////////////////////
	// Run things
	////////////////////////////////////////////////////////////////////

	// For some reason popups requires a fully loaded page jQuery.ready(...) causes problems for some.
	// The old addOnloadHook did something similar to the below
	if (document.readyState == 'complete') {
		autoEdit();
	}
	//will setup popups
	else {
		$(window).on('load', autoEdit);
	}

	// Support for MediaWiki's live preview, VisualEditor's saves and Echo's flyout.
	(function () {
		var once = true;
		function dynamicContentHandler($content) {
			// Try to detect the hook fired on initial page load and disregard
			// it, we already hook to onload (possibly to different parts of
			// page - it's configurable) and running twice might be bad. Ugly…
			if ($content.attr('id') == 'mw-content-text') {
				if (once) {
					once = false;
					return;
				}
			}

			function registerHooksForVisibleNavpops() {
				for (var i = 0; pg.current.links && i < pg.current.links.length; ++i) {
					var navpop = pg.current.links[i].navpopup;
					if (!navpop || !navpop.isVisible()) {
						continue;
					}

					Navpopup.tracker.addHook(posCheckerHook(navpop));
				}
			}

			function doIt() {
				registerHooksForVisibleNavpops();
				$content.each(function () {
					this.ranSetupTooltipsAlready = false;
					setupTooltips(this);
				});
			}

			setupPopups(doIt);
		}

		// This hook is also fired after page load.
		mw.hook('wikipage.content').add(dynamicContentHandler);

		mw.hook('ext.echo.overlay.beforeShowingOverlay').add(function ($overlay) {
			dynamicContentHandler($overlay.find('.mw-echo-state'));
		});
	})();
});