Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/49488


Change subject: debug mode
......................................................................

debug mode

* the chached values are written to the database with delay
* optionally fields for debugging are introduced

Change-Id: Ic9e8ee7558e0496e3cffd4d3e8bea7a4c0c7d276
---
M MathRenderer.php
1 file changed, 112 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/88/49488/1

diff --git a/MathRenderer.php b/MathRenderer.php
index 10676aa..fc3e94c 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -17,7 +17,8 @@
  */
 abstract class MathRenderer {
        /**
-        *  The following variables should made private, as soon it can be 
verified that they are not being directly accessed by other extensions.
+        *  The following variables should made private, as soon it can be 
verified
+        *  that they are not being directly accessed by other extensions.
         */
        var $mode = MW_MATH_PNG;
        var $tex = '';
@@ -27,6 +28,12 @@
        var $mathml = '';
        var $conservativeness = 0;
        var $params = '';
+       //DEBUG variables
+       protected $log='';
+       protected $status_code='';
+       protected $valid_xml='';
+       private $success=false;
+       protected $timestamp;
        protected $recall;
        protected $anchorID = 0;
 
@@ -82,7 +89,7 @@
        }
 
        /**
-        * Returns TeX to HTML
+        * Performs the rendering and returns the rendered element that needs 
to be embedded.
         *
         * @return string of rendered HTML
         */
@@ -109,10 +116,52 @@
         */
        public function getInputHash() {
                // TODO: What happens if $tex is empty?
-               $dbr = wfGetDB( DB_SLAVE );
-               return $dbr->encodeBlob( pack( "H32", md5( $this->tex ) ) ); # 
Binary packed, not hex
+               if ($this->inputhash==''){
+                       $dbr = wfGetDB( DB_SLAVE );
+                       return $dbr->encodeBlob( pack( "H32", md5( $this->tex ) 
) ); # Binary packed, not hex
+               } else {
+                       return $this->inputhash;
+               }
        }
-
+       public function initializeFromDBRow($rpage){
+               global $wgDebugMath;
+               $dbr = wfGetDB( DB_SLAVE );
+               $xhash = unpack( 'H32md5', $dbr->decodeBlob( 
$rpage->math_outputhash ) . "                " );
+               $this->hash = $xhash['md5'];
+               $this->conservativeness = $rpage->math_html_conservativeness;
+               $this->html = $rpage->math_html;
+               $this->mathml =utf8_decode( $rpage->math_mathml);
+               $this->recall = true;
+               if($wgDebugMath){
+                       $this->tex=$rpage->math_tex;
+                       $this->status_code=$rpage->math_status;
+                       $this->valid_xml=$rpage->valid_xml;
+                       $this->log=$rpage->math_log;
+                       $this->timestamp=$rpage->math_timestamp;
+               }
+       }
+       /**
+        * @return array with the database column names
+        */
+       private function dbInArray(){
+               global $wgDebugMath;
+               $in= array(
+                               'math_inputhash',
+                               'math_outputhash'  ,
+                               'math_html_conservativeness' ,
+                               'math_html',
+                               'math_mathml');
+               if ($wgDebugMath){
+                       $debug_in= array(
+                                       'math_status' ,
+                                       'valid_xml' ,
+                                       'math_tex' ,
+                                       'math_log',
+                                       'math_timestamp');
+                       $in=array_merge($in,$debug_in);
+               }
+               return $in;
+       }
        /**
         * Reads rendering data from database
         *
@@ -122,23 +171,14 @@
                $dbr = wfGetDB( DB_SLAVE );
                $rpage = $dbr->selectRow(
                        'math',
-                       array(
-                               'math_outputhash', 
'math_html_conservativeness', 'math_html',
-                               'math_mathml'
-                       ),
+                       $this->dbInArray(),
                        array(
                                'math_inputhash' => $this->getInputHash()
                        ),
                        __METHOD__
                );
                if ( $rpage !== false ) {
-                       # Trailing 0x20s can get dropped by the database, add 
it back on if necessary:
-                       $xhash = unpack( 'H32md5', $dbr->decodeBlob( 
$rpage->math_outputhash ) . "                " );
-                       $this->hash = $xhash['md5'];
-                       $this->conservativeness = 
$rpage->math_html_conservativeness;
-                       $this->html = $rpage->math_html;
-                       $this->mathml = $rpage->math_mathml;
-                       $this->recall = true;
+                       $this->initializeFromDBRow($rpage);
                        return true;
                }
 
@@ -146,31 +186,49 @@
                $this->recall = false;
                return false;
        }
-
+       /**
+        * @return Ambigous <multitype:, multitype:unknown number string mixed >
+        */
+       private function dbOutArray(){
+               global $wgDebugMath;
+               $dbr = wfGetDB( DB_SLAVE );
+               if ( $this->hash )
+                       $outmd5_sql = $dbr->encodeBlob( pack( 'H32', 
$this->hash ) );
+               else
+                       $outmd5_sql = 0; //field cannot be null
+               //TODO: Change Database layout to allow for null values
+               $out= array(
+                               'math_inputhash' => $this->getInputHash(),
+                               'math_outputhash' => $outmd5_sql ,
+                               'math_html_conservativeness' => 
$this->conservativeness,
+                               'math_html' => $this->html,
+                               'math_mathml' => utf8_encode($this->mathml));
+               if ($wgDebugMath){
+                       $debug_out= array(
+                                       'math_status' => $this->status_code,
+                                       'valid_xml' => $this->valid_xml,
+                                       'math_tex' => $this->tex,
+                                       'math_log' => $this->log);
+                       $out=array_merge($out,$debug_out);
+               }
+               wfDebugLog("Math","storeVAL:".var_export(utf8_encode ( 
$this->mathml),true)."ENDStoreVAL");
+               return $out;
+       }
        /**
         * Writes rendering entry to database
         */
