CommentParser: Inject a forgotten service

Also sort alphabetically.

Change-Id: I9e77c4aa1fba930f382e3c4f17ac0504c2f06668
This commit is contained in:
Bartosz Dziewoński 2022-02-21 18:39:36 +01:00
parent aeabff63c9
commit 85165543f4
3 changed files with 21 additions and 15 deletions

View file

@ -8,7 +8,7 @@ use DateTime;
use DateTimeImmutable; use DateTimeImmutable;
use DateTimeZone; use DateTimeZone;
use Language; use Language;
use MediaWiki\MediaWikiServices; use MediaWiki\Languages\LanguageConverterFactory;
use MWException; use MWException;
use Title; use Title;
use Wikimedia\IPUtils; use Wikimedia\IPUtils;
@ -22,16 +22,12 @@ use Wikimedia\Parsoid\Utils\DOMCompat;
class CommentParser { class CommentParser {
private const SIGNATURE_SCAN_LIMIT = 100; private const SIGNATURE_SCAN_LIMIT = 100;
/** @var Element */
private $rootNode;
/** @var Title */
private $title;
/** @var Config */ /** @var Config */
private $config; private $config;
/** @var Language */ /** @var Language */
private $language; private $language;
/** @var LanguageConverterFactory */
private $languageConverterFactory;
private $dateFormat; private $dateFormat;
private $digits; private $digits;
@ -40,16 +36,26 @@ class CommentParser {
private $localTimezone; private $localTimezone;
private $timezones; private $timezones;
/** @var Element */
private $rootNode;
/** @var Title */
private $title;
/** /**
* @param Language $language Content language
* @param Config $config * @param Config $config
* @param Language $language Content language
* @param LanguageConverterFactory $languageConverterFactory
* @param LanguageData $languageData * @param LanguageData $languageData
*/ */
public function __construct( public function __construct(
Language $language, Config $config, LanguageData $languageData Config $config,
Language $language,
LanguageConverterFactory $languageConverterFactory,
LanguageData $languageData
) { ) {
$this->config = $config; $this->config = $config;
$this->language = $language; $this->language = $language;
$this->languageConverterFactory = $languageConverterFactory;
$data = $languageData->getLocalData(); $data = $languageData->getLocalData();
$this->dateFormat = $data['dateFormat']; $this->dateFormat = $data['dateFormat'];
@ -464,8 +470,7 @@ class CommentParser {
* @return string[] Regular expressions * @return string[] Regular expressions
*/ */
public function getLocalTimestampRegexps(): array { public function getLocalTimestampRegexps(): array {
$langConv = MediaWikiServices::getInstance()->getLanguageConverterFactory() $langConv = $this->languageConverterFactory->getLanguageConverter( $this->language );
->getLanguageConverter( $this->language );
return array_map( function ( $contLangVariant ) { return array_map( function ( $contLangVariant ) {
return $this->getTimestampRegexp( return $this->getTimestampRegexp(
$contLangVariant, $contLangVariant,
@ -485,8 +490,7 @@ class CommentParser {
* @return callable[] Parser functions * @return callable[] Parser functions
*/ */
private function getLocalTimestampParsers(): array { private function getLocalTimestampParsers(): array {
$langConv = MediaWikiServices::getInstance()->getLanguageConverterFactory() $langConv = $this->languageConverterFactory->getLanguageConverter( $this->language );
->getLanguageConverter( $this->language );
return array_map( function ( $contLangVariant ) { return array_map( function ( $contLangVariant ) {
return $this->getTimestampParser( return $this->getTimestampParser(
$contLangVariant, $contLangVariant,

View file

@ -7,8 +7,9 @@ use MediaWiki\MediaWikiServices;
return [ return [
'DiscussionTools.CommentParser' => static function ( MediaWikiServices $services ): CommentParser { 'DiscussionTools.CommentParser' => static function ( MediaWikiServices $services ): CommentParser {
return new CommentParser( return new CommentParser(
$services->getContentLanguage(),
$services->getMainConfig(), $services->getMainConfig(),
$services->getContentLanguage(),
$services->getLanguageConverterFactory(),
$services->getService( 'DiscussionTools.LanguageData' ) $services->getService( 'DiscussionTools.LanguageData' )
); );
}, },

View file

@ -124,8 +124,9 @@ trait TestUtils {
public static function createParser( array $data ): CommentParser { public static function createParser( array $data ): CommentParser {
$services = MediaWikiServices::getInstance(); $services = MediaWikiServices::getInstance();
return new CommentParser( return new CommentParser(
$services->getContentLanguage(),
$services->getMainConfig(), $services->getMainConfig(),
$services->getContentLanguage(),
$services->getLanguageConverterFactory(),
new MockLanguageData( $data ) new MockLanguageData( $data )
); );
} }