Extension talk:Cargo

What does Allowed Values actually do?
I tried out Extension:Cargo/Storing_data allowed values e.g.  . I was still able to assign the field a value not on the list. So what does the parameter actually do? Is it only to feed PageForms? Tenbergen (talk) 05:01, 10 December 2021 (UTC)

Table recreation doesn't seem to work in 1.37
If I recreate a table in MW1.37 and then run the runJobs.php to speed it up I get the following error, repeatedly: 2021-11-23 05:50:22 cargoPopulateTable dbTableName=Project replaceOldRows= namespace=0 title= requestId=YZyBEawni10429LV0Poz2AAAAFM (id=14240,timestamp=20211123055010) STARTING 2021-11-23 05:50:22 cargoPopulateTable dbTableName=Project replaceOldRows= namespace=0 title= requestId=YZyBEawni10429LV0Poz2AAAAFM (id=14240,timestamp=20211123055010) t=0 error=InvalidArgumentException: The given PageIdentity does not represent a proper page The table never gets populated. If I switch back to my backup directory from pre-upgrade (MW1.36.2) the table recreate works. This is using Cargo	3.0 (ee250d4) 07:36, 22 November 2021 Tenbergen (talk) 06:00, 23 November 2021 (UTC)


 * Thanks for that bug report. This was indeed a real issue, and it appears to have been caused by a bug in MediaWiki itself, surprisingly enough. I just checked in a fix to Cargo to get around it, so if you get the latest Cargo code, it should work with MW 1.37. Yaron Koren (talk) 16:09, 25 November 2021 (UTC)
 * Thank you for this, I'm on a wiki farm which just upgraded to 1.37, and found the same error. Came straight here, I can pass this along to admins there (looks like was reported at T296435 and fixed here--thanks Yaron!). FrozenPlum (talk) 07:57, 9 December 2021 (UTC)

Problem with multiple joins
Hello,

I have been working on code for a book catalog. I have hit the following small situation where I cannot seen to add another table in a cargo_query to provide the information I need.

The query

works and produces the expected output.

When I add the additional table Books, and the additional join expression Books._ID=Books__Genres._rowID  in order to extract the book title it likes like this:

