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//if(typeof(coord_templatename)=="undefined")varcoord_templatename='Location';if(typeof(accuracy)=="undefined")varaccuracy=5;if(typeof(defaulttype)=="undefined")vardefaulttype="landmark";// can be overridden in your monobook.js ( insert: var coord_templatename = 'something'; )//// 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[s]{0,1}:\/\/maps\.google\.([a-zA-Z]+)\//;varlatlon;// magic!if(coord_filter.test(coordinate1)){latlon=mw.util.getParamValue('ll',coordinate1).split(",");}// more magic!if(coordinate1.substr(0,26)=='http://www.wikimapia.org/#'){varfrom_ll=coordinate1.substr(30);varampers=from_ll.indexOf('&z=');latlon=(from_ll.substr(0,ampers)).split('&lon=');}// even more magic!if(coordinate1.substr(0,21)=='http://maps.live.com/'){varfrom_ll=coordinate1.substr(coordinate1.indexOf("&cp=")+4);varampers=from_ll.indexOf('&');if(ampers==-1){latlon=from_ll.split("~");}else{latlon=(from_ll.substr(0,ampers)).split("~");}}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(accuracy)+'|'+mark_ns+'|'+Math.floor(lon)+'|'+Math.floor(lon_m)+'|'+lon_s.toPrecision(accuracy)+'|'+mark_ew+'|heading:?}}\n';//'|type:'+defaulttype+'}}\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>