Inject service ContentLanguage into ThreadItemStore

Change-Id: Ie9b7d462c8ddf4abb749ee07537ccec1949b8fba
This commit is contained in:
Fomafix 2024-07-03 10:16:27 +00:00
parent af1ee2ded7
commit 3c76c7918b
2 changed files with 8 additions and 5 deletions

View file

@ -44,7 +44,8 @@ return [
$services->getPageStore(), $services->getPageStore(),
$services->getRevisionStore(), $services->getRevisionStore(),
$services->getTitleFormatter(), $services->getTitleFormatter(),
$services->getActorStore() $services->getActorStore(),
$services->getContentLanguage()
); );
}, },
'DiscussionTools.ThreadItemFormatter' => static function ( MediaWikiServices $services ): ThreadItemFormatter { 'DiscussionTools.ThreadItemFormatter' => static function ( MediaWikiServices $services ): ThreadItemFormatter {

View file

@ -3,6 +3,7 @@
namespace MediaWiki\Extension\DiscussionTools; namespace MediaWiki\Extension\DiscussionTools;
use Exception; use Exception;
use Language;
use MediaWiki\Config\Config; use MediaWiki\Config\Config;
use MediaWiki\Config\ConfigFactory; use MediaWiki\Config\ConfigFactory;
use MediaWiki\Extension\DiscussionTools\ThreadItem\CommentItem; use MediaWiki\Extension\DiscussionTools\ThreadItem\CommentItem;
@ -10,7 +11,6 @@ use MediaWiki\Extension\DiscussionTools\ThreadItem\DatabaseCommentItem;
use MediaWiki\Extension\DiscussionTools\ThreadItem\DatabaseHeadingItem; use MediaWiki\Extension\DiscussionTools\ThreadItem\DatabaseHeadingItem;
use MediaWiki\Extension\DiscussionTools\ThreadItem\DatabaseThreadItem; use MediaWiki\Extension\DiscussionTools\ThreadItem\DatabaseThreadItem;
use MediaWiki\Extension\DiscussionTools\ThreadItem\HeadingItem; use MediaWiki\Extension\DiscussionTools\ThreadItem\HeadingItem;
use MediaWiki\MediaWikiServices;
use MediaWiki\Page\PageStore; use MediaWiki\Page\PageStore;
use MediaWiki\Revision\RevisionRecord; use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\RevisionStore; use MediaWiki\Revision\RevisionStore;
@ -44,6 +44,7 @@ class ThreadItemStore {
private RevisionStore $revStore; private RevisionStore $revStore;
private TitleFormatter $titleFormatter; private TitleFormatter $titleFormatter;
private ActorStore $actorStore; private ActorStore $actorStore;
private Language $language;
public function __construct( public function __construct(
ConfigFactory $configFactory, ConfigFactory $configFactory,
@ -52,7 +53,8 @@ class ThreadItemStore {
PageStore $pageStore, PageStore $pageStore,
RevisionStore $revStore, RevisionStore $revStore,
TitleFormatter $titleFormatter, TitleFormatter $titleFormatter,
ActorStore $actorStore ActorStore $actorStore,
Language $language
) { ) {
$this->config = $configFactory->makeConfig( 'discussiontools' ); $this->config = $configFactory->makeConfig( 'discussiontools' );
$this->dbProvider = $dbProvider; $this->dbProvider = $dbProvider;
@ -61,6 +63,7 @@ class ThreadItemStore {
$this->revStore = $revStore; $this->revStore = $revStore;
$this->titleFormatter = $titleFormatter; $this->titleFormatter = $titleFormatter;
$this->actorStore = $actorStore; $this->actorStore = $actorStore;
$this->language = $language;
} }
/** /**
@ -181,9 +184,8 @@ class ThreadItemStore {
return []; return [];
} }
$language = MediaWikiServices::getInstance()->getContentLanguage();
// Mirrors CommentParser::truncateForId // Mirrors CommentParser::truncateForId
$heading = trim( $language->truncateForDatabase( $heading, 80, '' ), '_' ); $heading = trim( $this->language->truncateForDatabase( $heading, 80, '' ), '_' );
$dbw = $this->dbProvider->getPrimaryDatabase(); $dbw = $this->dbProvider->getPrimaryDatabase();