MediaWiki talk:OSM.js

From Meta, a Wikimedia project coordination wiki

Please update the script to: http://de.wikipedia.org/wiki/Benutzer:Kolossos/osm.js

There is additional "secure"-Support. So the map will still have no "https" but the links inside will have it. To this it is support of page title. Thanks.--Kolossos 21:31, 8 December 2010 (UTC)[reply]

Done --WizardOfOz talk 22:28, 8 December 2010 (UTC)[reply]

URL encoding[edit]

{{editprotected}} Please chance the URL title-parameter to:

+ '&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) )

--Kolossos (talk) 22:41, 20 March 2012 (UTC)[reply]

Done, but please check. Thanks, Savhñ 11:02, 25 March 2012 (UTC)[reply]
Seems good. --Kolossos (talk) 11:46, 26 March 2012 (UTC)[reply]

Please remove

if (wgServer == "https://secure.wikimedia.org") {var osm_secure='&secure=1';} else {var osm_secure=;}

Also change that addOnloadHook with $. Move openStreetMapToggle before openStreetMapInit so JSLint stops complaining. --Locos epraix 07:46, 28 March 2012 (UTC)[reply]

It's been three weeks now. Just replace the code with

// Using OpenStreetMap in Wikipedia.
// (c) 2008 by Magnus Manske
// Released under GPL

function openStreetMapToggle () {
  var osm_secure = '',
      c = document.getElementById ( 'coordinates' ) ;
  if ( !c ) return ;
  var cs = document.getElementById ( 'contentSub' ),
      osm = document.getElementById ( 'openstreetmap' ) ;

  if ( cs && osm ) {
    if ( osm.style.display == 'none' ) {
      osm.style.display = 'block' ;
    } else {
      osm.style.display = 'none' ;
    }
    return false ;
  }

  var found_link = false,
      a = c.getElementsByTagName ( 'a' ),
      h;
  for ( var i = 0 ; i < a.length ; i++ ) {
    h = a[i].href ;
    if ( !h.match( /geohack/ ) ) continue ;
    found_link = true ;
    break ;
  }
  if ( !found_link ) return ; // No geohack link found

  h = h.split('params=')[1] ;

  if ( window.location.protocol == 'https:' ) {
    osm_secure = '&secure=1' ;
  }

  var iframe = document.createElement ( 'iframe' ),
      url = '//toolserver.org/~kolossos/openlayers/kml-on-ol.php?lang=' + osm_proj_lang + '&uselang=' + wgUserLanguage + '&params=' + h + '&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) ) + osm_secure ;

  iframe.id = 'openstreetmap' ;
  iframe.style.width = '100%' ;
  iframe.style.height = '350px' ;
  iframe.style.clear = 'both' ;
  iframe.src = url ;
  cs.appendChild ( iframe ) ;
  return false ;
}

function openStreetMapInit () {
  var c = document.getElementById ( 'coordinates' ) ;
  if ( !c ) return ;

  var a = c.getElementsByTagName ( 'a' ),
      geohack = false;
  for ( var i = 0 ; i < a.length ; i++ ) {
    var h = a[i].href ;
    if ( !h.match( /geohack/ ) ) continue ;
    geohack = true ;
    break ;
  }
  if ( !geohack ) return ;

  var na = document.createElement ( 'a' ) ;
  na.href = '#' ;
  na.onclick = openStreetMapToggle ;
  na.appendChild ( document.createTextNode ( osm_proj_map ) ) ;
  c.appendChild ( document.createTextNode ( ' (' ) ) ;
  c.appendChild ( na ) ;
  c.appendChild ( document.createTextNode ( ')   ' ) ) ;
}

$( openStreetMapInit ) ;

--Locos epraix 22:02, 19 April 2012 (UTC)[reply]

Hecho, perdón por el retraso. Por favor comprueba que sea correcto, y en caso de que haya un error, contacta a otro admin (si acaso por el IRC), yo mismo estaré ausente la próxima semana. Un saludo, Savhñ 20:58, 20 April 2012 (UTC)[reply]

Code cleanup and exclude globe[edit]

{{editprotected}} The OSM inline map currently only works with earth coordinates, so it should be disabled when globe: is set, as is done on German Wikipedia (see de:MediaWiki:Common.js). In addition to to a check .match(/_globe:/)) I ended up cleaning up the code. jQuery has been supported for quite some time now, so I see no reason for using inconvenient syntax like document.createElement . My rewritten code is located at User:Danmichaelo/Sandbox.js. There is also a diff to the original code, but it's not very readable... I've tested the code at Norwegian Bokmål Wikipedia ([1]) and it seems to work fine. Danmichaelo (talk) 23:05, 11 August 2012 (UTC)[reply]

Done, I've took your version, but I had to alter the script. You should especially notice the security fix at line 36! - Hoo man (talk) 18:04, 5 September 2012 (UTC)[reply]
Thanks for checking and improving my code! There is a problem with the last selector though (lines 62-64).
		$('#coordinates').append(' (<a id="coordinates_map" href="#">' + osm_proj_map + '</a>)   ')
		.find('a')
		.click(openStreetMapToggle);
