Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| LuaPageImageResolver | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| resolve | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace PageImages; |
| 4 | |
| 5 | use MediaWiki\Extension\Scribunto\Engines\LuaCommon\TitleAttributeResolver; |
| 6 | use MediaWiki\Linker\LinkTarget; |
| 7 | use MediaWiki\Parser\ParserOutputFlags; |
| 8 | use MediaWiki\Title\Title; |
| 9 | |
| 10 | class LuaPageImageResolver extends TitleAttributeResolver { |
| 11 | |
| 12 | public function __construct( |
| 13 | private readonly PageImages $pageImages, |
| 14 | ) { |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * @param LinkTarget $target |
| 19 | * @return string|null |
| 20 | */ |
| 21 | public function resolve( LinkTarget $target ) { |
| 22 | $title = Title::newFromLinkTarget( $target ); |
| 23 | if ( !$title->canExist() ) { |
| 24 | return null; |
| 25 | } |
| 26 | |
| 27 | $this->incrementExpensiveFunctionCount(); |
| 28 | if ( $title->equals( $this->getEngine()->getTitle() ) ) { |
| 29 | $parserOutput = $this->getEngine()->getParser()->getOutput(); |
| 30 | $parserOutput->setOutputFlag( ParserOutputFlags::VARY_REVISION ); |
| 31 | } |
| 32 | |
| 33 | $file = $this->pageImages->getImage( $title ); |
| 34 | if ( !$file ) { |
| 35 | return null; |
| 36 | } |
| 37 | return $file->getTitle()->getPrefixedText(); |
| 38 | } |
| 39 | } |