Use i18n params for errors than appending raw string, with test
* Remove parameters/append that are never outputted by texvc.ml * Add missing math_output_error to i18n file * Improve a few qqq descriptions Change-Id: Iea5139682fbe8389e578549f5f62e5505f4c0b48
This commit is contained in:
parent
163ff0a019
commit
32e2f4d4f5
|
@ -26,13 +26,14 @@ $messages['en'] = array(
|
|||
// Math errors
|
||||
'math_failure' => 'Failed to parse',
|
||||
'math_unknown_error' => 'unknown error',
|
||||
'math_unknown_function' => 'unknown function',
|
||||
'math_unknown_function' => 'unknown function \'$1\'',
|
||||
'math_lexing_error' => 'lexing error',
|
||||
'math_syntax_error' => 'syntax error',
|
||||
'math_image_error' => 'PNG conversion failed; check for correct installation of latex and dvipng (or dvips + gs + convert)',
|
||||
'math_bad_tmpdir' => 'Cannot write to or create math temp directory',
|
||||
'math_bad_output' => 'Cannot write to or create math output directory',
|
||||
'math_notexvc' => 'Missing texvc executable; please see math/README to configure.',
|
||||
'math_output_error' => 'Cannot store math image on filesystem.',
|
||||
);
|
||||
|
||||
/** Message documentation (Message documentation)
|
||||
|
@ -79,17 +80,19 @@ This message is followed by "(", Error message(*1), Additional message, "): " a
|
|||
* {{msg-mw|Math bad output}}
|
||||
* {{msg-mw|Math notexvc}}
|
||||
* {{msg-mw|Math output error}}',
|
||||
'math_unknown_error' => 'Used as error message.
|
||||
'math_unknown_error' => 'Used as error message for unknown texvc error.
|
||||
|
||||
This message follows the message {{msg-mw|Math failure}}.
|
||||
{{Identical|Unknown error}}',
|
||||
'math_unknown_function' => 'Used as error message.
|
||||
'math_unknown_function' => 'Used as error message when texvc encounters an unknown function.
|
||||
|
||||
$1 - Name of unknown function
|
||||
|
||||
This message follows the message {{msg-mw|Math failure}}.',
|
||||
'math_lexing_error' => 'Used as error message.
|
||||
'math_lexing_error' => 'Used as error message for a texvc lexing error.
|
||||
|
||||
This message follows the message {{msg-mw|Math failure}}.',
|
||||
'math_syntax_error' => 'Used as error message.
|
||||
'math_syntax_error' => 'Used as error message for a texvc syntax error.
|
||||
|
||||
This message follows the message {{msg-mw|Math failure}}.
|
||||
{{Identical|Syntax error}}',
|
||||
|
@ -106,6 +109,9 @@ This message follows the message {{msg-mw|Math failure}}.',
|
|||
This message follows the message {{msg-mw|Math failure}}.',
|
||||
'math_notexvc' => 'Used as error message.
|
||||
|
||||
This message follows the message {{msg-mw|Math failure}}.',
|
||||
'math_output_error' => 'Used as error message if the texvc output file could not be stored.
|
||||
|
||||
This message follows the message {{msg-mw|Math failure}}.',
|
||||
);
|
||||
|
||||
|
|
|
@ -105,14 +105,16 @@ abstract class MathRenderer {
|
|||
* Returns an internationalized HTML error string
|
||||
*
|
||||
* @param string $msg message key for specific error
|
||||
* @param string $append string to append after error
|
||||
* @param Varargs $parameters (optional) zero or more message parameters for specific error
|
||||
* @return string HTML error string
|
||||
*/
|
||||
protected function getError( $msg, $append = '' ) {
|
||||
protected function getError( $msg /*, ... */ ) {
|
||||
$mf = wfMessage( 'math_failure' )->inContentLanguage()->escaped();
|
||||
$errmsg = wfMessage( $msg )->inContentLanguage()->escaped();
|
||||
$parameters = func_get_args();
|
||||
array_shift( $parameters );
|
||||
$errmsg = wfMessage( $msg, $parameters )->inContentLanguage()->escaped();
|
||||
$source = htmlspecialchars( str_replace( "\n", ' ', $this->tex ) );
|
||||
return "<strong class='error'>$mf ($errmsg$append): $source</strong>\n";
|
||||
return "<strong class='error'>$mf ($errmsg): $source</strong>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -94,6 +94,32 @@ class MathTexvc extends MathRenderer {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an error returned by texvc to a localized exception
|
||||
*
|
||||
* @param string $texvcResult error result returned by texvc
|
||||
*/
|
||||
public function convertTexvcError( $texvcResult ) {
|
||||
$texvcStatus = substr( $texvcResult, 0, 1 );
|
||||
|
||||
$errDetails = htmlspecialchars( substr( $texvcResult, 1 ) );
|
||||
switch( $texvcStatus ) {
|
||||
case 'E':
|
||||
$errMsg = $this->getError( 'math_lexing_error' );
|
||||
break;
|
||||
case 'S':
|
||||
$errMsg = $this->getError( 'math_syntax_error' );
|
||||
break;
|
||||
case 'F':
|
||||
$errMsg = $this->getError( 'math_unknown_function', $errDetails );
|
||||
break;
|
||||
default:
|
||||
$errMsg = $this->getError( 'math_unknown_error' );
|
||||
}
|
||||
|
||||
return $errMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual call to texvc
|
||||
*
|
||||
|
@ -169,20 +195,7 @@ class MathTexvc extends MathRenderer {
|
|||
$this->setMathml( null );
|
||||
$this->setConservativeness( self::LIBERAL );
|
||||
} else {
|
||||
$errbit = htmlspecialchars( substr( $contents, 1 ) );
|
||||
switch( $retval ) {
|
||||
case 'E':
|
||||
$errmsg = $this->getError( 'math_lexing_error', $errbit );
|
||||
break;
|
||||
case 'S':
|
||||
$errmsg = $this->getError( 'math_syntax_error', $errbit );
|
||||
break;
|
||||
case 'F':
|
||||
$errmsg = $this->getError( 'math_unknown_function', $errbit );
|
||||
break;
|
||||
default:
|
||||
$errmsg = $this->getError( 'math_unknown_error', $errbit );
|
||||
}
|
||||
$errmsg = $this->convertTexvcError( $contents );
|
||||
}
|
||||
|
||||
if ( !$errmsg ) {
|
||||
|
|
|
@ -114,4 +114,39 @@ class MathTexvcTest extends MediaWikiTestCase {
|
|||
// ... it will return the error result instead:
|
||||
$this->assertEquals( $texvc->render(), 'error' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests behavior of convertTexvcError
|
||||
*
|
||||
* @covers MathTexvc::convertTexvcError
|
||||
*/
|
||||
public function testConvertTexvcError() {
|
||||
$texvc = $this->getMockBuilder( 'MathTexvc' )
|
||||
->setMethods(NULL)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mathFailure = wfMessage( 'math_failure' )->inContentLanguage()->escaped();
|
||||
|
||||
$actualLexing = $texvc->convertTexvcError( 'E' );
|
||||
$expectedLexing = wfMessage( 'math_lexing_error', '' )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualLexing, 'Lexing error contains general math failure message' );
|
||||
$this->assertContains( $expectedLexing, $actualLexing, 'Lexing error contains detailed error for lexing' );
|
||||
|
||||
$actualSyntax = $texvc->convertTexvcError( 'S' );
|
||||
$expectedSyntax = wfMessage( 'math_syntax_error', '' )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualSyntax, 'Syntax error contains general math failure message' );
|
||||
$this->assertContains( $expectedSyntax, $actualSyntax, 'Syntax error contains detailed error for syntax' );
|
||||
|
||||
$unknownFunction = 'figureEightIntegral';
|
||||
$actualUnknownFunction = $texvc->convertTexvcError( "F$unknownFunction" );
|
||||
$expectedUnknownFunction = wfMessage( 'math_unknown_function', $unknownFunction )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualUnknownFunction, 'Unknown function error contains general math failure message' );
|
||||
$this->assertContains( $expectedUnknownFunction, $actualUnknownFunction, 'Unknown function error contains detailed error for unknown function' );
|
||||
|
||||
$actualUnknownError = $texvc->convertTexvcError( 'Q' );
|
||||
$expectedUnknownError = wfMessage( 'math_unknown_error', '' )->inContentLanguage()->escaped();
|
||||
$this->assertContains( $mathFailure, $actualUnknownError, 'Unknown error contains general math failure message' );
|
||||
$this->assertContains( $expectedUnknownError, $actualUnknownError, 'Unknown error contains detailed error for unknownError' );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue