User:Plastikspork/spork.js

// SporkSpork function SporkSpork { document.forms.editform.wpSummary.value = "Format" + " " + "page";

var txt = document.forms.editform.wpTextbox1;

txt.value = txt.value.replace(/[\t ]*\|[\t ]*([\r\n])[\|]*([\t ]*[^{}\[\]<>\|=]*=)/gi,'$1|$2'); txt.value = txt.value.replace(/[\t ]*\|[\t ]*([\r\n]|)[\t ]*(\}\})/gi,'$1$2'); txt.value = txt.value.replace(/[\t ]*<.\-\-[^<>]*\-\->[\t ]*[\r\n]\|[\t ]*free_name[\t ]*=[\t ]*[\r\n]\|[\t ]*free_value[\t ]*=[\t ]*[\r\n]/gim, '');

txt.value = txt.value.replace(/(\{\{conv)infobox\|[ ]*([0-9\.]*)[ ]*\|[ ]*([a-z]+)\|[ ]*\|([a-z]+)[ ]*(\}\})/gim, '$1ert|$2|$3|$4|abbr=on$5');

txt.value = txt.value.replace(/(\|[\t ]*(?:total|national|youth|manager|)(?:years|caps|caps\(goals\)|clubs|goals))1([\t ]*=)((?:[^\|\[\]<>]|\[\^\[\*\]\])*)<[\/ \t]*br[\/ \t]*>/gi, '$11$2$3 $12$2'); txt.value = txt.value.replace(/(\|[\t ]*(?:total|national|youth|manager|)(?:years|caps|caps\(goals\)|clubs|goals))2([\t ]*=)((?:[^\|\[\]<>]|\[\^\[\*\]\])*)<[\/ \t]*br[\/ \t]*>/gi, '$12$2$3 $13$2'); txt.value = txt.value.replace(/(\|[\t ]*(?:total|national|youth|manager|)(?:years|caps|caps\(goals\)|clubs|goals))3([\t ]*=)((?:[^\|\[\]<>]|\[\^\[\*\]\])*)<[\/ \t]*br[\/ \t]*>/gi, '$13$2$3 $14$2'); txt.value = txt.value.replace(/(\|[\t ]*(?:total|national|youth|manager|)(?:years|caps|caps\(goals\)|clubs|goals))4([\t ]*=)((?:[^\|\[\]<>]|\[\^\[\*\]\])*)<[\/ \t]*br[\/ \t]*>/gi, '$14$2$3 $15$2'); txt.value = txt.value.replace(/(\|[\t ]*(?:total|national|youth|manager|)(?:years|caps|caps\(goals\)|clubs|goals))5([\t ]*=)((?:[^\|\[\]<>]|\[\^\[\*\]\])*)<[\/ \t]*br[\/ \t]*>/gi, '$15$2$3 $16$2'); txt.value = txt.value.replace(/(\|[\t ]*(?:total|national|youth|manager|)(?:years|caps|caps\(goals\)|clubs|goals))6([\t ]*=)((?:[^\|\[\]<>]|\[\^\[\*\]\])*)<[\/ \t]*br[\/ \t]*>/gi, '$16$2$3 $17$2'); txt.value = txt.value.replace(/(\|[\t ]*(?:total|national|youth|manager|)(?:years|caps|caps\(goals\)|clubs|goals))7([\t ]*=)((?:[^\|\[\]<>]|\[\^\[\*\]\])*)<[\/ \t]*br[\/ \t]*>/gi, '$17$2$3 $18$2'); txt.value = txt.value.replace(/(\|[\t ]*(?:total|national|youth|manager|)(?:years|caps|caps\(goals\)|clubs|goals))8([\t ]*=)((?:[^\|\[\]<>]|\[\^\[\*\]\])*)<[\/ \t]*br[\/ \t]*>/gi, '$18$2$3 $19$2'); txt.value = txt.value.replace(/(\|[\t ]*(?:total|national|youth|manager|)(?:years|caps|caps\(goals\)|clubs|goals))9([\t ]*=)((?:[^\|\[\]<>]|\[\^\[\*\]\])*)<[\/ \t]*br[\/ \t]*>/gi, '$19$2$3 $110$2'); txt.value = txt.value.replace(/(\|[\t ]*(?:total|national|youth|manager|)(?:years|caps|caps\(goals\)|clubs|goals))10([\t ]*=)((?:[^\|\[\]<>]|\[\^\[\*\]\])*)<[\/ \t]*br[\/ \t]*>/gi, '$110$2$3 $111$2');

