Topic on Extension talk:ParserFunctions

Both possible results from an #if are occurring?

5
99.232.155.35 (talkcontribs)

ImageRangeTest is a the range check template; it returns either a 0 or a 1 depending on if the {{{1}}} number is in any of the matching ranges. The number indicates a specific graphic in a game - there's a max possible graphic number, and there are unused graphic positions, so this allows me to test if the particular graphic is one that exists, or which doesn't exist.

This is a simplified version of the ifeq test I'm using to then link to an image of that particular graphic: {{#ifeq: {{ImageRangeTest | {{{1}}} }} | 1 | This image does not exist. | [[File:{{{1}}}.png]] }}

Everything works fine, displays fine, etc. The resulting HTML is fine; either it has the img tag and links the image, or there is no img tag, and "This image does not exist." is displayed.

  • However*, there's still one problem, and it looks like a possible bug with #ifeq. When I look at Special:WantedFiles, all of those {{{1}}}.png files that fail the rangetest here show up there as missing files. When I look at the details on any of them, the only page showing a link to any particular missing file is the one which has the above ifeq test.

So, say the page name is Foobar, and {{{1}}} is 2001. 2001 fails the rangecheck. The template then creates the text "This image does not exist." on the page Foobar. The generated HTML for Foobar has no img tag linking 2001.png. However, Special:WantedFiles still shows 2001.png as a WantedFile, and File:2001.png shows: File usage The following page uses this file:

Foobar

So it looks like both possible results from an #if are generated, and only then is the system deciding which one to actually use - which in this case, is generating a bogus WantedFile. (And in my case, that adds up to a few thousand bogus wantedfile entries, making it much harder to spot valid wantedfiles.)

Dinoguy1000 (talkcontribs)

I'm guessing ImageRangeTest contains some code to the effect of {{ #ifexist: File:{{{1}}}.png || 1 }}? #ifexist always counts as a link to the tested page; as it is currently implemented, this is the only way to determine if the page does exist, and also the only way to ensure it correctly updates if a previously nonexistent page is created (or a previously existing page is deleted).

99.232.155.35 (talkcontribs)

No, no calls to ifexist. This is ImageRangeTest: {{#switch: 1 | {{Rangecheck|{{{1}}}|4318|4323}} ... | {{Rangecheck|{{{1}}}|42325|99999}} = 1 | #default = 0 }}

and this is Rangecheck: {{#ifexpr: {{{1|}}} >= {{{2|}}}|{{#ifexpr: {{{1|}}} <= {{{3|}}}|1|0}}|0}}

Dinoguy1000 (talkcontribs)

Does this still happen if you test some contrived case where the outermost #ifeq doesn't call any template? Something like {{ #ifeq: 1 | 1 | This image does not exist. | [[File:{{{1}}}.png]] }}.

Brianfreud (talkcontribs)

Managed to fix it, I think. I'd oversimplfied above. For whatever reason, the following combo of templates, ifeq, and var seems to have been the combined trigger for the issue (in v. 1.27.0 through 1.33.1) {{#vardefine: graphic|99999}}{{#vardefine:image|{{#ifeq: {{ImageRangeTest | {{#var: graphic}} }} | 1 | This image does not exist. | [[File:{{#var:graphic}}.png]] }} }} .. {{#var:image}}

99999 can be anything; in my particular case, it was taking it from the category page using the above template's title:

{{#vardefine: graphic |{{#replace:{{PAGENAME}}|UO:Items using graphic |}} }}

The image var was actually only used in one place, so I took it out of a var and moved the ifeq to where {{#var:image}} had been. That stopped the invisible non-use of the file from happening.