Merge "Minor clean up, optimisations and documentation corrections"

This commit is contained in:
jenkins-bot 2015-01-22 19:39:56 +00:00 committed by Gerrit Code Review
commit 8477bdb059
5 changed files with 59 additions and 57 deletions

View File

@ -224,32 +224,32 @@ class MathHooks {
$type = $updater->getDB()->getType(); $type = $updater->getDB()->getType();
if ( in_array( $type, $map ) ) { 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 {
throw new Exception( "Math extension does not currently support $type database." ); 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; return true;
} }

View File

@ -118,8 +118,11 @@ $wgMathDirectory = false;
/** /**
* The url of the mathoid server. * 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'; $wgMathMathMLUrl = 'http://mathoid.testme.wmflabs.org';

View File

@ -13,6 +13,7 @@ class MathMathML extends MathRenderer {
protected $defaultAllowedRootElements = array( 'math' ); protected $defaultAllowedRootElements = array( 'math' );
protected $allowedRootElements = ''; protected $allowedRootElements = '';
protected $hosts; protected $hosts;
/** @var boolean if false MathML output is not validated */ /** @var boolean if false MathML output is not validated */
private $XMLValidation = true; private $XMLValidation = true;
protected $inputType = 'tex'; protected $inputType = 'tex';
@ -20,16 +21,14 @@ class MathMathML extends MathRenderer {
/** /**
* @param string $inputType * @param string $inputType
*/ */
public function setInputType($inputType) public function setInputType($inputType) {
{
$this->inputType = $inputType; $this->inputType = $inputType;
} }
/** /**
* @return string * @return string
*/ */
public function getInputType() public function getInputType() {
{
return $this->inputType; return $this->inputType;
} }
@ -101,26 +100,26 @@ class MathMathML extends MathRenderer {
*/ */
private function renderingRequired() { private function renderingRequired() {
if ( $this->isPurge() ) { if ( $this->isPurge() ) {
wfDebugLog( "Math", "Rerendering was requested." ); wfDebugLog( 'Math', 'Rerendering was requested.' );
return true; return true;
} else { } else {
$dbres = $this->isInDatabase(); $dbres = $this->isInDatabase();
if ( $dbres ) { if ( $dbres ) {
if ( $this->isValidMathML( $this->getMathml() ) ) { if ( $this->isValidMathML( $this->getMathml() ) ) {
wfDebugLog( "Math", "Valid MathML entry found in database." ); wfDebugLog( 'Math', 'Valid MathML entry found in database.' );
if ( $this->getSvg() ) { if ( $this->getSvg() ) {
wfDebugLog( "Math", "SVG-fallback found in database." ); wfDebugLog( 'Math', 'SVG-fallback found in database.' );
return false; return false;
} else { } else {
wfDebugLog( "Math", "SVG-fallback missing." ); wfDebugLog( 'Math', 'SVG-fallback missing.' );
return true; return true;
} }
} else { } else {
wfDebugLog( "Math", "Malformatted entry found in database" ); wfDebugLog( 'Math', 'Malformatted entry found in database' );
return true; return true;
} }
} else { } else {
wfDebugLog( "Math", "No entry found in database." ); wfDebugLog( 'Math', 'No entry found in database.' );
return true; return true;
} }
} }
@ -166,14 +165,14 @@ class MathMathML extends MathRenderer {
if ( $status->hasMessage( 'http-timed-out' ) ) { if ( $status->hasMessage( 'http-timed-out' ) ) {
$error = $this->getError( 'math_timeout', $this->getModeStr(), $host ); $error = $this->getError( 'math_timeout', $this->getModeStr(), $host );
$res = false; $res = false;
wfDebugLog( "Math", "\nTimeout:" wfDebugLog( 'Math', "\nTimeout:"
. var_export( array( 'post' => $post, 'host' => $host . var_export( array( 'post' => $post, 'host' => $host
, 'timeout' => $wgMathLaTeXMLTimeout ), true ) . "\n\n" ); , 'timeout' => $wgMathLaTeXMLTimeout ), true ) . "\n\n" );
} else { } else {
// for any other unkonwn http error // for any other unkonwn http error
$errormsg = $status->getHtml(); $errormsg = $status->getHtml();
$error = $this->getError( 'math_invalidresponse', $this->getModeStr(), $host, $errormsg, $this->getModeStr( MW_MATH_MATHML ) ); $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 . var_export( array( 'post' => $post, 'host' => $host
, 'errormsg' => $errormsg ), true ) . "\n\n" ); , 'errormsg' => $errormsg ), true ) . "\n\n" );
} }
@ -183,9 +182,10 @@ class MathMathML extends MathRenderer {
} }
/** /**
* Picks a MathML daemon. * Return a MathML daemon host.
* If more than one demon are available one is chosen from the *
* $wgMathMathMLUrl array. * If more than one demon is available, one is chosen at random.
*
* @return string * @return string
*/ */
protected function pickHost() { protected function pickHost() {
@ -194,7 +194,7 @@ class MathMathML extends MathRenderer {
} else { } else {
$host = $this->hosts; $host = $this->hosts;
} }
wfDebugLog( "Math", "picking host " . $host ); wfDebugLog( 'Math', 'picking host ' . $host );
return $host; return $host;
} }
@ -217,7 +217,7 @@ class MathMathML extends MathRenderer {
$out = 'type=tex&q=' . rawurlencode( $input ); $out = 'type=tex&q=' . rawurlencode( $input );
} }
} }
wfDebugLog( "Math", 'Get post data: ' . $out ); wfDebugLog( 'Math', 'Get post data: ' . $out );
return $out; return $out;
} }
@ -269,7 +269,7 @@ class MathMathML extends MathRenderer {
$log = wfMessage( 'math_unknown_error' )->inContentLanguage()->escaped(); $log = wfMessage( 'math_unknown_error' )->inContentLanguage()->escaped();
} }
$this->lastError = $this->getError( 'math_mathoid_error', $host, $log ); $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 . var_export( array( 'post' => $post, 'host' => $host
, 'result' => $res ), true ) . "\n\n" ); , 'result' => $res ), true ) . "\n\n" );
return false; return false;
@ -307,7 +307,7 @@ class MathMathML extends MathRenderer {
} }
$xmlObject = new XmlTypeCheck( $XML, null, false ); $xmlObject = new XmlTypeCheck( $XML, null, false );
if ( !$xmlObject->wellFormed ) { 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 { } else {
$name = $xmlObject->getRootElement(); $name = $xmlObject->getRootElement();
$elementSplit = explode( ':', $name ); $elementSplit = explode( ':', $name );
@ -319,7 +319,7 @@ class MathMathML extends MathRenderer {
if ( in_array( $localName , $this->getAllowedRootElements() ) ) { if ( in_array( $localName , $this->getAllowedRootElements() ) ) {
$out = true; $out = true;
} else { } else {
wfDebugLog( "Math", "got wrong root element : $name" ); wfDebugLog( 'Math', "got wrong root element : $name" );
} }
} }
return $out; return $out;
@ -345,7 +345,7 @@ class MathMathML extends MathRenderer {
*/ */
public function correctSvgStyle( $svg, &$style ) { public function correctSvgStyle( $svg, &$style ) {
if ( preg_match( '/style="([^"]*)"/', $svg, $styles ) ) { if ( preg_match( '/style="([^"]*)"/', $svg, $styles ) ) {
$style .= " ".$styles[1]; // merge styles $style .= ' ' . $styles[1]; // merge styles
if ( $this->getMathStyle() === MW_MATHSTYLE_DISPLAY ) { if ( $this->getMathStyle() === MW_MATHSTYLE_DISPLAY ) {
// TODO: Improve style cleaning // TODO: Improve style cleaning
$style = preg_replace( '/margin\-(left|right)\:\s*\d+(\%|in|cm|mm|em|ex|pt|pc|px)\;/', '', $style ); $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 // a SVGReader from a string that represents the SVG
// content // content
if ( preg_match( "/height=\"(.*?)\"/" , $this->getSvg(), $matches ) ) { if ( preg_match( "/height=\"(.*?)\"/" , $this->getSvg(), $matches ) ) {
$style .= "height: " . $matches[1] . "; "; $style .= 'height: ' . $matches[1] . '; ';
} }
if ( preg_match( "/width=\"(.*?)\"/", $this->getSvg(), $matches ) ) { 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 * @return string the class name
*/ */
private function getClassName( $fallback = false ) { private function getClassName( $fallback = false ) {
$class = "mwe-math-"; $class = 'mwe-math-';
if ( $fallback ) { if ( $fallback ) {
$class .= 'fallback-image-'; $class .= 'fallback-image-';
} else { } else {

View File

@ -19,7 +19,7 @@
* @ingroup Maintenance * @ingroup Maintenance
*/ */
require_once( dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' ); require_once __DIR__ . '/../../../maintenance/Maintenance.php';
class MathGenerateTests extends Maintenance class MathGenerateTests extends Maintenance
{ {
@ -85,9 +85,9 @@ class MathGenerateTests extends Maintenance
echo '.'; echo '.';
} }
echo "Generated $i tests\n"; 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"; $maintClass = 'MathGenerateTests';
require_once( RUN_MAINTENANCE_IF_MAIN ); require_once RUN_MAINTENANCE_IF_MAIN;

View File

@ -79,9 +79,8 @@ class MathCoverageTest extends MediaWikiTestCase {
* Gets the test-data from the file ParserTest.json * 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 * @return array($input, $output) where $input is the test input string and $output is the rendered html5-output string
*/ */
public function testProvider() public function testProvider() {
{ return json_decode( file_get_contents( __DIR__ . '/ParserTest.json' ) );
return json_decode( file_get_contents( dirname( __FILE__ ) . '/ParserTest.json' ) );
} }
private function normalize( $input ) { private function normalize( $input ) {