it throws an error Error 42P01: ERROR: invalid reference to FROM-clause entry for table "cargo__Genres" LINE 1: ... LEFT OUTER JOIN "cargo__Genres__Gen_parent" ON (("cargo__Ge...

^

HINT: There is an entry for table "cargo__Genres", but it cannot be referenced from this part of the query. Function: CargoSQLQuery::run Query: SELECT "_pageName" AS "Genre","cargo__Books__Genres"."_rowID" AS "_rowID","cargo__Books"."_pageName" AS "_pageName" FROM "cargo__Genres","cargo__Books" LEFT OUTER JOIN "cargo__Genres__Gen_parent" ON (("cargo__Genres"."_ID"="cargo__Genres__Gen_parent"."_rowID")) LEFT OUTER JOIN "cargo__Books__Genres" ON (("cargo__Genres"."_pageName"="cargo__Books__Genres"."_value") AND ("cargo__Books"."_ID"="cargo__Books__Genres"."_rowID")) WHERE "cargo__Genres__Gen_parent"."_value" = 'math' ORDER BY "_pageName","cargo__Books__Genres"."_rowID","cargo__Books"."_pageName" LIMIT 100

Could you please help. I am not sure how to fix this. I have googled and the best I saw is that I am mixing explicit and implicit joins andI am now really confused.

Thanks. Lbundle (talk) 02:13, 23 November 2021 (UTC)


 * Sorry about that - there's nothing actually wrong with your query (and I'm glad you figured out how to get around the limitations of HOLDS). Sometimes the handling of #cargo_query doesn't work correctly if the "tables" and "join on" arguments are not in a specific order, and that is the case here. After some trial and error, I believe the following values for those two parameters will work:

tables=Books, Books__Genres, Genres, Genres__Gen_parent |join on=Books._ID=Books__Genres._rowID, Books__Genres._value=Genres._pageName, Genres._ID=Genres__Gen_parent._rowID


 * This is obviously a bug in Cargo, which I hope will get fixed soon. Yaron Koren (talk) 18:08, 24 November 2021 (UTC)


 * Thank you very much! This ordering you proposed worked. Lbundle (talk) 03:26, 28 November 2021 (UTC)

“This is not allowed in Cargo API queries”
''Exception caught: Error: Field alias "_pageID" starts with an underscore (_). This is not allowed in Cargo API queries.'' But why? --StasR (talk) 20:11, 8 November 2021 (UTC)


 * I don't remember now, and it doesn't look like I wrote it down anywhere. I think it's a technical issue with MediaWiki's API handling. Yaron Koren (talk) 14:57, 9 November 2021 (UTC)

How to retrieve _pageTitle in a template?
How on earth does one retrieve _pageTitle, inside of a template used by cargo to format a row? I could find no example of this... figured it out a long time ago by trial and error, but can't seem to figure it out again, and I no longer have a reference. Any help with this would be much appreciated. I'm used named parameters, so in a template I'm using things such as rather than. I can't figure out how in the word to retrieve this, tried, , , , etc., nothing works. I need to use named parameters, is that my issue??!? Thanks TiltedCerebellum (talk) 04:35, 10 November 2021 (UTC)


 * Nm, finally figured out what I was doing wrong. In the cargo statement  and in the surrogate template, . Presuambly the same can be done with   and in the surrogate template, . TiltedCerebellum (talk) 04:44, 10 November 2021 (UTC)

Nest cells for querying
This may not be a problem with with querying on-wiki specifically, but when querying externally, sometimes, having hundreds of columns may not be the best thing (on a JSON). With a JSON query specifically, is there a way I can concatenate some fields so they get "grouped" on a query via the API? What I mean is this: The  would be a column, consisting of other columns that have the results, so when I query the   column without specifying one language, it shows all the results in the languages I have added. Lakelimbo (talk) 14:19, 12 November 2021 (UTC)


 * Try using GROUP_CONCAT within the "fields" parameter (you will also have to do a "group by" - hopefully you know how to do that). Yaron Koren (talk) 01:32, 15 November 2021 (UTC)

Exclude images when storing table cell content
I'm trying to figure out if Cargo is suitable for my project - if I have an image (internal or external) in a table cell, how do I exclude it and only store/query the cell (link) text?
 * I'm not sure I understand - are you saying you have a value like "...some text here... [[File:SomeImage.jpg]] ...other text here..." in a template call on some page, but you want the value stored in the corresponding Cargo table to just be "...some text here... ...other text here..."? If so, you may have to create a custom Lua module for that text processing, with the Scribunto extension, and then put a call to that module inside the relevant field(s) in the relevant #cargo_store call(s). Yaron Koren (talk) 02:10, 15 November 2021 (UTC)
 * Yep, that's it. I have flag icons next to the country names (links) and want to store the text only, but also display the corresponding flag next to the country in tables creates with Cargo. Is there a built-in function for this in the extension? Since the filenames are always the same as the link text, perhaps it's easier to add the images with a script to keep the table cells clean for Cargo use?


 * How about storing the country name as plain text in a Cargo field (e.g. country=United Kingdom), and in the template that uses Cargo just display it as ?

Add category via Cargo query
I would like to "automatically" add category to the page via Cargo query. Lets have query like

This really adds category e.g., only that it also displays this in the page without parsing wiki code. So the result of the CONCAT is included twice, once as wikitext, once as nowiki text.

How can I get rid off the nowiki display?

--Radouch (talk) 12:51, 14 November 2021 (UTC)


 * Just found the solution: I have to add  to the query.
 * --Radouch (talk) 13:02, 14 November 2021 (UTC)

Length limit of CONCAT argument or template argument?
I try to use CONCAT as workaround for template bug, see above and. Unfortunately, it seems there is some limit (about 248 characters) for the length of CONCAT argument (e.g. the argument in  has 10 characters). Another possibility is that there is limit for template argument as whole: if counting with  it gives 255 characters (very suspicious number :-) ).

If this limit is reached, no data nor error is returned by the query.

Any ideas about the course of the problem and/or the solution of it?

--Radouch (talk) 14:13, 14 November 2021 (UTC)

Query of an object held on _pageName
This should be a simple query of attributes of an external object.

The _pageName is CPF00001 and the CP_Form_Variant is CPF00002. CPF00002 is the object that I would like to get additional field information. What am I doing wrong?

