| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Math; |
| 4 |
|
| 5 |
use ValueFormatters\FormatterOptions; |
| 6 |
use Wikibase\Repo\Rdf\DedupeBag; |
| 7 |
use Wikibase\Repo\Rdf\EntityMentionListener; |
| 8 |
use Wikibase\Repo\Rdf\RdfVocabulary; |
| 9 |
use Wikibase\Repo\WikibaseRepo; |
| 10 |
use Wikimedia\Purtle\RdfWriter; |
| 11 |
|
| 12 |
class WikibaseHook { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
public static function onWikibaseRepoDataTypes( array &$dataTypeDefinitions ) { |
| 19 |
global $wgMathEnableWikibaseDataType; |
| 20 |
|
| 21 |
if ( !$wgMathEnableWikibaseDataType ) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
$dataTypeDefinitions['PT:math'] = [ |
| 26 |
'value-type' => 'string', |
| 27 |
'validator-factory-callback' => static function () { |
| 28 |
|
| 29 |
$factory = WikibaseRepo::getDefaultValidatorBuilders(); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
$validators = $factory->buildStringValidators(); |
| 35 |
$validators[] = new MathValidator(); |
| 36 |
return $validators; |
| 37 |
}, |
| 38 |
'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) { |
| 39 |
return new MathFormatter( $format ); |
| 40 |
}, |
| 41 |
'rdf-builder-factory-callback' => static function ( |
| 42 |
$mode, |
| 43 |
RdfVocabulary $vocab, |
| 44 |
RdfWriter $writer, |
| 45 |
EntityMentionListener $tracker, |
| 46 |
DedupeBag $dedupe |
| 47 |
) { |
| 48 |
return new MathMLRdfBuilder(); |
| 49 |
}, |
| 50 |
]; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public static function onWikibaseClientDataTypes( array &$dataTypeDefinitions ) { |
| 58 |
global $wgMathEnableWikibaseDataType; |
| 59 |
|
| 60 |
if ( !$wgMathEnableWikibaseDataType ) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
$dataTypeDefinitions['PT:math'] = [ |
| 65 |
'value-type' => 'string', |
| 66 |
'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) { |
| 67 |
return new MathFormatter( $format ); |
| 68 |
}, |
| 69 |
]; |
| 70 |
} |
| 71 |
|
| 72 |
} |