5 * @subpackage SpecialPage
11 require_once( 'MogileFS.php' );
16 function wfSpecialUploadMogile() {
18 $form = new UploadFormMogile( $wgRequest );
22 /** @package MediaWiki */
23 class UploadFormMogile
extends UploadForm
{
25 * Move the uploaded file from its temporary location to the final
26 * destination. If a previous version of the file exists, move
27 * it into the archive subdirectory.
29 * @todo If the later save fails, we may have disappeared the original file.
31 * @param string $saveName
32 * @param string $tempName full path to the temporary file
33 * @param bool $useRename Not used in this implementation
35 function saveUploadedFile( $saveName, $tempName, $useRename = false ) {
37 $mfs = MogileFS
::NewMogileFS();
39 $this->mSavedFile
= "image!{$saveName}";
41 if( $mfs->getPaths( $this->mSavedFile
)) {
42 $this->mUploadOldVersion
= gmdate( 'YmdHis' ) . "!{$saveName}";
43 if( !$mfs->rename( $this->mSavedFile
, "archive!{$this->mUploadOldVersion}" ) ) {
44 $wgOut->showFileRenameError( $this->mSavedFile
,
45 "archive!{$this->mUploadOldVersion}" );
49 $this->mUploadOldVersion
= '';
52 if ( $this->mStashed
) {
53 if (!$mfs->rename($tempName,$this->mSavedFile
)) {
54 $wgOut->showFileRenameError($tempName, $this->mSavedFile
);
58 if ( !$mfs->saveFile($this->mSavedFile
,'normal',$tempName )) {
59 $wgOut->showFileCopyError( $tempName, $this->mSavedFile
);
68 * Stash a file in a temporary directory for later processing
69 * after the user has confirmed it.
71 * If the user doesn't explicitly cancel or accept, these files
72 * can accumulate in the temp directory.
74 * @param string $saveName - the destination filename
75 * @param string $tempName - the source temporary file to save
76 * @return string - full path the stashed file, or false on failure
79 function saveTempUploadedFile( $saveName, $tempName ) {
82 $stash = 'stash!' . gmdate( "YmdHis" ) . '!' . $saveName;
83 $mfs = MogileFS
::NewMogileFS();
84 if ( !$mfs->saveFile( $stash, 'normal', $tempName ) ) {
85 $wgOut->showFileCopyError( $tempName, $stash );
93 * Stash a file in a temporary directory for later processing,
94 * and save the necessary descriptive info into the session.
95 * Returns a key value which will be passed through a form
96 * to pick up the path info on a later invocation.
101 function stashSession() {
102 $stash = $this->saveTempUploadedFile(
103 $this->mUploadSaveName
, $this->mUploadTempName
);
106 # Couldn't save the file.
110 $key = mt_rand( 0, 0x7fffffff );
111 $_SESSION['wsUploadData'][$key] = array(
112 'mUploadTempName' => $stash,
113 'mUploadSize' => $this->mUploadSize
,
114 'mOname' => $this->mOname
);
119 * Remove a temporarily kept file stashed by saveTempUploadedFile().
123 function unsaveUploadedFile() {
125 $mfs = MogileFS
::NewMogileFS();
126 if ( ! $mfs->delete( $this->mUploadTempName
) ) {
127 $wgOut->showFileDeleteError( $this->mUploadTempName
);