Page MenuHomePhabricator

Argument 1 passed to Language::equals() must be an instance of Language, instance of StubUserLang given
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

What happens?:

You see a page with error:

[1ed3e341128a47cd2d91fd56] 2023-01-06 10:39:52: Fatal exception of type "TypeError"

What should have happened instead?:
Redirect to home page

Software version (skip for WMF-hosted wikis like Wikipedia):

  • MediaWiki - 1.40.0-alpha
  • PHP - 7.4.33 (fpm-fcgi)

Other information (browser name/version, screenshots, etc.):
Stacktrace:

[2023-01-06T10:35:35.542411+00:00] exception.ERROR: [6161efb29c13633d3a34e94e] /wiki/Special:MyLanguage/Project_list   TypeError: Argument 1 passed to Language::equals() must be an instance of Language, instance of MediaWiki\StubObject\StubUserLang given, called in /srv/mediawiki/tags/2023-01-04_14:36:20/includes/specials/SpecialMyLanguage.php on line 168 {"exception":"[object] (TypeError(code: 0): Argument 1 passed to Language::equals() must be an instance of Language, instance of MediaWiki\\StubObject\\StubUserLang given, called in /srv/mediawiki/tags/2023-01-04_14:36:20/includes/specials/SpecialMyLanguage.php on line 168 at /srv/mediawiki/tags/2023-01-04_14:36:20/includes/language/Language.php:4359)
[stacktrace]
#0 /srv/mediawiki/tags/2023-01-04_14:36:20/includes/specials/SpecialMyLanguage.php(168): Language->equals()
#1 /srv/mediawiki/tags/2023-01-04_14:36:20/includes/specials/SpecialMyLanguage.php(106): SpecialMyLanguage->findTitleInternal()
#2 /srv/mediawiki/tags/2023-01-04_14:36:20/includes/specials/SpecialMyLanguage.php(84): SpecialMyLanguage->findTitle()
#3 /srv/mediawiki/tags/2023-01-04_14:36:20/includes/MediaWiki.php(276): SpecialMyLanguage->getRedirect()
#4 /srv/mediawiki/tags/2023-01-04_14:36:20/includes/MediaWiki.php(916): MediaWiki->performRequest()
#5 /srv/mediawiki/tags/2023-01-04_14:36:20/includes/MediaWiki.php(571): MediaWiki->main()
#6 /srv/mediawiki/tags/2023-01-04_14:36:20/index.php(50): MediaWiki->run()
#7 /srv/mediawiki/tags/2023-01-04_14:36:20/index.php(46): wfIndexMain()
#8 {main}
","exception_url":"/wiki/Special:MyLanguage/Project_list","reqId":"6161efb29c13633d3a34e94e","caught_by":"entrypoint"} []

Without the Special:MyLanguage the URL redirects to the main page

This appears to be reproducible locally also if you create the following page:

#REDIRECT[[Special:MainPage]]

And try to navigate to it with Special:MyLanguage

Event Timeline

SpecialMyLanguage.php
		$uiLang = $this->getLanguage();
		$baseLang = $base->getPageLanguage();

		if ( $uiLang->equals( $baseLang ) && !$forTransclusion ) {

Title::getPageLanguage is documented to return stub object, maybe swapping the equals() call would be enough.
The line number in master for that is 151, not the reported 168. Not sure which version the error based on.

Due to some other work around the deprecation of wfGetLangObj the unstubbing of $wgLang can happen later and resulting in this error, which was not showing up before

Nikerabbit subscribed.

We have custom patch to make SpecialMyLanguage includable, which explains the line numbers. As far as I can see, it does not affect this code path so I think this is a problem in core.

Phan can detect this (only) in the strict mode

includes\specials\SpecialMyLanguage.php:151 PhanPartialTypeMismatchArgument Argument 1 ($lang) is $baseLang of type \Language|\MediaWiki\StubObject\StubUserLang but \Language::equals() takes \Language (\MediaWiki\StubObject\StubObject|\MediaWiki\StubObject\StubUserLang is incompatible) defined at includes\language\Language.php:4359

Change 879611 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/core@master] specials: Swap order for Language::equals in Special:MyLanguage

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

Change 879611 merged by jenkins-bot:

[mediawiki/core@master] specials: Swap order for Language::equals in Special:MyLanguage

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