Cleanup to ImagePage::openShowImage()
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Mon, 12 Nov 2012 19:52:27 +0000 (20:52 +0100)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 20 Dec 2012 22:24:54 +0000 (22:24 +0000)
- Removed useless $showLink variable and related check since the variable is always defined to true
- Moved $linktext up so that there's no need to use a temporary variable to modify it
- Moved $longDesc down where it's used
- Change "else { if ( ... ) { } }" to elseif for better clarity

Change-Id: I65dcbb76c7f0a0441a6420e76affe797a3dc9c45

includes/ImagePage.php

index c831f64..1beaad0 100644 (file)
@@ -327,7 +327,8 @@ class ImagePage extends Article {
                        $height_orig = $this->displayImg->getHeight( $page );
                        $height = $height_orig;
 
-                       $longDesc = wfMessage( 'parentheses', $this->displayImg->getLongDesc() )->text();
+                       $filename = wfEscapeWikiText( $this->displayImg->getName() );
+                       $linktext = $filename;
 
                        wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this, &$out ) );
 
@@ -351,7 +352,7 @@ class ImagePage extends Article {
                                                # Note that $height <= $maxHeight now, but might not be identical
                                                # because of rounding.
                                        }
-                                       $msgbig = wfMessage( 'show-big-image' )->escaped();
+                                       $linktext = wfMessage( 'show-big-image' )->escaped();
                                        if ( $this->displayImg->getRepo()->canTransformVia404() ) {
                                                $thumbSizes = $wgImageLimits;
                                        } else {
@@ -397,7 +398,6 @@ class ImagePage extends Article {
                                $params['height'] = $height;
                                $thumbnail = $this->displayImg->transform( $params );
 
-                               $showLink = true;
                                $anchorclose = Html::rawElement( 'div', array( 'class' => 'mw-filepage-resolutioninfo' ), $msgsmall );
 
                                $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
@@ -471,48 +471,39 @@ class ImagePage extends Article {
                                                "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
                                        );
                                }
-                       } else {
+                       } elseif ( $this->displayImg->isSafeFile() ) {
                                # if direct link is allowed but it's not a renderable image, show an icon.
-                               if ( $this->displayImg->isSafeFile() ) {
-                                       $icon = $this->displayImg->iconThumb();
-
-                                       $out->addHTML( '<div class="fullImageLink" id="file">' .
-                                               $icon->toHtml( array( 'file-link' => true ) ) .
-                                               "</div>\n" );
-                               }
+                               $icon = $this->displayImg->iconThumb();
 
-                               $showLink = true;
+                               $out->addHTML( '<div class="fullImageLink" id="file">' .
+                                       $icon->toHtml( array( 'file-link' => true ) ) .
+                                       "</div>\n" );
                        }
 
-                       if ( $showLink ) {
-                               $filename = wfEscapeWikiText( $this->displayImg->getName() );
-                               $linktext = $filename;
-                               if ( isset( $msgbig ) ) {
-                                       $linktext = wfEscapeWikiText( $msgbig );
-                               }
-                               $medialink = "[[Media:$filename|$linktext]]";
-
-                               if ( !$this->displayImg->isSafeFile() ) {
-                                       $warning = wfMessage( 'mediawarning' )->plain();
-                                       // dirmark is needed here to separate the file name, which
-                                       // most likely ends in Latin characters, from the description,
-                                       // which may begin with the file type. In RTL environment
-                                       // this will get messy.
-                                       // The dirmark, however, must not be immediately adjacent
-                                       // to the filename, because it can get copied with it.
-                                       // See bug 25277.
-                                       $out->addWikiText( <<<EOT
+                       $longDesc = wfMessage( 'parentheses', $this->displayImg->getLongDesc() )->text();
+
+                       $medialink = "[[Media:$filename|$linktext]]";
+
+                       if ( !$this->displayImg->isSafeFile() ) {
+                               $warning = wfMessage( 'mediawarning' )->plain();
+                               // dirmark is needed here to separate the file name, which
+                               // most likely ends in Latin characters, from the description,
+                               // which may begin with the file type. In RTL environment
+                               // this will get messy.
+                               // The dirmark, however, must not be immediately adjacent
+                               // to the filename, because it can get copied with it.
+                               // See bug 25277.
+                               $out->addWikiText( <<<EOT
 <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
 <div class="mediaWarning">$warning</div>
 EOT
-                                               );
-                               } else {
-                                       $out->addWikiText( <<<EOT
+                                       );
+                       } else {
+                               $out->addWikiText( <<<EOT
 <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
 </div>
 EOT
-                                       );
-                               }
+                               );
                        }
 
                        // Add cannot animate thumbnail warning