Jump to content

Module talk:GetShortDescription

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

subst

[edit]

Hi there, just noticed a bit of oddness when using subst:

  • {{#invoke:GetShortDescription|main |name=Brazil |only=explicit}} → table
  • {{#invoke:GetShortDescription|main |name=Brazil}} → table
  • {{subst:#invoke:GetShortDescription|main |name=Brazil |only=explicit}}
  • {{subst:#invoke:GetShortDescription|main |name=Brazil}} → country in South America

Olivaw-Daneel (talk) 10:19, 23 January 2023 (UTC)[reply]

Huh. Looks like the last one is getting the wikidata, which means the penultimate, requesting only the explicit, is not getting the wikidata as a fallback and is thus empty. Sorry this came up now; I'm genuinely on my last legs for the day. I will attack it after some sleep. The explicit request requires preprocessing to handle weirdly configured (gotta account for weird stuff or it falls apart when it meets it) short desc templates, because lua's pattern matching is no match for grown-up regex. My guess is that the preprocessing is being bullied during the substitution. Possibly a frame problem; frames are weird. I'll figure it out ASAP. Fred Gandt · talk · contribs 10:57, 23 January 2023 (UTC)[reply]
Yeah; almost certainly a frame issue; via template it's fine:
  • {{subst:User:Fred Gandt/sandbox/Get short description |name=Brazil |only=explicit }} → table

Fred Gandt · talk · contribs 11:06, 23 January 2023 (UTC)[reply]

oh I derp; of course it just dumped the invoke on the page and left; I really need to sleep Fred Gandt · talk · contribs 11:09, 23 January 2023 (UTC)[reply]
The substitution happens before the preprocessing, so the preprocessing never happens. This leaves the found short desc template in its raw state and the pattern matching for the content fails, so we get the empty string for explicit, and the wikidata fallback otherwise. I will have to manually process the short desc template. This isn't so bad. But to put into perspective why I am not doing it right now; I just past 25 hours awake and it really feels like it. See ya tomorrow 😜 Fred Gandt · talk · contribs 13:04, 23 January 2023 (UTC)[reply]
Thanks, no hurry! Olivaw-Daneel (talk) 17:07, 23 January 2023 (UTC)[reply]
Btw, there's really no rush wrt to the GAN usage; don't want to hurry your development time. For {{GAN}} I was thinking of starting with the code used in {{Annotated link}}, as I've already gotten that to work, and it seems good enough to start with. We can later switch to your module version when it's ready; perhaps in sync with when Template_talk:Annotated_link#Module concludes. How does that sound to you? Olivaw-Daneel (talk) 04:29, 24 January 2023 (UTC)[reply]
Absolutely great if that works for you 😊 This all started to replace the template code of {{annotated link}} which is already horrible to maintain and will only get worse, so eventually that template will being using this module anyway 😁 Substituting is always a pain; the existence of various kludges to get around the issue is proof of it; safesubst, subst and all kinds of weird breaking of inclusion tags... The removal of preprocessing from the module will improve performance anyway, so it's good to do even if not for fixing the substitution issue. Fred Gandt · talk · contribs 04:44, 24 January 2023 (UTC)[reply]

Fixed in my test Module; needs more testing before pushing

  • {{subst:#invoke:User:Fred Gandt|main |name=Brazil |only=explicit}} → Country in South America
  • {{subst:#invoke:User:Fred Gandt|main |name=Brazil}} → Country in South America

Fred Gandt · talk · contribs 09:26, 24 January 2023 (UTC)[reply]

Pushed to release; nice little performance boost too:

Old

NewPP limit report
Parsed by mw1351
Cached time: 20230124093803
Cache expiry: 1814400
Reduced expiry: false
Complications: [vary‐revision‐sha1, vary‐page‐id, show‐toc]
CPU time usage: 0.276 seconds
Real time usage: 0.339 seconds
Preprocessor visited node count: 566/1000000
Post‐expand include size: 20103/2097152 bytes
Template argument size: 744/2097152 bytes
Highest expansion depth: 14/100
Expensive parser function count: 7/500
Unstrip recursion depth: 0/20
Unstrip post‐expand size: 4974/5000000 bytes
Lua time usage: 0.208/10.000 seconds
Lua memory usage: 15322087/52428800 bytes
Number of Wikibase entities loaded: 0/400
New

NewPP limit report Parsed by mw1478 Cached time: 20230124094020 Cache expiry: 1814400 Reduced expiry: false Complications: [vary‐revision‐sha1, vary‐page‐id, show‐toc] CPU time usage: 0.184 seconds Real time usage: 0.237 seconds Preprocessor visited node count: 566/1000000 Post‐expand include size: 20103/2097152 bytes Template argument size: 744/2097152 bytes Highest expansion depth: 14/100 Expensive parser function count: 7/500 Unstrip recursion depth: 0/20 Unstrip post‐expand size: 4974/5000000 bytes Lua time usage: 0.138/10.000 seconds Lua memory usage: 15322564/52428800 bytes

Number of Wikibase entities loaded: 0/400

Fred Gandt · talk · contribs 09:44, 24 January 2023 (UTC)[reply]

For the record: there's still a problem; it's just a different problem. Fred Gandt · talk · contribs 12:50, 24 January 2023 (UTC)[reply]

I think I fixed it; it's plugged into Module:Annotated link and the results are pretty nifty:

Code: {{#invoke:Annotated link|main |name=The Partisan |quote=yes |only=wikidata |desc_first_letter_case=upper |wedge=from the album ''[[Songs from a Room]]'' |aka=La Complainte du partisan |aka_lang=fr }}

Result: "The Partisan", also known as La Complainte du partisan, from the album Songs from a Room – Song composed by Anna Marly with lyrics by Emmanuel d'Astier de La Vigerie performed by Leonard Cohen

And yes, it works if it's substed 😉 Fred Gandt · talk · contribs 21:28, 24 January 2023 (UTC)[reply]

Alright, now testing Oceania, where the WP shortdesc is "Geographical region in the Pacific Ocean":
  • {{#invoke:GetShortDescription|main |name=Oceania |only=explicit}} → table
  • {{#invoke:GetShortDescription|main |name=Oceania}} → table
  • {{subst:#invoke:GetShortDescription|main |name=Oceania |only=explicit}}
  • {{subst:#invoke:GetShortDescription|main |name=Oceania}} → geographic region that includes Australasia, Melanesia, Micronesia and Polynesia
Olivaw-Daneel (talk) 07:29, 26 January 2023 (UTC)[reply]
I wonder when I broke it? Poor timing; I have to go out for a bit; I'll get right on it when I get home. Fred Gandt · talk · contribs 07:42, 26 January 2023 (UTC)[reply]
Fixed. I did check it was working, but obviously wasn't paying close enough attention. Fred Gandt · talk · contribs 10:30, 26 January 2023 (UTC)[reply]

I see "Result: table" a couple of times in the documentation - is that intentional? Olivaw-Daneel (talk) 05:31, 8 February 2023 (UTC)[reply]

It's a side effect of alterations not yet properly documented while I work on stabilising the configuration. Tables are returned by the invocation under some circumstances; that's actually inthe docs somewhere... It's on the todo list. Fred Gandt · talk · contribs 05:38, 8 February 2023 (UTC)[reply]

Using this module

[edit]

I see a lot of talk discussing the term "table" being the only thing returned from this, which is the problem I've run into. I see the discussion last was mentioned in February. Any progress, resolution, workaround, or tool that can get just the description returned from an annotated link? Thanks! GeogSage (⚔Chat?⚔) 22:06, 1 December 2023 (UTC)[reply]

The term "table" isn't returned; the module returns a table of data, kinda like an object in JavaScript, which will include various accessible bits of data depending on the use case and results. The word table shows up in text when this is directly invoked (I should get around to rewriting the docs some day) as an effect of stringification (the parser tries to make the best of the situation by stating that there's a table, bless it). Another module importing this'n would be able to probe the table for all the data it carries and use it as required, as Module:Annotated link does. If you tell me what you're trying to achieve, I can maybe help, perhaps by building another module that imports this'n, and outputs the description as raw text? Fred Gandt · talk · contribs 14:23, 2 December 2023 (UTC)[reply]
Thanks for the explanation! I'm currently trying to teach JavaScript to myself while winging the Wikipedia markup language.
My plan is mostly just trying to practice a bit and push things on tables. I'm trying to build a table for my user page for pages created, with columns for page, page description, date created, etc. Ideally, I'd like to pull the description directly for the table, rather then manually type out the short description, so it will update as time progresses.
So instead of:

{|class="wikitable sortable" style="width:99%;" ! style="text-align:center;"|Title ! stype="text-align:center;"|Year first published ! style="text-align:center;"|Short Description ! style="text-align:center;"|Notes |- | [[Concepts and Techniques in Modern Geography ] | 2022 | Series of geography publications | |- |}

The Markup would look something more like:

{|class="wikitable sortable" style="width:99%;" ! style="text-align:center;"|Title ! stype="text-align:center;"|Year first published ! style="text-align:center;"|Short Description ! style="text-align:center;"|Notes |- | [[Concepts and Techniques in Modern Geography ] | 2022 | {#invoke:GetShortDescription|main |name=Concepts and Techniques in Modern Geography |only=explicit} | |- |}

Again, just me messing around trying to play with things in layouts on my userpage that I can try to use later in more formal pages later. Not a huge emergency. GeogSage (⚔Chat?⚔) 17:36, 2 December 2023 (UTC)[reply]
If you add |stringify=True it returns text. Olivaw-Daneel (talk) 20:33, 2 December 2023 (UTC)[reply]
That's smart; I wish I'd thought of that! All jokes aside; I'm not functioning well right now, so thanks Olivaw :) Fred Gandt · talk · contribs 22:57, 2 December 2023 (UTC)[reply]
I put together the basic idea of how I wanted to use this module on my user page if you're interested in seeing how I wanted to use your work. I'm a native Python speaker, so pardon any sloppiness.
Ideally, I think this concept might be useful for tables for improving list articles. GeogSage (⚔Chat?⚔) 05:39, 3 December 2023 (UTC)[reply]
Awesome! Thanks this works fantastic! I really appreciate the help! GeogSage (⚔Chat?⚔) 01:52, 3 December 2023 (UTC)[reply]

I think it would be better if the invokable version of this module always returned a string rather than a table, because it is not possible to work with tables in wikicode. When requiring it in other modules, than the current table output would be useful — Martin (MSGJ · talk) 14:24, 21 August 2024 (UTC)[reply]

How does this differ from the older Module:Get short description? Should the two be merged? Dpleibovitz (talk) 00:55, 1 March 2024 (UTC)[reply]

That one was written earlier but this one seems to have many more features than that one. Pinging @Qwerfjkl for comment — Martin (MSGJ · talk) 14:19, 21 August 2024 (UTC)[reply]
Martin, I'm indifferent, and my module is too inefficient to really be useful. Note that Trappist the monk wrote a more efficient version in the sandbox. — Qwerfjkltalk 14:44, 21 August 2024 (UTC)[reply]
I'm not sure how efficient this module is either, but searching the contents of a page is always time-consuming. @Trappist the monk any comments on this? — Martin (MSGJ · talk) 17:10, 21 August 2024 (UTC)[reply]
Module:Get short description is inefficient because of lines 11–13. At line 11, the module fetches the content of the target article/page. At line 13, the module preprocesses the article/page. That means that it spends a lot of time doing that which need not be done when fetching a short description. Preprocessing can be likened to the delay you see between clicking the Publish changes button and your browser beginning to display the rendered page. This module then reads the preprocess rendering and looks for the html that was rendered by the {{short description}} template (a <div>...</div> tag), extracts the description and is done.
The sandbox version also fetches the article/page content. Instead of preprocessing to html, the sandbox simply hunts for the {{short description}} wikitext. Usually that is the first template in an article per WP:SDPLACE. Sometimes, the template name in wikitext is a redirect so the sandbox repeats the search for each known redirect until a short description template is found or it runs out of redirects.
Did I answer your questions?
Trappist the monk (talk) 17:36, 21 August 2024 (UTC)[reply]

Redirects

[edit]

I think this module will follow redirects, which may not always be desirable. For example {{#invoke:GetShortDescription|main|name=Liam Ashley|stringify=true}} gives "2006 murder in Auckland" which is the short description of Murder of Liam Ashley, but I would prefer it take the Wikidata label from Liam Ashley (Q129493533) which is "murder victim" — Martin (MSGJ · talk) 14:17, 21 August 2024 (UTC)[reply]