Fixed regex in doMagicLinks (broken since r15976)
[mediawiki.git] / includes / SpecialUploadMogile.php
blob51a6dd28c5bffd1e59f4f37accac8d144e5fdfd5
1 <?php
2 /**
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
8 /**
11 require_once( 'SpecialUpload.php' );
12 require_once( 'MogileFS.php' );
14 /**
15 * Entry point
17 function wfSpecialUploadMogile() {
18 global $wgRequest;
19 $form = new UploadFormMogile( $wgRequest );
20 $form->execute();
23 /** @package MediaWiki */
24 class UploadFormMogile extends UploadForm {
25 /**
26 * Move the uploaded file from its temporary location to the final
27 * destination. If a previous version of the file exists, move
28 * it into the archive subdirectory.
30 * @todo If the later save fails, we may have disappeared the original file.
32 * @param string $saveName
33 * @param string $tempName full path to the temporary file
34 * @param bool $useRename Not used in this implementation
36 function saveUploadedFile( $saveName, $tempName, $useRename = false ) {
37 global $wgOut;
38 $mfs = MogileFS::NewMogileFS();
40 $this->mSavedFile = "image!{$saveName}";
42 if( $mfs->getPaths( $this->mSavedFile )) {
43 $this->mUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}";
44 if( !$mfs->rename( $this->mSavedFile, "archive!{$this->mUploadOldVersion}" ) ) {
45 $wgOut->showFileRenameError( $this->mSavedFile,
46 "archive!{$this->mUploadOldVersion}" );
47 return false;
49 } else {
50 $this->mUploadOldVersion = '';
53 if ( $this->mStashed ) {
54 if (!$mfs->rename($tempName,$this->mSavedFile)) {
55 $wgOut->showFileRenameError($tempName, $this->mSavedFile );
56 return false;
58 } else {
59 if ( !$mfs->saveFile($this->mSavedFile,'normal',$tempName )) {
60 $wgOut->showFileCopyError( $tempName, $this->mSavedFile );
61 return false;
63 unlink($tempName);
65 return true;
68 /**
69 * Stash a file in a temporary directory for later processing
70 * after the user has confirmed it.
72 * If the user doesn't explicitly cancel or accept, these files
73 * can accumulate in the temp directory.
75 * @param string $saveName - the destination filename
76 * @param string $tempName - the source temporary file to save
77 * @return string - full path the stashed file, or false on failure
78 * @access private
80 function saveTempUploadedFile( $saveName, $tempName ) {
81 global $wgOut;
83 $stash = 'stash!' . gmdate( "YmdHis" ) . '!' . $saveName;
84 $mfs = MogileFS::NewMogileFS();
85 if ( !$mfs->saveFile( $stash, 'normal', $tempName ) ) {
86 $wgOut->showFileCopyError( $tempName, $stash );
87 return false;
89 unlink($tempName);
90 return $stash;
93 /**
94 * Stash a file in a temporary directory for later processing,
95 * and save the necessary descriptive info into the session.
96 * Returns a key value which will be passed through a form
97 * to pick up the path info on a later invocation.
99 * @return int
100 * @access private
102 function stashSession() {
103 $stash = $this->saveTempUploadedFile(
104 $this->mUploadSaveName, $this->mUploadTempName );
106 if( !$stash ) {
107 # Couldn't save the file.
108 return false;
111 $key = mt_rand( 0, 0x7fffffff );
112 $_SESSION['wsUploadData'][$key] = array(
113 'mUploadTempName' => $stash,
114 'mUploadSize' => $this->mUploadSize,
115 'mOname' => $this->mOname );
116 return $key;
120 * Remove a temporarily kept file stashed by saveTempUploadedFile().
121 * @access private
122 * @return success
124 function unsaveUploadedFile() {
125 global $wgOut;
126 $mfs = MogileFS::NewMogileFS();
127 if ( ! $mfs->delete( $this->mUploadTempName ) ) {
128 $wgOut->showFileDeleteError( $this->mUploadTempName );
129 return false;
130 } else {
131 return true;