镜像自地址
https://github.com/wikimedia/mediawiki-extensions-Math.git
已同步 2024-06-02 15:50:20 +08:00
22a3e5fc55
Configuring parser-factory-callback is not necessary here because it's the same as the default for the string value type. Setting a data type specific custom parser will soon allow for data type specific overrides of the parser whenever a statement value is deserialized, and setting it may result in additional data type lookups. Bug: T360603 Change-Id: I6a859b8d9cf25d8a837b366434380169e404fe6b
73 行
1.9 KiB
PHP
73 行
1.9 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\Math;
|
|
|
|
use ValueFormatters\FormatterOptions;
|
|
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;
|
|
},
|
|
'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 );
|
|
},
|
|
];
|
|
}
|
|
|
|
}
|