Content deleted Content added
m Archiving 1 discussion(s) from Module talk:WikidataIB) (bot |
Fix Linter errors. |
||
(8 intermediate revisions by 3 users not shown) | |||
Line 8:
Since the function already references [[Module:URL]], a much better way to do it would be to just reuse what the Module exports. The block starting with {{code|p.url2}} should be rewritten as:
<
local fmt_url = require([[Module:URL]])._url -- put this near the top
Line 28:
return fmt_url(url or txt) .. (icon and ' ' .. icon or "")
end
</
:
: The module doesn't currently reference [[Module:URL]] and it's preferable to reduce the number of external dependencies, rather than increase them unnecessarily. One of the issues with using {{tl|URL}} which prompted the fork to {{tl|URL2}} was that passing a blank url causes an error message by default in URL, but not in URL2:
Line 263:
::: I think the solution to the locally supplied image is to wrap the wikidata call for the caption in something like <code><nowiki>{{#if:{{{image|}}} |{{caption|}} |{{wdib |fwd=ALL |osd=n |P18 |qual=P2096 |qualsonly=y |qid={{{qid|}}} }}</nowiki></code> which would only use a locally supplied caption with a locally supplied image.
::: There's a constraint on Wikidata that {{q|P18}} should have a single-value, but it does get ignored. You should always limit the number of images returned by setting {{para|maxvals|1}} if you're using the usual image syntax. That will return the first image and the first media legend, so it should avoid the potential for having a caption not associated with the image (probably!). --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 20:40, 30 September 2020 (UTC)
== Help! ==
There are a problem, I can't work it out. Maybe I need <code>getPropOfProp</code>, or perhaps <code>getQualifierValue</code> or <code>getValueByQual</code> or even <code>getSumOfParts</code>. The trouble there is that doesn't seem to be much in the way of documentation.
The problems is of a (Philippine) place, say {{Q|Q13786}} with property {{Q|P610}} with one or more instances of places as qualifier, for instance {{Q|Q6922008}} which will each have a qualifier of {{Q|P2044}}. So how can I show direct elevation? → Cebu 1097 m
[[User:Not Samuel Pepys|Not Samuel Pepys]] ([[User talk:Not Samuel Pepys|talk]]) 14:16, 23 October 2020 (UTC)
:
: {{re|Not Samuel Pepys}} For {{q|Q13786}} with property {{q|P610}}, you can find the value of the qualifier {{q|P2044}} like this:
:* <code><nowiki>{{#invoke:WikidataIB |getValue |P610 |fwd=ALL |osd=n |noicon=t |qual=P2044 |qid=Q13786}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P610 |fwd=ALL |osd=n |noicon=t |qual=P2044 |qid=Q13786}}
: If you just want the value of of the qualifier without the property value, then add the {{para|qualsonly|true}} parameter:
:* <code><nowiki>{{#invoke:WikidataIB |getValue |P610 |fwd=ALL |osd=n |noicon=t |qual=P2044 |qualsonly=t |qid=Q13786}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P610 |fwd=ALL |osd=n |noicon=t |qual=P2044 |qualsonly=t |qid=Q13786}}
: If you want the unit abbreviated or conversions, let me know as that will require a small patch to enable abbreviations and conversions for qualifiers using getValue.
: Optionally, you can fetch the values of properties of {{q|Q6922008}} by using getPropOfProp from {{q|Q13786}} like this:
:* <code><nowiki>{{#invoke:WikidataIB |getPropOfProp |prop1=P610 |fwd=ALL |osd=n |noicon=t |prop2=P2044 |qid=Q13786}}</nowiki></code> → {{#invoke:WikidataIB |getPropOfProp |prop1=P610 |fwd=ALL |osd=n |noicon=t |prop2=P2044 |qid=Q13786}}
: That works because {{q|P610}} is stored in Wikidata both as a qualifier in the {{q|Q13786}} entry ''and'' as a property in the {{q|Q6922008}} entry.
: Unit abbreviations and conversions already work for getPropOfProp:
:* <code><nowiki>{{#invoke:WikidataIB |getPropOfProp |prop1=P610 |fwd=ALL |osd=n |noicon=t |prop2=P2044 |uabbr=t |qid=Q13786}}</nowiki></code> → {{#invoke:WikidataIB |getPropOfProp |prop1=P610 |fwd=ALL |osd=n |noicon=t |prop2=P2044 |uabbr=t |qid=Q13786}}
:* <code><nowiki>{{#invoke:WikidataIB |getPropOfProp |prop1=P610 |fwd=ALL |osd=n |noicon=t |prop2=P2044 |conv=y |qid=Q13786}}</nowiki></code> → {{#invoke:WikidataIB |getPropOfProp |prop1=P610 |fwd=ALL |osd=n |noicon=t |prop2=P2044 |conv=y |qid=Q13786}}
== I don't come here often. Is it me, or are there a couple of problemettes? ==
1 Minor problem in climate<br />
::<nowiki>A1 {{safesubst:#invoke:WikidataIB |getValue |P2564|qid=Q315703|fwd=ALL|sn=true|osd=no|noicon=true}}</nowiki><br />
:::gives the right answer [[Tropical rainforest climate|Af]]<br />
:::except that I want it unlink ...<br />
::<nowiki>A2 {{safesubst:#invoke:WikidataIB |getValue |P2564|qid=Q315703|fwd=ALL|sn=true|osd=no|noicon=true|linked=no}}</nowiki><br />
:::tropical rainforest climate<br />
:::but it no longer gives the shortname.<br />
::<nowiki>short name (sn)</nowiki> has not enough description in main document, and none at all in the sandboxes.<br />
2 Minor problem in scaling money<br />
::<nowiki>B1 ₱{{safesubst:#invoke:WikidataIB |getValue |P3087|qid=Q315771|fwd=ALL|rank=b|osd=no|noicon=true|su=false}}</nowiki><br />
:::unscaled→ ₱171,234,667.17<br />
::<nowiki>B2 ₱{{safesubst:#invoke:WikidataIB |getValue |P3087|qid=Q315771|fwd=ALL|rank=b|osd=no|noicon=true|scale=3|su=false}}</nowiki><br />
:::thousands→ ₱171,235 thousand<br />
:::integer only<br />
::<nowiki>B3 ₱{{safesubst:#invoke:WikidataIB |getValue |P3087|qid=Q315771|fwd=ALL|rank=b|osd=no|noicon=true|scale=6|su=false}}</nowiki><br />
:::millions→ ₱171.2 million<br />
:::has one decimal, not integer<br />
::<nowiki>B4 ₱{{safesubst:#invoke:WikidataIB |getValue |P3087|qid=Q315771|fwd=ALL|rank=b|osd=no|noicon=true|scale=9|su=false}}</nowiki><br />
:::billions→ ₱0.1712 billion<br />
:::has four decimals, not integer<br />
::<nowiki>BY ₱{{safesubst:#invoke:WikidataIB |getValue |P3087|qid=Q315771|fwd=ALL|rank=b|osd=no|noicon=true|scale=a|su=false}}</nowiki><br />
:::auto scaling→ ₱171,235 thousand<br />
:::it doesn't seem correct - scaling here should be <nowiki>scale=6</nowiki>
::<nowiki>BZ ₱{{safesubst:#invoke:WikidataIB |getValue |P3087|qid=Q1889017|fwd=ALL|rank=b|osd=no|noicon=true|scale=a|su=false}}</nowiki><br />
:::auto scaling→ ₱1,590 million<br />
:::it doesn't seem correct - scaling here should be <nowiki>scale=9</nowiki><br />
:[[Special:Contributions/46.69.62.85|46.69.62.85]] ([[User talk:46.69.62.85|talk]]) 12:24, 16 October 2020 (UTC)
:'''2'''
{|
| style="text-align:left;" | 2a ''rounding''
|-
| style="vertical-align:top;max-width:12.5em;"| I think it's trying to be too clever.<br />See [[James Thurber]] – The Bear Who Let lt Alone
| style="text-align:left;" |<poem><code>
-- round scaled numbers to integers or 4 sig fig
if (scale > 0 or sc == "a") then
if amount < 1e4 then
amount = roundto(amount, 4)
else
amount = math.floor(amount + 0.5)
end
end</code></poem>
|-
| I think it should all end up with 1D except scale 0, nothing to do with sig figs
|-
| style="text-align:left;" | 2b ''auto scale''
|-
| style="vertical-align:top;"| It seems wrong – this is the part:
| style="text-align:left;" |<poem><code>
if sc == "a" then
-- automatic scaling
if amount > 1e15 then
scale = 12
elseif amount > 1e12 then
scale = 9
elseif amount > 1e9 then
scale = 6
elseif amount > 1e6 then
scale = 3
else
scale = 0
end
else
scale = tonumber(args.scale) or 0
if scale < 0 or scale > 12 then scale = 0 end
scale = math.floor(scale/3) * 3
end
local factor = 10^scale
amount = amount / factor</code></poem>
|-
| style="vertical-align:top;"| I think it should be changing along
| style="text-align:left;" |<poem><code>
if sc == "a" then
-- automatic scaling
if amount > 1e12 then
scale = 12
elseif amount > 1e9 then
scale = 9
elseif amount > 1e6 then
scale = 6
elseif amount > 1e3 then
scale = 3
else
scale = 0
end
else
scale = tonumber(args.scale) or 0
if scale < 0 or scale > 12 then scale = 0 end
scale = math.floor(scale/3) * 3
end
local factor = 10^scale
amount = amount / factor</code></poem>
|-
| although I don't know why very large numbers are not given any scaling.<br />See [[Long and short scales]]. And the coding is very slow.
|}
: 1 A1: There is no use-case for an unlinked short name. Displaying something like '''Climate''' Af is nonsensical to most readers, whereas '''Climate''' [[Tropical rainforest climate|Af]] allows the reader a chance to learn what the classification is. Your desire for unlinked text is not helpful.
: 1 A2: because there is no use-case for an unlinked short name, I only coded fetching a short name when the item is linked.
: If you don't think there's enough documentation on short name, please feel free to add something to [[Module:WikidataIB/doc]] which is ''not'' protected.
: 2 B1 to B4 and 2a: Because these values are for use in infoboxes, the space is constrained. What is the point in quoting cents when we have values in the millions of dollars? I simply disagree with your suggestion that we should normally be placing values into infoboxes with 11 significant figures. I think 171.2 billion is far superior in an infobox to 171,234,667.17 in 99.9% of cases. Rounding these values to four sig fig is a good compromise between precision and use of available space. I completely reject your suggestion to round to 1 decimal place. If we scale 1,149 on my scheme to scale=3, we get 1.149 thousand. On your scheme, we get 1.1 thousand - that's a relatively big error.
: 2 BY, BZ and 2b: If we use autoscaling, I would expect 1,149 to display as 1,149, not as 1.149 thousand, which takes up far more space and is not in line with common usage. I disagree that is being "too clever". I'm ambivalent about bigger values, so I don't have a problem with displaying 1,149,000 as either 1.149 million or 1,149 thousand. In any given case, the autoscaling can be overriden by setting a scale value anyway.
: Very big numbers are ambiguous when using trillion, etc. and who understands quadrillion, quintillion and so on? They could easily be implemented, but how much use would they get? Do you have examples of their use in infoboxes?
: As for the coding being very slow, please feel free to re-write the module in faster code. There are several sandboxes you can use to demonstrate your improvements. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 22:38, 11 November 2020 (UTC)
== Another problem ==
<nowiki>{{#invoke:WikidataIB |getValue |P1082||qid=Q2673519|fwd=ALL|rank=p n|osd=no|noicon=true|sorted=yes|qsorted=yes|maxvals=2|list=p-1|qo=true|qual=P585}}</nowiki> gives {{#invoke:WikidataIB |getValue |P1082||qid=Q2673519|fwd=ALL|rank=p n|osd=no|noicon=true|sorted=yes|qsorted=yes|maxvals=2|list=p-1|qo=true|qual=P585}} which is what I want. But giving full date <nowiki>{{#invoke:WikidataIB |getValue |P1082||qid=Q2673519|fwd=ALL|rank=p n|osd=no|noicon=true|sorted=yes|qsorted=yes|maxvals=2|list=p-1|qo=true|qual=P585</nowiki>'''|qdf=dmy'''<nowiki>}}</nowiki> (and / or |df=dmy) changes the date: {{#invoke:WikidataIB |getValue |P1082||qid=Q2673519|fwd=ALL|rank=p n|osd=no|noicon=true|sorted=yes|qsorted=yes|maxvals=2|list=p-1|qo=true|qual=P585|qdf=dmy}}<br />Help! [[User:Not Samuel Pepys|Not Samuel Pepys]] ([[User talk:Not Samuel Pepys|talk]]) 17:27, 11 November 2020 (UTC)
:
: {{re|Not Samuel Pepys}} WikidataIB uses the default sorting in Lua for property and qualifier values, so if you set {{para|sorted|yes}}, it will sort the output values alphanumerically. The setting of {{para|qsorted}} is irrelevant because there is not more than one qualifier value in each case.
: If we go through the steps in refining the values from {{q|Q2673519}}, you can see what's happening. This is with {{para|df|y}} (because the default for qualifiers is year-only):
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |qual=P585}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |qual=P585}}
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585}}
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y}}
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y |list=p-1}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y |list=p-1}}
: This is with {{para|df|dmy}}:
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |qual=P585 |qdf=dmy}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |qual=P585 |qdf=dmy}}
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585 |qdf=dmy}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585 |qdf=dmy}}
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y |qdf=dmy}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y |qdf=dmy}}
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y |list=p-1 |qdf=dmy}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=p n |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y |list=p-1 |qdf=dmy}}
: As you can see, 2010 sorts before 2015, but 1 August 2015 sorts before 1 May 2010. I need to write a new sorting routine to replace the default for use when the values are dates. Sorry, but that's a bit more of a job and may take me a while to implement. For now, I'd recommend using the preferred value from Wikidata:
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=best |osd=no |noicon=true |qual=P585 |qdf=dmy}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=b |osd=no |noicon=true |qual=P585 |qdf=dmy}}
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=best |osd=no |noicon=true |sorted=yes |qual=P585 |qdf=dmy}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=b |osd=no |noicon=true |sorted=yes |qual=P585 |qdf=dmy}}
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=best |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y |qdf=dmy}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=b |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y |qdf=dmy}}
:* <code><nowiki>{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=best |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y |list=p-1 |qdf=dmy}}</nowiki></code> → {{#invoke:WikidataIB |getValue |P1082 |qid=Q2673519 |fwd=ALL |rank=b |osd=no |noicon=true |sorted=yes |qual=P585 |qo=y |list=p-1 |qdf=dmy}}
: I'll make sure it's on the to-do list. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 21:58, 11 November 2020 (UTC)
::I think the "easiest" would be using Y F d (in #time: syntax). As long as it was the right date, #time: would use what parts it needs without knowing which order the parts are. All my questions are connected with {{tlx|PH wikidata}} – [[User:Not Samuel Pepys|Not Samuel Pepys]] ([[User talk:Not Samuel Pepys|talk]]) 23:33, 11 November 2020 (UTC)
::: The module uses [[Module:Complex date]] to render dates in whatever language is required, and using <code>mw.language:formatDate</code> (the Scribunto implementation of the #time parser function) would break that functionality as well as failing when qualifiers like 'circa' are added. If I still had the value of the timestamp available when doing the sorting, I could sort that alphanumerically and that would be easiest way. I'm considering prepending the timestamp to the formatted date and then stripping it off after sorting as a solution to the problem. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 00:21, 12 November 2020 (UTC)
== Wrong default for display parameter passed to Coord template by getCoords ==
Right now if you use the getCoords function and don't explicitly provide a display parameter, it sets a default of "inline, title". This is unexpected and unnecessary since {{tl|Coord}} has a pre-existing default for display which is "inline". Thus, getCoords doesn't need to pass its own default display parameter. And even if it did, it should be "inline", not "inline, title". This is causing confusion for people who are migrating templates to use WikidataIB instead of {{tl|Coord}} directly: [https://en.wikipedia.org/wiki/Module_talk:Coordinates#Duplication_of_coordinates][https://en.wikipedia.org/wiki/Template_talk:Infobox_bridge#Multiple_coordinates]. [[User:Kaldari|Kaldari]] ([[User talk:Kaldari|talk]]) 04:10, 8 December 2020 (UTC)
:
: {{re|Kaldari}} thanks for the bug report. In the sandbox I checked the result of not providing a default from getCoords and it looks fine - see [[Module talk:WikidataIB/sandbox/testing #Coordinates]]. I've now made that version live, so please ping me if any errors show up. Cheers --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 20:43, 8 December 2020 (UTC)
== Visibility of pen icon ==
It seems Wikidata has a bit of a problem with drive-by vandalism, and the prominent pen icon may be contributing to that. (I know {{Q|Q83125}} was suffering badly after the pen icons were added, to the extent that this item is now protected.) I was going to suggest suppressing these icons for non-confirmed users, if this is possible. — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 12:03, 15 December 2020 (UTC)
: {{re|MSGJ}} I added the class "autoconfirmed-show" to the pen icon in the sandbox and tested it by checking against an unconfirmed alt account and when not logged in. It looked fine, so I've made the edit live. It works for [[Tower Bridge]], so I guess we just have to wait to see if there are objections from elsewhere. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 17:46, 15 December 2020 (UTC)
::Thanks. It's seems a reasonable precaution, and readers don't want to see all those icons anyway. — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 19:23, 15 December 2020 (UTC)
== Returning a qualifier only for values where a second qualifier matches a given qval? ==
Currently if a statement has multiple values, getQualifierValue will return the requested qualifier for each of those values. Could a variant be made that only returns a the qualifier for one the values where a second qualifier matches a given qval. For example,
{{Q|Q38382414}} is an {{Q|Q1607826 }} for multiple journals. I would like to retrieve only the {{Property|P580}} for the journal {{Q|Q24657325}}.
{{collapse|text=
<code><nowiki>{{#invoke:WikidataIB |getQualifierValue |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |fetchwikidata=ALL |onlysourced=no |noicon=true}}</nowiki></code>
*'''returns:''' {{#invoke:WikidataIB |getQualifierValue |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |fetchwikidata=ALL |onlysourced=no |noicon=true}}
Ideally, would like:<br>
<code><nowiki>{{#invoke:WikidataIB |getQualifierValue |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 </nowiki>'''{{!}}qualtocheck=P642 {{!}}qualtocheckval=Q24657325'''<nowiki> |fetchwikidata=ALL |onlysourced=no |noicon=true}}</nowiki></code>
*'''returns:''' 24 July 2016
|example syntax}}
Would that be possible to implement? [[User:Evolution and evolvability|T.Shafee(Evo<small>&</small>Evo)]]<sup>[[User talk:Evolution and evolvability|talk]]</sup> 07:24, 3 December 2020 (UTC)
:
: {{re|Evolution and evolvability}} it would be possible, I think, but I'll need an uninterrupted session to work up the code. I try to find a slot in the next week or so. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 20:46, 8 December 2020 (UTC)
::{{re|RexxS}} Thank you so much in advance! Appreciated as always. [[User:Evolution and evolvability|T.Shafee(Evo<small>&</small>Evo)]]<sup>[[User talk:Evolution and evolvability|talk]]</sup> 22:56, 8 December 2020 (UTC)
{{od}}
{{re|Evolution and evolvability}} I'm loathe to implement two more parameters, so I've implemented a filter parameter that looks like this: <code>|filter = P642==Q22674854</code>. It seems to work, but I'd prefer to see if it fits your needs and doesn't have bugs before I incorporate it into the main module.
In {{q|Q38382414}}: property {{q|P39}} equal to {{q|Q1607826}} has multiple {{q|P580}} qualifiers. A filter can pick one of them.
Examples 2 and 3 filter on: (2) {{q|Q1607826}} {{q|P642}} {{q|Q22674854}}, and (3) {{q|Q1607826}} {{q|P642}} {{q|Q939416}}, returning the {{q|P580}} where the filter matches.
{| class="wikitable"
|+ Demo of filter
|-
! scope="col" | Code
! scope="col" | Result
|-
| <code><nowiki>{{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580}}</nowiki></code> || {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580}}
|-
| <code><nowiki>{{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P642==Q22674854}}}</nowiki></code> || {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P642==Q22674854}}
|-
| {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P642==Q939416}} || {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P642==Q939416}}
|}
If you get a chance, please test it out. I know you can provoke errors if you give nonsensical values for the filter, and I've tried to catch them, but I can't guarantee I've found them all. Cheers --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 20:42, 15 December 2020 (UTC)
::Excellent! I can completely understand the want to avoid additional parameters where possible. For the uses I've tried, it out for it seems to work well. The only case it couldn't handle have been:
::* using a filter to try to find missing fields via their empty string return (could be very useful for omitting things with end dates to include only current items):
:::<code><nowiki>{{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P582==}}</nowiki></code>
::*using a date as the filter and a 'greater than' <code><=</code> or 'less than' <code>>=</code> comparator (useful for uncluding things that were the start and end dates are outside a given period:
:::<code><nowiki> {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P642 |filter=P580>=2016-01-01}}</nowiki></code>
::*Could be useful to have an antifilter implemented <code>!=</code>
:::<code><nowiki> {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P642!=Q22674854}}</nowiki></code>
::However, already very useful for the sort of filtering I'm lookng to start with. [[User:Evolution and evolvability|T.Shafee(Evo<small>&</small>Evo)]]<sup>[[User talk:Evolution and evolvability|talk]]</sup> 06:03, 16 December 2020 (UTC)
:::
::: {{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> [[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> <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]] — Martin <small>([[User:MSGJ|MSGJ]] · [[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? — Martin <small>([[User:MSGJ|MSGJ]] · [[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 — Martin <small>([[User:MSGJ|MSGJ]] · [[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 — Martin <small>([[User:MSGJ|MSGJ]] · [[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
<span><!--span tag inserted here October 2022 to prevent spurious Linter error-->{{#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? — Martin <small>([[User:MSGJ|MSGJ]] · [[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 — Martin <small>([[User:MSGJ|MSGJ]] · [[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 — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 20:29, 2 January 2021 (UTC)
:I've removed URL2 from [[Template:Infobox bridge]] until this error is resolved — Martin <small>([[User:MSGJ|MSGJ]] · [[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? — Martin <small>([[User:MSGJ|MSGJ]] · [[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 — Martin <small>([[User:MSGJ|MSGJ]] · [[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 — Martin <small>([[User:MSGJ|MSGJ]] · [[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 — Martin <small>([[User:MSGJ|MSGJ]] · [[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. — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 16:28, 8 January 2021 (UTC)
|