Extension talk:Cargo
Keep historical query results on wiki
editI guess this could be achieved if Cargo could output unparsed wikitext. That could then be copy and pasted into the wiki page in place of the query. Is that possible?
Are there other ways? Writing this I wonder about the "subst" thing so I'll try that today. Jonathan3 (talk) 10:52, 12 January 2025 (UTC)
- Subst doesn't work, of course.
- I have a vague memory of using the "template" output type to achieve this with fairly simple queries, probably with "nowiki" tags etc. But that needed two separate queries. It would be cool if Cargo could just output that automatically with the change of a parameter.
- Thinking about it more, you wouldn't want it as an output type at all - you'd want it as a generic Cargo parameter like the existing "no html". Jonathan3 (talk) 12:17, 12 January 2025 (UTC)
- @Jonathan3: This does sound like an interesting idea. It'd be sort of similar to meta:User:ListeriaBot or wikidata:User:InteGraalityBot I guess, in that the wikitext result of the query would be stored as a page revision and so changes to the output could be tracked. Perhaps you could do it with an export format (e.g. a single-column CSV that could output a wikitext table row per result). Then a bot could fetch the export and write the results to the wiki. Sam Wilson 00:10, 13 January 2025 (UTC)
- Thanks. Being able to track changes to query output over time sounds even better. But what I had in mind in mind in my case was just a one-off wikitext rendering of the query result (using any output format) to know what it was on a certain date, and to avoid using Cargo from that point. Jonathan3 (talk) 07:27, 13 January 2025 (UTC)
I have a vague memory of using the "template" output type to achieve this with fairly simple queries, probably with "nowiki" tags etc. But that needed two separate queries.
- Yes, it works by wrapping the formatting template's name, such as
|template = Template-CargoRow
in<nowiki>
tags, but yeah, still requires more effort than is ideal. I've requested the same, for different reasons (debugging the interaction of Cargo with formatting templates, or queries within queries that use such templates etc., similar to how DPL3's|debug=5
works), but it hasn't been an option as of yet. We too often want to preserve one-time output without having another query to cache every 24 hours, though I'm sure there are other use-cases as well (I've come a cross a couple but can't recall atm). FrozenPlum (talk) 00:03, 16 January 2025 (UTC)- Thanks for that. I've just tried it and get a load of errors like "UNIQ--nowiki-00000001-QINU". It probably works all right on a simple Cargo query though. Jonathan3 (talk) 01:07, 22 January 2025 (UTC)
Example of "tree" output format
editIs there an example of this online? Thanks. Jonathan3 (talk) 00:57, 22 January 2025 (UTC)
- @Jonathan3: I was just playing around with it here: https://freopedia.org/Items But it seems that it's adding wikilinks for every value, which is annoying. I've tried doing things with CONCAT etc. but can't figure out how to customize the display of each node in the tree. Sam Wilson 01:08, 22 January 2025 (UTC)
Equivalent to SMW's "graph" format
editIs there any way to achieve this using Cargo, perhaps along with another extension?
https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Result_Formats
graph
- Graph format (Displays the relation between pages)
- Process format (Displays process graphs)
Jonathan3 (talk) 01:03, 22 January 2025 (UTC)
- Are there any actual examples for "format=process"? The examples I see that are ostensibly for the Process format all seem to use "format=graph". Anyway, the Graph format seems to be basically about creating flowcharts. You can do that in Cargo with the "bpmn" format, if that's all that is. Yaron Koren (talk) 04:35, 22 January 2025 (UTC)
- It would be for creating a sort of "family tree" of things, based on Cargo fields showing relationships between pages. Jonathan3 (talk) 08:50, 22 January 2025 (UTC)
In fact, something like this on Litmaps would be amazing: https://app.litmaps.com/preview/189679191 Jonathan3 (talk) 10:05, 22 January 2025 (UTC)
- That's definitely an informative graph, but something like that seems out of the scope of either SMW or Cargo - it would probably require custom coding. Yaron Koren (talk) 16:11, 22 January 2025 (UTC)
Storing and querying +Infinity and -Infinity
editWhen storing ranges from one number to another, is there a way to store +∞ and -∞ in Cargo in Float fields? And would it be possible to query for these ranges with something like this?
{{#cargo_query:tables=Ranges
|fields=Ranges._pageName
|where=Ranges.from > {{{from|'-Inf'}}} AND Ranges.to < {{{to|'+Inf'}}}
}}
Regadless of trying to store '-Inf'
or Inf
, it fails to make the row. Yonicstudios (talk) 18:35, 23 January 2025 (UTC)
- @Yonicstudios: Could you store null and take that to indicate an open-ended range? That's how I've done it in the past. Otherwise, add an extra boolean field e.g.
Ranges.from_infinity
and query that. Sam Wilson 23:33, 23 January 2025 (UTC)- Seems like
COALESCE(Ranges.from >= {{{from|NULL}}}, TRUE) AND COALESCE(Ranges.to <= {{{to|NULL}}}, TRUE)
is doing the trick! Yonicstudios (talk) 01:35, 25 January 2025 (UTC)
- Seems like
PHP Warning: Invalid argument supplied for foreach() in SpecialSwitchCargoTable.php on line 42
editPHP Warning: Invalid argument supplied for foreach() in /var/www/html/extensions/Cargo/includes/specials/SpecialSwitchCargoTable.php on line 42, referer: https://www.example.com/Special:SwitchCargoTable/Resources
Jonathan3 (talk) 10:33, 24 January 2025 (UTC)
Store value in main table on basis of query on parent table
editLet's say we have a Books table and an Editions table. The Editions table has a Publication date field. I'd like to store the earliest publication date as a date field in the Books table. But I can't get it to work. Any ideas? The date field just won't store at all. I've tried the normal way, and also using Lua.
(This is mainly to get round the fact that the Drilldown page will display a load of duplicates if it shows the Books and Editions tables.) Jonathan3 (talk) 00:25, 26 January 2025 (UTC)
- I guess it's just possible, as the #cargo_store happens before any #cargo_query. Does that sound right? Jonathan3 (talk) 01:13, 26 January 2025 (UTC)