Last modified: 2010-09-02 16:51:51 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T26337, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 24337 - Passing a template parameter into a query throws an error
Passing a template parameter into a query throws an error
Status: RESOLVED INVALID
Product: MediaWiki extensions
Classification: Unclassified
Semantic MediaWiki (Other open bugs)
unspecified
All All
: Normal major (vote)
: ---
Assigned To: Markus Krötzsch
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-07-11 09:34 UTC by Neill Mitchell
Modified: 2010-09-02 16:51 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Neill Mitchell 2010-07-11 09:34:56 UTC
Hi.

I have a number of queries that I use on a lot of pages. Rather than put the query into every page, it would be much easier to create a template with the query in it and then pass in the required parameters.

An example using the cities theme.

I have a cities query that is used on a number of pages. So in each page that uses it I simply have:

{{City Query|Berlin}} (or whatever city I want - this is a trivial example).

The City Query template contains:

{{#ask:
[[Category:Cities]]
[[City::{{{1|}}}]]
|?Population
|?Mayor
|?Size
|?Twinned with
|?Has a river
}}

However, {{City Query|Berlin}} throws the error:
"The part "]]" of the query was not understood. Results might not be as 
expected."

and the ask returns all cities in the cities category, not just Berlin.

Surely this is just a simple passing issue that can be easily fixed?
It would be very powerful to be able to pass in parameters to a query like this and would also result in cleaner pages without duplicating almost identical queries everywhere.

I am using SMW 1.5.1.
Comment 1 Neill Mitchell 2010-07-11 10:25:29 UTC
Sorry, was using a SMW 1.4.3 instance. Seems to work fine on SMW 1.5.1, which is great!
Comment 2 Neill Mitchell 2010-07-11 10:42:59 UTC
Spoke too soon. The bug is present.

If you have more than one template variable then it throws the error. For example:

{{City Query|+|Yes}}

{{#ask:
[[Category:Cities]]
[[City::{{{1|}}}]]
[[Has a river::{{{2|}}}]]
|?Population
|?Mayor
|?Size
|?Twinned with
|?Has a river
}}

Throws the error:
"]][[Has a river::" cannot be used as a page name in this wiki. Some use of "<nowiki>

and it returns all cities in the category regardless of Has a river value.

So, as I first suspected, there seems to be a parsing issue here.
Comment 3 Markus Krötzsch 2010-08-29 19:47:19 UTC
It turns out that there is a minor issue here but that the main problem is actually not a bug: what the above template does is to construct a malformed query when some of the parameters are not given. Namely, the parameters are simply replaced by nothing (empty strings). So you get a query like, say,

{{#ask:
[[Category:Cities]]
[[City::]]
[[Has a river::]]
|?Population
|?Mayor
|?Size
|?Twinned with
|?Has a river
}}

This query, whether created by a template or not, will cause an error message from SMW since the conditions cannot be parsed. The minor issue is that SMW assumes that property condition values are of length at least one. So the first "]" is taken to belong to a value, which thus extends until the next closing pair of "]]" after the following condition. This makes the error somewhat hard to read. But the query would not work without errors either way.

If you want to have optional query conditions in a template, then you should use the ParserFunctions extension with its #if parser function to test for emptiness. The whole query part (from [[ to ]]( should then be omitted if no parameter is given for it. Alternatively, the template could use some relevant default (syntax: {{{1|default}}}) instead of an empty string. Using "_" there will at least make the error more readable.

In particular, queries do work properly with template parameters, and this bug can be closed.
Comment 4 Markus Krötzsch 2010-08-29 19:47:48 UTC
P.S. I created a testing page at http://sandbox.semantic-mediawiki.org/wiki/Bug_24337
Comment 5 Neill Mitchell 2010-09-02 10:20:32 UTC
Hi Markus.

Thanks for your response.

There's been a lot of chat about using #if on the mailing list :)

I guess, as you say, that queries should not return anything if there is an error in the parameters rather than returning the entire query set.
Comment 6 Markus Krötzsch 2010-09-02 15:38:45 UTC
Thanks for the comment: it made me notice an omission in our documentation that I have now fixed. SMW already has the feature that you ask for (not running queries if there are errors), but it is disabled by default. The configuration option for this is called $smwgIgnoreQueryErrors, see http://semantic-mediawiki.org/wiki/Help:Configuration#smwgIgnoreQueryErrors .
Comment 7 Neill Mitchell 2010-09-02 16:51:51 UTC
Hi Markus.

Thanks for amending the documentation. Being able to stop SMW running queries with dud parameters is really useful.

:)

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links