From e562c908e89306289f21aa7a85fac5822394e823 Mon Sep 17 00:00:00 2001 From: Lens0021 Date: Thu, 14 Apr 2022 11:47:36 +0900 Subject: [PATCH] Add support for MediaWiki 1.38 (#73) --- .phan/config.php | 1 + .../PortableInfoboxParserTagController.php | 25 +++++++++++++++++-- .../Helpers/PortableInfoboxParsingHelper.php | 14 +++++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index c76bfea..49570e5 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -17,6 +17,7 @@ $cfg['exclude_analysis_directory_list'] = array_merge( $cfg['suppress_issue_types'] = [ 'PhanPluginMixedKeyNoKey', 'SecurityCheck-LikelyFalsePositive', + 'UnusedPluginSuppression', ]; $cfg['scalar_implicit_cast'] = true; diff --git a/includes/controllers/PortableInfoboxParserTagController.php b/includes/controllers/PortableInfoboxParserTagController.php index 74d1efd..634be47 100644 --- a/includes/controllers/PortableInfoboxParserTagController.php +++ b/includes/controllers/PortableInfoboxParserTagController.php @@ -156,7 +156,7 @@ class PortableInfoboxParserTagController { // (see: PortableInfoboxDataService.class.php) $infoboxes = json_decode( - $parserOutput->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), + self::parserOutputGetPageProperty( $parserOutput, PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), true ); @@ -168,12 +168,33 @@ class PortableInfoboxParserTagController { 'metadata' => $raw->getMetadata() ]; - $parserOutput->setProperty( + self::parserOutputSetPageProperty( + $parserOutput, PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME, json_encode( $infoboxes ) ); } + private static function parserOutputGetPageProperty( \ParserOutput $parserOutput, string $name ) { + if ( method_exists( \ParserOutput::class, 'getPageProperty' ) ) { + // @phan-suppress-next-line PhanUndeclaredMethod since 1.38 + return $parserOutput->getPageProperty( $name ); + } else { + // @phan-suppress-next-line PhanDeprecatedFunction deprecated since 1.38 + return $parserOutput->getProperty( $name ); + } + } + + private static function parserOutputSetPageProperty( \ParserOutput $parserOutput, string $name, $value ) { + if ( method_exists( \ParserOutput::class, 'setPageProperty' ) ) { + // @phan-suppress-next-line PhanUndeclaredMethod since 1.38 + $parserOutput->setPageProperty( $name, $value ); + } else { + // @phan-suppress-next-line PhanDeprecatedFunction deprecated since 1.38 + $parserOutput->setProperty( $name, $value ); + } + } + private function handleError( $message ) { $renderedValue = ' ' . $message . ''; diff --git a/includes/services/Helpers/PortableInfoboxParsingHelper.php b/includes/services/Helpers/PortableInfoboxParsingHelper.php index 038093a..1575f3f 100644 --- a/includes/services/Helpers/PortableInfoboxParsingHelper.php +++ b/includes/services/Helpers/PortableInfoboxParsingHelper.php @@ -52,7 +52,7 @@ class PortableInfoboxParsingHelper { } return json_decode( - $parser->getOutput()->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), + self::parserOutputGetPageProperty( $parser->getOutput(), PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), true ); } @@ -68,11 +68,21 @@ class PortableInfoboxParsingHelper { $parser->parse( $this->fetchArticleContent( $title ), $title, $parserOptions ); return json_decode( - $parser->getOutput()->getProperty( PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), + self::parserOutputGetPageProperty( $parser->getOutput(), PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME ), true ); } + private static function parserOutputGetPageProperty( \ParserOutput $parserOutput, string $name ) { + if ( method_exists( \ParserOutput::class, 'getPageProperty' ) ) { + // @phan-suppress-next-line PhanUndeclaredMethod since 1.38 + return $parserOutput->getPageProperty( $name ); + } else { + // @phan-suppress-next-line PhanDeprecatedFunction deprecated since 1.38 + return $parserOutput->getProperty( $name ); + } + } + /** * @param Title $title *