TheDJ has uploaded a new change for review.

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

Change subject: Math: Retrieve dimensions of math images
......................................................................

Math: Retrieve dimensions of math images

no patches other than mysql
no updates of already rendered stuff

Bug: 20202
Change-Id: Ie05162223d386a47e92609ece2ed1ecbb79f317c
---
M Math.hooks.php
M MathRenderer.php
M MathTexvc.php
M db/math.mssql.sql
M db/math.oracle.sql
M db/math.pg.sql
M db/math.sql
A db/patches/math-imgwidth-height-field.sql
8 files changed, 63 insertions(+), 5 deletions(-)


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

diff --git a/Math.hooks.php b/Math.hooks.php
index 60eb2f0..3efc8eb 100644
--- a/Math.hooks.php
+++ b/Math.hooks.php
@@ -246,6 +246,12 @@
                        throw new MWException( "Math extension does not 
currently support $type database." );
                }
 
+               // Apply patches
+               if ( $type === 'mysql' ) {
+                       $updater->addExtensionField( 'math', 'math_image_width',
+                               dirname( __FILE__ ) . '/db/patches/' . 
'math-imgwidth-height.sql' );
+               }
+
                return true;
        }
 
diff --git a/MathRenderer.php b/MathRenderer.php
index 088c351..dd17713 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -40,6 +40,9 @@
        protected $mathml = '';
        protected $conservativeness = 0;
        protected $params = '';
+       protected $imageWidth;
+       protected $imageHeight;
+
        // STATE OF THE CLASS INSTANCE
        /** @var boolean has variable tex been security-checked */
        protected $texSecure = false;
@@ -209,6 +212,8 @@
                $this->html = $rpage->math_html;
                $this->mathml = utf8_decode( $rpage->math_mathml );
                $this->storedInDatabase = true;
+               $this->imageWidth = $rpage->math_img_width;
+               $this->imageHeight = $rpage->math_img_height;
        }
 
        /**
@@ -216,7 +221,7 @@
         */
        private function dbInArray() {
                return array( 'math_inputhash', 'math_outputhash', 
'math_html_conservativeness', 'math_html',
-                               'math_mathml' );
+                               'math_mathml', 'math_img_width', 
'math_img_height' );
        }
        /**
         * Writes rendering entry to database.
@@ -254,7 +259,8 @@
                }
                $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 ) );
+                               'math_mathml' => utf8_encode( $this->mathml ),
+                               'math_img_width' => $this->getImageWidth(), 
'math_img_height' => $this->getImageHeight() );
                wfDebugLog( "Math", "Store Data:" . var_export( $out, true ) . 
"\n\n" );
                return $out;
        }
@@ -496,5 +502,24 @@
        public function getUserInputTex() {
                return $this->userInputTex;
        }
+
+       public function getImageWidth() {
+               return $this->imageWidth;
+       }
+
+       public function setImageWidth( $width ) {
+               $this->changed = true;
+               $this->imageWidth = $width;
+       }
+
+       public function getImageHeight() {
+               return $this->imageHeight;
+       }
+
+       public function setImageHeight( $height ) {
+               $this->changed = true;
+               $this->imageHeight = $height;
+       }
+
 }
 
diff --git a/MathTexvc.php b/MathTexvc.php
index 37e4b70..0ccbee6 100644
--- a/MathTexvc.php
+++ b/MathTexvc.php
@@ -85,6 +85,12 @@
                        'class' => 'mwe-math-fallback-png-inline tex',
                        'alt' => $this->getTex()
                );
+               if ( $this->getImageWidth() !== null && $this->getImageHeight() 
!== null ) {
+                       $attributes[ 'height' ] = $this->getImageHeight();
+                       $attributes[ 'width' ] = $this->getImageWidth();
+               } else {
+                       wfDebugLog( "Math", "No image sizes for 
{$this->getHash()}" );
+               }
                if ( $this->getMathStyle() === MW_MATHSTYLE_DISPLAY ){
                        // if DisplayStyle is true, the equation will be 
centered in a new line
                        $attributes[ 'class' ] = 'mwe-math-fallback-png-display 
tex';
@@ -224,6 +230,13 @@
                        return $this->getError( 'math_image_error' );
                }
 
+               // Get dimensions of file
+               $imgsize = getimagesize( "$tmpDir/{$this->getHash()}.png" );
+               if ( $imgsize ) {
+                       $this->setImageWidth( $imgsize[ 0 ] );
+                       $this->setImageHeight( $imgsize[ 1 ] );
+               }
+
                $hashpath = $this->getHashPath(); // final storage directory
 
                $backend = $this->getBackend();
diff --git a/db/math.mssql.sql b/db/math.mssql.sql
index a74d26d..6182ca1 100644
--- a/db/math.mssql.sql
+++ b/db/math.mssql.sql
@@ -8,4 +8,6 @@
    math_html_conservativeness tinyint NOT NULL,
    math_html NVARCHAR(MAX),
    math_mathml NVARCHAR(MAX),
+   math_img_width int,
+   math_img_height int,
 );
diff --git a/db/math.oracle.sql b/db/math.oracle.sql
index 9e40d29..b6e3c6e 100644
--- a/db/math.oracle.sql
+++ b/db/math.oracle.sql
@@ -3,6 +3,8 @@
   math_outputhash             VARCHAR2(32)      NOT NULL,
   math_html_conservativeness  NUMBER  NOT NULL,
   math_html                   CLOB,
-  math_mathml                 CLOB
+  math_mathml                 CLOB,
+  math_img_width              NUMBER,
+  math_img_height             NUMBER
 );
 CREATE UNIQUE INDEX &mw_prefix.math_u01 ON &mw_prefix.math (math_inputhash);
diff --git a/db/math.pg.sql b/db/math.pg.sql
index e42eada..92f0a9e 100644
--- a/db/math.pg.sql
+++ b/db/math.pg.sql
@@ -3,5 +3,7 @@
   math_outputhash             BYTEA     NOT NULL,
   math_html_conservativeness  SMALLINT  NOT NULL,
   math_html                   TEXT,
-  math_mathml                 TEXT
+  math_mathml                 TEXT,
+  math_img_width              INT,
+  math_img_height             INT
 );
diff --git a/db/math.sql b/db/math.sql
index f509555..cfe6d32 100644
--- a/db/math.sql
+++ b/db/math.sql
@@ -17,7 +17,13 @@
   math_html text,
 
   -- MathML output from texvc, or from LaTeXML
-  math_mathml text
+  math_mathml text,
+
+  -- Math image's width
+  math_img_width int default NULL,
+
+  -- Math image's height
+  math_img_height int default NULL,
 ) /*$wgDBTableOptions*/;
 
 CREATE UNIQUE INDEX /*i*/math_inputhash ON /*_*/math (math_inputhash);
diff --git a/db/patches/math-imgwidth-height-field.sql 
b/db/patches/math-imgwidth-height-field.sql
new file mode 100644
index 0000000..7404ed3
--- /dev/null
+++ b/db/patches/math-imgwidth-height-field.sql
@@ -0,0 +1,2 @@
+ALTER TABLE /*_*/math ADD COLUMN math_img_width int default null;;
+ALTER TABLE /*_*/math ADD COLUMN math_img_height int default null;;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie05162223d386a47e92609ece2ed1ecbb79f317c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: TheDJ <hartman.w...@gmail.com>

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

Reply via email to