2015-12-14 20:26:29 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use ValueFormatters\FormatterOptions;
|
|
|
|
use ValueParsers\StringParser;
|
2016-02-09 19:53:51 +00:00
|
|
|
use Wikibase\Rdf\DedupeBag;
|
|
|
|
use Wikibase\Rdf\EntityMentionListener;
|
|
|
|
use Wikibase\Rdf\RdfVocabulary;
|
2015-12-14 20:26:29 +00:00
|
|
|
use Wikibase\Repo\Parsers\WikibaseStringValueNormalizer;
|
|
|
|
use Wikibase\Repo\WikibaseRepo;
|
2016-02-09 19:53:51 +00:00
|
|
|
use Wikimedia\Purtle\RdfWriter;
|
2015-12-14 20:26:29 +00:00
|
|
|
|
|
|
|
class MathWikidataHook {
|
2016-01-12 20:21:46 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-14 20:26:29 +00:00
|
|
|
* Add Datatype "Math" to the Wikibase Repository
|
|
|
|
*/
|
|
|
|
public static function onWikibaseRepoDataTypes( array &$dataTypeDefinitions ) {
|
2016-01-12 20:21:46 +00:00
|
|
|
global $wgMathEnableWikibaseDataType;
|
|
|
|
|
|
|
|
if ( !$wgMathEnableWikibaseDataType ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-12 20:53:25 +00:00
|
|
|
$dataTypeDefinitions['PT:math'] = [
|
2015-12-14 20:26:29 +00:00
|
|
|
'value-type' => 'string',
|
|
|
|
'validator-factory-callback' => function() {
|
|
|
|
// load validator builders
|
|
|
|
$factory = WikibaseRepo::getDefaultValidatorBuilders();
|
|
|
|
|
|
|
|
// initialize an array with string validators
|
|
|
|
// returns an array of validators
|
|
|
|
// that add basic string validation such as preventing empty strings
|
|
|
|
$validators = $factory->buildStringValidators();
|
|
|
|
$validators[] = new MathValidator();
|
|
|
|
return $validators;
|
|
|
|
},
|
|
|
|
'parser-factory-callback' => function( ParserOptions $options ) {
|
|
|
|
$repo = WikibaseRepo::getDefaultInstance();
|
|
|
|
$normalizer = new WikibaseStringValueNormalizer( $repo->getStringNormalizer() );
|
|
|
|
return new StringParser( $normalizer );
|
|
|
|
},
|
|
|
|
'formatter-factory-callback' => function( $format, FormatterOptions $options ) {
|
|
|
|
global $wgOut;
|
2017-02-17 22:55:51 +00:00
|
|
|
$wgOut->addModuleStyles( [ 'ext.math.styles' ] );
|
2015-12-14 20:26:29 +00:00
|
|
|
return new MathFormatter( $format );
|
|
|
|
},
|
2016-02-09 19:53:51 +00:00
|
|
|
'rdf-builder-factory-callback' => function (
|
|
|
|
$mode,
|
|
|
|
RdfVocabulary $vocab,
|
|
|
|
RdfWriter $writer,
|
|
|
|
EntityMentionListener $tracker,
|
|
|
|
DedupeBag $dedupe
|
|
|
|
) {
|
|
|
|
return new MathMLRdfBuilder();
|
|
|
|
},
|
2016-04-12 20:53:25 +00:00
|
|
|
];
|
2015-12-14 20:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add Datatype "Math" to the Wikibase Client
|
|
|
|
*/
|
|
|
|
public static function onWikibaseClientDataTypes( array &$dataTypeDefinitions ) {
|
2016-01-12 20:21:46 +00:00
|
|
|
global $wgMathEnableWikibaseDataType;
|
|
|
|
|
|
|
|
if ( !$wgMathEnableWikibaseDataType ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-12 20:53:25 +00:00
|
|
|
$dataTypeDefinitions['PT:math'] = [
|
2015-12-14 20:26:29 +00:00
|
|
|
'value-type' => 'string',
|
|
|
|
'formatter-factory-callback' => function( $format, FormatterOptions $options ) {
|
|
|
|
global $wgOut;
|
2017-05-26 15:24:50 +00:00
|
|
|
$wgOut->addModuleStyles( [ 'ext.math.styles' ] );
|
2015-12-14 20:26:29 +00:00
|
|
|
return new MathFormatter( $format );
|
|
|
|
},
|
2016-04-12 20:53:25 +00:00
|
|
|
];
|
2015-12-14 20:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|