Page MenuHomePhabricator

Add parser function for associated wikidata item ID
Open, Needs TriagePublicFeature

Description

Similar to T110683, there are some cases where it would be convenient to get the wikidata item ID of the parser context page in wiki markup. For example, a graph could use ID as a parameter to geoshapes service to get the outline of the current geographical object (eg city), or as a parameter to a sparql query.

Event Timeline

Ok from my side. Ideas for a name?

Parser functions usually require some parameters. I think a magic word (like {{WBREPONAME}}) fits better. Could be for instance {{ITEMID}} or {{ENTITYID}}.

I think we should do the parser function, not a magic keyword. This way we can expand it to do a page lookup. For example, {{ ENTITYID | United States }} is replaced with Q30. The optional first parameter would be the valid page title, as parsed by the local wiki. This will also allow us to easily do {{ ENTITYID | en:United States }} in another Wikipedia language, and still get Q30.

This comment was removed by Bugreporter.

[…] Could be for instance {{ITEMID}} or {{ENTITYID}}.

Both sound ok to me, maybe I lean a little towards itemid. A more verbose form like wikibase-itemid probably doesn't make to much sense, does it?

I think we should do the parser function, not a magic keyword. This way we can expand it to do a page lookup. For example, {{ ENTITYID | United States }} is replaced with Q30. The optional first parameter would be the valid page title, as parsed by the local wiki. This will also allow us to easily do {{ ENTITYID | en:United States }} in another Wikipedia language, and still get Q30.

This would probably require T142093: Decide how to do usage tracking for strings used to lookup entities (page titles, external ids, …) to be implemented. We could probably start with a parser function that doesn't take any arguments and then extend upon that, if we can/ want to.

Is there any progress with this feature? Users would really like to use templates like population history -- where users would just place it on the page, instead of requiring a Lua module to get the ID and use tag expansion into wiki markup.

Is there any progress with this feature? Users would really like to use templates like population history -- where users would just place it on the page, instead of requiring a Lua module to get the ID and use tag expansion into wiki markup.

Why don't you use [[https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua#mw.wikibase.getEntityIdForCurrentPage|mw.wikibase.getEntityIdForCurrentPage]] for that? If it's not meant to use the entity id of the current page, how would you know the title of the target page?

@hoo, thanks, I know I can use Lua to get the Wikidata ID, but this means that instead of simply copying one template like this one to all the different wikis, the community would have to copy at least two - the template plus the Lua module, and keep them in sync. Having a wikimarkup to extract at least the current Wikidata ID would mean that only the template would need to be copied.

Bean49 changed the subtype of this task from "Task" to "Feature Request".

I propose {{WIKIBASEITEMID}} magic word. Like {{PAGEID}}, {{PAGEID:page name}}. See also T349571.

@Pppery What would be the correct project? What project deals with the {{PAGEID}} magic word? This is not about Wikidata, this is about magic words and page properties on Wikipedia. No one seems to deal with this feature request since 2016. Could you help please?

MediaWiki-extensions-WikibaseClient is the correct project. This code would be added to https://www.mediawiki.org/wiki/Extension:Wikibase_Client if someone (who won't be me) were to implement it. MediaWiki-Parser is IMO also wrong, but not so wrong that I am going to remove it.

Magic words are not Wikibase client. This a Wikipedia pageprops. See T349571 for links. Could someone add the right project and assign the task?

But it needs to come from Wikibase Client. So this is correct.

https://en.wikipedia.org/w/api.php?action=query&format=json&prop=pageprops&titles=Kofoworola%20Abeni%20Pratt&formatversion=2
gives

{
  "batchcomplete": true,
  "query": {
      "pages": [
          {
              "pageid": 51046741,
              "ns": 0,
              "title": "Kofoworola Abeni Pratt",
              "pageprops": {
                  "defaultsort": "Pratt, Kofoworola Abeni",
                  "page_image": "Kofoworola_Abeni_Pratt.jpg",
                  "wikibase-shortdesc": "20th-century Nigerian nurse; first black Chief Nursing Officer of Nigeria",
                  "wikibase_item": "Q25796287"
              }
          }
      ]
  }
}

I suspect that there is a table with page properties. As I see, it is already integrated, just needs a magic word like {{WIKIBASEITEMID}}.

You can see it here:

select * from page_props where pp_propname = 'wikibase_item' limit 100

https://quarry.wmcloud.org/query/77832

Michael subscribed.

I'm adding this to the Lua board, even though it technically is not about Lua, but still about accessing data from the client within the content of an article, so close enough.