-       protected function writeDBEntry() {
+       protected function writeDBEntry( $dbw=null ) {
                # Now save it back to the DB:
-               if ( !wfReadOnly() ) {
-                       $dbw = wfGetDB( DB_MASTER );
-                       if ( $this->hash ) {
-                               $outmd5_sql = $dbw->encodeBlob( pack( 'H32', 
$this->hash ) );
-                       } else {
-                               $outmd5_sql = null;
+                       if ( !wfReadOnly() ) {
+                       if($dbw==null){
+                               $dbw = wfGetDB( DB_MASTER );
                        }
                        wfDebugLog( "Math", 'store entry for $' . $this->tex . 
'$ in database (hash:' . $this->getInputHash() . ')\n' );
-                       $dbw->replace(
-                               'math',
-                               array( 'math_inputhash' ),
-                               array(
-                                       'math_inputhash' => 
$this->getInputHash(),
-                                       'math_outputhash' => $outmd5_sql ,
-                                       'math_html_conservativeness' => 
$this->conservativeness,
-                                       'math_html' => $this->html,
-                                       'math_mathml' => $this->mathml,
-                                       ),
-                               __METHOD__
+                       $outArray=$this->dbOutArray();
+                       $dbw->onTransactionIdle(
+                               function () use ($dbw,$outArray){
+                                       $dbw->replace('math', array( 
'math_inputhash' ), $outArray, __METHOD__);
+                                       }
                        );
                }
        }
@@ -203,7 +261,19 @@
        public function isRecall() {
                return $this->recall;
        }
-
+       /**
+        * returns true if the rendering was successful
+        * @return boolean
+        */
+       public function isSuccess() {
+               return $this->success;
+       }
+       /**
+        *
+        */
+       public function setSuccess($b) {
+               $this->success=$b;
+       }
        /**
         * Gets anchor ID
         *
@@ -230,4 +300,10 @@
        public function getTex() {
                return $this->tex;
        }
+       /**
+        * get the timestamp, of the last rending of that equation
+        */
+       public function getTimestamp(){
+               return $this->timestamp;
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/49488
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic9e8ee7558e0496e3cffd4d3e8bea7a4c0c7d276
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to