Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
WikibaseHook | |
0.00% |
0 / 37 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
onWikibaseRepoDataTypes | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
6 | |||
onWikibaseClientDataTypes | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Math; |
4 | |
5 | use ParserOptions; |
6 | use ValueFormatters\FormatterOptions; |
7 | use ValueParsers\StringParser; |
8 | use Wikibase\Repo\Parsers\WikibaseStringValueNormalizer; |
9 | use Wikibase\Repo\Rdf\DedupeBag; |
10 | use Wikibase\Repo\Rdf\EntityMentionListener; |
11 | use Wikibase\Repo\Rdf\RdfVocabulary; |
12 | use Wikibase\Repo\WikibaseRepo; |
13 | use Wikimedia\Purtle\RdfWriter; |
14 | |
15 | class WikibaseHook { |
16 | |
17 | /** |
18 | * Add Datatype "Math" to the Wikibase Repository |
19 | * @param array[] &$dataTypeDefinitions |
20 | */ |
21 | public static function onWikibaseRepoDataTypes( array &$dataTypeDefinitions ) { |
22 | global $wgMathEnableWikibaseDataType; |
23 | |
24 | if ( !$wgMathEnableWikibaseDataType ) { |
25 | return; |
26 | } |
27 | |
28 | $dataTypeDefinitions['PT:math'] = [ |
29 | 'value-type' => 'string', |
30 | 'validator-factory-callback' => static function () { |
31 | // load validator builders |
32 | $factory = WikibaseRepo::getDefaultValidatorBuilders(); |
33 | |
34 | // initialize an array with string validators |
35 | // returns an array of validators |
36 | // that add basic string validation such as preventing empty strings |
37 | $validators = $factory->buildStringValidators(); |
38 | $validators[] = new MathValidator(); |
39 | return $validators; |
40 | }, |
41 | 'parser-factory-callback' => static function ( ParserOptions $options ) { |
42 | $normalizer = new WikibaseStringValueNormalizer( WikibaseRepo::getStringNormalizer() ); |
43 | return new StringParser( $normalizer ); |
44 | }, |
45 | 'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) { |
46 | return new MathFormatter( $format ); |
47 | }, |
48 | 'rdf-builder-factory-callback' => static function ( |
49 | $mode, |
50 | RdfVocabulary $vocab, |
51 | RdfWriter $writer, |
52 | EntityMentionListener $tracker, |
53 | DedupeBag $dedupe |
54 | ) { |
55 | return new MathMLRdfBuilder(); |
56 | }, |
57 | ]; |
58 | } |
59 | |
60 | /** |
61 | * Add Datatype "Math" to the Wikibase Client |
62 | * @param array[] &$dataTypeDefinitions |
63 | */ |
64 | public static function onWikibaseClientDataTypes( array &$dataTypeDefinitions ) { |
65 | global $wgMathEnableWikibaseDataType; |
66 | |
67 | if ( !$wgMathEnableWikibaseDataType ) { |
68 | return; |
69 | } |
70 | |
71 | $dataTypeDefinitions['PT:math'] = [ |
72 | 'value-type' => 'string', |
73 | 'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) { |
74 | return new MathFormatter( $format ); |
75 | }, |
76 | ]; |
77 | } |
78 | |
79 | } |