Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ParsoidWrappingParserOutputProvider | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getParserOutput | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * WikiLambda extension Parsoid wrapper for Wikibase's content injection tracking system |
| 5 | * |
| 6 | * @file |
| 7 | * @ingroup Extensions |
| 8 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
| 9 | * @license MIT |
| 10 | */ |
| 11 | |
| 12 | namespace MediaWiki\Extension\WikiLambda\ParserFunction; |
| 13 | |
| 14 | use MediaWiki\Parser\ParserOutput; |
| 15 | use Wikibase\Client\ParserOutput\ParserOutputProvider; |
| 16 | use Wikimedia\Parsoid\Config\StubMetadataCollector; |
| 17 | use Wikimedia\Parsoid\Core\ContentMetadataCollector; |
| 18 | |
| 19 | /** |
| 20 | * Provides a ParserOutput for the Parsoid wrapping of the Wikifunctions content. |
| 21 | * |
| 22 | * @todo This should really be provided by Wikibase, not us, but needs must. |
| 23 | */ |
| 24 | class ParsoidWrappingParserOutputProvider implements ParserOutputProvider { |
| 25 | private ContentMetadataCollector $contentMetadataCollector; |
| 26 | |
| 27 | public function __construct( ContentMetadataCollector $contentMetadataCollector ) { |
| 28 | $this->contentMetadataCollector = $contentMetadataCollector; |
| 29 | } |
| 30 | |
| 31 | public function getParserOutput(): ParserOutput { |
| 32 | // In tests, instead of a real ParserOutput Parsoid uses a StubMetadataCollector |
| 33 | if ( $this->contentMetadataCollector instanceof StubMetadataCollector ) { |
| 34 | $dummyParserOutput = new ParserOutput(); |
| 35 | $dummyParserOutput->collectMetadata( $this->contentMetadataCollector ); |
| 36 | return $dummyParserOutput; |
| 37 | } |
| 38 | |
| 39 | // ParserOutput implements the ContentMetadataCollector interface, but phan can't |
| 40 | // magically know that, so help it out. |
| 41 | // @phan-suppress-next-line PhanTypeMismatchReturnSuperType |
| 42 | return $this->contentMetadataCollector; |
| 43 | } |
| 44 | } |