Page MenuHomePhabricator

Template: Maplink — add ability to use lat/lng or Wikidata Qid for a point
Open, HighPublic

Description

See also: T188291: Display point features (coordinates) from the results of a SPARQL query on a map in Wikipedia

Background

Various wikis have created a template that is effectively a wrapper of the <maplink> and/or <mapframe> tags, to make them easier for editors to use.

The problem

The templates were setup to show shapes and lines from .map files on Commons, or from a Wikidata id (technically from OSM based on that id), but not for points (i.e. the coordinates specified on a Wikidata item)

The solution

Retrieve the coordinates from the Wikidata using Lua (or from template parameter), and pass that into the <maplink> tag. This is implemented in enwiki's Module:Mapframe (called from Template:Maplink).

The new problems

(1) This was only fixed on enwiki, and still needs to be propagated through to other wikis, preferably with local translations (at least for the documentation, possibly for the end-user parameters). The TNT module mentioned by Yurik might be able to help with that.
(2) Not all the templates are based off the enwiki version. The fix needs to be adapted for those templates and/or their modules.

Implementation

The wikis Listed below have some version of Template:Maplink (Q27882107) and/or Module:Mapframe (Q52554979). Those that are ticked are able to display point features, and extract coordinates from Wikidata.

  • arwiki
  • bnwiki
  • enwiki
  • fawiki
  • idwiki
  • itwiki
  • jawiki
  • kowiki
  • sawiki
  • dewikisource
  • enwikivoyage
  • hiwikivoyage
  • itwikivoyage
Original task description

Based on our testing and conversation here, we'd like to see if using latitude and longitude as a valid data entry point—along with a Wikidata Qid for a single point—can be added to the Template:Maplink and Template:Mapbox.

Unfortunately, there are a large number of articles that use the Template:Maplink but are effectively "broken" because they use a single Wikidata Qid for a simple lat/lng point object or are using the incorrect syntax (using shape-inverse instead of type=shape). This change won't help those 'broken' maps, but it would give users an alternate method in which to use when adding a maplink to an article.

Adding in this ability could also greatly increase the amount of articles that would have an interactive map experience, since average editors could easily add them into pages that already have coordinates (and new articles that will have coordinates in them), maybe even using this query as a starting point: https://en.wikipedia.org/wiki/Category:Coordinates_on_Wikidata or even this: https://en.wikipedia.org/wiki/Category:Coordinates_not_on_Wikidata

Event Timeline

debt created this task.Oct 16 2017, 6:26 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptOct 16 2017, 6:26 PM
debt updated the task description. (Show Details)Oct 16 2017, 6:31 PM
debt moved this task from Backlog to To-do on the Maps-Sprint board.

To add further details: I almost got this working in Template:Maplink/sandbox (permalink) - the map shows at the correct lat/long position (retrieved from Wikidata or entered manually) but there is no marker present, even though the geoJSON follows the examples on mw:Help:Extension:Kartographer. E.g. putting {{Maplink/sandbox|id=Q797|type=point}} into Special:ExpandTemplates shows that it expands to

<span><maplink null="" text="Map" class="" longitude="-150" latitude="64">
{
  "type": "Feature",
  "geometry": { "type": "Point", "coordinates": [64, -150] },
  "properties": {
    "title": "ExpandTemplates",
    "marker-symbol":"marker",
    "marker-color": "5E74F3"
  }
}
</maplink></span>

yet the marker doesn't show up in the map from the produced maplink.

Yurik added a comment.Oct 17 2017, 1:36 AM

@Evad37 your geo position is wrong. First is the longitude, second is the latitude. Inside the geometry.

Yurik added a comment.Oct 17 2017, 1:41 AM

P.S. I fixed the template

Evad37 closed this task as Resolved.Oct 17 2017, 3:29 AM
Evad37 claimed this task.

Thanks Yurik. I've made the changes to the live templates, and they're working.

debt added a comment.Oct 17 2017, 4:47 PM

I've been testing this out...and I'm not sure why some work on Wikipedia and some work on Wikivoyage, but not both.

For example the following works on Wikipedia, but not Wikivoyage:

{{maplink|type=point|id=Q4596068|text=1st Bank}}

This one works on Wikivoyage, but not Wikipedia:

{{maplink|type=point|Coord=|39.0425|-108.686111|text=coordinates by lat lng no icon}}

What am I missing?

Evad37 reopened this task as Open.Oct 18 2017, 3:44 AM

