Remove useless debug functionality

* MathDebug was intended to provide advanced debugging functionality
  for the math extension. However, the interesting debugging and
  logging feature never made it from the debug branch to the master.
* The current debug functionality is mostly useless. Only some values
  are written to memory and never used thereafter.
* This change moves the existing functionality to the MathSearch
  extension and introduced the required hook for that.

Details:
* $wgMathDebug is removed
* A new Hook MathRenderingResultRetrieved is created
* The math rendering object is printed to the svg error
  page if wgDebugComments is active (instead of wgMathDebug)

Change-Id: I6fad69b5d9b9ca8a7d12c7e410d3ae6180fbddbf
This commit is contained in:
physikerwelt 2015-07-12 21:40:34 +02:00
parent da6865c014
commit 5c12ed983f
7 changed files with 20 additions and 75 deletions

View File

@ -205,9 +205,6 @@ define( 'MW_MATH_CHECK_NEW' , 2 );
*/
$wgMathDisableTexFilter = MW_MATH_CHECK_NEW;
/** Stores debug information in the database and provides more detailed debug output */
$wgMathDebug = false;
/** @var boolean $wgMathEnableExperimentalInputFormats enables experimental MathML and AsciiMath input format support */
$wgMathEnableExperimentalInputFormats = false;
////////// end of config settings.

View File

