Avoid undefined offset for $wgImageLimits
authorumherirrender <umherirrender_de.wp@web.de>
Sat, 2 Feb 2013 13:48:33 +0000 (14:48 +0100)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Sun, 10 Feb 2013 12:36:25 +0000 (13:36 +0100)
This can happen, when customized $wgImageLimits, but not
the option in $wgDefaultOptions

Notice:  Undefined offset: 2 in \includes\ImagePage.php on line 364

Change-Id: I1dbcde8782f239279602f509e5987606af8db241

includes/ImagePage.php

index 953b1f7..3337ffd 100644 (file)
@@ -298,18 +298,7 @@ class ImagePage extends Article {
                $dirmark = $lang->getDirMarkEntity();
                $request = $this->getContext()->getRequest();
 
-               $sizeSel = intval( $user->getOption( 'imagesize' ) );
-               if ( !isset( $wgImageLimits[$sizeSel] ) ) {
-                       $sizeSel = User::getDefaultOption( 'imagesize' );
-
-                       // The user offset might still be incorrect, specially if
-                       // $wgImageLimits got changed (see bug #8858).
-                       if ( !isset( $wgImageLimits[$sizeSel] ) ) {
-                               // Default to the first offset in $wgImageLimits
-                               $sizeSel = 0;
-                       }
-               }
-               $max = $wgImageLimits[$sizeSel];
+               $max = $this->getImageLimitsFromOption( $user, 'imagesize' );
                $maxWidth = $max[0];
                $maxHeight = $max[1];
 
@@ -358,10 +347,7 @@ class ImagePage extends Article {
                                        } else {
                                                # Creating thumb links triggers thumbnail generation.
                                                # Just generate the thumb for the current users prefs.
-                                               $thumbOption = $user->getOption( 'thumbsize' );
-                                               $thumbSizes = array( isset( $wgImageLimits[$thumbOption] )
-                                                       ? $wgImageLimits[$thumbOption]
-                                                       : $wgImageLimits[User::getDefaultOption( 'thumbsize' )] );
+                                               $thumbSizes = array( $this->getImageLimitsFromOption( $user, 'thumbsize' ) );
                                        }
                                        # Generate thumbnails or thumbnail links as needed...
                                        $otherSizes = array();
@@ -918,6 +904,34 @@ EOT
                        return $a->page_namespace - $b->page_namespace;
                }
        }
+
+       /**
+        * Returns the corrosponding $wgImageLimits entry for the selected user option
+        *
+        * @param $user User
+        * @param $optionName string Name of a option to check, typically imagesize or thumbsize
+        * @return array
+        * @since 1.21
+        */
+       public function getImageLimitsFromOption( $user, $optionName ) {
+               global $wgImageLimits;
+
+               $option = intval( $user->getOption( $optionName ) );
+               if ( !isset( $wgImageLimits[$option] ) ) {
+                       $option = User::getDefaultOption( $optionName );
+               }
+
+               // The user offset might still be incorrect, specially if
+               // $wgImageLimits got changed (see bug #8858).
+               if ( !isset( $wgImageLimits[$option] ) ) {
+                       // Default to the first offset in $wgImageLimits
+                       $option = 0;
+               }
+
+               return isset( $wgImageLimits[$option] )
+                       ? $wgImageLimits[$option]
+                       : array( 800, 600 ); // if nothing is set, fallback to a hardcoded default
+       }
 }
 
 /**