Gallery: Use Parser::parseWidthParam() for gallery dimensions
[lhc/web/wiklou.git] / includes / gallery / ImageGalleryBase.php
index 6884f65..700c8ee 100644 (file)
@@ -38,6 +38,11 @@ abstract class ImageGalleryBase extends ContextSource {
         */
        protected $mShowBytes;
 
+       /**
+        * @var bool Whether to show the dimensions in categories
+        */
+       protected $mShowDimensions;
+
        /**
         * @var bool Whether to show the filename. Default: true
         */
@@ -136,6 +141,7 @@ abstract class ImageGalleryBase extends ContextSource {
                $galleryOptions = $this->getConfig()->get( 'GalleryOptions' );
                $this->mImages = [];
                $this->mShowBytes = $galleryOptions['showBytes'];
+               $this->mShowDimensions = $galleryOptions['showDimensions'];
                $this->mShowFilename = true;
                $this->mParser = false;
                $this->mHideBadImages = false;
@@ -171,7 +177,7 @@ abstract class ImageGalleryBase extends ContextSource {
        /**
         * Set the caption (as plain text)
         *
-        * @param string $caption Caption
+        * @param string $caption
         */
        function setCaption( $caption ) {
                $this->mCaption = htmlspecialchars( $caption );
@@ -180,7 +186,7 @@ abstract class ImageGalleryBase extends ContextSource {
        /**
         * Set the caption (as HTML)
         *
-        * @param string $caption Caption
+        * @param string $caption
         */
        public function setCaptionHtml( $caption ) {
                $this->mCaption = $caption;
@@ -201,22 +207,26 @@ abstract class ImageGalleryBase extends ContextSource {
        /**
         * Set how wide each image will be, in pixels.
         *
-        * @param int $num Integer > 0; invalid numbers will be ignored
+        * @param string $num Number. Unit other than 'px is invalid. Invalid numbers
+        *   and those below 0 are ignored.
         */
        public function setWidths( $num ) {
-               if ( $num > 0 ) {
-                       $this->mWidths = (int)$num;
+               $parsed = Parser::parseWidthParam( $num, false );
+               if ( isset( $parsed['width'] ) && $parsed['width'] > 0 ) {
+                       $this->mWidths = $parsed['width'];
                }
        }
 
        /**
         * Set how high each image will be, in pixels.
         *
-        * @param int $num Integer > 0; invalid numbers will be ignored
+        * @param string $num Number. Unit other than 'px is invalid. Invalid numbers
+        *   and those below 0 are ignored.
         */
        public function setHeights( $num ) {
-               if ( $num > 0 ) {
-                       $this->mHeights = (int)$num;
+               $parsed = Parser::parseWidthParam( $num, false );
+               if ( isset( $parsed['width'] ) && $parsed['width'] > 0 ) {
+                       $this->mHeights = $parsed['width'];
                }
        }
 
@@ -283,6 +293,16 @@ abstract class ImageGalleryBase extends ContextSource {
                return empty( $this->mImages );
        }
 
+       /**
+        * Enable/Disable showing of the dimensions of an image in the gallery.
+        * Enabled by default.
+        *
+        * @param bool $f Set to false to disable
+        */
+       function setShowDimensions( $f ) {
+               $this->mShowDimensions = (bool)$f;
+       }
+
        /**
         * Enable/Disable showing of the file size of an image in the gallery.
         * Enabled by default.