Skip to content

Fix TypeError in ImageModal when file does not exist#72

Merged
malberts merged 1 commit intooetterer:masterfrom
kghbln:fix-imagemodal-file-bool
Mar 30, 2026
Merged

Fix TypeError in ImageModal when file does not exist#72
malberts merged 1 commit intooetterer:masterfrom
kghbln:fix-imagemodal-file-bool

Conversation

@kghbln
Copy link
Copy Markdown
Collaborator

@kghbln kghbln commented Mar 29, 2026

Summary

  • When $wgBootstrapComponentsModalReplaceImageTag is enabled and a page references a non-existent file, onImageBeforeProduceHTML passes false for $file to ImageModal::__construct(), which has a strict File type hint → TypeError
  • Adds a guard to skip modal replacement when $file is false, letting MediaWiki render its normal missing-file link

Fixes #71

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
@kghbln kghbln requested a review from malberts March 29, 2026 14:31
): bool {
if ( $this->getConfig()->has( 'BootstrapComponentsModalReplaceImageTag' ) &&
$this->getConfig()->get( 'BootstrapComponentsModalReplaceImageTag' ) ) {
if ( !$file ) {
Copy link
Copy Markdown
Collaborator

@malberts malberts Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@malberts malberts merged commit b27b7dd into oetterer:master Mar 30, 2026
0 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError in ImageModal when file doesn't exist (onImageBeforeProduceHTML)

2 participants