mathConfig = $mathConfig;
$this->rendererFactory = $rendererFactory;
$this->logger = LoggerFactory::getInstance( 'Math' );
}
/**
* @param null|string $query
*/
public function execute( $query ) {
$this->setHeaders();
if ( !( $this->getUser()->isNamed() ) ) {
// This page is primarily of interest to developers.
// This action is comparable to previewing or parsing a small snippet of wikitext.
// If using RESTBase instead of native MML, this page makes HTTP requests to it.
// Optimization: Avoid uncached math parsing for logged-out users.
throw new UserNotLoggedIn();
}
$out = $this->getOutput();
$enabledMathModes = $this->mathConfig->getValidRenderingModeNames();
$req = $this->getRequest();
$tex = $req->getText( 'wptex' );
if ( $tex === '' ) {
$out->addWikiMsg( 'math-status-introduction', count( $enabledMathModes ) );
foreach ( $enabledMathModes as $modeNr => $modeName ) {
$out->wrapWikiMsg( '=== $1 ===', $modeName );
switch ( $modeNr ) {
case MathConfig::MODE_MATHML:
$this->runMathMLTest( $modeName );
break;
case MathConfig::MODE_LATEXML:
$this->runMathLaTeXMLTest( $modeName );
break;
case MathConfig::MODE_NATIVE_MML:
$this->runNativeTest( $modeName );
}
}
}
$form = new MathTestInputForm( $this, $enabledMathModes, $this->rendererFactory );
$form->show();
}
private function runNativeTest( string $modeName ) {
$this->getOutput()->addWikiMsgArray( 'math-test-start', [ $modeName ] );
$renderer = $this->rendererFactory->getRenderer( "a+b", [], MathConfig::MODE_NATIVE_MML );
if ( !$this->assertTrue( $renderer->render(), "Rendering of a+b in $modeName" ) ) {
return;
}
$real = str_replace( "\n", '', $renderer->getHtmlOutput() );
$expected = '+';
$this->assertContains( $expected, $real, "Checking the presence of '+' in the MathML output" );
$this->getOutput()->addWikiMsgArray( 'math-test-end', [ $modeName ] );
}
private function runMathMLTest( string $modeName ) {
$this->getOutput()->addWikiMsgArray( 'math-test-start', [ $modeName ] );
$this->testSpecialCaseText();
$this->testMathMLIntegration();
$this->testPmmlInput();
$this->getOutput()->addWikiMsgArray( 'math-test-end', [ $modeName ] );
}
private function runMathLaTeXMLTest( string $modeName ) {
$this->getOutput()->addWikiMsgArray( 'math-test-start', [ $modeName ] );
$this->testLaTeXMLIntegration();
$this->testLaTeXMLLinebreak();
$this->getOutput()->addWikiMsgArray( 'math-test-end', [ $modeName ] );
}
public function testSpecialCaseText() {
$renderer = $this->rendererFactory->getRenderer( 'x^2+\text{a sample Text}', [], MathConfig::MODE_MATHML );
$expected = 'a sample Text';
if ( !$this->assertTrue( $renderer->render(), 'Rendering the input "x^2+\text{a sample Text}"' ) ) {
return;
}
$this->assertContains(
$expected, $renderer->getHtmlOutput(), 'Comparing to the reference rendering'
);
}
/**
* Checks the basic functionality
* i.e. if the span element is generated right.
*/
public function testMathMLIntegration() {
$renderer = $this->rendererFactory->getRenderer( "a+b", [], MathConfig::MODE_MATHML );
if ( !$this->assertTrue( $renderer->render(), "Rendering of a+b in plain MathML mode" ) ) {
return;
}
$real = str_replace( "\n", '', $renderer->getHtmlOutput() );
$expected = '+';
$this->assertContains( $expected, $real, "Checking the presence of '+' in the MathML output" );
$this->assertContains(
'