Merge "Add separate database table for LaTeXML (step 3)"

This commit is contained in:
Frédéric Wang 2014-05-27 15:49:42 +00:00 committed by Gerrit Code Review
commit 423d80ef35
5 changed files with 32 additions and 14 deletions

View file

@ -192,7 +192,7 @@ class MathLaTeXML extends MathRenderer {
/**
* Picks a LaTeXML daemon.
* If more than one demon are availible one is chosen from the
* If more than one daemon are available one is chosen from the
* $wgMathLaTeXMLUrl array.
* @return string
*/
@ -252,7 +252,7 @@ class MathLaTeXML extends MathRenderer {
// mess up the browser output.
$this->lastError = $this->getError( 'math_latexml_invalidxml', $host );
wfDebugLog( "Math", "\nLaTeXML InvalidMathML:"
. var_export( array( 'post' => $post, 'host' => $host
. var_export( array( 'post' => $post, 'host' => $host
, 'result' => $result ), true ) . "\n\n" );
wfProfileOut( __METHOD__ );
return false;
@ -261,7 +261,7 @@ class MathLaTeXML extends MathRenderer {
$this->lastError = $this->getError( 'math_latexml_invalidjson', $host );
wfDebugLog( "Math", "\nLaTeXML InvalidJSON:"
. var_export( array( 'post' => $post, 'host' => $host
, 'res' => $res ), true ) . "\n\n" );
, 'res' => $res ), true ) . "\n\n" );
wfProfileOut( __METHOD__ );
return false;
}
@ -347,4 +347,8 @@ class MathLaTeXML extends MathRenderer {
return Xml::tags( 'span', $attribs, $mml );
}
protected function getMathTableName() {
return 'mathlatexml';
}
}

View file

@ -182,8 +182,8 @@ abstract class MathRenderer {
wfDebugLog( 'Math', $msg );
// If we can not check if mathml output is valid, we skip the test and assume that it is valid.
$this->recall = true;
wfProfileOut( __METHOD__ );
return true;
wfProfileOut( __METHOD__ );
return true;
} elseif ( StringUtils::isUtf8( $this->mathml ) ) {
$this->recall = true;
wfProfileOut( __METHOD__ );
@ -191,7 +191,7 @@ abstract class MathRenderer {
}
}
# Missing from the database and/or the render cache
# Missing from the database and/or the render cache
$this->recall = false;
wfProfileOut( __METHOD__ );
return false;
@ -234,9 +234,9 @@ abstract class MathRenderer {
wfDebugLog( "Math", 'store entry for $' . $this->tex . '$ in database (hash:' . bin2hex( $this->hash ) . ")\n" );
$outArray = $this->dbOutArray();
$dbw->onTransactionIdle(
function() use( $dbw, $outArray ) {
$dbw->replace( 'math', array( 'math_inputhash' ), $outArray, __METHOD__ );
} );
function() use( $dbw, $outArray ) {
$dbw->replace( 'math', array( 'math_inputhash' ), $outArray, __METHOD__ );
} );
}
}
@ -496,5 +496,12 @@ abstract class MathRenderer {
public function getUserInputTex() {
return $this->userInputTex;
}
}
protected abstract function getMathTableName();
public function getModeStr() {
$names = MathHooks::getMathNames();
return $names[ $this->getMode() ];
}
}

View file

@ -46,4 +46,7 @@ class MathSource extends MathRenderer {
);
}
protected function getMathTableName() {
throw new MWException ( 'in math source mode no database caching should happen');
}
}

View file

@ -360,4 +360,8 @@ class MathTexvc extends MathRenderer {
return false;
}
protected function getMathTableName() {
return 'math';
}
}

View file

@ -26,7 +26,7 @@ class MathRendererTest extends MediaWikiTestCase {
*/
public function testWriteCacheSkip() {
$renderer = $this->getMockBuilder( 'MathRenderer' )
->setMethods( array( 'writeToDatabase' , 'render' ) )
->setMethods( array( 'writeToDatabase' , 'render', 'getMathTableName' ) )
->disableOriginalConstructor()
->getMock();
$renderer->expects( $this->never() )
@ -40,7 +40,7 @@ class MathRendererTest extends MediaWikiTestCase {
*/
public function testWriteCache() {
$renderer = $this->getMockBuilder( 'MathRenderer' )
->setMethods( array( 'writeToDatabase' , 'render' ) )
->setMethods( array( 'writeToDatabase' , 'render', 'getMathTableName' ) )
->disableOriginalConstructor()
->getMock();
$renderer->expects( $this->never() )
@ -54,7 +54,7 @@ class MathRendererTest extends MediaWikiTestCase {
*/
public function testChangeHash() {
$renderer = $this->getMockBuilder( 'MathRenderer' )
->setMethods( array( 'render' ) )
->setMethods( array( 'render', 'getMathTableName' ) )
->disableOriginalConstructor()
->getMock();
$this->assertEquals(
@ -71,7 +71,7 @@ class MathRendererTest extends MediaWikiTestCase {
public function testSetPurge() {
$renderer = $this->getMockBuilder( 'MathRenderer' )
->setMethods( array( 'render' ) )
->setMethods( array( 'render', 'getMathTableName' ) )
->disableOriginalConstructor()
->getMock();
$renderer->setPurge();