Page MenuHomePhabricator

TypeError: MediaWiki\Extension\PdfHandler\PdfHandler::pageCount(): Argument #1 ($image) must be of type MediaWiki\FileRepo\File\File, MediaWiki\FileRepo\File\ArchivedFile given, called in /srv/mediawiki/php-1.45.0-wmf.22/includ
Open, Needs TriagePublicPRODUCTION ERROR

Description

Error
  • service.version: 1.45.0-wmf.22
  • timestamp: 2025-10-09T00:58:10.467Z
  • labels.phpversion: 8.1.33
  • trace.id: 9ff38741-fd55-4a44-8e65-bee38ce7a05b
  • Find trace.id in Logstash
labels.normalized_message
[{reqId}] {exception_url}   TypeError: MediaWiki\Extension\PdfHandler\PdfHandler::pageCount(): Argument #1 ($image) must be of type MediaWiki\FileRepo\File\File, MediaWiki\FileRepo\File\ArchivedFile given, called in /srv/mediawiki/php-1.45.0-wmf.22/includ
FrameLocationCall
from/srv/mediawiki/php-1.45.0-wmf.22/extensions/PdfHandler/includes/PdfHandler.php(366)
#0/srv/mediawiki/php-1.45.0-wmf.22/includes/filerepo/file/ArchivedFile.php(643)MediaWiki\Extension\PdfHandler\PdfHandler->pageCount(MediaWiki\FileRepo\File\ArchivedFile)
#1/srv/mediawiki/php-1.45.0-wmf.22/includes/api/ApiQueryFilearchive.php(214)MediaWiki\FileRepo\File\ArchivedFile->pageCount()
#2/srv/mediawiki/php-1.45.0-wmf.22/includes/api/ApiQuery.php(752)MediaWiki\Api\ApiQueryFilearchive->execute()
#3/srv/mediawiki/php-1.45.0-wmf.22/includes/api/ApiMain.php(2036)MediaWiki\Api\ApiQuery->execute()
#4/srv/mediawiki/php-1.45.0-wmf.22/includes/api/ApiMain.php(944)MediaWiki\Api\ApiMain->executeAction()
#5/srv/mediawiki/php-1.45.0-wmf.22/includes/api/ApiMain.php(915)MediaWiki\Api\ApiMain->executeActionWithErrorHandling()
#6/srv/mediawiki/php-1.45.0-wmf.22/includes/api/ApiEntryPoint.php(138)MediaWiki\Api\ApiMain->execute()
#7/srv/mediawiki/php-1.45.0-wmf.22/includes/MediaWikiEntryPoint.php(184)MediaWiki\Api\ApiEntryPoint->execute()
#8/srv/mediawiki/php-1.45.0-wmf.22/api.php(30)MediaWiki\MediaWikiEntryPoint->run()
#9/srv/mediawiki/w/api.php(3)require(string)
#10{main}
Notes
  • Started in 1.45.0-wmf.22
  • Only 6 hits so far after rolling to group1

Details

Request URL
https://commons.wikimedia.org/w/api.php?action=query&falimit=*&faprefix=*&faprop=*&format=*&formatversion=*&list=*

Event Timeline

TheDJ subscribed.

This is a bug in core, not in PdfHandler. The API asks for pagecount, so ApiQueryFilearchive calls ArchivedFile::pageCount(), which hands the handler $this:

// ArchivedFile.php:644
$this->pageCount = $this->handler->pageCount( $this );

But ArchivedFile doesn't extend File, which is what MediaHandler expects:

// MediaHandler.php:558
public function pageCount( File $file ) { … }

PdfHandler just inherits that signature. This seems to have been broken for a while (at least 2019). I'm guessing this is why MediaHandler::isMultiPage() still uses untyped argument for file.

There doesn't even seem to be a good fix for this right now, as File and ArchivedFile have no suitable interface contract and pageCount itself depends on metadata retrieval via getDimensionInfo, but that depends on MediaHandlerState, which ArchivedFile also doens't implement.

I think that technically means that an ArchivedFile cannot return the pagecount to begin with, and this has bleeded into the the API triggering this problem...
Question is.. do we remove pageCount from ArchivedFile ?