Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ParserContext | |
0.00% |
0 / 5 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getPrefixedDBkey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRevisionId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTargetLanguage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Kartographer\Tag; |
4 | |
5 | use MediaWiki\Language\Language; |
6 | use MediaWiki\Parser\Parser; |
7 | use MediaWiki\Title\TitleFormatter; |
8 | |
9 | /** |
10 | * Meant to encapsulate all relevant incoming (!) context that's historically attached to the legacy |
11 | * {@see Parser} class. This is very similar to Parsoid's "view of {@see ParserOptions}", see |
12 | * {@see \MediaWiki\Parser\Parsoid\Config\PageConfig}. |
13 | * |
14 | * @license MIT |
15 | */ |
16 | class ParserContext { |
17 | |
18 | private Parser $parser; |
19 | private TitleFormatter $titleFormatter; |
20 | |
21 | public function __construct( Parser $parser, TitleFormatter $titleFormatter ) { |
22 | $this->parser = $parser; |
23 | $this->titleFormatter = $titleFormatter; |
24 | } |
25 | |
26 | /** |
27 | * @see \MediaWiki\Parser\Parsoid\Config\PageConfig::getLinkTarget |
28 | */ |
29 | public function getPrefixedDBkey(): string { |
30 | // @phan-suppress-next-line PhanTypeMismatchArgumentNullable That's hard deprecated anyway |
31 | return $this->titleFormatter->getPrefixedDBkey( $this->parser->getPage() ); |
32 | } |
33 | |
34 | /** |
35 | * @see \MediaWiki\Parser\Parsoid\Config\PageConfig::getRevisionId |
36 | * @return int|null Can be null during preview |
37 | */ |
38 | public function getRevisionId(): ?int { |
39 | return $this->parser->getRevisionId(); |
40 | } |
41 | |
42 | public function getTargetLanguage(): Language { |
43 | // Can only be StubUserLang on special pages, but these can't contain <map…> tags |
44 | return $this->parser->getTargetLanguage(); |
45 | } |
46 | |
47 | } |