From 2735ef964cd747af42c89753ea5204aa2851b248 Mon Sep 17 00:00:00 2001 From: kghbln Date: Sun, 29 Mar 2026 16:30:32 +0200 Subject: [PATCH] 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: https://github.com/oetterer/BootstrapComponents/issues/71 --- src/HooksHandler.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/HooksHandler.php b/src/HooksHandler.php index 475142f..fa01e95 100644 --- a/src/HooksHandler.php +++ b/src/HooksHandler.php @@ -140,6 +140,9 @@ public function onImageBeforeProduceHTML( ): bool { if ( $this->getConfig()->has( 'BootstrapComponentsModalReplaceImageTag' ) && $this->getConfig()->get( 'BootstrapComponentsModalReplaceImageTag' ) ) { + if ( !$file ) { + return true; + } $imageModal = new ImageModal( $linker, $title, $file, $this->getNestingController(), $this->getBootstrapComponentsService() );