Fix _PAGEIMG annotation on MediaWiki 1.46 (PageImages::getPageImage() removed) - #287
Merged
Conversation
PageImages\PageImages::getPageImage() was deprecated in MediaWiki 1.45 and removed in MediaWiki 1.46, so PageImagesPropertyAnnotator throws Error: Call to undefined method PageImages\PageImages::getPageImage() on 1.46. The existing class_exists() guard cannot catch this: the class still exists, only the static method is gone. The throw happens in getPageImage() -> getPageImageTitle() -> addAnnotation(), before any addPropertyObjectValue() call completes. Since nothing in the class catches it, the Error propagates out of the annotator and aborts the entire smw.update job, so *all* semantic data for the page is lost -- not just the page image annotation. Prefer the PageImages.PageImages service (registered since MW 1.44) and its instance method getImage( Title ): ?File, falling back to the static method so MW 1.43 -- the oldest version extension.json supports -- keeps working. ServiceContainer::hasService() is available across the whole supported range; MW 1.43 and 1.46 both pin wikimedia/services 4.0.0. getImage() returns ?File, so `?? false` preserves the declared File|bool return type of getPageImage(). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014voSKNULm15JZokJ4CqBJk
Codecov Report❌ Patch coverage is
❌ Your project check has failed because the head coverage (87.71%) is below the adjusted base coverage (88.23%). You can increase the head coverage or adjust the Removed Code Behavior. Additional details and impacted files@@ Coverage Diff @@
## master #287 +/- ##
============================================
- Coverage 88.14% 87.71% -0.43%
- Complexity 377 379 +2
============================================
Files 40 40
Lines 1021 1026 +5
============================================
Hits 900 900
- Misses 121 126 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On MediaWiki 1.46,
_PAGEIMGannotation throws an uncaughtError. Because the throw happens before any property value is written, it aborts the wholesmw.updatejob — so all semantic data for the page is lost, not just the page-image annotation.Root cause
PageImages\PageImages::getPageImage()was deprecated in MW 1.45 and removed in MW 1.46.PageImages.PageImagesservicegetPageImage()getImage()ServiceWiring.php)The existing
class_exists( '\PageImages\PageImages' )guard cannot catch this — the class still exists, only the static method is gone.Impact
getPageImage()is called fromgetPageImageTitle(), called fromaddAnnotation()beforeaddPropertyObjectValue()runs. There is notry/catchin the class, so theErrorpropagates out of the annotator and kills the entire job.Observed on a production wiki (MW 1.46, SMW 7.1.0-alpha, PHP 8.4): every job in every sampled runner invocation failed, with the queue entering
"reached": "none-ready"and a backoff set onsmw.update.{ "jobs": [ { "type": "smw.update", "status": "failed", "error": "Error: Call to undefined method PageImages\\PageImages::getPageImage() in …/PageImagesPropertyAnnotator.php on line 80", "time": 3700 } ], "reached": "none-ready" }The fix
Prefer the
PageImages.PageImagesservice (registered since MW 1.44) and its instance methodgetImage( Title ): ?File, falling back to the static method so MW 1.43 — the oldest versionextension.jsonsupports ("MediaWiki": ">= 1.43") — keeps working.This matches the migration path named in PageImages' own commit introducing the service:
$services->getService( 'PageImages.PageImages' )->getImage( $title ).ServiceContainer::hasService()is available across the whole supported range — MW 1.43 and 1.46 both pinwikimedia/services4.0.0, which has it.getImage()returns?File, so?? falsepreserves the declaredFile|boolreturn type.Behaviour is otherwise unchanged: if PageImages is not installed,
class_exists()is false and the method returnsfalseexactly as before.Why CI did not catch it
.github/workflows/ci.yamlcovers MW 1.43, 1.44 and 1.45 only. MW 1.46 — the sole version where the method is absent — is untested, whileextension.jsondeclares">= 1.43"with no upper bound. Adding 1.46 to the matrix would be worthwhile as a follow-up.Testing
php -lclean.REL1_43/REL1_44/REL1_45/REL1_46andwikimedia/services4.0.0.PageImages.PageImagesis reliably available at the point the annotator runs inside a job.