mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-12 01:08:55 +00:00
Merge "Minor clean up, optimisations and documentation corrections"
This commit is contained in:
commit
8477bdb059
|
@ -224,32 +224,32 @@ class MathHooks {
|
|||
|
||||
$type = $updater->getDB()->getType();
|
||||
|
||||
if ( in_array( $type, $map ) ) {
|
||||
$sql = dirname( __FILE__ ) . '/db/math.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'math', $sql );
|
||||
if ( in_array( MW_MATH_LATEXML, $wgMathValidModes ) ) {
|
||||
if ( in_array( $type, array( 'mysql', 'sqlite', 'postgres' ) ) ) {
|
||||
$sql = dirname( __FILE__ ) . '/db/mathlatexml.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'mathlatexml', $sql );
|
||||
if ( $type == 'mysql' ){
|
||||
$sql = dirname( __FILE__ ) . '/db/patches/mathlatexml.mathml-length-adjustment.mysql.sql';
|
||||
$updater->modifyExtensionField( 'mathlatexml', 'math_mathml', $sql );
|
||||
}
|
||||
} else {
|
||||
throw new Exception( "Math extension does not currently support $type database for LaTeXML." );
|
||||
}
|
||||
}
|
||||
if ( in_array( MW_MATH_MATHML, $wgMathValidModes ) ) {
|
||||
if ( in_array( $type, array( 'mysql', 'sqlite', 'postgres' ) ) ) {
|
||||
$sql = dirname( __FILE__ ) . '/db/mathoid.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'mathoid', $sql );
|
||||
} else {
|
||||
throw new Exception( "Math extension does not currently support $type database for Mathoid." );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( !in_array( $type, $map ) ) {
|
||||
throw new Exception( "Math extension does not currently support $type database." );
|
||||
}
|
||||
$sql = __DIR__ . '/db/math.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'math', $sql );
|
||||
if ( in_array( MW_MATH_LATEXML, $wgMathValidModes ) ) {
|
||||
if ( in_array( $type, array( 'mysql', 'sqlite', 'postgres' ) ) ) {
|
||||
$sql = __DIR__ . '/db/mathlatexml.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'mathlatexml', $sql );
|
||||
if ( $type == 'mysql' ){
|
||||
$sql = __DIR__ . '/db/patches/mathlatexml.mathml-length-adjustment.mysql.sql';
|
||||
$updater->modifyExtensionField( 'mathlatexml', 'math_mathml', $sql );
|
||||
}
|
||||
} else {
|
||||
throw new Exception( "Math extension does not currently support $type database for LaTeXML." );
|
||||
}
|
||||
}
|
||||
if ( in_array( MW_MATH_MATHML, $wgMathValidModes ) ) {
|
||||
if ( in_array( $type, array( 'mysql', 'sqlite', 'postgres' ) ) ) {
|
||||
$sql = __DIR__ . '/db/mathoid.' . $type . '.sql';
|
||||
$updater->addExtensionTable( 'mathoid', $sql );
|
||||
} else {
|
||||
throw new Exception( "Math extension does not currently support $type database for Mathoid." );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
7
Math.php
7
Math.php
|
@ -118,8 +118,11 @@ $wgMathDirectory = false;
|
|||
|
||||
/**
|
||||
* The url of the mathoid server.
|
||||
* see http://www.formulasearchengine.com/mathoid
|
||||
* TODO: Move documentation to WMF
|
||||
*
|
||||
* 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';
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class MathMathML extends MathRenderer {
|
|||
protected $defaultAllowedRootElements = array( 'math' );
|
||||
protected $allowedRootElements = '';
|
||||
protected $hosts;
|
||||
|
||||
/** @var boolean if false MathML output is not validated */
|
||||
private $XMLValidation = true;
|
||||
protected $inputType = 'tex';
|
||||
|
@ -20,16 +21,14 @@ class MathMathML extends MathRenderer {
|
|||
/**
|
||||
* @param string $inputType
|
||||
*/
|
||||
public function setInputType($inputType)
|
||||
{
|
||||
public function setInputType($inputType) {
|
||||
$this->inputType = $inputType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getInputType()
|
||||
{
|
||||
public function getInputType() {
|
||||
return $this->inputType;
|
||||
}
|
||||
|
||||
|
@ -101,26 +100,26 @@ class MathMathML extends MathRenderer {
|
|||
*/
|
||||
private function renderingRequired() {
|
||||
if ( $this->isPurge() ) {
|
||||
wfDebugLog( "Math", "Rerendering was requested." );
|
||||
wfDebugLog( 'Math', 'Rerendering was requested.' );
|
||||
return true;
|
||||
} else {
|
||||
$dbres = $this->isInDatabase();
|
||||
if ( $dbres ) {
|
||||
if ( $this->isValidMathML( $this->getMathml() ) ) {
|
||||
wfDebugLog( "Math", "Valid MathML entry found in database." );
|
||||
wfDebugLog( 'Math', 'Valid MathML entry found in database.' );
|
||||
if ( $this->getSvg() ) {
|
||||
wfDebugLog( "Math", "SVG-fallback found in database." );
|
||||
wfDebugLog( 'Math', 'SVG-fallback found in database.' );
|
||||
return false;
|
||||
} else {
|
||||
wfDebugLog( "Math", "SVG-fallback missing." );
|
||||
wfDebugLog( 'Math', 'SVG-fallback missing.' );
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
wfDebugLog( "Math", "Malformatted entry found in database" );
|
||||
wfDebugLog( 'Math', 'Malformatted entry found in database' );
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
wfDebugLog( "Math", "No entry found in database." );
|
||||
wfDebugLog( 'Math', 'No entry found in database.' );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -166,14 +165,14 @@ class MathMathML extends MathRenderer {
|
|||
if ( $status->hasMessage( 'http-timed-out' ) ) {
|
||||
$error = $this->getError( 'math_timeout', $this->getModeStr(), $host );
|
||||
$res = false;
|
||||
wfDebugLog( "Math", "\nTimeout:"
|
||||
wfDebugLog( 'Math', "\nTimeout:"
|
||||
. var_export( array( 'post' => $post, 'host' => $host
|
||||
, 'timeout' => $wgMathLaTeXMLTimeout ), true ) . "\n\n" );
|
||||
} else {
|
||||
// for any other unkonwn http error
|
||||
$errormsg = $status->getHtml();
|
||||
$error = $this->getError( 'math_invalidresponse', $this->getModeStr(), $host, $errormsg, $this->getModeStr( MW_MATH_MATHML ) );
|
||||
wfDebugLog( "Math", "\nNoResponse:"
|
||||
wfDebugLog( 'Math', "\nNoResponse:"
|
||||
. var_export( array( 'post' => $post, 'host' => $host
|
||||
, 'errormsg' => $errormsg ), true ) . "\n\n" );
|
||||
}
|
||||
|
@ -183,9 +182,10 @@ class MathMathML extends MathRenderer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Picks a MathML daemon.
|
||||
* If more than one demon are available one is chosen from the
|
||||
* $wgMathMathMLUrl array.
|
||||
* Return a MathML daemon host.
|
||||
*
|
||||
* If more than one demon is available, one is chosen at random.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function pickHost() {
|
||||
|
@ -194,7 +194,7 @@ class MathMathML extends MathRenderer {
|
|||
} else {
|
||||
$host = $this->hosts;
|
||||
}
|
||||
wfDebugLog( "Math", "picking host " . $host );
|
||||
wfDebugLog( 'Math', 'picking host ' . $host );
|
||||
return $host;
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,7 @@ class MathMathML extends MathRenderer {
|
|||
$out = 'type=tex&q=' . rawurlencode( $input );
|
||||
}
|
||||
}
|
||||
wfDebugLog( "Math", 'Get post data: ' . $out );
|
||||
wfDebugLog( 'Math', 'Get post data: ' . $out );
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ class MathMathML extends MathRenderer {
|
|||
$log = wfMessage( 'math_unknown_error' )->inContentLanguage()->escaped();
|
||||
}
|
||||
$this->lastError = $this->getError( 'math_mathoid_error', $host, $log );
|
||||
wfDebugLog( 'Math', "Mathoid conversion error:"
|
||||
wfDebugLog( 'Math', 'Mathoid conversion error:'
|
||||
. var_export( array( 'post' => $post, 'host' => $host
|
||||
, 'result' => $res ), true ) . "\n\n" );
|
||||
return false;
|
||||
|
@ -307,7 +307,7 @@ class MathMathML extends MathRenderer {
|
|||
}
|
||||
$xmlObject = new XmlTypeCheck( $XML, null, false );
|
||||
if ( !$xmlObject->wellFormed ) {
|
||||
wfDebugLog( "Math", "XML validation error:\n " . var_export( $XML, true ) . "\n" );
|
||||
wfDebugLog( 'Math', "XML validation error:\n " . var_export( $XML, true ) . "\n" );
|
||||
} else {
|
||||
$name = $xmlObject->getRootElement();
|
||||
$elementSplit = explode( ':', $name );
|
||||
|
@ -319,7 +319,7 @@ class MathMathML extends MathRenderer {
|
|||
if ( in_array( $localName , $this->getAllowedRootElements() ) ) {
|
||||
$out = true;
|
||||
} else {
|
||||
wfDebugLog( "Math", "got wrong root element : $name" );
|
||||
wfDebugLog( 'Math', "got wrong root element : $name" );
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
|
@ -345,7 +345,7 @@ class MathMathML extends MathRenderer {
|
|||
*/
|
||||
public function correctSvgStyle( $svg, &$style ) {
|
||||
if ( preg_match( '/style="([^"]*)"/', $svg, $styles ) ) {
|
||||
$style .= " ".$styles[1]; // merge styles
|
||||
$style .= ' ' . $styles[1]; // merge styles
|
||||
if ( $this->getMathStyle() === MW_MATHSTYLE_DISPLAY ) {
|
||||
// TODO: Improve style cleaning
|
||||
$style = preg_replace( '/margin\-(left|right)\:\s*\d+(\%|in|cm|mm|em|ex|pt|pc|px)\;/', '', $style );
|
||||
|
@ -356,10 +356,10 @@ class MathMathML extends MathRenderer {
|
|||
// a SVGReader from a string that represents the SVG
|
||||
// content
|
||||
if ( preg_match( "/height=\"(.*?)\"/" , $this->getSvg(), $matches ) ) {
|
||||
$style .= "height: " . $matches[1] . "; ";
|
||||
$style .= 'height: ' . $matches[1] . '; ';
|
||||
}
|
||||
if ( preg_match( "/width=\"(.*?)\"/", $this->getSvg(), $matches ) ) {
|
||||
$style .= "width: " . $matches[1] . ";";
|
||||
$style .= 'width: ' . $matches[1] . ';';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -399,7 +399,7 @@ class MathMathML extends MathRenderer {
|
|||
* @return string the class name
|
||||
*/
|
||||
private function getClassName( $fallback = false ) {
|
||||
$class = "mwe-math-";
|
||||
$class = 'mwe-math-';
|
||||
if ( $fallback ) {
|
||||
$class .= 'fallback-image-';
|
||||
} else {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
* @ingroup Maintenance
|
||||
*/
|
||||
|
||||
require_once( dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' );
|
||||
require_once __DIR__ . '/../../../maintenance/Maintenance.php';
|
||||
|
||||
class MathGenerateTests extends Maintenance
|
||||
{
|
||||
|
@ -85,9 +85,9 @@ class MathGenerateTests extends Maintenance
|
|||
echo '.';
|
||||
}
|
||||
echo "Generated $i tests\n";
|
||||
file_put_contents( dirname( __FILE__ ) . '/../tests/ParserTest.json', json_encode( $parserTests, JSON_PRETTY_PRINT ) );
|
||||
file_put_contents( __DIR__ . '/../tests/ParserTest.json', json_encode( $parserTests, JSON_PRETTY_PRINT ) );
|
||||
}
|
||||
}
|
||||
|
||||
$maintClass = "MathGenerateTests";
|
||||
require_once( RUN_MAINTENANCE_IF_MAIN );
|
||||
$maintClass = 'MathGenerateTests';
|
||||
require_once RUN_MAINTENANCE_IF_MAIN;
|
||||
|
|
|
@ -79,9 +79,8 @@ class MathCoverageTest extends MediaWikiTestCase {
|
|||
* Gets the test-data from the file ParserTest.json
|
||||
* @return array($input, $output) where $input is the test input string and $output is the rendered html5-output string
|
||||
*/
|
||||
public function testProvider()
|
||||
{
|
||||
return json_decode( file_get_contents( dirname( __FILE__ ) . '/ParserTest.json' ) );
|
||||
public function testProvider() {
|
||||
return json_decode( file_get_contents( __DIR__ . '/ParserTest.json' ) );
|
||||
}
|
||||
|
||||
private function normalize( $input ) {
|
||||
|
|
Loading…
Reference in a new issue