Nothing Special   »   [go: up one dir, main page]

Page MenuHomePhabricator

Error: Call to a member function addModules() on null
Closed, ResolvedPublic

Description

from /srv/mediawiki/1.42/includes/gallery/TraditionalImageGallery.php(71)<br />\n#0 /srv/mediawiki/1.42/extensions/Cargo/includes/formats/CargoGalleryFormat.php(170): TraditionalImageGallery-&gt;toHTML()

Event Timeline

Running MediaWiki 1.42 and php 8.2

Change #1078053 had a related patch set uploaded (by Paladox; author: Paladox):

[mediawiki/extensions/Cargo@master] Fix "Error: Call to a member function addModules() on null"

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

Hi - what version of Cargo? For what it's worth, the current/old code works fine me, on MW 1.43.

Hi - what version of Cargo? For what it's worth, the current/old code works fine me, on MW 1.43.

3.6.1 (0dd6d46) 08:22, 9 September 2024

Okay. That's unfortunate - I just tried, and it it looks like, with MW 1.43, the exact opposite problem happens: getParser() works fine, but using getParserFactory() leads to that "Call to a member function addModules() on null" error. Evidently there was some rearrangement of the setting of ParserOutput between MW 1.42 and 1.43. I don't know what the best solution for this is.

Actually - having looked more at the code, I may have found a fix that works for all MW versions. Could you try putting in the following change?

--- a/includes/formats/CargoGalleryFormat.php
+++ b/includes/formats/CargoGalleryFormat.php
@@ -142,7 +142,12 @@ class CargoGalleryFormat extends CargoDisplayFormat {
                        // User specified something invalid, fallback to default.
                        $gallery = ImageGalleryBase::factory( false );
                }
-               $gallery->setParser( MediaWikiServices::getInstance()->getParser() );
+               $parseWidthParamChecker = new ReflectionMethod( Parser::class, 'parseWidthParam' );
+               if ( !$parseWidthParamChecker->isStatic() ) {
+                       // MW >= 1.43
+                       // This is all due to the change at
+                       // https://phabricator.wikimedia.org/rMW0450b5e4d58387a0d57dc699c2c58f8e780ca44e
+                       $gallery->setParser( MediaWikiServices::getInstance()->getParser() );
+               }

If I works for you on mw 1.42 then it's safe for you to merge.

Change #1078053 merged by jenkins-bot:

[mediawiki/extensions/Cargo@master] Fix "Error: Call to a member function addModules() on null"

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

Yaron_Koren claimed this task.

Okay, hopefully it works across all versions now!