From 85165543f4edda8168a6fc27f5582925f49624d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 21 Feb 2022 18:39:36 +0100 Subject: [PATCH] CommentParser: Inject a forgotten service Also sort alphabetically. Change-Id: I9e77c4aa1fba930f382e3c4f17ac0504c2f06668 --- includes/CommentParser.php | 30 +++++++++++++++++------------- includes/ServiceWiring.php | 3 ++- tests/phpunit/TestUtils.php | 3 ++- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/includes/CommentParser.php b/includes/CommentParser.php index f1601ef37..67308f18c 100644 --- a/includes/CommentParser.php +++ b/includes/CommentParser.php @@ -8,7 +8,7 @@ use DateTime; use DateTimeImmutable; use DateTimeZone; use Language; -use MediaWiki\MediaWikiServices; +use MediaWiki\Languages\LanguageConverterFactory; use MWException; use Title; use Wikimedia\IPUtils; @@ -22,16 +22,12 @@ use Wikimedia\Parsoid\Utils\DOMCompat; class CommentParser { private const SIGNATURE_SCAN_LIMIT = 100; - /** @var Element */ - private $rootNode; - /** @var Title */ - private $title; - /** @var Config */ private $config; - /** @var Language */ private $language; + /** @var LanguageConverterFactory */ + private $languageConverterFactory; private $dateFormat; private $digits; @@ -40,16 +36,26 @@ class CommentParser { private $localTimezone; private $timezones; + /** @var Element */ + private $rootNode; + /** @var Title */ + private $title; + /** - * @param Language $language Content language * @param Config $config + * @param Language $language Content language + * @param LanguageConverterFactory $languageConverterFactory * @param LanguageData $languageData */ public function __construct( - Language $language, Config $config, LanguageData $languageData + Config $config, + Language $language, + LanguageConverterFactory $languageConverterFactory, + LanguageData $languageData ) { $this->config = $config; $this->language = $language; + $this->languageConverterFactory = $languageConverterFactory; $data = $languageData->getLocalData(); $this->dateFormat = $data['dateFormat']; @@ -464,8 +470,7 @@ class CommentParser { * @return string[] Regular expressions */ public function getLocalTimestampRegexps(): array { - $langConv = MediaWikiServices::getInstance()->getLanguageConverterFactory() - ->getLanguageConverter( $this->language ); + $langConv = $this->languageConverterFactory->getLanguageConverter( $this->language ); return array_map( function ( $contLangVariant ) { return $this->getTimestampRegexp( $contLangVariant, @@ -485,8 +490,7 @@ class CommentParser { * @return callable[] Parser functions */ private function getLocalTimestampParsers(): array { - $langConv = MediaWikiServices::getInstance()->getLanguageConverterFactory() - ->getLanguageConverter( $this->language ); + $langConv = $this->languageConverterFactory->getLanguageConverter( $this->language ); return array_map( function ( $contLangVariant ) { return $this->getTimestampParser( $contLangVariant, diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 19f59f4a2..4d4d6bbe1 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -7,8 +7,9 @@ use MediaWiki\MediaWikiServices; return [ 'DiscussionTools.CommentParser' => static function ( MediaWikiServices $services ): CommentParser { return new CommentParser( - $services->getContentLanguage(), $services->getMainConfig(), + $services->getContentLanguage(), + $services->getLanguageConverterFactory(), $services->getService( 'DiscussionTools.LanguageData' ) ); }, diff --git a/tests/phpunit/TestUtils.php b/tests/phpunit/TestUtils.php index 5092cd9a8..a843c45b4 100644 --- a/tests/phpunit/TestUtils.php +++ b/tests/phpunit/TestUtils.php @@ -124,8 +124,9 @@ trait TestUtils { public static function createParser( array $data ): CommentParser { $services = MediaWikiServices::getInstance(); return new CommentParser( - $services->getContentLanguage(), $services->getMainConfig(), + $services->getContentLanguage(), + $services->getLanguageConverterFactory(), new MockLanguageData( $data ) ); }