[MediaWiki-l] A real MW question this time!

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[MediaWiki-l] A real MW question this time!

Jan Steinman
(even though it peripherally involves MySQL)

This on MediaWiki 1.16.2 (Yea, I know. I will upgrade Any Day Now...)

I am trying to do conditional display, based on the result of a custom extension. This extension evaluates MySQL.

I want to include a header and table if records exist, otherwise not include the header nor the empty table.

I have an extension called "sql2wikiInline" that returns exactly one row, without column headers. I ask the table for a "count(*)" and then conditionally include the header and the result of another SQL query, this one with multiple lines and column headers.

The problem is that #ifeq: does not seem to be working as I understand it. My "sql2wikiInline" apparently appends whitespace to the end, but according to the documentation of #ifeq:, it should not matter for comparing numerics. But quoting the whitespace ("0 ") doesn't work, either.

Doing this:
        COUNT = "{{#tag:sql2wikiInline|SELECT count(*) FROM s_product_harvest h INNER JOIN mw_user u ON h.who1 = u.user_id WHERE u.user_name = '{{{1}}}'|database=EcoReality}}"

prints
        COUNT = "0 "

which I would assume #ifeq: would properly compare to an unquoted "0" numeral.

But doing this:
        xxx {{#ifeq:"0 "|"{{#tag:sql2wikiInline|SELECT count(*) FROM s_product_harvest h INNER JOIN mw_user u ON h.who1 = u.user_id WHERE u.user_name = '{{{1}}}'|database=EcoReality}}"|no harvests|some harvests}} xxx

prints
        xxx some harvests xxx

no matter what number the count(*) expression returns, with or without the quotes around the comparison parameters.

So, two questions for the parser function gurus out there:

1) Am I doing something obviously wrong? I've poked around at a few different elaborations, and can't make it work.

2) If it appears I'm using it correctly, what's my next step? How can I determine if my SQL extension is sneaking in some invisibles that are blowing #ifeq:s mind?

Thanks in advance for any assistance offered -- and I have the right list this time, I hope!

PS: this code is on a template page that includes a "some records" example:
        http://www.ecoreality.org/wiki/Template:Personal_statistics_for

and here is a page that uses the template above, where the record count is zero:
        http://www.ecoreality.org/wiki/User:Mary_Troke/Statistics

Self sign-up is disallowed and only administrators can edit pages with this extension. If you REALLY want to get in and play with it, let me know and I'll give you an admin account.

:::: The primary impediment to community is the stranglehold that hierarchical corporate-driven models of employemnt have on individuals. They so completely drain the life-energy of people in endeavors that are only marginally related to survival or fun that when people return home at the end of the day they're exhausted, suitable only for a few hours of TV and dropping into bed. -- Thom Hartmann
:::: Jan Steinman, EcoReality Co-op ::::


_______________________________________________
MediaWiki-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: A real MW question this time!

Tim Starling-2
On 05/11/13 07:38, Jan Steinman wrote:
> But doing this: xxx {{#ifeq:"0 "|"{{#tag:sql2wikiInline|SELECT
> count(*) FROM s_product_harvest h INNER JOIN mw_user u ON h.who1 =
> u.user_id WHERE u.user_name = '{{{1}}}'|database=EcoReality}}"|no
> harvests|some harvests}} xxx

#tag generates an opaque placeholder, you can't compare it to things
with #ifeq. It would work if your sql2wikiInline extension provided a
proper parser function interface, instead of using #tag.

-- Tim Starling


_______________________________________________
MediaWiki-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: A real MW question this time!

Jan Steinman
> From: Tim Starling <[hidden email]>
>
> On 05/11/13 07:38, Jan Steinman wrote:
>> But doing this: xxx {{#ifeq:"0 "|"{{#tag:sql2wikiInline|SELECT
>> count(*) FROM s_product_harvest h INNER JOIN mw_user u ON h.who1 =
>> u.user_id WHERE u.user_name = '{{{1}}}'|database=EcoReality}}"|no
>> harvests|some harvests}} xxx
>
> #tag generates an opaque placeholder, you can't compare it to things
> with #ifeq. It would work if your sql2wikiInline extension provided a
> proper parser function interface, instead of using #tag.

You've got my attention.

Can you point me to a starting point for figuring this out? (I find crawling through MediaWiki documentation to be an "opaque placeholder." :-)

It can be used as "<sql2wikiInline>...</sql2wikiInline>", but I think you're saying if it could be used as "{{#sql2wikiInline:..." it would work.

:::: Giving society cheap, abundant energy at this point would be the equivalent of giving an idiot child a machine gun. -- Paul Ehrlich
:::: Jan Steinman, EcoReality Co-op ::::


_______________________________________________
MediaWiki-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: A real MW question this time!

Tim Starling-2
On 06/11/13 14:39, Jan Steinman wrote:

>> From: Tim Starling <[hidden email]>
>>
>> On 05/11/13 07:38, Jan Steinman wrote:
>>> But doing this: xxx {{#ifeq:"0 "|"{{#tag:sql2wikiInline|SELECT
>>> count(*) FROM s_product_harvest h INNER JOIN mw_user u ON
>>> h.who1 = u.user_id WHERE u.user_name =
>>> '{{{1}}}'|database=EcoReality}}"|no harvests|some harvests}}
>>> xxx
>>
>> #tag generates an opaque placeholder, you can't compare it to
>> things with #ifeq. It would work if your sql2wikiInline extension
>> provided a proper parser function interface, instead of using
>> #tag.
>
> You've got my attention.
>
> Can you point me to a starting point for figuring this out? (I find
> crawling through MediaWiki documentation to be an "opaque
> placeholder." :-)

"Strip marker" is the preferred jargon, but I don't think there's much
about it on mediawiki.org.

Basically, tag extensions return raw HTML, which is guarded from
interpretation by the wikitext parser by temporarily replacing it with
a placeholder. Parser functions return wikitext by default, so don't
need to be guarded.

> It can be used as "<sql2wikiInline>...</sql2wikiInline>", but I
> think you're saying if it could be used as "{{#sql2wikiInline:..."
> it would work.

Yes. There is a documentation about how to make such parser functions
at <https://www.mediawiki.org/wiki/Manual:Parser_functions>

-- Tim Starling


_______________________________________________
MediaWiki-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l