Module talk:WikidataIB/Archive 7: Difference between revisions

Content deleted Content added
No edit summary
m Archiving 1 discussion(s) from Module talk:WikidataIB) (bot
Line 476:
::: {{re|Evolution and evolvability}} There comes a point where I end up writing a query language instead of a module to return data for use in infoboxes. The first use you suggest really is best solved by a query using the WDQS. We don't put missing fields in infoboxes.
::: I considered the possibility of using operators other than equality and I deliberately coded the filter parsing to allow easy expansion in the future. However, dates are a much less structured datatype because we may have to accept inputs of dmy, mdy, ymd, and others, and Wikidata stores a timestamp, so there's a fair bit of processing to get a comparison. I have most of the code already elsewhere in the module, so it's not too bad, but it won't be high on my to-do list. Cheers --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 22:25, 16 December 2020 (UTC)
 
== URL handling ==
 
In [[Grapette]], {{tl|Infobox drink}} is fetching URLs that end up formatted not quite right. Here's one of them:
 
<pre>
<tr><th scope="row">Website</th><td><span class="url">[http://www.grapette.com<span class='penicon'> www<wbr/>.grapette<wbr/>.com<span class='penicon'>]</span>&nbsp;[[File:OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt=Edit this on Wikidata|link=https://www.wikidata.org/wiki/Q5597031?uselang=en#P856|Edit this on Wikidata]]</span></td></tr>
</pre>
 
Note the two opening span tags with class=penicon being opened inside the URL brackets, which are already wrapped in a span tag. One of those misplaced span tags is never closed. I think the URL needs a span tag and the penicon needs a span tag, but something appears to be going wrong here. I think it should look like this:
 
<pre>
<tr><th scope="row">Website</th><td><span class="url">[http://www.grapette.com www<wbr/>.grapette<wbr/>.com]</span>&nbsp;<span class='penicon'>[[File:OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt=Edit this on Wikidata|link=https://www.wikidata.org/wiki/Q5597031?uselang=en#P856|Edit this on Wikidata]]</span></td></tr>
</pre>
 
Or something close to that. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 03:20, 29 September 2020 (UTC)
:This is also happening with {{tl|Infobox software}} at [[SLinCA@Home]]. The invalid wikitext is also visible in the example at [[Module:WikidataIB#Function url2]]. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 13:27, 29 September 2020 (UTC)
::
:: Hi {{u|Jonesey95}}. Thanks for spotting that. It's caused by my attempts to resolve the [[#Wrapping of pencil icon]] thread above. The code in url2 assumed that the text and the pen-icon were separated by a non-breaking space, so went south when I moved the nbsp inside the span. I've restored the code that generates the pen icon to its previous state. Let me know if that doesn't fix it. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 14:33, 29 September 2020 (UTC)
:::Those two articles are fixed now, so it looks like you did something good in the most recent edits. Thanks. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 14:50, 29 September 2020 (UTC)
::::More problems at [[Swing Bridge, River Tyne]] via {{tl|Infobox bridge}}. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 22:47, 28 October 2020 (UTC)
:::::Yes, one can see the issue with example 4 at [[Module:WikidataIB#Function url2]] &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 15:16, 29 October 2020 (UTC)
{{ping|Jonesey95}} do you know which edit caused this, and can it be reverted? &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 19:02, 31 October 2020 (UTC)
:I think it was [https://en.wikipedia.org/w/index.php?title=Module%3AWikidataIB&type=revision&diff=980966172&oldid=972799895 one of these five edits] by {{U|RexxS}}. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 21:53, 31 October 2020 (UTC)
::I suspect the later two edits on 24 Sep. I've put the prior version in [[Module:WikidataIB/sandbox]] and will do some testing &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 10:38, 1 November 2020 (UTC)
Gentle poke to prevent archiving. As far as I know this is still an error, and I haven't had time to look into it &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 10:41, 17 November 2020 (UTC)
: {{re|MSGJ}} I think the function now adds the extra {{tag|wbr|o}} tags, so the concerns in articles should be met. Can you confirm that, Martin?
: Example 4 at [[Module:WikidataIB#Function url2]] is a test of the case where an editor supplies <code><nowiki>{{url|http://www.example.com/}}</nowiki></code> as the local parameter in an infobox, instead of <code><nowiki>http://www.example.com/</nowiki></code>. That's an error on the part of the editor, and I was trying to catch that and rectify in the url2 code. I need to have another look at how best to fix that now, but it's not what I'd consider a "breaking case" if an erroneous input produces an erroneous output. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 20:15, 26 November 2020 (UTC)
::Thanks for looking into this. I think the problems on Infobox bridge were caused by the parameters being enclosed with {{tl|url}}. For example
<pre>{{#invoke:WikidataIB|url2|url={{url|https://www.portoftyne.co.uk/about-us/history/heritage-sites/heritage-sites}}}}</pre>
::produces
{{#invoke:WikidataIB|url2|url={{url|https://www.portoftyne.co.uk/about-us/history/heritage-sites/heritage-sites}}}}
::which is what we were seeing on [[Swing Bridge, River Tyne]]. I believe it is quite common for this template to be used in infoboxes, so unless there is a reliable way of detecting it, I could not use url2 in the way I was previously. Would it be better if only the value from wikidata were put through url2, and the fallback value just displayed raw? &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 21:05, 26 November 2020 (UTC)
::: {{re|MSGJ}} I finally remembered what I'd been doing. The call to ur2 in WikidataIB was the prototype for an alternative function that I developed in [[Module:URL]]. I recommend using [[Template:URL2]]. It uses a lot of the code used by {{t|url}} but doesn't give error messages with a nil input (useful for Wikidata) and can take the output of {{tl|url}} as its input if an editor uses that as the local parameter.
:::* <code><nowiki>{{URL2|}}</nowiki></code> → {{URL2|}}
:::* <code><nowiki>{{URL2|www.portoftyne.co.uk/about-us/history/heritage-sites/heritage-sites}}</nowiki></code> → {{URL2|www.portoftyne.co.uk/about-us/history/heritage-sites/heritage-sites}}
:::* <code><nowiki>{{URL2|https://www.portoftyne.co.uk/about-us/history/heritage-sites/heritage-sites}}</nowiki></code> → {{URL2|https://www.portoftyne.co.uk/about-us/history/heritage-sites/heritage-sites}}
:::* <code><nowiki>{{URL2|{{url|https://www.portoftyne.co.uk/about-us/history/heritage-sites/heritage-sites}}}}</nowiki></code> → {{URL2|{{url|https://www.portoftyne.co.uk/about-us/history/heritage-sites/heritage-sites}}}}
::: The point is to use it when designing infoboxes, so in [[Template:Infobox bridge]] I would code the Website data like this:
:::* <code><nowiki>| data15 = {{URL2|{{{website|}}}}}</nowiki></code>
::: To use the {{q|P856}} property from Wikidata, you could write:
:::* <code><nowiki>| data15 = {{URL2|{{#invoke:WikidataIB|getValue|P856|name=website|fetchwikidata={{{fetchwikidata|}}}|onlysourced={{{onlysourced|no}}}|{{{website|}}}}}}}</nowiki></code>
::: or the equivalent short-form:
:::* <code><nowiki>| data15 = {{URL2|{{wdib|P856|name=website|fwd={{{fetchwikidata|}}}|osd={{{onlysourced|no}}}|{{{website|}}}}}}}</nowiki></code>
::: I probably should deprecate the url2 function in WikidataIB, as its only advantage is keeping the penicon from Wikidata out of the microformat that is created and I could replicate that in [[Module:URL]]. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 02:14, 27 November 2020 (UTC)
::::Just to confirm that {{tl|URL2}} was deployed successfully and seems to be working correctly. Thanks for looking into this &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 14:19, 9 December 2020 (UTC)
 
===Follow-up===
I've come across a problem:
*<code><nowiki>{{wdib|P856|qid=Q7123825|fwd=ALL|osd=no}}</nowiki></code> → {{wdib|P856|qid=Q7123825|fwd=ALL|osd=no}}
*But <code><nowiki>{{URL2|{{wdib|P856|qid=Q7123825|fwd=ALL|osd=no}}}}</nowiki></code> → {{URL2|{{wdib|P856|qid=Q7123825|fwd=ALL|osd=no}}}}
The File:OOjs should not be there &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 20:29, 2 January 2021 (UTC)
:I've removed URL2 from [[Template:Infobox bridge]] until this error is resolved &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 06:35, 3 January 2021 (UTC)
:I can't help but feel this could be coded more sensibly. Currently {{tl|wdib}} adds a pencil icon, then URL2 (I think) is trying to remove it again (and failing), and in the end we want a pencil icon. Would it not be better to read the data, then format it, then add the pencil icon on at the end? &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 07:03, 3 January 2021 (UTC)
:I've noticed that <code><nowiki>{{#invoke:WikidataIB |url2|... </nowiki></code> seems to be doing the job correctly &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 07:12, 3 January 2021 (UTC)
:*<code><nowiki>{{#invoke:WikidataIB |url2 |url={{wdib|P856|qid=Q7123825|fwd=ALL|osd=no}}}}</nowiki></code> → {{#invoke:WikidataIB |url2 |url={{wdib|P856|qid=Q7123825|fwd=ALL|osd=no}}}}
::
:: {{re|MSGJ|label=Martin}} yes, the url2 code in WikidataIB is more likely to handle the data from Wikidata correctly, but does a worse job with values entered locally. The problems I've been having is that I wanted to use the functionality of the tried and tested [[Module:URL]] to handle the potential input from WikidataIB, and I didn't write that module, so it doesn't perform exactly as I would have wished. I also assumed that I could take shortcuts and leave the pen icon code in place while Module:URL processed it. I've now done as you suggested, and stripped off the pen icon before passing the url to the main part of Module:URL, then adding it back when it is returned. The updated code is in [[Module:URL/sandbox]] (which is called from {{tl|URL2/sandbox}}}:
::* <code><nowiki>{{URL2|{{wdib|P856|qid=Q7123825|fwd=ALL|osd=no}}}}</nowiki></code> → {{URL2|{{wdib|P856|qid=Q7123825|fwd=ALL|osd=no}}}}
::* <code><nowiki>{{URL2/sandbox|{{wdib|P856|qid=Q7123825|fwd=ALL|osd=no}}}}</nowiki></code> → {{URL2/sandbox|{{wdib|P856|qid=Q7123825|fwd=ALL|osd=no}}}}
:: If you have a chance to test it, that would be helpful, but I think it should be fine to implement in the main [[Module:URL]] as it only affects the call from {{tl|URL2}}. Please let me know if that doesn't fix the problem now. Cheers --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 13:54, 3 January 2021 (UTC)
That seems to be working fine, thank you. If you don't mind me saying, it still seems rather cumbersome. Rather than
:Read URL → add pen → remove pen → format URL → add pen
would it not be possible to
:Read URL → format URL → add pen
I appreciate it would require another function in this module, but I think it would be more robust and less likely to break again in the future &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 08:11, 5 January 2021 (UTC)
:One thing I still don't understand is what caused it to break this time, because it was definitely working on 9 December when I followed your advice above &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 08:13, 5 January 2021 (UTC)
:
:: {{re|MSGJ|;abel=Martin}}. The problem is that "Read URL → add pen" takes place in Module:WikidataIB and "format URL" takes place in Module:URL. There is an intermediate step of "return wikitext from first module → pass wikitext to second module" that takes place in a template, outside of the modules. I don't want to duplicate all of the code in Module:URL here, nor does anyone want to duplicate getValue in Module:URL, so we work with a two-module solution. The way it currently works may appear cumbersome, but the pen icon requires not only the image used, but also the Wikidata link, which needs the item-ID and the property-ID. So it is actually quite elegant in passing not only the url itself, but also all of the other pieces of information from one module to another in a single piece of text. Of course, it requires a bit of unpacking on entry to the second module, but as you saw, that's not a big deal. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 16:21, 5 January 2021 (UTC)
:::Okay. I was assuming that this module could call that module to do the bits it needs. &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 16:28, 8 January 2021 (UTC)