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