A database query error has occurred. Did you forget to run your application's database schema updater after upgrading? Query: SELECT `_pageName` AS `Form Name`,`CP_Quality_Record` AS `Quality Record`,`CP_Process_Element` AS `Process Element`,`CP_Form_Applicability` AS `Applicability` FROM `cargo__CPF` WHERE _pageName HOLDS "CPF00002" ORDER BY `_pageName`,`CP_Quality_Record`,`CP_Process_Element`,`CP_Form_Applicability` LIMIT 100 Function: CargoSQLQuery::run Error: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'HOLDS "CPF00002" ORDER BY `_pageName`,`CP_Quality_Record`,`CP_Process_Element`,' at line 1 (localhost)


 * Try putting single quotes instead of double quotes around - that may make the difference. (Strings are meant to be enclosed in single quotes.) Yaron Koren (talk) 19:52, 15 November 2021 (UTC)


 * I think you want LIKE instead of HOLDS, as HOLDS is for lists and I don't think _pageName returns a list. Maybe Cargo isn't converting HOLDS into SQL seeing as the field isn't a list? Try . I wonder what that does for an empty CP_Form_Variant though.


 * Or, on second thoughts, if CP_Form_Variant will match the query exactly then.


 * I use double quotations for queries as a lot of my page names contain single quotation marks. Jonathan3 (talk) 09:51, 18 November 2021 (UTC)
 * Oh yeah, it should be "LIKE" (with the percentages) - I didn't even notice that part. Yaron Koren (talk) 15:24, 18 November 2021 (UTC)
 * This still gives zero results. But if I only have one object instead of two objects in the array, it gives me a result. 199.247.33.108 15:57, 10 December 2021 (UTC)

#cargo_query: use "group by" and keep duplicates
Hello, I want to extract all the occurrences from a table, grouped by the values that a certain field has. Is that possible using 'group by'? Thanks. --Carloposo (talk) 09:19, 18 November 2021 (UTC)


 * I'm just an amateur at this but if you want to display every row then maybe it's "order by" that you want? Jonathan3 (talk) 09:52, 18 November 2021 (UTC)
 * Thanks Jonathan3. I didn't explain it properly, my bad. Suppose I have a table called "Fruits". It has these fields: Name, Color. I'd like to extract each row and print it like this:

etc. Using 'group by' results in:
 * Red
 * Apple
 * Strawberry
 * Yellow
 * Banana
 * Lemon
 * Red
 * Apple
 * Yellow
 * Banana

Thanks.


 * I think you could use templates to have queries within queries. Or Lua. Jonathan3 (talk) 11:45, 18 November 2021 (UTC)


 * Or the "table" output format can merge cells that have the same content, I think. I'm replying on mobile so the indentation isn't working - sorry. Jonathan3 (talk) 11:47, 18 November 2021 (UTC)
 * Thank you Jonathan3, they both worked. --Carloposo (talk) 13:01, 18 November 2021 (UTC)

Drilldown error
If a filter value in Drilldown contains the symbol ‘#’, then this leads to the error: [412c4661f00b7f08ae3ca0d8] /index.php/Special:Drilldown/redirects?selector=%3B%3B%3B%23 MWException from line 124 of <...>/html/extensions/Cargo/includes/CargoSQLQuery.php: Error in "where" parameter: the string "#" cannot be used within #cargo_query. This is especially strange when this filter option is listed before the input field among the options. It turns out that the error is caused by the link proposed by the Drilldown page.

I understand why this symbol is prohibited in arbitrary user queries, but in forms that explicitly provide for string input, it could be allowed (or automatically replaced with ). --StasR (talk) 17:56, 28 November 2021 (UTC)

