Debian Codegraph @

extensions/Math/src/MathDataUpdater.php

raw symbols SCIP
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 * @var PropertyDataTypeMatcher
23 */
24 private $propertyDataTypeMatcher;
25
26 /**
27 * @inheritDoc
28 */
29 public function __construct( PropertyDataTypeMatcher $propertyDataTypeMatcher ) {
30 $this->propertyDataTypeMatcher = $propertyDataTypeMatcher;
31 }
32
33 /**
34 * Extract some data or do processing on a Statement during parsing.
35 *
36 * This method is normally invoked when processing a StatementList
37 * for all Statements on a StatementListProvider (e.g. an Item).
38 *
39 * @param Statement $statement
40 */
41 public function processStatement( Statement $statement ) {
42 $propertyId = $statement->getPropertyId();
43 if ( $this->propertyDataTypeMatcher->isMatchingDataType( $propertyId, 'math' ) ) {
44 $this->hasMath = true;
45 }
46 }
47
48 /**
49 * Update extension data, properties or other data in ParserOutput.
50 * These updates are invoked when EntityContent::getParserOutput is called.
51 *
52 * @param ParserOutput $parserOutput
53 */
54 public function updateParserOutput( ParserOutput $parserOutput ) {
55 if ( $this->hasMath ) {
56 $parserOutput->addModuleStyles( [ 'ext.math.styles' ] );
57 }
58 }
59 }