adds the click event to all anchors within #coordinates, but normally you would only add it to #coordinates_map, leaving a link to geohack on toolserver, and perhaps one to a coordinate help page. At nowiki, for instance, the content of #coordinates looks like this:
<span id="coordinates">
 <a href="/wiki/Jordens_koordinatsystem" title="Jordens koordinatsystem">Koordinater</a>: 
 <span class="plainlinks nourlexpansion"><a rel="nofollow" class="external text" href="http://toolserver.org/~geohack/geohack.php?language=no&pagename=Bergen&params=60_23_33_N_005_19_24_E_type:city(256600)_region:NO-12"><span class="geo-default"><span class="geo-dms" title="Kart, flyfoto og andre data for dette stedet"><span class="latitude">60°23′33″N</span> <span class="longitude">005°19′24″Ø</span></span></span></a></span> 
 (<a id="coordinates_map" href="#">kart</a>)   
</span>
Therefore, please change line 63 to
		.find('#coordinates_map')
or something similar. Danmichaelo (talk) 17:36, 7 September 2012 (UTC)[reply]

Done, I'm using:

$('#coordinates').append(
	' (',
	$('<a id="coordinates_map" href="#">' + osm_proj_map + '</a>').click(openStreetMapToggle),
	')   '
);

now - Hoo man (talk) 15:34, 9 September 2012 (UTC)[reply]

Great Danmichaelo (talk) 09:55, 11 September 2012 (UTC)[reply]

Disabling OSM map for globes other than Earth is OK, but now it is disabled even when "globe:earth" is found. I suggest disabling it only for other globes, but not for "globe:earth", because this parameter is sometimes found in Wikipedias. Example of "globe:earth" being copied from enwiki to cawiki and therefore disabling inline OSM for one article.--Pere prlpz (talk) 21:40, 26 December 2012 (UTC)[reply]

Legacy JavaScript[edit]

Hello! This script has been detected as using deprecated parameters that need to be replaced with the updated version. Examples include addOnloadHook() needs to be replaced with $(); all wgGlobalVariables need to be properly gotten with mw.config.get( 'wgGlobalVariable' ); and addPortletLink needs to be called with mw.util.addPortletLink. Please see MW:ResourceLoader/Legacy JavaScript for details. Thank you. {{U|Technical 13}} (etc) 16:54, 18 January 2015 (UTC)[reply]

Done (I hope) - Hoo man (talk) 23:38, 13 January 2016 (UTC)[reply]
@Hoo man: I just saw, that the text written next to the coordinates in hsb.wp changed from "karta" (which was the equivalent in hsb for "map") to "null". As far as I know, the local word for "map" came from the local MediaWiki:Common.js before, which seemingly has changed now. So what do we have to change on hsb.wp now to get the right word back? --j.budissin 10:30, 14 January 2016 (UTC)[reply]
@J budissin: I just updated all users of this script across all wikis, thus the problem should be fixed. Cheers, Hoo man (talk) 13:27, 14 January 2016 (UTC)[reply]
Very good, thanks a lot! --j.budissin 14:03, 14 January 2016 (UTC)[reply]
This still is a problem on no.wikipedia.org. What change should be done? Haros (talk) 20:32, 20 January 2016 (UTC)[reply]
Found it in da.wikipedia.org. Ok now. Haros (talk) 20:45, 20 January 2016 (UTC)[reply]
Done (marking for clarity) Nux (talk) 12:57, 19 October 2022 (UTC)[reply]

Logo orientation[edit]

Can we also choose the orientation of the OSM logo or it's superfluous? For example to put the logo on the left, here (ku:MediaWiki:Gadget-Osm.js copy of de.wikipedia).--Ghybu (talk) 20:43, 14 August 2017 (UTC)[reply]

Polish Wikipedia has a problem[edit]

There is an article pl:Uznam in the Polish Wikipedia and very strange defect in WIWOSM that nobody is able to fix.

  • Wikidata version is Q3255 -> OK
  • German version is Usedom -> OK
  • Polish version is Uznam -> incorrect location

One of the solution I suggested is to modify the OSM script that allow to override wgTitle with variant in other language especially with Wikidata entity. Currently there is only test for osm_project_lang variable.

I prepared my own version of the OSM.js, where is added support for optional variable osm_proj_title. The corresponding gadget uses the new variable to pass Wikidata language and title to the script, which resolves the strange issue for me.

Despite the status of the defect in WIWOSM, an option to use Wikidata entities connected to articles as source for relation to OSM seems to be good idea. The Q numbers served by Wikidata are much more stable than article names. So I ask here to provide such support to use Wikidata as primary source for generating WIWOSM links, and article titles as fallback in case of lack Wikidata entry. Paweł Ziemian (talk) 19:42, 16 September 2018 (UTC)[reply]

Done I fixed the shape in question on the server. Wikidata shape doesn't exist any more, but might fix that later. See: phab:T158575. Nux (talk) 23:29, 18 October 2022 (UTC)[reply]