Page MenuHomePhabricator

CargoPageValues should initialize Parser with a PageReference [PATCH]
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue:

  • Make sure you didn't disable PHP deprecation warnings, and that you have a way to see them.
  • Make sure you have the bundled PageImages extension enabled, and Cargo installed and enabled.
  • Visit the PageValues special page implemented by Cargo, e.g.: /wiki/Special:PageValues/SomeTitle.
  • Alternatively to the last point, this also works: /w/index.php?title=SomeTitle&action=pagevalues.

(Either way, the Cargo special page PageValues is invoked with the given page title as a "parameter" of sorts.)

What happens?:

The following deprecation warning is logged:

Use of MediaWiki\Parser\Parser::getPage without a Title set was deprecated in MediaWiki 1.34. [Called from PageImages\Hooks\ParserFileProcessingHookHandlers::onParserModifyImageHTML in /path/to/mw/extensions/PageImages/includes/Hooks/ParserFileProcessingHookHandlers.php at line 110]

What should have happened instead?:

I believe no deprecation warning should be logged, but I'm not entirely sure what's going on; see below for as far as my investigation went.

Software version:

MW 1.43.5 with the corresponding PageImages version, and latest Cargo release at this time (3.8.4).

https://bg3.wiki/wiki/Special:Version

Judging by the source code, I believe this issue probably still exists in the latest version of MediaWiki & PageImages, but I can't be sure because I don't have an environment where I can test it.

Other information:

I've traced the cause of this faulty(?) warning as follows, though I couldn't get to the root cause:

  1. PageImages calls $parser->getPage() here: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/PageImages/+/refs/heads/master/includes/Hooks/ParserFileProcessingHookHandlers.php#90 (This would be line 110 in the REL1_43 branch; it's line 90 on master right now.)
  2. That function checks if ( $this->mTitle->isSpecial( 'Badtitle' ) ) { ... }: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/master/includes/parser/Parser.php#968
  3. I believe that if statement should fail, since we are clearly in Special:PageValues which is a valid special page implemented by Cargo. However...
  4. The Title::isSpecial( $name ) implementation seems to call SpecialPageFactory::resolveAlias() with $this->mDbkeyform: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/master/includes/title/Title.php#1254 (At this point, I'm not sure what the Title object has in its mDbkeyform field.)
  5. That method, SpecialPageFactory::resolveAlias(), is just meant to split e.g. PageValues/SomeTitle into PageValues and SomeTitle, but instead it returns Badtitle as the first value (and Missing as the second; see below).
  6. The reason for that appears to be that the result of SpecialPageFactory::getAliasList() must be mapping PageValues to Badtitle for some reason? Or does $title->mDbkeyvalue not contain PageValues/SomeTitle at this point? I don't know; this is as far as I got.
  7. Note that after the if statement above passes, there's a further call to SpecialPageFactory::resolveAlias() but this time getting the second value it returns; this ends up being 'Missing' instead of the actual title.

Here's Cargo's implementation of Special:PageValues: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/Cargo/+/refs/heads/master/includes/specials/CargoPageValues.php

I can't tell if the problem is with PageImages, Cargo, or MW core.

Event Timeline

Cargo seems the likeliest cause here; PageImages isn't doing something weird and this warning usually means that whatever set up the parser didn't do so properly.

I agree that this shouldn't be happening, though.

Found the root cause, I think.

Parser.php sets mTitle to Title::makeTitle( NS_SPECIAL, 'Badtitle/Missing' ) at the end of __construct() so that's surely where the Badtitle and Missing shenanigans come from.

That mTitle property is private, and after the constructor it's only set in setPage(). That is also called from setTitle() (deprecated) and startParse() which is private and called from a bunch of other methods like parse().

This means one must call either setPage(), setTitle(), or one of the parse entry points with a valid page or title object, or else it will remain Special:Badtitle/Missing.

CargoPageValues ends up invoking the parser by calling CargoQueryDisplayer::getFormattedQueryResults() which calls formatFieldValue() which calls CargoUtils::smartParse().

There, it gets a parser via MediaWikiServices::getInstance()->getParser() which, I assume, is not automatically initialized with the current page.

I guess the best thing to do is for CargoPageValues to call MediaWikiServices::getInstance()->getParser().setPage(...) somewhere at the start. E.g.:

diff --git a/includes/specials/CargoPageValues.php b/includes/specials/CargoPageValues.php
index 6b32812..203d042 100644
--- a/includes/specials/CargoPageValues.php
+++ b/includes/specials/CargoPageValues.php
@@ -9,6 +9,8 @@
 
 use MediaWiki\Html\Html;
 use MediaWiki\Title\Title;
+use MediaWiki\Page\PageReferenceValue;
+use MediaWiki\MediaWikiServices;
 
 class CargoPageValues extends IncludableSpecialPage {
        public $mTitle;
@@ -38,6 +40,9 @@ class CargoPageValues extends IncludableSpecialPage {
                $pageName = $this->mTitle->getPrefixedText();
                $out->setPageTitle( $this->msg( 'cargo-pagevaluesfor', $pageName )->text() );
 
+               $pageRef = PageReferenceValue::localReference( NS_SPECIAL, "PageValues/$pageName" );
+               MediaWikiServices::getInstance()->getParser()->setPage( $pageRef );
+
                $text = '';
 
                $tableNames = [];

Seems to stop the deprecation warnings for me.

@Yaron_Koren Would be great if this could be applied to the next release :-)

Taylan renamed this task from Parser::getPage() erroneously(?) reports deprecation warning. to CargoPageValues should initialize Parser with a PageReference [PATCH].Oct 4 2025, 10:56 AM
Taylan removed a project: PageImages.

Change #1193929 had a related patch set uploaded (by Yaron Koren; author: Yaron Koren):

[mediawiki/extensions/Cargo@master] Add PageReference to Parser in Special:PageValues

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

Change #1193929 merged by jenkins-bot:

[mediawiki/extensions/Cargo@master] Add PageReference to Parser in Special:PageValues - patch by Taylan

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

@Taylan - thank you for the research, and the detailed explanation! Hopefully this fixes the problem.

Yaron_Koren claimed this task.