Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
WikibaseHook | |
0.00% |
0 / 31 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
onWikibaseRepoDataTypes | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
6 | |||
onWikibaseClientDataTypes | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 |
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 | * Add Datatype "Math" to the Wikibase Repository |
16 | * @param array[] &$dataTypeDefinitions |
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 | // load validator builders |
29 | $factory = WikibaseRepo::getDefaultValidatorBuilders(); |
30 | |
31 | // initialize an array with string validators |
32 | // returns an array of validators |
33 | // that add basic string validation such as preventing empty strings |
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 | * Add Datatype "Math" to the Wikibase Client |
55 | * @param array[] &$dataTypeDefinitions |
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 | } |