mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-12-01 10:46:36 +00:00
be7be3becb
1) Because enabling native MathML now requires special configuration steps from the users, they can as well just check their math font setup. Hence we remove the Web font fallback. 2) We then can actually just remove ext.math.desktop.css since no specific style is necessary any more on desktop. 3) We also no longer need to add the Web font to the list of font-family on the <math> element. We actually just remove the whole font-family rule so that it is up to web engines developers & users to decide the best math font to use (e.g. via the "Fonts for mathematics" option in the font preference menu of Firefox). Change-Id: I1818d288b0f28715a460e3163590e4d0374c42b4
82 lines
2.3 KiB
PHP
82 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;
|
|
$styles = [ 'ext.math.scripts', 'ext.math.styles' ];
|
|
$wgOut->addModuleStyles( $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 );
|
|
},
|
|
];
|
|
}
|
|
|
|
}
|