Page MenuHomePhabricator

TypeError in MobileFrontend RemovableClassesTransform (PHP 8.4)
Closed, ResolvedPublic3 Estimated Story PointsBUG REPORT

Description

Caused by T255586

Steps to Reproduce

  1. Navigate to the wiki’s main page, or create any page that contains HTML content, for example:
<div class="testing-task-phab-400401">
</div>
  1. Access the mobile view by visiting /w/index.php?title=Main_Page&mobileaction=toggle_view_mobile
  2. The error occurs during page rendering

Actual Results

A TypeError is thrown with the following message:

TypeError: MobileFrontend\Transforms\RemovableClassesTransform::apply(): Argument #1 ($node) must be of type DOMElement, Dom\HTMLElement given, called in extensions/MobileFrontend/includes/MobileFormatter.php on line 32

Full stack trace:

from extensions/MobileFrontend/includes/Transforms/RemovableClassesTransform.php(23) 
#0 extensions/MobileFrontend/includes/MobileFormatter.php(32): MobileFrontend\Transforms\RemovableClassesTransform->apply() 
#1 extensions/MobileFrontend/includes/ExtMobileFrontend.php(173): MobileFormatter->applyTransforms() 
#2 extensions/MobileFrontend/includes/ExtMobileFrontend.php(75): ExtMobileFrontend::domParseMobile() 
#3 extensions/MobileFrontend/includes/MobileFrontendHooks.php(357): ExtMobileFrontend::domParseWithContentProvider() 
#4 includes/HookContainer/HookContainer.php(155): MobileFrontendHooks->onOutputPageBeforeHTML() 
#5 includes/HookContainer/HookRunner.php(2783): MediaWiki\HookContainer\HookContainer->run() 
#6 includes/Output/OutputPage.php(2633): MediaWiki\HookContainer\HookRunner->onOutputPageBeforeHTML() 
#7 includes/Output/OutputPage.php(2661): MediaWiki\Output\OutputPage->addParserOutputText() 
#8 includes/page/Article.php(931): MediaWiki\Output\OutputPage->addParserOutput() 
#9 includes/page/Article.php(739): MediaWiki\Page\Article->doOutputFromParserCache() 
#10 includes/page/Article.php(551): MediaWiki\Page\Article->generateContentOutput() 
#11 includes/actions/ViewAction.php(84): MediaWiki\Page\Article->view() 
#12 includes/actions/ActionEntryPoint.php(728): MediaWiki\Actions\ViewAction->show() 
#13 includes/actions/ActionEntryPoint.php(505): MediaWiki\Actions\ActionEntryPoint->performAction() 
#14 includes/actions/ActionEntryPoint.php(143): MediaWiki\Actions\ActionEntryPoint->performRequest() 
#15 includes/MediaWikiEntryPoint.php(198): MediaWiki\Actions\ActionEntryPoint->execute() 
#16 index.php(58): MediaWiki\MediaWikiEntryPoint->run() 
#17 {main}

Expected Results

The mobile view should load normally without any TypeError, displaying the main page in mobile format.

Environment

Analysis

The error occurs because RemovableClassesTransform::apply() expects a DOMElement but receives a Dom\HTMLElement instead. This suggests a type compatibility issue, possibly related to recent changes in MediaWiki's DOM handling or PHP 8.4 compatibility.

The issue appears to be in the type of declaration mismatch between what's being passed from MobileFormatter and what RemovableClassesTransform expects to receive.

Event Timeline

Reedy renamed this task from TypeError in MobileFrontend RemovableClassesTransform [PHP 8.4] to TypeError in MobileFrontend RemovableClassesTransform.Jul 24 2025, 8:58 PM
Jdlrobson-WMF subscribed.

Is this a production error at time of writing?

Is this a production error at time of writing?

Nope, it’s only corrupted in PHP 8.4+ versions, and I already researched thoroughly that when HTML is used and the toggle to mobile is applied, or when accessing from a mobile device, as I mentioned in the description, it doesn’t work

Thanks! @egardner this sounds like this is low priority for now but will become UBN at some point in the future when we bump our PHP version so please prioritize accordingly.

Note that in Readers Growth we've had two engineers (me and @egardner) running into this developing on Macs with PHP installed from Homebrew.

We can work around it for now by either downgrading to php-8.2, or by locally reverting ee1b1eec6c6a2439df09cc4dfc19008d00d01229 on MobileFrontend.

Change #1182901 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/extensions/MobileFrontend@master] WIP: Use Parsoid DOM types to support PHP >= 8.4

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

Change #1182910 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/extensions/MobileFrontend@master] Replace use of DOMXPath in MakeSectionsTransform

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

Change #1182911 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/extensions/MobileFrontend@master] Replace DOMXPath in MoveLeadParagraphTransform

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

Change #1182920 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/extensions/MobileFrontend@master] Verify DOM types against IDLeDOM

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

Change #1182962 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/services/parsoid@master] Ensure that Parsoid DOM aliases are loaded before parsing

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

Other than the page appearing normally after load, on the client side are there any other cues that can be used to validate this once it is fixed?

HSwan-WMF set the point value for this task to 3.Sep 10 2025, 4:44 PM
Esanders renamed this task from TypeError in MobileFrontend RemovableClassesTransform to TypeError in MobileFrontend RemovableClassesTransform (PHP 8.4).Sep 10 2025, 5:11 PM

Change #1182962 merged by jenkins-bot:

[mediawiki/services/parsoid@master] Ensure that Parsoid DOM aliases are loaded before parsing

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

