Index: trunk/phase3/includes/specials/SpecialUploadMogile.php |
— | — | @@ -1,135 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * @file |
5 | | - * @ingroup SpecialPage |
6 | | - */ |
7 | | - |
8 | | -/** |
9 | | - * You will need the extension MogileClient to use this special page. |
10 | | - */ |
11 | | -require_once( 'MogileFS.php' ); |
12 | | - |
13 | | -/** |
14 | | - * Entry point |
15 | | - */ |
16 | | -function wfSpecialUploadMogile() { |
17 | | - global $wgRequest; |
18 | | - $form = new UploadFormMogile( $wgRequest ); |
19 | | - $form->execute(); |
20 | | -} |
21 | | - |
22 | | -/** |
23 | | - * Extends Special:Upload with MogileFS. |
24 | | - * @ingroup SpecialPage |
25 | | - */ |
26 | | -class UploadFormMogile extends UploadForm { |
27 | | - /** |
28 | | - * Move the uploaded file from its temporary location to the final |
29 | | - * destination. If a previous version of the file exists, move |
30 | | - * it into the archive subdirectory. |
31 | | - * |
32 | | - * @todo If the later save fails, we may have disappeared the original file. |
33 | | - * |
34 | | - * @param string $saveName |
35 | | - * @param string $tempName full path to the temporary file |
36 | | - * @param bool $useRename Not used in this implementation |
37 | | - */ |
38 | | - function saveUploadedFile( $saveName, $tempName, $useRename = false ) { |
39 | | - global $wgOut; |
40 | | - $mfs = MogileFS::NewMogileFS(); |
41 | | - |
42 | | - $this->mSavedFile = "image!{$saveName}"; |
43 | | - |
44 | | - if( $mfs->getPaths( $this->mSavedFile )) { |
45 | | - $this->mUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}"; |
46 | | - if( !$mfs->rename( $this->mSavedFile, "archive!{$this->mUploadOldVersion}" ) ) { |
47 | | - $wgOut->showFileRenameError( $this->mSavedFile, |
48 | | - "archive!{$this->mUploadOldVersion}" ); |
49 | | - return false; |
50 | | - } |
51 | | - } else { |
52 | | - $this->mUploadOldVersion = ''; |
53 | | - } |
54 | | - |
55 | | - if ( $this->mStashed ) { |
56 | | - if (!$mfs->rename($tempName,$this->mSavedFile)) { |
57 | | - $wgOut->showFileRenameError($tempName, $this->mSavedFile ); |
58 | | - return false; |
59 | | - } |
60 | | - } else { |
61 | | - if ( !$mfs->saveFile($this->mSavedFile,'normal',$tempName )) { |
62 | | - $wgOut->showFileCopyError( $tempName, $this->mSavedFile ); |
63 | | - return false; |
64 | | - } |
65 | | - unlink($tempName); |
66 | | - } |
67 | | - return true; |
68 | | - } |
69 | | - |
70 | | - /** |
71 | | - * Stash a file in a temporary directory for later processing |
72 | | - * after the user has confirmed it. |
73 | | - * |
74 | | - * If the user doesn't explicitly cancel or accept, these files |
75 | | - * can accumulate in the temp directory. |
76 | | - * |
77 | | - * @param string $saveName - the destination filename |
78 | | - * @param string $tempName - the source temporary file to save |
79 | | - * @return string - full path the stashed file, or false on failure |
80 | | - * @access private |
81 | | - */ |
82 | | - function saveTempUploadedFile( $saveName, $tempName ) { |
83 | | - global $wgOut; |
84 | | - |
85 | | - $stash = 'stash!' . gmdate( "YmdHis" ) . '!' . $saveName; |
86 | | - $mfs = MogileFS::NewMogileFS(); |
87 | | - if ( !$mfs->saveFile( $stash, 'normal', $tempName ) ) { |
88 | | - $wgOut->showFileCopyError( $tempName, $stash ); |
89 | | - return false; |
90 | | - } |
91 | | - unlink($tempName); |
92 | | - return $stash; |
93 | | - } |
94 | | - |
95 | | - /** |
96 | | - * Stash a file in a temporary directory for later processing, |
97 | | - * and save the necessary descriptive info into the session. |
98 | | - * Returns a key value which will be passed through a form |
99 | | - * to pick up the path info on a later invocation. |
100 | | - * |
101 | | - * @return int |
102 | | - * @access private |
103 | | - */ |
104 | | - function stashSession() { |
105 | | - $stash = $this->saveTempUploadedFile( |
106 | | - $this->mUploadSaveName, $this->mUploadTempName ); |
107 | | - |
108 | | - if( !$stash ) { |
109 | | - # Couldn't save the file. |
110 | | - return false; |
111 | | - } |
112 | | - |
113 | | - $key = mt_rand( 0, 0x7fffffff ); |
114 | | - $_SESSION['wsUploadData'][$key] = array( |
115 | | - 'mUploadTempName' => $stash, |
116 | | - 'mUploadSize' => $this->mUploadSize, |
117 | | - 'mOname' => $this->mOname ); |
118 | | - return $key; |
119 | | - } |
120 | | - |
121 | | - /** |
122 | | - * Remove a temporarily kept file stashed by saveTempUploadedFile(). |
123 | | - * @access private |
124 | | - * @return success |
125 | | - */ |
126 | | - function unsaveUploadedFile() { |
127 | | - global $wgOut; |
128 | | - $mfs = MogileFS::NewMogileFS(); |
129 | | - if ( ! $mfs->delete( $this->mUploadTempName ) ) { |
130 | | - $wgOut->showFileDeleteError( $this->mUploadTempName ); |
131 | | - return false; |
132 | | - } else { |
133 | | - return true; |
134 | | - } |
135 | | - } |
136 | | -} |
Index: trunk/extensions/MogileClient/SpecialUploadMogile.php |
— | — | @@ -0,0 +1,135 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * @ingroup SpecialPage |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * You will need the extension MogileClient to use this special page. |
| 10 | + */ |
| 11 | +require_once( 'MogileFS.php' ); |
| 12 | + |
| 13 | +/** |
| 14 | + * Entry point |
| 15 | + */ |
| 16 | +function wfSpecialUploadMogile() { |
| 17 | + global $wgRequest; |
| 18 | + $form = new UploadFormMogile( $wgRequest ); |
| 19 | + $form->execute(); |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * Extends Special:Upload with MogileFS. |
| 24 | + * @ingroup SpecialPage |
| 25 | + */ |
| 26 | +class UploadFormMogile extends UploadForm { |
| 27 | + /** |
| 28 | + * Move the uploaded file from its temporary location to the final |
| 29 | + * destination. If a previous version of the file exists, move |
| 30 | + * it into the archive subdirectory. |
| 31 | + * |
| 32 | + * @todo If the later save fails, we may have disappeared the original file. |
| 33 | + * |
| 34 | + * @param string $saveName |
| 35 | + * @param string $tempName full path to the temporary file |
| 36 | + * @param bool $useRename Not used in this implementation |
| 37 | + */ |
| 38 | + function saveUploadedFile( $saveName, $tempName, $useRename = false ) { |
| 39 | + global $wgOut; |
| 40 | + $mfs = MogileFS::NewMogileFS(); |
| 41 | + |
| 42 | + $this->mSavedFile = "image!{$saveName}"; |
| 43 | + |
| 44 | + if( $mfs->getPaths( $this->mSavedFile )) { |
| 45 | + $this->mUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}"; |
| 46 | + if( !$mfs->rename( $this->mSavedFile, "archive!{$this->mUploadOldVersion}" ) ) { |
| 47 | + $wgOut->showFileRenameError( $this->mSavedFile, |
| 48 | + "archive!{$this->mUploadOldVersion}" ); |
| 49 | + return false; |
| 50 | + } |
| 51 | + } else { |
| 52 | + $this->mUploadOldVersion = ''; |
| 53 | + } |
| 54 | + |
| 55 | + if ( $this->mStashed ) { |
| 56 | + if (!$mfs->rename($tempName,$this->mSavedFile)) { |
| 57 | + $wgOut->showFileRenameError($tempName, $this->mSavedFile ); |
| 58 | + return false; |
| 59 | + } |
| 60 | + } else { |
| 61 | + if ( !$mfs->saveFile($this->mSavedFile,'normal',$tempName )) { |
| 62 | + $wgOut->showFileCopyError( $tempName, $this->mSavedFile ); |
| 63 | + return false; |
| 64 | + } |
| 65 | + unlink($tempName); |
| 66 | + } |
| 67 | + return true; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Stash a file in a temporary directory for later processing |
| 72 | + * after the user has confirmed it. |
| 73 | + * |
| 74 | + * If the user doesn't explicitly cancel or accept, these files |
| 75 | + * can accumulate in the temp directory. |
| 76 | + * |
| 77 | + * @param string $saveName - the destination filename |
| 78 | + * @param string $tempName - the source temporary file to save |
| 79 | + * @return string - full path the stashed file, or false on failure |
| 80 | + * @access private |
| 81 | + */ |
| 82 | + function saveTempUploadedFile( $saveName, $tempName ) { |
| 83 | + global $wgOut; |
| 84 | + |
| 85 | + $stash = 'stash!' . gmdate( "YmdHis" ) . '!' . $saveName; |
| 86 | + $mfs = MogileFS::NewMogileFS(); |
| 87 | + if ( !$mfs->saveFile( $stash, 'normal', $tempName ) ) { |
| 88 | + $wgOut->showFileCopyError( $tempName, $stash ); |
| 89 | + return false; |
| 90 | + } |
| 91 | + unlink($tempName); |
| 92 | + return $stash; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Stash a file in a temporary directory for later processing, |
| 97 | + * and save the necessary descriptive info into the session. |
| 98 | + * Returns a key value which will be passed through a form |
| 99 | + * to pick up the path info on a later invocation. |
| 100 | + * |
| 101 | + * @return int |
| 102 | + * @access private |
| 103 | + */ |
| 104 | + function stashSession() { |
| 105 | + $stash = $this->saveTempUploadedFile( |
| 106 | + $this->mUploadSaveName, $this->mUploadTempName ); |
| 107 | + |
| 108 | + if( !$stash ) { |
| 109 | + # Couldn't save the file. |
| 110 | + return false; |
| 111 | + } |
| 112 | + |
| 113 | + $key = mt_rand( 0, 0x7fffffff ); |
| 114 | + $_SESSION['wsUploadData'][$key] = array( |
| 115 | + 'mUploadTempName' => $stash, |
| 116 | + 'mUploadSize' => $this->mUploadSize, |
| 117 | + 'mOname' => $this->mOname ); |
| 118 | + return $key; |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Remove a temporarily kept file stashed by saveTempUploadedFile(). |
| 123 | + * @access private |
| 124 | + * @return success |
| 125 | + */ |
| 126 | + function unsaveUploadedFile() { |
| 127 | + global $wgOut; |
| 128 | + $mfs = MogileFS::NewMogileFS(); |
| 129 | + if ( ! $mfs->delete( $this->mUploadTempName ) ) { |
| 130 | + $wgOut->showFileDeleteError( $this->mUploadTempName ); |
| 131 | + return false; |
| 132 | + } else { |
| 133 | + return true; |
| 134 | + } |
| 135 | + } |
| 136 | +} |
Property changes on: trunk/extensions/MogileClient/SpecialUploadMogile.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 137 | + native |
Name: svn:keywords |
2 | 138 | + Author Date Id Revision |