Add separate database table for LaTeXML (step 3)

Currently the PNG and the LaTeXML rendering mode
use a common table in the database. If both rendering
modes are allowed in a wiki simultaneously this causes
problems, because the fields are continuously overwritten.

This change adds the method getMathTableName that will
allow renderers to access their specific table in the
database.

Change-Id: I8b11ffd0a39fadd7d3c8de1e94e74ff5f490430d
This commit is contained in:
physikerwelt 2014-05-27 04:46:53 +00:00
parent 1de09cd270
commit bf33d51320
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();