Capitalization fix in memcached setting
[lhc/web/wiklou.git] / includes / ImagePage.php
index 42c219e..a5e515c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- *
+ * @package MediaWiki
  */
 
 /**
@@ -10,6 +10,7 @@ require_once( 'Image.php' );
 
 /**
  * Special handling for image description pages
+ * @package MediaWiki
  */
 class ImagePage extends Article {
 
@@ -36,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();
+               $url  = $this->img->getViewURL();
                $anchoropen = '';
                $anchorclose = '';
+               if ( $wgUseImageResize && $wgUser->getOption( 'imagesize' ) != '' ) {
+                       $max = $wgImageLimits[ intval( $wgUser->getOption( 'imagesize' ) ) ];
+                       $maxWidth = $max[0];
+                       $maxHeight = $max[1];
+               }
 
 
                if ( $this->img->exists() ) {
@@ -51,20 +57,33 @@ 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 = "<br>{$msg}</a>";
+
+                                       $url = $this->img->createThumb( $maxWidth );
+                                       $height = floor( $height * $maxWidth / $width );
+                                       $width  = $maxWidth;
+                               } 
+                               if ( $height > $maxHeight && $wgUseImageResize ) {
                                        $anchoropen  = "<a href=\"{$url}\">";
-                                       $anchorclose = '</a>';
-                                       $url=$this->img->createThumb( $wgMaxImageWidth );
-                                       $height = floor( $height * $wgMaxImageWidth / $width );
-                                       $width  = $wgMaxImageWidth;
+                                       $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>";
+                                    htmlspecialchars( $wgRequest->getVal( 'image' ) )."\" />" . $anchorclose . "</div>";
                        } else {
                                $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img->getName(),"")."</div>";
                        }
                        $wgOut->addHTML( $s );
+                       if($this->img->fromSharedDirectory) {
+                               $wgOut->addWikiText("<div class=\"sharedUploadNotice\">".wfMsg("sharedupload")."</div>");
+                       }
                }
        }
        
@@ -140,7 +159,7 @@ class ImagePage extends Article {
                
                # Only sysops can delete images. Previously ordinary users could delete 
                # old revisions, but this is no longer the case.
-               if ( !$wgUser->isSysop() ) {
+               if ( !$wgUser->isAllowed('delete') ) {
                        $wgOut->sysopRequired();
                        return;
                }
@@ -176,7 +195,7 @@ class ImagePage extends Article {
 
        function doDelete()
        {
-               global $wgOut, $wgUser, $wgLang, $wgRequest;
+               global $wgOut, $wgUser, $wgContLang, $wgRequest;
                global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
                $fname = 'ImagePage::doDelete';
 
@@ -203,8 +222,13 @@ class ImagePage extends Article {
                        }
                        $dest = wfImageDir( $image );
                        $archive = wfImageDir( $image );
-                       if ( ! @unlink( "{$dest}/{$image}" ) ) {
-                               $wgOut->fileDeleteError( "{$dest}/{$image}" );
+                       
+                       # Delete the image file if it exists; due to sync problems
+                       # or manual trimming sometimes the file will be missing.
+                       $targetFile = "{$dest}/{$image}";
+                       if( file_exists( $targetFile ) && ! @unlink( $targetFile ) ) {
+                               # If the deletion operation actually failed, bug out:
+                               $wgOut->fileDeleteError( $targetFile );
                                return;
                        }
                        $dbw->delete( 'image', array( 'img_name' => $image ) );
@@ -237,7 +261,7 @@ class ImagePage extends Article {
                        # Image itself is now gone, and database is cleaned.
                        # Now we remove the image description page.
 
-                       $nt = Title::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
+                       $nt = Title::newFromText( $wgContLang->getNsText( Namespace::getImage() ) . ":" . $image );
                        $article = new Article( $nt );
                        $article->doDeleteArticle( $reason ); # ignore errors
 
@@ -248,7 +272,7 @@ class ImagePage extends Article {
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
                $sk = $wgUser->getSkin();
-               $loglink = $sk->makeKnownLink( $wgLang->getNsText(
+               $loglink = $sk->makeKnownLink( $wgContLang->getNsText(
                  Namespace::getWikipedia() ) .
                  ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
 
@@ -264,7 +288,17 @@ class ImagePage extends Article {
 
                $name = substr( $oldimage, 15 );
                $archive = wfImageArchiveDir( $name );
-               if ( ! @unlink( "{$archive}/{$oldimage}" ) ) {
+               
+               # Delete the image if it exists. Sometimes the file will be missing
+               # due to manual intervention or weird sync problems; treat that
+               # condition gracefully and continue to delete the database entry.
+               # Also some records may end up with an empty oi_archive_name field
+               # if the original file was missing when a new upload was made;
+               # don't try to delete the directory then!
+               #
+               $targetFile = "{$archive}/{$oldimage}";
+               if( $oldimage != '' && file_exists( $targetFile ) && !@unlink( $targetFile ) ) {
+                       # If we actually have a file and can't delete it, throw an error.
                        $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
                } else {
                        # Log the deletion
@@ -279,11 +313,15 @@ class ImagePage extends Article {
                global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
 
                $oldimage = $wgRequest->getText( 'oldimage' );
-               
                if ( strlen( $oldimage ) < 16 ) {
-                       $wgOut->unexpectedValueError( 'oldimage', $oldimage );
+                       $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
                        return;
                }
+               if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
+                       $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
+                       return;
+               }
+
                if ( wfReadOnly() ) {
                        $wgOut->readOnlyPage();
                        return;
@@ -299,13 +337,13 @@ class ImagePage extends Article {
                $curfile = "{$dest}/{$name}";
 
                if ( ! is_file( $curfile ) ) {
-                       $wgOut->fileNotFoundError( $curfile );
+                       $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
                        return;
                }
                $oldver = wfTimestampNow() . "!{$name}";
                
                $dbr =& wfGetDB( DB_SLAVE );
-               $size = $dbr->getField( 'oldimage', 'oi_size', 'oi_archive_name=\'' .
+               $size = $dbr->selectField( 'oldimage', 'oi_size', 'oi_archive_name=\'' .
                  $dbr->strencode( $oldimage ) . "'" );
 
                if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {