Merge "Show no size links on image pages with errors"
[lhc/web/wiklou.git] / includes / ImagePage.php
index c831f64..953b1f7 100644 (file)
@@ -156,7 +156,7 @@ class ImagePage extends Article {
                        $pageLang = $this->getTitle()->getPageViewLanguage();
                        $out->addHTML( Xml::openElement( 'div', array( 'id' => 'mw-imagepage-content',
                                'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
-                               'class' => 'mw-content-'.$pageLang->getDir() ) ) );
+                               'class' => 'mw-content-' . $pageLang->getDir() ) ) );
 
                        parent::view();
 
@@ -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 {
@@ -368,12 +369,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' ),
@@ -381,7 +389,7 @@ class ImagePage extends Article {
                                                        params( count( $otherSizes ) )->parse()
                                                );
                                        }
-                               } elseif ( $width == 0 && $height == 0 ){
+                               } elseif ( $width == 0 && $height == 0 ) {
                                        # Some sort of audio file that doesn't have dimensions
                                        # Don't output a no hi res message for such a file
                                        $msgsmall = '';
@@ -397,7 +405,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 +478,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
@@ -547,7 +545,7 @@ EOT
                                        array( 'delete', 'move' ),
                                        $this->getTitle()->getPrefixedText(),
                                        '',
-                                       array(  'lim' => 10,
+                                       array( 'lim' => 10,
                                                'conds' => array( "log_action != 'revision'" ),
                                                'showIfEmpty' => false,
                                                'msgKey' => array( 'moveddeleted-notice' )
@@ -614,7 +612,7 @@ EOT
 
                /* Add canonical to head if there is no local page for this shared file */
                if( $descUrl && $this->mPage->getID() == 0 ) {
-                       $out->addLink( array( 'rel' => 'canonical', 'href' => $descUrl ) );
+                       $out->setCanonicalUrl( $descUrl );
                }
 
                $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
@@ -639,7 +637,7 @@ EOT
                return $uploadTitle->getFullURL( array(
                        'wpDestFile' => $this->mPage->getFile()->getName(),
                        'wpForReUpload' => 1
-                ) );
+               ) );
        }
 
        /**
@@ -796,9 +794,14 @@ EOT
 
                        $link = Linker::linkKnown( Title::makeTitle( $element->page_namespace, $element->page_title ) );
                        if ( !isset( $redirects[$element->page_title] ) ) {
+                               # No redirects
                                $liContents = $link;
+                       } elseif ( count( $redirects[$element->page_title] ) === 0 ) {
+                               # Redirect without usages
+                               $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams( $link, '' )->parse();
                        } else {
-                               $ul = "<ul class='mw-imagepage-redirectstofile'>\n";
+                               # Redirect with usages
+                               $li = '';
                                foreach ( $redirects[$element->page_title] as $row ) {
                                        $currentCount++;
                                        if ( $currentCount > $limit ) {
@@ -806,13 +809,18 @@ EOT
                                        }
 
                                        $link2 = Linker::linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) );
-                                       $ul .= Html::rawElement(
+                                       $li .= Html::rawElement(
                                                'li',
                                                array( 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
                                                $link2
                                                ) . "\n";
                                }
-                               $ul .= '</ul>';
+
+                               $ul = Html::rawElement(
+                                       'ul',
+                                       array( 'class' => 'mw-imagepage-redirectstofile'),
+                                       $li
+                                       ) . "\n";
                                $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams(
                                        $link, $ul )->parse();
                        }
@@ -1043,9 +1051,9 @@ class ImageHistoryList extends ContextSource {
                                } else {
                                        list( $ts, ) = explode( '!', $img, 2 );
                                        $query = array(
-                                               'type'   => 'oldimage',
+                                               'type' => 'oldimage',
                                                'target' => $this->title->getPrefixedText(),
-                                               'ids'    => $ts,
+                                               'ids' => $ts,
                                        );
                                        $del = Linker::revDeleteLink( $query,
                                                $file->isDeleted( File::DELETED_RESTRICTED ), $canHide );
@@ -1165,7 +1173,7 @@ class ImageHistoryList extends ContextSource {
        protected function getThumbForLine( $file ) {
                $lang = $this->getLanguage();
                $user = $this->getUser();
-               if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE,$user )
+               if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE, $user )
                        && !$file->isDeleted( File::DELETED_FILE ) )
                {
                        $params = array(