(bug 35565) Special:Log/patrol doesn't indicate whether patrolling was automatic
[mediawiki.git] / includes / upload / UploadFromFile.php
blob234fde848b390181967c6ac5343e4b47872d0f45
1 <?php
2 /**
3 * Implements regular file uploads
5 * @ingroup Upload
6 * @author Bryan Tong Minh
7 */
8 class UploadFromFile extends UploadBase {
10 /**
11 * @var WebRequestUpload
13 protected $mUpload = null;
15 /**
16 * @param $request WebRequest
17 * @return null
19 function initializeFromRequest( &$request ) {
20 $upload = $request->getUpload( 'wpUploadFile' );
21 $desiredDestName = $request->getText( 'wpDestFile' );
22 if( !$desiredDestName )
23 $desiredDestName = $upload->getName();
25 return $this->initialize( $desiredDestName, $upload );
28 /**
29 * Initialize from a filename and a WebRequestUpload
30 * @param $name
31 * @param $webRequestUpload
32 * @return null
34 function initialize( $name, $webRequestUpload ) {
35 $this->mUpload = $webRequestUpload;
36 return $this->initializePathInfo( $name,
37 $this->mUpload->getTempName(), $this->mUpload->getSize() );
40 /**
41 * @param $request
42 * @return bool
44 static function isValidRequest( $request ) {
45 # Allow all requests, even if no file is present, so that an error
46 # because a post_max_size or upload_max_filesize overflow
47 return true;
50 /**
51 * @return string
53 public function getSourceType() {
54 return 'file';
57 /**
58 * @return array
60 public function verifyUpload() {
61 # Check for a post_max_size or upload_max_size overflow, so that a
62 # proper error can be shown to the user
63 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
64 if ( $this->mUpload->isIniSizeOverflow() ) {
65 return array(
66 'status' => UploadBase::FILE_TOO_LARGE,
67 'max' => min(
68 self::getMaxUploadSize( $this->getSourceType() ),
69 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
70 wfShorthandToInteger( ini_get( 'post_max_size' ) )
76 return parent::verifyUpload();