Page MenuHomePhabricator

ref in #if is shown
Closed, InvalidPublicBUG REPORT

Description

Code:

{{#if:<ref>hello world</ref>|1|0}}

Result:
The cite is shown at the bottom:

1

     1. ^ hello world

Event Timeline

@Shalomori123: Thanks for reporting this. Please use the bug report form (linked from the top of the task creation page) to create a bug report, and fill in the sections in the template instead of deleting them. What should have happened instead?

It should not be shown, because the text itself on the "if" condition doesn't shown.

thiemowmde changed the task status from Open to Stalled.Nov 20 2023, 4:31 PM
thiemowmde subscribed.

This is very similar to the behavior of #ifexists described in T14019.

The snippet of wikitext in the first part of the #if is not executed in a vacuum, like it would be a separate document. It needs to be executed as being part of the document. This implies the reference is created, collected, and rendered as part of the list at the end of the document. This is not a mistake but by design.

Furthermore, the provided example doesn't make much sense. An #if with a <ref> in this position can never be false. What is it supposed to do? Please provide a real-world use case. Otherwise we can't do much but close this ticket as invalid.

I faced this issue when tried to check if a section exists in other page, using the gadget of lst. This check is looking like this: {{#if:{{#section:page|abc}}|'''abc:''' {{#section:page|abc}}}}
It's helpful when you want that title or any text will be shown only if the section exists.
But when the section contains a ref, the software present its refs twice at the bottom.

I'm sorry, but I don't think it makes much sense to expect code that quite literally says "include this section" to not include the section. What you probably need is some kind of {{#ifsectionexists: … }}, as discussed in T337480. That's neither a bug in <ref> nor in #if, but in MediaWiki-extensions-LabeledSectionTransclusion.