4 * @addtogroup SpecialPage
10 require_once( 'MogileFS.php' );
15 function wfSpecialUploadMogile() {
17 $form = new UploadFormMogile( $wgRequest );
21 class UploadFormMogile
extends UploadForm
{
23 * Move the uploaded file from its temporary location to the final
24 * destination. If a previous version of the file exists, move
25 * it into the archive subdirectory.
27 * @todo If the later save fails, we may have disappeared the original file.
29 * @param string $saveName
30 * @param string $tempName full path to the temporary file
31 * @param bool $useRename Not used in this implementation
33 function saveUploadedFile( $saveName, $tempName, $useRename = false ) {
35 $mfs = MogileFS
::NewMogileFS();
37 $this->mSavedFile
= "image!{$saveName}";
39 if( $mfs->getPaths( $this->mSavedFile
)) {
40 $this->mUploadOldVersion
= gmdate( 'YmdHis' ) . "!{$saveName}";
41 if( !$mfs->rename( $this->mSavedFile
, "archive!{$this->mUploadOldVersion}" ) ) {
42 $wgOut->showFileRenameError( $this->mSavedFile
,
43 "archive!{$this->mUploadOldVersion}" );
47 $this->mUploadOldVersion
= '';
50 if ( $this->mStashed
) {
51 if (!$mfs->rename($tempName,$this->mSavedFile
)) {
52 $wgOut->showFileRenameError($tempName, $this->mSavedFile
);
56 if ( !$mfs->saveFile($this->mSavedFile
,'normal',$tempName )) {
57 $wgOut->showFileCopyError( $tempName, $this->mSavedFile
);
66 * Stash a file in a temporary directory for later processing
67 * after the user has confirmed it.
69 * If the user doesn't explicitly cancel or accept, these files
70 * can accumulate in the temp directory.
72 * @param string $saveName - the destination filename
73 * @param string $tempName - the source temporary file to save
74 * @return string - full path the stashed file, or false on failure
77 function saveTempUploadedFile( $saveName, $tempName ) {
80 $stash = 'stash!' . gmdate( "YmdHis" ) . '!' . $saveName;
81 $mfs = MogileFS
::NewMogileFS();
82 if ( !$mfs->saveFile( $stash, 'normal', $tempName ) ) {
83 $wgOut->showFileCopyError( $tempName, $stash );
91 * Stash a file in a temporary directory for later processing,
92 * and save the necessary descriptive info into the session.
93 * Returns a key value which will be passed through a form
94 * to pick up the path info on a later invocation.
99 function stashSession() {
100 $stash = $this->saveTempUploadedFile(
101 $this->mUploadSaveName
, $this->mUploadTempName
);
104 # Couldn't save the file.
108 $key = mt_rand( 0, 0x7fffffff );
109 $_SESSION['wsUploadData'][$key] = array(
110 'mUploadTempName' => $stash,
111 'mUploadSize' => $this->mUploadSize
,
112 'mOname' => $this->mOname
);
117 * Remove a temporarily kept file stashed by saveTempUploadedFile().
121 function unsaveUploadedFile() {
123 $mfs = MogileFS
::NewMogileFS();
124 if ( ! $mfs->delete( $this->mUploadTempName
) ) {
125 $wgOut->showFileDeleteError( $this->mUploadTempName
);