txt.value = txt.value.replace(/([^{])[ ]*•[ ]*/gi, '$1\{\{•w\}\} '); txt.value = txt.value.replace(/(list[0-9][ ]*=)[ ]*(\[\[)/g, '$1 \{\{nowrap begin\}\}$2'); txt.value = txt.value.replace(/(\{\{nowrap begin\}\}(?:\{\{•w\}\}|[^{}\r\n])*)([\r\n])/g, '$1\{\{nowrap end\}\}$2'); txt.value = txt.value.replace(/]*>/gi, ''); txt.value = txt.value.replace(/<\/span>/gi, '');

txt.value = txt.value.replace(/Infobox[_ ]+locomotive/gi, 'Infobox locomotive'); txt.value = txt.value.replace(/(leading|trailing|driver)size   /g, '$1diameter'); txt.value = txt.value.replace(/(leading|trailing|driver)size[ ]*/g, '$1diameter ');

txt.value = txt.value.replace(/= [ ]*/g, '= '); txt.value = txt.value.replace(/ [ ]*$/g, ''); txt.value = txt.value.replace(/\|[ ]*coords[ ]*=/gi, '| coordinates = ');

txt.value = txt.value.replace(/(\{\{)[_ ]*([Ii]nfobox[_ ]+District[_ ]+Peru)/gi, '$1subst:$2/sandbox\n| coordinates ='); txt.value = txt.value.replace(/(map[ ]*=[ ]*)\[\[(Image|File):([^\|\]\[]*)/gi, '$1$3|');

txt.value = txt.value.replace(/((?:area|density|pop)[ ]*=[ ]*)\{\{[_ ]*[Cc]ommas[_ ]*\|([^{}\|]*)[ ]*\}\}/g, '$1$2'); txt.value = txt.value.replace(/((?:area|density|pop)[ ]*=[ ]*[0-9]+)[\., ]([0-9][0-9][0-9])/g, '$1$2'); txt.value = txt.value.replace(/((?:area|density|pop)[ ]*=[ ]*[0-9]+)\,([0-9][0-9]?[^0-9])/g, '$1.$2'); txt.value = txt.value.replace(/(pop[ ]*=[ ]*[0-9]+[ ]*)([^0-9\r\n])/g, '$1\n|population_as_of=$2'); txt.value = txt.value.replace(/(population_as_of[ ]*=[ ]*)\(([^\(\)\r\n]*)\)/g, '$1$2'); txt.value = txt.value.replace(/(population_as_of[ ]*=[ ]*[^\(\)\r\n]*est)imate/g, '$1.'); txt.value = txt.value.replace(/(coordinates[ ]*=[ ]*)([\r\n](?:.|[\r\n])*)(\{\{coord[^{}]*display[ ]*=[ ]*title[^{}]*\}\})/gim, '$1$3$2'); txt.value = txt.value.replace(/((?:province|region)[ ]*=[ ]*\[\[)([^\[\]\|]*) (Province|Region)[ ]*(\]\])/gi, '$1$2 $3|$2$4'); txt.value = txt.value.replace(/\|[ ]*web[ ]*=[ ]*(www\.)([^ \|<>\[\]\r\n]*)/gi, '|website = $2');

txt.value = txt.value.replace(/\|latd[ ]*=[ ]*\|latm[ ]*=[ ]*\|lats[ ]*=[ ]*\|latNS[ ]*=[ ]*[\r\n]\|longd[ ]*=[ ]*\|longm[ ]*=[ ]*\|longs[ ]*=[ ]*\|longEW[ ]*=[ ]*([\r\n])/gim, '| coordinates = $1');

txt.value = txt.value.replace(/\{\{coord[ ]*\|[ ]*(-?[0-9]+\.[0-9]+)[ ]*\|[ ]*(-?[0-9]+\.[0-9]+)[ ]*(?:\|[ ]*[^0-9 {}][^{}]*\}\}|\}\})[\r\n]((?:.|[\r\n])*)coordinates[ ]*=/gim, '$3 latd = $1 | longd = $2');

txt.value = txt.value.replace(/(\{\{[Cc]oord)[ ]*(\|)[ ]*latd[ ]*=[ ]*/gi, '$1$2'); txt.value = txt.value.replace(/(\{\{[Cc]oord\|[0-9]+)[ ]*(\|)[ ]*latm[ ]*=[ ]*/gi, '$1$2'); txt.value = txt.value.replace(/(\{\{[Cc]oord\|[0-9]+\|[0-9]+)[ ]*(\|)[ ]*lats[ ]*=[ ]*/gi, '$1$2'); txt.value = txt.value.replace(/(\{\{[Cc]oord\|[0-9]+\|[0-9]+\|[0-9]+)[ ]*(\|)[ ]*latNS[ ]*=[ ]*/gi, '$1$2'); txt.value = txt.value.replace(/(\{\{[Cc]oord\|[0-9]+\|[0-9]+\|[0-9]+\|[NS])[ ]*(\|)[ ]*longd[ ]*=[ ]*/gi, '$1$2'); txt.value = txt.value.replace(/(\{\{[Cc]oord\|[0-9]+\|[0-9]+\|[0-9]+\|[NS]\|[0-9]+)[ ]*(\|)[ ]*longm[ ]*=[ ]*/gi, '$1$2'); txt.value = txt.value.replace(/(\{\{[Cc]oord\|[0-9]+\|[0-9]+\|[0-9]+\|[NS]\|[0-9]+\|[0-9]+)[ ]*(\|)[ ]*longs[ ]*=[ ]*/gi, '$1$2'); txt.value = txt.value.replace(/(\{\{[Cc]oord\|[0-9]+\|[0-9]+\|[0-9]+\|[NS]\|[0-9]+\|[0-9]+\|[0-9]+)[ ]*(\|)[ ]*longEW[ ]*=[ ]*/gi, '$1$2'); txt.value = txt.value.replace(/(\{\{[Cc]oord\|[0-9]+\|[0-9]+\|[0-9]+\|[NS]\|[0-9]+\|[0-9]+\|[0-9]+\|[EW])(\}\})/gi, '$1|$2');

txt.value = txt.value.replace(/((?: |[\r\n])*==[ ]*References[ ]*==[\r\n]*)\*?[ ]*(\{\{(?:|cite[_ ]+)gnis[^{}]*\}\})/gim, ' $1\{\{reflist\}\}');

// Template alignment txt.value = txt.value.replace(/\|[ ]*(\}\})[ ]*([\r\n])/g, '$1$2');

txt.value = txt.value.replace(/lat_long[ ]*=[ ]*/gi, 'coordinates = ');

if(0) { txt.value = spork_coord(txt.value); }

if( txt.value.search( /\{\{[_ ]*[Cc]oord[_ ]*\|[_ ]*[0-9-][ ]*/ ) >= 0 ) { txt.value = txt.value.replace(/(coordinates[ ]*=[ ]*)[^{}\[\]\|\r\n]*/gi, '$1'); } txt.value = txt.value.replace(/(coordinates[ ]*=[ ]*)([\r\n]?\|(?:[\r\n]|.)*)(\{\{[_ ]*[Cc]oor[^{}]*title[^{}]*\}\})[\r\n]?/gm, '$1$3$2'); txt.value = txt.value.replace(/(\{\{[_ ]*[Cc]oor[^{}]*title[^{}]*\}\})[\r\n]?((?:[\r\n]|.)*coordinates[ ]*=[ ]*)([\r\n]?\|)/gm, '$2$1$3'); txt.value = txt.value.replace(/(coordinates[ ]*=[ ]*)\{\{[Cc]oord missing[^{}]*\}\}/g, '$1');

if ( txt.value.search( /\|[ ]*longd[ ]*=[ ]*[0-9]/ ) >= 0 ) { if ( txt.value.search( /\{\{[Cc]oord/ ) >= 0 ) { txt.value = txt.value.replace(/\{\{[_ ]*[Cc]oord[^{}]*\}\}[\r\n]/g, ''); txt.value = txt.value.replace(/(\|[ ]*longd.*)([\r\n])/gi, '$1$2| coordinates_display = title$2'); } }

if ( txt.value.search( /\{\{[_ ]*infobox[_ ]+(?:airport|dam|islands)/i ) < 0 ) { txt.value = txt.value.replace(/coordinates[ ]*=[ ]*\{\{[_ ]*[Cc]oord[ ]*\|[ ]*(-?[0-9]+\.[0-9]+)[ ]*\|[ ]*(-?[0-9]+\.[0-9]+)[ ]*(?:\|[ ]*[^0-9{}\|][^{}]*\}\}|\}\})/g, 'latd = $1|longd = $2'); txt.value = txt.value.replace(/coordinates[ ]*=[ ]*\{\{[_ ]*[Cc]oord[ ]*\|[ ]*([0-9]*)[ ]*\|[ ]*([0-9]*)[ ]*\|[ ]*([0-9\.]*)[ ]*\|[ ]*([NS])[ ]*\|[ ]*([0-9]*)[ ]*\|[ ]*([0-9]*)[ ]*\|[ ]*([0-9\.]*)[ ]*\|[ ]*([EW])[ ]*\|[ ]*([^\|{}]*)[ ]*[^{}]*\}\}/g, 'latd = $1|latm = $2|lats = $3|latNS = $4\r|longd = $5|longm = $6|longs = $7|longEW = $8\r|coordinates_type = $9\r|coordinates_display = title'); txt.value = txt.value.replace(/coordinates[ ]*=[ ]*\{\{[_ ]*[Cc]oord[ ]*\|[ ]*([0-9]*)[ ]*\|[ ]*([0-9\.]*)[ ]*\|[ ]*([NS])[ ]*\|[ ]*([0-9]*)[ ]*\|[ ]*([0-9\.]*)[ ]*\|[ ]*([EW])[ ]*\|[ ]*([^\|{}]*)[ ]*[^{}]*\}\}/g, 'latd = $1|latm = $2|lats = |latNS = $3\r|longd = $4|longm = $5|longs = |longEW = $6\r|coordinates_type = $7\r|coordinates_display = title'); }

txt.value = txt.value.replace(/\{\{nowrap\|([^{} ]*) ([^{} ]*)\}\}/gi, '$1 $2'); txt.value = txt.value.replace(/\{\{nowrap\|([^{} ]*)\}\}/gi, '$1'); txt.value = txt.value.replace(/(\|[ ]*latd.*)(\|[ ]*longd.*)(\|[ ]*coordinates_type.*)(\|[ ]*coordinates_display.*)([\r\n])/gi, '$1$5$2$5$3$5$4$5');

if( txt.value.search( /\*?[ ]*\{\{[ _]*Mapit-US-cityscale\|([^\|{}]*\|[^\|{}]*)\}\}/ ) >= 0 ) { m = txt.value.match(/\*?[ ]*\{\{[ _]*Mapit-US-cityscale\|([^\|{}]*\|[^\|{}]*)\}\}/); txt.value = '\{\{coord|' + m[1].toString + '|region:US_type:landmark|format=dms|display=title\}\}\n' + txt.value; txt.value = txt.value.replace(/\*?[ ]*\{\{[ _]*Mapit-US-cityscale\|([^\|{}]*\|[^\|{}]*)\}\}[ ]*[\r\n]?/, ''); } txt.value = txt.value.replace(/(coordinates_type[ ]*=[ ]*)display=[a-z]+/gi, '$1region:US_type:landmark');

txt.value = txt.value.replace(/==[ ]*External links[ ]*==(?:[\r\n]| |\*[ ]*[\r\n])*([\r\n]\[\[Category|[\r\n]\{\{[^{}]*(?:County|Census Area|Parish))/, '$1'); txt.value = txt.value.replace(/ \([ ]*-?[0-9\.]+,[ ]*-?[0-9\.]+[ ]*\) and has/, '');

if( txt.value.search( /(?:= 0) { if( txt.value.search( /(?:{reflist|<references)/gi ) < 0 ) { txt.value = txt.value.replace(/(==[ ]*References[^\r\n]*==)/i, '$1\n\{\{reflist\}\}'); }    if( txt.value.search( /(?:{reflist|<references)/gi ) < 0 ) { txt.value = txt.value.replace(/(==[ ]*External[^\r\n]*==)/i, '== References ==\n\{\{reflist\}\}\n\n$1'); }    if( txt.value.search( /(?:{reflist|<references)/gi ) < 0 ) { txt.value = txt.value.replace(/(==[ ]*See also[^\r\n]*==)/i, '$1\n\n== References ==\n\{\{reflist\}\}\n'); }    if( txt.value.search( /(?:{reflist|<references)/gi ) < 0 ) { txt.value = txt.value.replace(/([\r\n]\{\{[^{}\|]*\}\}[\r\n])/i, '\n== References ==\n\{\{reflist\}\}\n\n$1'); }    if( txt.value.search( /(?:{reflist|<references)/gi ) < 0 ) { txt.value = txt.value + '\{\{reflist\}\}\n'; } }

// txt.value = txt.value.replace(/(\|[ ]*(?:lat|long))(d|m|s|NS|EW)/, '$1_$2'); // txt.value = txt.value.replace(/(\|[ ]*(?:lat|long))(d|m|s|NS|EW)/, '$1_$2'); // txt.value = txt.value.replace(/(\|[ ]*(?:lat|long))(d|m|s|NS|EW)/, '$1_$2'); // txt.value = txt.value.replace(/(\|[ ]*(?:lat|long))(d|m|s|NS|EW)/, '$1_$2'); // txt.value = txt.value.replace(/(\|[ ]*(?:lat|long))(d|m|s|NS|EW)/, '$1_$2'); // txt.value = txt.value.replace(/(\|[ ]*(?:lat|long))(d|m|s|NS|EW)/, '$1_$2'); // txt.value = txt.value.replace(/(\|[ ]*(?:lat|long))(d|m|s|NS|EW)/, '$1_$2'); // txt.value = txt.value.replace(/(\|[ ]*(?:lat|long))(d|m|s|NS|EW)/, '$1_$2'); txt.value = txt.value.replace(/(\|[ ]*)(leader_name)([ ]*=)([ ]*(?:\[\^\[\*\]\]|[^\[\]\|]*)) \((\[\^\[\*\]\])\)/gi, '$1$2$3$4\n|leader_party$3 $5'); txt.value = txt.value.replace(/([^\r\n])(\|[ ]*subdivision_type[0-9])/gi, '$1\n$2'); txt.value = txt.value.replace(/([^\r\n])(\|[ ]*subdivision_type[0-9])/gi, '$1\n$2'); txt.value = txt.value.replace(/(\|[ ]*subdivision_type[1-9][^\r\n]*)([\r\n])(\|[ ]*subdivision_(?:name|type)[ ]*=[^\r\n]*)/gim, '$3$2$1'); txt.value = txt.value.replace(/(\|[ ]*subdivision_type[2-9][^\r\n]*)([\r\n])(\|[ ]*subdivision_(?:name|type)(?:1|)[ ]*=[^\r\n]*)/gim, '$3$2$1'); txt.value = txt.value.replace(/\{\{official\|(http:\/\/www\.)([^{}]*)(\/?)\}\}/gi, '[$1$2$3 $2]'); txt.value = txt.value.replace(/(\{\{)(Demography 7col)/gi,'$1subst:$2|source= INE (Spain)'); document.forms.editform.wpMinoredit.checked = true; document.forms.editform.wpDiff.click; // document.forms.editform.wpPreview.click; // document.forms.editform.wpSave.click; }

function spork_deg_to_dms(str) { var tmp = Math.abs(parseFloat(str));

var d = Math.floor(tmp); tmp = 60*(tmp - d); var m = Math.floor(tmp); tmp = 60*(tmp - m); var s = Math.round(tmp);

if( s >= 60 ) { s = s - 60; m = m + 1; } if( m >= 60 ) { m = m - 60; d = d + 1; }

if( parseFloat(str) < 0 ) { d = -1*d; }

return d + '|' + m + '|' + s; }

function spork_coord(str) {

str = str.replace(/(\{\{[_ ]*[Cc]oord[^{}]*)(\|[ ]*display[^\|{}]*)(\|[^{}]*)(\}\})/g, '$1$3$2$4'); str = str.replace(/(\{\{[_ ]*[Cc]oord[^{}]*)\|[ ]*format[ ]*=[ ]*dms/g, '$1'); str = str.replace(/(\{\{[_ ]*[Cc]oord[_ ]*\|)[ ]*([0-9]+\.?[0-9]*)[ ]*\|[ ]*([0-9]+\.?[0-9]*)[ ]*(\}\}|\|[ ]*[a-z]|\|[ ]*\}\})/g, '$1$2|N|$3|E$4'); str = str.replace(/(\{\{[_ ]*[Cc]oord[_ ]*\|)[ ]*-([0-9]+\.?[0-9]*)[ ]*\|[ ]*([0-9]+\.?[0-9]*)[ ]*(\}\}|\|[ ]*[a-z]|\|[ ]*\}\})/g, '$1$2|S|$3|E$4'); str = str.replace(/(\{\{[_ ]*[Cc]oord[_ ]*\|)[ ]*([0-9]+\.?[0-9]*)[ ]*\|[ ]*-([0-9]+\.?[0-9]*)[ ]*(\}\}|\|[ ]*[a-z]|\|[ ]*\}\})/g, '$1$2|N|$3|W$4'); str = str.replace(/(\{\{[_ ]*[Cc]oord[_ ]*\|)[ ]*-([0-9]+\.?[0-9]*)[ ]*\|[ ]*-([0-9]+\.?[0-9]*)[ ]*(\}\}|\|[ ]*[a-z]|\|[ ]*\}\})/g, '$1$2|S|$3|W$4');

var m = str.match(/\{\{[_ ]*[Cc]oord[_ ]*\|[ ]*-?[0-9\.]+[ ]*\|[ ]*[NS][ ]*\|[ ]*-?[0-9\.]+[ ]*\|[ ]*[EW][^{}]*\}\}/g); if (m) { // For each coord template on the list for (var i = 0; i < m.length; i++) { if( m[i].toString.search(/format=dms/) < 0 ) { var n_arr = m[i].toString.match(/\{\{[_ ]*[Cc]oord[_ ]*\|[ ]*(-?[0-9\.]+)[ ]*(\|[ ]*[NS])[ ]*\|[ ]*(-?[0-9\.]+)[ ]*(\|[ ]*[EW])([^{}]*\}\})/); var c = n_arr[0];  // Contains the coord template var lat = n_arr[1]; // Contains the latitude var NS = n_arr[2]; // Contains the NS      var lon = n_arr[3]; // Contains the longitude var EW = n_arr[4]; // Contains the EW      var dis = n_arr[5]; // Contains the type, display, ... lat = spork_deg_to_dms(lat); lon = spork_deg_to_dms(lon); if( lat.search(/\|0$/) >= 0 && lon.search(/\|0$/) >= 0 ) { lat = lat.replace(/\|0$/, ''); lon = lon.replace(/\|0$/, ''); }     c = c.replace(/([\|\(\)])/g, '\\$1'); var nr = new RegExp(c, "g"); str = str.replace(nr, "\{\{coord|" + lat + NS + "|" + lon + EW + dis); }   }  }  return str; }

function spork_mapit(str) {

str = str.replace(/(?:[Gg]eolinks|[Mm]apit)-US-(?:city|street)scale/g, 'Mapit-US-cityscale'); str = str.replace(/, and it is located at \{\{[_ ]*coord[^{}]*\}\} \([ ]*-?[0-9\.]*,[ ]*-[0-9\.]*[ ]*\)/, ''); str = str.replace(/([0-9])[\.\r\n ]*\[(http[^\[\]]*downloadzipcode[^\[\]]*)\/([A-Z]+)\/([0-9]+)\/?\]/, '$1 '); str = str.replace(/(\{\{[_ ]*PennPlaceMap)[ ]*\|[ ]*([^{}\|]*)[ ]*\|[ ]*([^{}\|]*)[ ]*\|[ ]*[^{}\|]*(\}\})/, '$1|$2|$3$4'); str = str.replace(/(\{\{[Cc]oor[^{}]*\|[ ]*(?:[EW]|-?[0-9]+))([ ]*\}\})/gi, '$1region:US_type:city$2'); str = str.replace(/(\{\{[Cc]oor[^{}]*\|[ ]*)city([ ]*\}\})/gi, '$1region:US_type:city$2'); str = str.replace(/(\{\{[Cc]oor[^{}]*\|[ ]*)type:city([ ]*\}\})/gi, '$1region:US_type:city$2');

if( str.search( /User:Plastikspork\/blank/ ) < 0 ) { str = str.replace(/('''[^\r\n]*)([\r\n])/, '\{\{subst:' + 'User:Plastikspork/blank$2|name =$2|type =$2|state =$2|county =$2|city =$2|image =$2|caption =$2|pop =$2|year =$2|area =$2|land =$2|water =$2|coordinates =$2|elevation =$2|gnis =$2|fips =$2|map =$2|areacode = $2|zipcode =$2|timezone =c$2|website =$2|pos =$2\}\}$2$1$2'); }

str = str.replace(/(coordinates[ ]*=[ ]*)([\r\n]?\|(?:[\r\n]|.)*)(\{\{)[_ ]*Mapit-US-cityscale([^{}]*)(\}\})[\r\n]?/gm, '$1$3coord$4|region:US_type:city|display=inline,title$5$2'); if( str.search( /([^']*|[^']+'[^']+) (?:\([^\(\)]*\) |)(?:is|was) an? (.*?) in (?:.*?)(?:\[\^\[\*\]\], |)\[\[([^\[\]\|]*) (?:County|Census Area|Parish), ([^\[\]\|]*)(?:|\|[^\[\]\|]*)\]\]/ ) >= 0 ) { var m = str.match(/([^']*|[^']+'[^']+) (?:\([^\(\)]*\) |)(?:is|was) an? (.*?) in (?:.*?)(?:\[\^\[\*\]\], |)\[\[([^\[\]\|]*) (?:County|Census Area|Parish), ([^\[\]\|]*)(?:|\|[^\[\]\|]*)\]\]/); str = str.replace(/(\|name[ ]*=[ ]*)([\r\n])/, '$1' + m[1].toString + '$2'); str = str.replace(/(\|type[ ]*=[ ]*)([\r\n])/, '$1' + m[2].toString + '$2'); str = str.replace(/(\|county[ ]*=[ ]*)([\r\n])/, '$1' + m[3].toString + '$2'); str = str.replace(/(\|state[ ]*=[ ]*)([\r\n])/, '$1' + m[4].toString + '$2'); } else if( str.search( /([^']*|[^']+'[^']+) (?:\([^\(\)]*\) |)(?:is|was) an? (.*?) (?:in|near|located|by|along)/) >= 0 && str.search( /\{\{[ ]*([^{}_]+) (?:County|Census Area|Parish), ([A-Z][^{}_]*[^_ {}])[ ]*\}\}/) >= 0 ) { var m = str.match(/([^']*|[^']+'[^']+) (?:\([^\(\)]*\) |)(?:is|was) an? (.*?) (?:in|near|located|by|along)/); str = str.replace(/(\|name[ ]*=[ ]*)([\r\n])/, '$1' + m[1].toString + '$2'); str = str.replace(/(\|type[ ]*=[ ]*)([\r\n])/, '$1' + m[2].toString + '$2'); var m = str.match(/\{\{[ ]*([^{}_]+) (?:County|Census Area|Parish), ([A-Z][^{}_]*[^_ {}])[ ]*\}\}/); str = str.replace(/(\|county[ ]*=[ ]*)([\r\n])/, '$1' + m[1].toString + '$2'); str = str.replace(/(\|state[ ]*=[ ]*)([\r\n])/, '$1' + m[2].toString + '$2'); }

str = str.replace(/(county[ ]*=[ ]*)[^\r\n,\|]* Township, ([^\r\n\|]*)([\r\n])/i, '$1$2$3'); if( str.search( /\[([^\[\]\|]*)( Township, [^\|]*)(?:\||\])/i ) >= 0 ) { m = str.match(/\[([^\[\]\|]*)( Township, [^\|]*)(?:\||\])/i); str = str.replace(/(\|city[ ]*=[ ]*)([\r\n])/, '|town=' + m[1].toString + '$2$1$2'); } str = str.replace(/(\|[ ]*type[ ]*=[ ]*)(?:very small|small|tiny|rural),? /i, '$1'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*\[\[census-designated place)(\]\])[^\r\n]*/gi, '$1|CDP$2'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[^\r\n]*)rural /gi, '$1'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[\[ ]*)borough([\]]*)[^\r\n]*/gi, '$1Borough$2'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[\[ ]*)village([\]]*)[^\r\n]*/gi, '$1Village$2'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[\[ ]*)town([\]]*)[^\r\n]*/gi, '$1Town$2'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[\[ ]*)city([\]]*)[^\r\n]*/gi, '$1City$2'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[\[ ]*)ghost town([\]]*)[^\r\n]*/gi, '$1Ghost town$2'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*)(?:unincorporated |)community/gi, '$1Unincorporated community'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[\[ ]*)unincorporated/gi, '$1Unincorporated'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[\[ ]*)hamlet/gi, '$1Hamlet'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[ ]*\[\^\*\|)unincorporated/gi, '$1Unincorporated'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[ ]*\[\^\*\|)hamlet/gi, '$1Hamlet'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[ ]*\[\^\*\|)unincorporated(\]\]) ([a-z]+)/gi, '$1Unincorporated $3$2'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[ ]*[^\r\n]*) located/gi, '$1'); str = str.replace(/(\|[ ]*type[ ]*=[ ]*[ ]*[^\r\n]*) (?:on|in|within|near|along) [^\r\n]*/gi, '$1');

if( str.search( /\[*area code\]* (?:of |is |)([0-9][0-9][0-9])/i ) >= 0 ) { m = str.match(/\[*area code\]* (?:of |is |)([0-9][0-9][0-9])/i); str = str.replace(/(\|areacode[ ]*=[ ]*)([\r\n])/, '$1' + m[1].toString + '$2'); } if( str.search( /\[*ZIP code\]*:? (?:of |is |)([0-9]+)/i ) >= 0 ) { m = str.match(/\[*ZIP code\]*:? (?:of |is |)([0-9]+)/i); str = str.replace(/(\|zipcode[ ]*=[ ]*)([\r\n])/, '$1' + m[1].toString + '$2'); } if( str.search( /\[*ZIP code\]*s? (?:of|is|serving the neighborhood are) ([0-9]+(?: and [0-9]+|))/i ) >= 0 ) { m = str.match(/\[*ZIP code\]*s? (?:of|is|serving the neighborhood are) ([0-9]+(?: and [0-9]+|))/i); str = str.replace(/(\|zipcode[ ]*=[ ]*)([\r\n])/, '$1' + m[1].toString + '$2'); } if( str.search( /there were ([0-9,]+) people/ ) >= 0 ) { m = str.match(/there were ([0-9,]+) people/); str = str.replace(/(\|pop[ ]*=[ ]*)([\r\n])/, '$1' + m[1].toString + '$2'); } if( str.search( /2000 census\]*[^\[\]\r\n]*population of ([0-9,]+)/ ) >= 0 ) { m = str.match(/2000 census\]*[^\[\]\r\n]*population of ([0-9,]+)/); str = str.replace(/(\|pop[ ]*=[ ]*)([\r\n])/, '$1' + m[1].toString + '$2'); } if( str.search( /elevation (?:is|of) ([0-9,]+)(?: | )feet/ ) >= 0 ) { m = str.match(/elevation (?:is|of) ([0-9,]+)(?: | )feet/); str = str.replace(/(\|elevation[ ]*=[ ]*)([\r\n])/, '$1' + m[1].toString + '$2'); } str = str.replace(/(\|[ ]*elevation[ ]*=[ ]*[0-9]+),([0-9][0-9][0-9])/gi, '$1$2'); if( str.search( /]*>[^<>]*\{\{(?:|cite[_ ]+)[_ ]*gnis[0-9]*[_ ]*\|[ ]*(?:id[ ]*=[ ]*|)([0-9]+)[ ]*(?:\||\}\})[^<>]*(?:accessed |accessdate[ ]*=[ ]*)([^<>{}\|\.]*)[\. ]*(?:\}\}|<\/ref>)/i ) >= 0 ) { m = str.match(/]*>[^<>]*\{\{(?:|cite[_ ]+)[_ ]*gnis[0-9]*[_ ]*\|[ ]*(?:id[ ]*=[ ]*|)([0-9]+)[ ]*(?:\||\}\})[^<>]*(?:accessed |accessdate[ ]*=[ ]*)([^<>{}\|\.]*)[\. ]*(?:\}\}|<\/ref>)/i); str = str.replace(/(\|gnis[ ]*=[ ]*)([\r\n])/, '$1' + m[1].toString + '\{\{subst:#tag:ref|\{\{cite gnis|id=' + m[1].toString + '|name=\{\{subst:PAGENAME\}\}|accessdate='+m[2].toString+'\}\}|name="gnis"\}\}$2'); } if( str.search( /\{\{(?:|cite[_ ]+)[_ ]*gnis[0-9]*[_ ]*\|[ ]*(?:id[ ]*=[ ]*|)([0-9]+)[ ]*(?:\||\}\})/i ) >= 0 ) { m = str.match(/\{\{(?:|cite[_ ]+)[_ ]*gnis[0-9]*[_ ]*\|[ ]*(?:id[ ]*=[ ]*|)([0-9]+)[ ]*(?:\||\}\})/i); str = str.replace(/(\|gnis[ ]*=[ ]*)([\r\n])/, '$1' + m[1].toString + '\{\{subst:#tag:ref|\{\{cite gnis|id=' + m[1].toString + '|name=\{\{subst:PAGENAME\}\}|accessdate=\}\}|name="gnis"\}\}$2'); } if( str.search( /#tag:ref\|[{]+cite gnis\|id=[ ]*([0-9]+)[ ]*\|/ ) >= 0 ) { m = str.match(/#tag:ref\|[{]+cite gnis\|id=[ ]*([0-9]+)[ ]*\|/); str = str.replace(new RegExp(']*>[^<>]*[{]+gnis[0-9]*[ ]*\\|[ ]*(?:id[ ]*=[ ]*|)' + m[1].toString + '[^<>]*<\/ref>', 'g'), ' '); } if( str.search( /a total area of [0-9\.]+(?: | |\[\[)*square mile(?: | |\]\])*s \(([0-9\.]+)(?: | |\[\[)*km²(?: |\]\])*/ ) >= 0 ) {    m = str.match(/a total area of [0-9\.]+(?: | |\[\[)*square mile(?: | |\]\])*s \(([0-9\.]+)(?: | |\[\[)*km²(?: |\]\])*/); str = str.replace(/(\|area[ ]*=[ ]*)[ ]*([\r\n])/, '$1' + m[1].toString + '$2'); if( str.search( /all of it land/ ) >= 0 ) { str = str.replace(/(\|land[ ]*=[ ]*)[ ]*([\r\n])/, '$1' + m[1].toString + '$2'); } }  if( str.search( /[0-9\.]+(?: | |\[\[)*square mile(?: | |\]\])*s \(([0-9\.]+)(?: | |\[\[)*km²(?: |\]\])*\) of it is land/ ) >= 0 ) { m = str.match(/[0-9\.]+(?: | |\[\[)*square mile(?: | |\]\])*s \(([0-9\.]+)(?: | |\[\[)*km²(?: |\]\])*\) of it is land/); str = str.replace(/(\|land[ ]*=[ ]*)[ ]*([\r\n])/, '$1' + m[1].toString + '$2'); } if( str.search( /and [0-9\.]+(?: | |\[\[)*square mile(?: | |\]\])*s \(([0-9\.]+)(?: | |\[\[)*km²(?: |\]\])*\) of it(?:\([^\(\)]+\)| )*is water/ ) >= 0 ) { m = str.match(/and [0-9\.]+(?: | |\[\[)*square mile(?: | |\]\])*s \(([0-9\.]+)(?: | |\[\[)*km²(?: |\]\])*\) of it(?:\([^\(\)]+\)| )*is water/); str = str.replace(/(\|water[ ]*=[ ]*)[ ]*([\r\n])/, '$1' + m[1].toString + '$2'); } if( str.search( /\{\{[_ ]*PennPlaceMap[_ ]*\|([^{}\|]*)\|([^{}\|]*)\}\}/ ) >= 0 ) { m = str.match(/\{\{[_ ]*PennPlaceMap[_ ]*\|([^{}\|]*)\|([^{}\|]*)\}\}/); str = str.replace(/(\|map[ ]*=[ ]*)([\r\n])/, '$1 Map of ' + m[2].toString + ', ' + m[1].toString + ' County, Pennsylvania Highlighted.png$2'); str = str.replace(/\{\{[_ ]*PennPlaceMap[_ ]*\|[^{}\|]*\|[^{}\|]*\}\}[\r\n]?/, ''); } str = str.replace(/\[\^\[\*doton[^\[\]]*\]\][\r\n]?/gi, '');

if( str.search( /state[ ]*=[ ]*(?:Connecticut|Delaware|Georgia|Indiana|Maine|Maryland|Massachusetts|New Hampshire|New Jersey|New York|North Carolina|Ohio|Pennsylvania|Rhode Island|South Carolina|Vermont|Virginia|West Virginia|Florida)/ ) >= 0 ) { str = str.replace(/(timezone[ ]*=[ ]*)[CMWPAH]/gi, '$1e'); } if( str.search( /state[ ]*=[ ]*(?:Arizona|Colorado|New Mexico|Utah|Wyoming|Idaho|Montana)/ ) >= 0 ) { str = str.replace(/(timezone[ ]*=[ ]*)[CEWPAH]/gi, '$1m'); } if( str.search( /state[ ]*=[ ]*(?:California|Nevada|Oregon|Washington)/ ) >= 0 ) { str = str.replace(/(timezone[ ]*=[ ]*)[CEMPAH]/gi, '$1w'); } if( str.search( /state[ ]*=[ ]*(?:Alaska)/ ) >= 0 ) { str = str.replace(/(timezone[ ]*=[ ]*)[CEMPWH]/gi, '$1a'); } if( str.search( /state[ ]*=[ ]*(?:Hawaii)/ ) >= 0 ) { str = str.replace(/(timezone[ ]*=[ ]*)[CEMPWA]/gi, '$1h'); } if( str.search( /(?:= 0 ) { if( str.search( /(?:{reflist|<references)/gi ) < 0 ) { str = str.replace(/(==[ ]*External[^\r\n]*==)/i, '== References ==\n\{\{reflist\}\}\n\n$1'); }    if( str.search( /(?:{reflist|<references)/gi ) < 0 ) { str = str.replace(/(\{\{[^{}]*(?:County|Census Area|Parish)[^{}]*\}\}|\{\{[^{}]*stub[^{}]*)/i, '== References ==\n\{\{reflist\}\}\n\n$1'); } }  return str; }

//Allows URI to be properly decoded for view mode (see WP:AutoEd) function SporkSpork_QueryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } } return null; }

addOnloadHook(function { if( SporkSpork_QueryString('SporkSpork1') ) {  SporkSpork; } if (document.forms.editform) {  mw.util.addPortletLink('p-tb', 'javascript:SporkSpork', 'Spork', 'ca-sporkspork', 'Spork', 'z', document.getElementById('t-specialpages')); } else if ( (mw.config.get('wgAction') == "view") && mw.config.get('wgIsArticle')) {   var url = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=edit';   mw.util.addPortletLink('p-tb', url + '&SporkSpork1=true', 'Spork', 'ca-sporkspork', 'Spork', 'z', document.getElementById('t-specialpages')); } });