Fix TypeError in ImageModal when file does not exist#72
Merged
malberts merged 1 commit intooetterer:masterfrom Mar 30, 2026
Merged
Fix TypeError in ImageModal when file does not exist#72malberts merged 1 commit intooetterer:masterfrom
malberts merged 1 commit intooetterer:masterfrom
Conversation
The ImageBeforeProduceHTML hook passes File|false for the $file parameter. When a page references a non-existent file, $file is false. ImageModal::__construct() has a strict File type hint, causing a TypeError. Add a guard to skip modal replacement when the file does not exist, letting MediaWiki render its normal missing-file link instead. Bug: oetterer#71
malberts
reviewed
Mar 30, 2026
| ): bool { | ||
| if ( $this->getConfig()->has( 'BootstrapComponentsModalReplaceImageTag' ) && | ||
| $this->getConfig()->get( 'BootstrapComponentsModalReplaceImageTag' ) ) { | ||
| if ( !$file ) { |
Collaborator
There was a problem hiding this comment.
This guard clause can be the first statement, before the existing if.
Better to test explicitly: $file === false
And the docstring is wrong. But that's for another day.
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
$wgBootstrapComponentsModalReplaceImageTagis enabled and a page references a non-existent file,onImageBeforeProduceHTMLpassesfalsefor$filetoImageModal::__construct(), which has a strictFiletype hint → TypeError$fileisfalse, letting MediaWiki render its normal missing-file linkFixes #71