en.Wikivoyage's {{maplink}} is a different template to en.Wikipedia's {{maplink}}. As well as having different parameters, it uses voy:Module:Map to create the <maplink> tag rather than creating it directly, like enwiki's version. Reopening this bug so that other projects' templates/modules (see d:Q27882107 can be investigated and upgraded.

As for the second example, the parameters aren't quite right: coordinates need to be inside a {{coord}} tempate, and passed to |coord= rather than separate parameters, i.e.

{{maplink|type=point|coord={{Coord|39.0425|-108.686111}}|text=coordinates by lat lng no icon}}
Evad37 updated the task description. (Show Details)Oct 18 2017, 3:55 AM
Yurik added a comment.Oct 18 2017, 4:27 AM

@Evad37 you might be interested in looking at the TNT module -- its available on many wikis already. It allows you to keep the description for all template parameter documentation in a single .tab page. This way, when you copy the template to another language, and you later add a new parameter, template users won't need to update their doc pages - it will show for them right away in english. later they can click the "edit translations" button underneath, and fix it for each new parameter.

Here's an example of a template that doesn't need to be modified in every language:
https://www.mediawiki.org/wiki/Template:Graph:Stacked

debt added a comment.Oct 18 2017, 3:20 PM

en.Wikivoyage's {{maplink}} is a different template to en.Wikipedia's {{maplink}}. As well as having different parameters, it uses voy:Module:Map to create the <maplink> tag rather than creating it directly, like enwiki's version.

argh, of course every project has a slightly different maplink template :-/

As for the second example, the parameters aren't quite right: coordinates need to be inside a {{coord}} tempate, and passed to |coord= rather than separate parameters, i.e.

{{maplink|type=point|coord={{Coord|39.0425|-108.686111}}|text=coordinates by lat lng no icon}}

That works, thanks! Now, I just need to figure out why I'm getting Lua errors on a few pages I'm upgrading.

Hi @debt, we tried to triage this at today's Collab-Maps Team meeting, but no one seemed to be able to fully understand the issue here or what is involved. Can you please explain it more fully and give a few examples of where this is broken? Thanks!

debt added a comment.Feb 23 2018, 1:56 AM

Hi @jmatazzoni - this is a bit difficult issue. Each wiki is slightly different in their maplink templates, so a 'one size fits all' template for adding a maplink just doesn't exist. It'd be totally cool if it did, but...yeah. :(

In the task description is the details for which wiki's are not working for adding a single Wikidata point to a maplink and having it work. Multiple Wikidata points work, but, generally, not just one point will work with maplink.

Evad37 added a comment.EditedFeb 23 2018, 2:56 AM

@jmatazzoni Some further details that might help with clarification:

  • The background: Various wikis have created a template that is effectively a wrapper of the <maplink> tag, to make it easier for editors to use.
  • The problem: The templates were setup to show shapes and lines from .map files on Commons, or from a Wikidata id (technically from OSM based on that id), but not for points (i.e. the coordinates specified on a Wikidata item)
  • The solution: Retrieve the coordinates from the Wikidata using Lua, and pass that into the <maplink> tag.
  • Example: this edit to en:Template:Maplink, of which a key line of code is
"geometry": { "type": "Point", "coordinates": [{{#invoke:coordinates|coord2text|{{{coord| {{WikidataCoord|display=| {{{id| {{{ids| {{#invoke:Wikidata|pageId}} }}} }}} }} }}}|long}}, {{#invoke:coordinates|coord2text|{{{coord| {{WikidataCoord|display=| {{{id| {{{ids| {{#invoke:Wikidata|pageId}} }}} }}} }} }}}|lat}}] },
  • which:
  • The new problems:
    • (1) This was only fixed on enwiki, and requires the above two modules and template. All of that needs to be propagated through to other wikis, preferably with local translations (at least for the documentation, possibly for the end-user parameters). The TNT module mentioned above might be able to help with that.
    • (2) Not all the templates are based off the enwiki version. The fix needs to be adapted for those templates and/or their modules.

Update: The enwiki template has had mapframe functionality added, and been rewritten with Lua Module:Mapframe. As well as providing new features (mainly displaying multiple things on the same map), it will make translation/localisation easier.

Evad37 updated the task description. (Show Details)May 10 2018, 10:54 AM
Restricted Application added a subscriber: revi. · View Herald TranscriptMay 10 2018, 10:54 AM
Evad37 updated the task description. (Show Details)May 10 2018, 1:45 PM
Evad37 updated the task description. (Show Details)May 10 2018, 1:50 PM
Evad37 updated the task description. (Show Details)May 11 2018, 3:22 AM
Evad37 added a comment.EditedJun 8 2018, 3:45 AM

Fully implementing T188291 is the better way to resolve this across all projects without having to resort to Lua.

Evad37 updated the task description. (Show Details)Jun 8 2018, 3:46 AM
Mholloway added a project: patch-welcome.
Restricted Application added a subscriber: Liuxinyu970226. · View Herald TranscriptThu, Dec 12, 4:16 PM