Content deleted Content added
«+"as per Wikipedia:WikiProject Location Format", "requires" → "depends", "addlilink" → "wikitabs"» |
«279 words changed» use autoedit.js |
||
Line 1:
// [[User:Quarl/location_canonicalize.js]] - canonicalizes ___location WikiLinks
// as per [[Wikipedia:WikiProject Location Format]] // Example: [[Seattle, Washington]] becomes [[Seattle, Washington|Seattle]], [[Washington]], [[USA]].
// depends: wikipage.js, util.js, wikitabs.js, wikiedit.js, autoedit.js
// quarl 2006-01-22 initial version
// quarl 2006-02-08 refactored to autoedit.js
//<pre><nowiki>
location_canonicalize = new
'LocZ', 'ca-locz', 'Canonicalize ___location wikilinks',
'Location canonicalization');
location_canonicalize.initData = function() {
var CountryData = function(states, link_country, regexp_country) {
this.states = states;
Line 151 ⟶ 69:
}
var inputs = [];
// special case for hat link, if there is one
if (input.match(/^: *''.*/)) {
var infobox = RegExp.lastMatch;
var right = RegExp.rightContext;
inputs.push(infobox);
input = right;
}
// special case the first Infobox, if there is one
if (input.match(/^(?:{{Infobox(?:.|\n)*?\n}}|{\|(?:.|\n)*?\n\|})/i)) {
// var left = RegExp.leftContext;
var infobox = RegExp.lastMatch;
var right = RegExp.rightContext;
// treat the infobox separately, so that USA links get added to main
// article.
inputs.push(infobox);
input = right;
}
inputs.push(input);
return inputs;
}
this.buildRegExp = function() {
return /\[\[ *(?:([^|\]]+?) *\| *)?([^\]]+?) *\]\]/;
}
this.replaceRegExp = function(d, m) {
var wlink = m[1] || m[2];
var wtext = m[2];
// non-main namespace - usually a category
if (wtext.match(/:/)) return
if (wlink != wtext) return;
Line 179 ⟶ 132:
if (!wfull) continue;
if (d.left.match(c.regexp_country)) {
// Already mentioned country. Delete redundant subsequent
// country links
if (d.right.match(c.regexp_country_sq)) {
d.right = RegExp.rightContext;
// only count as a change if we actually delete it!
++changes;
Line 189 ⟶ 142:
} else {
// Haven't mentioned country earlier
if (d.right.match(c.regexp_country_sq)) {
// it's
} else {
// not there; add it.
Line 199 ⟶ 152:
if (changes) {
}
return;
}
return
}
|