Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
WikibaseHookHandler
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 onWikibaseRepoDataTypes
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
12
 onWikibaseClientDataTypes
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace MediaWiki\Extension\Score;
4
5use ValueFormatters\FormatterOptions;
6use Wikibase\Repo\Rdf\DedupeBag;
7use Wikibase\Repo\Rdf\EntityMentionListener;
8use Wikibase\Repo\Rdf\NullEntityRdfBuilder;
9use Wikibase\Repo\Rdf\RdfVocabulary;
10use Wikibase\Repo\WikibaseRepo;
11use Wikimedia\Purtle\RdfWriter;
12
13class WikibaseHookHandler {
14    /**
15     * Add Datatype "Musical notation" to the Wikibase Repository
16     * @param array[] &$dataTypeDefinitions
17     */
18    public static function onWikibaseRepoDataTypes( array &$dataTypeDefinitions ) {
19        global $wgMusicalNotationEnableWikibaseDataType;
20
21        /**
22         * Enable the datatype in Quibble (CI) contexts so that we can test the integration
23         * of Score with Wikibase.
24         */
25        if ( !$wgMusicalNotationEnableWikibaseDataType && !defined( 'MW_QUIBBLE_CI' ) ) {
26            return;
27        }
28
29        $dataTypeDefinitions['PT:musical-notation'] = [
30            'value-type' => 'string',
31            'validator-factory-callback' => static function () {
32                global $wgScoreMaxLength;
33                // load validator builders
34                $factory = WikibaseRepo::getDefaultValidatorBuilders();
35                // initialize an array with string validators
36                // returns an array of validators
37                // that add basic string validation such as preventing empty strings
38                $validators = $factory->buildStringValidators( $wgScoreMaxLength );
39                // $validators[] = new ScoreValidator();
40                // TODO: Take out the validation out of Score
41                return $validators;
42            },
43            'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) {
44                return new ScoreFormatter( $format );
45            },
46            'rdf-builder-factory-callback' => static function (
47                $mode,
48                RdfVocabulary $vocab,
49                RdfWriter $writer,
50                EntityMentionListener $tracker,
51                DedupeBag $dedupe
52            ) {
53                // TODO: Implement
54                return new NullEntityRdfBuilder();
55            },
56        ];
57    }
58
59    /**
60     * Add Datatype "Musical notation" to the Wikibase Client
61     * @param array[] &$dataTypeDefinitions
62     */
63    public static function onWikibaseClientDataTypes( array &$dataTypeDefinitions ) {
64        global $wgMusicalNotationEnableWikibaseDataType;
65
66        /**
67         * Enable the datatype in Quibble (CI) contexts so that we can test the integration
68         * of Score with Wikibase.
69         */
70        if ( !$wgMusicalNotationEnableWikibaseDataType && !defined( 'MW_QUIBBLE_CI' ) ) {
71            return;
72        }
73        $dataTypeDefinitions['PT:musical-notation'] = [
74            'value-type' => 'string',
75            'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) {
76                return new ScoreFormatter( $format );
77            },
78        ];
79    }
80
81}