Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LexemeHistoryAction
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getPageTitle
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare( strict_types = 1 );
4
5namespace Wikibase\Lexeme\MediaWiki\Actions;
6
7use MediaWiki\Actions\HistoryAction;
8use MediaWiki\Context\IContextSource;
9use MediaWiki\Page\Article;
10use Wikibase\Lexeme\DataAccess\Store\LemmaLookup;
11use Wikibase\Lexeme\Domain\Model\LexemeId;
12use Wikibase\Lexeme\Presentation\Formatters\LexemeTermFormatter;
13use Wikibase\Lib\Store\EntityIdLookup;
14
15/**
16 * @license GPL-2.0-or-later
17 */
18class LexemeHistoryAction extends HistoryAction {
19
20    private EntityIdLookup $entityIdLookup;
21    private LemmaLookup $lemmaLookup;
22    private LexemeTermFormatter $lexemeTermFormatter;
23
24    public function __construct(
25        Article $article,
26        IContextSource $context,
27        EntityIdLookup $entityIdLookup,
28        LemmaLookup $lemmaLookup,
29        LexemeTermFormatter $lexemeTermFormatter
30    ) {
31        parent::__construct( $article, $context );
32
33        $this->entityIdLookup = $entityIdLookup;
34        $this->lemmaLookup = $lemmaLookup;
35        $this->lexemeTermFormatter = $lexemeTermFormatter;
36    }
37
38    /** @inheritDoc */
39    protected function getPageTitle() {
40        /** @var LexemeId $lexemeId */
41        $lexemeId = $this->entityIdLookup->getEntityIdForTitle( $this->getTitle() );
42        '@phan-var LexemeId $lexemeId';
43
44        if ( !$lexemeId ) {
45            return parent::getPageTitle();
46        }
47
48        $idSerialization = $lexemeId->getSerialization();
49        $lemmaTerms = $this->lemmaLookup->getLemmas( $lexemeId );
50
51        $labelText = $this->lexemeTermFormatter->format( $lemmaTerms );
52
53        return $this->msg( 'wikibase-history-title-with-label' )
54            ->plaintextParams( $idSerialization )->rawParams( $labelText );
55    }
56}