*Tweak rev_deleted message
[mediawiki.git] / includes / SpecialUploadMogile.php
blob438e1df4585fbb2d9e04fc83aea848aef4364a5c
1 <?php
2 /**
4 * @addtogroup SpecialPage
5 */
7 /**
8 * You will need the extension MogileClient to use this special page.
9 */
10 require_once( 'MogileFS.php' );
12 /**
13 * Entry point
15 function wfSpecialUploadMogile() {
16 global $wgRequest;
17 $form = new UploadFormMogile( $wgRequest );
18 $form->execute();
21 /**
22 * Extends Special:Upload with MogileFS.
23 * @addtogroup SpecialPage
25 class UploadFormMogile extends UploadForm {
26 /**
27 * Move the uploaded file from its temporary location to the final
28 * destination. If a previous version of the file exists, move
29 * it into the archive subdirectory.
31 * @todo If the later save fails, we may have disappeared the original file.
33 * @param string $saveName
34 * @param string $tempName full path to the temporary file
35 * @param bool $useRename Not used in this implementation
37 function saveUploadedFile( $saveName, $tempName, $useRename = false ) {
38 global $wgOut;
39 $mfs = MogileFS::NewMogileFS();
41 $this->mSavedFile = "image!{$saveName}";
43 if( $mfs->getPaths( $this->mSavedFile )) {
44 $this->mUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}";
45 if( !$mfs->rename( $this->mSavedFile, "archive!{$this->mUploadOldVersion}" ) ) {
46 $wgOut->showFileRenameError( $this->mSavedFile,
47 "archive!{$this->mUploadOldVersion}" );
48 return false;
50 } else {
51 $this->mUploadOldVersion = '';
54 if ( $this->mStashed ) {
55 if (!$mfs->rename($tempName,$this->mSavedFile)) {
56 $wgOut->showFileRenameError($tempName, $this->mSavedFile );
57 return false;
59 } else {
60 if ( !$mfs->saveFile($this->mSavedFile,'normal',$tempName )) {
61 $wgOut->showFileCopyError( $tempName, $this->mSavedFile );
62 return false;
64 unlink($tempName);
66 return true;
69 /**
70 * Stash a file in a temporary directory for later processing
71 * after the user has confirmed it.
73 * If the user doesn't explicitly cancel or accept, these files
74 * can accumulate in the temp directory.
76 * @param string $saveName - the destination filename
77 * @param string $tempName - the source temporary file to save
78 * @return string - full path the stashed file, or false on failure
79 * @access private
81 function saveTempUploadedFile( $saveName, $tempName ) {
82 global $wgOut;
84 $stash = 'stash!' . gmdate( "YmdHis" ) . '!' . $saveName;
85 $mfs = MogileFS::NewMogileFS();
86 if ( !$mfs->saveFile( $stash, 'normal', $tempName ) ) {
87 $wgOut->showFileCopyError( $tempName, $stash );
88 return false;
90 unlink($tempName);
91 return $stash;
94 /**
95 * Stash a file in a temporary directory for later processing,
96 * and save the necessary descriptive info into the session.
97 * Returns a key value which will be passed through a form
98 * to pick up the path info on a later invocation.
100 * @return int
101 * @access private
103 function stashSession() {
104 $stash = $this->saveTempUploadedFile(
105 $this->mUploadSaveName, $this->mUploadTempName );
107 if( !$stash ) {
108 # Couldn't save the file.
109 return false;
112 $key = mt_rand( 0, 0x7fffffff );
113 $_SESSION['wsUploadData'][$key] = array(
114 'mUploadTempName' => $stash,
115 'mUploadSize' => $this->mUploadSize,
116 'mOname' => $this->mOname );
117 return $key;
121 * Remove a temporarily kept file stashed by saveTempUploadedFile().
122 * @access private
123 * @return success
125 function unsaveUploadedFile() {
126 global $wgOut;
127 $mfs = MogileFS::NewMogileFS();
128 if ( ! $mfs->delete( $this->mUploadTempName ) ) {
129 $wgOut->showFileDeleteError( $this->mUploadTempName );
130 return false;
131 } else {
132 return true;