Skip to content

Commit b27b7dd

Browse files
kghblnmalberts
authored andcommitted
Fix TypeError in ImageModal when file does not exist
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: #71
1 parent 21785bb commit b27b7dd

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/HooksHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ public function onImageBeforeProduceHTML(
140140
): bool {
141141
if ( $this->getConfig()->has( 'BootstrapComponentsModalReplaceImageTag' ) &&
142142
$this->getConfig()->get( 'BootstrapComponentsModalReplaceImageTag' ) ) {
143+
if ( !$file ) {
144+
return true;
145+
}
143146
$imageModal = new ImageModal( $linker, $title, $file,
144147
$this->getNestingController(), $this->getBootstrapComponentsService()
145148
);

0 commit comments

Comments
 (0)