Verify known image types on upload.
[lhc/web/wiklou.git] / includes / ImagePage.php
index 585f933..c717ce5 100644 (file)
@@ -1,11 +1,17 @@
 <?php
+/**
+ * @package MediaWiki
+ */
 
-/*
-       Special handling for image description pages
-*/
-
+/**
+ *
+ */
 require_once( 'Image.php' );
 
+/**
+ * Special handling for image description pages
+ * @package MediaWiki
+ */
 class ImagePage extends Article {
 
        /* private */ var $img;  // Image object this page is shown for. Initilaized in openShowImage, not
@@ -31,11 +37,16 @@ class ImagePage extends Article {
 
        function openShowImage()
        {
-               global $wgOut, $wgUser, $wgRequest, $wgMaxImageWidth, $wgUseImageResize;
+               global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize;
                $this->img  = Image::newFromTitle( $this->mTitle );
                $url  = $this->img->getUrl();
                $anchoropen = '';
                $anchorclose = '';
+               if ( $wgUseImageResize && $wgUser->getOption( 'imagesize' ) != '' ) {
+                       $max = $wgImageLimits[ intval( $wgUser->getOption( 'imagesize' ) ) ];
+                       $maxWidth = $max[0];
+                       $maxHeight = $max[1];
+               }
 
 
                if ( $this->img->exists() ) {
@@ -46,14 +57,24 @@ class ImagePage extends Article {
                                # image
                                $width = $this->img->getWidth();
                                $height = $this->img->getHeight();
-                               if ( $width > $wgMaxImageWidth && $wgUseImageResize ) {
+                               $msg = wfMsg('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
+                               if ( $width > $maxWidth && $wgUseImageResize ) {
                                        $anchoropen  = "<a href=\"{$url}\">";
-                                       $anchorclose = '</a>';
-                                       $url=$this->img->createThumb( $wgMaxImageWidth );
-                                       $height = floor( $height * $wgMaxImageWidth / $width );
-                                       $width  = $wgMaxImageWidth;
+                                       $anchorclose = "<br>{$msg}</a>";
+
+                                       $url = $this->img->createThumb( $maxWidth );
+                                       $height = floor( $height * $maxWidth / $width );
+                                       $width  = $maxWidth;
+                               } 
+                               if ( $height > $maxHeight && $wgUseImageResize ) {
+                                       $anchoropen  = "<a href=\"{$url}\">";
+                                       $anchorclose = "<br>{$msg}</a>";
+
+                                       $width = floor( $width * $maxHeight / $height );
+                                       $height = $maxHeight;
+                                       $url = $this->img->createThumb( $width );
                                }
-                               $s = "<div class=\"fullImage\">" . $anchoropen .
+                               $s = "<div class=\"fullImageLink\">" . $anchoropen .
                                     "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
                                     $wgRequest->getVal( 'image' )."\" />" . $anchorclose . "</div>";
                        } else {
@@ -68,9 +89,10 @@ class ImagePage extends Article {
                # For overloading
        }
 
-       # If the page we've just displayed is in the "Image" namespace,
-       # we follow it with an upload history of the image and its usage.
-
+       /**
+        * If the page we've just displayed is in the "Image" namespace,
+        * we follow it with an upload history of the image and its usage.
+        */
        function imageHistory()
        {
                global $wgUser, $wgOut;
@@ -172,7 +194,7 @@ class ImagePage extends Article {
        {
                global $wgOut, $wgUser, $wgLang, $wgRequest;
                global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
-               $fname = 'Article::doDelete';
+               $fname = 'ImagePage::doDelete';
 
                $reason = $wgRequest->getVal( 'wpReason' );
                $image = $wgRequest->getVal( 'image' );
@@ -180,7 +202,21 @@ class ImagePage extends Article {
                
                $dbw =& wfGetDB( DB_MASTER );
 
-               if ( !is_null( $image ) ) {
+               if ( !is_null( $oldimage ) ) {
+                       # Squid purging
+                       if ( $wgUseSquid ) {
+                               $urlArr = Array(
+                                       $wgInternalServer.wfImageArchiveUrl( $oldimage )
+                               );
+                               wfPurgeSquidServers($urlArr);
+                       }
+                       $this->doDeleteOldImage( $oldimage );
+                       $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
+                       $deleted = $oldimage;
+               } else {
+                       if ( is_null ( $image ) ) {
+                               $image = $this->mTitle->getDBkey();
+                       }
                        $dest = wfImageDir( $image );
                        $archive = wfImageDir( $image );
                        if ( ! @unlink( "{$dest}/{$image}" ) ) {
@@ -200,7 +236,7 @@ class ImagePage extends Article {
                        
 
                        $urlArr = Array();
-                       while ( $s = $dbr->fetchObject( $res ) ) {
+                       while ( $s = $dbw->fetchObject( $res ) ) {
                                $this->doDeleteOldImage( $s->oi_archive_name );
                                $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name );
                        }       
@@ -222,21 +258,8 @@ class ImagePage extends Article {
                        $article->doDeleteArticle( $reason ); # ignore errors
 
                        $deleted = $image;
-               } else if ( !is_null( $oldimage ) ) {
-                       # Squid purging
-                       if ( $wgUseSquid ) {
-                               $urlArr = Array(
-                                       $wgInternalServer.wfImageArchiveUrl( $oldimage )
-                               );
-                               wfPurgeSquidServers($urlArr);
-                       }
-                       $this->doDeleteOldImage( $oldimage );
-                       $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
-                       $deleted = $oldimage;
-               } else {
-                       $this->doDeleteArticle( $reason ); # ignore errors
-                       $deleted = $this->mTitle->getPrefixedText();
                }
+
                $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
@@ -257,8 +280,12 @@ class ImagePage extends Article {
 
                $name = substr( $oldimage, 15 );
                $archive = wfImageArchiveDir( $name );
-               if ( ! unlink( "{$archive}/{$oldimage}" ) ) {
+               if ( ! @unlink( "{$archive}/{$oldimage}" ) ) {
                        $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
+               } else {
+                       # Log the deletion
+                       $log = new LogPage( 'delete' );
+                       $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
                }
        }