<?php
/**
*
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
*/
/**
- *
+ * You will need the extension MogileClient to use this special page.
*/
-require_once( 'SpecialUpload.php' );
-
+require_once( 'MogileFS.php' );
/**
* Entry point
*/
function wfSpecialUploadMogile() {
- global $wgRequest;
- $form = new UploadFormMogile( $wgRequest );
- $form->execute();
+ global $wgRequest;
+ $form = new UploadFormMogile( $wgRequest );
+ $form->execute();
}
-
+/**
+ * Extends Special:Upload with MogileFS.
+ * @addtogroup SpecialPage
+ */
class UploadFormMogile extends UploadForm {
/**
* Move the uploaded file from its temporary location to the final
* @param bool $useRename Not used in this implementation
*/
function saveUploadedFile( $saveName, $tempName, $useRename = false ) {
- global $wgUploadDirectory, $wgOut;
+ global $wgOut;
+ $mfs = MogileFS::NewMogileFS();
- $this->mSavedFile = "archive!{$saveName}";
+ $this->mSavedFile = "image!{$saveName}";
- if( $mfs->getPaths( $this->mSavedFile ) ) {
+ if( $mfs->getPaths( $this->mSavedFile )) {
$this->mUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}";
- if( !$mfs->rename( $this->mSavedFile, "${archive}!{$this->mUploadOldVersion}" ) ) {
- $wgOut->fileRenameError( $this->mSavedFile,
- "${archive}!{$this->mUploadOldVersion}" );
+ if( !$mfs->rename( $this->mSavedFile, "archive!{$this->mUploadOldVersion}" ) ) {
+ $wgOut->showFileRenameError( $this->mSavedFile,
+ "archive!{$this->mUploadOldVersion}" );
return false;
}
} else {
$this->mUploadOldVersion = '';
}
-
- if ( $mfs->saveFile($this->mSavedFile,'image',$tempName )) {
- $wgOut->fileCopyError( $tempName, $this->mSavedFile );
- return false;
+
+ if ( $this->mStashed ) {
+ if (!$mfs->rename($tempName,$this->mSavedFile)) {
+ $wgOut->showFileRenameError($tempName, $this->mSavedFile );
+ return false;
+ }
+ } else {
+ if ( !$mfs->saveFile($this->mSavedFile,'normal',$tempName )) {
+ $wgOut->showFileCopyError( $tempName, $this->mSavedFile );
+ return false;
+ }
+ unlink($tempName);
}
- unlink($tempName);
return true;
}
global $wgOut;
$stash = 'stash!' . gmdate( "YmdHis" ) . '!' . $saveName;
-
- if ( !$mfs->saveFile( $tempName, 'stash', $stash ) ) {
- $wgOut->fileCopyError( $tempName, $stash );
+ $mfs = MogileFS::NewMogileFS();
+ if ( !$mfs->saveFile( $stash, 'normal', $tempName ) ) {
+ $wgOut->showFileCopyError( $tempName, $stash );
return false;
}
unlink($tempName);
return $stash;
}
-
+
/**
* Stash a file in a temporary directory for later processing,
* and save the necessary descriptive info into the session.
# Couldn't save the file.
return false;
}
-
+
$key = mt_rand( 0, 0x7fffffff );
$_SESSION['wsUploadData'][$key] = array(
'mUploadTempName' => $stash,
/**
* Remove a temporarily kept file stashed by saveTempUploadedFile().
* @access private
+ * @return success
*/
function unsaveUploadedFile() {
- if ( ! @$mfs->delete( $this->mUploadTempName ) ) {
- $wgOut->fileDeleteError( $this->mUploadTempName );
+ global $wgOut;
+ $mfs = MogileFS::NewMogileFS();
+ if ( ! $mfs->delete( $this->mUploadTempName ) ) {
+ $wgOut->showFileDeleteError( $this->mUploadTempName );
+ return false;
+ } else {
+ return true;
}
}
-
- /* -------------------------------------------------------------- */
}
-?>
+