Editing any page results in duplicate row
Hi, I just updated to MW1.37. I also updated all the extensions. Now, every time I edit a page, the page gets duplicated, even if I do not change anything. It happens using both PageForms and the Visual Editor. If I edit the page again all good, no other row is added. Thank you.


 * Does this happen with just one page type, or with all of them? (Assuming you have more than one Cargo-enabled template.) Yaron Koren (talk) 19:41, 30 November 2021 (UTC)
 * It happens with all the Cargo-enabled Templates.--Carloposo (talk) 08:31, 1 December 2021 (UTC)
 * Is this a public wiki? If not, would you be willing to pastebin the wikitext of one of the templates, and link to that? Yaron Koren (talk) 13:58, 1 December 2021 (UTC)
 * Sure https://pastebin.com/Qjsz7id2 --Carloposo (talk) 14:04, 1 December 2021 (UTC)


 * I can't reproduce this problem. Are you using the latest Cargo code? Yaron Koren (talk) 03:26, 2 December 2021 (UTC)
 * I am using the latest Cargo code. I think I found a pattern. If I edit a page and do not fill in all the fields, the record gets duplicated. If I re-edit the same page and fill in all the fields, the duplicated record gets deleted. --Carloposo (talk) 08:38, 2 December 2021 (UTC)
 * I think this issue is connected to the topic "Can't populate Cargo db fields with empty data" (see above). If you read there, I had issues populating the db with empty fields. I fixed it removing STRICT_TRANS_TABLES from mysql. In the meantime, you released a new version of Cargo with a fix, which I never had the chance to test because I was relying on the fix on mysql. I just put STRICT_TRANS_TABLES back and getting the same error when doing cargoRecreateData.--Carloposo (talk) 13:55, 2 December 2021 (UTC)
 * Should be linked to https://phabricator.wikimedia.org/T290165 and (somehow) https://phabricator.wikimedia.org/T285176 --Carloposo (talk) 09:03, 3 December 2021 (UTC)
 * Adding infos to give more context, sorry. I noticed PageForms (latest version 5.3) doesn't check mandatory fields anymore now. --Carloposo (talk) 10:52, 3 December 2021 (UTC)

Possible to Fetch JSON data from Cargo Table Export from URL
Is it possible to extract a JSON format of a Cargo Table using the Cargo Export url? I've tried something in jquery var url = "mediawiki.org/index.php

$.getJSON(url, {table: "sample", fields: 'name, value', format:"json"}, function(data) {...}); Schen11 (talk)


 * Yes, that's possible. Did that not work? Yaron Koren (talk) 04:29, 6 December 2021 (UTC)

Query not displaying multiples (tried HOLDS and HOLDS LIKE)
The purpose of this code: Normally, I would just display the form in my template but this form field is page and I want to display other form fields associated with the page.

The code above works but only shows one item. I want it to display more than one and I have tried HOLDS and HOLDS LIKE.
 * Have you tried removing "group by"? --Carloposo (talk) 11:59, 10 December 2021 (UTC)


 * That did not work. Any other ideas? 199.247.33.108 15:14, 10 December 2021 (UTC)


 * Probably you need to put percentages around the LIKE value, i.e. LIKE "% %". Yaron Koren (talk) 15:44, 10 December 2021 (UTC)
 * This still gives zero results. But if I only have one object instead of two objects in the array, it gives me a result.
 * This is my current where:
 * | where=_pageName LIKE "%%"
 * What array are you talking about? Yaron Koren (talk) 16:28, 10 December 2021 (UTC)
 * CP_Form_Variant is a List of Page 199.247.33.108 19:01, 10 December 2021 (UTC)
 * Oh... no wonder it's not working. Is this value also stored in some table? If so, it's probably best to use both of those tables in this query, with "HOLDS" within the "join on" value. Yaron Koren (talk) 19:05, 10 December 2021 (UTC)
 * Thanks Yaron! I am only using one table but I know when I look at the tables in mysql there is probably a table for the list. I am not very good with joins but at least I know the solution.
 * Thanks again! Margaret 199.247.33.108 19:22, 10 December 2021 (UTC)


 * This code is complaining 'Error: Table cpf not found.'
 * Could you help me with this table and join statement? I am not sure what I am doing wrong. Thank you! Margaret 199.247.33.209 15:37, 13 December 2021 (UTC)


 * There are a few issues here. One is that table and field names are case-sensitive, so it should be "CPF" and not "cpf". The bigger one, though, is that the second table I'm talking about should be the table that holds the page on which this query is located - the one that holds this "CP Form Variant" value. It's not the "CPF" table, I assume? Yaron Koren (talk) 16:14, 13 December 2021 (UTC)
 * The query is indeed displayed on the CPF _pageName. 199.247.33.209 16:44, 13 December 2021 (UTC)
 * Okay, so "CP_Form_Variant" is a field within CPF pages that links to other CPF pages? And if that's true, do you want this page to display the variants of this page, or display other pages that this page is a variant of? Yaron Koren (talk) 18:29, 13 December 2021 (UTC)
 * I could just display the variant and just get the page name. I want to get the other fields of the cp_form_variant page. 199.247.33.209 18:45, 13 December 2021 (UTC)

