// This is a modified version of [[User:Sam Sailor/Scripts/Sagittarius+.js]] ([[Special:Diff/865729138]])
// Such script itself was a modified version of [[User:Kephir/gadgets/sagittarius.js]] ([[Special:PermaLink/785248045]])
// Docs: [[User:Sam Sailor/Scripts/Sagittarius+]]

/*jshint undef:true, latedef:true, shadow:true, loopfunc:true, scripturl:true, undef:true */
/*globals jQuery, mw, importStylesheet */
mw.loader.using(['jquery.suggestions', 'mediawiki.api', 'mediawiki.Title', 'mediawiki.action.view.redirectPage'], function () { // <nowiki>
'use strict';

if (mw.config.get('wgNamespaceNumber') < 0)
	return;

importStylesheet('User:Sam Sailor/Scripts/Sagittarius+.css');

function normaliseAnchor(anchor) {
	function encodeCodePoint(c) {
		if (c === 0x20)
			return '_';
		if (c < 0x80) {
			return '.' + c.toString(16).toUpperCase();
		} else if (c < 0x800) {
			return '.' + (0xc0 |  (c >>>  6)        ).toString(16).toUpperCase() +
				'.' + (0x80 | ( c         & 0x3f)).toString(16).toUpperCase();
		} else if (c < 0x10000) {
			return '.' + (0xe0 |  (c >>> 12)        ).toString(16).toUpperCase() +
				'.' + (0x80 | ((c >>>  6) & 0x3f)).toString(16).toUpperCase() +
				'.' + (0x80 | ( c         & 0x3f)).toString(16).toUpperCase();
		} else if (c < 0x200000) {
			return '.' + (0xf0 |  (c >>> 18)        ).toString(16).toUpperCase() +
				'.' + (0x80 | ((c >>> 12) & 0x3f)).toString(16).toUpperCase() +
				'.' + (0x80 | ((c >>>  6) & 0x3f)).toString(16).toUpperCase() +
				'.' + (0x80 | ( c         & 0x3f)).toString(16).toUpperCase();
		} else if (c < 0x4000000) {
			return '.' + (0xf8 |  (c >>> 24)        ).toString(16).toUpperCase() +
				'.' + (0x80 | ((c >>> 18) & 0x3f)).toString(16).toUpperCase() +
				'.' + (0x80 | ((c >>> 12) & 0x3f)).toString(16).toUpperCase() +
				'.' + (0x80 | ((c >>>  6) & 0x3f)).toString(16).toUpperCase() +
				'.' + (0x80 | ( c         & 0x3f)).toString(16).toUpperCase();
		} else if (c < 0x80000000) {
			return '.' + (0xfc |  (c >>> 30)        ).toString(16).toUpperCase() +
				'.' + (0x80 | ((c >>> 24) & 0x3f)).toString(16).toUpperCase() +
				'.' + (0x80 | ((c >>> 18) & 0x3f)).toString(16).toUpperCase() +
				'.' + (0x80 | ((c >>> 12) & 0x3f)).toString(16).toUpperCase() +
				'.' + (0x80 | ((c >>>  6) & 0x3f)).toString(16).toUpperCase() +
				'.' + (0x80 | ( c         & 0x3f)).toString(16).toUpperCase();
		}
	}

	// "." is not escaped!
	return anchor.replace(/[^0-9A-Za-z_:\.]/g, function (m) { /* [\ud800-\udbff][\udc00-\dfff]| */
		if (m.length === 2) { // surrogate pair
			return encodeCodePoint((m.charCodeAt(0) & 0x3ff) << 10 | m.charCodeAt(1) & 0x3ff);
		} else {
			return encodeCodePoint(m.charCodeAt(0));
		}
	});
}

function normaliseTitle(title) {
	try {
		var t = new mw.Title(title);
		return t.getPrefixedText();
	} catch (e) {
		return null;
	}
}

function el(tag, child, attr, events) {
	var node = document.createElement(tag);
 
	if (child) {
		if ((typeof child === 'string') || (typeof child.length !== 'number'))
			child = [child];
		for (var i = 0; i < child.length; ++i) {
			var ch = child[i];
			if ((ch === void(null)) || (ch === null))
				continue;
			else if (typeof ch !== 'object')
				ch = document.createTextNode(String(ch));
			node.appendChild(ch);
		}
	}

	if (attr) for (var key in attr) {
		if ((attr[key] === void(0)) || (attr[key] === null))
			continue;
		node.setAttribute(key, String(attr[key]));
	}

	if (events) for (var key in events) {
		var handler = events[key];
		if ((key === 'input') && (window.oninput === void(0))) {
			key = 'change';
		}
		node.addEventListener(key, handler, false);
	}

	return node;
}

function link(child, href, attr, ev) {
	attr = attr || {};
	ev = ev || {};
	if (typeof attr === 'string') {
		attr = { "title": attr };
	}
	if (typeof href === 'string')
		attr.href = href;
	else {
		attr.href = 'javascript:void(null);';
		ev.click = href;
	}
	return el('a', child, attr, ev);
}

var templateGroups = {
	"fromacg": "From – abbreviation, capitalisation, and grammar",
	"frompos": "From parts of speach",
	"fromspe": "From – spelling",
	"fromangen": "From alternative names, general",
	"fromangeo": "From alternative names, geography",
	"fromanp": "From alternative names, people",
	"fromans": "From alternative names, scientific",
	"fromant": "From alternative names, technical",
	"fromc": "From comics",
	"fromd": "From disambiguations",
	"fromf": "From fiction",
	"fromi": "From ISO codes",
	"fromri": "From related info",
	"fromrp": "From related people",
	"fromt": "From – transportation",
	"frommdm": "From mergers, duplicates, and moves",
	"fromn": "From – navigation",
	"togps": "To – grammar, punctuation, and spelling",
	"toan": "To alternative names",
	"tond": "To – navigation and disambiguation",
	"tons": "To namespaces",
	"toc": "To comics",
	"tom": "To miscellaneous",
	"misc": "Miscellaneous"
};

var templateAliases = {
	"R adr": "R avoided double redirect",
	"R double redirect avoided": "R avoided double redirect",
	"Radr": "R avoided double redirect",
	"Redirect avoided double redirect": "R avoided double redirect",

	"R acronym": "R from acronym",
	"Redirect from acronym": "R from acronym",
	"R acr": "R from acronym",
	"Redirect acr": "R from acronym",
	"Redirect acronym": "R from acronym",
	"R from ac": "R from acronym",
	"Redirect from ac": "R from acronym",
	"R from acr": "R from acronym",
	"Redirect from acr": "R from acronym",

	"Redirect to acronym": "R to acronym",
	
	"Redirect from adjective": "R from adjective",
	"R from adjective phrase": "R from adjective",
	"Redirect from adjective phrase": "R from adjective",
	"R from adj": "R from adjective",
	"Redirect from adj": "R from adjective",
	"R adj": "R from adjective",
	"Redirect adj": "R from adjective",
	"R aj": "R from adjective",
	"Redirect aj": "R from adjective",
	"R from adjectival form": "R from adjective",
	"R adjective": "R from adjective",

	"R adv": "R from adverb",
	"Redirect from adverb": "R from adverb",
	
	"R airport": "R from airport code",
	"Redirect from airport code": "R from airport code",

	"R from an album": "R from album",
	"R from EP": "R from album",
	"R to song": "R from album",
	"Redirect from album": "R from album",
	"Redirect from EP": "R from album",

	"R alt lang": "R from alternative language",
	"R alter lang": "R from alternative language",
	"R from alt lang": "R from alternative language",
	"R from alt langs": "R from alternative language",
	"R from alt language": "R from alternative language",
	"R from alt languages": "R from alternative language",
	"R from alternate language": "R from alternative language",
	"R from alternative langs": "R from alternative language",
	"R from alternative languages": "R from alternative language",
	"R from another language": "R from alternative language",
	"R from foreign": "R from alternative language",
	"R from foreign language": "R from alternative language",
	"R from Foreign name": "R from alternative language",
	"R from foreign name": "R from alternative language",
	"R from lang": "R from alternative language",
	"R from language": "R from alternative language",
	"R from non-English name": "R from alternative language",
	"R from original language": "R from alternative language",
	"R from other language": "R from alternative language",
	"R from other languages": "R from alternative language",
	"R from translation": "R from alternative language",
	"R in other languages": "R from alternative language",
	"R lang": "R from alternative language",
	"R to alt language": "R from alternative language",
	"R to alternative language": "R from alternative language",
	"R to English": "R from alternative language",
	"R to non-English name": "R from alternative language",
	"R to other language": "R from alternative language",
	"R-alter-lang": "R from alternative language",
	"Ralterlang": "R from alternative language",
	"Redirect from alternative language": "R from alternative language",
	"Redirect from alternative languages": "R from alternative language",
	"Redirect from another language": "R from alternative language",
	"Redirect from foreign language": "R from alternative language",
	"Redirect from foreign name": "R from alternative language",
	"Redirect from other language": "R from alternative language",

	"R alt": "R from alternative name",
	"R alt name": "R from alternative name",
	"R alternate": "R from alternative name",
	"R alternate name": "R from alternative name",
	"R alternative": "R from alternative name",
	"R alternative name": "R from alternative name",
	"R an": "R from alternative name",
	"R at": "R from alternative name",
	"R for alternative name": "R from alternative name",
	"R from alias": "R from alternative name",
	"R from alt name": "R from alternative name",
	"R from alt title": "R from alternative name",
	"R from alternate name": "R from alternative name",
	"R from alternate name and others": "R from alternative name",
	"R from alternate names": "R from alternative name",
	"R from alternate title": "R from alternative name",
	"R from alternative": "R from alternative name",
	"R from alternative form": "R from alternative name",
	"R from Alternative Name": "R from alternative name",
	"R from Alternative name": "R from alternative name",
	"R from alternative names": "R from alternative name",
	"R from alternative term": "R from alternative name",
	"R from alternative title": "R from alternative name",
	"R from an": "R from alternative name",
	"R from an alternate name": "R from alternative name",
	"R from another name": "R from alternative name",
	"R from mantra": "R from alternative name",
	"R from native name": "R from alternative name",
	"R from nick": "R from alternative name",
	"R from nickname": "R from alternative name",
	"R from official name": "R from alternative name",
	"R from other name": "R from alternative name",
	"R from popular name": "R from alternative name",
	"R from slang name": "R from alternative name",
	"R from slang term": "R from alternative name",
	"R from slang title": "R from alternative name",
	"R from title": "R from alternative name",
	"R nick": "R from alternative name",
	"R other": "R from alternative name",
	"R to alternate": "R from alternative name",
	"R to alternate name": "R from alternative name",
	"R to alternate title": "R from alternative name",
	"R to alternative name": "R from alternative name",
	"R to alternative title": "R from alternative name",
	"R to nickname": "R from alternative name",
	"R to other name": "R from alternative name",
	"R to pseudonym": "R from alternative name",
	"R to stage name": "R from alternative name",
	"Redirect alternative": "R from alternative name",
	"Redirect form alternative name": "R from alternative name",
	"Redirect form alternative transliteration": "R from alternative name",
	"Redirect form married name": "R from alternative name",
	"Redirect form pen-name": "R from alternative name",
	"Redirect form stage name": "R from alternative name",
	"Redirect from alias": "R from alternative name",
	"Redirect from alternate name": "R from alternative name",
	"Redirect from alternate title": "R from alternative name",
	"Redirect from alternative name": "R from alternative name",
	"Redirect from alternative title": "R from alternative name",
	"Redirect from an": "R from alternative name",
	"Redirect from homotypic synonym": "R from alternative name",
	"Redirect from hoterotypic synonym": "R from alternative name",
	"Redirect from local name": "R from alternative name",
	"Redirect from maiden name": "R from alternative name",
	"Redirect from married name": "R from alternative name",
	"Redirect from native name": "R from alternative name",
	"Redirect from native place name": "R from alternative name",
	"Redirect from nick-name": "R from alternative name",
	"Redirect from nickname": "R from alternative name",
	"Redirect from nom-de-guerre": "R from alternative name",
	"Redirect from other name": "R from alternative name",
	"Redirect from other part of speech": "R from alternative name",
	"Redirect from popular name": "R from alternative name",
	"Redirect from single name": "R from alternative name",
	"Redirect from slang": "R from alternative name",
	"Redirect from slang name": "R from alternative name",
	"Redirect from slang term": "R from alternative name",
	"Redirect from slang title": "R from alternative name",
	"Redirect from stylisation": "R from alternative name",
	"Redirect from unmarried name": "R from alternative name",
	"Redirect to alternative name": "R from alternative name",
	"Redirect to assumed name": "R from alternative name",
	"Redirect to married name": "R from alternative name",
	"Redirect to name without title": "R from alternative name",
	"emplate:Redirect to nickname": "R from alternative name",
	"Redirect to pen-name": "R from alternative name",
	"Redirect to pseudonym": "R from alternative name",
	"Redirect to psuedonym": "R from alternative name",
	"Redirect to stage name": "R from alternative name",
	"Redirect to stage-name": "R from alternative name",
	"Redirect to transcribed name": "R from alternative name",
	"Redirect to transcription": "R from alternative name",
	
	"R from alt spelling": "R from alternative spelling",
	"R from spelling": "R from alternative spelling",
	"R from alternate spelling": "R from alternative spelling",
	"R from another spelling": "R from alternative spelling",
	"R from alternative spellings": "R from alternative spelling",
	"R from other spelling": "R from alternative spelling",
	"R spell": "R from alternative spelling",
	"R from different spelling": "R from alternative spelling",
	"Redirect from alternative spelling": "R from alternative spelling",
	"R from unofficial spelling": "R from alternative spelling",
	"R alternative spelling": "R from alternative spelling",
	"R spelling": "R from alternative spelling",
	"R to alternative spelling": "R from alternative spelling",
	"R to alt spelling": "R from alternative spelling",
	"R to alternate spelling": "R from alternative spelling",
	"R to another spelling": "R from alternative spelling",
	"R to alternative spellings": "R from alternative spelling",
	"R to different spelling": "R from alternative spelling",
	"Redirect to alternative spelling": "R from alternative spelling",
	"R to unofficial spelling": "R from alternative spelling",
	"R from UK spelling": "R from alternative spelling",
	"Redirect from alt spelling": "R from alternative spelling",
	"R as": "R from alternative spelling",
	"Redirect as": "R from alternative spelling",
	"R from anglicization": "R from alternative spelling",
	"R to British": "R from alternative spelling",
	"R to American": "R from alternative spelling",
	"Redirect from UK spelling": "R from alternative spelling",
	"R from obsolete spelling": "R from alternative spelling",

	"R ambig": "R from ambiguous term",
	"R ambiguous": "R from ambiguous term",
	"R from ambig": "R from ambiguous term",
	"R from ambiguous": "R from ambiguous term",
	"R from ambiguous name": "R from ambiguous term",
	"R from ambiguous page": "R from ambiguous term",
	"R from ambiguous page name": "R from ambiguous term",
	"R from ambiguous title": "R from ambiguous term",
	"R from ambiguous word": "R from ambiguous term",
	"Redirect from ambig": "R from ambiguous term",
	"Redirect from ambiguous page": "R from ambiguous term",
	"Redirect from ambiguous term": "R from ambiguous term",
	"Redirect from ambiguous title": "R from ambiguous term",

	"R from American": "R from American English",
	"Redirect from American English": "R from American English",
	"R from AE": "R from American English",
	"R from American spelling": "R from American English",

	"RPT": "R to anchor",
	"R anchor": "R to anchor",
	"R from plausible term": "R to anchor",
	"R to Anchor": "R to anchor",
	"R to anchors": "R to anchor",
	"R to embedded anchor": "R to anchor",
	"R to glossary entry": "R to anchor",
	"Redirect to anchor": "R to anchor",
	"Rta": "R to anchor",

	"R animal": "R from animal",
	"Redirect from animal": "R from animal",
	
	"R to anthroponymy": "R to anthroponymy page",
	
	"R ant": "R from antonym",
	"R from opposite": "R from antonym",
	"Redirect from antonym": "R from antonym",
	
	"Redirect from ASCII": "R from ASCII-only",
	"R fa": "R from ASCII-only",
	"R from ASCII": "R from ASCII-only",
	"Redirect from ASCII-only": "R from ASCII-only",
	
	"R ta": "R to ASCII-only",
	"R to ASCII": "R to ASCII-only",
	"Redirect to ASCII-only": "R to ASCII-only",
	
	"R atc": "R from ATC code",
	"Redirect from ATC code": "R from ATC code",

	"R atcvet": "R from ATCvet code",
	"Redirect from ATCvet code": "R from ATCvet code",
	
	"R form maiden name": "R from birth name",
	"R from maiden name": "R from birth name",
	"R nee": "R from birth name",
	"R to married name": "R from birth name",
	
	"From books": "R from book",
	"R book": "R from book",
	"R from a book": "R from book",
	"Redirect from a book": "R from book",
	"Redirect from book": "R from book",
	
	"R brand": "R from brand name",
	"R from brand": "R from brand name",
	"R from brandname": "R from brand name",
	"Redirect from brand name": "R from brand name",
	
	"R from British": "R from British English",
	"Redirect from British English": "R from British English",
	"R from BE": "R from British English",
	"R from British spelling": "R from British English",
	
	"R br": "R from bus route",
	"R bus": "R from bus route",
	"R bus route": "R from bus route",
	"R from br": "R from bus route",
	"R from bus": "R from bus route",
	"Redirect br": "R from bus route",
	"Redirect bus": "R from bus route",
	"Redirect bus route": "R from bus route",
	"Redirect from br": "R from bus route",
	"Redirect from bus": "R from bus route",
	"Redirect from bus route": "R from bus route",
	
	"R from London bus": "R from London bus route",
	"R LBR": "R from London bus route",
	"R London br": "R from London bus route",
	"R London bus": "R from London bus route",
	"R London bus route": "R from London bus route",
	"Redirect LBR": "R from London bus route",
	"Redirect London br": "R from London bus route",
	"Redirect London bus": "R from London bus route",
	"Redirect London bus route": "R from London bus route",

	"R from NYC bus": "R from NYC bus route",
	"R NYC br": "R from NYC bus route",
	"R NYC bus": "R from NYC bus route",
	"R NYC bus route": "R from NYC bus route",
	"R NYCBR": "R from NYC bus route",
	"Redirect from NYC bus route": "R from NYC bus route",
	"Redirect NYC br": "R from NYC bus route",
	"Redirect NYC bus": "R from NYC bus route",
	"Redirect NYC bus route": "R from NYC bus route",
	"Redirect NYCBR": "R from NYC bus route",

	"Redirect from CamelCase": "R from CamelCase",
	"R from camelcase": "R from CamelCase",
	"Rcc": "R from CamelCase",
	"R fCC": "R from CamelCase",
	"R from camel case": "R from CamelCase",
	"R from camelCase": "R from CamelCase",
	"R from StudlyCaps": "R from CamelCase",
	"R from studlycaps": "R from CamelCase",
	"R from studly caps": "R from CamelCase",
	"R from Studly Caps": "R from CamelCase",
	"R rcc": "R from CamelCase",
	
	"R Csn": "R from Canadian settlement name",
	"R csn": "R from Canadian settlement name",
	"Redirect from Canadian settlement name": "R from Canadian settlement name",
	
	"R catchphrase": "R from catchphrase",
	"Redirect from catchphrase": "R from catchphrase",
	
	"R cat": "R to category namespace",
	"R to cat": "R to category namespace",
	"R to category": "R to category namespace",
	"R to category page": "R to category namespace",
	"R to category space": "R to category namespace",
	"Redirect to category namespace": "R to category namespace",
	
	"R cityprov": "R from city and province",
	"Redirect from city and province": "R from city and province",
	
	"R citystate": "R from city and state",
	"Redirect from city and state": "R from city and state",

	"Redirect from noun": "R from common noun",
	"R from noun phrase": "R from common noun",
	"Redirect from noun phrase": "R from common noun",
	"R noun": "R from common noun",
	"Redirect noun": "R from common noun",
	"R from noun": "R from common noun",
	"Redirect from common noun": "R from common noun",
	
	"R con": "R for convenience",
	"R conv": "R for convenience",
	"R convenience": "R for convenience",
	"R convenient": "R for convenience",
	"Rcon": "R for convenience",
	"Redirect con": "R for convenience",
	"Redirect conv": "R for convenience",
	"Redirect convenience": "R for convenience",
	"Redirect convenient": "R for convenience",
	"Redirect for convenience": "R for convenience",
	
	"R decade": "R to decade",
	"Redirect to decade": "R to decade",
	
	"R from name with diacritics": "R from diacritic",
	"R from title with diacritics": "R from diacritic",
	"R with diacritics": "R from diacritic",
	"Redirect from title with diacritics": "R from diacritic",
	"Redirect from diacritics": "R from diacritic",
	"R dia": "R from diacritic",
	"R from accent": "R from diacritic",
	"R with accents": "R from diacritic",
	"R from diacritics": "R from diacritic",
	"Redirect from diacritic": "R from diacritic",
	
	"R to accents": "R to diacritic",
	"Redirects from title without diacritics": "R to diacritic",
	"RDiacr": "R to diacritic",
	"R to unicode name": "R to diacritic",
	"R to unicode": "R to diacritic",
	"R to title with diacritics": "R to diacritic",
	"R from name without diacritics": "R to diacritic",
	"R from original name without diacritics": "R to diacritic",
	"R without diacritics": "R to diacritic",
	"R diacritics": "R to diacritic",
	"Redirect from title without diacritics": "R to diacritic",
	"Redirect to Unicode": "R to diacritic",
	"R to Unicode": "R to diacritic",
	"Redirect without diacritics": "R to diacritic",
	"R to Unicode name": "R to diacritic",
	"Redirect to Unicode name": "R to diacritic",
	"Redirect from name without diacritics": "R to diacritic",
	"R from title without diacritics": "R to diacritic",
	"R to diacritical marks": "R to diacritic",
	"R to diacritical mark": "R to diacritic",
	"R without accents": "R to diacritic",
	"Redirect to diacritics": "R to diacritic",
	"R to diacritics": "R to diacritic",
	"Redirect to diacritic": "R to diacritic",
	"R to accent": "R to diacritic",
	"Redirects from titles without diacritics": "R to diacritic",
	
	"R dab": "R to disambiguation page",
	"R disambig": "R to disambiguation page",
	"R dp": "R to disambiguation page",
	"R from disambig": "R to disambiguation page",
	"R from disambiguation": "R to disambiguation page",
	"R from disambiguation page": "R to disambiguation page",
	"R to DAB": "R to disambiguation page",
	"R to dab": "R to disambiguation page",
	"R to dis": "R to disambiguation page",
	"R to disambig": "R to disambiguation page",
	"R to disambiguation": "R to disambiguation page",
	"R to dp": "R to disambiguation page",
	"Redirect dp": "R to disambiguation page",
	"Redirect to dab": "R to disambiguation page",
	"Redirect to dis": "R to disambiguation page",
	"Redirect to disambiguation": "R to disambiguation page",
	"Redirect to disambiguation page": "R to disambiguation page",
	"Redirect to dp": "R to disambiguation page",
	"Rtdp": "R to disambiguation page",
	
	"R dn": "R from domain name",
	"R from domain": "R from domain name",
	"R from dotcom": "R from domain name",
	"R from URL": "R from domain name",
	"R from url": "R from domain name",
	"R from web address": "R from domain name",
	"R from website": "R from domain name",
	"Redirect dn": "R from domain name",
	"Redirect from domain name": "R from domain name",
	
	"R dou": "R from duplicated article",
	"R double": "R from duplicated article",
	"R double article": "R from duplicated article",
	"R du": "R from duplicated article",
	"R dup": "R from duplicated article",
	"R duplicated": "R from duplicated article",
	"R duplicated article": "R from duplicated article",
	"R from duplicate": "R from duplicated article",
	"R from duplicate article": "R from duplicated article",
	"Redirect dou": "R from duplicated article",
	"Redirect double": "R from duplicated article",
	"Redirect double article": "R from duplicated article",
	"Redirect du": "R from duplicated article",
	"Redirect dup": "R from duplicated article",
	"Redirect duplicated": "R from duplicated article",
	"Redirect duplicated article": "R from duplicated article",
	"Redirect from duplicated article": "R from duplicated article",
	
	"Character redirect entry": "R from fictional character",
	"CharR to list entry": "R from fictional character",
	"Crl": "R from fictional character",
	"R fc": "R from fictional character",
	"R from character": "R from fictional character",
	"R to character list entry": "R from fictional character",
	"Redirect from character": "R from fictional character",
	"Redirect from fictional character": "R from fictional character",
	"Redirect to character list entry": "R from fictional character",
	
	"R ext": "R from file extension",
	"R from filename extension": "R from file extension",
	"Redirect from file extension": "R from file extension",

	"R from EXIF": "R from file metadata link",
	"R from Exif": "R from file metadata link",
	"R from exif": "R from file metadata link",
	"R metadata": "R from file metadata link",
	"Redirect from EXIF": "R from file metadata link",
	"Redirect from EXIF file metadata link": "R from file metadata link",
	"Redirect from file metadata link": "R from file metadata link",
	
	"R from filename title": "R from filename",
	"Redirect from filename": "R from filename",
	
	"R fn": "R from former name",
	"R former": "R from former name",
	"R former name": "R from former name",
	"R former title": "R from former name",
	"R from archaic name": "R from former name",
	"R from archaic title": "R from former name",
	"R from changed name": "R from former name",
	"R from former title": "R from former name",
	"R from old name": "R from former name",
	"R from old title": "R from former name",
	"R from older name": "R from former name",
	"R from older title": "R from former name",
	"R from original name": "R from former name",
	"R from previous name": "R from former name",
	"R from previous title": "R from former name",
	"R from working title": "R from former name",
	"R ft": "R from former name",
	"R old": "R from former name",
	"R old name": "R from former name",
	"R old title": "R from former name",
	"R older": "R from former name",
	"R older name": "R from former name",
	"R older title": "R from former name",
	"R to current name": "R from former name",
	"R to current title": "R from former name",
	"R to modern name": "R from former name",
	"R to modern title": "R from former name",
	"R to new name": "R from former name",
	"R to new title": "R from former name",
	"R to newer name": "R from former name",
	"R to newer title": "R from former name",
	"R to present name": "R from former name",
	"R to present title": "R from former name",
	"Redirect fn": "R from former name",
	"Redirect former": "R from former name",
	"Redirect former name": "R from former name",
	"Redirect former title": "R from former name",
	"Redirect from archaic name": "R from former name",
	"Redirect from archaic title": "R from former name",
	"Redirect from former name": "R from former name",
	"Redirect from former title": "R from former name",
	"Redirect from old name": "R from former name",
	"Redirect from old title": "R from former name",
	"Redirect from older name": "R from former name",
	"Redirect from older title": "R from former name",
	"Redirect from original name": "R from former name",
	"Redirect from previous name": "R from former name",
	"Redirect from previous title": "R from former name",
	"Redirect from working title": "R from former name",
	"Redirect ft": "R from former name",
	"Redirect old name": "R from former name",
	"Redirect old title": "R from former name",
	"Redirect older": "R from former name",
	"Redirect older name": "R from former name",
	"Redirect older title": "R from former name",
	"Redirect to current name": "R from former name",
	"Redirect to current title": "R from former name",
	"Redirect to modern name": "R from former name",
	"Redirect to modern title": "R from former name",
	"Redirect to new name": "R from former name",
	"Redirect to new title": "R from former name",
	"Redirect to newer name": "R from former name",
	"Redirect to newer title": "R from former name",
	"Redirect to present name": "R from former name",
	"Redirect to present title": "R from former name",
	
	"R from feminine": "R from gender",
	"R from masculine": "R from gender",
	"R from sex": "R from gender",
	"Redirect from gender": "R from gender",
	
	"R ge": "R from gerund",
	"Redirect ge": "R from gerund",
	"Redirect from gerund": "R from gerund",
	
	"R from first name": "R from given name",
	"R from forename": "R from given name",
	"R given name": "R from given name",
	"Redirect from given name": "R from given name",
	
	"R high": "R from highway",
	"Redirect from highway": "R from highway",

	"R from highway in state": "R from highway in region",
	"R from highway in state with possibilities": "R from highway in region",
	"R highr": "R from highway in region",
	"Redirect from highway in region": "R from highway in region",
	
	"R from highway in region without possibilites": "R from highway in region without possibilities",
	"R from highway without possibilites": "R from highway in region without possibilities",
	"R highrwop": "R from highway in region without possibilities",
	"Redirect from highway in region without possibilities": "R from highway in region without possibilities",

	"R from historic term": "R from historic name",
	"R from historic title": "R from historic name",
	"R from historical": "R from historic name",
	"R from historical name": "R from historic name",
	"R from historical term": "R from historic name",
	"R from historical title": "R from historic name",
	"R from obsolete name": "R from historic name",
	"R from obsolete term": "R from historic name",
	"R from obsolete title": "R from historic name",
	"R his": "R from historic name",
	"R historic": "R from historic name",
	"R historic name": "R from historic name",
	"R historic title": "R from historic name",
	"R historical": "R from historic name",
	"R historical name": "R from historic name",
	"R historical title": "R from historic name",
	"R hn": "R from historic name",
	"R ht": "R from historic name",
	"Redirect from historic name": "R from historic name",
	"Redirect from historic title": "R from historic name",
	"Redirect from historical name": "R from historic name",
	"Redirect from historical title": "R from historic name",
	"Redirect from obsolete name": "R from historic name",
	"Redirect from obsolete title": "R from historic name",
	"Redirect his": "R from historic name",
	"Redirect historic": "R from historic name",
	"Redirect historic name": "R from historic name",
	"Redirect historic title": "R from historic name",
	"Redirect historical": "R from historic name",
	"Redirect historical name": "R from historic name",
	"Redirect historical title": "R from historic name",
	"Redirect hn": "R from historic name",
	"Redirect ht": "R from historic name",
	
	"R from adopted name": "R to historic name",
	"R from adoptive name": "R to historic name",
	"R from later name": "R to historic name",
	"R from name change": "R to historic name",
	"R from new name": "R to historic name",
	"R from newer name": "R to historic name",
	"R from rebranding": "R to historic name",
	"R from successor company name": "R to historic name",
	"R thn": "R to historic name",
	"R to earlier name": "R to historic name",
	"R to early name": "R to historic name",
	"R to historic title": "R to historic name",
	"R to old name": "R to historic name",
	"R to older name": "R to historic name",
	"R to original name": "R to historic name",
	"R to predecessor company name": "R to historic name",
	"Redirect from new name": "R to historic name",
	"Redirect to historic name": "R to historic name",
	"Redirect to historic title": "R to historic name",
	
	"R from ambiguous disambiguation": "R from incomplete disambiguation",
	"R from incomplete dab": "R from incomplete disambiguation",
	"R from incomplete disambigaution": "R from incomplete disambiguation",
	"R from insufficient disambiguation": "R from incomplete disambiguation",
	"R from missing disambiguation": "R from incomplete disambiguation",
	"R from partial disambiguation": "R from incomplete disambiguation",
	"R indab": "R from incomplete disambiguation",
	"R partial dab": "R from incomplete disambiguation",
	"Redirect from incomplete disambiguation": "R from incomplete disambiguation",
	"Redirect from missing disambiguation": "R from incomplete disambiguation",
	"Redirect md": "R from incomplete disambiguation",
	
	"R from an incomplete name": "R from incomplete name",
	"R from incomplete title": "R from incomplete name",
	"R to complete name": "R from incomplete name",
	"R to complete title": "R from incomplete name",
	"Redirect from incomplete name": "R from incomplete name",
	"Redirect from incomplete title": "R from incomplete name",
	"Redirect to complete name": "R from incomplete name",
	"Redirect to complete title": "R from incomplete name",
	
	"R id": "R from incorrect disambiguation",
	"R wd": "R from incorrect disambiguation",
	"R wrongdab": "R from incorrect disambiguation",
	"Redirect from incorrect disambiguation": "R from incorrect disambiguation",
	"Redirect id": "R from incorrect disambiguation",
	"Redirect wd": "R from incorrect disambiguation",
	
	"From fake name": "R from incorrect name",
	"From false name": "R from incorrect name",
	"From inaccurate name": "R from incorrect name",
	"From misleading name": "R from incorrect name",
	"From misnomer": "R from incorrect name",
	"From wrong name": "R from incorrect name",
	"R from erroneous name": "R from incorrect name",
	"R from error": "R from incorrect name",
	"R from improper name": "R from incorrect name",
	"R from improper title": "R from incorrect name",
	"R from inaccurate name": "R from incorrect name",
	"R from inappropriate name": "R from incorrect name",
	"R from inappropriate title": "R from incorrect name",
	"R from incorrect": "R from incorrect name",
	"R from incorrect title": "R from incorrect name",
	"R from misleading name": "R from incorrect name",
	"R from misnomer": "R from incorrect name",
	"R from unsuitable title": "R from incorrect name",
	"R from wrong name": "R from incorrect name",
	"R from wrong title": "R from incorrect name",
	"R incorrect": "R from incorrect name",
	"R incorrect name": "R from incorrect name",
	"R to appropriate name": "R from incorrect name",
	"R to appropriate title": "R from incorrect name",
	"R to correct name": "R from incorrect name",
	"R to correct title": "R from incorrect name",
	"R to corrected name": "R from incorrect name",
	"R to corrected title": "R from incorrect name",
	"R to proper name": "R from incorrect name",
	"R to proper title": "R from incorrect name",
	"R wrong": "R from incorrect name",
	"R wrongname": "R from incorrect name",
	"Redirect form incorrect name": "R from incorrect name",
	"Redirect from improper name": "R from incorrect name",
	"Redirect from improper title": "R from incorrect name",
	"Redirect from inaccurate name": "R from incorrect name",
	"Redirect from inappropriate name": "R from incorrect name",
	"Redirect from inappropriate title": "R from incorrect name",
	"Redirect from incorrect name": "R from incorrect name",
	"Redirect from incorrect title": "R from incorrect name",
	"Redirect from unsuitable title": "R from incorrect name",
	"Redirect from wrong name": "R from incorrect name",
	"Redirect from wrong title": "R from incorrect name",
	"Redirect to appropriate name": "R from incorrect name",
	"Redirect to appropriate title": "R from incorrect name",
	"Redirect to correct name": "R from incorrect name",
	"Redirect to correct title": "R from incorrect name",
	"Redirect to corrected name": "R from incorrect name",
	"Redirect to corrected title": "R from incorrect name",
	"Redirect to proper name": "R from incorrect name",
	"Redirect to proper title": "R from incorrect name",

	"R ab": "R from initialism",
	"R abb": "R from initialism",
	"R abbr": "R from initialism",
	"R abbreviation": "R from initialism",
	"R from ab": "R from initialism",
	"R from abb": "R from initialism",
	"R from abbr": "R from initialism",
	"R from abbrev": "R from initialism",
	"R from abbreviation": "R from initialism",
	"R from abbreviations": "R from initialism",
	"R from common abbreviation": "R from initialism",
	"R from common initialism": "R from initialism",
	"R from common initials": "R from initialism",
	"R from init": "R from initialism",
	"R from initial": "R from initialism",
	"R from initialisms": "R from initialism",
	"R from initials": "R from initialism",
	"R ii": "R from initialism",
	"R in": "R from initialism",
	"R init": "R from initialism",
	"R initialism": "R from initialism",
	"Redirect ab": "R from initialism",
	"Redirect abb": "R from initialism",
	"Redirect abbr": "R from initialism",
	"Redirect from ab": "R from initialism",
	"Redirect from abb": "R from initialism",
	"Redirect from abbr": "R from initialism",
	"Redirect from abbreviation": "R from initialism",
	"Redirect from abbreviations": "R from initialism",
	"Redirect from common abbreviation": "R from initialism",
	"Redirect from common initialism": "R from initialism",
	"Redirect from common initials": "R from initialism",
	"Redirect from init": "R from initialism",
	"Redirect from initialism": "R from initialism",
	"Redirect from initials": "R from initialism",
	"Redirect ii": "R from initialism",
	"Redirect in": "R from initialism",
	"Redirect init": "R from initialism",
	"Rinit": "R from initialism",
	
	"R to initials": "R to initialism",
	"R to abbreviation": "R to initialism",
	"Redirect to initialism": "R to initialism",
	"Redirect to initials": "R to initialism",
	"Redirect to abbreviation": "R to initialism",
	"R to abbrev": "R to initialism",
	"Redirect to abbrev": "R to initialism",
	"R to abb": "R to initialism",
	"Redirect to abb": "R to initialism",
	"R to ab": "R to initialism",
	"Redirect to ab": "R to initialism",
	"R to initialisms": "R to initialism",
	"Redirect to initialisms": "R to initialism",
	"R to init": "R to initialism",
	"Redirect to init": "R to initialism",
	"R to common initialism": "R to initialism",
	"Redirect to common initialism": "R to initialism",
	"R to common initials": "R to initialism",
	"Redirect to common initials": "R to initialism",
	"R to ci": "R to initialism",
	"Redirect to ci": "R to initialism",
	"R to abbreviations": "R to initialism",
	"Redirect to abbreviations": "R to initialism",
	"R to abbr": "R to initialism",
	"Redirect to abbr": "R to initialism",
	"R to common abbreviation": "R to initialism",
	"Redirect to common abbreviation": "R to initialism",
	"R to ca": "R to initialism",
	"Redirect to ca": "R to initialism",
	"R to in": "R to initialism",
	"Redirect to in": "R to initialism",
	"Rtab": "R to initialism",
	"Rtin": "R to initialism",
	"Rti": "R to initialism",
	
	"R jointbio": "R to joint biography",
	"R to joint bio": "R to joint biography",
	"Redirect to joint biography": "R to joint biography",
	
	"R from broader name": "R from less specific name",
	"R from broader subject": "R from less specific name",
	"R from broader title": "R from less specific name",
	"R from broader topic": "R from less specific name",
	"R from generic name": "R from less specific name",
	"R from less specific": "R from less specific name",
	"R from less specific geographic name": "R from less specific name",
	"R from less specific subject": "R from less specific name",
	"R from less specific title": "R from less specific name",
	"R from less specific topic": "R from less specific name",
	"R from more general name": "R from less specific name",
	"R from more general subject": "R from less specific name",
	"R from more general title": "R from less specific name",
	"R from more general topic": "R from less specific name",
	"R general": "R from less specific name",
	"R less specific": "R from less specific name",
	"R to more specific name": "R from less specific name",
	"Redirect from a less specific name": "R from less specific name",
	"Redirect from a more general name": "R from less specific name",
	"Redirect from less specific name": "R from less specific name",
	"Redirect from more general name": "R from less specific name",
	"Redirect to more specific name": "R from less specific name",

	"R from letter-word combination": "R from letter–word combination",
	"R lwc": "R from letter–word combination",
	"Redirect from letter-word combination": "R from letter–word combination",
	"Redirect from letter–word combination": "R from letter–word combination",

	"R from title with ligatures": "R from ligature",
	"R from ligatures": "R from ligature",
	
	"R from title without ligatures": "R to ligature",
	"R to ligatures": "R to ligature",

	"R from list entry": "R to list item",
	"R list": "R to list item",
	"R to a list entry": "R to list item",
	"R to list": "R to list item",
	"R to list entry": "R to list item",
	"Redirect to list": "R to list item",
	"Redirect to list entry": "R to list item",
	
	"R flt": "R from list topic",
	"R list topic": "R from list topic",
	"Redirect from list topic": "R from list topic",
	
	"R from a longer name": "R from long name",
	"R from complete name": "R from long name",
	"R from complete title": "R from long name",
	"R from full name": "R from long name",
	"R from full title": "R from long name",
	"R from lengthened name": "R from long name",
	"R from lengthened title": "R from long name",
	"R from lengthy name": "R from long name",
	"R from lengthy title": "R from long name",
	"R from long": "R from long name",
	"R from long title": "R from long name",
	"R from longer": "R from long name",
	"R from longer name": "R from long name",
	"R from longer title": "R from long name",
	"R full": "R from long name",
	"R full name": "R from long name",
	"R long": "R from long name",
	"R to abbreviated name": "R from long name",
	"R to abbreviated title": "R from long name",
	"R to incomplete name": "R from long name",
	"R to incomplete title": "R from long name",
	"R to short": "R from long name",
	"R to short name": "R from long name",
	"R to short title": "R from long name",
	"R to shortened name": "R from long name",
	"R to shortened title": "R from long name",
	"R to shorter name": "R from long name",
	"R to shorter title": "R from long name",
	"Redirect form full name": "R from long name",
	"Redirect from complete name": "R from long name",
	"Redirect from complete title": "R from long name",
	"Redirect from full name": "R from long name",
	"Redirect from full title": "R from long name",
	"Redirect from lengthened name": "R from long name",
	"Redirect from lengthened title": "R from long name",
	"Redirect from lengthy name": "R from long name",
	"Redirect from lengthy title": "R from long name",
	"Redirect from long name": "R from long name",
	"Redirect from long title": "R from long name",
	"Redirect from longer name": "R from long name",
	"Redirect from longer title": "R from long name",
	"Redirect to abbreviated name": "R from long name",
	"Redirect to abbreviated title": "R from long name",
	"Redirect to incomplete name": "R from long name",
	"Redirect to incomplete title": "R from long name",
	"Redirect to short name": "R from long name",
	"Redirect to short title": "R from long name",
	"Redirect to shortened name": "R from long name",
	"Redirect to shortened title": "R from long name",
	"Redirect to shorter name": "R from long name",
	"Redirect to shorter title": "R from long name",
	
	"R from band member": "R from member",
	"R from cast member": "R from member",
	"R from player": "R from member",
	"R from teammate": "R from member",
	"R to parent": "R from member",
	"Redirect from member": "R from member",
	
	"R hatnote": "R mentioned in hatnote",
	"R mentioned in a hatnote": "R mentioned in hatnote",
	"Redirect mentioned in hatnote": "R mentioned in hatnote",
	
	"R after merge": "R from merge",
	"R from former child": "R from merge",
	"R FROM MERGE": "R from merge",
	"R From Merge": "R from merge",
	"R from Merge": "R from merge",
	"R from merge": "R from merge",
	"R from merged article": "R from merge",
	"R from Merger": "R from merge",
	"R from merger": "R from merge",
	"R from merges": "R from merge",
	"R merge": "R from merge",
	"R to merge": "R from merge",
	"Redirect after merge": "R from merge",
	"Redirect from merge": "R from merge",

	"R from miscapitalization": "R from miscapitalisation",
	"R from incorrect capitalisation": "R from miscapitalisation",
	"R from incorrect capitalization": "R from miscapitalisation",
	"Redirect from miscapitalisation": "R from miscapitalisation",
	"Redirect from incorrect capitalization": "R from miscapitalisation",
	"Redirect from incorrect capitalisation": "R from miscapitalisation",
	"R miscap": "R from miscapitalisation",
	"R from overcapitalisation": "R from miscapitalisation",
	"R from over-capitalisation": "R from miscapitalisation",
	"R from over-capitalization": "R from miscapitalisation",
	"R from overcapitalization": "R from miscapitalisation",
	"R from miscap": "R from miscapitalisation",
	"R from miscaps": "R from miscapitalisation",
	"Redirect from overcapitalization": "R from miscapitalisation",
	"R from incorrect capitlisation": "R from miscapitalisation",

	"R from mispelling": "R from misspelling",
	"R for misspelling": "R from misspelling",
	"R from mispeling": "R from misspelling",
	"R from typo": "R from misspelling",
	"R from misspellings": "R from misspelling",
	"R from incorrect spelling": "R from misspelling",
	"R from misprint": "R from misspelling",
	"R from misspeling": "R from misspelling",
	"R from mispellings": "R from misspelling",
	"R misspelling": "R from misspelling",
	"R From Misspelling": "R from misspelling",
	"R From Mispelling": "R from misspelling",
	"Redirect from misspelling": "R from misspelling",
	"R from mis-spelling": "R from misspelling",
	"R from mis-spellings": "R from misspelling",
	"R typo": "R from misspelling",
	"R from spelling mistake": "R from misspelling",
	"Redirect from incorrect spelling": "R from misspelling",
	"R from common misspelling": "R from misspelling",
	"Redirect from common misspelling": "R from misspelling",
	"Redirect from typo": "R from misspelling",
	"Redirect cm": "R from misspelling",
	"R mi": "R from misspelling",
	"Redirect mi": "R from misspelling",
	"Redirect form misspelling": "R from misspelling",
	"R from tpyo": "R from misspelling",
	"Redirect from mis-spelling": "R from misspelling",
	"Redirect from uncommon misspelling": "R from misspelling",
	"Rfm": "R from misspelling",
	"R from misspell": "R from misspelling",
	"Redirect from spelling error": "R from misspelling",
	"R from full common typo": "R from misspelling",
	"Redirect form mis-spelling": "R from misspelling",
	"From typographical error": "R from misspelling",
	"Redirect from typographical error": "R from misspelling",

	"R from alternative punctuation": "R from modification",
	"R mod": "R from modification",
	"R from punctuation": "R from modification",
	"R from alternate punctuation": "R from modification",
	"R from other punctuation": "R from modification",
	"R from alternative spacing": "R from modification",
	"R from alternate spacing": "R from modification",
	"R from incorrect punctuation": "R from modification",
	"R from other hyphenation": "R from modification",
	"R from name with alternate punctuation": "R from modification",
	"Redirect from punctuation": "R from modification",
	"R from alteration": "R from modification",
	"R from rearrangement": "R from modification",
	"R from alternative hyphenation": "R from modification",
	"R to alternative punctuation": "R from modification",
	"Redirect to modification": "R from modification",
	"R to alternate punctuation": "R from modification",
	"R to other punctuation": "R from modification",
	"R to modification": "R from modification",
	"R to alternative hyphenation": "R from modification",
	"R to alternative spacing": "R from modification",
	"R to alternate spacing": "R from modification",
	"Redirect from modification": "R from modification",
	"R from missing punctuation": "R from modification",
	"Redirect from missing punctuation": "R from modification",
	"Redirect from rearrangement": "R from modification",
	"R from word reorder": "R from modification",
	"Redirect from word reorder": "R from modification",
	"Redirect from other word order": "R from modification",
	"R from other word order": "R from modification",
	"R from other arrangement": "R from modification",
	"Redirect from other arrangement": "R from modification",
	"R from word rearrangement": "R from modification",
	"Redirect from word rearrangement": "R from modification",
	"R from other word arrangement": "R from modification",
	"Redirect from other word arrangement": "R from modification",
	"R from reorder": "R from modification",
	"Redirect from reorder": "R from modification",
	"R from other order": "R from modification",
	"Redirect from other order": "R from modification",
	"R from extra punctuation": "R from modification",
	"Redirect from extra punctuation": "R from modification",
	"Redirect from added punctuation": "R from modification",
	"R from added punctuation": "R from modification",
	"R from mod": "R from modification",
	"Redirect from mod": "R from modification",
	"Redirect from incorrect punctuation": "R from modification",
	"Redirect from alternative punctuation": "R from modification",
	"R from extra spacing": "R from modification",
	"Redirect from extra spacing": "R from modification",
	"Redirect from alternate spacing": "R from modification",
	"Redirect from alternative spacing": "R from modification",
	"R from other spacing": "R from modification",
	"Redirect from other spacing": "R from modification",
	"Redirect from alteration": "R from modification",
	"R from modified name": "R from modification",
	"Redirect from modified name": "R from modification",
	"R from modified title": "R from modification",
	"Redirect from modified title": "R from modification",
	"Redirect from name with alternate punctuation": "R from modification",
	"R from title with alternate punctuation": "R from modification",
	"Redirect from title with alternate punctuation": "R from modification",
	"Redirect from other punctuation": "R from modification",
	"Redirect from alternate punctuation": "R from modification",
	"R from arrangement": "R from modification",
	"Redirect from arrangement": "R from modification",
	"R from hyphenation": "R from modification",
	"Redirect from hyphenation": "R from modification",
	"Redirect from other hyphenation": "R from modification",
	"R from alternate hyphenation": "R from modification",
	"Redirect from alternate hyphenation": "R from modification",
	"Redirect from alternative hyphenation": "R from modification",
	"R from incorrect hyphenation": "R from modification",
	"Redirect from incorrect hyphenation": "R from modification",
	"R from missing hyphenation": "R from modification",
	"Redirect from missing hyphenation": "R from modification",
	"R from extra hyphenation": "R from modification",
	"Redirect from extra hyphenation": "R from modification",
	"R from spacing": "R from modification",
	"Redirect from spacing": "R from modification",
	"R from incorrect spacing": "R from modification",
	"Redirect from incorrect spacing": "R from modification",
	"R from missing spacing": "R from modification",
	"Redirect from missing spacing": "R from modification",
	"R from added hyphenation": "R from modification",
	"Redirect from added hyphenation": "R from modification",
	"R from added spacing": "R from modification",
	"Redirect from added spacing": "R from modification",
	"R from altered name": "R from modification",
	"Redirect from altered name": "R from modification",
	"R from altered title": "R from modification",
	"Redirect from altered title": "R from modification",
	"R from alt": "R from modification",
	"Redirect from alt": "R from modification",
	"Redirect mod": "R from modification",
	"R modification": "R from modification",
	"Redirect modification": "R from modification",
	"R alteration": "R from modification",
	"Redirect alteration": "R from modification",
	"R mo": "R from modification",
	"Redirect mo": "R from modification",
	"R from ordering": "R from modification",
	"Redirect from ordering": "R from modification",
	"R from reordering": "R from modification",
	"Redirect from reordering": "R from modification",
	"R from mo": "R from modification",
	"Redirect from mo": "R from modification",
	"R missing spacing": "R from modification",
	"Redirect missing spacing": "R from modification",
	"R ms": "R from modification",
	"Redirect ms": "R from modification",
	"R msp": "R from modification",
	"Redirect msp": "R from modification",
	"R mp": "R from modification",
	"Redirect mp": "R from modification",
	"R eh": "R from modification",
	"Redirect eh": "R from modification",
	"Redirect mh": "R from modification",
	"R mh": "R from modification",
	"R missing hyphenation": "R from modification",
	"Redirect from title with different punctuation": "R from modification",
	"R from alt punctuation": "R from modification",
	"R from alt punct": "R from modification",
	"R from modificatoin": "R from modification",
	"R from modification.": "R from modification",
	"R from mispunctuation": "R from modification",
	"R from whitespace": "R from modification",
	"R from mod name": "R from modification",
	"R from correct hyphenation": "R from modification",
	"Redirect from different punctuation": "R from modification",
	"R ih": "R from modification",
	"R to mod": "R from modification",
	"R from modify": "R from modification",
	"Redirect from different spacing": "R from modification",
	"Redirect to alternative punctuation": "R from modification",

	"R from less general name": "R from more specific name",
	"R from more correct name": "R from more specific name",
	"R from more precise name": "R from more specific name",
	"R from more specific": "R from more specific name",
	"R from population to species": "R from more specific name",
	"R from specific name": "R from more specific name",
	"R from subspecies to species": "R from more specific name",
	"R from subtitle": "R from more specific name",
	"R from variety to species": "R from more specific name",
	"R less general": "R from more specific name",
	"R more specific": "R from more specific name",
	"R specific": "R from more specific name",
	"R to less general name": "R from more specific name",
	"R to less precise name": "R from more specific name",
	"R to less specific": "R from more specific name",
	"R to less specific name": "R from more specific name",
	"R to more general name": "R from more specific name",
	"Redirect from more specific name": "R from more specific name",
	"Redirect to less specific": "R from more specific name",
	"Redirect to more general": "R from more specific name",
	
	"R from geo": "R from more specific geographic name",
	"R from more specific place name": "R from more specific geographic name",
	"R from specific geographic location": "R from more specific geographic name",
	"R from specific geographic name": "R from more specific geographic name",
	"R from specific place name": "R from more specific geographic name",
	"R to Spanish municipality": "R from more specific geographic name",
	"Redirect from more specific geographic name": "R from more specific geographic name",
	
	"R from page move": "R from move",
	"R from rename": "R from move",
	"R move": "R from move",
	"R page move": "R from move",
	"R pm": "R from move",
	"Redirect from move": "R from move",
	"Redirect from page move": "R from move",
	"Redirect move": "R from move",
	"Redirect page move": "R from move",
	"Redirect pm": "R from move",
	
	"R from honorable title": "R from name with title",
	"R from honorary": "R from name with title",
	"R from honorary name": "R from name with title",
	"R from honorary title": "R from name with title",
	"R from honorific": "R from name with title",
	"R from honorific name": "R from name with title",
	"R from honorific style": "R from name with title",
	"R from honorific title": "R from name with title",
	"R with title": "R from name with title",
	
	"R from biased name": "R from non-neutral name",
	"R from curse": "R from non-neutral name",
	"R from curse word": "R from non-neutral name",
	"R from derogatory": "R from non-neutral name",
	"R from derogatory name": "R from non-neutral name",
	"R from derogatory term": "R from non-neutral name",
	"R from ethnic slur": "R from non-neutral name",
	"R from expletive": "R from non-neutral name",
	"R from explicit word": "R from non-neutral name",
	"R from insult": "R from non-neutral name",
	"R from laudatory": "R from non-neutral name",
	"R from laudatory name": "R from non-neutral name",
	"R from laudatory term": "R from non-neutral name",
	"R from less neutral name": "R from non-neutral name",
	"R from non neutral name": "R from non-neutral name",
	"R from non-neutral": "R from non-neutral name",
	"R from non-neutral phrase": "R from non-neutral name",
	"R from non-neutral sentence": "R from non-neutral name",
	"R from non-neutral word": "R from non-neutral name",
	"R from pejorative": "R from non-neutral name",
	"R from pejorative name": "R from non-neutral name",
	"R from pejorative term": "R from non-neutral name",
	"R from POV name": "R from non-neutral name",
	"R from PoV name": "R from non-neutral name",
	"R from promotional": "R from non-neutral name",
	"R from promotional name": "R from non-neutral name",
	"R from racial slur": "R from non-neutral name",
	"R from royal style": "R from non-neutral name",
	"R from rude word": "R from non-neutral name",
	"R from slang": "R from non-neutral name",
	"R from slur": "R from non-neutral name",
	"R from style": "R from non-neutral name",
	"R from styles": "R from non-neutral name",
	"R from swear": "R from non-neutral name",
	"R from swear word": "R from non-neutral name",
	"R from vulgar word": "R from non-neutral name",
	"R nnn": "R from non-neutral name",
	"R pejorative": "R from non-neutral name",
	"R to more neutral name": "R from non-neutral name",
	"R to neutral": "R from non-neutral name",
	"R to neutral name": "R from non-neutral name",
	"R to NPOV name": "R from non-neutral name",
	"Redirect from non-neutral name": "R from non-neutral name",
	"Redirect from pejorative": "R from non-neutral name",
	
	"R from numbers": "R from numerals",
	"R from numeral": "R from numerals",
	"Redirect from numerals": "R from numerals",
	"Rfn": "R from numerals",
	
	"R to numbers": "R to numerals",
	"R to numeral": "R to numerals",
	"Redirect to numeral": "R to numerals",
	"Redirect to numerals": "R to numerals",
	"Rtn": "R to numerals",
	
	"R foh": "R with old history",
	"R from old history": "R with old history",
	"R woh": "R with old history",
	"Redirect old": "R with old history",
	"Redirect with old history": "R with old history",
	
	"R for alternate capitalization": "R from other capitalisation",
	"R for alternate capitalisation": "R from other capitalisation",
	"R for alternative capitalization": "R from other capitalisation",
	"R for alternative capitalisation": "R from other capitalisation",
	"R from alternate capitalisation": "R from other capitalisation",
	"R from alternative capitalisation": "R from other capitalisation",
	"R from other capitalization": "R from other capitalisation",
	"R from alternate capitalization": "R from other capitalisation",
	"R from lowercase": "R from other capitalisation",
	"R from alt cap": "R from other capitalisation",
	"R from other Capitalization": "R from other capitalisation",
	"R from capitalization": "R from other capitalisation",
	"R from Capitalisation": "R from other capitalisation",
	"R from Capitalization": "R from other capitalisation",
	"R from capitalisation": "R from other capitalisation",
	"R to Capitalization": "R from other capitalisation",
	"R from alternative capitalization": "R from other capitalisation",
	"Redirect from capitalisation": "R from other capitalisation",
	"R from caps": "R from other capitalisation",
	"R from cap": "R from other capitalisation",
	"R from another capitalisation": "R from other capitalisation",
	"R from another capitalization": "R from other capitalisation",
	"R cap": "R from other capitalisation",
	"R from other caps": "R from other capitalisation",
	"R from alt case": "R from other capitalisation",
	"R to alternate capitalisation": "R from other capitalisation",
	"R from different capitalization": "R from other capitalisation",
	"R to other capitalization": "R from other capitalisation",
	"R caps": "R from other capitalisation",
	"R from other cap": "R from other capitalisation",
	"R from other case": "R from other capitalisation",
	"R from alternative cap": "R from other capitalisation",
	"R from alternative case": "R from other capitalisation",
	"R from different cap": "R from other capitalisation",
	"R from different case": "R from other capitalisation",
	"R from other capitialisation": "R from other capitalisation",
	"R capitalisation": "R from other capitalisation",
	"R from capital": "R from other capitalisation",
	"R from other capitilisation": "R from other capitalisation",
	"R from alternative capitialisation": "R from other capitalisation",
	"Redirect from other capitalisation": "R from other capitalisation",
	"R to alternate capitalization": "R from other capitalisation",
	"Redirect from other capitalization": "R from other capitalisation",
	"R from other Capitalisation": "R from other capitalisation",
	"R to alternative capitalization": "R from other capitalisation",
	"R to alternative capitalisation": "R from other capitalisation",
	"R to alt cap": "R from other capitalisation",
	"R to capitalization": "R from other capitalisation",
	"R to Capitalisation": "R from other capitalisation",
	"R to capitalisation": "R from other capitalisation",
	"R to other caps": "R from other capitalisation",
	"R to different capitalization": "R from other capitalisation",
	"R to other capitialisation": "R from other capitalisation",
	"R to other capitilisation": "R from other capitalisation",
	"R from uppercase": "R from other capitalisation",
	"R from lower case": "R from other capitalisation",
	"R to other capitalisation": "R from other capitalisation",
	"R from all caps": "R from other capitalisation",
	"Redirect from all caps": "R from other capitalisation",
	"R ac": "R from other capitalisation",
	"Redirect ac": "R from other capitalisation",
	"Rcap": "R from other capitalisation",
	"R from alt caps": "R from other capitalisation",
	"Redirect from alt caps": "R from other capitalisation",
	"R to uppercase": "R from other capitalisation",
	"Redirect from different capitalization": "R from other capitalisation",
	"R to lowercase": "R from other capitalisation",
	"R from alternative capital": "R from other capitalisation",
	"R from capitals": "R from other capitalisation",
	"Redirect from alternative capitalisation": "R from other capitalisation",
	"R from alt capitalization": "R from other capitalisation",
	"Redirect from alternate capitalisation": "R from other capitalisation",
	"Capitalization redirect": "R from other capitalisation",
	"R from mixed case": "R from other capitalisation",
	"R from alt capitalisation": "R from other capitalisation",
	"Redirect from capitalization": "R from other capitalisation",
	"Redirect from alternate capitalization": "R from other capitalisation",
	"Redirect from alternative capitalization": "R from other capitalisation",
	"Redirect from lowercase": "R from other capitalisation",
	"R Capitalization": "R from other capitalisation",
	
	"R fod": "R from other disambiguation",
	"R from alt dab": "R from other disambiguation",
	"R from alt disambig": "R from other disambiguation",
	"R from alternate disambiguation": "R from other disambiguation",
	"R from alternative disambiguation": "R from other disambiguation",
	"R from different disambiguation": "R from other disambiguation",
	"R from other dab": "R from other disambiguation",
	"R to alternate disambiguation": "R from other disambiguation",
	"R to alternative disambiguation": "R from other disambiguation",
	"R to other disambiguation": "R from other disambiguation",
	"Redirect from alternative disambiguation": "R from other disambiguation",
	"Redirect from other disambiguation": "R from other disambiguation",
	
	"R from people": "R from person",
	"R from persons": "R from person",
	"R to person": "R from person",
	"Redirect from people": "R from person",
	"Redirect from person": "R from person",
	
	"R from Plural": "R from plural",
	"R to singular": "R from plural",
	"Redirect to singular": "R from plural",
	"Redirect from plural": "R from plural",
	"R from pluralization": "R from plural",
	"Redirect from pluralization": "R from plural",
	"R from pluralisation": "R from plural",
	"Redirect from pluralisation": "R from plural",
	"R from plural form": "R from plural",
	"Redirect from plural form": "R from plural",
	"Redirect in plural form": "R from plural",
	"R in plural form": "R from plural",
	"R in plural": "R from plural",
	"Redirect in plural": "R from plural",
	"R from pluralised title": "R from plural",
	"Redirect from pluralised title": "R from plural",
	"R from pluralized title": "R from plural",
	"Redirect from pluralized title": "R from plural",
	"R from pluralised form": "R from plural",
	"Redirect from pluralised form": "R from plural",
	"R from pluralized form": "R from plural",
	"Redirect from pluralized form": "R from plural",
	"R from plural title": "R from plural",
	"Redirect from plural title": "R from plural",
	"R to singular title": "R from plural",
	"Redirect to singular title": "R from plural",
	"R to singular form": "R from plural",
	"Redirect to singular form": "R from plural",
	"R pl": "R from plural",
	"Redirect pl": "R from plural",
	"R fpl": "R from plural",

	"R from possibilities": "R with possibilities",
	"R from subtopic with possibilities": "R with possibilities",
	"R opt": "R with possibilities",
	"R po": "R with possibilities",
	"R pos": "R with possibilities",
	"R poss": "R with possibilities",
	"R possibilities": "R with possibilities",
	"R pot": "R with possibilities",
	"R with article potential": "R with possibilities",
	"R with options": "R with possibilities",
	"R with poss": "R with possibilities",
	"R with possibilites": "R with possibilities",
	"R with Possibilities": "R with possibilities",
	"R with possibility": "R with possibilities",
	"R with possibilties": "R with possibilities",
	"R with possiblities": "R with possibilities",
	"R with pot": "R with possibilities",
	"R with potential": "R with possibilities",
	"R with promise": "R with possibilities",
	"Redirect from subtopic with possibilities": "R with possibilities",
	"Redirect opt": "R with possibilities",
	"Redirect po": "R with possibilities",
	"Redirect pos": "R with possibilities",
	"Redirect poss": "R with possibilities",
	"Redirect pot": "R with possibilities",
	"Redirect with article potential": "R with possibilities",
	"Redirect with possibilities": "R with possibilities",
	"Redirect with pot": "R with possibilities",
	"Redirects with possibilities": "R with possibilities",
	"Redirects with potential": "R with possibilities",
	"RWP": "R with possibilities",
	"RwP": "R with possibilities",
	"Rwp": "R with possibilities",

	"R from product": "R from product name",
	"R from service": "R from product name",
	"R prod": "R from product name",
	"Redirect from product": "R from product name",

	"Redirect from proper noun": "R from proper noun",
	"R from proper name": "R from proper noun",
	"Redirect from proper name": "R from proper noun",
	"R from capitalised noun": "R from proper noun",
	"Redirect from capitalised noun": "R from proper noun",
	"R from capitalized noun": "R from proper noun",
	"Redirect from capitalized noun": "R from proper noun",
	"R from proper": "R from proper noun",
	"Redirect from proper": "R from proper noun",
	"R pn": "R from proper noun",
	"Redirect pn": "R from proper noun",
	"R cn": "R from proper noun",
	"Redirect cn": "R from proper noun",

	"R asn": "R from alternative scientific name",
	"R from another scientific name": "R from alternative scientific name",
	"R from taxonomic synonym": "R from alternative scientific name",
	"R to alternative scientific name": "R from alternative scientific name",
	"Raltsci": "R from alternative scientific name",
	"Redirect asn": "R from alternative scientific name",
	"Redirect from alternative scientific name": "R from alternative scientific name",
	"Redirect from biological synonym": "R from alternative scientific name",
	"Redirect from taxonomic synonym": "R from alternative scientific name",
	"Redirect to alternative scientific name": "R from alternative scientific name",

	"Template:R sa": "R from scientific abbreviation",
	"Redirect from scientific abbreviation": "R from scientific abbreviation",
	"Rsa": "R from scientific abbreviation",
	
	"Redirect to subsection": "R to section",
	"R to subsection": "R to section",
	"R from section": "R to section",
	"R section": "R to section",
	"R sect": "R to section",
	"R sec": "R to section",
	"R se": "R to section",
	"Redirect sec": "R to section",
	"Redirect se": "R to section",
	"Rts": "R to section",
	"R to a section": "R to section",
	"Section redirect": "R to section",
	"R to Section": "R to section",
	"Redirect to section": "R to section",

	"Redirect from stylization": "R from stylization",
	"R sty": "R from stylization",
	"Redirect sty": "R from stylization",
	"R stylized": "R from stylization",
	"Redirect stylized": "R from stylization",
	"R stylised": "R from stylization",
	"Redirect stylised": "R from stylization",
	"Redirect cs": "R from stylization",
	"R styled": "R from stylization",
	"R from stylisation": "R from stylization",
	"R from styling": "R from stylization",
	"R from stylized": "R from stylization",
	"R from stylised": "R from stylization",
	"R from stylised name": "R from stylization",
	"R from stylized name": "R from stylization",
	"R from styled name": "R from stylization",
	"R from styled": "R from stylization",
	"R stylization": "R from stylization",
	
	"Redirect from alternative transliteration": "R from alternative transliteration",
	"R altrans": "R from alternative transliteration",
	"R from transliteration": "R from alternative transliteration",
	"R from alt transliteration": "R from alternative transliteration",
	"R from alternate transliteration": "R from alternative transliteration",
	"Redirect from transliteration": "R from alternative transliteration",
	"R from alternative romanisation": "R from alternative transliteration",
	"R from other transliteration": "R from alternative transliteration",
	"R from another transliteration": "R from alternative transliteration",
	
	"R from U character": "R from Unicode",
	"R from unicode": "R from Unicode",
	"R from Unicode character": "R from Unicode",
	"R U": "R from Unicode",
	"R u": "R from Unicode",
	"R Uc": "R from Unicode",
	"R Unicode": "R from Unicode",
	"R unicode": "R from Unicode",
	"Redirect from U character": "R from Unicode",
	"Redirect from Unicode": "R from Unicode",
	"Redirect from unicode": "R from Unicode",
	"Redirect from Unicode character": "R from Unicode",
	"Redirect U": "R from Unicode",
	"Redirect u": "R from Unicode",
	"Redirect Uc": "R from Unicode",
	"Redirect Unicode": "R from Unicode",

	"Redirect from verb": "R from verb",
	"R from verb phrase": "R from verb",
	"Redirect from verb phrase": "R from verb",
	"R vb": "R from verb",
	"Redirect vb": "R from verb",
	"R verb": "R from verb",
	"Redirect verb": "R from verb",

	"Printworthy": "R printworthy",
	"Printworthy redirect": "R printworthy",
	"Printworthy redirects": "R printworthy",
	"R p": "R printworthy",
	"R printable": "R printworthy",
	"R pw": "R printworthy",
	"R suitable for offline version": "R printworthy",
	"R yes print": "R printworthy",
	"Redirect from printworthy title": "R printworthy",
	"Redirect printworthy": "R printworthy",
	"Redirect pw": "R printworthy",
	
	"This is a redirect.": "Redirect category shell",
	"Redr"               : "Redirect category shell",
	"Rcat shell"    : "Redirect category shell",
	"RCAT shell"    : "Redirect category shell",
	"redirect shell": "Redirect category shell",
	"rcatsh"        : "Redirect category shell",
	
	"": ""
};

var wgNamespaceIds = mw.config.get('wgNamespaceIds');

var redirectTemplates = {
	/* source */
	"R from acronym": {
		"group": "fromacg",
		"label": "acronym"
	},
	"R from initialism": {
		"group": "fromacg",
		"label": "initialism"
	},
	"R from CamelCase": {
		"group": "fromacg",
		"label": "CamelCase"
	},
	"R from miscapitalisation": {
		"group": "fromacg",
		"label": "miscapitalisation",
		"implies": "R unprintworthy"
	},
	"R from other capitalisation": {
		"group": "fromacg",
		"label": "other capitalisation",
		"implies": "R unprintworthy"
	},
	"R from modification": {
		"group": "fromacg",
		"label": "modification"
	},
	"R from plural": {
		"group": "fromacg",
		"label": "plural",
		"implies": "R unprintworthy"
	},
	"R from adjective": {
		"group": "frompos",
		"label": "adjective"
	},
	"R from adverb": {
		"group": "frompos",
		"label": "adverb"
	},
	"R from common noun": {
		"group": "frompos",
		"label": "common noun"
	},
	"R from gerund": {
		"group": "frompos",
		"label": "gerund"
	},
	"R from proper noun": {
		"group": "frompos",
		"label": "proper noun"
	},
	"R from verb": {
		"group": "frompos",
		"label": "verb"
	},
	"R from alternative spelling": {
		"group": "fromspe",
		"label": "alternative spelling"
	},
	"R from misspelling": {
		"group": "fromspe",
		"label": "misspelling",
		"implies": "R unprintworthy"
	},
	"R from American English": {
		"group": "fromspe",
		"label": "American English",
		"implies": "R unprintworthy"
	},
	"R from British English": {
		"group": "fromspe",
		"label": "British English",
		"implies": "R unprintworthy"
	},
	"R from ASCII": {
		"group": "fromspe",
		"label": "ASCII-only title",
		"auto": "from-ascii-to-unicode"
	},
	"R from diacritic": {
		"group": "fromspe",
		"label": "diacritic",
		"implies": "R unprintworthy"
	},
	"R from ligature": {
		"group": "fromspe",
		"label": "ligature",
		"implies": "R unprintworthy"
	},
	"R from stylization": {
		"group": "fromspe",
		"label": "stylization"
	},
	"R from alternative transliteration": {
		"group": "fromspe",
		"label": "alternative transliteration"
	},
	"R from Unicode": {
		"group": "fromspe",
		"label": "Unicode"
	},
	"R from Wade–Giles romanization": {
		"group": "fromspe",
		"label": "Wade–Giles romanization"
	},
	"R from alternative language": {
		"group": "fromangen",
		"label": "alternative language"
	},
	"R from alternative name": {
		"group": "fromangen",
		"label": "alternative name"
	},
	"R from company name": {
		"group": "fromangen",
		"label": "company name"
	},
	"R from former name": {
		"group": "fromangen",
		"label": "former name"
	},
	"R from historic name": {
		"group": "fromangen",
		"label": "historic name"
	},
	"R from incomplete name": {
		"group": "fromangen",
		"label": "incomplete name"
	},
	"R from incorrect name": {
		"group": "fromangen",
		"label": "incorrect name",
		"implies": "R unprintworthy"
	},
	"R from letter–word combination": {
		"group": "fromangen",
		"label": "letter–word combination"
	},
	"R from long name": {
		"group": "fromangen",
		"label": "long name"
	},
	"R from portmanteau": {
		"group": "fromangen",
		"label": "portmanteau"
	},
	"R from predecessor company name": {
		"group": "fromangen",
		"label": "predecessor company name"
	},
	"R from short name": {
		"group": "fromangen",
		"label": "short name"
	},
	"R from sort name": {
		"group": "fromangen",
		"label": "sort name"
	},
	"R from less specific name": {
		"group": "fromangen",
		"label": "less specific name"
	},
	"R from more specific name": {
		"group": "fromangen",
		"label": "more specific name"
	},
	"R from antonym": {
		"group": "fromangen",
		"label": "antonym",
		"implies": ["R printworthy"]
	},
	"R from eponym": {
		"group": "fromangen",
		"label": "eponym"
	},
	"R from synonym": {
		"group": "fromangen",
		"label": "synonym"
	},
	"R from Roman numerals": {
		"group": "fromangen",
		"label": "Roman numerals"
	},
	"R from Canadian settlement name": {
		"group": "fromangeo",
		"label": "Canadian settlement name"
	},
	"R from name and country": {
		"group": "fromangeo",
		"label": "name and country"
	},
	"R from city and state": {
		"group": "fromangeo",
		"label": "city and state"
	},
	"R from city and province": {
		"group": "fromangeo",
		"label": "city and province"
	},
	"R from more specific geographic name": {
		"group": "fromangeo",
		"label": "more specific geographic name"
	},
	"R from postal abbreviation": {
		"group": "fromangeo",
		"label": "postal abbreviation"
	},
	"R from postal code": {
		"group": "fromangeo",
		"label": "postal code"
	},
	"R from US postal abbreviation": {
		"group": "fromangeo",
		"label": "US postal abbreviation"
	},
	"R from birth name": {
		"group": "fromanp",
		"label": "birth name"
	},
	"R from given name": {
		"group": "fromanp",
		"label": "given name"
	},
	"R from married name": {
		"group": "fromanp",
		"label": "married name"
	},
	"R from name with title": {
		"group": "fromanp",
		"label": "name with title",
		"implies": "R unprintworthy"
	},
	"R from non-neutral name": {
		"group": "fromanp",
		"label": "non-neutral name",
		"implies": "R unprintworthy"
	},
	"R from personal name": {
		"group": "fromanp",
		"label": "personal name",
		"implies": "R unprintworthy"
	},
	"R from pseudonym": {
		"group": "fromanp",
		"label": "pseudonym"
	},
	"R from surname": {
		"group": "fromanp",
		"label": "surname"
	},
	"R from scientific abbreviation": {
		"group": "fromans",
		"label": "scientific abbreviation",
		"implies": ["R printworthy"]
	},
	"R from scientific name": {
		"group": "fromans",
		"label": "scientific name",
		"implies": ["R printworthy"]
	},
	"R from alternative scientific name": {
		"group": "fromans",
		"label": "alternative scientific name"
	},
	"R from monotypic taxon": {
		"group": "fromans",
		"label": "monotypic taxon"
	},
	"R from airline code": {
		"group": "fromant",
		"label": "airline code"
	},
	"R from airport code": {
		"group": "fromant",
		"label": "airport code"
	},
	"R from ATC code": {
		"group": "fromant",
		"label": "ATC code"
	},
	"R from ATCvet code": {
		"group": "fromant",
		"label": "ATCvet code"
	},
	"R from Bluebook abbreviation": {
		"group": "fromant",
		"label": "Bluebook abbreviation"
	},
	"R from brand name": {
		"group": "fromant",
		"label": "brand name"
	},
	"R from drug trade name": {
		"group": "fromant",
		"label": "drug trade name"
	},
	"R from file extension": {
		"group": "fromant",
		"label": "file extension"
	},
	"R from filename": {
		"group": "fromant",
		"label": "filename"
	},
	"R from Java package name": {
		"group": "fromant",
		"label": "Java package name",
		"implies": "R unprintworthy"
	},
	"R from MathSciNet abbreviation": {
		"group": "fromant",
		"label": "MathSciNet abbreviation"
	},
	"R from molecular formula": {
		"group": "fromant",
		"label": "molecular formula"
	},
	"R from NLM abbreviation": {
		"group": "fromant",
		"label": "NLM abbreviation"
	},
	"R from product name": {
		"group": "fromant",
		"label": "product name"
	},
	"R from slogan": {
		"group": "fromant",
		"label": "slogan"
	},
	"R from symbol": {
		"group": "fromant",
		"label": "symbol"
	},
	"R from systematic abbreviations": {
		"group": "fromant",
		"label": "systematic abbreviations"
	},
	"R from technical name": {
		"group": "fromant",
		"label": "technical name"
	},
	"R from trademark": {
		"group": "fromant",
		"label": "trademark"
	},
	"R comics from alternative name": {
		"group": "fromc",
		"label": "comics from alternative name"
	},
	"R comics from merge": {
		"group": "fromc",
		"label": "comics from merge"
	},
	"R comics with possibilities": {
		"group": "fromc",
		"label": "comics with possibilities"
	},
	"R comics from related word": {
		"group": "fromc",
		"label": "comics from related word"
	},
	"R from ambiguous term": {
		"group": "fromd",
		"label": "ambiguous term",
		"implies": "R unprintworthy"
	},
	"R from incomplete disambiguation": {
		"group": "fromd",
		"label": "incomplete disambiguation"
	},
	"R from incorrect disambiguation": {
		"group": "fromd",
		"label": "incorrect disambiguation"
	},
	"R from other disambiguation": {
		"group": "fromd",
		"label": "other disambiguation"
	},
	"R from predictable disambiguation": {
		"group": "fromd",
		"label": "predictable disambiguation",
		"implies": "R unprintworthy"
	},
	"R from unnecessary disambiguation": {
		"group": "fromd",
		"label": "unnecessary disambiguation"
	},
	"R from fictional character": {
		"group": "fromf",
		"label": "fictional character"
	},
	"R from fictional element": {
		"group": "fromf",
		"label": "fictional element"
	},
	"R from fictional location": {
		"group": "fromf",
		"label": "fictional location"
	},
	"R from ISO 4 abbreviation": {
		"group": "fromi",
		"label": "ISO 4 abbreviation",
		"implies": ["R printworthy"]
	},
	"R from ISO 639 code": {
		"group": "fromi",
		"label": "ISO 639 code"
	},
	"R from ISO 3166 code": {
		"group": "fromi",
		"label": "ISO 3166 code"
	},
	"R from ISO 4217 code": {
		"group": "fromi",
		"label": "ISO 4217 code"
	},
	"R from ISO 15924 code": {
		"group": "fromi",
		"label": "ISO 15924 code"
	},
	"R from album": {
		"group": "fromri",
		"label": "album"
	},
	"R from animal": {
		"group": "fromri",
		"label": "animal"
	},
	"R from book": {
		"group": "fromri",
		"label": "book",
		"implies": "R unprintworthy"
	},
	"R from catchphrase": {
		"group": "fromri",
		"label": "catchphrase"
	},
	"R from domain name": {
		"group": "fromri",
		"label": "domain name"
	},
	"R from top-level domain": {
		"group": "fromri",
		"label": "top-level domain"
	},
	"R from film": {
		"group": "fromri",
		"label": "film"
	},
	"R from gender": {
		"group": "fromri",
		"label": "gender"
	},
	"R from legislation": {
		"group": "fromri",
		"label": "legislation",
		"implies": "R unprintworthy"
	},
	"R from list topic": {
		"group": "fromri",
		"label": "list topic"
	},
	"R from phrase": {
		"group": "fromri",
		"label": "phrase"
	},
	"R from quotation": {
		"group": "fromri",
		"label": "quotation"
	},
	"R from related word": {
		"group": "fromri",
		"label": "related word"
	},
	"R from school": {
		"group": "fromri",
		"label": "school"
	},
	"R from song": {
		"group": "fromri",
		"label": "song"
	},
	"R from subtopic": {
		"group": "fromri",
		"label": "subtopic"
	},
	"R from team": {
		"group": "fromri",
		"label": "team"
	},
	"R from work": {
		"group": "fromri",
		"label": "work"
	},
	"R from member": {
		"group": "fromrp",
		"label": "member"
	},
	"R from person": {
		"group": "fromrp",
		"label": "person"
	},
	"R from relative": {
		"group": "fromrp",
		"label": "relative"
	},
	"R from spouse": {
		"group": "fromrp",
		"label": "spouse"
	},
	"R from writer": {
		"group": "fromrp",
		"label": "writer"
	},
	"R from bus route": {
		"group": "fromt",
		"label": "bus route"
	},
	"R from London bus route": {
		"group": "fromt",
		"label": "London bus route"
	},
	"R from NYC bus route": {
		"group": "fromt",
		"label": "NYC bus route"
	},
	"R from highway": {
		"group": "fromt",
		"label": "highway"
	},
	"R from highway in region": {
		"group": "fromt",
		"label": "highway in region"
	},
	"R from highway in region without possibilities": {
		"group": "fromt",
		"label": "highway in region without possibilities"
	},
	"R from duplicated article": {
		"group": "frommdm",
		"label": "duplicated article"
	},
	"R with history": {
		"group": "frommdm",
		"label": "with history"
	},
	"R from merge": {
		"group": "frommdm",
		"label": "merge"
	},
	"R from move": {
		"group": "frommdm",
		"label": "move"
	},
	"R with old history": {
		"group": "frommdm",
		"label": "with old history",
		"implies": "R unprintworthy"
	},
	"R avoided double redirect": {
		"group": "fromn",
		"label": "avoided double redirect"
	},
	"R from file metadata link": {
		"group": "fromn",
		"label": "file metadata link"
	},
	"R mentioned in hatnote": {
		"group": "fromn",
		"label": "mentioned in hatnote"
	},
	"R from shortcut": {
		"group": "fromn",
		"label": "shortcut",
		"conflict": "R from template shortcut"
	},
	"R from template shortcut": {
		"group": "fromn",
		"label": "template shortcut"
	},
	/* TO */
	"R to acronym": {
		"group": "togps",
		"label": "acronym"
	},
	"R to initialism": {
		"group": "togps",
		"label": "initialism"
	},
	"R to ASCII": {
		"group": "togps",
		"label": "ASCII-only title",
		"implies": "R unprintworthy"
	},
	"R to diacritic": {
		"group": "togps",
		"label": "diacritic"
	},
	"R to ligature": {
		"group": "togps",
		"label": "ligature",
		"implies": "R unprintworthy"
	},
	"R to plural": {
		"group": "togps",
		"label": "plural",
		"implies": "R unprintworthy"
	},
	"R to former name": {
		"group": "toan",
		"label": "former name"
	},
	"R to historic name": {
		"group": "toan",
		"label": "historic name"
	},
	"R to joint biography": {
		"group": "toan",
		"label": "joint biography"
	},
	"R to name with title": {
		"group": "toan",
		"label": "name with title"
	},
	"R to monotypic taxon": {
		"group": "toan",
		"label": "monotypic taxon"
	},
	"R to scientific name": {
		"group": "toan",
		"label": "scientific name"
	},
	"R to systematic name": {
		"group": "toan",
		"label": "systematic name"
	},
	"R to technical name": {
		"group": "toan",
		"label": "technical name"
	},
	"R to anchor": {
		"group": "tond",
		"label": "anchor",
		"implies": "R unprintworthy"
	},
	"R to anthroponymy page": {
		"group": "tond",
		"label": "anthroponymy page"
	},
	"R to disambiguation page": {
		"group": "tond",
		"label": "disambiguation page"
	},
	"R to list entry": {
		"group": "tond",
		"label": "list entry"
	},
	"R to section": {
		"group": "tond",
		"label": "section",
		"auto": "anchor"
	},
	"R to category namespace": {
		"group": "tons",
		"label": "category namespace (from other namespaces)",
		"target-namespace": wgNamespaceIds.category,
		"xnr-only": true
	},
	"R to draft namespace": {
		"group": "tons",
		"label": "draft namespace (from other namespaces)",
		"target-namespace": wgNamespaceIds.draft
	},
	"R to help namespace": {
		"group": "tons",
		"label": "help namespace",
		"target-namespace": wgNamespaceIds.help
	},
	"R to main namespace": {
		"group": "tons",
		"label": "main namespace (from other namespaces)",
		"target-namespace": 0,
		"xnr-only": true
	},
	"R to portal namespace": {
		"group": "tons",
		"label": "portal namespace",
		"target-namespace": wgNamespaceIds.portal
	},
	"R to project namespace": {
		"group": "tons",
		"label": "Wikipedia namespace",
		"target-namespace": wgNamespaceIds.project
	},
	"R to talk page": {
		"group": "tons",
		"label": "talk namespace (from non-talk namespaces)",
		"target-talk": true
	},
	"R to template namespace": {
		"group": "tons",
		"label": "template namespace (from other namespaces)",
		"target-namespace": wgNamespaceIds.template,
		"xnr-only": true
	},
	"R to user namespace": {
		"group": "tons",
		"label": "user namespace (from other namespaces)",
		"target-namespace": wgNamespaceIds.user
	},
	"R comics to list entry": {
		"group": "toc",
		"label": "comics to list entry"
	},
	"R comics naming convention": {
		"group": "toc",
		"label": "comics naming convention"
	},
	"R comics to section": {
		"group": "toc",
		"label": "comics to section"
	},
	"R to decade": {
		"group": "tom",
		"label": "decade article"
	},
	"R to related topic": {
		"group": "tom",
		"label": "related topic"
	},
	"R to subpage": {
		"group": "tom",
		"label": "subpage"
	},
	"R to subtopic": {
		"group": "tom",
		"label": "subtopic"
	},
	"R to TV episode list entry": {
		"group": "tom",
		"label": "TV episode list entry"
	},
	/* miscellanea */
	"R for convenience": {
		"group": "misc",
		"label": "for convenience"
	},
	"R with possibilities": {
		"group": "misc",
		"label": "might be worthy of own article",
		"conflict": [
			"R unprintworthy",
			"R from subtopic without possibilities",
			"R from highway in region without possibilities"
		]
	},
	"R printworthy": {
		"group": "misc",
		"label": "printworthy",
		"conflict": "R unprintworthy"
	},
	"R unprintworthy": {
		"group": "misc",
		"label": "unprintworthy",
		"conflict": "R printworthy"
	},

	"": void(0) // for convenience
};
delete redirectTemplates[""];

var api = new mw.Api();
var contentText = document.getElementById('mw-content-text');
var firstHeading = document.getElementById('firstHeading');
var redirMsg = contentText.getElementsByClassName('redirectMsg')[0];
var uiWrapper = el('div');
var edittoken = null;

function MarkupBlob(markup) {
	if (!markup) {
		this.target = '';
		this.rcatt = {};
		this.tail = '';
	} else
		this.parse(markup);
}

MarkupBlob.prototype.parse = function (markup) {
	var rdrx = /^#REDIRECT\s*\[\[\s*([^\|{}[\]]+?)\s*]]\s*/i;
	var tprx = /^\s*((([A-Za-z ]+)((?:\|(?:[^|{}]*|(([^|}]*)))+)*)))\s*/i;
	var m;

	if (!(m = rdrx.exec(markup)))
		throw new Error('Not a redirect');
	markup = markup.substr(m[0].length);
	this.target = m[1];

	this.rcatt = {};
	out: while ((m = tprx.exec(markup))) {
		var alias = normaliseTitle(m[1]);
		while (templateAliases[alias])
			alias = templateAliases[alias]; // hopefully there are no loops.
		
		if (alias === "This is a redirect") {
			var params = m[2].split('|');
			for (var j = 0; j < params.length; ++j) {
				if (!params[j])
					continue;
				if (params[j].indexOf('=') !== -1)
					break out;
				alias = normaliseTitle("R " + params[j]);
				while (templateAliases[alias])
					alias = templateAliases[alias]; // hopefully there are still no loops.
				if (alias in redirectTemplates)
					this.rcatt[alias] = true;
				else
					break out;
			}
		} else if (alias === "Redirect category shell") {
			var mm, rr = /(((.*?)))/g;
			while (mm = rr.exec(m[2])) {
				alias = normaliseTitle(mm[1]);
				while (templateAliases[alias])
					alias = templateAliases[alias];
				if (alias in redirectTemplates)
					this.rcatt[alias] = true;
			}
		} else if (alias in redirectTemplates) {
			if (m[2]) // TODO
				break;
			this.rcatt[alias] = true;
		} else {
			break;	
		}
		markup = markup.substr(m[0].length);
	}

	this.tail = markup;
};

MarkupBlob.prototype.toString = function () {
	var markup = '#REDIRECT [[' + this.target + ']] ';
	var tail = '';
	var wrapped = [];
	for (var key in this.rcatt) {
		if (this.rcatt[key])
			if ((wrapped.length < 6) && /^R\s+/.test(key))
				wrapped.push('((' + key + '))\n');
			else
				tail += '((' + key + '))\n';
		
	}
	if (wrapped.length)
		markup += "((Redirect category shell|\n" + wrapped.join("") + "))\n";
	markup += tail + '\n';
	markup += this.tail;
	return markup;
};

function buildTagList(rcatt) {
	function makeCheckBox(key) {
		return el('label', [
			el('input', null, {
				type: "checkbox",
				checked: (key in rcatt) ? "checked" : null,
			}, {
				change: function (ev) {
					rcatt[key] = this.checked;
				}
			}),
			' ',
			redirectTemplates[key].label
		], {
			"title": redirectTemplates[key].tooltip
		});
	}
	var list = el('dl', null, { "class": "tag-list" });
	var group = {};
	for (var key in templateGroups) {
		list.appendChild(el('dt', templateGroups[key]));
		list.appendChild(el('dd', group[key] = el('ul')));
	}
	for (var key in redirectTemplates) {
		var label = makeCheckBox(key);
		group[redirectTemplates[key].group].appendChild(el('li', label));
	}
	return list;
}

function buildEditingUI(mblob, saveCallback) {
	var statusbar;
	var needsCheck = true;
	var doSave;
	var uiLink, uiTarget;
	mblob = mblob || new MarkupBlob();
	
	function setStatus(status) {
		while (statusbar.firstChild)
			statusbar.removeChild(statusbar.firstChild);
		if (status) {
			if (typeof status === 'string')
				statusbar.appendChild(document.createTextNode(status));
			else {
				for (var j = 0; j < status.length; ++j) {
					if (typeof status[j] === 'string')
						statusbar.appendChild(document.createTextNode(status[j]));
					else
						statusbar.appendChild(status[j]);
				}
			}
		}
	}
	
	function inputChanged(ev) {
		/*jshint validthis:true */
		try {
			mblob.target = this.value;
			var t = new mw.Title(this.value);
			var frag = t.getFragment() ? '#' + normaliseAnchor(t.getFragment()) : '';
			uiLink.href = mw.util.getUrl(t.getPrefixedDb(), { redirect: "no" }) + frag;
			setStatus();
		} catch (e) {
			setStatus('Invalid title.');
			uiLink.href = 'javascript:void(0);';
		}
		needsCheck = true;
	}

	var uiStatusLine;
	var ui = el('form', [
		el('div', [
			el('ul', [
				el('li', [
					uiTarget = el('input', null, {
						'type': 'text',
						'class': 'redirectText',
						'value': mblob.target
					}, {
						'input': inputChanged,
						'change': inputChanged,
						'blur': function (ev) { // i would not have to write this, if it were not for jQuery. seriously.
							if (mblob.target === this.value)
								return;
							inputChanged.call(this, ev);
						}
					})
				])
			], { 'class': 'redirectText' })
		], { 'class': 'redirectMsg' }),
		buildTagList(mblob.rcatt),
		uiStatusLine = el('p', [
			statusbar = el('span', [], {
				'class': 'status-line'
			}),
			el('span', [
				link(["Statistics for this page"], 'https://tools.wmflabs.org/pageviews?project=en.wikipedia.org&pages=' + encodeURIComponent(mw.config.get('wgPageName'))),
				' • ',
				link(["WP:TMR"], mw.util.getUrl("Wikipedia:Template messages/Redirect pages")),
				' • ',
				link(["About Sagittarius+"], mw.util.getUrl("User:Sam Sailor/Scripts/Sagittarius+"))
			], {
				'style': 'float: right;'
			})
		])
	], {
		'action': 'javascript:void(0)',
		'class': 'kephir-sagittarius-editor'
	}, {
		'submit': function (ev) {
			ev.preventDefault();
			ui.doCheck(saveCallback);
		}
	});
	ui.statusLine = uiStatusLine;

	var sectCache = {};
	var $uiTarget = jQuery(uiTarget);
	$uiTarget.suggestions({
		submitOnClick: false,
		delay: 500,
		fetch: function (query) {
			$uiTarget.suggestions('suggestions', []);
			if (query.indexOf('#') !== -1) {
				var title = query.substr(0, query.indexOf('#'));
				var sect = query.substr(query.indexOf('#') + 1);

				if (sectCache[title]) {
					var normSect = normaliseAnchor(sect);
					$uiTarget.suggestions('suggestions',
						sectCache[title].filter(function (item) {
							var norm = normaliseAnchor(item.anchor);
							return norm.substr(0, normSect.length) === normSect;
						})
					);
					return;	
				}

				api.get({
					action: 'parse',
					page: title,
					prop: 'sections|properties',
					redirects: '1'
				}).then(function (result) {
					if (result.parse.redirects && result.parse.redirects.length) {
						// XXX
						return;
					}
					
					var disambig = false; // XXX

					var normSect = normaliseAnchor(sect);
					sectCache[title] = result.parse.sections.map(function (item) {
						return {
							anchor: item.anchor,
							title: title + '#' + decodeURIComponent(item.anchor.replace(/_/g, ' ').replace(/\.([0-9A-Fa-f][0-9A-Fa-f])/g, '%')), // XXX: hack
							disambig: disambig,
							toString: function () {
								return this.title;
							}
						};
					});

					$uiTarget.suggestions('suggestions',
						sectCache[title].filter(function (item) {
							var norm = normaliseAnchor(item.anchor);
							return norm.substr(0, normSect.length) === normSect;
						})
					);
				});
				return;
			}

			api.get({
				action: 'query',
				generator: 'allpages',
				gapprefix: query,
				gaplimit: 16,
				prop: 'info|pageprops',
			}).then(function (result) {
				var pglist = [];
				for (var pgid in result.query.pages) {
					var page = result.query.pages[pgid];
					pglist.push({
						title: page.title,
						pageid: page.pageid,
						disambig: page.pageprops && ('disambiguation' in page.pageprops),
						redirect: 'redirect' in page,
						toString: function () {
							return this.title;
						}
					});
				}
				$uiTarget.suggestions('suggestions', pglist);
			});
		},
		result: {
			render: function (item, content) {
				var elm = this[0];
				elm.appendChild(el('span', [item.title], {
					style: item.redirect ? 'font-style: italic' : ''
				}));
				if (item.disambig)
					elm.appendChild(el('small', [' (disambiguation page)']));
				if (item.redirect)
					elm.appendChild(el('small', [' (redirect)']));
			},
			
			select: function ($textbox) {
				var item = this.data('text');
				var textbox = $textbox[0];

				textbox.value = item.title;
				if (item.redirect) {
					api.get({
						action: 'query',
						pageids: item.pageid,
						redirects: '1'
					}).then(function (result) {
						var redir = result.query.redirects.pop();
						textbox.value = redir.to + (redir.tofragment ? '#' + redir.tofragment : '');
					});
				}

				return true;
			}
		}
	});

	ui.doCheck = function (callback) {
		var that = this;

		if (!/^\s*[^\|{}[\]]+\s*$/.test(mblob.target)) {
			setStatus(['Error: the target page name is invalid.']);
			return;
		}

		if (needsCheck) {
			var oldTarget = mblob.target;
			var normTarget;
			try {
				normTarget = new mw.Title(oldTarget);
			} catch (e) {
				setStatus(['"', oldTarget, '" is not a valid page name. Try again to proceed anyway.']);
				return;
			}

			setStatus(['Checking target validity...']);
			needsCheck = false;

			api.get({
				action: 'parse',
				page: oldTarget = mblob.target,
				prop: 'sections',
				redirects: '1'
			}, {
				success: function (result) {
					var m;
					if (result.error) {
						if (result.error.code === 'missingtitle') {
							setStatus([
								'Error: The target page "',
								link([normTarget.getPrefixedText()], mw.util.getUrl(normTarget.getPrefixedText(), { "class": "new" })),
								'" does not exist. Try again to proceed anyway.'
							]);
						} else {
							setStatus([
								'API error: "',
								result.error.info,
								'" [code: ', el('code', [result.error.code]), ']'
							]);
						}
						return;
					}

					if (result.parse.redirects && result.parse.redirects[0]) {
						var newTarget = result.parse.redirects[0].to + (result.parse.redirects[0].tofragment ? "#" + result.parse.redirects[0].tofragment : "");
						setStatus([
							'Error: The target page "',
							link([normTarget.getPrefixedText()], mw.util.getUrl(normTarget.getPrefixedText(), { redirect: "no" })),
							'" is already a redirect to "',
							link([newTarget], mw.util.getUrl(newTarget, { redirect: "no" })),
							'". Try again to proceed anyway, or ',
							link(['retarget this redirect to point there directly'], function () {
								uiTarget.value = mblob.target = newTarget +
									((!result.parse.redirects[0].tofragment && normTarget.fragment) ? '#' + normTarget.fragment : '');
								needsCheck = true;
							}),
							'.'
						]);
						return;
					}

					if (normTarget.fragment) { // we have a section link
						var sect = normaliseAnchor(normTarget.fragment);
						var isValidSect = false;

						var sectlist = result.parse.sections;
						for (var j = 0; j < sectlist.length; ++j) {
							if (sectlist[j].anchor === sect)
								isValidSect = true;
						}

						if (!isValidSect) {
							setStatus([
								'Error: The target page "',
								link([normTarget.getPrefixedText()], mw.util.getUrl(normTarget.getPrefixedText(), { redirect: "no" })),
								'" does not have a a section called "',
								normTarget.fragment,
								'". Try again to proceed anyway.'
							]);

							return;
						}
					}

					callback(setStatus);
				}
			});
			
			return;
		}

		callback(setStatus);
	};

	return ui;
}

if ((mw.config.get('wgAction') === 'view') && (mw.config.get('wgArticleId') === 0)) { // nonexistent page.
	uiWrapper.appendChild(el('div', [
		link(['Create a redirect'], function () {
			while (uiWrapper.hasChildNodes())
				uiWrapper.removeChild(uiWrapper.firstChild);
			var mblob = new MarkupBlob();
			var ui = buildEditingUI(mblob, function (setStatus) {
				setStatus(['Saving...']);
				api.post({
					action: 'edit',
					title: mw.config.get('wgPageName'),
					token: mw.user.tokens.get('editToken'),
					createonly: 1,
					summary: 'Redirecting to [[' + mblob.target + ']] ([[User:Sam Sailor/Scripts/Sagittarius+|Sagittarius+]])',
					text: mblob.toString()
				}, {
					success: function (result) {
						if (result.error) {
							setStatus([
								'API error: "',
								result.error.info,
								'" [code: ', el('code', [result.error.code]), ']'
							]);
							return;
						}
						setStatus(['Saved. Reloading page...']);
						if (/redirect=no/.test(location.href)) // XXX
							location.reload();
						else
							location.search = location.search ? location.search + '&redirect=no' : '?redirect=no';
					}
				});				
			});
			ui.statusLine.insertBefore(el('input', null, {
				type: 'submit',
				value: 'Save'
			}), ui.statusLine.firstChild);
			uiWrapper.appendChild(ui);
		}), ' from this page with Sagittarius+'
	], {
		"class": "kephir-sagittarius-invite"
	}));
	contentText.parentNode.insertBefore(uiWrapper, contentText);
} else if ((mw.config.get('wgAction') === 'view') && mw.config.get('wgIsRedirect') && redirMsg) {
	// start editor immediately
	uiWrapper.appendChild(el('div', ['Loading page source…'], {
		"class": "kephir-sagittarius-loading"
	}));
	contentText.insertBefore(uiWrapper, contentText.firstChild);
	api.get({
		action: 'query',
		prop: 'info|revisions',
		rvprop: 'timestamp|content',
		pageids: mw.config.get('wgArticleId'),
		rvstartid: mw.config.get('wgRevisionId'),
		rvlimit: 1,
		rvdir: 'older',
		intoken: 'edit',
	}, {
		success: function (result) {
			if (result.error) {
				uiWrapper.appendChild(el('div', [
					'API error: "',
					result.error.info,
					'" [code: ', el('code', [result.error.code]), ']. Reload to try again.'
				], {
					"class": "kephir-sagittarius-error"
				}));
				return;
			}
			while (uiWrapper.hasChildNodes())
				uiWrapper.removeChild(uiWrapper.firstChild);
			var page = result.query.pages[mw.config.get('wgArticleId')];
			var mblob;
			var token = page.edittoken;
			try {
				mblob = new MarkupBlob(page.revisions[0]['*']);
			} catch(e) {
				uiWrapper.appendChild(el('div', ['Error: unable to parse page. Edit the source manually.'], {
					"class": "kephir-sagittarius-error"
				}));
				return;
			}
			redirMsg.parentNode.removeChild(redirMsg);
			var ui = buildEditingUI(mblob, function (setStatus) {
				setStatus(['Saving...']);
				api.post({
					action: 'edit',
					title: mw.config.get('wgPageName'),
					basetimestamp: page.revisions[0].timestamp,
					token: mw.user.tokens.get('editToken'),
					summary: 'Redirecting to [[' + mblob.target + ']] ([[User:Sam Sailor/Scripts/Sagittarius+|Sagittarius+]])',
					text: mblob.toString()
				}, {
					success: function (result) {
						if (result.error) {
							setStatus([
								'API error: "',
								result.error.info,
								'" [code: ', el('code', [result.error.code]), ']'
							]);
							return;
						}
						setStatus(['Saved. Reloading page...']);
						if (/redirect=no/.test(location.href)) // XXX
							location.reload();
						else
							location.search = location.search ? location.search + '&redirect=no' : '?redirect=no';
					}
				});				
			});
			ui.statusLine.insertBefore(el('input', null, {
				type: 'submit',
				value: 'Save'
			}), ui.statusLine.firstChild);
			uiWrapper.appendChild(ui);
		}
	});
} else if ((mw.config.get('wgPageContentModel') === 'wikitext') && ((mw.config.get('wgAction') === 'edit') || (mw.config.get('wgAction') === 'submit'))) {
	if (mw.util.getParamValue('section'))
		return;
	var editform = document.getElementById('editform');

	if (editform.wpTextbox1.readOnly)
		return;

	var uiPivot = document.getElementsByClassName('wikiEditor-ui')[0];

	var ui, mblob;
	firstHeading.appendChild(document.createTextNode(' '));
	firstHeading.appendChild(link(['♐'], function () {
		if (ui && ui.parentNode)
			ui.parentNode.removeChild(ui);

		try {
			mblob = new MarkupBlob(editform.wpTextbox1.value);
		} catch (e) {
			alert("Error: unable to parse page. This page is probably not a redirect.");
			return;
		}

		ui = buildEditingUI(mblob, function () {
			editform.wpSummary.value = 'Redirecting to [[' + mblob.target + ']] ([[User:Sam Sailor/Scripts/Sagittarius+|Sagittarius+]])';
			editform.wpTextbox1.value = mblob.toString();
			mblob = null;
			ui.style.display = 'none';
			uiPivot.style.display = '';
		});
		ui.style.display = 'none';
		ui.statusLine.insertBefore(el('input', null, {
			type: "button",
			value: "Cancel",
		}, {
			click: function () {
				mblob = null;
				ui.style.display = 'none';
				uiPivot.style.display = '';				
			}
		}), ui.statusLine.firstChild);
		ui.statusLine.insertBefore(el('input', null, {
			type: "submit",
			value: "Check"
		}), ui.statusLine.firstChild);
		uiPivot.parentNode.insertBefore(ui, uiPivot);
		uiPivot.style.display = 'none';
		ui.style.display = '';
	}, {
		"class": "kephir-sagittarius-editlink",
		"title": "Edit this redirect with Sagittarius+"
	}));

	var submitButton;
	var inputs = editform.getElementsByTagName('input');
	for (var i = 0; i < inputs.length; ++i) {
		inputs[i].addEventListener('click', function (ev) {
			submitButton = this;
		}, false);
	}

	editform.addEventListener('submit', function (ev) {
		if (submitButton !== editform.wpSave)
			return;
		if (mblob) {
			ev.preventDefault();
			ev.stopImmediatePropagation();
			ui.doCheck(function (setStatus) {
				setStatus(['Proceeding with saving...']);
				editform.wpTextbox1.value = mblob.toString();
				editform.wpSummary.value = 'Redirecting to [[' + mblob.target + ']] ([[User:Sam Sailor/Scripts/Sagittarius+|Sagittarius+]])';
				mblob = null;
				editform.submit();
			});
		}
	}, false);
}

if (!window.kephirSagittariusFollowCategoryRedirects)
if ((mw.config.get('wgAction') === 'view') && (mw.config.get('wgNamespaceNumber') === wgNamespaceIds.category)) {
	var pagesList = document.getElementById('mw-pages').getElementsByClassName('mw-redirect');
	for (var i = 0; i < pagesList.length; ++i) {
		pagesList[i].href += '?redirect=no';
	}
}

});
/*</source>
 
[[:Category:Wikipedia scripts]]
*/