| 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 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class MathDataUpdater implements StatementDataUpdater { |
| 17 |
|
| 18 |
|
| 19 |
private $hasMath = false; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
private $propertyDataTypeMatcher; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public function __construct( PropertyDataTypeMatcher $propertyDataTypeMatcher ) { |
| 30 |
$this->propertyDataTypeMatcher = $propertyDataTypeMatcher; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 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 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public function updateParserOutput( ParserOutput $parserOutput ) { |
| 55 |
if ( $this->hasMath ) { |
| 56 |
$parserOutput->addModuleStyles( [ 'ext.math.styles' ] ); |
| 57 |
} |
| 58 |
} |
| 59 |
} |