const HOOK_ABORTED = 11;
const SESSION_VERSION = 2;
+ const SESSION_KEYNAME = 'wsUploadData';
+
+ static public function getSessionKeyname() {
+ return self::SESSION_KEYNAME;
+ }
/**
* Returns true if uploads are enabled.
}
/**
- * Return the file size
+ * Return true if the file is empty
+ * @return bool
*/
public function isEmptyFile() {
return empty( $this->mFileSize );
}
/**
- * @param string $srcPath the source path
- * @returns the real path if it was a virtual URL
+ * Return the file size
+ * @return integer
+ */
+ public function getFileSize() {
+ return $this->mFileSize;
+ }
+
+ /**
+ * Append a file to the Repo file
+ *
+ * @param string $srcPath Path to source file
+ * @param string $toAppendPath Path to the Repo file that will be appended to.
+ * @return Status Status
+ */
+ protected function appendToUploadFile( $srcPath, $toAppendPath ) {
+ $repo = RepoGroup::singleton()->getLocalRepo();
+ $status = $repo->append( $srcPath, $toAppendPath );
+ return $status;
+ }
+
+ /**
+ * @param $srcPath String: the source path
+ * @return the real path if it was a virtual URL
*/
function getRealPath( $srcPath ) {
$repo = RepoGroup::singleton()->getLocalRepo();
/**
* Verify whether the upload is sane.
- * Returns self::OK or else an array with error information
+ * @return mixed self::OK or else an array with error information
*/
- public function verifyUpload() {
+ public function verifyUpload( ) {
/**
* If there was no filename or a zero size given, give up quick.
*/
);
}
+ /**
+ * Make sure this file can be created
+ */
+ $result = $this->validateNameAndOverwrite();
+ if( $result !== true ) {
+ return $result;
+ }
+
+ $error = '';
+ if( !wfRunHooks( 'UploadVerification',
+ array( $this->mDestName, $this->mTempPath, &$error ) ) ) {
+ // @fixme This status needs another name...
+ return array( 'status' => self::HOOK_ABORTED, 'error' => $error );
+ }
+
+ return array( 'status' => self::OK );
+ }
+
+ /**
+ * Verify that the name is valid and, if necessary, that we can overwrite
+ *
+ * @return mixed true if valid, otherwise and array with 'status'
+ * and other keys
+ **/
+ public function validateNameAndOverwrite() {
$nt = $this->getTitle();
if( is_null( $nt ) ) {
$result = array( 'status' => $this->mTitleError );
'overwrite' => $overwrite
);
}
-
- $error = '';
- if( !wfRunHooks( 'UploadVerification',
- array( $this->mDestName, $this->mTempPath, &$error ) ) ) {
- // This status needs another name...
- return array( 'status' => self::HOOK_ABORTED, 'error' => $error );
- }
-
- return array( 'status' => self::OK );
+ return true;
}
/**
/**
* Check whether the user can edit, upload and create the image.
*
- * @param User $user the user to verify the permissions against
+ * @param $user the User object to verify the permissions against
* @return mixed An array as returned by getUserPermissionsErrors or true
* in case the user has proper permissions.
*/
/**
* Check for non fatal problems with the file
*
- * @return array Array of warnings
+ * @return Array of warnings
*/
public function checkWarnings() {
$warnings = array();
$status = $this->getLocalFile()->upload( $this->mTempPath, $comment, $pageText,
File::DELETE_SOURCE, $this->mFileProps, false, $user );
- if( $status->isGood() && $watch ) {
- $user->addWatch( $this->getLocalFile()->getTitle() );
- }
-
if( $status->isGood() ) {
+ if ( $watch ) {
+ $user->addWatch( $this->getLocalFile()->getTitle() );
+ }
+
wfRunHooks( 'UploadComplete', array( &$this ) );
}
* filter out illegal characters, and try to make a legible name
* out of it. We'll strip some silently that Title would die on.
*/
- $basename = $this->mDesiredDestName;
-
- $this->mFilteredName = wfStripIllegalFilenameChars( $basename );
+ $this->mFilteredName = wfStripIllegalFilenameChars( $this->mDesiredDestName );
/* Normalize to title form before we do any further processing */
$nt = Title::makeTitleSafe( NS_FILE, $this->mFilteredName );
if( is_null( $nt ) ) {
return $this->mTitle = null;
}
- $nt = Title::makeTitleSafe( NS_FILE, $this->mFilteredName );
- if( is_null( $nt ) ) {
- $this->mTitleError = self::ILLEGAL_FILENAME;
- return $this->mTitle = null;
- }
return $this->mTitle = $nt;
}
* If the user doesn't explicitly cancel or accept, these files
* can accumulate in the temp directory.
*
- * @param string $saveName - the destination filename
- * @param string $tempSrc - the source temporary file to save
- * @return string - full path the stashed file, or false on failure
+ * @param $saveName String: the destination filename
+ * @param $tempSrc String: the source temporary file to save
+ * @return String: full path the stashed file, or false on failure
*/
protected function saveTempUploadedFile( $saveName, $tempSrc ) {
$repo = RepoGroup::singleton()->getLocalRepo();
* Returns a key value which will be passed through a form
* to pick up the path info on a later invocation.
*
- * @return int Session key
+ * @return Integer: session key
*/
public function stashSession() {
$status = $this->saveTempUploadedFile( $this->mDestName, $this->mTempPath );
}
$key = $this->getSessionKey();
- $_SESSION['wsUploadData'][$key] = array(
+ $_SESSION[self::SESSION_KEYNAME][$key] = array(
'mTempPath' => $status->value,
'mFileSize' => $this->mFileSize,
'mFileProps' => $this->mFileProps,
*/
protected function getSessionKey() {
$key = mt_rand( 0, 0x7fffffff );
- $_SESSION['wsUploadData'][$key] = array();
+ $_SESSION[self::SESSION_KEYNAME][$key] = array();
return $key;
}
* Perform case-insensitive match against a list of file extensions.
* Returns true if the extension is in the list.
*
- * @param string $ext
- * @param array $list
- * @return bool
+ * @param $ext String
+ * @param $list Array
+ * @return Boolean
*/
public static function checkFileExtension( $ext, $list ) {
return in_array( strtolower( $ext ), $list );
* Perform case-insensitive match against a list of file extensions.
* Returns true if any of the extensions are in the list.
*
- * @param array $ext
- * @param array $list
- * @return bool
+ * @param $ext Array
+ * @param $list Array
+ * @return Boolean
*/
public static function checkFileExtensionList( $ext, $list ) {
foreach( $ext as $e ) {
/**
* Checks if the mime type of the uploaded file matches the file extension.
*
- * @param string $mime the mime type of the uploaded file
- * @param string $extension The filename extension that the file is to be served with
- * @return bool
+ * @param $mime String: the mime type of the uploaded file
+ * @param $extension String: the filename extension that the file is to be served with
+ * @return Boolean
*/
public static function verifyExtension( $mime, $extension ) {
$magic = MimeMagic::singleton();
* potentially harmful. The present implementation will produce false
* positives in some situations.
*
- * @param string $file Pathname to the temporary upload file
- * @param string $mime The mime type of the file
- * @param string $extension The extension of the file
- * @return bool true if the file contains something looking like embedded scripts
+ * @param $file String: pathname to the temporary upload file
+ * @param $mime String: the mime type of the file
+ * @param $extension String: the extension of the file
+ * @return Boolean: true if the file contains something looking like embedded scripts
*/
public static function detectScript( $file, $mime, $extension ) {
global $wgAllowTitlesInSVG;
* This relies on the $wgAntivirus and $wgAntivirusSetup variables.
* $wgAntivirusRequired may be used to deny upload if the scan fails.
*
- * @param string $file Pathname to the temporary upload file
+ * @param $file String: pathname to the temporary upload file
* @return mixed false if not virus is found, NULL if the scan fails or is disabled,
* or a string containing feedback from the virus scanner if a virus was found.
* If textual feedback is missing but a virus was found, this function returns true.
/**
* Check if a user is the last uploader
*
- * @param User $user
- * @param string $img, image name
- * @return bool
+ * @param $user User object
+ * @param $img String: image name
+ * @return Boolean
*/
public static function userCanReUpload( User $user, $img ) {
if( $user->isAllowed( 'reupload' ) ) {
* - File exists with normalized extension
* - The file looks like a thumbnail and the original exists
*
- * @param File $file The file to check
+ * @param $file The File object to check
* @return mixed False if the file does not exists, else an array
*/
public static function getExistsWarning( $file ) {