Change #1187841 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.22.0-a21

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

Change #1187841 merged by jenkins-bot:

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.22.0-a21

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

Tested on PHP 8.4.12, works fine, anyone want to comment?

PHP 8.4.13 via homebrew still fails:

Internal error
[e8bd351877e5afbfd8425413] /w/index.php?title=Main_Page&mobileaction=toggle_view_mobile TypeError: MobileFrontend\Transforms\RemovableClassesTransform::apply(): Argument #1 ($node) must be of type DOMElement, Dom\HTMLElement given, called in /opt/homebrew/var/www/w/extensions/MobileFrontend/includes/MobileFormatter.php on line 32

Backtrace:

from /opt/homebrew/var/www/w/extensions/MobileFrontend/includes/Transforms/RemovableClassesTransform.php(23)
#0 /opt/homebrew/var/www/w/extensions/MobileFrontend/includes/MobileFormatter.php(32): MobileFrontend\Transforms\RemovableClassesTransform->apply(Dom\HTMLElement)
#1 /opt/homebrew/var/www/w/extensions/MobileFrontend/includes/ExtMobileFrontend.php(173): MobileFormatter->applyTransforms(array)
#2 /opt/homebrew/var/www/w/extensions/MobileFrontend/includes/ExtMobileFrontend.php(75): ExtMobileFrontend::domParseMobile(MediaWiki\Output\OutputPage, string)
#3 /opt/homebrew/var/www/w/extensions/MobileFrontend/includes/MobileFrontendHooks.php(356): ExtMobileFrontend::domParseWithContentProvider(MobileFrontend\ContentProviders\DefaultContentProvider, MediaWiki\Output\OutputPage, bool)
#4 /opt/homebrew/var/www/w/includes/HookContainer/HookContainer.php(155): MobileFrontendHooks->onOutputPageBeforeHTML(MediaWiki\Output\OutputPage, string)
#5 /opt/homebrew/var/www/w/includes/HookContainer/HookRunner.php(3083): MediaWiki\HookContainer\HookContainer->run(string, array)
#6 /opt/homebrew/var/www/w/includes/Output/OutputPage.php(2633): MediaWiki\HookContainer\HookRunner->onOutputPageBeforeHTML(MediaWiki\Output\OutputPage, string)
#7 /opt/homebrew/var/www/w/includes/Output/OutputPage.php(2661): MediaWiki\Output\OutputPage->addParserOutputText(string, array)
#8 /opt/homebrew/var/www/w/includes/page/Article.php(931): MediaWiki\Output\OutputPage->addParserOutput(MediaWiki\Parser\ParserOutput, MediaWiki\Parser\ParserOptions, array)
#9 /opt/homebrew/var/www/w/includes/page/Article.php(739): MediaWiki\Page\Article->doOutputFromParserCache(MediaWiki\Parser\ParserOutput, MediaWiki\Parser\ParserOptions, MediaWiki\Output\OutputPage, array)
#10 /opt/homebrew/var/www/w/includes/page/Article.php(551): MediaWiki\Page\Article->generateContentOutput(MediaWiki\User\User, MediaWiki\Parser\ParserOptions, int, MediaWiki\Output\OutputPage, array)
#11 /opt/homebrew/var/www/w/includes/actions/ViewAction.php(84): MediaWiki\Page\Article->view()
#12 /opt/homebrew/var/www/w/includes/actions/ActionEntryPoint.php(734): MediaWiki\Actions\ViewAction->show()
#13 /opt/homebrew/var/www/w/includes/actions/ActionEntryPoint.php(505): MediaWiki\Actions\ActionEntryPoint->performAction(MediaWiki\Page\Article, MediaWiki\Title\Title)
#14 /opt/homebrew/var/www/w/includes/actions/ActionEntryPoint.php(143): MediaWiki\Actions\ActionEntryPoint->performRequest()
#15 /opt/homebrew/var/www/w/includes/MediaWikiEntryPoint.php(198): MediaWiki\Actions\ActionEntryPoint->execute()
#16 /opt/homebrew/var/www/w/index.php(58): MediaWiki\MediaWikiEntryPoint->run()
#17 {main}

Main Page contains:

<strong>MediaWiki has been installed.</strong>

Consult the [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] for information on using the wiki software.

== Getting started ==
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]
egardner lowered the priority of this task from High to Medium.Oct 9 2025, 5:15 PM

Change #1182901 merged by jenkins-bot:

[mediawiki/extensions/MobileFrontend@master] Use Parsoid DOM types to support PHP >= 8.4

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

Change #1182910 merged by jenkins-bot:

[mediawiki/extensions/MobileFrontend@master] Replace use of DOMXPath in MakeSectionsTransform

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

Change #1182911 merged by jenkins-bot:

[mediawiki/extensions/MobileFrontend@master] Replace use of DOMXPath in MoveLeadParagraphTransform

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

Change #1182920 merged by jenkins-bot:

[mediawiki/extensions/MobileFrontend@master] Verify DOM types against IDLeDOM

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

@bvibber Patches were merged, should work now?

@bvibber Patches were merged, should work now?

testing... woohoo! CONFIRMED mobile pages with offending sections now working on my Mac running macOS 15 and homebrew with PHP 8.4.14 (apache2handler)

Thanks everybody for making this fix happen; this simplifies my dev setup a lot by not having to keep a second version of PHP hacked into my web server. :D

I think we're good to resolve this task now!

cscott claimed this task.
cscott added a project: Essential-Work.