Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 4 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ParserContext | |
0.00% |
0 / 4 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
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 | public function __construct( |
| 19 | private readonly Parser $parser, |
| 20 | private readonly TitleFormatter $titleFormatter, |
| 21 | ) { |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @see \MediaWiki\Parser\Parsoid\Config\PageConfig::getLinkTarget |
| 26 | */ |
| 27 | public function getPrefixedDBkey(): string { |
| 28 | return $this->titleFormatter->getPrefixedDBkey( $this->parser->getPage() ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @see \MediaWiki\Parser\Parsoid\Config\PageConfig::getRevisionId |
| 33 | * @return int|null Can be null during preview |
| 34 | */ |
| 35 | public function getRevisionId(): ?int { |
| 36 | return $this->parser->getRevisionId(); |
| 37 | } |
| 38 | |
| 39 | public function getTargetLanguage(): Language { |
| 40 | // Can only be StubUserLang on special pages, but these can't contain <map…> tags |
| 41 | return $this->parser->getTargetLanguage(); |
| 42 | } |
| 43 | |
| 44 | } |