mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-13 17:56:59 +00:00
fcdfc31611
Follows-up 946a18d1
, which accidentally added a scripts module
to the styles queue (which is a no-op).
Fixes the following debug warning:
> Unexpected general module "ext.math.scripts" in styles queue.
Bug: T158376
Change-Id: Id026fbaa48cfab582b192bc0974ba7c6f01f37d0
81 lines
2.3 KiB
PHP
81 lines
2.3 KiB
PHP
<?php
|
|
|
|
use ValueFormatters\FormatterOptions;
|
|
use ValueParsers\StringParser;
|
|
use Wikibase\Rdf\DedupeBag;
|
|
use Wikibase\Rdf\EntityMentionListener;
|
|
use Wikibase\Rdf\RdfVocabulary;
|
|
use Wikibase\Repo\Parsers\WikibaseStringValueNormalizer;
|
|
use Wikibase\Repo\WikibaseRepo;
|
|
use Wikimedia\Purtle\RdfWriter;
|
|
|
|
class MathWikidataHook {
|
|
|
|
/**
|
|
* Add Datatype "Math" to the Wikibase Repository
|
|
*/
|
|
public static function onWikibaseRepoDataTypes( array &$dataTypeDefinitions ) {
|
|
global $wgMathEnableWikibaseDataType;
|
|
|
|
if ( !$wgMathEnableWikibaseDataType ) {
|
|
return;
|
|
}
|
|
|
|
$dataTypeDefinitions['PT:math'] = [
|
|
'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;
|
|
$wgOut->addModuleStyles( [ 'ext.math.styles' ] );
|
|
return new MathFormatter( $format );
|
|
},
|
|
'rdf-builder-factory-callback' => function (
|
|
$mode,
|
|
RdfVocabulary $vocab,
|
|
RdfWriter $writer,
|
|
EntityMentionListener $tracker,
|
|
DedupeBag $dedupe
|
|
) {
|
|
return new MathMLRdfBuilder();
|
|
},
|
|
];
|
|
}
|
|
|
|
/*
|
|
* Add Datatype "Math" to the Wikibase Client
|
|
*/
|
|
public static function onWikibaseClientDataTypes( array &$dataTypeDefinitions ) {
|
|
global $wgMathEnableWikibaseDataType;
|
|
|
|
if ( !$wgMathEnableWikibaseDataType ) {
|
|
return;
|
|
}
|
|
|
|
$dataTypeDefinitions['PT:math'] = [
|
|
'value-type' => 'string',
|
|
'formatter-factory-callback' => function( $format, FormatterOptions $options ) {
|
|
global $wgOut;
|
|
$styles = [ 'ext.math.scripts', 'ext.math.styles' ];
|
|
$wgOut->addModuleStyles( $styles );
|
|
return new MathFormatter( $format );
|
|
},
|
|
];
|
|
}
|
|
|
|
}
|