Template talk:Wikidata location#Label text or sitelink text

Debugging

This template is a bugger to debug, so I'm dropping here a "beautified" version of the template as it was at 14:49, 29 July 2017 UTC.

{{#if:{{{location|}}}

|

{{{location|}}}

|

{{#if:{{#invoke:WikidataIB|checkBlacklist|name=location|suppressfields={{{suppressfields|}}} }}

|

{{comma separated values

| 1 =

{{#if:{{#Property:P706|from={{{qid|}}}}}

|

{{#ifexist:{{#invoke:Wikidata|getRawValue|P706|qid={{{qid|}}}|onlysourced=no|FETCH_WIKIDATA}}, {{#invoke:Wikidata|getRawValue|P131|qid={{{qid|}}}|onlysourced=no|FETCH_WIKIDATA}}

|

{{#invoke:Wikidata

|

{{#invoke:WikidataIB|getValue|P706|qid={{{qid|}}}|name=location|suppressfields={{{suppressfields|}}}|fetchwikidata={{{fetchwikidata|ALL}}}|onlysourced={{{onlysourced|no}}}|noicon=yes|{{{terrainfeature|}}} }}

}}

{{#ifeq:{{{refs|yes}}} |yes

|

{{wikidata|references|normal+|{{{qid|}}}|P706}}

}}

}}

| 2 =

{{#invoke:WikidataIB|getValue|P276|qid={{{qid|}}}|name=location|suppressfields={{{suppressfields|}}}|fetchwikidata={{{fetchwikidata|ALL}}}|onlysourced={{{onlysourced|no}}}|noicon=yes|{{{location|}}}}}

{{#ifeq:{{{refs|yes}}} | yes

|

{{wikidata|references|normal+|{{{qid|}}}|P276}}

}}

| 3 =

{{#ifexist:{{#invoke:Wikidata|getRawValue|P706|qid={{{qid|}}}|onlysourced=no|FETCH_WIKIDATA}}, {{#invoke:Wikidata|getRawValue|P131|qid={{{qid|}}}|onlysourced=no|FETCH_WIKIDATA}}

|

|

{{#ifexist:{{#invoke:Wikidata|getRawValue|P131|qid={{{qid|}}}|onlysourced=no|FETCH_WIKIDATA}}

|

{{#invoke:Wikidata

|

{{#invoke:WikidataIB|getValue|P131|qid={{{qid|}}}|name=location|suppressfields={{{suppressfields|}}}|fetchwikidata={{{fetchwikidata|ALL}}}|onlysourced={{{onlysourced|no}}}|noicon=yes|{{{area|}}}}}

}}

{{#ifeq:{{{refs|yes}}} | yes

|

{{wikidata|references|normal+|{{{qid|}}}|P131}}

}}

}}

| 4 =

{{#ifeq:{{#Property:P17|from={{{qid|}}}}} | United States of America

|

{{#if:{{#Property:P706|from={{{qid|}}}}}{{#Property:P276|from={{{qid|}}}}}{{#Property:P131|from={{{qid|}}}}}

|

US

|

United States

}}

|

{{#ifeq:{{#Property:P17|from={{{qid|}}}}} | no value

|

{{#if:{{#Property:P30|from={{{qid|}}}}}

|

{{#Property:P30|from={{{qid|}}}}}

{{#ifeq:{{{refs|yes}}} | yes

|

{{wikidata|references|normal+|{{{qid|}}}|P30}}

}}

{{EditAtWikidata|pid=P17|qid={{{qid|}}} }}

}}

|

{{#if:{{#Property:P17|from={{{qid|}}}}}

|

{{#if:{{#invoke:WikidataIB|checkBlacklist|name=location|suppressfields={{{suppressfields|}}} }}

|

{{#Property:P17|from={{{qid|}}} }}

{{#ifeq:{{{refs|yes}}} | yes

|

{{wikidata|references|normal+|{{{qid|}}}|P17}}

}}

{{EditAtWikidata|pid=P17|qid={{{qid|}}} }}

}}

}}

}}

}}

}}

}}

|

}}

{{documentation}}

= Template and module =

I've also created a debugging template at Template:Wikidata location/debug that can be used to show the output of this template along with the values of the five properties that it uses, which may help when examining its behaviour. --RexxS (talk) 14:51, 29 July 2017 (UTC)

Update: {{ping|Mike Peel|Rehman}} I've now got Module:WDloc working after a fashion. It's set (for now) to display a table of all the Wikidata location values for an article, along with my best guess for what ought to be the location reported in an infobox. I can quickly disable the table display if we agree on the "best" location to be returned for any article.

In {{q|Q172822}}, {{#invoke:WDloc|location|fetchwikidata=ALL |qid=Q172822}} gives:

{{#invoke:WDloc|location|fetchwikidata=ALL |qid=Q172822}}

Whereas {{Wikidata location/debug |qid=Q172822}} shows:

{{Wikidata location/debug |qid=Q172822}}

{{reflist-talk}}

I think the module gives a better result than {{tl|Wikidata location}} in this case. Maybe the countries/continents shouldn't be linked.

In {{q|Q3299222}}, we can see {{#invoke:WDloc|location|fetchwikidata=ALL |qid=Q3299222}} gives:

{{#invoke:WDloc|location|fetchwikidata=ALL |qid=Q3299222}}

We really need to try out as many articles as possible when we get a chance, so that we can form an opinion on whether I've picked the best algorithm for determining what is to be displayed. --RexxS (talk) 20:59, 30 July 2017 (UTC)

: {{ping|RexxS}} Trying {{#invoke:WDloc|location|fetchwikidata=ALL|qid=Q1513315}} (South Pole Telescope, as usual) throws an error: {{#invoke:WDloc|location|fetchwikidata=ALL|qid=Q1513315}}. Thanks. Mike Peel (talk) 21:18, 30 July 2017 (UTC)

: I've set up a test page at User:Mike Peel/Test locations that fetches the locations for optical and radio telescopes through the module. It mostly looks good. I've been told before that links to the countries should be avoided, though, as they're overlinking. Other then that, there's just the Antarctica bug mentioned above. Thanks. Mike Peel (talk) 21:43, 30 July 2017 (UTC)

: A few other issues: apparently it should be "US", unless there is no other location information in which case it's "United States". And for {{Q|Q18132140}} (amongst others), Geo-feature should be shown (it currently just shows the country); see {{Q|Q4938704}} for a case where geo-feature + admin unit + country is needed, and {{Q|Q787671}} where it's location + admin unit (although this is because the data isn't stored right on Wikidata). Thanks. Mike Peel (talk) 22:03, 30 July 2017 (UTC)

::

:: {{ping|Mike Peel|label=Mike}} I've updated the code to deal with "novalue" as well as "somevalue" and sorted out the US/United States requirement. As your page was too long for the parsers, I've split it into three parts:

::* User:RexxS/Test locations1

::* User:RexxS/Test locations2

::* User:RexxS/Test locations3

:: Sadly, the module doesn't seem to be any better than {{tl|Wikidata location}} and shows few differences, such as returning: "South Pole, Antarctic Treaty area" instead of "South Pole, Antarctic Treaty area, Antarctica" in South Pole Telescope (I set it not to return continent unless it was the only location as requested); and "China" instead of "People's Republic of China" (because that's the name of our article). I haven't checked them all, so there may be other differences – perhaps improvements or perhaps not.

:: On the other hand, if someone is going to use the template on objects other than telescopes, like the {{Q|Q172822}}, then we might want to avoid locations like "Colorado River[1], Arizona, Nevada, Mohave County, Clark County[1][2], US". --RexxS (talk) 18:56, 31 July 2017 (UTC)

::: Thanks, those look like improvements. Using preferred values (which is the difference for Q172822) is definitely a good step forward - although we should look through User:Mike_Peel/World_Heritage_Sites to see if there are any issues there (since there are WHS's that span multiple countries). Just to be clear on my view here: the sooner we can scrap my template and switch over to using your module here, the better. :-) Thanks. Mike Peel (talk) 02:30, 1 August 2017 (UTC)

::: {{ping|RexxS}} Circling back to this, I think it's nearly ready to replace my template/hack in regular use, I think the main thing that's outstanding is the concatenating of links. The main ones we need to check are "geofeature, adminlocation" and "adminlocation1, adminlocation2", Would it be possible to add those in such a way that doesn't cause the disambig people problems? There are other things (in particular see User_talk:Nikkimaria#Location_formatting), but perhaps that's for the next version unless they're straightforward to do. Thanks. Mike Peel (talk) 16:44, 23 September 2017 (UTC)

:::: Sorry {{u|Mike Peel|Mike}}, I'm not really sure about what you mean by concatenating of links. I'm a dinosaur of small brain and I really need concrete examples. When I looked at Nikki's page, I was immediately worried about how you think I might deal with Riverside, California. Is that the problem?

:::: Are we going to face a similar problem with locations like Southwark, London? If you want the 'London' unlinked, then the code would also unlink 'Ulaanbaatar' in Baganuur, Ulaanbaatar – is that desirable? The injunction to delink "names of major geographic features" in Wikipedia:Manual of Style/Linking is not easily amenable to coding into an algorithm, unless somebody is willing to supply an exhaustive list of the names of major geographic features. I'm rather stuck at that point. --RexxS (talk) 19:25, 23 September 2017 (UTC)

::::: {{ping|RexxS}} As far as I can tell, the aim is to have links like Riverside, California, Southwark, London, Mount Wilson, California and so on, i.e. single links rather than two separate links or one link and one plaintext. The complication being that the two halves are from separate properties on Wikidata. That's what I was using the #ifexist statements for in this template, to check for the existance of such a link and to use that if available. Can that be done in Lua? Thanks. Mike Peel (talk) 19:39, 23 September 2017 (UTC)

:::::: {{ping|Mike Peel}} Well, I just tried {{#invoke:WDloc|location|fetchwikidata=ALL}} in The Mission Inn Hotel & Spa. This gives: {{#invoke:WDloc|location|fetchwikidata=ALL|qid=Q1920529}}

:::::: How do we deal with that in a systematic way? If editors can set both {{Q|Q99}} and {{Q|49243}} as values for {{Q|P131}} in {{Q|Q1920529}} – and with undefined order – it's going to need the code to start looking for an occurrence of one value within the other and dropping any that are contained. Do I have to cater for three values? four? The programming is going to need me to find several hours of uninterrupted time to crack that one.

:::::: I have no idea yet how I can generate Southwark, London from Wikidata. Our article is called Southwark – compare that with Riverside, California. Compare the en-wp site links (interlanguage links) for {{Q|Q5273898}} with those for {{Q|Q49243}}. No consistency. Here's the result for King's Bench Prison: {{#invoke:WDloc|location|fetchwikidata=ALL|qid=Q3403975}} How am I to generate London from that? --RexxS (talk) 21:47, 23 September 2017 (UTC)

::::::: {{ping|RexxS}} Yeah, this is complicated and messy. :-( With the ordering, I've mostly been manually changing them on Wikidata, which isn't great. If there are two values, maybe try checking them both ways around, so Riverside, California returns a result, but California, Riverside doesn't. In cases where the second part isn't present, I'd say just stick with the single links (e.g., don't try to generate 'London' if it's not here). Ideally we'd have different location parameters on Wikidata for state vs. county, but I think that was discussed in the past and rejected for some reason. Thanks. Mike Peel (talk) 21:55, 23 September 2017 (UTC)

:::::::: {{ping|Mike Peel}} Yes, I realised that I'd have to check (if A is in B) and (if B is in A) with two entries. But can you see how it increases as N(N-1) if we have to cater for 3, 4, ... values? Even with three values, we have to check six possibilities: (if A is in B); (if B is in A); (if A is in C); (if C is in A); (if C is in B); (if B is in C). That's why I posed the question how many we ought to cater for. Perhaps we can run a few SPARQL queries to get an idea of the maximum number of values of each location property in the current database? --RexxS (talk) 23:15, 23 September 2017 (UTC)

::::::::: {{ping|RexxS}} True. From my experience so far, I think we're talking about low numbers (<5 or so), but I appreciate the problems that could be caused if there are more than that, and I don't know how well this scales... Thanks. Mike Peel (talk) 23:26, 23 September 2017 (UTC)

Location excluding country

Hello Mike and RexxS! Is there way to use this template to generate the location, excluding the country (i.e. all other parts)? Rehman 12:38, 30 July 2017 (UTC)

: Hi {{u|Rehman}}, not this template, but I could probably create one for you if I had an example or two of what you want. Apart from {{q|P30}} and {{q|P17}}, Wikidata has three other possible ways of expressing location:

:* {{q|P276}} – example: Library of Alexandria location = Alexandria

:* {{q|P131}} – example: Eiffel Tower located in the administrative territorial entity = 7th arrondissement of Paris

:* {{q|P706}} – example: Erta Ale located on terrain feature = Erta Ale Range

: Are those the sorts of things you wanted? --RexxS (talk) 13:21, 30 July 2017 (UTC)

::

::Hi RexxS. Thanks for the quick reply. Basically, I want to use {{tl|Wikidata location}}, but with 'country' on one parameter, and all other parts on another. I intend to use it on {{tl|Infobox power station}}. Rehman 13:25, 30 July 2017 (UTC)

::: OK, that sounds a sensible request. As an example, I looked at Hoover Dam. Wikidata holds the following information on its location: {{q|P131}} = Arizona, Nevada, Mohave County, Clark County; {{q|P706}} = Colorado River. That's quite a lot of information to jam into a single field in an infobox, so do you think that editors would be willing to go to Wikidata and mark the county values as preferred (as I've just done)? Then for the Hoover Dam, you'd only have to use something like:

:::* {{#invoke:WikidataIB |getPreferredValue |P131 |fetchwikidata=ALL}} → {{#invoke:WikidataIB |getPreferredValue |P131 |fetchwikidata=ALL |qid=Q172822}}

::: In the infobox design, it would look like:

:::* {{#invoke:WikidataIB |getPreferredValue |P131 |name=location |fetchwikidata={{{fetchwikidata|}}} |suppressfields={{{suppressfields|}}} |onlysourced={{{onlysourced|}}} |noicon={{{noicon|}}} |qid={{{qid|}}} |{{{location|}}}} }}

::: Would that work for other power stations? --RexxS (talk) 13:53, 30 July 2017 (UTC)

::::

::::Yes, that seems to be the best way forward. And then probably have a bot or query run (would you know how?) to scan articles which have such long entries (such as the old version of Hoover Dam), so that we can manually tweak the preferred entries... Thanks for your help, and detailed reply. Appreciate it :) Rehman 16:09, 30 July 2017 (UTC)

Hello RexxS! I hope you're doing well. Do you think it would be possible to implement parameters in this template, so that we could optionally disable key parts of the output? (i.e exclude only the country) I tried looking at the code, but I'm afraid it is in a whole new level of complexity for me! Rehman 04:00, 9 August 2018 (UTC)

: Hi {{u|Rehman}}! I'm well, thanks - hope you are too. I've made some changes in the sandbox to implement a {{para|displaycountry}} parameter. If you set it to "no", it should suppress the {{q|P17}} value form the template. Because it's so complex, I can't be certain it will catch all the cases you want. Would you be able to test it out where you wanted to use it and let me know if it's not doing what you expect, please?

: In {{q|Q46879}}:

:* {{Wikidata location/sandbox|qid=Q46879}} → {{Wikidata location/sandbox|qid=Q46879}}

:* {{Wikidata location/sandbox|qid=Q46879|displaycountry=no}} → {{Wikidata location/sandbox|qid=Q46879|displaycountry=no}}

: As soon as I'm certain it meets your needs, I can update the main template from the sandbox. Tell me if you want a different name for the parameter. Regards --RexxS (talk) 18:16, 9 August 2018 (UTC)

::

::Thank you, RexxS! I did some tests on random articles, it worked quite well, except for when districts and provinces are both stated (as in {{Q|3440914}}). Since districts are within provinces, "Kandy District" should come before "Central Province" when previewing {{Infobox power station/sandbox}} in :en:Victoria Dam (Sri Lanka), for example. Do you think this is something that can be fixed? Rehman 06:44, 10 August 2018 (UTC)

::: I would be wary of code implementing {{para|displaycountry|no}} via 854209968. This template already implements, {{para|terrainfeature}}, {{para|location}}, and {{para|area}} in addition to {{para|onlysourced}}, {{para|suppressfields}} and {{para|fetchwikidata}} (though I notice all the calls to {{mlx|WikidataIB|getValue}} improperly always set {{para|name|location}} regardless when fetching claims for {{wdp|P706}}, {{wdp|P276}} and {{wdp|P131}}; I might have to fix that). Would it not be better to implement a similar {{para|country}} override for {{wdp|P17}} instead of {{para|displaycountry}}? If someone wants to suppress it they could just provide an blank argument for the parameter. —Uzume (talk) 17:25, 27 June 2020 (UTC)

:::: {{re|Uzume}} The {{para|name}} parameter contains the name of the infobox field that the call is made from. That is the name an editor will specify if they want to either include the infobox field in {{para|fetchwikidata}} or exclude the field using {{para|suppressfields}}. The infobox designer will choose a sensible name that should be obvious to an editor: in this case "location" is the name an editor will use to whitelist or blacklist the field. That brings me to the issue of {{tl|wd}}, which does not implement the whitelist, blacklist, or onlysourced filtering that {{tl|wdib}} does. If you test for an non-empty value using {{tl|wd}}, you may still have an empty value returned from the {{tl|wdib}} later on because of any filtering set. --RexxS (talk) 13:41, 28 June 2020 (UTC)

::: I also notice {{para|location}} seems to be improperly implemented having two meanings: once at the top allowing one to replace everything and later for just replacing {{wdp|P276}}. The latter can never be used properly. —Uzume (talk) 17:25, 27 June 2020 (UTC)

::: {{ping|Mike Peel}} Mike, do you think there's a solution possible for the "districts are inside provinces" issue within this template without messing up too much? For comparison:

::: {{#invoke: WikidataIB |location |Q3440914}} → {{#invoke: WikidataIB |location |Q3440914}}

::: What do you reckon? --RexxS (talk) 12:15, 10 August 2018 (UTC)

:::: {{ping|RexxS}} Definitely. I think that code can replace a good chunk of this template, although I guess we'd still need to keep it for the {{Wikidata entity link|P706}}, {{Wikidata entity link|P276}} and {{Wikidata entity link|P30}} cases, unless there's an easy way that they could also be added to the Lua code. If you get the chance before I do, perhaps test it out in the sandbox either here or on Commons? Thanks. Mike Peel (talk) 14:12, 10 August 2018 (UTC)

County

I'm looking for a way to obtain the county of an entity. Would this module be able to help with this? Is there any way to specify which subdivision to display? Thanks — Martin (MSGJ · talk) 16:42, 2 March 2021 (UTC)