Merge "Various fixes for EnhancedChangesList"
[lhc/web/wiklou.git] / includes / upload / UploadBase.php
index b162de2..4c8148a 100644 (file)
@@ -31,8 +31,6 @@
  * UploadBase and subclasses are the backend of MediaWiki's file uploads.
  * The frontends are formed by ApiUpload and SpecialUpload.
  *
- * See also includes/docs/upload.txt
- *
  * @author Brion Vibber
  * @author Bryan Tong Minh
  * @author Michael Dale
@@ -250,7 +248,7 @@ abstract class UploadBase {
 
        /**
         * @param string $srcPath the source path
-        * @return string the real path if it was a virtual URL
+        * @return string|bool the real path if it was a virtual URL Returns false on failure
         */
        function getRealPath( $srcPath ) {
                wfProfileIn( __METHOD__ );
@@ -259,12 +257,15 @@ abstract class UploadBase {
                        // @todo just make uploads work with storage paths
                        // UploadFromStash loads files via virtual URLs
                        $tmpFile = $repo->getLocalCopy( $srcPath );
-                       $tmpFile->bind( $this ); // keep alive with $this
-                       wfProfileOut( __METHOD__ );
-                       return $tmpFile->getPath();
+                       if ( $tmpFile ) {
+                               $tmpFile->bind( $this ); // keep alive with $this
+                       }
+                       $path = $tmpFile ? $tmpFile->getPath() : false;
+               } else {
+                       $path = $srcPath;
                }
                wfProfileOut( __METHOD__ );
-               return $srcPath;
+               return $path;
        }
 
        /**
@@ -319,8 +320,8 @@ abstract class UploadBase {
 
                $error = '';
                if ( !wfRunHooks( 'UploadVerification',
-                       array( $this->mDestName, $this->mTempPath, &$error ) ) )
-               {
+                       array( $this->mDestName, $this->mTempPath, &$error ) )
+               {
                        wfProfileOut( __METHOD__ );
                        return array( 'status' => self::HOOK_ABORTED, 'error' => $error );
                }
@@ -394,7 +395,6 @@ abstract class UploadBase {
                return true;
        }
 
-
        /**
         * Verifies that it's ok to include the uploaded file
         *
@@ -421,7 +421,6 @@ abstract class UploadBase {
                        }
                }
 
-
                $handler = MediaHandler::getHandler( $mime );
                if ( $handler ) {
                        $handlerStatus = $handler->verifyUpload( $this->mTempPath );
@@ -656,7 +655,11 @@ abstract class UploadBase {
                // Check dupes against archives
                $archivedImage = new ArchivedFile( null, 0, "{$hash}.{$this->mFinalExtension}" );
                if ( $archivedImage->getID() > 0 ) {
-                       $warnings['duplicate-archive'] = $archivedImage->getName();
+                       if ( $archivedImage->userCan( File::DELETED_FILE ) ) {
+                               $warnings['duplicate-archive'] = $archivedImage->getName();
+                       } else {
+                               $warnings['duplicate-archive'] = '';
+                       }
                }
 
                wfProfileOut( __METHOD__ );
@@ -722,7 +725,8 @@ abstract class UploadBase {
                # exclamation mark, so restrict file name to 240 bytes.
                if ( strlen( $this->mFilteredName ) > 240 ) {
                        $this->mTitleError = self::FILENAME_TOO_LONG;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                }
 
                /**
@@ -735,7 +739,8 @@ abstract class UploadBase {
                $nt = Title::makeTitleSafe( NS_FILE, $this->mFilteredName );
                if ( is_null( $nt ) ) {
                        $this->mTitleError = self::ILLEGAL_FILENAME;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                }
                $this->mFilteredName = $nt->getDBkey();
 
@@ -776,19 +781,22 @@ abstract class UploadBase {
 
                if ( $this->mFinalExtension == '' ) {
                        $this->mTitleError = self::FILETYPE_MISSING;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                } elseif ( $blackListedExtensions ||
                                ( $wgCheckFileExtensions && $wgStrictFileExtensions &&
                                        !$this->checkFileExtensionList( $ext, $wgFileExtensions ) ) ) {
                        $this->mBlackListedExtensions = $blackListedExtensions;
                        $this->mTitleError = self::FILETYPE_BADTYPE;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                }
 
                // Windows may be broken with special characters, see bug XXX
                if ( wfIsWindows() && !preg_match( '/^[\x0-\x7f]*$/', $nt->getText() ) ) {
                        $this->mTitleError = self::WINDOWS_NONASCII_FILENAME;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                }
 
                # If there was more than one "extension", reassemble the base
@@ -801,10 +809,12 @@ abstract class UploadBase {
 
                if ( strlen( $partname ) < 1 ) {
                        $this->mTitleError = self::MIN_LENGTH_PARTNAME;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                }
 
-               return $this->mTitle = $nt;
+               $this->mTitle = $nt;
+               return $this->mTitle;
        }
 
        /**
@@ -1097,7 +1107,6 @@ abstract class UploadBase {
                return false;
        }
 
-
        /**
         * Check a whitelist of xml encodings that are known not to be interpreted differently
         * by the server's xml parser (expat) and some common browsers.