[MediaWiki-commits] [Gerrit] Add debug fields - change (mediawiki...MathSearch)
jenkins-bot has submitted this change and it was merged. Change subject: Add debug fields .. Add debug fields Change-Id: Ic7ee7967b4aab756d2f58e54e2703f58b6eb5a44 --- M MathObject.php 1 file changed, 216 insertions(+), 156 deletions(-) Approvals: Physikerwelt: Looks good to me, approved jenkins-bot: Verified diff --git a/MathObject.php b/MathObject.php index 3b25a68..57f161b 100644 --- a/MathObject.php +++ b/MathObject.php @@ -2,70 +2,25 @@ use MediaWiki\Logger\LoggerFactory; class MathObject extends MathMathML { - + // 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 = ''; protected $anchorID = 0; protected $revisionID = 0; protected $index_timestamp = null; protected $dbLoadTime= 0; protected $mathTableName = null; - public function getAnchorID() { - return $this-anchorID; - } - - public function setAnchorID( $ID ) { - $this-anchorID = $ID; - } - - public function getRevisionID() { - return $this-revisionID; - } - - public function setRevisionID( $ID ) { - $this-revisionID = $ID; - } - - public function getIndexTimestamp() { - return $this-index_timestamp; - } - - public function getInputHash() { - if ( $this-inputHash ) { - return $this-inputHash; - } else { - return parent::getInputHash(); - } - } - public static function hash2md5( $hash ){ //TODO: make MathRenderer::dbHash2md5 public $dbr = wfGetDB( DB_SLAVE ); $xhash = unpack( 'H32md5', $dbr-decodeBlob( $hash ) . ); return $xhash['md5']; - } - /** -* -* @global boolean $wgMathDebug -* @param stdClass $res -* @return boolean|\self -*/ - public static function constructformpagerow( $res ) { - global $wgMathDebug; - if ( $res $res-mathindex_revision_id 0 ) { - $class = get_called_class(); - /** @type MathObject $instance */ - $instance = new $class; - $instance-setRevisionID( $res-mathindex_revision_id ); - $instance-setAnchorID( $res-mathindex_anchor ); - if ( $wgMathDebug isset($res-mathindex_timestamp) ) { - $instance-index_timestamp = $res-mathindex_timestamp; - } - $instance-inputHash = $res-mathindex_inputhash; - $instance-readFromDatabase(); - return $instance; - } else { - return false; - } } public static function findSimilarPages( $pid ) { @@ -92,6 +47,156 @@ } catch ( Exception $e ) { return DatabaseProblem; } + } + + public static function cloneFromRenderer(MathRenderer $renderer){ + $instance = new MathObject( $renderer-getTex() ); + $instance-setMathml( $renderer-getMathml() ); + $instance-setSvg( $renderer-getSvg() ); + $instance-setMode( $renderer-getMode() ); + $instance-setMathStyle( $renderer-getMathStyle() ); + return $instance; + } + + /** +* +* @param int $pid +* @param int $eid +* @return self instance +*/ + public static function constructformpage( $pid, $eid ) { + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr-selectRow( + array( 'mathindex' ), self::dbIndexFieldsArray(), 'mathindex_revision_id = ' . $pid + . ' AND mathindex_anchor= ' . $eid . '' ); + $start = microtime(true); + $o = self::constructformpagerow( $res ); + LoggerFactory::getInstance( 'MathSearch' )-warning( 'Fetched in '. microtime( true ) - $start ); + return $o; + } + + /** +* @return array +*/ + private static function dbIndexFieldsArray() { + global $wgMathDebug; + $in = array( + 'mathindex_revision_id', + 'mathindex_anchor', + 'mathindex_inputhash' ); +
[MediaWiki-commits] [Gerrit] Add debug fields - change (mediawiki...MathSearch)
Physikerwelt has uploaded a new change for review. https://gerrit.wikimedia.org/r/224369 Change subject: Add debug fields .. Add debug fields Change-Id: Ic7ee7967b4aab756d2f58e54e2703f58b6eb5a44 --- M MathObject.php 1 file changed, 216 insertions(+), 156 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MathSearch refs/changes/69/224369/1 diff --git a/MathObject.php b/MathObject.php index 3b25a68..57f161b 100644 --- a/MathObject.php +++ b/MathObject.php @@ -2,70 +2,25 @@ use MediaWiki\Logger\LoggerFactory; class MathObject extends MathMathML { - + // 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 = ''; protected $anchorID = 0; protected $revisionID = 0; protected $index_timestamp = null; protected $dbLoadTime= 0; protected $mathTableName = null; - public function getAnchorID() { - return $this-anchorID; - } - - public function setAnchorID( $ID ) { - $this-anchorID = $ID; - } - - public function getRevisionID() { - return $this-revisionID; - } - - public function setRevisionID( $ID ) { - $this-revisionID = $ID; - } - - public function getIndexTimestamp() { - return $this-index_timestamp; - } - - public function getInputHash() { - if ( $this-inputHash ) { - return $this-inputHash; - } else { - return parent::getInputHash(); - } - } - public static function hash2md5( $hash ){ //TODO: make MathRenderer::dbHash2md5 public $dbr = wfGetDB( DB_SLAVE ); $xhash = unpack( 'H32md5', $dbr-decodeBlob( $hash ) . ); return $xhash['md5']; - } - /** -* -* @global boolean $wgMathDebug -* @param stdClass $res -* @return boolean|\self -*/ - public static function constructformpagerow( $res ) { - global $wgMathDebug; - if ( $res $res-mathindex_revision_id 0 ) { - $class = get_called_class(); - /** @type MathObject $instance */ - $instance = new $class; - $instance-setRevisionID( $res-mathindex_revision_id ); - $instance-setAnchorID( $res-mathindex_anchor ); - if ( $wgMathDebug isset($res-mathindex_timestamp) ) { - $instance-index_timestamp = $res-mathindex_timestamp; - } - $instance-inputHash = $res-mathindex_inputhash; - $instance-readFromDatabase(); - return $instance; - } else { - return false; - } } public static function findSimilarPages( $pid ) { @@ -92,6 +47,156 @@ } catch ( Exception $e ) { return DatabaseProblem; } + } + + public static function cloneFromRenderer(MathRenderer $renderer){ + $instance = new MathObject( $renderer-getTex() ); + $instance-setMathml( $renderer-getMathml() ); + $instance-setSvg( $renderer-getSvg() ); + $instance-setMode( $renderer-getMode() ); + $instance-setMathStyle( $renderer-getMathStyle() ); + return $instance; + } + + /** +* +* @param int $pid +* @param int $eid +* @return self instance +*/ + public static function constructformpage( $pid, $eid ) { + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr-selectRow( + array( 'mathindex' ), self::dbIndexFieldsArray(), 'mathindex_revision_id = ' . $pid + . ' AND mathindex_anchor= ' . $eid . '' ); + $start = microtime(true); + $o = self::constructformpagerow( $res ); + LoggerFactory::getInstance( 'MathSearch' )-warning( 'Fetched in '. microtime( true ) - $start ); + return $o; + } + + /** +* @return array +*/ + private static function dbIndexFieldsArray() { + global $wgMathDebug; + $in = array( + 'mathindex_revision_id', + 'mathindex_anchor', +