mediawiki-extensions-Math/MathInputCheckRestbase.php
physikerwelt 1ec767791b Make math usable without RESTbase
* Do not contact RESTbase in texvc rendering mode and
  use the well established tex checking that is already build
  into texvc.
* Do not use RESTbase in LaTeXML mode.

Background:
In I1982612e8c6a356e3dbdf447724ac82e5968cc77 RESTbased replaced
texvccheck that was a derivate of texvc designed for people
that wanted to use secure MathML rendering using mathoid.
The integration of mathoid to restbase made this feature obsolete.
However, texvccheck was not only used to check the latex input
that was sent to mathoid, but also the string which was sent to texvc.
Since texvc has already build in tex checking this is not
required and does not improve security.
Finally, users updating from old versions of the math extension
(prior to 2014) that do not have textexvccheck installed,
do not need to compile the texvccheck binary after this change.

PS5: Also treats the case where VisualEditor is not installed.

Bug: T121173
Change-Id: I1bd076b09206869b5ed75280d22e1b36bfb8d8ad
2015-12-11 22:04:12 +01:00

88 lines
2.3 KiB
PHP

<?php
/**
* MediaWiki math extension
*
* (c) 2002-2015 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz,
* and other MediaWiki contributors
* GPLv2 license; info in main package.
*
* @author Moritz Schubotz
*/
use MediaWiki\Logger\LoggerFactory;
class MathInputCheckRestbase extends MathInputCheck {
private $restbaseInterface;
/**
* Default constructor
* (performs no checking)
* @param string $tex the TeX input string to be checked
* @param bool $displayStyle
*/
public function __construct( $tex = '', $displayStyle = true ) {
parent::__construct( $tex );
$this->restbaseInterface = new MathRestbaseInterface( $tex, $displayStyle );
}
/**
* @see https://phabricator.wikimedia.org/T119300
* @param stdClass $e
* @param MathRenderer $errorRenderer
* @return string
*/
public function errorObjectToHtml( stdClass $e, $errorRenderer = null ) {
if ( $errorRenderer === null ) {
$errorRenderer = new MathSource( $this->inputTeX );
}
if ( isset( $e->error->message ) ){
if ( $e->error->message === 'Illegal TeX function' ) {
return $errorRenderer->getError( 'math_unknown_function', $e->error->found );
} elseif ( preg_match( '/Math extension/', $e->error->message ) ) {
$names = MathHooks::getMathNames();
$mode = $names['mathml'];
try {
$host = $this->restbaseInterface->getUrl( '' );
}
catch ( Exception $ignore ) {
$host = 'invalid';
}
$msg = $e->error->message;
return $errorRenderer->getError( 'math_invalidresponse', $mode, $host, $msg );
}
return $errorRenderer->getError( 'math_syntax_error' );
}
return $errorRenderer->getError( 'math_unknown_error' );
}
/**
* @return boolean
*/
public function isValid() {
return $this->restbaseInterface->checkTeX();
}
/**
* Some TeX checking programs may return
* a modified tex string after having checked it.
* You can get the altered tex string with this method
* @return string A valid Tex string
*/
public function getValidTex() {
return $this->restbaseInterface->getCheckedTex();
}
/**
* Returns the string of the last error.
* @return string
*/
public function getError() {
$err = $this->restbaseInterface->getError();
if ( $err === null ){
return null;
}
return $this->errorObjectToHtml( $err );
}
}