Page MenuHomePhabricator

Articles about zero (0) not displaying title in Vector skin
Closed, ResolvedPublic

Description

Reported first on English Wikipedia all articles about zero (0) (where 0 is the actual title) are not showing the first title heading and it's empty in the HTML code.

Steps to produce

Go to English Wikipedia's article about "0" https://en.wikipedia.org/wiki/0
*Or to nn.wiki https://nn.wikipedia.org/wiki/0
*Or to this redirect on fr https://fr.wikipedia.org/w/index.php?title=0&redirect=no

Expected result

The first heading of all pages above show 0

Actual result

They show nothing. But may contain (editsection) link, I guess that's based on a user preference.

This happens only on Vector skin, all other skins display normally including mobile ones

Event Timeline

See https://en.wikipedia.org/w/index.php?title=Wikipedia:Village_pump_(technical)&curid=3252662&diff=890608048&oldid=890603467

To clarify, this is affecting articles whose title is exactly "0" (the number zero, with no quotation marks).

Old code:

if ( $this->data['title'] != '' ) {
	// Loose comparison with '!=' is intentional, to catch null and false too, but not '0'
	echo Html::rawElement( 'h1',
		[
		'id' => 'firstHeading',
		'class' => 'firstHeading',
		'lang' => $this->get( 'pageLanguage' ),
		],
		// Raw HTML
		$this->get( 'title' )
	);
}

New code:

invoke.php
$params = [
	// Loose comparison with '!=' is intentional, to catch null and false too, but not '0'
	'html-title' => ( $this->data['title'] != '' ? $this->get( 'title' ) : null ),
];
template.mustache
{{#html-title}}<h1 >{{{html-title}}}</h1>{{/html-title}}

I recall explicitly testing for what happens with empty string and "0" which are notorious in PHP for being confusing "truthy" values, and I've confirmed again today that these appear to work as expected:

php maintenance/eval.php
$tp = new TemplateParser(__DIR__);
$tp2 = Wikimedia\TestingAccessWrapper::newFromObject($tp);
$code = $tp2->compile('{{#foo}}<div>yep</div>{{/foo}}');
$code = substr( $code, 5 );
$renderer = eval( $code );
echo $renderer( [ 'foo' => '0' ] );
# "<div>yep</div>"

So the conditional part is working fine. null, undefined and empty string skip the conditional (as intended) and "0" enters the conditional (also as intended).

In terms of variable substitution, it also works fine. The zero renders.

$code = $tp2->compile('foo: {{foo}}. foo raw: {{{foor}}}.');
$code = substr( $code, 5 );
$renderer = eval( $code );
echo $renderer( [ 'foo' => '0', 'foor' => '0' ] );
# foo: 0. foo raw: 0.

The problem happens at the point where I least expect it. It's the substitution of a variable when inside a conditional for that variable.

wat
$code = $tp2->compile('{{#foo}}<div>{{{foo}}}</div>{{/foo}}');
$code = substr( $code, 5 );
$renderer = eval( $code );
echo $renderer( [ 'foo' => '0' ] );
# <div></div>
echo $renderer( [ 'foo' => 'meh' ] );
# <div>meh</div>

Then, and only then, LightNCandy decides the zero should be printed as an empty string. What!?

Change 500805 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/skins/Vector@master] Fix <h1> to be present even if title is "0"

https://gerrit.wikimedia.org/r/500805

Change 500805 merged by jenkins-bot:
[mediawiki/skins/Vector@master] Fix <h1> to be present even if title is "0"

https://gerrit.wikimedia.org/r/500805

Change 500815 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/skins/Vector@wmf/1.33.0-wmf.24] Fix <h1> to be present even if title is "0"

https://gerrit.wikimedia.org/r/500815

Change 500816 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/skins/Vector@wmf/1.33.0-wmf.23] Fix <h1> to be present even if title is "0"

https://gerrit.wikimedia.org/r/500816

Change 500816 merged by jenkins-bot:
[mediawiki/skins/Vector@wmf/1.33.0-wmf.23] Fix <h1> to be present even if title is "0"

https://gerrit.wikimedia.org/r/500816

Change 500815 merged by jenkins-bot:
[mediawiki/skins/Vector@wmf/1.33.0-wmf.24] Fix <h1> to be present even if title is "0"

https://gerrit.wikimedia.org/r/500815

Mentioned in SAL (#wikimedia-operations) [2019-04-02T20:20:42Z] <krinkle@deploy1001> Synchronized php-1.33.0-wmf.23/skins/Vector/includes/: I6e04b512d / T219864 (duration: 01m 00s)

Mentioned in SAL (#wikimedia-operations) [2019-04-02T20:23:32Z] <krinkle@deploy1001> Synchronized php-1.33.0-wmf.24/skins/Vector/includes/: I6e04b512d / T219864 (duration: 00m 59s)