jenkins-bot has submitted this change and it was merged. Change subject: Reduce log output size ......................................................................
Reduce log output size * The Math extension creates a log of debug output, this slows down page rendering significantly. * This page suppresses the log output, unless the $wgMathDebug is set to true. Change-Id: I82ff6a31cd191119ec0c71c32eeb9570afd629db --- M Math.hooks.php M MathLaTeXML.php M MathMathML.php M MathRenderer.php M MathTexvc.php 5 files changed, 88 insertions(+), 67 deletions(-) Approvals: Physikerwelt: Looks good to me, approved jenkins-bot: Verified diff --git a/Math.hooks.php b/Math.hooks.php index 62b64e0..66e791e 100644 --- a/Math.hooks.php +++ b/Math.hooks.php @@ -117,10 +117,10 @@ } 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(); } wfRunHooks( 'MathFormulaRendered', @@ -159,8 +159,8 @@ ); // 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]; } diff --git a/MathLaTeXML.php b/MathLaTeXML.php index 4fca925..565f863 100644 --- a/MathLaTeXML.php +++ b/MathLaTeXML.php @@ -82,9 +82,9 @@ $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 @@ 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 @@ // 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; diff --git a/MathMathML.php b/MathMathML.php index c90a9c0..4d90153 100644 --- a/MathMathML.php +++ b/MathMathML.php @@ -160,16 +160,22 @@ 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 @@ */ 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 @@ $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 { diff --git a/MathRenderer.php b/MathRenderer.php index c50bb3c..1956c5b 100644 --- a/MathRenderer.php +++ b/MathRenderer.php @@ -125,7 +125,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ * 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 @@ $names = MathHooks::getMathNames(); return $names[ $this->getMode() ]; } + } diff --git a/MathTexvc.php b/MathTexvc.php index a2f6113..249c382 100644 --- a/MathTexvc.php +++ b/MathTexvc.php @@ -32,7 +32,6 @@ * @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 @@ $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 @@ 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 @@ $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 @@ $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 @@ 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 @@ } 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 @@ // 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', -- To view, visit https://gerrit.wikimedia.org/r/197228 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I82ff6a31cd191119ec0c71c32eeb9570afd629db Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Math Gerrit-Branch: develop Gerrit-Owner: Physikerwelt <w...@physikerwelt.de> Gerrit-Reviewer: Physikerwelt <w...@physikerwelt.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits