Module talk:WikidataIB/Archive 7
Appearance
![]() | This is an archive of past discussions about Module:WikidataIB. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 | ← | Archive 5 | Archive 6 | Archive 7 | Archive 8 |
Add more wbr in URLs
{{edit template-protected}}
The current url2
function only adds soft line-breaks after dots in the URL. This is insufficient for things as simple as http://opensource.org/licenses/HPND when put in an infobox.
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 p.url2
should be rewritten as:
local fmt_url = require([[Module:URL]])._url -- put this near the top
-------------------------------------------------------------------------------
-- url2 takes a parameter url= that is a proper url potentially followed by an edit icon
-- It returns a wikitext representation with line-wraps for infobox use.
-- If no parameter is supplied, it returns nothing.
-- This is the equivalent of Template:URL
-- but it keeps the "edit at Wikidata" pen icon out of the microformat.
-- Usually it will take its url parameter directly from a Wikidata call:
-- e.g. {{#invoke:WikidataIB |url2 |url={{wdib |P856 |qid=Q23317 |fwd=ALL |osd=no}}
-------------------------------------------------------------------------------
-- Dependencies: Module:URL
-------------------------------------------------------------------------------
p.url2 = function(frame)
local txt = frame.args.url or ""
if txt == "" then return nil end
local url, icon = txt:match("(.+) (.+)")
return fmt_url(url or txt) .. (icon and ' ' .. icon or "")
end
Artoria2e5 🌉 12:37, 15 July 2020 (UTC)
- 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 {{URL}} which prompted the fork to {{URL2}} was that passing a blank url causes an error message by default in URL, but not in URL2:
{{#invoke:URL |url | }}
→{{URL|example.com|optional display text}}
{{#invoke:WikidataIB |url2 |url= }}
→
- There is little point in re-using the code from Module:URL if it's going to reintroduce the problem that the fork was intended to fix. If the extra functionality required is simply to add word break opportunities at forward-slashes, then simplistically, changing to
local disp, _ = addr:gsub("%.", "<wbr>."):gsub("/", "<wbr>/")
- would seem to me to achieve the desired result. Similarly, fragments could be accommodated, but I don't see the use-case for that in infoboxes. --RexxS (talk) 20:10, 15 July 2020 (UTC)