00001 <?php 00010 require_once( 'MogileFS.php' ); 00011 00015 function wfSpecialUploadMogile() { 00016 global $wgRequest; 00017 $form = new UploadFormMogile( $wgRequest ); 00018 $form->execute(); 00019 } 00020 00025 class UploadFormMogile extends UploadForm { 00037 function saveUploadedFile( $saveName, $tempName, $useRename = false ) { 00038 global $wgOut; 00039 $mfs = MogileFS::NewMogileFS(); 00040 00041 $this->mSavedFile = "image!{$saveName}"; 00042 00043 if( $mfs->getPaths( $this->mSavedFile )) { 00044 $this->mUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}"; 00045 if( !$mfs->rename( $this->mSavedFile, "archive!{$this->mUploadOldVersion}" ) ) { 00046 $wgOut->showFileRenameError( $this->mSavedFile, 00047 "archive!{$this->mUploadOldVersion}" ); 00048 return false; 00049 } 00050 } else { 00051 $this->mUploadOldVersion = ''; 00052 } 00053 00054 if ( $this->mStashed ) { 00055 if (!$mfs->rename($tempName,$this->mSavedFile)) { 00056 $wgOut->showFileRenameError($tempName, $this->mSavedFile ); 00057 return false; 00058 } 00059 } else { 00060 if ( !$mfs->saveFile($this->mSavedFile,'normal',$tempName )) { 00061 $wgOut->showFileCopyError( $tempName, $this->mSavedFile ); 00062 return false; 00063 } 00064 unlink($tempName); 00065 } 00066 return true; 00067 } 00068 00081 function saveTempUploadedFile( $saveName, $tempName ) { 00082 global $wgOut; 00083 00084 $stash = 'stash!' . gmdate( "YmdHis" ) . '!' . $saveName; 00085 $mfs = MogileFS::NewMogileFS(); 00086 if ( !$mfs->saveFile( $stash, 'normal', $tempName ) ) { 00087 $wgOut->showFileCopyError( $tempName, $stash ); 00088 return false; 00089 } 00090 unlink($tempName); 00091 return $stash; 00092 } 00093 00103 function stashSession() { 00104 $stash = $this->saveTempUploadedFile( 00105 $this->mUploadSaveName, $this->mUploadTempName ); 00106 00107 if( !$stash ) { 00108 # Couldn't save the file. 00109 return false; 00110 } 00111 00112 $key = mt_rand( 0, 0x7fffffff ); 00113 $_SESSION['wsUploadData'][$key] = array( 00114 'mUploadTempName' => $stash, 00115 'mUploadSize' => $this->mUploadSize, 00116 'mOname' => $this->mOname ); 00117 return $key; 00118 } 00119 00125 function unsaveUploadedFile() { 00126 global $wgOut; 00127 $mfs = MogileFS::NewMogileFS(); 00128 if ( ! $mfs->delete( $this->mUploadTempName ) ) { 00129 $wgOut->showFileDeleteError( $this->mUploadTempName ); 00130 return false; 00131 } else { 00132 return true; 00133 } 00134 } 00135 }