From c598851620a16fa2f0dc643ffaf3f24cb251768c Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sat, 2 Feb 2013 14:48:33 +0100 Subject: [PATCH] Avoid undefined offset for $wgImageLimits 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 | 46 +++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 953b1f7d03..3337ffd179 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -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 + } } /** -- 2.20.1