MediaWiki:AddCoordinates.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
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.
/*
  Script to add cordinates
  coordinates: A location template to add
*/
 
window.AddCoordinates = {
  run : function () {
    var coordinates = decodeURIComponent(mw.util.getParamValue('coordinates'));
    if (coordinates==="") return; 

    var wptext = document.getElementById ('wpTextbox1');
    if (!wptext) return;

    var newtext = wptext.value.replace (/\{\{[Ll]ocation possible\}\}/g, coordinates);
    if (wptext.value==newtext){
      newtext = wptext.value.replace("== [[Commons:Copyright tags|Licensing]]: ==", coordinates + "\n" + "== [[Commons:Copyright tags|Licensing]]: ==");
      if (wptext.value==newtext){
        newtext = wptext.value.replace("== Licensing ==", coordinates + "\n" + "== Licensing ==");
        if (wptext.value==newtext){
          newtext = wptext.value.replace("== License information ==", coordinates + "\n" + "== License information ==");
          if (wptext.value==newtext){
            newtext = wptext.value + coordinates;          
          }
        }
      }
    }
    wptext.value = newtext;
    var wpsummary = document.getElementById ('wpSummary');
    if (wpsummary) {
      wpsummary.value = "Added location using [[MediaWiki:AddCoordinates.js|AddCoordinates.js]]";
    }
  }
};

if ( mw.config.get( 'wgAction' ) == 'edit' ) {
 $(document).ready( AddCoordinates.run );
}