Okay, so the former. In that case, the following might work:

Yaron Koren (talk) 19:31, 13 December 2021 (UTC)

Date fields throws DBError on drilldown with Postgres
Hi, currently we get database errors on using the drilldown on (any) table that holds a 'date' field. It makes no difference if all fields have a valid date in, or some fields are empty (which is stored as null, as we see it in the database). Recreating the tables (without any error) and/or update doesn't help here. On every other table without 'date' fields we see no problems.

We are running:

The error itself (sorry for the german, neither language option I tried changes it ...). In short it seems the operator  doesn't work on 'date' with Postgres:

[f055627acce5ab7a404cc888] /wiki/Spezial:Drilldown/Vakuumpumpe?_single Wikimedia\Rdbms\DBQueryError: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading or after adding a new extension? Error 42883: FEHLER: Operator existiert nicht: date <> integer LINE 1: ...alias" WHERE ("Vakuumpumpe_alias"."Letztewartung" != 0) ^ HINT: Kein Operator stimmt mit dem angegebenen Namen und den Argumenttypen überein. Sie müssen möglicherweise ausdrückliche Typumwandlungen hinzufügen. Function: Query: SELECT MIN("Vakuumpumpe_alias"."Letztewartung") AS min_date,MAX("Vakuumpumpe_alias"."Letztewartung") AS max_date FROM "cargo__Vakuumpumpe" "Vakuumpumpe_alias" WHERE ("Vakuumpumpe_alias"."Letztewartung" != 0)

Brabi81 (talk) 07:41, 14 December 2021 (UTC)

How to add a table to Special:MultiPageEdit
At 46:40 in the YouTube-video MediaWiki extension Cargo Introduction a reference is made to the page Special:Cargo Tables.

The page displays a list of options (View|Drilldown|Edit|Recreate Data|Delete)). By selecting the 'Edit' functionality the entire table can be viewed and modified by means of Special:MultiPageEdit.

In my private wiki (ver 1.37) the Special:Cargo Tables results in a table displaying the items as icons rather than plain text. There is no way to trigger 'Edit' for the tables. Thus the table is not available for selection in Special:MultiPageEdit

How can I enable the table for Multi Page editing?


 * This is actually a Page Forms question - Special:CargoTables does include links to Special:MultiPageEdit, but really you should go right to Special:MultiPageEdit to see which templates are getting handled and which aren't. I think the basic rules are something like: only templates that are edited with a form, where the form only handles that one template and the template is only handled by one form, are editable via Special:MultiPageEdit. Yaron Koren (talk) 03:34, 16 December 2021 (UTC)


 * Thank you very much. That helped to solve it. In the end a typo caused the trouble. When creating the template with Special:CreateClass the template name was given with lowercase letters. The actual template page begins with an capital letter. That was not reflected in the form page. 84.180.56.66 08:07, 16 December 2021 (UTC)


 * Great! Yaron Koren (talk) 14:28, 16 December 2021 (UTC)

Direct URL link to Cargo page based on unique field
Is there any way of forming a URL that would go straight to a page, eg example.com/...cargo_field=1234?

