(bug 13453) Fix rebuildrecentchanges for DB's with FK constraints
[lhc/web/wiklou.git] / includes / upload / UploadBase.php
index 8795d76..147da3d 100644 (file)
@@ -22,19 +22,15 @@ abstract class UploadBase {
 
        const SUCCESS = 0;
        const OK = 0;
-       const BEFORE_PROCESSING = 1;
-       const LARGE_FILE_SERVER = 2;
        const EMPTY_FILE = 3;
        const MIN_LENGTH_PARTNAME = 4;
        const ILLEGAL_FILENAME = 5;
-       const PROTECTED_PAGE = 6;
        const OVERWRITE_EXISTING_FILE = 7;
        const FILETYPE_MISSING = 8;
        const FILETYPE_BADTYPE = 9;
        const VERIFICATION_ERROR = 10;
        const UPLOAD_VERIFICATION_ERROR = 11;
-       const UPLOAD_WARNING = 12;
-       const INTERNAL_ERROR = 13;
+       const HOOK_ABORTED = 11;
        const MIN_LENGHT_PARTNAME = 14;
 
        const SESSION_VERSION = 2;
@@ -80,10 +76,16 @@ abstract class UploadBase {
 
                // Get the upload class
                $type = ucfirst( $type );
-               $className = 'UploadFrom' . $type;
-               wfDebug( __METHOD__ . ": class name: $className\n" );
-               if( !in_array( $type, self::$uploadHandlers ) )
-                       return null;
+               
+               // Give hooks the chance to handle this request
+               $className = null;
+               wfRunHooks( 'UploadCreateFromRequest', array( $type, &$className ) );
+               if ( is_null( $className ) ) {
+                       $className = 'UploadFrom' . $type;
+                       wfDebug( __METHOD__ . ": class name: $className\n" );
+                       if( !in_array( $type, self::$uploadHandlers ) )
+                               return null;
+               }
 
                // Check whether this upload class is enabled
                if( !call_user_func( array( $className, 'isEnabled' ) ) )
@@ -136,6 +138,19 @@ abstract class UploadBase {
        public function isEmptyFile(){
                return empty( $this->mFileSize );
        }
+       
+       /**
+     * getRealPath
+     * @param string $srcPath the source path
+     * @returns the real path if it was a virtual url
+     */
+       function getRealPath( $srcPath ){
+               $repo = RepoGroup::singleton()->getLocalRepo();
+               if ( $repo->isVirtualUrl( $srcPath ) ) {
+                       return $repo->resolveVirtualUrl( $srcPath );
+               }
+               return $srcPath;
+       }
 
        /**
         * Verify whether the upload is sane.
@@ -147,7 +162,21 @@ abstract class UploadBase {
                 */
                if( $this->isEmptyFile() )
                        return array( 'status' => self::EMPTY_FILE );
+               
+               /**
+                * Look at the contents of the file; if we can recognize the
+                * type but it's corrupt or data of the wrong type, we should
+                * probably not accept it.
+                */
+               $verification = $this->verifyFile();
+               if( $verification !== true ) {
+                       if( !is_array( $verification ) )
+                               $verification = array( $verification );
+                       return array( 'status' => self::VERIFICATION_ERROR,
+                                       'details' => $verification );
 
+               }
+               
                $nt = $this->getTitle();
                if( is_null( $nt ) ) {
                        $result = array( 'status' => $this->mTitleError );
@@ -166,26 +195,11 @@ abstract class UploadBase {
                if( $overwrite !== true )
                        return array( 'status' => self::OVERWRITE_EXISTING_FILE, 'overwrite' => $overwrite );
 
-               /**
-                * Look at the contents of the file; if we can recognize the
-                * type but it's corrupt or data of the wrong type, we should
-                * probably not accept it.
-                */
-               $verification = $this->verifyFile();
-
-               if( $verification !== true ) {
-                       if( !is_array( $verification ) )
-                               $verification = array( $verification );
-                       return array( 'status' => self::VERIFICATION_ERROR,
-                                       'details' => $verification );
-
-               }
-
                $error = '';
                if( !wfRunHooks( 'UploadVerification',
                                array( $this->mDestName, $this->mTempPath, &$error ) ) ) {
                        // This status needs another name...
-                       return array( 'status' => self::UPLOAD_VERIFICATION_ERROR, 'error' => $error );
+                       return array( 'status' => self::HOOK_ABORTED, 'error' => $error );
                }
 
                return array( 'status' => self::OK );
@@ -318,15 +332,6 @@ abstract class UploadBase {
                if( $exists !== false )
                        $warnings['exists'] = $exists;
 
-               // Check whether this may be a thumbnail
-               if( $exists !== false && $exists[0] != 'thumb'
-                               && self::isThumbName( $filename ) ){
-                       // Make the title
-                       $nt = $this->getTitle();
-                       $warnings['file-thumbnail-no'] = substr( $filename, 0,
-                               strpos( $nt->getText() , '-' ) +1 );
-               }
-
                // Check dupes against existing files
                $hash = File::sha1Base36( $this->mTempPath );
                $dupes = RepoGroup::singleton()->findBySha1( $hash );
@@ -344,19 +349,6 @@ abstract class UploadBase {
                if ( $archivedImage->getID() > 0 )
                        $warnings['duplicate-archive'] = $archivedImage->getName();
 
-               $filenamePrefixBlacklist = self::getFilenamePrefixBlacklist();
-               foreach( $filenamePrefixBlacklist as $prefix ) {
-                       if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
-                               $warnings['filename-bad-prefix'] = $prefix;
-                               break;
-                       }
-               }
-
-               # If the file existed before and was deleted, warn the user of this
-               # Don't bother doing so if the file exists now, however
-               if( $localFile->wasDeleted() && !$localFile->exists() )
-                       $warnings['filewasdeleted'] = $localFile->getTitle();
-
                return $warnings;
        }
 
@@ -528,15 +520,6 @@ abstract class UploadBase {
                return $key;
        }
 
-       /**
-        * Remove a temporarily kept file stashed by saveTempUploadedFile().
-        * @return success
-        */
-       public function unsaveUploadedFile() {
-               $repo = RepoGroup::singleton()->getLocalRepo();
-               $success = $repo->freeTemp( $this->mTempPath );
-               return $success;
-       }
 
        /**
         * If we've modified the upload file we need to manually remove it
@@ -700,7 +683,7 @@ abstract class UploadBase {
                * when served with a generic content-type.
                */
                $tags = array(
-                       '<a',
+                       '<a href',
                        '<body',
                        '<head',
                        '<html',   #also in safari