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 );
}
+ /**
+ * 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
/**
* 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;
}
/**
}
$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;
}