Extension talk:Cargo

Latest comment: 7 days ago by FrozenPlum in topic Cannot change the label of the field

Adding part of page name as default value edit

In my wiki, to create a new page, you call the template for a new page with subst: first, so a basic page structure is inserted into the new page. I am now including a call to a cargo template with this basic structure template. Since all page names are structured the same way (street name street number (town), e.g. Main street 234 (Footown)), I would like to use the page name to prepopulate the fields street name, street number, and town. Since we are creating new pages not by form, but by red links or searches, the default parameter does not work. So, I am trying to set these values in the structure template. I can include the magic word {{PAGENAME}}, but once I use parser functions like #sub and #pos to select just the street name, the street number, and the town name, I get an error. Within the structure template my call looks like this:

{{cargotemplate
|street=''combination of #sub, #pos, and {{PAGENAME}}''
|street number=''combination of #sub, #pos, and {{PAGENAME}}''
|town=''combination of #sub, #pos, and {{PAGENAME}}''}}

Is a "prepopulation" like this possible? How would I do it? Sorry if this has been asked before. Dumpstar (talk) 15:58, 2 April 2024 (UTC)Reply

Is this a Cargo question? It sounds like just a core MediaWiki question. Yaron Koren (talk) 17:33, 2 April 2024 (UTC)Reply
Should string parser functions like #sub and #pos work as value inputs for a field in a Cargo template? Dumpstar (talk) 17:42, 2 April 2024 (UTC)Reply
I personally wouldn't use the term "Cargo template", but yes, I think so. Presumably the fact that you're using subst: complicates things, but that's not a Cargo issue. Yaron Koren (talk) 17:46, 2 April 2024 (UTC)Reply

CEIL function adding commas to number, bug? edit

I have a cargo query that does some math on the returned column value. When using the CEIL function, it appears that the returned number is formatted as a string and suddenly has commas in it. for example:

 {{#cargo_query:
 table=Prices
 |fields=IF(Price<0,0,Price)*1000
 |where=Item='apples' 
 |format=list
 |more results text=
 |no html
 |default=0
 }}

A query like this will return a value like 1234.56

But, if I want to round this up to the nearest whole number and change the fields parameter to:

 fields=CEIL(IF(Price<0,0,Price)*1000)

Now, I get a number back like 1,235

I need that comma to not be there. Any clues why this is happening and how to stop it? I have tested this with MySQL database and the number returned from a CEIL operation does not have a comma, so I am thinking Cargo may be adding it somehow.

My current work around is to use the #expr: ceil() parser function, but this complicates the code and makes it harder to maintain.

Why is the comma a problem? because this gets sent to another template that does more math on the value. AllenKll (talk) 19:17, 10 April 2024 (UTC)Reply

Right, Cargo views CEIL() as returning an integer, and then formats it accordingly. I think you can get around that by putting CONCAT( ) around the whole thing. Yaron Koren (talk) 19:30, 10 April 2024 (UTC)Reply
That worked. Seems hacky, but it's better than nothing. Thanks. AllenKll (talk) 19:55, 10 April 2024 (UTC)Reply
Great! I agree. Yaron Koren (talk) 20:41, 10 April 2024 (UTC)Reply

Query within a query? edit

Is it possible to use the result of one cargo query as an input to another query? In my mind, it would look something like this:

{{#cargo_query: table = Books
|fields = _pageName
|where = Author = '{{#cargo_query: tables = Books|fields = Author|where = _pageName='{{PAGENAME}}'}}'
}}

but using that format produces Error in "where" parameter: the string "--" cannot be used within #cargo_query.

Perhaps there is a better way of doing this that I'm just not thinking of. Penguinaut 22 (talk) 19:26, 14 April 2024 (UTC)Reply

I'm not surprised that that doesn't work, although I don't why it's giving that specific error message. Anyway, depending on what exact query you're trying to do, it might be possible to just do it via a "join". The second best option, I would say, is to move this query into a Lua module (if you have the Scribunto extension), and then store the first query's result in a variable, which you pass to the second query. Another option is to use the "template" format for the inner/first query, and then put the outer/second query into that "formatting" template. Yaron Koren (talk) 13:05, 15 April 2024 (UTC)Reply
Hmmm yes I didn't think of using the template format. That worked like a charm, thanks! Penguinaut 22 (talk) 02:03, 16 April 2024 (UTC)Reply

Output format = Wikitext edit

Is there any way to get Cargo to output a result in wikitext format? DPL3 can, for example using debug=5.

Use cases:

  • One-time (or expensive) query output whose result can be converted instead to wikitext.
  • Data that changes very infrequently, not warranting live query to repeatedly cache.
  • Swapping to wikitext, so data is still displayed while moving, renaming, or changing tables or columns, or especially migrating wiki locations, say if Cargo is not supported on a different wiki platform. Or converting key items (like main page queries) to wikitext if Cargo needs to be temporarily disabled.
  • For instant troubleshooting of Cargo interaction with template format, particularly when templates are used for formatting within templates, and queries within queries.

We largely use template format, with table headers in intro/outro, and <pre></pre> in |intro= and |outro= doesn't work, for obvious reasons. Next I'll try doing these tags in header, footer, and formatting template...-- that didn't work ofc (the values never got carried to the rows). Though setting |template = <pre>Template-CargoRow</pre> got us part of the way, thankfully carrying the values to the rows and outputting that as wikitext.

It just feels like Cargo, which works with wikitext input, should ideally be able to output to (pre-tag escaped) wikitext, on MediaWiki. A wikitext output format would be hugely appreciated, and solve several issues for us and perhaps for other users. Thanks!

FrozenPlum (talk) 00:05, 18 April 2024 (UTC)Reply

Cannot change the label of the field edit

I changed a couple of fields' labels in a template, but one of them cannot be processed and still shows the past title. What might cause this issue? Saving the template again and recreating the table doesn't help. 83.27.55.123 13:01, 24 April 2024 (UTC)Reply

A number of things could cause this... is your MediaWiki job queue empty, or how many jobs are in the queue? Your question may be impossible to answer without more information, or a link to your wiki's relevant pages. Normally provided/expected information:
  • MediaWiki, Cargo, and php versions, which you can get from your wiki's Special:Version page.
  • The template wikitext.
  • The page wikitext.
FrozenPlum (talk) 19:10, 24 April 2024 (UTC)Reply
Return to "Cargo" page.