Physikerwelt has submitted this change and it was merged.

Change subject: New Feature: size of output
......................................................................


New Feature: size of output

* calculates the size of output
* adjust Formulainfo to Math 2.0

Change-Id: If45f0f101d8d696884602f9249ed74c1018f9b0f
---
M FormulaInfo.php
M MathObject.php
M SpecialMathSearch.php
3 files changed, 136 insertions(+), 96 deletions(-)

Approvals:
  Physikerwelt: Verified; Looks good to me, approved



diff --git a/FormulaInfo.php b/FormulaInfo.php
index 326dbd3..536c7b6 100644
--- a/FormulaInfo.php
+++ b/FormulaInfo.php
@@ -42,6 +42,9 @@
                        return false;
                }
                $wgOut->addWikiText( "Info for <code>" . $tex . '</code>' );
+               /**
+                * @var MathObject Description
+                */
                $mo = new MathObject( $tex );
                $allPages = $mo->getAllOccurences();
                if ( $allPages ) {
@@ -51,48 +54,81 @@
                }
        }
        public static function DisplayInfo( $pid, $eid ) {
-               global $wgOut, $wgMathDebug;
-               $wgOut->addWikiText( '==General==' );
-               $wgOut->addWikiText( 'Display information for equation id:' . 
$eid . ' on page id:' . $pid );
+               global $wgMathDebug, $wgOut;
+               /* $out Output page find out how to get that variable in a 
static context*/
+               $out = $wgOut;
+               $out->addWikiText( '==General==' );
+               $out->addWikiText( 'Display information for equation id:' . 
$eid . ' on page id:' . $pid );
                $article = Article::newFromId( $pid );
                if ( !$article ) {
-                       $wgOut->addWikiText( 'There is no page with page id:' . 
$pid . ' in the database.' );
+                       $out->addWikiText( 'There is no page with page id:' . 
$pid . ' in the database.' );
                        return false;
                }
 
                $pagename = (string)$article->getTitle();
-               $wgOut->addWikiText( "* Page found: 
[[$pagename#math$eid|$pagename]] (eq $eid)  ", false );
-               $wgOut->addHtml( '<a href="/index.php?title=' . $pagename . 
'&action=purge&mathpurge=true">(force rerendering)</a>' );
+               $out->addWikiText( "* Page found: 
[[$pagename#math$eid|$pagename]] (eq $eid)  ", false );
+               $out->addHtml( '<a href="/index.php?title=' . $pagename . 
'&action=purge&mathpurge=true">(force rerendering)</a>' );
+
+               /* @var $mo MathObject  */
                $mo = MathObject::constructformpage( $pid, $eid );
-               $wgOut->addWikiText( "Occurences on the following pages:" );
+               $out->addWikiText( "Occurences on the following pages:" );
                wfDebugLog( "MathSearch", var_export( $mo->getAllOccurences(), 
true ) );
                // $wgOut->addWikiText('<b>:'.var_export($res,true).'</b>');
-               $wgOut->addWikiText( 'TeX (as stored in database): 
<syntaxhighlight>' . $mo->getTex(). '</syntaxhighlight>');
-
-               $wgOut->addWikiText( 'MathML : ', false );
-               $wgOut->addHTML( $mo->getMathml() );
-               $wgOut->addHtml( '<a href="/wiki/Special:MathSearch?pattern=' . 
urlencode( $mo->getTex() ) . '&searchx=Search"><img 
src="http://wikidemo.formulasearchengine.com/images/FSE-PIC.png"; width="15" 
height="15"></a>' );
+               $out->addWikiText( 'TeX (as stored in database): 
<syntaxhighlight>' . $mo->getTex(). '</syntaxhighlight>');
+               $out->addWikiText( 'MathML 
('.self::getlengh($mo->getMathml()).') :', false );
+               $out->addHtml( '<a href="/wiki/Special:MathSearch?mathpattern=' 
. urlencode( $mo->getTex() ) . '&searchx=Search"><img 
src="http://wikidemo.formulasearchengine.com/images/FSE-PIC.png"; width="15" 
height="15"></a>' );
+               $out->addHtml(  $mo->getMathml() );
                # $log=htmlspecialchars( $res->math_log );
-               $wgOut->addWikiText( '==Similar pages==' );
-               $wgOut->addWikiText( 'Calculataed based on the variables 
occuring on the entire ' . $pagename . ' page' );
+               $out->addHtml( "<br />\n" );
+               $out->addWikiText( 'SVG ('.self::getlengh($mo->getSvg()).') :', 
false );
+               $out->addHtml( $mo->getFallbackImage( false , true, '' ));
+               $out->addHtml( "<br />\n" );
+               $out->addWikiText( 'PNG ('.self::getlengh($mo->getPng()).') :', 
false );
+               $out->addHtml($mo->getFallbackImage( true , true , ''));
+               $out->addHtml( "<br />\n" );
+               $out->addWikiText( 'Hash : '.$mo->getMd5(), false );
+               $out->addHtml( "<br />" );
+               $out->addWikiText( '==Similar pages==' );
+               $out->addWikiText( 'Calculataed based on the variables occuring 
on the entire ' . $pagename . ' page' );
                $mo->findSimilarPages( $pid );
-               $wgOut->addWikiText( '==Variables==' );
+               $out->addWikiText( '==Variables==' );
                $mo->getObservations();
                // $wgOut->addWikiText( "[[$pagename#math$eid|Eq: $eid]] ", 
false );
-               $wgOut->addWikiText( '==MathML==' );
+               $out->addWikiText( '==MathML==' );
 
-               $wgOut->addHtml( "<br />" );
-               $wgOut->addWikiText( '<syntaxhighlight lang="xml">'.( 
$mo->getMathml() ).'</syntaxhighlight>');
-               $wgOut->addHtml( "<br />" );
-               $wgOut->addHtml( "<br />" );
+               $out->addHtml( "<br />" );
+               $out->addHtml('<div class="NavFrame"><div 
class="NavHead">mathml</div>
+<div class="NavContent">');
+               $out->addWikiText( '<syntaxhighlight lang="xml" >'.( 
$mo->getMathml() ).'</syntaxhighlight>');
+               $out->addHtml('</div></div>');
+               $out->addHtml( "<br />" );
+               $out->addHtml( "<br />" );
                if ( $wgMathDebug ) {
-               $wgOut->addWikiText( '==LOG and Debug==' );
-               $wgOut->addWikiText( 'Rendered at : <syntaxhighlight>' . 
$mo->getTimestamp()
+               $out->addWikiText( '==LOG and Debug==' );
+               $out->addWikiText( 'Rendered at : <syntaxhighlight>' . 
$mo->getTimestamp()
                        . '</syntaxhighlight> an idexed at <syntaxhighlight>' . 
$mo->getIndexTimestamp() . '</syntaxhighlight>' );
-               $wgOut->addWikiText( 'validxml : <syntaxhighlight>' . 
$mo->isValidMathML( $mo->getMathml() ) . '</syntaxhighlight> recheck:', false );
-               $wgOut->addHtml( $mo->isValidMathML( $mo->getMathml() ) ? 
"valid":"invalid" );
-               $wgOut->addWikiText( 'status : <syntaxhighlight>' . 
$mo->getStatusCode() . '</syntaxhighlight>' );
-               $wgOut->addHtml( htmlspecialchars( $mo->getLog() ) );
+               $out->addWikiText( 'validxml : <syntaxhighlight>' . 
$mo->isValidMathML( $mo->getMathml() ) . '</syntaxhighlight> recheck:', false );
+               $out->addHtml( $mo->isValidMathML( $mo->getMathml() ) ? 
"valid":"invalid" );
+               $out->addWikiText( 'status : <syntaxhighlight>' . 
$mo->getStatusCode() . '</syntaxhighlight>' );
+               $out->addHtml( htmlspecialchars( $mo->getLog() ) );
                }
        }
+       private static function getlengh($binray){
+               $uncompressed = strlen( $binray );
+               $compressed = strlen(gzcompress ($binray));
+               return self::formatBytes($uncompressed). " / 
".self::formatBytes($compressed) ;
+       }
+               private static function formatBytes($bytes, $precision = 3) {
+                       $units = array('B', 'KB', 'MB', 'GB', 'TB');
+
+                       $bytes = max($bytes, 0);
+                       $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
+                       $pow = min($pow, count($units) - 1);
+
+                       // Uncomment one of the following alternatives
+                       $bytes /= pow(1024, $pow);
+                       //$bytes /= (1 << (10 * $pow));
+
+               return round($bytes, $precision) . ' ' . $units[$pow];
+       }
 }
diff --git a/MathObject.php b/MathObject.php
index 7944bcc..51b1535 100644
--- a/MathObject.php
+++ b/MathObject.php
@@ -1,9 +1,10 @@
 <?php
-class MathObject extends MathLaTeXML {
+
+class MathObject extends MathMathML {
+
        protected $anchorID = 0;
        protected $pageID = 0;
        protected $index_timestamp = null;
-       protected $inputHash = '';
 
        private static function DebugPrint( $s ) {
                // $s= Sanitizer::safeEncodeAttribute($s);
@@ -13,18 +14,23 @@
        public function getAnchorID() {
                return $this->anchorID;
        }
+
        public function setAnchorID( $ID ) {
                $this->anchorID = $ID;
        }
+
        public function getPageID() {
                return $this->pageID;
        }
+
        public function setPageID( $ID ) {
                $this->pageID = $ID;
        }
+
        public function getIndexTimestamp() {
                return $this->index_timestamp;
        }
+
        public function getInputHash() {
                wfDebugLog( 'MathSearch', 'Debugger dies here' );
                // die('end of debug toolbar');
@@ -34,19 +40,20 @@
                        return parent::getInputHash();
                }
        }
+
        public static function constructformpagerow( $res ) {
                global $wgMathDebug;
                if ( $res->mathindex_page_id > 0 ) {
-               $instance = new self();
-               $instance->setPageID( $res->mathindex_page_id );
-               $instance->setAnchorID( $res->mathindex_anchor );
-               if ( $wgMathDebug ) {
-                       $instance->index_timestamp = $res->mathindex_timestamp;
-               }
-               $instance->inputHash = $res->mathindex_inputhash;
-               $instance->readFromDatabase();
-               self::DebugPrint( 'got' . var_export( $instance, true ) );
-               return $instance;
+                       $instance = new self();
+                       $instance->setPageID( $res->mathindex_page_id );
+                       $instance->setAnchorID( $res->mathindex_anchor );
+                       if ( $wgMathDebug ) {
+                               $instance->index_timestamp = 
$res->mathindex_timestamp;
+                       }
+                       $instance->inputHash = $res->mathindex_inputhash;
+                       $instance->readFromDatabase();
+                       self::DebugPrint( 'got' . var_export( $instance, true ) 
);
+                       return $instance;
                } else {
                        return false;
                }
@@ -57,54 +64,51 @@
                $out = "";
                $dbr = wfGetDB( DB_SLAVE );
                try {
-               $res = $dbr->select( 'mathpagesimilarity',
-                       array( 'pagesimilarity_A as A', 'pagesimilarity_B as 
B', 'pagesimilarity_Value as V' ),
-                       "pagesimilarity_A=$pid OR pagesimilarity_B=$pid",
-                       __METHOD__,
-                       array( "ORDER BY" => 'V DESC', "LIMIT" => 10 )
+                       $res = $dbr->select( 'mathpagesimilarity', array( 
'pagesimilarity_A as A', 'pagesimilarity_B as B', 'pagesimilarity_Value as V' 
), "pagesimilarity_A=$pid OR pagesimilarity_B=$pid", __METHOD__, array(
+                               "ORDER BY" => 'V DESC', "LIMIT" => 10 )
                        );
-               foreach ( $res as $row ) {
-                       if ( $row->A == $pid ) {
-                               $other = $row->B;
-                       } else {
-                               $other = $row->A;
+                       foreach ( $res as $row ) {
+                               if ( $row->A == $pid ) {
+                                       $other = $row->B;
+                               } else {
+                                       $other = $row->A;
+                               }
+                               $article = WikiPage::newFromId( $other );
+                               $out .= '# [[' . $article->getTitle() . ']] 
similarity ' .
+                                               $row->V * 100 . "%\n";
+                               // .' ( pageid'.$other.'/'.$row->A.')' );
                        }
-                       $article = WikiPage::newFromId( $other );
-                       $out .= '# [[' . $article->getTitle() . ']] similarity 
' .
-                                       $row->V * 100 . "%\n";
-                                       // .' ( pageid'.$other.'/'.$row->A.')' 
);
-               }
-               $wgOut->addWikiText( $out );
+                       $wgOut->addWikiText( $out );
                } catch ( Exception $e ) {
                        return "DatabaseProblem";
                }
        }
+
        public function getObservations() {
                global $wgOut;
                $dbr = wfGetDB( DB_SLAVE );
                try {
-               $res = $dbr->select( array( "mathobservation", "mathvarstat", 
'mathpagestat' )
-                               , array( "mathobservation_featurename", 
"mathobservation_featuretype", 'varstat_featurecount',
-                                               'pagestat_featurecount', 
"count(*) as localcnt" ),
-                               array( "mathobservation_inputhash" => 
$this->getInputHash(),
-                                               'varstat_featurename = 
mathobservation_featurename',
-                                               'varstat_featuretype = 
mathobservation_featuretype',
-                                               'pagestat_pageid' => 
$this->getPageID(),
-                                               'pagestat_featureid = 
varstat_id'
-                                               )
-                               , __METHOD__,
-                               array( 'GROUP BY' => 
'mathobservation_featurename',
-                                               'ORDER BY' => 
'varstat_featurecount' )
-                               );
+                       $res = $dbr->select( array( "mathobservation", 
"mathvarstat", 'mathpagestat' )
+                                       , array( "mathobservation_featurename", 
"mathobservation_featuretype", 'varstat_featurecount',
+                               'pagestat_featurecount', "count(*) as localcnt" 
), array( "mathobservation_inputhash" => $this->getInputHash(),
+                               'varstat_featurename = 
mathobservation_featurename',
+                               'varstat_featuretype = 
mathobservation_featuretype',
+                               'pagestat_pageid' => $this->getPageID(),
+                               'pagestat_featureid = varstat_id'
+                                       )
+                                       , __METHOD__, array( 'GROUP BY' => 
'mathobservation_featurename',
+                               'ORDER BY' => 'varstat_featurecount' )
+                       );
                } catch ( Exception $e ) {
                        return "Databaseproblem";
                }
                if ( $res ) {
-               foreach ( $res as $row ) {
-                       $wgOut->addWikiText( '*' . 
$row->mathobservation_featuretype . ' <code>' .
-                                       utf8_decode( 
$row->mathobservation_featurename ) . '</code> (' . $row->localcnt . '/'
-                                       . $row->pagestat_featurecount . "/" . 
$row->varstat_featurecount . ')' );
-               } }
+                       foreach ( $res as $row ) {
+                               $wgOut->addWikiText( '*' . 
$row->mathobservation_featuretype . ' <code>' .
+                                               utf8_decode( 
$row->mathobservation_featurename ) . '</code> (' . $row->localcnt . '/'
+                                               . $row->pagestat_featurecount . 
"/" . $row->varstat_featurecount . ')' );
+                       }
+               }
        }
 
        public function updateObservations( $dbw = null ) {
@@ -120,23 +124,20 @@
                $dbw->delete( "mathobservation", array( 
"mathobservation_inputhash" => $this->getInputHash() ) );
                foreach ( $rule as $feature ) {
                        $dbw->insert( "mathobservation", array(
-                                       "mathobservation_inputhash" => 
$this->getInputHash(),
-                                       "mathobservation_featurename" => 
utf8_encode( $feature[4] ),
-                                       "mathobservation_featuretype" => 
utf8_encode( $feature[1] ),
+                               "mathobservation_inputhash" => 
$this->getInputHash(),
+                               "mathobservation_featurename" => utf8_encode( 
$feature[ 4 ] ),
+                               "mathobservation_featuretype" => utf8_encode( 
$feature[ 1 ] ),
                        ) );
-               if ( !$dbgiven ) {
-                       $dbw->commit();
+                       if ( !$dbgiven ) {
+                               $dbw->commit();
                        }
-
                }
-
        }
+
        public static function constructformpage( $pid, $eid ) {
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->selectRow(
-                               array( 'mathindex' ),
-                               self::dbIndexFieldsArray(),
-                               'mathindex_page_id = ' . $pid
+                               array( 'mathindex' ), 
self::dbIndexFieldsArray(), 'mathindex_page_id = ' . $pid
                                . ' AND mathindex_anchor= ' . $eid
                );
                self::DebugPrint( var_export( $res, true ) );
@@ -148,12 +149,10 @@
         * @return array(MathObject)
         */
        public function getAllOccurences() {
-               $out = array();
+               $out = array( );
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select(
-                               'mathindex',
-                               self::dbIndexFieldsArray(),
-                               array( 'mathindex_inputhash' => 
$this->getInputHash() )
+                               'mathindex', self::dbIndexFieldsArray(), array( 
'mathindex_inputhash' => $this->getInputHash() )
                );
 
                foreach ( $res as $row ) {
@@ -166,15 +165,16 @@
                }
                return $out;
        }
+
        public function getPageTitle() {
                $article = Article::newFromId( $this->getPageID() );
-               return (string)$article->getTitle();
+               return (string) $article->getTitle();
        }
 
        public function printLink2Page( $hidePage = true ) {
                global $wgOut;
                $wgOut->addHtml( "&nbsp;&nbsp;&nbsp;" );
-               $pageString = $hidePage ? "":$this->getPageTitle() . " ";
+               $pageString = $hidePage ? "" : $this->getPageTitle() . " ";
                $wgOut->addWikiText( "[[" . $this->getPageTitle() . "#math" . 
$this->getAnchorID()
                                . "|" . $pageString . "Eq: " . 
$this->getAnchorID() . "]] ", false );
                // $wgOut->addHtml( MathLaTeXML::embedMathML( $this->mathml ) );
@@ -187,12 +187,12 @@
        private static function dbIndexFieldsArray() {
                global $wgMathDebug;
                $in = array(
-                               'mathindex_page_id',
-                               'mathindex_anchor'  ,
-                               'mathindex_inputhash' );
+                       'mathindex_page_id',
+                       'mathindex_anchor',
+                       'mathindex_inputhash' );
                if ( $wgMathDebug ) {
                        $debug_in = array(
-                                       'mathindex_timestamp' );
+                               'mathindex_timestamp' );
                        $in = array_merge( $in, $debug_in );
                }
                return $in;
@@ -201,15 +201,17 @@
        public function render( $purge = false ) {
 
        }
+
 }
+
 /*
  * $sql = "INSERT INTO varstat (\n"
     . "`varstat_featurename` ,\n"
     . "` varstat_featuretype` ,\n"
     . "`varstat_featurecount`\n"
     . ") SELECT `mathobservation_featurename`,`mathobservation_featuretype`, 
count(*) as CNT FROM `mathobservation` JOIN mathindex on 
`mathobservation_inputhash` =mathindex_inputhash GROUP by 
`mathobservation_featurename`, `mathobservation_featuretype` ORDER BY CNT DESC";
-    
-    
+
+
     $sql = "INSERT INTO 
mathpagestat(`pagestat_featurename`,`pagestat_featuretype`,`pagestat_pageid`,`pagestat_featurecount`)\n"
     . "SELECT 
`mathobservation_featurename`,`mathobservation_featuretype`,mathindex_page_id, 
count(*) as CNT FROM `mathobservation` JOIN mathindex on 
`mathobservation_inputhash` =mathindex_inputhash GROUP by 
`mathobservation_featurename`, `mathobservation_featuretype`,mathindex_page_id 
ORDER BY CNT DESC";
  */
\ No newline at end of file
diff --git a/SpecialMathSearch.php b/SpecialMathSearch.php
index 31aeb4a..6a5368f 100644
--- a/SpecialMathSearch.php
+++ b/SpecialMathSearch.php
@@ -148,7 +148,9 @@
                                                
$domRes->setAttribute('mathcolor', '#cc0000');
                                                $out->addHtml( 
$domRes->ownerDocument->saveXML());
                                        } else {
-                                               
$out->addHtml(MathLaTeXML::embedMathML($mml));
+                                               $renderer = new MathMathML();
+                                               $renderer->setMathml($mml);
+                                               
$out->addHtml($renderer->getHtmlOutput());
                                        }
                                }
 
@@ -270,7 +272,7 @@
         * @return boolean
         */
        function render() {
-               $renderer = new MathLaTeXML($this->mathpattern);
+               $renderer = new MathMathML($this->mathpattern);
                $renderer->setLaTeXMLSettings('profile=mwsquery');
                $renderer->setAllowedRootElments(array('query'));
                $renderer->render(true);

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

Gerrit-MessageType: merged
Gerrit-Change-Id: If45f0f101d8d696884602f9249ed74c1018f9b0f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MathSearch
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <w...@physikerwelt.de>
Gerrit-Reviewer: Physikerwelt <w...@physikerwelt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to