8 * You will need the extension MogileClient to use this special page.
10 require_once( 'MogileFS.php' );
15 function wfSpecialUploadMogile() {
17 $form = new UploadFormMogile( $wgRequest );
22 * Extends Special:Upload with MogileFS.
23 * @ingroup SpecialPage
25 class UploadFormMogile
extends UploadForm
{
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 ) {
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}" );
51 $this->mUploadOldVersion
= '';
54 if ( $this->mStashed
) {
55 if (!$mfs->rename($tempName,$this->mSavedFile
)) {
56 $wgOut->showFileRenameError($tempName, $this->mSavedFile
);
60 if ( !$mfs->saveFile($this->mSavedFile
,'normal',$tempName )) {
61 $wgOut->showFileCopyError( $tempName, $this->mSavedFile
);
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
81 function saveTempUploadedFile( $saveName, $tempName ) {
84 $stash = 'stash!' . gmdate( "YmdHis" ) . '!' . $saveName;
85 $mfs = MogileFS
::NewMogileFS();
86 if ( !$mfs->saveFile( $stash, 'normal', $tempName ) ) {
87 $wgOut->showFileCopyError( $tempName, $stash );
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.
103 function stashSession() {
104 $stash = $this->saveTempUploadedFile(
105 $this->mUploadSaveName
, $this->mUploadTempName
);
108 # Couldn't save the file.
112 $key = mt_rand( 0, 0x7fffffff );
113 $_SESSION['wsUploadData'][$key] = array(
114 'mUploadTempName' => $stash,
115 'mUploadSize' => $this->mUploadSize
,
116 'mOname' => $this->mOname
);
121 * Remove a temporarily kept file stashed by saveTempUploadedFile().
125 function unsaveUploadedFile() {
127 $mfs = MogileFS
::NewMogileFS();
128 if ( ! $mfs->delete( $this->mUploadTempName
) ) {
129 $wgOut->showFileDeleteError( $this->mUploadTempName
);