Content deleted Content added
comma |
〈176 words changed〉new org w/ namespaces; add USA to lone state links |
||
Line 9:
//<pre><nowiki>
location_canonicalize = new Object();
location_canonicalize.run = function() {
location_canonicalize.initData();
wikiPage.getEditorAsync(location_canonicalize.edit);
}
location_canonicalize.edit = function(editor) {
// make changes
Line 102 ⟶ 55:
}
location_canonicalize.initData = function() {
if (this.init) return;
this.init = true;
this.USstates = [
'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado',
'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho',
'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine',
'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi',
'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey',
'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio',
'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina',
'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia',
'Washington', 'West Virginia', 'Wisconsin', 'Wyoming' ];
this.regexp_USsubstate = (
new RegExp('^([^,]+), *(' +
location_canonicalize_USstates.join('|') +
')$'));
this.regexp_USstate = (
new RegExp('^(?:' + location_canonicalize_USstates.join('|') +
')$'));
}
location_canonicalize.wikilink = function(wlink, wtext, left, right) {
// non-main namespace - usually a category
if (wtext.match(/:/)) return null;
if (wlink == wtext &&
wtext.match(location_canonicalize.regexp_USsubstate))
{
var city = RegExp.$1, state = RegExp.$2;
var wfull = '[[' + wtext + '|' + city + ']]';
// only add link to state and country if we haven't yet mentioned them.
if (!left.match('[['+state+']]')) {
wfull += ', [['+state+']]';
if (!left.match(/\[\[(?:United[ _]States(?:[ _][^|\]]+?)?|USA)(?:\|[^|\]]+?|)?\]\]/)) {
wfull += ', [[United States|USA]]';
}
}
// get rid of any redundant subsequent [[USA]] link
right = right.replace(/^, *\[\[(?:United[ _]States(?:[ _][^|\]]+?)?|USA)(?:\|[^|\]]+?|)?\]\]/, '');
return { wfull: wfull, left: left, right: right};
}
if (wlink == wtext && wtext.match(location_canonicalize.regexp_USstate)) {
// state link -- just make sure there's a [[USA]] link if necessary
if (!left.match(/\[\[(?:United[ _]States(?:[ _][^|\]]+?)?|USA)(?:\|[^|\]]+?|)?\]\]/)) {
var wfull = '[['+wtext+']]';
wfull += ', [[United States|USA]]';
// get rid of any redundant subsequent [[USA]] link
right = right.replace(/^, *\[\[(?:United[ _]States(?:[ _][^|\]]+?)?|USA)(?:\|[^|\]]+?|)?\]\]/, '');
return { wfull: wfull, left: left, right: right};
}
return null;
}
// TODO: Canada, India, etc.
return null;
}
location_canonicalize.load = function() {
if (wikiPage.nsSpecialP) return;
addTab('javascript:location_canonicalize.run()', 'locz', 'ca-locz', 'Canonicalize ___location wikilinks');
}
addOnloadHook(
//</nowiki></pre>
|