Code style cleanup

Cleanup whitespace and quoting, mostly related to logging function
usage.

Change-Id: I82ff6a31cd191119ec0c71c32eeb9570afd629db
This commit is contained in:
physikerwelt 2015-03-16 15:51:16 -04:00 committed by BryanDavis
parent de79176fe1
commit 6742dedda4
5 changed files with 88 additions and 67 deletions

View File

@ -117,10 +117,10 @@ class MathHooks {
}
if ( $renderer->render() ) {
wfDebugLog( "Math" , "Rendering successful. Writing output" );
wfDebugLog( 'Math', "Rendering successful. Writing output" );
$renderedMath = $renderer->getHtmlOutput();
} else {
wfDebugLog( "Math" , "Rendering failed. Printing error message." );
wfDebugLog( 'Math', "Rendering failed. Printing error message." );
return $renderer->getLastError();
}
Hooks::run( 'MathFormulaPostRender',
@ -156,8 +156,8 @@ class MathHooks {
);
// If the default option is not in the valid options the
// user interface throws an exception (BUG 64844)
if ( ! in_array( $wgDefaultUserOptions['math'] , $wgMathValidModes ) ){
wfDebugLog( 'Math', "Warning: Misconfiguration \$wgDefaultUserOptions['math'] is not in \$wgMathValidModes. Please check your LocalSetting.php file.");
if ( ! in_array( $wgDefaultUserOptions['math'] , $wgMathValidModes ) ) {
wfDebugLog( 'Math', "Warning: Misconfiguration \$wgDefaultUserOptions['math'] is not in \$wgMathValidModes. Please check your LocalSetting.php file." );
// Display the checkbox in the first option.
$wgDefaultUserOptions['math'] = $wgMathValidModes[0];
}

View File

@ -82,9 +82,9 @@ class MathLaTeXML extends MathMathML {
$tex = '{\displaystyle ' . $tex . '}';
}
$texcmd = rawurlencode( $tex );
$settings = $this->serializeSettings( $this->getLaTeXMLSettings( ) );
$settings = $this->serializeSettings( $this->getLaTeXMLSettings() );
$postData = $settings . '&tex=' . $texcmd;
wfDebugLog( "Math", 'Get post data: ' . $postData );
wfDebugLog( 'Math', 'Get post data: ' . $postData );
return $postData;
}
@ -96,7 +96,7 @@ class MathLaTeXML extends MathMathML {
global $wgMathDebug;
if ( trim( $this->getTex() ) === '' ) {
wfDebugLog( "Math", "Rendering was requested, but no TeX string is specified." );
wfDebugLog( 'Math', "Rendering was requested, but no TeX string is specified." );
$this->lastError = $this->getError( 'math_empty_tex' );
return false;
}
@ -124,18 +124,22 @@ class MathLaTeXML extends MathMathML {
// Do not print bad mathml. It's probably too verbose and might
// mess up the browser output.
$this->lastError = $this->getError( 'math_invalidxml', $this->getModeStr(), $host );
wfDebugLog( "Math", "\nLaTeXML InvalidMathML:"
. var_export( array( 'post' => $post, 'host' => $host
, 'result' => $res ), true ) . "\n\n" );
wfDebugLog( 'Math', "\nLaTeXML InvalidMathML:" . var_export( array(
'post' => $post,
'host' => $host,
'result' => $res
), true ) . "\n\n" );
return false;
}
} else {
$this->lastError = $this->getError( 'math_invalidjson', $this->getModeStr(), $host );
wfDebugLog( "Math", "\nLaTeXML InvalidJSON:"
. var_export( array( 'post' => $post, 'host' => $host
, 'res' => $res ), true ) . "\n\n" );
return false;
}
wfDebugLog( 'Math', "\nLaTeXML InvalidJSON:" . var_export( array(
'post' => $post,
'host' => $host,
'res' => $res
), true ) . "\n\n" );
return false;
}
} else {
// Error message has already been set.
return false;

View File

@ -160,16 +160,22 @@ class MathMathML extends MathRenderer {
if ( $status->hasMessage( 'http-timed-out' ) ) {
$error = $this->getError( 'math_timeout', $this->getModeStr(), $host );
$res = false;
wfDebugLog( 'Math', "\nTimeout:"
. var_export( array( 'post' => $post, 'host' => $host
, 'timeout' => $wgMathLaTeXMLTimeout ), true ) . "\n\n" );
wfDebugLog( 'Math', "\nTimeout:" . var_export( array(
'post' => $post,
'host' => $host,
'timeout' => $wgMathLaTeXMLTimeout
), true ) . "\n\n" );
} else {
// for any other unkonwn http error
$errormsg = $status->getHtml();
$error = $this->getError( 'math_invalidresponse', $this->getModeStr(), $host, $errormsg, $this->getModeStr( MW_MATH_MATHML ) );
wfDebugLog( 'Math', "\nNoResponse:"
. var_export( array( 'post' => $post, 'host' => $host
, 'errormsg' => $errormsg ), true ) . "\n\n" );
$error =
$this->getError( 'math_invalidresponse', $this->getModeStr(), $host, $errormsg,
$this->getModeStr( MW_MATH_MATHML ) );
wfDebugLog( 'Math', "\nNoResponse:" . var_export( array(
'post' => $post,
'host' => $host,
'errormsg' => $errormsg
), true ) . "\n\n" );
}
return false;
}
@ -199,14 +205,15 @@ class MathMathML extends MathRenderer {
*/
public function getPostData() {
$input = $this->getTex();
if ( $this->inputType == 'pmml' || $this->getMode() == MW_MATH_LATEXML && $this->getMathml() ) {
if ( $this->inputType == 'pmml' ||
$this->getMode() == MW_MATH_LATEXML && $this->getMathml() ) {
$out = 'type=mml&q=' . rawurlencode( $this->getMathml() );
} elseif ( $this->inputType == 'ascii' ) {
$out = 'type=asciimath&q=' . rawurlencode( $input );
} else {
if ( $this->getMathStyle() == MW_MATHSTYLE_INLINE_DISPLAYSTYLE ) {
// default preserve the (broken) layout as it was
$out = 'type=inline-TeX&q=' .rawurlencode( '{\\displaystyle ' . $input . '}' );
$out = 'type=inline-TeX&q=' . rawurlencode( '{\\displaystyle ' . $input . '}' );
} else {
$out = 'type=tex&q=' . rawurlencode( $input );
}
@ -242,16 +249,20 @@ class MathMathML extends MathRenderer {
$log = wfMessage( 'math_unknown_error' )->inContentLanguage()->escaped();
}
$this->lastError = $this->getError( 'math_mathoid_error', $host, $log );
wfDebugLog( 'Math', 'Mathoid conversion error:'
. var_export( array( 'post' => $post, 'host' => $host
, 'result' => $res ), true ) . "\n\n" );
wfDebugLog( 'Math', 'Mathoid conversion error:' . var_export( array(
'post' => $post,
'host' => $host,
'result' => $res
), true ) . "\n\n" );
return false;
}
} else {
$this->lastError = $this->getError( 'math_invalidjson', $host );
wfDebugLog( 'Math', "\nMathML InvalidJSON:"
. var_export( array( 'post' => $post, 'host' => $host
, 'res' => $res ), true ) . "\n\n" );
wfDebugLog( 'Math', "\nMathML InvalidJSON:" . var_export( array(
'post' => $post,
'host' => $host,
'res' => $res
), true ) . "\n\n" );
return false;
}
} else {

View File

@ -125,7 +125,7 @@ abstract class MathRenderer {
if ( isset( $params['display'] ) ) {
$layoutMode = $params['display'];
if ( $layoutMode == 'block' ) {
$mathStyle = MW_MATHSTYLE_DISPLAY ;
$mathStyle = MW_MATHSTYLE_DISPLAY;
// TODO: Implement caching for attributes of the math tag
// Currently the key for the database entry relating to an equation
// is md5($tex) the new option to determine if the tex input
@ -149,10 +149,11 @@ abstract class MathRenderer {
if ( !in_array( $mode, $wgMathValidModes ) ) {
$mode = $wgDefaultUserOptions['math'];
}
if ( $wgMathEnableExperimentalInputFormats === true && $mode == MW_MATH_MATHML && isset( $params['type'] ) ) {
if ( $wgMathEnableExperimentalInputFormats === true && $mode == MW_MATH_MATHML &&
isset( $params['type'] ) ) {
// Support of MathML input (experimental)
// Currently support for mode MW_MATH_MATHML only
if( !in_array( $params['type'], array( 'pmml', 'ascii' ) ) ) {
if ( !in_array( $params['type'], array( 'pmml', 'ascii' ) ) ) {
unset( $params['type'] );
}
}
@ -171,7 +172,7 @@ abstract class MathRenderer {
default:
$renderer = new MathMathML( $tex, $params );
}
wfDebugLog ( "Math", 'start rendering $' . $renderer->tex . '$ in mode ' . $mode );
wfDebugLog( 'Math', 'start rendering $' . $renderer->tex . '$ in mode ' . $mode );
$renderer->setMathStyle( $mathStyle );
return $renderer;
}
@ -325,30 +326,36 @@ abstract class MathRenderer {
global $wgMathDebug;
# Now save it back to the DB:
if ( !wfReadOnly() ) {
$dbw = $dbw ? : wfGetDB( DB_MASTER );
wfDebugLog( "Math", 'store entry for $' . $this->tex . '$ in database (hash:' . $this->getMd5() . ")\n" );
$dbw = $dbw ?: wfGetDB( DB_MASTER );
wfDebugLog( 'Math', 'store entry for $' . $this->tex . '$ in database (hash:' .
$this->getMd5() . ")\n" );
$outArray = $this->dbOutArray();
$method = __METHOD__;
$mathTableName = $this->getMathTableName();
if ( $this->isInDatabase() ) {
$inputHash = $this->getInputHash();
$dbw->onTransactionIdle(
function() use( $dbw, $outArray, $wgMathDebug, $inputHash, $method, $mathTableName ) {
$dbw->update( $mathTableName, $outArray , array( 'math_inputhash' => $inputHash ), $method );
if ( $wgMathDebug ) wfDebugLog( "Math", 'Row updated after db transaction was idle: ' . var_export( $outArray , true ) . " to database \n" );
} );
$dbw->onTransactionIdle( function () use (
$dbw, $outArray, $inputHash, $method, $mathTableName
) {
$dbw->update( $mathTableName, $outArray,
array( 'math_inputhash' => $inputHash ), $method );
wfDebugLog( 'Math', 'Row updated after db transaction was idle: ' .
var_export( $outArray, true ) . " to database \n" );
} );
} else {
$dbw->onTransactionIdle(
function() use( $dbw, $outArray, $wgMathDebug, $method, $mathTableName ) {
$dbw->insert( $mathTableName, $outArray, $method , array ( 'IGNORE' ) );
if ( $wgMathDebug ) {
wfDebugLog( "Math", 'Row inserted after db transaction was idle ' . var_export( $outArray , true ) . " to database \n" );
if ( $dbw->affectedRows() == 0 ) {
// That's the price for the delayed update.
wfDebugLog( "Math", 'Entry could not be written. Might be changed in between. ' );
}
$dbw->onTransactionIdle( function () use (
$dbw, $outArray, $wgMathDebug, $method, $mathTableName
) {
$dbw->insert( $mathTableName, $outArray, $method, array( 'IGNORE' ) );
if ( $wgMathDebug ) {
wfDebugLog( 'Math', 'Row inserted after db transaction was idle ' .
var_export( $outArray, true ) . " to database \n" );
if ( $dbw->affectedRows() == 0 ) {
// That's the price for the delayed update.
wfDebugLog( 'Math', 'Entry could not be written. Might be changed in between. ' );
}
} );
}
} );
}
}
}
@ -387,14 +394,13 @@ abstract class MathRenderer {
* Writes cache. Writes the database entry if values were changed
*/
public function writeCache() {
global $wgMathDebug;
if ( $wgMathDebug) wfDebugLog( "Math" , "writing of cache requested." );
wfDebugLog( 'Math', "writing of cache requested." );
if ( $this->isChanged() ) {
if ( $wgMathDebug) wfDebugLog( "Math" , "Change detected. Perform writing." );
wfDebugLog( 'Math', "Change detected. Perform writing." );
$this->writeToDatabase();
return true;
} else {
if ( $wgMathDebug) wfDebugLog( "Math" , "Nothing was changed. Don't write to database." );
wfDebugLog( 'Math', "Nothing was changed. Don't write to database." );
return false;
}
}
@ -683,4 +689,5 @@ abstract class MathRenderer {
$names = MathHooks::getMathNames();
return $names[ $this->getMode() ];
}
}

View File

@ -32,7 +32,6 @@ class MathTexvc extends MathRenderer {
* @return array
*/
public function dbOutArray() {
global $wgMathDebug;
$out = array();
$dbr = wfGetDB( DB_SLAVE );
$outmd5_sql = $dbr->encodeBlob( pack( 'H32', $this->hash ) );
@ -44,7 +43,7 @@ class MathTexvc extends MathRenderer {
$out['math_html'] = $this->html;
$out['math_mathml'] = utf8_encode( $this->getMathml() );
$out['math_inputhash'] = $this->getInputHash();
if ( $wgMathDebug ) wfDebugLog( 'Math', 'Store Hashpath of image' . bin2hex( $outmd5_sql ) );
wfDebugLog( 'Math', 'Store Hashpath of image' . bin2hex( $outmd5_sql ) );
return $out;
}
@ -100,7 +99,7 @@ class MathTexvc extends MathRenderer {
public function getHashPath() {
$path = $this->getBackend()->getRootStoragePath() .
'/math-render/' . $this->getHashSubPath();
wfDebugLog( "Math", "TeX: getHashPath, hash is: {$this->getHash()}, path is: $path\n" );
wfDebugLog( 'Math', "TeX: getHashPath, hash is: {$this->getHash()}, path is: $path\n" );
return $path;
}
@ -176,7 +175,7 @@ class MathTexvc extends MathRenderer {
$tmpDir = wfTempDir();
if ( !is_executable( $wgTexvc ) ) {
wfDebugLog( 'texvc', "$wgTexvc does not exist or is not executable." );
wfDebugLog( 'Math', "$wgTexvc does not exist or is not executable." );
return $this->getError( 'math_notexvc' );
}
@ -194,17 +193,17 @@ class MathTexvc extends MathRenderer {
$cmd = 'sh -c ' . wfEscapeShellArg( $cmd );
}
wfDebugLog( 'Math', "TeX: $cmd\n" );
wfDebugLog( 'texvc', "Executing '$cmd'." );
wfDebugLog( 'Math', "Executing '$cmd'." );
$retval = null;
$contents = wfShellExec( $cmd, $retval );
wfDebugLog( 'Math', "TeX output:\n $contents\n---\n" );
if ( strlen( $contents ) == 0 ) {
if ( !file_exists( $tmpDir ) || !is_writable( $tmpDir ) ) {
wfDebugLog( 'texvc', "TeX output directory $tmpDir is missing or not writable" );
wfDebugLog( 'Math', "TeX output directory $tmpDir is missing or not writable" );
return $this->getError( 'math_bad_tmpdir' );
} else {
wfDebugLog( 'texvc', "TeX command '$cmd' returned no output and status code $retval." );
wfDebugLog( 'Math', "TeX command '$cmd' returned no output and status code $retval." );
return $this->getError( 'math_unknown_error' );
}
}
@ -218,9 +217,9 @@ class MathTexvc extends MathRenderer {
if ( $retval == 'C' ) {
$this->setConservativeness( self::CONSERVATIVE );
} elseif ( $retval == 'M' ) {
$this->setConservativeness( self::MODERATE );
$this->setConservativeness( self::MODERATE );
} else {
$this->setConservativeness( self::LIBERAL );
$this->setConservativeness( self::LIBERAL );
}
$outdata = substr( $contents, 33 );
@ -231,7 +230,7 @@ class MathTexvc extends MathRenderer {
} elseif ( ( $retval == 'c' ) || ( $retval == 'm' ) || ( $retval == 'l' ) ) {
$this->setHtml( substr( $contents, 33 ) );
if ( $retval == 'c' ) {
$this->setConservativeness( self::CONSERVATIVE ) ;
$this->setConservativeness( self::CONSERVATIVE );
} elseif ( $retval == 'm' ) {
$this->setConservativeness( self::MODERATE );
} else {
@ -281,12 +280,12 @@ class MathTexvc extends MathRenderer {
// Bug 56769: buffer the writes and do them at the end.
if ( !isset( $wgHooks['ParserAfterParse']['FlushMathBackend'] ) ) {
$backend->mathBufferedWrites = array();
$wgHooks['ParserAfterParse']['FlushMathBackend'] = function() use ( $backend ) {
$wgHooks['ParserAfterParse']['FlushMathBackend'] = function () use ( $backend ) {
global $wgHooks;
unset( $wgHooks['ParserAfterParse']['FlushMathBackend'] );
$backend->doQuickOperations( $backend->mathBufferedWrites );
unset( $backend->mathBufferedWrites );
} ;
};
}
$backend->mathBufferedWrites[] = array(
'op' => 'store',