Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| WikiLinkParserFactory | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getWikiLinkParser | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace FileImporter\Services\Wikitext; |
| 4 | |
| 5 | use FileImporter\Remote\MediaWiki\MediaWikiSourceUrlParser; |
| 6 | use MediaWiki\Language\LanguageFactory; |
| 7 | use MediaWiki\Title\NamespaceInfo; |
| 8 | use MediaWiki\Title\TitleParser; |
| 9 | |
| 10 | /** |
| 11 | * @license GPL-2.0-or-later |
| 12 | * @author Thiemo Kreuz |
| 13 | */ |
| 14 | class WikiLinkParserFactory { |
| 15 | use MediaWikiSourceUrlParser; |
| 16 | |
| 17 | public function __construct( |
| 18 | // FIXME: This needs to be a parser in the context of the *source* wiki |
| 19 | private readonly TitleParser $titleParser, |
| 20 | private readonly NamespaceInfo $namespaceInfo, |
| 21 | private readonly LanguageFactory $languageFactory, |
| 22 | ) { |
| 23 | } |
| 24 | |
| 25 | public function getWikiLinkParser( ?string $languageCode, string $interWikiPrefix ): WikiLinkParser { |
| 26 | $parser = new WikiLinkParser(); |
| 27 | |
| 28 | // Minor performance optimization: skip this step if there is nothing to unlocalize |
| 29 | if ( $languageCode && $languageCode !== 'en' ) { |
| 30 | $language = $this->languageFactory->getLanguage( $languageCode ); |
| 31 | $parser->registerWikiLinkCleaner( new NamespaceUnlocalizer( |
| 32 | new LocalizedMediaWikiNamespaceLookup( $language ), |
| 33 | $this->namespaceInfo |
| 34 | ) ); |
| 35 | } |
| 36 | |
| 37 | $parser->registerWikiLinkCleaner( new WikiLinkPrefixer( |
| 38 | $interWikiPrefix, |
| 39 | $this->titleParser |
| 40 | ) ); |
| 41 | |
| 42 | return $parser; |
| 43 | } |
| 44 | |
| 45 | } |