Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
//<pre>// Script to embed Coordinate template generation in MediaWiki's edit page// inspired by [[:en:User:Pilaf/livepreview.js]]//// defaults//varcoord_templatename='Location';// can be overridden with 'coor_dms'//// Insert the coordinate Form into the edit box.//functioncoordinatesInstall(){copywarn=document.getElementById('editpage-copywarn');if(copywarn!=null){varcleaner="<br style=\\'clear:both;\\' />";CoordinatesHTML='<div style="border: 1px solid gray; padding: 3px; margin-top: 2px; margin-bottom:2px;">'CoordinatesHTML+='<input type="button" value="Insert as '+coord_templatename+'" onclick="interpretCoordinates();" /> ';CoordinatesHTML+='<input type="text" size="80" id="CoordinateBox" /></div>';copywarn.innerHTML=CoordinatesHTML+copywarn.innerHTML;}}//// Hook up instalation function//$(coordinatesInstall);//// Coordinate interpretation//functioninterpretCoordinates(){varcoordinate1=document.getElementById('CoordinateBox').value;varcoordinate2='';varcoord_filter=/http:\/\/www\.google\.([a-zA-Z]+)\/maps/;varlatlon;// magic!if(coordinate1.substr(0,19)=='http://maps.google.'||coord_filter.test(coordinate1)){varfrom_ll=coordinate1.substr(coordinate1.indexOf("&ll=")+4);varampers=from_ll.indexOf('&');if(ampers==-1){latlon=from_ll.split(",");}else{latlon=(from_ll.substr(0,ampers)).split(",");}}// more magic!if(coordinate1.substr(0,27)=='http://www.wikimapia.org/##'){varfrom_ll=coordinate1.substr(29);varampers=from_ll.indexOf('&z=');latlon=(from_ll.substr(0,ampers)).split("&x=");latlon[0]/=1000000.0;latlon[1]/=1000000.0;}varmark_ns='N';varmark_ew='E';varlat=latlon[0];varlon=latlon[1];if(lat<0){lat*=-1;mark_ns='S';}if(lon<0){lon*=-1;mark_ew='W';}varlat_m=(lat-Math.floor(lat))*60.0;varlon_m=(lon-Math.floor(lon))*60.0;varlat_s=(lat_m-Math.floor(lat_m))*60.0;varlon_s=(lon_m-Math.floor(lon_m))*60.0;//coordinate2 = '{{coor_d|'+lat+'|'+mark_ns+'|'+lon+'|'+mark_ew+'|type:landmark}}';coordinate2='{{'+coord_templatename+'|'+Math.floor(lat)+'|'+Math.floor(lat_m)+'|'+lat_s.toPrecision(5)+'|'+mark_ns+'|'+Math.floor(lon)+'|'+Math.floor(lon_m)+'|'+lon_s.toPrecision(5)+'|'+mark_ew+'|type:landmark}}\n';vareditbox=document.getElementById('wpTextbox1');varinformation_template=(editbox.value).indexOf('{{Information')if(information_template>-1){vareditbox_content_1=(editbox.value).substr(0,information_template);vareditbox_content_2=(editbox.value).substr(information_template);editbox.value=editbox_content_1+coordinate2+editbox_content_2;}else{vareditbox_content=editbox.value;editbox.value=coordinate2+editbox_content;}}//</pre>