mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-12-18 18:40:39 +00:00
c416046515
* mediawiki/mediawiki-codesniffer: 35.0.0 → 36.0.0 * php-parallel-lint/php-parallel-lint: 1.2.0 → 1.3.0 Change-Id: Iccba9c52c8390b00fe1cc31e5f3bed3074e27f85
80 lines
2.2 KiB
PHP
80 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\Math;
|
|
|
|
use ParserOptions;
|
|
use ValueFormatters\FormatterOptions;
|
|
use ValueParsers\StringParser;
|
|
use Wikibase\Repo\Parsers\WikibaseStringValueNormalizer;
|
|
use Wikibase\Repo\Rdf\DedupeBag;
|
|
use Wikibase\Repo\Rdf\EntityMentionListener;
|
|
use Wikibase\Repo\Rdf\RdfVocabulary;
|
|
use Wikibase\Repo\WikibaseRepo;
|
|
use Wikimedia\Purtle\RdfWriter;
|
|
|
|
class WikibaseHook {
|
|
|
|
/**
|
|
* Add Datatype "Math" to the Wikibase Repository
|
|
* @param array[] &$dataTypeDefinitions
|
|
*/
|
|
public static function onWikibaseRepoDataTypes( array &$dataTypeDefinitions ) {
|
|
global $wgMathEnableWikibaseDataType;
|
|
|
|
if ( !$wgMathEnableWikibaseDataType ) {
|
|
return;
|
|
}
|
|
|
|
$dataTypeDefinitions['PT:math'] = [
|
|
'value-type' => 'string',
|
|
'validator-factory-callback' => static 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' => static function ( ParserOptions $options ) {
|
|
$normalizer = new WikibaseStringValueNormalizer( WikibaseRepo::getStringNormalizer() );
|
|
return new StringParser( $normalizer );
|
|
},
|
|
'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) {
|
|
return new MathFormatter( $format );
|
|
},
|
|
'rdf-builder-factory-callback' => static function (
|
|
$mode,
|
|
RdfVocabulary $vocab,
|
|
RdfWriter $writer,
|
|
EntityMentionListener $tracker,
|
|
DedupeBag $dedupe
|
|
) {
|
|
return new MathMLRdfBuilder();
|
|
},
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Add Datatype "Math" to the Wikibase Client
|
|
* @param array[] &$dataTypeDefinitions
|
|
*/
|
|
public static function onWikibaseClientDataTypes( array &$dataTypeDefinitions ) {
|
|
global $wgMathEnableWikibaseDataType;
|
|
|
|
if ( !$wgMathEnableWikibaseDataType ) {
|
|
return;
|
|
}
|
|
|
|
$dataTypeDefinitions['PT:math'] = [
|
|
'value-type' => 'string',
|
|
'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) {
|
|
return new MathFormatter( $format );
|
|
},
|
|
];
|
|
}
|
|
|
|
}
|