From 2f3ebb21ef89a450739d9197c195031831a23d81 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Sun, 21 Jan 2024 19:41:02 -0500 Subject: [PATCH] Do not crash if addwiki/mediawiki-api-base is missing Instead of crashing with a fatal error and a stack trace, check if one of the classes that we need is available, using that class as a proxy for the overall package. If not, uses of the parser function return a nice error message but the parsing does not fail and the rest of the page can be shown. WIK-1250 --- src/RemoteWiki.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/RemoteWiki.php b/src/RemoteWiki.php index 0ee80ef..f739b78 100644 --- a/src/RemoteWiki.php +++ b/src/RemoteWiki.php @@ -52,6 +52,14 @@ public function __construct( * @return string */ public function remoteVersion( Parser $parser, $endPoint = null, $type = null ): string { + // Verify that the `addwiki/mediawiki-api-base` composer dependency is + // installed - we check if the `Addwiki\Mediawiki\Api\Client\MediaWiki` + // class is installed and assume that if it is, the entire package is + // available. + if ( !class_exists( MediaWiki::class ) ) { + return '(RemoteWiki: addwiki/mediawiki-api-base not installed)'; + } + if ( !$this->validateEndpoint( $endPoint ) ) { return ''; }