wiki.techinc.nl/includes/upload/UploadFromFile.php
Bryan Tong Minh b4310925ba Follow-up r70037: Fix ApiUpload by passing a WebRequestUpload to the the initializer
Follow-up r64403 and r69911: Fix broken upload from stash in Api. 

Please tests your commits, even if the change seems totally harmless. You can use <http://mwclient.svn.sourceforge.net/viewvc/mwclient/tests/upload_api_test.py?revision=HEAD&view=markup> to automatically test uploading via the Api.
2010-07-27 21:53:52 +00:00

55 lines
1.5 KiB
PHP

<?php
/**
* @file
* @ingroup upload
*
* @author Bryan Tong Minh
*
* Implements regular file uploads
*/
class UploadFromFile extends UploadBase {
protected $mUpload = null;
function initializeFromRequest( &$request ) {
$upload = $request->getUpload( 'wpUploadFile' );
$desiredDestName = $request->getText( 'wpDestFile' );
if( !$desiredDestName )
$desiredDestName = $upload->getName();
return $this->initialize( $desiredDestName, $upload );
}
/**
* Initialize from a filename and a WebRequestUpload
*/
function initialize( $name, $webRequestUpload ) {
$this->mUpload = $webRequestUpload;
return $this->initializePathInfo( $name,
$this->mUpload->getTempName(), $this->mUpload->getSize() );
}
static function isValidRequest( $request ) {
# Allow all requests, even if no file is present, so that an error
# because a post_max_size or upload_max_filesize overflow
return true;
}
public function verifyUpload() {
# Check for a post_max_size or upload_max_size overflow, so that a
# proper error can be shown to the user
if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
if ( $this->mUpload->isIniSizeOverflow() ) {
global $wgMaxUploadSize;
return array(
'status' => self::FILE_TOO_LARGE,
'max' => min(
$wgMaxUploadSize,
wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
wfShorthandToInteger( ini_get( 'post_max_size' ) )
),
);
}
}
return parent::verifyUpload();
}
}