I suppose an alternative would be to link to query results. Thanks. Jonathan3 (talk) 15:19, 19 December 2021 (UTC)


 * What if more than one page has that value for that field? Yaron Koren (talk) 01:46, 21 December 2021 (UTC)


 * In my mind I was only thinking of a field with a "unique" value so that wouldn't arise. If it did then I suppose there should be some sort of disambiguation page (query form result). Is it currently possible? I don't think so. Jonathan3 (talk) 01:49, 21 December 2021 (UTC)


 * No, although you could just put in a query, which would presumably accomplish more or less the same thing... Yaron Koren (talk) 01:52, 21 December 2021 (UTC)


 * If there were a feature like Google's old "I'm feeling lucky" option which takes you to the first result, and if that could be added to the URL, it would get round your "What if more than one page has that value for that field?" concern.


 * What I have in mind is something like nearly every sales website in the world, where you can go to a page like www.example.com/id=ABCD to see a product :-) Jonathan3 (talk) 02:01, 21 December 2021 (UTC)


 * Oh, I see. You could probably accomplish that with Page Forms' Special:RunQuery page, and the "embedded" Cargo query format. Yaron Koren (talk) 02:59, 21 December 2021 (UTC)


 * I think that would take you to the results page, but the query could be set up to have nice-looking results, so could be a good compromise. Thanks. Jonathan3 (talk) 00:49, 22 December 2021 (UTC)

Deleting a Cargo Table
How to delete a Cargo Table Alternate --Matjung (talk) 11:19, 30 December 2021 (UTC)
 * Log in as Administrator/Sysops
 * Goto Special:CargoTables
 * You should get a list with available Tables
 * Hit the Delete icon at the table to be deleted
 * Confirm the Deletion
 * Goto Special:DeleteCargoTable/NAME_OF_TABLE
 * Confirm the Deletion

Does Cargo support lines and polygons (besides points)?
I am considering to use Cargo instead of SMW. Important for me is whether I can store (besides geographical points) also lines and polygons, and whether I can display them on a map. So in fact: to define and use a field that stores a series of geographical coordinates.

Reading https://www.mediawiki.org/wiki/Extension:Cargo/Storing_data#Storage_of_coordinates I don't expect that Cargo supports lines and polygons.

I also tested a 'Coordinates' typed field with some coordinates, divided by a colon: 51.75284463529357, 5.0431281849590839: 51.755482428207017, 5.0421830972897626: 51.754842329817762, 5.0411433012562128. However, trying to show this on a map by means of a cargo_query, I don't get a line (but, at applying OpenLayers: NullIsland ;-)).

Besides that: the table structure of the Cargo tables have only two fields for storing a location: _lon and _lat.

So I think Cargo doesn't support lines and polygons. Am I right?


 * That's right, unfortunately. Yaron Koren (talk) 21:17, 5 January 2022 (UTC)

Cargo looks for template at e.g. :Index.php?title=Template:Author
I created on my environment the templates Author and Book as are discussed on the Cargo Quick start guide. After that I created a page and added the template 'Author' (by selecting it via the editor function to add a template to a page). At that moment the editor popup tells that the template has no description but that there may be information on the template page. A link is presented to /index.php?title=Sjabloon:Author. this is the page I just created, so I don't know why the editor popup doesn't show the fields I just configured on the template.

But OK, I insert the template, but don't add the Author data. Then I save the page and open it again. The source only has:.

The editor function now looks for the template in :Index.php?title=Sjabloon:Author, so in fact in /index.php?title=Index.php?title=Sjabloon:Author.

What am I doing wrong?

>>> This issue is not a Cargo issue, but a VisualEditor issue, I learned (see https://www.mediawiki.org/wiki/Topic:Vxmy0gm21vtf927f).

MySQL/MariaDB database user privileges required by Cargo
I know that the normal thing to do is GRANT ALL PRIVILEGES, but I'm thinking of reducing that and would like to know which privileges are required by Cargo for (a) the main database and (b) its own Cargo database. See Topic:Wnht96uupemgrsef. Thanks. Jonathan3 (talk) 11:55, 5 January 2022 (UTC)


 * For the main DB, no special privileges. For the Cargo DB, probably just the ones you listed (SELECT, INSERT, UPDATE, LOCK TABLES, DELETE), plus CREATE TABLE. Yaron Koren (talk) 21:16, 5 January 2022 (UTC)

Datatype "Monolingual text"
Hello,

Does an equivalent to SMW Datatype "Monolingual text" exist with Cargo ?


 * No... would it be useful? Yaron Koren (talk) 15:14, 10 January 2022 (UTC)

The need is to change the field label like in This is a property of type Has type::Text.

Language labels: Has preferred property label::Role@en Has preferred property label::Rolle@de


 * Where is that "Has preferred property label" property used? Yaron Koren (talk) 20:25, 11 January 2022 (UTC)