* Fix explicit s-maxage=0 on raw pages; should help with proxy issues in
[lhc/web/wiklou.git] / includes / ImagePage.php
index 1ffa52d..24b0e48 100644 (file)
@@ -7,7 +7,7 @@
  *
  */
 if( !defined( 'MEDIAWIKI' ) )
-       die();
+       die( -1 );
 
 require_once( 'Image.php' );
 
@@ -20,14 +20,18 @@ class ImagePage extends Article {
        /* private */ var $img;  // Image object this page is shown for
        var $mExtraDescription = false;
 
+       /**
+        * Handler for action=render
+        * Include body text only; none of the image extras
+        */
        function render() {
                global $wgOut;
-               $wgOut->setArticleBodyOnly(true);
-               $wgOut->addWikitext($this->getContent(true));
+               $wgOut->setArticleBodyOnly( true );
+               $wgOut->addSecondaryWikitext( $this->getContent() );
        }
 
        function view() {
-               global $wgUseExternalEditor, $wgOut, $wgShowEXIF;
+               global $wgOut, $wgShowEXIF;
 
                $this->img = new Image( $this->mTitle );
 
@@ -53,15 +57,16 @@ class ImagePage extends Article {
                                $wgOut->setArticleFlag( true );
                                $wgOut->setRobotpolicy( 'index,follow' );
                                $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
-                               $wgOut->addMetaTags();
                                $this->viewUpdates();
                        }
 
-                       if ($this->mExtraDescription) {
-                               $fol = wfMsg('shareddescriptionfollows');
-                               if ($fol != '-')
-                                       $wgOut->addWikiText(wfMsg('shareddescriptionfollows'));
-                               $wgOut->addHTML($this->mExtraDescription);
+                       # Show shared description, if needed
+                       if( $this->mExtraDescription ) {
+                               $fol = wfMsg( 'shareddescriptionfollows' );
+                               if( $fol != '-' ) {
+                                       $wgOut->addWikiText( $fol );
+                               }
+                               $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
                        }
 
                        $this->closeShowImage();
@@ -127,7 +132,7 @@ class ImagePage extends Article {
                $r .= '|}';
                return $r;
        }
-       
+
        /**
         * Get a list of EXIF metadata items which should be displayed when
         * the metadata table is collapsed.
@@ -148,23 +153,20 @@ class ImagePage extends Article {
 
        /**
         * Overloading Article's getContent method.
-        * Omit noarticletext if sharedupload
-        *
-        * @param $noredir If true, do not follow redirects
+        * 
+        * Omit noarticletext if sharedupload; text will be fetched from the
+        * shared upload server if possible.
         */
-       function getContent( $noredir )
-       {
-               if ( $this->img && $this->img->fromSharedDirectory && 0 == $this->getID() ) {
+       function getContent() {
+               if( $this->img && $this->img->fromSharedDirectory && 0 == $this->getID() ) {
                        return '';
                }
-               return Article::getContent( $noredir );
+               return Article::getContent();
        }
 
-       function openShowImage()
-       {
-               global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
-                      $wgUseImageResize, $wgRepositoryBaseUrl,
-                      $wgUseExternalEditor, $wgServer, $wgFetchCommonsDescriptions;
+       function openShowImage() {
+               global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize;
+
                $full_url  = $this->img->getURL();
                $anchoropen = '';
                $anchorclose = '';
@@ -193,15 +195,23 @@ class ImagePage extends Article {
 
                                # "Download high res version" link below the image
                                $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
-                               if ( $width > $maxWidth ) {
-                                       $height = floor( $height * $maxWidth / $width );
-                                       $width  = $maxWidth;
-                               }
-                               if ( $height > $maxHeight ) {
-                                       $width = floor( $width * $maxHeight / $height );
-                                       $height = $maxHeight;
-                               }
-                               if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) {
+
+                               # We'll show a thumbnail of this image
+                               if ( $width > $maxWidth || $height > $maxHeight ) {
+                                       # Calculate the thumbnail size.
+                                       # First case, the limiting factor is the width, not the height.
+                                       if ( $width / $height >= $maxWidth / $maxHeight ) {
+                                               $height = round( $height * $maxWidth / $width);
+                                               $width = $maxWidth;
+                                               # Note that $height <= $maxHeight now.
+                                       } else {
+                                               $newwidth = floor( $width * $maxHeight / $height);
+                                               $height = round( $height * $newwidth / $width );
+                                               $width = $newwidth;
+                                               # Note that $height <= $maxHeight now, but might not be identical
+                                               # because of rounding.
+                                       }
+
                                        if( $wgUseImageResize ) {
                                                $thumbnail = $this->img->getThumbnail( $width );
                                                if ( $thumbnail == null ) {
@@ -237,7 +247,7 @@ class ImagePage extends Article {
                                        $icon->toHtml() .
                                        '</a></div>' );
                                }
-                               
+
                                $showLink = true;
                        }
 
@@ -247,7 +257,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
@@ -324,7 +334,7 @@ END
 
                $sk = $wgUser->getSkin();
                $wgOut->addHTML( '<br /><ul>' );
-               if( $wgUser->isAllowed( 'reupload' ) ) {        
+               if( $wgUser->isAllowed( 'reupload' ) ) {
                        $wgOut->addWikiText( "<li>\n<div>". wfMsg( 'uploadnewversion', $this->getUploadUrl() ) ."</div>\n</li>\n" );
                }
                $wgOut->addHTML( '<li>' );
@@ -462,10 +472,10 @@ END
                return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
        }
 
-       function doDelete()
-       {
-               global $wgOut, $wgUser, $wgContLang, $wgRequest;
-               global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList;
+       function doDelete()     {
+               global $wgOut, $wgUser, $wgRequest, $wgUseSquid, $wgInternalServer;
+               global $wgPostCommitUpdateList;
+
                $fname = 'ImagePage::doDelete';
 
                $reason = $wgRequest->getVal( 'wpReason' );
@@ -488,9 +498,9 @@ END
 
                        # Squid purging
                        if ( $wgUseSquid ) {
-                               $urlArr = Array(
+                               $urlArr = array(
                                        $wgInternalServer.wfImageArchiveUrl( $oldimage ),
-                                       $wgInternalServer.$this->mTitle->getFullURL()
+                                       $this->mTitle->getInternalURL()
                                );
                                wfPurgeSquidServers($urlArr);
                        }
@@ -582,10 +592,8 @@ END
                }
        }
 
-       function revert()
-       {
+       function revert() {
                global $wgOut, $wgRequest, $wgUser;
-               global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
 
                $oldimage = $wgRequest->getText( 'oldimage' );
                if ( strlen( $oldimage ) < 16 ) {
@@ -680,7 +688,7 @@ class ImageHistoryList {
        }
 
        function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
-               global $wgUser, $wgLang, $wgContLang, $wgTitle;
+               global $wgUser, $wgLang, $wgTitle, $wgContLang;
 
                $datetime = $wgLang->timeanddate( $timestamp, true );
                $del = wfMsg( 'deleteimg' );
@@ -720,15 +728,15 @@ class ImageHistoryList {
                if ( 0 == $user ) {
                        $userlink = $usertext;
                } else {
-                       $userlink = $this->skin->makeLinkObj(
-                               Title::makeTitle( NS_USER, $usertext ),
-                               $usertext );
+                       $userlink = $this->skin->makeLinkObj( Title::makeTitle( NS_USER, $usertext ), $usertext );
+                       $usertalk = $this->skin->makeLinkObj( Title::makeTitle( NS_USER_TALK, $usertext), $wgContLang->getNsText( NS_TALK ) );
+                       $userdata = $userlink . ' (' . $usertalk . ')';
                }
                $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} . . {$widthheight} ({$nbytes})";
+               $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userdata} . . {$widthheight} ({$nbytes})";
 
                $s .= $this->skin->commentBlock( $description, $wgTitle );
                $s .= "</li>\n";