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;
// 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' ) ) )
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.
*/
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 );
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 );
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 );
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;
}
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
* when served with a generic content-type.
*/
$tags = array(
- '<a',
+ '<a href',
'<body',
'<head',
'<html', #also in safari