* (bug 3643) Fix image page display of large images with resizing disabled
[lhc/web/wiklou.git] / includes / ImagePage.php
index f7aec17..1ab1c36 100644 (file)
@@ -86,9 +86,9 @@ class ImagePage extends Article {
                global $wgLang;
                $r = '<ul id="filetoc">
                        <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>' .
-                       ($metadata ? '<li><a href="#metadata">' . wfMsg( 'metadata' ) . '</a></li>' : '') . '
-                       <li><a href="#filehistory">' . wfMsg( 'imghistory' ) . '</a></li>
-                       <li><a href="#filelinks">' . wfMsg( 'imagelinks' ) . '</a></li>
+                       ($metadata ? '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
+                       <li><a href="#filehistory">' . wfMsgHtml( 'imghistory' ) . '</a></li>
+                       <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>
                </ul>';
                return $r;
        }
@@ -103,11 +103,13 @@ class ImagePage extends Article {
         */
        function makeMetadataTable( $exif ) {
                $r = "{| class=metadata align=right width=250px\n";
-               $r .= '|+ id=metadata | '. htmlspecialchars( wfMsg( 'metadata' ) ) . "\n";
+               $r .= '|+ id=metadata | '. wfMsg( 'metadata' )  . "\n";
                foreach( $exif as $k => $v ) {
                        $tag = strtolower( $k );
-                       $r .= "! class=$tag |" . wfMsg( "exif-$tag" ) . "\n";
-                       $r .= "| class=$tag |" . htmlspecialchars( $v ) . "\n";
+                       $msg = wfMsg( "exif-$tag" );
+                       
+                       $r .= "! class=$tag | $msg\n";
+                       $r .= "| class=$tag | $v\n";
                        $r .= "|-\n";
                }
                return substr($r, 0, -3) . '|}';
@@ -132,14 +134,14 @@ class ImagePage extends Article {
                global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
                       $wgUseImageResize, $wgRepositoryBaseUrl,
                       $wgUseExternalEditor, $wgServer, $wgFetchCommonsDescriptions;
-               $full_url  = $this->img->getViewURL();
+               $full_url  = $this->img->getURL();
                $anchoropen = '';
                $anchorclose = '';
 
                if( $wgUser->getOption( 'imagesize' ) == '' ) {
                        $sizeSel = User::getDefaultOption( 'imagesize' );
                } else {
-                       $sizeSel = IntVal( $wgUser->getOption( 'imagesize' ) );
+                       $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
                }
                if( !isset( $wgImageLimits[$sizeSel] ) ) {
                        $sizeSel = User::getDefaultOption( 'imagesize' );
@@ -159,7 +161,7 @@ class ImagePage extends Article {
                                # image
 
                                # "Download high res version" link below the image
-                               $msg = wfMsg('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
+                               $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
                                if ( $width > $maxWidth ) {
                                        $height = floor( $height * $maxWidth / $width );
                                        $width  = $maxWidth;
@@ -168,25 +170,29 @@ class ImagePage extends Article {
                                        $width = floor( $width * $maxHeight / $height );
                                        $height = $maxHeight;
                                }
-                               if ( !$this->img->mustRender()
-                                  && ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) ) {
+                               if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) {
                                        if( $wgUseImageResize ) {
                                                $thumbnail = $this->img->getThumbnail( $width );
                                                if ( $thumbnail == null ) {
-                                                       $url = $full_url;
+                                                       $url = $this->img->getViewURL();
                                                } else {
-                                                       $url = $thumbnail->getUrl();
+                                                       $url = $thumbnail->getURL();
                                                }
                                        } else {
                                                # No resize ability? Show the full image, but scale
                                                # it down in the browser so it fits on the page.
-                                               $url = $full_url;
+                                               $url = $this->img->getViewURL();
                                        }
                                        $anchoropen  = "<a href=\"{$full_url}\">";
-                                       $anchorclose = "</a><br />\n$anchoropen{$msg}</a>";
+                                       $anchorclose = "</a><br />";
+                                       if( $this->img->mustRender() ) {
+                                               $showLink = true;
+                                       } else {
+                                               $anchorclose .= "\n$anchoropen{$msg}</a>";
+                                       }
                                } else {
-                                       $url = $full_url;
-                                       $showLink = $this->img->mustRender();
+                                       $url = $this->img->getViewURL();
+                                       $showLink = true;
                                }
                                $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
                                     "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
@@ -200,7 +206,7 @@ class ImagePage extends Article {
                                        $icon->toHtml() .
                                        '</a></div>' );
                                }
-
+                               
                                $showLink = true;
                        }
 
@@ -210,7 +216,7 @@ class ImagePage extends Article {
                                $info = wfMsg( 'fileinfo',
                                        ceil($this->img->getSize()/1024.0),
                                        $this->img->getMimeType() );
-
+       
                                if (!$this->img->isSafeFile()) {
                                        $warning = wfMsg( 'mediawarning' );
                                        $wgOut->addWikiText( <<<END
@@ -237,20 +243,29 @@ END
                        }
                } else {
                        # Image does not exist
-                       $wgOut->addWikiText( wfMsg( 'noimage', $this->getUploadUrl() ) );
+
+                       $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
+                       $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
+                               'wpDestFile=' . urlencode( $this->img->getName() ) );
+                       $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
                }
        }
 
        function printSharedImageText() {
-               global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut;
+               global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
 
                $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
-               $sharedtext = "<div class='sharedUploadNotice'>" . wfMsg("sharedupload");
+               $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
                if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
-                       $sharedtext .= " " . wfMsg("shareduploadwiki", $url);
+
+                       $sk = $wgUser->getSkin();
+                       $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
+                       $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
+                       array( 'wpDestFile' => urlencode( $this->img->getName() )));
+                       $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
                }
                $sharedtext .= "</div>";
-               $wgOut->addWikiText($sharedtext);
+               $wgOut->addHTML($sharedtext);
 
                if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
                        require_once("HttpFunctions.php");
@@ -277,9 +292,11 @@ END
                        return;
 
                $sk = $wgUser->getSkin();
-               $wgOut->addHTML( '<br /><ul><li>' );
-               $wgOut->addWikiText( '<div>'. wfMsg( 'uploadnewversion', $this->getUploadUrl() ) .'</div>' );
-               $wgOut->addHTML( '</li><li>' );
+               $wgOut->addHTML( '<br /><ul>' );
+               if( $wgUser->isAllowed( 'reupload' ) ) {        
+                       $wgOut->addWikiText( "<li>\n<div>". wfMsg( 'uploadnewversion', $this->getUploadUrl() ) ."</div>\n</li>\n" );
+               }
+               $wgOut->addHTML( '<li>' );
                $wgOut->addHTML( $sk->makeKnownLinkObj( $this->mTitle,
                        wfMsg( 'edit-externally' ), "action=edit&externaledit=true&mode=file" ) );
                $wgOut->addWikiText( '<div>' .  wfMsg('edit-externally-help') . '</div>' );
@@ -309,12 +326,16 @@ END
                        $s = $list->beginImageHistoryList() .
                                $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
                                        $this->mTitle->getDBkey(),  $line->img_user,
-                                       $line->img_user_text, $line->img_size, $line->img_description );
+                                       $line->img_user_text, $line->img_size, $line->img_description,
+                                       $line->img_width, $line->img_height
+                               );
 
                        while ( $line = $this->img->nextHistoryLine() ) {
                                $s .= $list->imageHistoryLine( false, $line->img_timestamp,
-                               $line->oi_archive_name, $line->img_user,
-                               $line->img_user_text, $line->img_size, $line->img_description );
+                                       $line->oi_archive_name, $line->img_user,
+                                       $line->img_user_text, $line->img_size, $line->img_description,
+                                       $line->img_width, $line->img_height
+                               );
                        }
                        $s .= $list->endImageHistoryList();
                } else { $s=''; }
@@ -627,7 +648,7 @@ class ImageHistoryList {
                return $s;
        }
 
-       function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) {
+       function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
                global $wgUser, $wgLang, $wgContLang, $wgTitle;
 
                $datetime = $wgLang->timeanddate( $timestamp, true );
@@ -673,10 +694,10 @@ class ImageHistoryList {
                                $usertext );
                }
                $nbytes = wfMsg( 'nbytes', $size );
+               $widthheight = wfMsg( 'widthheight', $width, $height );
                $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
 
-               $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
-                 . " . . {$userlink} ({$nbytes})";
+               $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
 
                $s .= $this->skin->commentBlock( $description, $wgTitle );
                $s .= "</li>\n";