Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| MathDataUpdater | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| processStatement | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| updateParserOutput | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\Math; |
| 4 | |
| 5 | use MediaWiki\Parser\ParserOutput; |
| 6 | use Wikibase\DataModel\Services\Entity\PropertyDataTypeMatcher; |
| 7 | use Wikibase\DataModel\Statement\Statement; |
| 8 | use Wikibase\Repo\ParserOutput\StatementDataUpdater; |
| 9 | |
| 10 | /** |
| 11 | * Add required styles for mathematical formulae to the ParserOutput. |
| 12 | * |
| 13 | * @license GPL-2.0-or-later |
| 14 | * @author Moritz Schubotz |
| 15 | */ |
| 16 | class MathDataUpdater implements StatementDataUpdater { |
| 17 | |
| 18 | /** @var bool */ |
| 19 | private $hasMath = false; |
| 20 | |
| 21 | /** |
| 22 | * @inheritDoc |
| 23 | */ |
| 24 | public function __construct( |
| 25 | private readonly PropertyDataTypeMatcher $propertyDataTypeMatcher, |
| 26 | ) { |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Extract some data or do processing on a Statement during parsing. |
| 31 | * |
| 32 | * This method is normally invoked when processing a StatementList |
| 33 | * for all Statements on a StatementListProvider (e.g. an Item). |
| 34 | */ |
| 35 | public function processStatement( Statement $statement ) { |
| 36 | $propertyId = $statement->getPropertyId(); |
| 37 | if ( $this->propertyDataTypeMatcher->isMatchingDataType( $propertyId, 'math' ) ) { |
| 38 | $this->hasMath = true; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Update extension data, properties or other data in ParserOutput. |
| 44 | * These updates are invoked when EntityContent::getParserOutput is called. |
| 45 | */ |
| 46 | public function updateParserOutput( ParserOutput $parserOutput ) { |
| 47 | if ( $this->hasMath ) { |
| 48 | $parserOutput->addModuleStyles( [ 'ext.math.styles' ] ); |
| 49 | $parserOutput->addModules( [ 'ext.math.polyfills' ] ); |
| 50 | } |
| 51 | } |
| 52 | } |