Merge "Improve Math test generation"

This commit is contained in:
jenkins-bot 2015-01-22 10:10:30 +00:00 committed by Gerrit Code Review
commit 6e119fdb9a

View file

@ -36,8 +36,7 @@ class MathGenerateTests extends Maintenance
} }
private static function getMathTagsFromPage( $titleString ) private static function getMathTagsFromPage( $titleString ) {
{
global $wgEnableScaryTranscluding; global $wgEnableScaryTranscluding;
$title = Title::newFromText( $titleString ); $title = Title::newFromText( $titleString );
if ( $title->exists() ) { if ( $title->exists() ) {
@ -52,15 +51,12 @@ class MathGenerateTests extends Maintenance
return 'Page does not exist'; return 'Page does not exist';
} }
} }
// TODO: find a better way to extract math elements from a page
$wikiText = Sanitizer::removeHTMLcomments( $wikiText ); $wikiText = Sanitizer::removeHTMLcomments( $wikiText );
$wikiText = preg_replace( '#<nowiki>(.*)</nowiki>#', '', $wikiText ); $wikiText = preg_replace( '#<nowiki>(.*)</nowiki>#', '', $wikiText );
preg_match_all( "#<math>(.*?)</math>#s", $wikiText, $math ); $math = array();
// TODO: Find a way to specify a key e.g '\nRenderTest:(.?)#<math>(.*?)</math>#s\n' Parser::extractTagsAndParams( array( 'math' ), $wikiText, $math );
// leads to array('\1'->'\2') with \1 eg Bug 2345 and \2 the math content return $math;
return $math[1];
} }
public function execute() public function execute()
@ -82,9 +78,9 @@ class MathGenerateTests extends Maintenance
} }
$i = 0; $i = 0;
foreach ( array_slice( $allEquations, $offset, $length, true ) as $input ) { foreach ( array_slice( $allEquations, $offset, $length, true ) as $input ) {
$output = MathRenderer::renderMath( $input, array(), MW_MATH_PNG ); $output = MathRenderer::renderMath( $input[1], $input[2], MW_MATH_PNG );
$output = preg_replace( '#src="(.*?)/(([a-f]|\d)*).png"#', 'src="\2.png"', $output ); $output = preg_replace( '#src="(.*?)/(([a-f]|\d)*).png"#', 'src="\2.png"', $output );
$parserTests[] = array( (string)$input, $output ); $parserTests[] = array( (string)$input[1], $output );
$i++; $i++;
echo '.'; echo '.';
} }