Revert "Update WikiData extensions to correct points for 1.21wmf11"
[lhc/web/wiklou.git] / includes / ImagePage.php
index 2a3e8e8..998d607 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();
@@ -369,12 +355,19 @@ class ImagePage extends Article {
                                                if ( $size[0] < $width_orig && $size[1] < $height_orig
                                                        && $size[0] != $width && $size[1] != $height )
                                                {
-                                                       $otherSizes[] = $this->makeSizeLink( $params, $size[0], $size[1] );
+                                                       $sizeLink = $this->makeSizeLink( $params, $size[0], $size[1] );
+                                                       if ( $sizeLink ) {
+                                                               $otherSizes[] = $sizeLink;
+                                                       }
                                                }
                                        }
-                                       $msgsmall = wfMessage( 'show-big-image-preview' )->
-                                               rawParams( $this->makeSizeLink( $params, $width, $height ) )->
-                                               parse();
+                                       $msgsmall = '';
+                                       $sizeLinkBigImagePreview = $this->makeSizeLink( $params, $width, $height );
+                                       if ( $sizeLinkBigImagePreview ) {
+                                               $msgsmall .= wfMessage( 'show-big-image-preview' )->
+                                                       rawParams( $sizeLinkBigImagePreview )->
+                                                       parse();
+                                       }
                                        if ( count( $otherSizes ) ) {
                                                $msgsmall .= ' ' .
                                                Html::rawElement( 'span', array( 'class' => 'mw-filepage-other-resolutions' ),
@@ -611,7 +604,7 @@ EOT
                $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
                $repo = $this->mPage->getFile()->getRepo()->getDisplayName();
 
-               if ( $descUrl && $descText && wfMessage( 'sharedupload-desc-here' )->plain() !== '-'  ) {
+               if ( $descUrl && $descText && wfMessage( 'sharedupload-desc-here' )->plain() !== '-' ) {
                        $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) );
                } elseif ( $descUrl && wfMessage( 'sharedupload-desc-there' )->plain() !== '-' ) {
                        $out->wrapWikiMsg( $wrap, array( 'sharedupload-desc-there', $repo, $descUrl ) );
@@ -811,7 +804,7 @@ EOT
 
                                $ul = Html::rawElement(
                                        'ul',
-                                       array( 'class' => 'mw-imagepage-redirectstofile'),
+                                       array( 'class' => 'mw-imagepage-redirectstofile' ),
                                        $li
                                        ) . "\n";
                                $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams(
@@ -911,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 = $user->getIntOption( $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
+       }
 }
 
 /**