@ -95,8 +95,6 @@ class MathLaTeXML extends MathMathML {
* @return boolean
*/
protected function doRender() {
global $wgMathDebug;
if ( trim( $this->getTex() ) === '' ) {
LoggerFactory::getInstance( 'Math' )->warning(
'Rendering was requested, but no TeX string is specified.' );
@ -118,10 +116,9 @@ class MathLaTeXML extends MathMathML {
if ( $jsonResult && json_last_error() === JSON_ERROR_NONE ) {
if ( $this->isValidMathML( $jsonResult->result ) ) {
$this->setMathml( $jsonResult->result );
if ( $wgMathDebug ) {
$this->setLog( $jsonResult->log );
$this->setStatusCode( $jsonResult->status_code );
}
Hooks::run( 'MathRenderingResultRetrieved',
array( &$renderer,
&$jsonResult ) );// Enables debugging of server results
return true;
} else {
// Do not print bad mathml. It's probably too verbose and might

View File

@ -195,6 +195,7 @@ class MathMathML extends MathRenderer {
protected function pickHost() {
if ( is_array( $this->hosts ) ) {
$host = array_rand( $this->hosts );
$this->hosts = $host; // Use the same host for this class instance
} else {
$host = $this->hosts;
}
@ -463,7 +464,6 @@ class MathMathML extends MathRenderer {
* @return bool
*/
private function processJsonResult( $jsonResult, $host ) {
global $wgMathDebug;
if ( $this->getMode() == MW_MATH_LATEXML || $this->inputType == 'pmml' ||
$this->isValidMathML( $jsonResult->mml )
) {
@ -479,12 +479,12 @@ class MathMathML extends MathRenderer {
LoggerFactory::getInstance( 'Math' )->error(
'Missing SVG property in JSON result.' );
}
if ( $wgMathDebug ) {
$this->setLog( $jsonResult->log );
}
if ( $this->getMode() != MW_MATH_LATEXML && $this->inputType != 'pmml' ) {
$this->setMathml( $jsonResult->mml );
}
Hooks::run( 'MathRenderingResultRetrieved',
array( &$renderer,
&$jsonResult ) );// Enables debugging of server results
return true;
} else {
$this->lastError = $this->getError( 'math_unknown_error', $host );

View File

@ -13,8 +13,7 @@ use MediaWiki\Logger\LoggerFactory;
* Abstract base class with static methods for rendering the <math> tags using
* different technologies. These static methods create a new instance of the
* extending classes and render the math tags based on the mode setting of the user.
* Furthermore this class handles the caching of the rendered output and provides
* debug information, if run in mathdebug mode.
* Furthermore this class handles the caching of the rendered output.
*
* @author Tomasz Wegrzanowski
* @author Brion Vibber
@ -39,15 +38,6 @@ abstract class MathRenderer {
/** @var string a userdefined identifier to link to the equation. */
protected $id = '';
// DEBUG VARIABLES
// Available, if Math extension runs in debug mode ($wgMathDebug = true) only.
/** @var int LaTeXML return code (will be available in future Mathoid versions as well) */
protected $statusCode = 0;
/** @var timestamp of the last modification of the database entry */
protected $timestamp;
/** @var log messages generated during conversion of mathematical content */
protected $log = '';
// STATE OF THE CLASS INSTANCE
/** @var boolean has variable tex been security-checked */
protected $texSecure = false;
@ -325,7 +315,6 @@ abstract class MathRenderer {
* @param DatabaseBase $dbw
*/
public function writeToDatabase( $dbw = null ) {
global $wgMathDebug;
# Now save it back to the DB:
if ( !wfReadOnly() ) {
$dbw = $dbw ?: wfGetDB( DB_MASTER );
@ -347,18 +336,16 @@ abstract class MathRenderer {
} );
} else {
$dbw->onTransactionIdle( function () use (
$dbw, $outArray, $wgMathDebug, $method, $mathTableName
$dbw, $outArray, $method, $mathTableName
) {
$dbw->insert( $mathTableName, $outArray, $method, array( 'IGNORE' ) );
if ( $wgMathDebug ) {
LoggerFactory::getInstance( 'Math' )->debug(
'Row inserted after db transaction was idle ' .
var_export( $outArray, true ) . " to database" );
if ( $dbw->affectedRows() == 0 ) {
// That's the price for the delayed update.
LoggerFactory::getInstance( 'Math' )->warning(
'Entry could not be written. Might be changed in between.' );
}
LoggerFactory::getInstance( 'Math' )->debug(
'Row inserted after db transaction was idle ' .
var_export( $outArray, true ) . " to database" );
if ( $dbw->affectedRows() == 0 ) {
// That's the price for the delayed update.
LoggerFactory::getInstance( 'Math' )->warning(
'Entry could not be written. Might be changed in between.' );
}
} );
}
@ -420,14 +407,6 @@ abstract class MathRenderer {
return $this->tex;
}
/**
* gets the timestamp, of the last rendering of that equation
* @return int
*/
public function getTimestamp() {
return $this->timestamp;
}
/**
* gets the rendering mode MW_MATH_*
*
@ -549,13 +528,6 @@ abstract class MathRenderer {
return $this->lastError;
}
/**
* @return string
*/
public function getLog() {
return $this->log;
}
/**
*
* @param (MW_MATHSTYLE_INLINE_DISPLAYSTYLE|MW_MATHSTYLE_DISPLAY|MW_MATHSTYLE_INLINE) $mathStyle
@ -574,28 +546,7 @@ abstract class MathRenderer {
public function getMathStyle() {
return $this->mathStyle;
}
/**
* @param string $log
*/
public function setLog( $log ) {
$this->changed = true;
$this->log = $log;
}
/**
* @return int
*/
public function getStatusCode() {
return $this->statusCode;
}
/**
* @param unknown_type $statusCode
*/
public function setStatusCode( $statusCode ) {
$this->changed = true;
$this->statusCode = $statusCode;
}
/**
* Get if the input tex was marked as secure
* @return boolean

View File

@ -119,11 +119,11 @@ class SpecialMathShowImage extends SpecialPage {
* @return xml svg image with the error message
*/
private function printSvgError( $msg ) {
global $wgMathDebug;
global $wgDebugComments;
$result = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 4"
preserveAspectRatio="xMidYMid meet" >' .
'<text text-anchor="start" fill="red" y="2">' . htmlspecialchars( $msg ) . '</text></svg>';
if ( $wgMathDebug ) {
if ( $wgDebugComments ) {
$result .= '<!--'. var_export($this->renderer, true) .'-->';
}
return $result;

View File

@ -74,7 +74,7 @@ class MathDatabaseTest extends MediaWikiTestCase {
/**
* Checks the creation of the math table without debugging enabled.
* Checks the creation of the math table.
* @covers MathHooks::onLoadExtensionSchemaUpdates
*/
public function testCreateTable() {

View File

@ -73,7 +73,7 @@ class MathLaTeXMLDatabaseTest extends MediaWikiTestCase {
}
/**
* Checks the creation of the math table without debugging enabled.
* Checks the creation of the math table.
* @covers MathHooks::onLoadExtensionSchemaUpdates
*/
public function testCreateTable() {