Brian Wolff has uploaded a new change for review.

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


Change subject: getPageDimensions failure handling incorrect
......................................................................

getPageDimensions failure handling incorrect

getPageDimensions returning false for failure wasn't being handled
properly, causing ugly output. As well the doc comment on that
method was wrong.

Most notably causing random whitespace output. aka:
https://commons.wikimedia.org/wiki/?curid=22151015

Bug: 41281
Change-Id: I1a49474309e15808928f877dfc29ae366d028928
---
M RELEASE-NOTES-1.22
M includes/filerepo/file/LocalFile.php
M includes/media/MediaHandler.php
3 files changed, 22 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/30/59530/1

diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22
index b360979..b6a70cc 100644
--- a/RELEASE-NOTES-1.22
+++ b/RELEASE-NOTES-1.22
@@ -31,6 +31,7 @@
   navigate to the page by entering the URL directly.
 * (bug 47138) Fixed a fatal error when a blocked user tries to automatically
   create an account on login due external authentication in some circumstances.
+* (bug 41281) Ugly output if file size could not be extracted for multi-page 
media.
 
 === API changes in 1.22 ===
 * (bug 46626) xmldoublequote parameter was removed. Because of a bug, the
diff --git a/includes/filerepo/file/LocalFile.php 
b/includes/filerepo/file/LocalFile.php
index b481e83..17cc915 100644
--- a/includes/filerepo/file/LocalFile.php
+++ b/includes/filerepo/file/LocalFile.php
@@ -604,7 +604,7 @@
         * Return the width of the image
         *
         * @param $page int
-        * @return bool|int Returns false on error
+        * @return int
         */
        public function getWidth( $page = 1 ) {
                $this->load();
@@ -614,7 +614,9 @@
                        if ( $dim ) {
                                return $dim['width'];
                        } else {
-                               return false;
+                               // For non-paged media, the false goes through 
an
+                               // intval, turning failure into 0, so do same 
here.
+                               return 0;
                        }
                } else {
                        return $this->width;
@@ -625,7 +627,7 @@
         * Return the height of the image
         *
         * @param $page int
-        * @return bool|int Returns false on error
+        * @return int
         */
        public function getHeight( $page = 1 ) {
                $this->load();
@@ -635,7 +637,9 @@
                        if ( $dim ) {
                                return $dim['height'];
                        } else {
-                               return false;
+                               // For non-paged media, the false goes through 
an
+                               // intval, turning failure into 0, so do same 
here.
+                               return 0;
                        }
                } else {
                        return $this->height;
diff --git a/includes/media/MediaHandler.php b/includes/media/MediaHandler.php
index b67f3d3..71c0d3b 100644
--- a/includes/media/MediaHandler.php
+++ b/includes/media/MediaHandler.php
@@ -300,18 +300,24 @@
         * Get an associative array of page dimensions
         * Currently "width" and "height" are understood, but this might be
         * expanded in the future.
-        * Returns false if unknown or if the document is not multi-page.
+        * Returns false if unknown.
+        *
+        * @note For non-paged media, use getImageSize.
         *
         * @param $image File
-        * @param $page Unused, left for backcompatibility?
-        * @return array
+        * @param $page What page to get dimensions of
+        * @return array|bool
         */
        function getPageDimensions( $image, $page ) {
                $gis = $this->getImageSize( $image, $image->getLocalRefPath() );
-               return array(
-                       'width' => $gis[0],
-                       'height' => $gis[1]
-               );
+               if ( $gis ) {
+                       return array(
+                               'width' => $gis[0],
+                               'height' => $gis[1]
+                       );
+               } else {
+                       return false;
+               }
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1a49474309e15808928f877dfc29ae366d028928
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <bawolff...@gmail.com>

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

Reply via email to