Use extension.json, empty PHP entry point
* Use string constants instead of integers * Derive new names from old via conversion of constant naming convention to CamelCase. * Replace old constant string e.g. 'MW_MATH_ABC_DEF' with new string 'abcDef' * Replace old constant value with new string. * Tests to demonstrates what is actually done. * Rename constants Bug: T106630 Bug: T106631 Bug: T87941 Change-Id: I6d1094ece79e912d9ddbef6681a25196c7a6e801
This commit is contained in:
parent
e32ba69383
commit
bc52c77d24
2
HISTORY
2
HISTORY
|
@ -7,5 +7,5 @@ Change notes from older releases. For current info see RELEASE-NOTES-3.0.0.
|
|||
* $wgLaTeXMLTimeout was renamed to $wgMathLaTeXMLTimeout
|
||||
* $wgMathValidModes is introduced:
|
||||
It determines the selectable math rendering modes MW_MATH_(PNG|MATHML|...) in user preferences.
|
||||
* $wgUseLaTeXML becomes unnecessary use $wgMathValidModes[] = MW_MATH_LATEXML;
|
||||
* $wgUseLaTeXML becomes unnecessary use $wgMathValidModes[] = 'latexml';
|
||||
to enable the LaTeXML rendering mode.
|
||||
|
|
131
Math.hooks.php
131
Math.hooks.php
|
@ -11,6 +11,88 @@ use MediaWiki\Logger\LoggerFactory;
|
|||
class MathHooks {
|
||||
const mathCacheKey = 'math=';
|
||||
|
||||
public static function mathConstantToString( $value, array $defs, $prefix, $default ){
|
||||
foreach ( $defs as $defKey => $defValue ) {
|
||||
if( !defined( $defKey ) ) {
|
||||
define( $defKey, $defValue );
|
||||
} elseif ( $defValue !== constant( $defKey ) ) {
|
||||
throw new Exception( 'Math constant "'. $defKey . '" has unexpected value "' .
|
||||
constant( $defKey ) . '" instead of "' . $defValue );
|
||||
}
|
||||
}
|
||||
$invDefs = array_flip( $defs );
|
||||
if ( is_int( $value ) ){
|
||||
if ( array_key_exists( $value , $invDefs ) ) {
|
||||
$value = $invDefs[$value];
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
if ( is_string( $value ) ){
|
||||
$newValues = array();
|
||||
foreach ( $defs as $k => $v ) {
|
||||
$newValues[$k] = preg_replace_callback( '/_(.)/', function ( $matches ) {
|
||||
return strtoupper( $matches[1] );
|
||||
}, strtolower( substr( $k, strlen( $prefix ) ) ) );
|
||||
}
|
||||
if ( array_key_exists( $value, $defs ) ) {
|
||||
return $newValues[$value];
|
||||
} elseif (in_array( $value, $newValues) ){
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
public static function mathStyleToString( $style, $default = 'inlineDisplaystyle' ) {
|
||||
$defs = array (
|
||||
'MW_MATHSTYLE_INLINE_DISPLAYSTYLE' => 0, // default large operator inline
|
||||
'MW_MATHSTYLE_DISPLAY' => 1, // large operators centered in a new line
|
||||
'MW_MATHSTYLE_INLINE' => 2, // small operators inline
|
||||
);
|
||||
return self::mathConstantToString( $style, $defs, $prefix = 'MW_MATHSTYLE_', $default );
|
||||
}
|
||||
|
||||
public static function mathCheckToString( $style, $default = 'always' ) {
|
||||
$defs = array (
|
||||
'MW_MATH_CHECK_ALWAYS' => 0,
|
||||
'MW_MATH_CHECK_NEVER' => 1,
|
||||
'MW_MATH_CHECK_NEW' => 2,
|
||||
);
|
||||
return self::mathConstantToString( $style, $defs, $prefix = 'MW_MATH_CHECK_', $default );
|
||||
}
|
||||
|
||||
public static function mathModeToString( $mode, $default = 'png' ) {
|
||||
// The following deprecated modes have been removed:
|
||||
// 'MW_MATH_SIMPLE' => 1
|
||||
// 'MW_MATH_HTML' => 2
|
||||
// 'MW_MATH_MODERN' => 4
|
||||
// 'MW_MATH_MATHJAX' => 6
|
||||
// 'MW_MATH_LATEXML_JAX' => 8
|
||||
|
||||
$defs = array (
|
||||
'MW_MATH_PNG' => 0,
|
||||
'MW_MATH_SOURCE' => 3,
|
||||
'MW_MATH_MATHML' => 5,
|
||||
'MW_MATH_LATEXML'=> 7 );
|
||||
|
||||
return self::mathConstantToString( $mode, $defs, $prefix = 'MW_MATH_', $default );
|
||||
}
|
||||
|
||||
public static function mathModeToHashKey( $mode, $default = 0 ) {
|
||||
$defs = array (
|
||||
'png' => 0,
|
||||
'source' => 3,
|
||||
'mathml' => 5,
|
||||
'latexml'=> 7 );
|
||||
|
||||
if ( array_key_exists( $mode, $defs ) ){
|
||||
return $defs[$mode];
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate a user dependent hash cache key.
|
||||
* The hash key depends on the rendering mode.
|
||||
|
@ -28,7 +110,8 @@ class MathHooks {
|
|||
$user = $wgUser;
|
||||
}
|
||||
|
||||
$mathOption = $user->getOption( 'math' );
|
||||
$mathString = self::mathModeToString( $user->getOption( 'math' ) );
|
||||
$mathOption = self::mathModeToHashKey( $mathString, 0 );
|
||||
// Check if the key already contains the math option part
|
||||
if (
|
||||
!preg_match(
|
||||
|
@ -98,8 +181,7 @@ class MathHooks {
|
|||
return '';
|
||||
}
|
||||
|
||||
$mode = (int)$parser->getUser()->getOption( 'math' );
|
||||
|
||||
$mode = self::mathModeToString( $parser->getUser()->getOption( 'math' ) );
|
||||
// Indicate that this page uses math.
|
||||
// This affects the page caching behavior.
|
||||
if ( is_callable( 'ParserOptions::getMath' ) ) {
|
||||
|
@ -128,7 +210,7 @@ class MathHooks {
|
|||
Hooks::run( 'MathFormulaPostRender',
|
||||
array( $parser, &$renderer, &$renderedMath ) );// Enables indexing of math formula
|
||||
$parser->getOutput()->addModuleStyles( array( 'ext.math.styles' ) );
|
||||
if ( $mode == MW_MATH_MATHML ) {
|
||||
if ( $mode == 'mathml' ) {
|
||||
$parser->getOutput()->addModuleStyles( array( 'ext.math.desktop.styles' ) );
|
||||
$parser->getOutput()->addModules( array( 'ext.math.scripts' ) );
|
||||
}
|
||||
|
@ -146,7 +228,7 @@ class MathHooks {
|
|||
* @return Boolean: true
|
||||
*/
|
||||
static function onGetPreferences( $user, &$defaultPreferences ) {
|
||||
global $wgMathValidModes, $wgDefaultUserOptions;
|
||||
global $wgDefaultUserOptions;
|
||||
$defaultPreferences['math'] = array(
|
||||
'type' => 'radio',
|
||||
'options' => array_flip( self::getMathNames() ),
|
||||
|
@ -155,12 +237,14 @@ class MathHooks {
|
|||
);
|
||||
// If the default option is not in the valid options the
|
||||
// user interface throws an exception (BUG 64844)
|
||||
if ( ! in_array( $wgDefaultUserOptions['math'] , $wgMathValidModes ) ) {
|
||||
$mode = MathHooks::mathModeToString( $wgDefaultUserOptions['math'] );
|
||||
if ( ! in_array( $mode , MathRenderer::getValidModes() ) ) {
|
||||
LoggerFactory::getInstance( 'Math' )->error( 'Misconfiguration: '.
|
||||
"\$wgDefaultUserOptions['math'] is not in \$wgMathValidModes.\n".
|
||||
"\$wgDefaultUserOptions['math'] is not in " . MathRenderer::getValidModes() . ".\n".
|
||||
"Please check your LocalSetting.php file." );
|
||||
// Display the checkbox in the first option.
|
||||
$wgDefaultUserOptions['math'] = $wgMathValidModes[0];
|
||||
$validModes = MathRenderer::getValidModes();
|
||||
$wgDefaultUserOptions['math'] = $validModes[0];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -171,18 +255,9 @@ class MathHooks {
|
|||
* @return array of strings
|
||||
*/
|
||||
public static function getMathNames() {
|
||||
global $wgMathValidModes;
|
||||
$MathConstantNames = array(
|
||||
MW_MATH_SOURCE => 'mw_math_source',
|
||||
MW_MATH_PNG => 'mw_math_png',
|
||||
MW_MATH_MATHML => 'mw_math_mathml',
|
||||
MW_MATH_LATEXML => 'mw_math_latexml',
|
||||
MW_MATH_LATEXML_JAX => 'mw_math_latexml_jax',
|
||||
MW_MATH_MATHJAX => 'mw_math_mathjax'
|
||||
);
|
||||
$names = array();
|
||||
foreach ( $wgMathValidModes as $mode ) {
|
||||
$names[$mode] = wfMessage( $MathConstantNames[$mode] )->escaped();
|
||||
foreach ( MathRenderer::getValidModes() as $mode ) {
|
||||
$names[ $mode ] = wfMessage( 'mw_math_' . $mode )->escaped();
|
||||
}
|
||||
|
||||
return $names;
|
||||
|
@ -198,7 +273,7 @@ class MathHooks {
|
|||
global $wgUser;
|
||||
|
||||
# Don't generate TeX PNGs (the lack of a sensible current directory causes errors anyway)
|
||||
$wgUser->setOption( 'math', MW_MATH_SOURCE );
|
||||
$wgUser->setOption( 'math', 'source' );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -211,7 +286,7 @@ class MathHooks {
|
|||
* @return bool
|
||||
*/
|
||||
static function onLoadExtensionSchemaUpdates( $updater = null ) {
|
||||
global $wgMathValidModes;
|
||||
|
||||
if ( is_null( $updater ) ) {
|
||||
throw new Exception( 'Math extension is only necessary in 1.18 or above' );
|
||||
}
|
||||
|
@ -225,7 +300,7 @@ class MathHooks {
|
|||
}
|
||||
$sql = __DIR__ . '/db/math.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'math', $sql );
|
||||
if ( in_array( MW_MATH_LATEXML, $wgMathValidModes ) ) {
|
||||
if ( in_array( 'latexml', MathRenderer::getValidModes() ) ) {
|
||||
if ( in_array( $type, array( 'mysql', 'sqlite', 'postgres' ) ) ) {
|
||||
$sql = __DIR__ . '/db/mathlatexml.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'mathlatexml', $sql );
|
||||
|
@ -237,7 +312,7 @@ class MathHooks {
|
|||
throw new Exception( "Math extension does not currently support $type database for LaTeXML." );
|
||||
}
|
||||
}
|
||||
if ( in_array( MW_MATH_MATHML, $wgMathValidModes ) ) {
|
||||
if ( in_array( 'mathml', MathRenderer::getValidModes() ) ) {
|
||||
if ( in_array( $type, array( 'mysql', 'sqlite', 'postgres' ) ) ) {
|
||||
$sql = __DIR__ . '/db/mathoid.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'mathoid', $sql );
|
||||
|
@ -284,4 +359,14 @@ class MathHooks {
|
|||
global $wgOut;
|
||||
$wgOut->addModules( array( 'ext.math.editbutton.enabler' ) );
|
||||
}
|
||||
|
||||
public static function registerExtension() {
|
||||
global $wgDefaultUserOptions, $wgMathValidModes, $wgMathDisableTexFilter;
|
||||
$wgMathValidModes = MathRenderer::getValidModes();
|
||||
if ( $wgMathDisableTexFilter == true ){ //ensure backwards compatibility
|
||||
$wgMathDisableTexFilter = 1;
|
||||
}
|
||||
$wgMathDisableTexFilter = MathRenderer::getDisableTexFilter();
|
||||
$wgDefaultUserOptions['math'] = self::mathModeToString( $wgDefaultUserOptions['math'] );
|
||||
}
|
||||
}
|
||||
|
|
313
Math.php
313
Math.php
|
@ -1,300 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* MediaWiki math extension
|
||||
*
|
||||
* @file
|
||||
* @ingroup Extensions
|
||||
* @version 2.0
|
||||
* @author Tomasz Wegrzanowski
|
||||
* @author Brion Vibber
|
||||
* @author Moritz Schubotz
|
||||
* @author Derk-Jan Hartman
|
||||
* @copyright © 2002-2012 various MediaWiki contributors
|
||||
* @license GPLv2 license; info in main package.
|
||||
* @link http://www.mediawiki.org/wiki/Extension:Math Documentation
|
||||
* @see https://bugzilla.wikimedia.org/show_bug.cgi?id=14202
|
||||
*/
|
||||
|
||||
if ( !defined( 'MEDIAWIKI' ) ) {
|
||||
die( "This is not a valid entry point to MediaWiki.\n" );
|
||||
}
|
||||
|
||||
// Extension credits that will show up on Special:Version
|
||||
$wgExtensionCredits['parserhook'][] = array(
|
||||
'path' => __FILE__,
|
||||
'name' => 'Math',
|
||||
'version' => '2.0.0',
|
||||
'author' => array(
|
||||
'Tomasz Wegrzanowski',
|
||||
'Brion Vibber',
|
||||
'Moritz Schubotz',
|
||||
'Derk-Jan Hartman',
|
||||
),
|
||||
'descriptionmsg' => 'math-desc',
|
||||
'url' => 'https://www.mediawiki.org/wiki/Extension:Math',
|
||||
);
|
||||
|
||||
/**@{
|
||||
* Maths constants
|
||||
*/
|
||||
define( 'MW_MATH_PNG', 0 );
|
||||
define( 'MW_MATH_SIMPLE', 1 ); /// @deprecated
|
||||
define( 'MW_MATH_HTML', 2 ); /// @deprecated
|
||||
define( 'MW_MATH_SOURCE', 3 );
|
||||
define( 'MW_MATH_MODERN', 4 ); /// @deprecated
|
||||
define( 'MW_MATH_MATHML', 5 );
|
||||
define( 'MW_MATH_MATHJAX', 6 ); /// @deprecated
|
||||
define( 'MW_MATH_LATEXML', 7 ); /// new in 1.22
|
||||
define( 'MW_MATH_LATEXML_JAX', 8 ); /// new in 1.22
|
||||
/**@}*/
|
||||
|
||||
/**@{
|
||||
* Mathstyle constants
|
||||
*/
|
||||
define( 'MW_MATHSTYLE_INLINE_DISPLAYSTYLE', 0 ); //default large operator inline
|
||||
define( 'MW_MATHSTYLE_DISPLAY', 1 ); // large operators centered in a new line
|
||||
define( 'MW_MATHSTYLE_INLINE', 2 ); // small operators inline
|
||||
// There is no style which renders small operators
|
||||
// but display the equation centered in a new line.
|
||||
/**@}*/
|
||||
|
||||
/**@var array defines the mode allowed on the server */
|
||||
$wgMathValidModes = array( MW_MATH_PNG, MW_MATH_SOURCE, MW_MATH_MATHML );
|
||||
|
||||
/*
|
||||
* The default rendering mode for anonymous users.
|
||||
* Valid options are defined in $wgMathValidModes.
|
||||
*/
|
||||
$wgDefaultUserOptions['math'] = MW_MATH_PNG;
|
||||
|
||||
/** Location of the texvc binary */
|
||||
$wgTexvc = __DIR__ . '/math/texvc';
|
||||
/**
|
||||
* Texvc background color
|
||||
* use LaTeX color format as used in \special function
|
||||
* for transparent background use value 'Transparent' for alpha transparency or
|
||||
* 'transparent' for binary transparency.
|
||||
*/
|
||||
$wgTexvcBackgroundColor = 'transparent';
|
||||
|
||||
/**
|
||||
* Normally when generating math images, we double-check that the
|
||||
* directories we want to write to exist, and that files that have
|
||||
* been generated still exist when we need to bring them up again.
|
||||
*
|
||||
* This lets us give useful error messages in case of permission
|
||||
* problems, and automatically rebuild images that have been lost.
|
||||
*
|
||||
* On a big site with heavy NFS traffic this can be slow and flaky,
|
||||
* so sometimes we want to short-circuit it by setting this to false.
|
||||
*/
|
||||
$wgMathCheckFiles = true;
|
||||
|
||||
/**
|
||||
* The URL path of the math directory. Defaults to "{$wgUploadPath}/math".
|
||||
*
|
||||
* See http://www.mediawiki.org/wiki/Manual:Enable_TeX for details about how to
|
||||
* set up mathematical formula display.
|
||||
*/
|
||||
$wgMathPath = false;
|
||||
|
||||
/**
|
||||
* The name of a file backend ($wgFileBackends) to use for storing math renderings.
|
||||
* Defaults to FSFileBackend using $wgMathDirectory as a base path.
|
||||
*
|
||||
* See http://www.mediawiki.org/wiki/Manual:Enable_TeX for details about how to
|
||||
* set up mathematical formula display.
|
||||
*/
|
||||
$wgMathFileBackend = false;
|
||||
|
||||
/**
|
||||
* The filesystem path of the math directory.
|
||||
* Defaults to "{$wgUploadDirectory}/math".
|
||||
*
|
||||
* See http://www.mediawiki.org/wiki/Manual:Enable_TeX for details about how to
|
||||
* set up mathematical formula display.
|
||||
*/
|
||||
$wgMathDirectory = false;
|
||||
|
||||
/**
|
||||
* The url of the mathoid server.
|
||||
*
|
||||
* Documentation: http://www.formulasearchengine.com/mathoid
|
||||
* Example value: http://mathoid.example.org:10042
|
||||
*
|
||||
* @todo Move documentation to mediawiki.org
|
||||
*/
|
||||
$wgMathMathMLUrl = 'http://mathoid.testme.wmflabs.org';
|
||||
|
||||
/**
|
||||
* The timeout for the HTTP-Request sent to the MathML to render an equation,
|
||||
* in seconds.
|
||||
*/
|
||||
$wgMathMathMLTimeout = 20;
|
||||
|
||||
/**
|
||||
* Use of LaTeXML for details see
|
||||
* <http://latexml.mathweb.org/help>
|
||||
*
|
||||
* If you want or need to run your own server, follow these installation
|
||||
* instructions and override $wgMathLaTeXMLUrl:
|
||||
* <http://www.formulasearchengine.com/LaTeXML>
|
||||
*
|
||||
* If you expect heavy load you can specify multiple servers. In that case one
|
||||
* server is randomly chosen for each rendering process. Specify the list of
|
||||
* servers in an array e.g $wgMathLaTeXMLUrl = array ( 'http://latexml.example.com/convert',
|
||||
* 'http://latexml2.example.com/convert');
|
||||
*/
|
||||
$wgMathLaTeXMLUrl = 'http://gw125.iu.xsede.org:8888'; // Sponsored by https://www.xsede.org/
|
||||
|
||||
/**
|
||||
* The timeout for the HTTP-Request sent to the LaTeXML to render an equation,
|
||||
* in seconds.
|
||||
*/
|
||||
$wgMathLaTeXMLTimeout = 240;
|
||||
/**
|
||||
* Setting for the LaTeXML renderer.
|
||||
* See http://dlmf.nist.gov/LaTeXML/manual/commands/latexmlpost.xhtml for details.
|
||||
*/
|
||||
$wgMathDefaultLaTeXMLSetting = array(
|
||||
'format' => 'xhtml',
|
||||
'whatsin' => 'math',
|
||||
'whatsout' => 'math',
|
||||
'pmml',
|
||||
'cmml',
|
||||
'mathtex',
|
||||
'nodefaultresources',
|
||||
'preload' => array( 'LaTeX.pool',
|
||||
'article.cls',
|
||||
'amsmath.sty',
|
||||
'amsthm.sty',
|
||||
'amstext.sty',
|
||||
'amssymb.sty',
|
||||
'eucal.sty',
|
||||
'[dvipsnames]xcolor.sty',
|
||||
'url.sty',
|
||||
'hyperref.sty',
|
||||
'[ids]latexml.sty',
|
||||
'texvc' ),
|
||||
);
|
||||
/**
|
||||
* The link to the texvccheck executable
|
||||
*/
|
||||
$wgMathTexvcCheckExecutable = __DIR__ . '/texvccheck/texvccheck';
|
||||
|
||||
/**@{
|
||||
* Math check constants
|
||||
*/
|
||||
define( 'MW_MATH_CHECK_ALWAYS', 0 ); /// backwards compatible to false
|
||||
define( 'MW_MATH_CHECK_NEVER' , 1 ); /// backwards compatible to true
|
||||
define( 'MW_MATH_CHECK_NEW' , 2 );
|
||||
/**@}*/
|
||||
/**
|
||||
* Option to disable the TeX security filter:
|
||||
* In general every math object, which is rendered by the math extension has its rendering cached in
|
||||
* a database.
|
||||
* MW_MATH_CHECK_ALWAYS: If set to MW_MATH_CHECK_ALWAYS only a subset of the TeX commands is allowed.
|
||||
* See the Wikipedia page Help:Math for details about the allowed commands.
|
||||
* MW_MATH_CHECK_NONE: If set to MW_MATH_CHECK_NONE any TeX expression is parsed.
|
||||
* This can be a potential security risk.
|
||||
* MW_MATH_CHECK_NEW checks only new equations. If the database does not yet contain the given math object,
|
||||
* then it is passed through texvccheck.
|
||||
* Please make sure to truncate the database tables (math, mathoid, mathlatexml) when switching from
|
||||
* MW_MATH_CHECK_NONE to MW_MATH_CHECK_NEW. Otherwise, unchecked content contained in the database
|
||||
* will be displayed.
|
||||
*/
|
||||
$wgMathDisableTexFilter = MW_MATH_CHECK_NEW;
|
||||
|
||||
/** @var boolean $wgMathEnableExperimentalInputFormats enables experimental MathML and AsciiMath input format support */
|
||||
$wgMathEnableExperimentalInputFormats = false;
|
||||
////////// end of config settings.
|
||||
|
||||
$wgExtensionFunctions[] = 'MathHooks::setup';
|
||||
$wgHooks['ParserFirstCallInit'][] = 'MathHooks::onParserFirstCallInit';
|
||||
$wgHooks['GetPreferences'][] = 'MathHooks::onGetPreferences';
|
||||
$wgHooks['LoadExtensionSchemaUpdates'][] = 'MathHooks::onLoadExtensionSchemaUpdates';
|
||||
$wgHooks['ParserTestTables'][] = 'MathHooks::onParserTestTables';
|
||||
$wgHooks['UnitTestsList'][] = 'MathHooks::onRegisterUnitTests';
|
||||
$wgHooks['PageRenderingHash'][] = 'MathHooks::onPageRenderingHash';
|
||||
$wgHooks['EditPageBeforeEditToolbar'][] = 'MathHooks::onEditPageBeforeEditToolbar';
|
||||
|
||||
$dir = __DIR__ . '/';
|
||||
$wgAutoloadClasses['MathHooks'] = $dir . 'Math.hooks.php';
|
||||
$wgAutoloadClasses['MathRenderer'] = $dir . 'MathRenderer.php';
|
||||
$wgAutoloadClasses['MathTexvc'] = $dir . 'MathTexvc.php';
|
||||
$wgAutoloadClasses['MathSource'] = $dir . 'MathSource.php';
|
||||
$wgAutoloadClasses['MathMathML'] = $dir . 'MathMathML.php';
|
||||
$wgAutoloadClasses['MathLaTeXML'] = $dir . 'MathLaTeXML.php';
|
||||
$wgAutoloadClasses['MathInputCheck'] = $dir . 'MathInputCheck.php';
|
||||
$wgAutoloadClasses['MathInputCheckTexvc'] = $dir . 'MathInputCheckTexvc.php';
|
||||
$wgAutoloadClasses['SpecialMathShowImage'] = $dir . 'SpecialMathShowImage.php';
|
||||
$wgAutoloadClasses['SpecialMathStatus'] = $dir . 'SpecialMathStatus.php';
|
||||
$wgMessagesDirs['Math'] = __DIR__ . '/i18n';
|
||||
$wgExtensionMessagesFiles['MathAlias'] = $dir . 'Math.alias.php';
|
||||
$wgExtensionMessagesFiles['MathAliasNoTranslate'] = $dir . 'Math.alias.noTranslate.php';
|
||||
|
||||
$wgParserTestFiles[] = $dir . 'mathParserTests.txt';
|
||||
|
||||
$wgSpecialPages['MathShowImage'] = 'SpecialMathShowImage';
|
||||
$wgSpecialPages['MathStatus'] = 'SpecialMathStatus';
|
||||
|
||||
$wgResourceModules['ext.math.styles'] = array(
|
||||
'position' => 'top',
|
||||
'localBasePath' => __DIR__ . '/modules',
|
||||
'remoteExtPath' => 'Math/modules',
|
||||
'styles' => 'ext.math.css',
|
||||
'targets' => array( 'desktop', 'mobile' ),
|
||||
);
|
||||
$wgResourceModules['ext.math.desktop.styles'] = array(
|
||||
'position' => 'top',
|
||||
'localBasePath' => __DIR__ . '/modules',
|
||||
'remoteExtPath' => 'Math/modules',
|
||||
'styles' => 'ext.math.desktop.css',
|
||||
);
|
||||
$wgResourceModules['ext.math.scripts'] = array(
|
||||
'localBasePath' => __DIR__ . '/modules',
|
||||
'remoteExtPath' => 'Math/modules',
|
||||
'scripts' => 'ext.math.js',
|
||||
);
|
||||
|
||||
|
||||
$moduleTemplate = array(
|
||||
'localBasePath' => __DIR__ . '/modules',
|
||||
'remoteExtPath' => 'Math/modules',
|
||||
);
|
||||
|
||||
$wgResourceModules['ext.math.editbutton.enabler'] = array(
|
||||
'scripts' => 'ext.math.editbutton.js',
|
||||
'messages' => array(
|
||||
'math_tip',
|
||||
'math_sample',
|
||||
),
|
||||
) + $moduleTemplate;
|
||||
|
||||
$wgResourceModules['ext.math.visualEditor'] = array(
|
||||
'scripts' => array(
|
||||
'VisualEditor/ve.dm.MWMathNode.js',
|
||||
'VisualEditor/ve.ce.MWMathNode.js',
|
||||
'VisualEditor/ve.ui.MWMathInspector.js',
|
||||
'VisualEditor/ve.ui.MWMathInspectorTool.js',
|
||||
),
|
||||
'styles' => array(
|
||||
'VisualEditor/ve.ce.MWMathNode.css',
|
||||
'VisualEditor/ve.ui.MWMathIcons.css',
|
||||
'VisualEditor/ve.ui.MWMathInspector.css',
|
||||
),
|
||||
'dependencies' => array(
|
||||
'ext.visualEditor.mwcore',
|
||||
),
|
||||
'messages' => array(
|
||||
'math-visualeditor-mwmathinspector-display',
|
||||
'math-visualeditor-mwmathinspector-display-block',
|
||||
'math-visualeditor-mwmathinspector-display-default',
|
||||
'math-visualeditor-mwmathinspector-display-inline',
|
||||
'math-visualeditor-mwmathinspector-id',
|
||||
'math-visualeditor-mwmathinspector-title',
|
||||
),
|
||||
'targets' => array( 'desktop', 'mobile' ),
|
||||
) + $moduleTemplate;
|
||||
|
||||
$wgVisualEditorPluginModules[] = 'ext.math.visualEditor';
|
||||
if ( function_exists( 'wfLoadExtension' ) ) {
|
||||
wfLoadExtension( 'Math' );
|
||||
// Keep i18n globals so mergeMessageFileList.php doesn't break
|
||||
$wgMessagesDirs['Math'] = __DIR__ . '/i18n';
|
||||
$wgExtensionMessagesFiles['Math'] = __DIR__ . '/Math.alias.php';
|
||||
$wgExtensionMessagesFiles['MathAliasNoTranslate'] = __DIR__ . '/Math.alias.noTranslate.php';
|
||||
/* wfWarn(
|
||||
'Deprecated PHP entry point used for Math extension. Please use wfLoadExtension instead, ' .
|
||||
'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
|
||||
);*/
|
||||
return;
|
||||
} else {
|
||||
die( 'This version of the Math extension requires MediaWiki 1.25+' );
|
||||
}
|
|
@ -62,14 +62,19 @@ class MathInputCheckTexvc extends MathInputCheck {
|
|||
*/
|
||||
public function doValidCheck() {
|
||||
global $wgMathTexvcCheckExecutable;
|
||||
if ( !is_executable( $wgMathTexvcCheckExecutable ) ) {
|
||||
if ( $wgMathTexvcCheckExecutable === false ){
|
||||
$texvcCheckExecutable = __DIR__ . '/texvccheck/texvccheck';
|
||||
} else {
|
||||
$texvcCheckExecutable = $wgMathTexvcCheckExecutable;
|
||||
}
|
||||
if ( !is_executable( $texvcCheckExecutable ) ) {
|
||||
$msg = 'Missing "texvccheck" executable. Please see math/README to configure.';
|
||||
trigger_error( $msg, E_USER_NOTICE );
|
||||
LoggerFactory::getInstance( 'Math' )->error( $msg );
|
||||
return true;
|
||||
}
|
||||
|
||||
$cmd = $wgMathTexvcCheckExecutable . ' ' . wfEscapeShellArg( $this->inputTeX );
|
||||
$cmd = $texvcCheckExecutable . ' ' . wfEscapeShellArg( $this->inputTeX );
|
||||
|
||||
if ( wfIsWindows() ) {
|
||||
# Invoke it within cygwin sh, because texvc expects sh features in its default shell
|
||||
|
|
|
@ -20,7 +20,7 @@ class MathLaTeXML extends MathMathML {
|
|||
global $wgMathLaTeXMLUrl;
|
||||
parent::__construct( $tex, $params );
|
||||
$this->hosts = $wgMathLaTeXMLUrl;
|
||||
$this->setMode( MW_MATH_LATEXML );
|
||||
$this->setMode( 'latexml' );
|
||||
}
|
||||
/**
|
||||
* Converts an array with LaTeXML settings to a URL encoded String.
|
||||
|
@ -75,8 +75,8 @@ class MathLaTeXML extends MathMathML {
|
|||
*/
|
||||
public function getLaTeXMLPostData() {
|
||||
$tex = $this->getTex();
|
||||
if ( $this->getMathStyle() == MW_MATHSTYLE_INLINE_DISPLAYSTYLE ) {
|
||||
// In MW_MATHSTYLE_INLINE_DISPLAYSTYLE the old
|
||||
if ( $this->getMathStyle() == 'inlineDisplaystyle' ) {
|
||||
// In 'inlineDisplaystyle' the old
|
||||
// texvc behavior is reproduced:
|
||||
// The equation is rendered in displaystyle
|
||||
// (texvc used $$ $tex $$ to render)
|
||||
|
@ -117,7 +117,7 @@ class MathLaTeXML extends MathMathML {
|
|||
if ( $this->isValidMathML( $jsonResult->result ) ) {
|
||||
$this->setMathml( $jsonResult->result );
|
||||
Hooks::run( 'MathRenderingResultRetrieved',
|
||||
array( &$renderer,
|
||||
array( &$this,
|
||||
&$jsonResult ) );// Enables debugging of server results
|
||||
return true;
|
||||
} else {
|
||||
|
@ -184,7 +184,7 @@ class MathLaTeXML extends MathMathML {
|
|||
public function calculateSvg() {
|
||||
$renderer = new MathMathML( $this->getTex() );
|
||||
$renderer->setMathml( $this->getMathml() );
|
||||
$renderer->setMode( MW_MATH_LATEXML );
|
||||
$renderer->setMode( 'latexml' );
|
||||
$res = $renderer->render( true );
|
||||
if ( $res == true ) {
|
||||
$this->setSvg( $renderer->getSvg() );
|
||||
|
|
|
@ -38,7 +38,7 @@ class MathMathML extends MathRenderer {
|
|||
public function __construct( $tex = '', $params = array() ) {
|
||||
global $wgMathMathMLUrl;
|
||||
parent::__construct( $tex, $params );
|
||||
$this->setMode( MW_MATH_MATHML );
|
||||
$this->setMode( 'mathml' );
|
||||
$this->hosts = $wgMathMathMLUrl;
|
||||
if ( isset( $params['type'] ) ) {
|
||||
if ( $params['type'] == 'pmml' ) {
|
||||
|
@ -174,7 +174,7 @@ class MathMathML extends MathRenderer {
|
|||
$errormsg = $status->getHtml();
|
||||
$error =
|
||||
$this->getError( 'math_invalidresponse', $this->getModeStr(), $host, $errormsg,
|
||||
$this->getModeStr( MW_MATH_MATHML ) );
|
||||
$this->getModeStr( 'mathml' ) );
|
||||
LoggerFactory::getInstance( 'Math' )->warning( 'NoResponse:' . var_export( array(
|
||||
'post' => $post,
|
||||
'host' => $host,
|
||||
|
@ -211,12 +211,12 @@ class MathMathML extends MathRenderer {
|
|||
public function getPostData() {
|
||||
$input = $this->getTex();
|
||||
if ( $this->inputType == 'pmml' ||
|
||||
$this->getMode() == MW_MATH_LATEXML && $this->getMathml() ) {
|
||||
$this->getMode() == 'latexml' && $this->getMathml() ) {
|
||||
$out = 'type=mml&q=' . rawurlencode( $this->getMathml() );
|
||||
} elseif ( $this->inputType == 'ascii' ) {
|
||||
$out = 'type=asciimath&q=' . rawurlencode( $input );
|
||||
} else {
|
||||
if ( $this->getMathStyle() == MW_MATHSTYLE_INLINE_DISPLAYSTYLE ) {
|
||||
if ( $this->getMathStyle() == 'inlineDisplaystyle' ) {
|
||||
// default preserve the (broken) layout as it was
|
||||
$out = 'type=inline-TeX&q=' . rawurlencode( '{\\displaystyle ' . $input . '}' );
|
||||
} else {
|
||||
|
@ -332,7 +332,7 @@ class MathMathML extends MathRenderer {
|
|||
public function correctSvgStyle( $svg, &$style ) {
|
||||
if ( preg_match( '/style="([^"]*)"/', $svg, $styles ) ) {
|
||||
$style .= ' ' . $styles[1]; // merge styles
|
||||
if ( $this->getMathStyle() === MW_MATHSTYLE_DISPLAY ) {
|
||||
if ( $this->getMathStyle() === 'display' ) {
|
||||
// TODO: Improve style cleaning
|
||||
$style = preg_replace( '/margin\-(left|right)\:\s*\d+(\%|in|cm|mm|em|ex|pt|pc|px)\;/', '', $style );
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ class MathMathML extends MathRenderer {
|
|||
} else {
|
||||
$class .= 'mathml-';
|
||||
}
|
||||
if ( $this->getMathStyle() == MW_MATHSTYLE_DISPLAY ) {
|
||||
if ( $this->getMathStyle() == 'display' ) {
|
||||
$class .= 'display';
|
||||
} else {
|
||||
$class .= 'inline';
|
||||
|
@ -406,7 +406,7 @@ class MathMathML extends MathRenderer {
|
|||
* @return string Html output that is embedded in the page
|
||||
*/
|
||||
public function getHtmlOutput() {
|
||||
if ( $this->getMathStyle() == MW_MATHSTYLE_DISPLAY ) {
|
||||
if ( $this->getMathStyle() == 'display' ) {
|
||||
$element = 'div';
|
||||
} else {
|
||||
$element = 'span';
|
||||
|
@ -420,7 +420,7 @@ class MathMathML extends MathRenderer {
|
|||
// Remove displayStyle attributes set by the MathML converter
|
||||
// (Beginning from Mathoid 0.2.5 block is the default layout.)
|
||||
$mml = preg_replace( '/(<math[^>]*)(display|mode)=["\'](inline|block)["\']/', '$1', $this->getMathml() );
|
||||
if ( $this->getMathStyle() == MW_MATHSTYLE_DISPLAY ) {
|
||||
if ( $this->getMathStyle() == 'display' ) {
|
||||
$mml = preg_replace( '/<math/', '<math display="block"', $mml );
|
||||
}
|
||||
$output .= Xml::tags( $element, array( 'class' => $this->getClassName(), 'style' => 'display: none;' ), $mml );
|
||||
|
@ -464,7 +464,7 @@ class MathMathML extends MathRenderer {
|
|||
* @return bool
|
||||
*/
|
||||
private function processJsonResult( $jsonResult, $host ) {
|
||||
if ( $this->getMode() == MW_MATH_LATEXML || $this->inputType == 'pmml' ||
|
||||
if ( $this->getMode() == 'latexml' || $this->inputType == 'pmml' ||
|
||||
$this->isValidMathML( $jsonResult->mml )
|
||||
) {
|
||||
if ( isset( $jsonResult->svg ) ) {
|
||||
|
@ -479,7 +479,7 @@ class MathMathML extends MathRenderer {
|
|||
LoggerFactory::getInstance( 'Math' )->error(
|
||||
'Missing SVG property in JSON result.' );
|
||||
}
|
||||
if ( $this->getMode() != MW_MATH_LATEXML && $this->inputType != 'pmml' ) {
|
||||
if ( $this->getMode() != 'latexml' && $this->inputType != 'pmml' ) {
|
||||
$this->setMathml( $jsonResult->mml );
|
||||
}
|
||||
Hooks::run( 'MathRenderingResultRetrieved',
|
||||
|
|
|
@ -31,8 +31,8 @@ abstract class MathRenderer {
|
|||
/** @var string the original user input string (which was used to calculate the inputhash) */
|
||||
protected $userInputTex = '';
|
||||
// FURTHER PROPERTIES OF THE MATHEMATICAL CONTENT
|
||||
/** @var (MW_MATHSTYLE_INLINE_DISPLAYSTYLE|MW_MATHSTYLE_DISPLAY|MW_MATHSTYLE_INLINE) the rendering style */
|
||||
protected $mathStyle = MW_MATHSTYLE_INLINE_DISPLAYSTYLE;
|
||||
/** @var ('inlineDisplaystyle'|'display'|'inline') the rendering style */
|
||||
protected $mathStyle = 'inlineDisplaystyle';
|
||||
/** @var array with userdefined parameters passed to the extension (not used) */
|
||||
protected $params = array();
|
||||
/** @var string a userdefined identifier to link to the equation. */
|
||||
|
@ -53,8 +53,8 @@ abstract class MathRenderer {
|
|||
protected $md5 = '';
|
||||
/** @var binary packed inputhash */
|
||||
protected $inputHash = '';
|
||||
/** @var int rendering mode MW_MATH_(PNG|MATHML|SOURCE...) */
|
||||
protected $mode = MW_MATH_PNG;
|
||||
/** @var string rendering mode */
|
||||
protected $mode = 'png';
|
||||
|
||||
/**
|
||||
* Constructs a base MathRenderer
|
||||
|
@ -76,10 +76,10 @@ abstract class MathRenderer {
|
|||
*
|
||||
* @param string $tex LaTeX markup
|
||||
* @param array $params HTML attributes
|
||||
* @param int $mode constant indicating rendering mode
|
||||
* @param string $mode constant indicating rendering mode
|
||||
* @return string HTML for math tag
|
||||
*/
|
||||
public static function renderMath( $tex, $params = array(), $mode = MW_MATH_PNG ) {
|
||||
public static function renderMath( $tex, $params = array(), $mode = 'png' ) {
|
||||
$renderer = self::getRenderer( $tex, $params, $mode );
|
||||
if ( $renderer->render() ) {
|
||||
return $renderer->getHtmlOutput();
|
||||
|
@ -107,16 +107,16 @@ abstract class MathRenderer {
|
|||
*
|
||||
* @param string $tex LaTeX markup
|
||||
* @param array $params HTML attributes
|
||||
* @param int $mode constant indicating rendering mode
|
||||
* @param string $mode indicating rendering mode
|
||||
* @return MathRenderer appropriate renderer for mode
|
||||
*/
|
||||
public static function getRenderer( $tex, $params = array(), $mode = MW_MATH_PNG ) {
|
||||
global $wgDefaultUserOptions, $wgMathValidModes, $wgMathEnableExperimentalInputFormats;
|
||||
public static function getRenderer( $tex, $params = array(), $mode = 'png' ) {
|
||||
global $wgDefaultUserOptions, $wgMathEnableExperimentalInputFormats;
|
||||
$mathStyle = null;
|
||||
if ( isset( $params['display'] ) ) {
|
||||
$layoutMode = $params['display'];
|
||||
if ( $layoutMode == 'block' ) {
|
||||
$mathStyle = MW_MATHSTYLE_DISPLAY;
|
||||
$mathStyle = 'display';
|
||||
// TODO: Implement caching for attributes of the math tag
|
||||
// Currently the key for the database entry relating to an equation
|
||||
// is md5($tex) the new option to determine if the tex input
|
||||
|
@ -129,7 +129,7 @@ abstract class MathRenderer {
|
|||
// be centered in a new line, or just in be displayed in the current line.
|
||||
$tex = '{\displaystyle ' . $tex . '}';
|
||||
} elseif ( $layoutMode == 'inline' ) {
|
||||
$mathStyle = MW_MATHSTYLE_INLINE;
|
||||
$mathStyle = 'inline';
|
||||
$tex = '{\textstyle ' . $tex . '}';
|
||||
}
|
||||
}
|
||||
|
@ -137,29 +137,28 @@ abstract class MathRenderer {
|
|||
if ( isset( $params['forcemathmode'] ) ) {
|
||||
$mode = $params['forcemathmode'];
|
||||
}
|
||||
if ( !in_array( $mode, $wgMathValidModes ) ) {
|
||||
if ( !in_array( $mode, self::getValidModes() ) ) {
|
||||
$mode = $wgDefaultUserOptions['math'];
|
||||
}
|
||||
if ( $wgMathEnableExperimentalInputFormats === true && $mode == MW_MATH_MATHML &&
|
||||
if ( $wgMathEnableExperimentalInputFormats === true && $mode == 'mathml' &&
|
||||
isset( $params['type'] ) ) {
|
||||
// Support of MathML input (experimental)
|
||||
// Currently support for mode MW_MATH_MATHML only
|
||||
// Currently support for mode 'mathml' only
|
||||
if ( !in_array( $params['type'], array( 'pmml', 'ascii' ) ) ) {
|
||||
unset( $params['type'] );
|
||||
}
|
||||
}
|
||||
switch ( $mode ) {
|
||||
case MW_MATH_MATHJAX:
|
||||
case MW_MATH_SOURCE:
|
||||
case 'source':
|
||||
$renderer = new MathSource( $tex, $params );
|
||||
break;
|
||||
case MW_MATH_PNG:
|
||||
case 'png':
|
||||
$renderer = new MathTexvc( $tex, $params );
|
||||
break;
|
||||
case MW_MATH_LATEXML:
|
||||
case 'latexml':
|
||||
$renderer = new MathLaTeXML( $tex, $params );
|
||||
break;
|
||||
case MW_MATH_MATHML:
|
||||
case 'mathml':
|
||||
default:
|
||||
$renderer = new MathMathML( $tex, $params );
|
||||
}
|
||||
|
@ -408,9 +407,9 @@ abstract class MathRenderer {
|
|||
}
|
||||
|
||||
/**
|
||||
* gets the rendering mode MW_MATH_*
|
||||
* Gets the rendering mode
|
||||
*
|
||||
* @return int
|
||||
* @return string
|
||||
*/
|
||||
public function getMode() {
|
||||
return $this->mode;
|
||||
|
@ -418,12 +417,11 @@ abstract class MathRenderer {
|
|||
|
||||
/**
|
||||
* Sets the rendering mode
|
||||
* @param int $newMode element of the array $wgMathValidModes
|
||||
* @param string $newMode element of the array $wgMathValidModes
|
||||
* @return bool
|
||||
*/
|
||||
public function setMode( $newMode ) {
|
||||
global $wgMathValidModes;
|
||||
if ( in_array( $newMode, $wgMathValidModes ) ) {
|
||||
if ( in_array( $newMode, self::getValidModes() ) ) {
|
||||
$this->mode = $newMode;
|
||||
return true;
|
||||
} else {
|
||||
|
@ -530,9 +528,9 @@ abstract class MathRenderer {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param (MW_MATHSTYLE_INLINE_DISPLAYSTYLE|MW_MATHSTYLE_DISPLAY|MW_MATHSTYLE_INLINE) $mathStyle
|
||||
* @param ('inlineDisplaystyle'|'display'|'inline') $mathStyle
|
||||
*/
|
||||
public function setMathStyle( $displayStyle = MW_MATHSTYLE_DISPLAY ) {
|
||||
public function setMathStyle( $displayStyle = 'display' ) {
|
||||
if ( $this->mathStyle !== $displayStyle ){
|
||||
$this->changed = true;
|
||||
}
|
||||
|
@ -541,7 +539,7 @@ abstract class MathRenderer {
|
|||
|
||||
/**
|
||||
* Returns the value of the DisplayStyle attribute
|
||||
* @return (MW_MATHSTYLE_INLINE_DISPLAYSTYLE|MW_MATHSTYLE_DISPLAY|MW_MATHSTYLE_INLINE) the DisplayStyle
|
||||
* @return ('inlineDisplaystyle'|'display'|'inline') the DisplayStyle
|
||||
*/
|
||||
public function getMathStyle() {
|
||||
return $this->mathStyle;
|
||||
|
@ -560,12 +558,11 @@ abstract class MathRenderer {
|
|||
* @return bool
|
||||
*/
|
||||
public function checkTex() {
|
||||
global $wgMathDisableTexFilter;
|
||||
if ( $this->texSecure || (int) $wgMathDisableTexFilter == MW_MATH_CHECK_NEVER ) {
|
||||
if ( $this->texSecure || self::getDisableTexFilter() == 'never' ) {
|
||||
// equation was already checked or checking is disabled
|
||||
return true;
|
||||
} else {
|
||||
if( (int) $wgMathDisableTexFilter == MW_MATH_CHECK_NEW && $this->mode != MW_MATH_SOURCE ){
|
||||
if( self::getDisableTexFilter() == 'new' && $this->mode != 'source' ){
|
||||
if( $this->readFromDatabase() ){
|
||||
return true;
|
||||
}
|
||||
|
@ -647,4 +644,14 @@ abstract class MathRenderer {
|
|||
return $names[ $this->getMode() ];
|
||||
}
|
||||
|
||||
public static function getValidModes(){
|
||||
global $wgMathValidModes;
|
||||
return array_map( "MathHooks::mathModeToString", $wgMathValidModes );
|
||||
}
|
||||
|
||||
|
||||
public static function getDisableTexFilter(){
|
||||
global $wgMathDisableTexFilter;
|
||||
return MathHooks::mathCheckToString( $wgMathDisableTexFilter );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class MathSource extends MathRenderer {
|
|||
*/
|
||||
function __construct( $tex = '', $params = array() ) {
|
||||
parent::__construct( $tex, $params );
|
||||
$this->setMode( MW_MATH_SOURCE );
|
||||
$this->setMode( 'source' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ class MathSource extends MathRenderer {
|
|||
function getHtmlOutput() {
|
||||
# No need to render or parse anything more!
|
||||
# New lines are replaced with spaces, which avoids confusing our parser (bugs 23190, 22818)
|
||||
if ( $this->getMathStyle() == MW_MATHSTYLE_DISPLAY ) {
|
||||
if ( $this->getMathStyle() == 'display' ) {
|
||||
$class = 'mwe-math-fallback-source-display';
|
||||
} else {
|
||||
$class = 'mwe-math-fallback-source-inline';
|
||||
|
|
|
@ -143,7 +143,7 @@ class MathTexvc extends MathRenderer {
|
|||
'class' => 'mwe-math-fallback-image-inline tex',
|
||||
'alt' => $this->getTex()
|
||||
);
|
||||
if ( $this->getMathStyle() === MW_MATHSTYLE_DISPLAY ){
|
||||
if ( $this->getMathStyle() === 'display' ){
|
||||
// if DisplayStyle is true, the equation will be centered in a new line
|
||||
$attributes[ 'class' ] = 'mwe-math-fallback-image-display tex';
|
||||
}
|
||||
|
@ -177,17 +177,21 @@ class MathTexvc extends MathRenderer {
|
|||
*/
|
||||
public function callTexvc() {
|
||||
global $wgTexvc, $wgTexvcBackgroundColor, $wgHooks;
|
||||
|
||||
if ( $wgTexvc === false ){
|
||||
$texvc = __DIR__ . '/math/texvc';
|
||||
} else {
|
||||
$texvc = $wgTexvc;
|
||||
}
|
||||
$tmpDir = wfTempDir();
|
||||
if ( !is_executable( $wgTexvc ) ) {
|
||||
if ( !is_executable( $texvc ) ) {
|
||||
LoggerFactory::getInstance( 'Math' )->error(
|
||||
"$wgTexvc does not exist or is not executable." );
|
||||
"$texvc does not exist or is not executable." );
|
||||
return $this->getError( 'math_notexvc' );
|
||||
}
|
||||
|
||||
$escapedTmpDir = wfEscapeShellArg( $tmpDir );
|
||||
|
||||
$cmd = $wgTexvc . ' ' .
|
||||
$cmd = $texvc . ' ' .
|
||||
$escapedTmpDir . ' ' .
|
||||
$escapedTmpDir . ' ' .
|
||||
wfEscapeShellArg( $this->getUserInputTex() ) . ' ' .
|
||||
|
@ -335,27 +339,7 @@ class MathTexvc extends MathRenderer {
|
|||
* @return string HTML string
|
||||
*/
|
||||
public function getHtmlOutput() {
|
||||
if ( $this->getMode() == MW_MATH_MATHML && $this->getMathml() != '' ) {
|
||||
return Xml::tags( 'math',
|
||||
$this->getAttributes( 'math',
|
||||
array( 'xmlns' => 'http://www.w3.org/1998/Math/MathML' ) ),
|
||||
$this->mathml );
|
||||
}
|
||||
if ( ( $this->getMode() == MW_MATH_PNG ) || ( $this->getHtml() == '' ) ||
|
||||
( ( $this->getMode() == MW_MATH_SIMPLE ) && ( $this->getConservativeness() != self::CONSERVATIVE ) ) ||
|
||||
( ( $this->getMode() == MW_MATH_MODERN || $this->getMode() == MW_MATH_MATHML ) && ( $this->getConservativeness() == self::LIBERAL ) )
|
||||
)
|
||||
{
|
||||
return $this->getMathImageHTML();
|
||||
} else {
|
||||
return Xml::tags( 'span',
|
||||
$this->getAttributes( 'span',
|
||||
array( 'class' => 'texhtml',
|
||||
'dir' => 'ltr'
|
||||
) ),
|
||||
$this->getHtml()
|
||||
);
|
||||
}
|
||||
return $this->getMathImageHTML();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
2
README
2
README
|
@ -14,7 +14,7 @@ If you prefer MathML rather than images you can use LaTeXML to convert the
|
|||
math tags to MathML. To use that feature you have to enable LaTeXML by setting
|
||||
$wgMathUseLaTeXML = true;
|
||||
It is possible to choose LaTeXML as default option (for anonymous user) by setting
|
||||
$wgDefaultUserOptions['math'] = MW_MATH_LATEXML;
|
||||
$wgDefaultUserOptions['math'] = 'latexml';
|
||||
in the LocalSettings.php file.
|
||||
The LaTeXML option requires php5-curl to be installed. Without php5-curl no proper
|
||||
error handling can be guaranteed.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
class SpecialMathShowImage extends SpecialPage {
|
||||
private $noRender = false;
|
||||
private $renderer = null;
|
||||
private $mode = MW_MATH_MATHML;
|
||||
private $mode = 'mathml';
|
||||
|
||||
function __construct() {
|
||||
parent::__construct(
|
||||
|
@ -28,7 +28,7 @@ class SpecialMathShowImage extends SpecialPage {
|
|||
$out->setArticleRelated( false );
|
||||
$out->setRobotPolicy( "noindex,nofollow" );
|
||||
$out->disable();
|
||||
if ( $success && $this->mode == MW_MATH_PNG ) {
|
||||
if ( $success && $this->mode == 'png' ) {
|
||||
$request->response()->header( "Content-type: image/png;" );
|
||||
} else {
|
||||
$request->response()->header( "Content-type: image/svg+xml; charset=utf-8" );
|
||||
|
@ -40,7 +40,7 @@ class SpecialMathShowImage extends SpecialPage {
|
|||
}
|
||||
|
||||
function execute( $par ) {
|
||||
global $wgMathValidModes, $wgMathEnableExperimentalInputFormats;
|
||||
global $wgMathEnableExperimentalInputFormats;
|
||||
$request = $this->getRequest();
|
||||
$hash = $request->getText( 'hash', '' );
|
||||
$tex = $request->getText( 'tex', '' );
|
||||
|
@ -49,10 +49,10 @@ class SpecialMathShowImage extends SpecialPage {
|
|||
} else {
|
||||
$asciimath = '';
|
||||
}
|
||||
$this->mode = $request->getInt( 'mode', MW_MATH_MATHML );
|
||||
if ( !in_array( $this->mode, $wgMathValidModes ) ) {
|
||||
$this->mode = $request->getInt( 'mode', 'mathml' );
|
||||
if ( !in_array( $this->mode, MathRenderer::getValidModes() ) ) {
|
||||
// Fallback to the default if an invalid mode was specified
|
||||
$this->mode = MW_MATH_MATHML;
|
||||
$this->mode = 'mathml';
|
||||
}
|
||||
if ( $hash === '' && $tex === '' && $asciimath === '' ) {
|
||||
$this->setHeaders( false );
|
||||
|
@ -60,10 +60,10 @@ class SpecialMathShowImage extends SpecialPage {
|
|||
} else {
|
||||
if ( $tex === '' && $asciimath === ''){
|
||||
switch ( $this->mode ) {
|
||||
case MW_MATH_PNG:
|
||||
case 'png':
|
||||
$this->renderer = MathTexvc::newFromMd5( $hash );
|
||||
break;
|
||||
case MW_MATH_LATEXML:
|
||||
case 'latexml':
|
||||
$this->renderer = MathLaTeXML::newFromMd5( $hash );
|
||||
break;
|
||||
default:
|
||||
|
@ -74,12 +74,12 @@ class SpecialMathShowImage extends SpecialPage {
|
|||
if ( $isInDatabase || $this->noRender ) {
|
||||
$success = $isInDatabase;
|
||||
} else {
|
||||
if ( $this->mode == MW_MATH_PNG ) {
|
||||
if ( $this->mode == 'png' ) {
|
||||
// get the texvc input from the mathoid database table
|
||||
// and render the conventional way
|
||||
$mmlRenderer = MathMathML::newFromMd5( $hash );
|
||||
$mmlRenderer->readFromDatabase();
|
||||
$this->renderer = MathRenderer::getRenderer( $mmlRenderer->getUserInputTex(), array(), MW_MATH_PNG );
|
||||
$this->renderer = MathRenderer::getRenderer( $mmlRenderer->getUserInputTex(), array(), 'png' );
|
||||
$this->renderer->setMathStyle( $mmlRenderer->getMathStyle() );
|
||||
}
|
||||
$success = $this->renderer->render();
|
||||
|
@ -92,7 +92,7 @@ class SpecialMathShowImage extends SpecialPage {
|
|||
$success = $this->renderer->render();
|
||||
}
|
||||
if ( $success ) {
|
||||
if ( $this->mode == MW_MATH_PNG ) {
|
||||
if ( $this->mode == 'png' ) {
|
||||
$output = $this->renderer->getPng();
|
||||
} else {
|
||||
$output = $this->renderer->getSvg();
|
||||
|
|
|
@ -34,10 +34,10 @@ class SpecialMathStatus extends SpecialPage {
|
|||
foreach ( $enabledMathModes as $modeNr => $modeName ){
|
||||
$out->addWikiText( "=== $modeName ===" );
|
||||
switch( $modeNr ){
|
||||
case MW_MATH_MATHML:
|
||||
case 'mathml':
|
||||
$this->runMathMLTest( $modeName );
|
||||
break;
|
||||
case MW_MATH_LATEXML:
|
||||
case 'latexml':
|
||||
$this->runMathLaTeXMLTest( $modeName );
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class SpecialMathStatus extends SpecialPage {
|
|||
}
|
||||
|
||||
public function testSpecialCaseText() {
|
||||
$renderer = MathRenderer::getRenderer( 'x^2+\text{a sample Text}', array(), MW_MATH_MATHML );
|
||||
$renderer = MathRenderer::getRenderer( 'x^2+\text{a sample Text}', array(), 'mathml' );
|
||||
$expected = 'a sample Text</mtext>';
|
||||
$this->assertTrue( $renderer->render(), 'Rendering the input "x^2+\text{a sample Text}"' );
|
||||
$this->assertContains( $expected, $renderer->getHtmlOutput(), 'Comparing to the reference rendering' );
|
||||
|
@ -85,7 +85,7 @@ class SpecialMathStatus extends SpecialPage {
|
|||
<use xlink:href="#E1-MJMATHI-62" x="1761" y="0"></use>
|
||||
</g>
|
||||
</svg>';
|
||||
$renderer = MathRenderer::getRenderer( "a+b", array(), MW_MATH_MATHML );
|
||||
$renderer = MathRenderer::getRenderer( "a+b", array(), 'mathml' );
|
||||
$this->assertTrue( $renderer->render( true ), "Rendering of a+b in plain MathML mode" );
|
||||
$real = str_replace( "\n", '', $renderer->getHtmlOutput() );
|
||||
$expected = '<mo>+</mo>';
|
||||
|
@ -104,7 +104,7 @@ class SpecialMathStatus extends SpecialPage {
|
|||
$renderer = new MathMathML( $inputSample, $attribs );
|
||||
$this->assertEquals( 'pmml', $renderer->getInputType(), 'Checking if MathML input is supported' );
|
||||
$this->assertTrue( $renderer->render(), 'Rendering Presentation MathML sample' );
|
||||
$real = MathRenderer::renderMath( $inputSample, $attribs, MW_MATH_MATHML );
|
||||
$real = MathRenderer::renderMath( $inputSample, $attribs, 'mathml' );
|
||||
$expected = 'hash=5628b8248b79267ecac656102334d5e3&mode=5';
|
||||
$this->assertContains( $expected, $real, 'Checking if the link to SVG image is correct' );
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ class SpecialMathStatus extends SpecialPage {
|
|||
* i.e. if the span element is generated right.
|
||||
*/
|
||||
public function testLaTeXMLIntegration() {
|
||||
$renderer = MathRenderer::getRenderer( "a+b", array(), MW_MATH_LATEXML );
|
||||
$renderer = MathRenderer::getRenderer( "a+b", array(), 'latexml' );
|
||||
$this->assertTrue( $renderer->render( true ), "Rendering of a+b in LaTeXML mode" );
|
||||
$expected = '<math xmlns="http://www.w3.org/1998/Math/MathML" id="p1.1.m1.1" class="ltx_Math" alttext="{\displaystyle a+b}" xref="p1.1.m1.1.cmml"><semantics id="p1.1.m1.1a" xref="p1.1.m1.1.cmml"><mrow id="p1.1.m1.1.4" xref="p1.1.m1.1.4.cmml"><mi id="p1.1.m1.1.1" xref="p1.1.m1.1.1.cmml">a</mi><mo id="p1.1.m1.1.2" xref="p1.1.m1.1.2.cmml">+</mo><mi id="p1.1.m1.1.3" xref="p1.1.m1.1.3.cmml">b</mi></mrow><annotation-xml encoding="MathML-Content" id="p1.1.m1.1.cmml" xref="p1.1.m1.1"><apply id="p1.1.m1.1.4.cmml" xref="p1.1.m1.1.4"><plus id="p1.1.m1.1.2.cmml" xref="p1.1.m1.1.2"/><ci id="p1.1.m1.1.1.cmml" xref="p1.1.m1.1.1">a</ci><ci id="p1.1.m1.1.3.cmml" xref="p1.1.m1.1.3">b</ci></apply></annotation-xml><annotation encoding="application/x-tex" id="p1.1.m1.1b" xref="p1.1.m1.1.cmml">{\displaystyle a+b}</annotation></semantics></math>';
|
||||
$real = preg_replace( "/\n\s*/", '', $renderer->getHtmlOutput() );
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
{
|
||||
"name": "Math",
|
||||
"version": "2.0.0",
|
||||
"author": [
|
||||
"Tomasz Wegrzanowski",
|
||||
"Brion Vibber",
|
||||
"Moritz Schubotz",
|
||||
"Derk-Jan Hartman"
|
||||
],
|
||||
"url": "https://www.mediawiki.org/wiki/Extension:Math",
|
||||
"descriptionmsg": "math-desc",
|
||||
"callback": "MathHooks::registerExtension",
|
||||
"type": "parserhook",
|
||||
"AutoloadClasses": {
|
||||
"MathHooks": "Math.hooks.php",
|
||||
"MathRenderer": "MathRenderer.php",
|
||||
"MathTexvc": "MathTexvc.php",
|
||||
"MathSource": "MathSource.php",
|
||||
"MathMathML": "MathMathML.php",
|
||||
"MathLaTeXML": "MathLaTeXML.php",
|
||||
"MathInputCheck": "MathInputCheck.php",
|
||||
"MathInputCheckTexvc": "MathInputCheckTexvc.php",
|
||||
"SpecialMathShowImage": "SpecialMathShowImage.php",
|
||||
"SpecialMathStatus": "SpecialMathStatus.php"
|
||||
},
|
||||
"DefaultUserOptions": {
|
||||
"math": "png"
|
||||
},
|
||||
"ExtensionFunctions": [
|
||||
"MathHooks::setup"
|
||||
],
|
||||
"ExtensionMessagesFiles": {
|
||||
"MathAlias": "Math.alias.php",
|
||||
"MathAliasNoTranslate": "Math.alias.noTranslate.php"
|
||||
},
|
||||
"Hooks": {
|
||||
"ParserFirstCallInit": [
|
||||
"MathHooks::onParserFirstCallInit"
|
||||
],
|
||||
"GetPreferences": [
|
||||
"MathHooks::onGetPreferences"
|
||||
],
|
||||
"LoadExtensionSchemaUpdates": [
|
||||
"MathHooks::onLoadExtensionSchemaUpdates"
|
||||
],
|
||||
"ParserTestTables": [
|
||||
"MathHooks::onParserTestTables"
|
||||
],
|
||||
"UnitTestsList": [
|
||||
"MathHooks::onRegisterUnitTests"
|
||||
],
|
||||
"PageRenderingHash": [
|
||||
"MathHooks::onPageRenderingHash"
|
||||
],
|
||||
"EditPageBeforeEditToolbar": [
|
||||
"MathHooks::onEditPageBeforeEditToolbar"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"MathCheckFiles": true,
|
||||
"MathDefaultLaTeXMLSetting": {
|
||||
"format": "xhtml",
|
||||
"whatsin": "math",
|
||||
"whatsout": "math",
|
||||
"0": "pmml",
|
||||
"1": "cmml",
|
||||
"2": "mathtex",
|
||||
"3": "nodefaultresources",
|
||||
"preload": [
|
||||
"LaTeX.pool",
|
||||
"article.cls",
|
||||
"amsmath.sty",
|
||||
"amsthm.sty",
|
||||
"amstext.sty",
|
||||
"amssymb.sty",
|
||||
"eucal.sty",
|
||||
"[dvipsnames]xcolor.sty",
|
||||
"url.sty",
|
||||
"hyperref.sty",
|
||||
"[ids]latexml.sty",
|
||||
"texvc"
|
||||
]
|
||||
},
|
||||
"MathDirectory": false,
|
||||
"MathDisableTexFilter": "new",
|
||||
"MathEnableExperimentalInputFormats": false,
|
||||
"MathFileBackend": false,
|
||||
"MathLaTeXMLTimeout": 240,
|
||||
"MathLaTeXMLUrl": "http://gw125.iu.xsede.org:8888",
|
||||
"MathMathMLTimeout": 20,
|
||||
"MathMathMLUrl": "http://mathoid.testme.wmflabs.org",
|
||||
"MathPath": false,
|
||||
"MathTexvcCheckExecutable": false,
|
||||
"MathValidModes": [
|
||||
"png",
|
||||
"source",
|
||||
"mathml"
|
||||
],
|
||||
"Texvc": false,
|
||||
"TexvcBackgroundColor": "transparent"
|
||||
},
|
||||
"VisualEditorPluginModules": [
|
||||
"ext.math.visualEditor"
|
||||
],
|
||||
"MessagesDirs": {
|
||||
"Math": [
|
||||
"i18n"
|
||||
]
|
||||
},
|
||||
"ParserTestFiles": [
|
||||
"mathParserTests.txt"
|
||||
],
|
||||
"ResourceModules": {
|
||||
"ext.math.styles": {
|
||||
"position": "top",
|
||||
"styles": "ext.math.css",
|
||||
"targets": [
|
||||
"desktop",
|
||||
"mobile"
|
||||
]
|
||||
},
|
||||
"ext.math.desktop.styles": {
|
||||
"position": "top",
|
||||
"styles": "ext.math.desktop.css"
|
||||
},
|
||||
"ext.math.scripts": {
|
||||
"scripts": "ext.math.js"
|
||||
},
|
||||
"ext.math.editbutton.enabler": {
|
||||
"scripts": "ext.math.editbutton.js",
|
||||
"messages": [
|
||||
"math_tip",
|
||||
"math_sample"
|
||||
]
|
||||
},
|
||||
"ext.math.visualEditor": {
|
||||
"scripts": [
|
||||
"VisualEditor/ve.dm.MWMathNode.js",
|
||||
"VisualEditor/ve.ce.MWMathNode.js",
|
||||
"VisualEditor/ve.ui.MWMathInspector.js",
|
||||
"VisualEditor/ve.ui.MWMathInspectorTool.js"
|
||||
],
|
||||
"styles": [
|
||||
"VisualEditor/ve.ce.MWMathNode.css",
|
||||
"VisualEditor/ve.ui.MWMathIcons.css",
|
||||
"VisualEditor/ve.ui.MWMathInspector.css"
|
||||
],
|
||||
"dependencies": [
|
||||
"ext.visualEditor.mwcore"
|
||||
],
|
||||
"messages": [
|
||||
"math-visualeditor-mwmathinspector-display",
|
||||
"math-visualeditor-mwmathinspector-display-block",
|
||||
"math-visualeditor-mwmathinspector-display-default",
|
||||
"math-visualeditor-mwmathinspector-display-inline",
|
||||
"math-visualeditor-mwmathinspector-id",
|
||||
"math-visualeditor-mwmathinspector-title"
|
||||
],
|
||||
"targets": [
|
||||
"desktop",
|
||||
"mobile"
|
||||
]
|
||||
}
|
||||
},
|
||||
"ResourceFileModulePaths": {
|
||||
"localBasePath": "modules",
|
||||
"remoteExtPath": "Math/modules"
|
||||
},
|
||||
"SpecialPages": {
|
||||
"MathShowImage": "SpecialMathShowImage",
|
||||
"MathStatus": "SpecialMathStatus"
|
||||
},
|
||||
"manifest_version": 1
|
||||
}
|
|
@ -78,7 +78,7 @@ class MathGenerateTests extends Maintenance
|
|||
}
|
||||
$i = 0;
|
||||
foreach ( array_slice( $allEquations, $offset, $length, true ) as $input ) {
|
||||
$output = MathRenderer::renderMath( $input[1], $input[2], MW_MATH_PNG );
|
||||
$output = MathRenderer::renderMath( $input[1], $input[2], 'png' );
|
||||
$output = preg_replace( '#src="(.*?)/(([a-f]|\d)*).png"#', 'src="\2.png"', $output );
|
||||
$parserTests[] = array( (string)$input[1], $output );
|
||||
$i++;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
( function ( $ ) {
|
||||
'use strict';
|
||||
// The MW_MATH_PNG and MW_MATH_MATHML constants are taken from Math.php
|
||||
var MW_MATH_PNG = 0, MW_MATH_MATHML = 5, img, url;
|
||||
var img, url;
|
||||
|
||||
// If MathPlayer is installed we show the MathML rendering.
|
||||
if (navigator.userAgent.indexOf('MathPlayer') > -1) {
|
||||
|
@ -17,7 +16,7 @@
|
|||
// Create a new PNG image to use as the fallback.
|
||||
img = document.createElement('img');
|
||||
url = this.style.backgroundImage.match(/url\('?([^']*)'?\)/)[1];
|
||||
img.setAttribute( 'src', url.replace('mode=' + MW_MATH_MATHML, 'mode=' + MW_MATH_PNG) );
|
||||
img.setAttribute( 'src', url.replace('mode=' + 'mathml', 'mode=' + 'png') );
|
||||
img.setAttribute( 'class', 'tex mwe-math-fallback-image-' + ($( this ).hasClass('mwe-math-fallback-image-inline') ? 'inline' : 'display') );
|
||||
img.setAttribute( 'aria-hidden', 'true' );
|
||||
this.parentNode.insertBefore( img, this );
|
||||
|
|
|
@ -70,7 +70,7 @@ class MathCoverageTest extends MediaWikiTestCase {
|
|||
// TODO: Link to the wikipage that contains the reference rendering
|
||||
$this->assertEquals(
|
||||
$this->normalize( $output ),
|
||||
$this->normalize( MathRenderer::renderMath( $input, array(), MW_MATH_PNG ) ),
|
||||
$this->normalize( MathRenderer::renderMath( $input, array(), 'png' ) ),
|
||||
"Failed to render $input"
|
||||
);
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class MathDatabaseTest extends MediaWikiTestCase {
|
|||
* @covers MathHooks::onLoadExtensionSchemaUpdates
|
||||
*/
|
||||
public function testCreateTable() {
|
||||
$this->setMwGlobals( 'wgMathValidModes', array( MW_MATH_PNG ) );
|
||||
$this->setMwGlobals( 'wgMathValidModes', array( 'png' ) );
|
||||
$this->db->dropTable( "math", __METHOD__ );
|
||||
$dbu = DatabaseUpdater::newForDB( $this->db );
|
||||
$dbu->doUpdates( array( "extensions" ) );
|
||||
|
|
|
@ -77,7 +77,7 @@ class MathLaTeXMLDatabaseTest extends MediaWikiTestCase {
|
|||
* @covers MathHooks::onLoadExtensionSchemaUpdates
|
||||
*/
|
||||
public function testCreateTable() {
|
||||
$this->setMwGlobals( 'wgMathValidModes', array( MW_MATH_LATEXML ) );
|
||||
$this->setMwGlobals( 'wgMathValidModes', array( 'latexml' ) );
|
||||
$this->db->dropTable( "mathlatexml", __METHOD__ );
|
||||
$dbu = DatabaseUpdater::newForDB( $this->db );
|
||||
$dbu->doUpdates( array( "extensions" ) );
|
||||
|
|
|
@ -65,7 +65,7 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
public function testCheckingAlways() {
|
||||
$this->setMwGlobals( "wgMathDisableTexFilter", MW_MATH_CHECK_ALWAYS );
|
||||
$this->setMwGlobals( "wgMathDisableTexFilter", 'always' );
|
||||
$renderer =
|
||||
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
|
||||
'render',
|
||||
|
@ -84,7 +84,7 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
public function testCheckingNever() {
|
||||
$this->setMwGlobals( "wgMathDisableTexFilter", MW_MATH_CHECK_NEVER );
|
||||
$this->setMwGlobals( "wgMathDisableTexFilter", 'never' );
|
||||
$renderer =
|
||||
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
|
||||
'render',
|
||||
|
@ -100,7 +100,7 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
public function testCheckingNewUnknown() {
|
||||
$this->setMwGlobals( "wgMathDisableTexFilter", MW_MATH_CHECK_NEW );
|
||||
$this->setMwGlobals( "wgMathDisableTexFilter", 'new' );
|
||||
$renderer =
|
||||
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
|
||||
'render',
|
||||
|
@ -119,7 +119,7 @@ class MathRendererTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
public function testCheckingNewKnown() {
|
||||
$this->setMwGlobals( "wgMathDisableTexFilter", MW_MATH_CHECK_NEW );
|
||||
$this->setMwGlobals( "wgMathDisableTexFilter", 'new' );
|
||||
$renderer =
|
||||
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
|
||||
'render',
|
||||
|
|
|
@ -10,7 +10,7 @@ class MathSourceTest extends MediaWikiTestCase {
|
|||
* i.e. if the span element is generated right.
|
||||
*/
|
||||
public function testBasics() {
|
||||
$real = MathRenderer::renderMath( "a+b", array(), MW_MATH_SOURCE );
|
||||
$real = MathRenderer::renderMath( "a+b", array(), 'source' );
|
||||
$this->assertEquals(
|
||||
'<span class="mwe-math-fallback-source-inline tex" dir="ltr">$ a+b $</span>',
|
||||
$real,
|
||||
|
@ -22,7 +22,7 @@ class MathSourceTest extends MediaWikiTestCase {
|
|||
* Checks if newlines are converted to spaces correctly.
|
||||
*/
|
||||
public function testNewLines() {
|
||||
$real = MathRenderer::renderMath( "a\n b", array(), MW_MATH_SOURCE );
|
||||
$real = MathRenderer::renderMath( "a\n b", array(), 'source' );
|
||||
$this->assertSame(
|
||||
'<span class="mwe-math-fallback-source-inline tex" dir="ltr">$ a b $</span>',
|
||||
$real,
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
/**
|
||||
* Test Math utility functions.
|
||||
*
|
||||
* @group Math
|
||||
*/
|
||||
class MathUtilsTest extends MediaWikiTestCase {
|
||||
|
||||
public function testMathModeToString() {
|
||||
$default = 'png-testing'; // use a different string for testing only
|
||||
$testCases = array(
|
||||
'MW_MATH_SIMPLE' => $default,
|
||||
'MW_MATH_HTML' => $default,
|
||||
'MW_MATH_MODERN' => $default,
|
||||
'MW_MATH_MATHJAX' => $default,
|
||||
'MW_MATH_LATEXML_JAX' => $default,
|
||||
'MW_MATH_PNG' => 'png',
|
||||
'MW_MATH_SOURCE' => 'source',
|
||||
'MW_MATH_MATHML' => 'mathml',
|
||||
'MW_MATH_LATEXML' => 'latexml',
|
||||
1 => $default,
|
||||
2 => $default,
|
||||
4 => $default,
|
||||
6 => $default,
|
||||
8 => $default,
|
||||
0 => 'png',
|
||||
3 => 'source',
|
||||
5 => 'mathml',
|
||||
7 => 'latexml',
|
||||
'png' => 'png',
|
||||
'source' => 'source',
|
||||
'mathml' => 'mathml',
|
||||
'latexml' => 'latexml',
|
||||
);
|
||||
foreach ( $testCases as $input => $expected ){
|
||||
$real = MathHooks::mathModeToString( $input, $default );
|
||||
$this->assertEquals( $expected, $real, "Conversion math mode $input -> $expected" );
|
||||
}
|
||||
}
|
||||
|
||||
public function testMathStyleToString() {
|
||||
$default = 'inlineDisplaystyle-test';
|
||||
$testCases = array(
|
||||
'MW_MATHSTYLE_INLINE_DISPLAYSTYLE' => 'inlineDisplaystyle',
|
||||
'MW_MATHSTYLE_DISPLAY' => 'display',
|
||||
'MW_MATHSTYLE_INLINE' => 'inline',
|
||||
0 => 'inlineDisplaystyle',
|
||||
1 => 'display',
|
||||
2 => 'inline',
|
||||
'inlineDisplaystyle' => 'inlineDisplaystyle',
|
||||
'display' => 'display',
|
||||
'inline' => 'inline',
|
||||
);
|
||||
foreach ( $testCases as $input => $expected ){
|
||||
$real = MathHooks::mathStyleToString( $input, $default );
|
||||
$this->assertEquals( $expected, $real, "Conversion in math style" );
|
||||
}
|
||||
}
|
||||
|
||||
public function testMathCheckToString() {
|
||||
$default = 'always-default';
|
||||
$testCases = array(
|
||||
'MW_MATH_CHECK_ALWAYS' => 'always',
|
||||
'MW_MATH_CHECK_NEVER' => 'never',
|
||||
'MW_MATH_CHECK_NEW' => 'new',
|
||||
0 => 'always',
|
||||
1 => 'never',
|
||||
2 => 'new',
|
||||
'always' => 'always',
|
||||
'never' => 'never',
|
||||
'new' => 'new',
|
||||
true => 'never',
|
||||
false => 'always'
|
||||
);
|
||||
|
||||
foreach ( $testCases as $input => $expected ){
|
||||
$real = MathHooks::mathCheckToString( $input, $default );
|
||||
$this->assertEquals( $expected, $real, "Conversion in math check method" );
|
||||
}
|
||||
}
|
||||
|
||||
public function testMathModeToHash() {
|
||||
$default = 0;
|
||||
$testCases = array (
|
||||
'png' => 0,
|
||||
'source' => 3,
|
||||
'mathml' => 5,
|
||||
'latexml'=> 7,
|
||||
'invalid'=> $default);
|
||||
|
||||
foreach ( $testCases as $input => $expected ){
|
||||
$real = MathHooks::mathModeToHashKey( $input, $default );
|
||||
$this->assertEquals( $expected, $real, "Conversion to hash key" );
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetMathNames() {
|
||||
$real = MathHooks::getMathNames();
|
||||
$this->assertEquals( 'PNG images', $real['png'] );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue