MediaWiki  1.34.0
UploadFromFile.php
Go to the documentation of this file.
1 <?php
30 class UploadFromFile extends UploadBase {
34  protected $mUpload = null;
35 
39  function initializeFromRequest( &$request ) {
40  $upload = $request->getUpload( 'wpUploadFile' );
41  $desiredDestName = $request->getText( 'wpDestFile' );
42  if ( !$desiredDestName ) {
43  $desiredDestName = $upload->getName();
44  }
45 
46  $this->initialize( $desiredDestName, $upload );
47  }
48 
54  function initialize( $name, $webRequestUpload ) {
55  $this->mUpload = $webRequestUpload;
56  $this->initializePathInfo( $name,
57  $this->mUpload->getTempName(), $this->mUpload->getSize() );
58  }
59 
64  static function isValidRequest( $request ) {
65  # Allow all requests, even if no file is present, so that an error
66  # because a post_max_size or upload_max_filesize overflow
67  return true;
68  }
69 
73  public function getSourceType() {
74  return 'file';
75  }
76 
80  public function verifyUpload() {
81  # Check for a post_max_size or upload_max_size overflow, so that a
82  # proper error can be shown to the user
83  if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
84  if ( $this->mUpload->isIniSizeOverflow() ) {
85  return [
86  'status' => UploadBase::FILE_TOO_LARGE,
87  'max' => min(
88  self::getMaxUploadSize( $this->getSourceType() ),
89  self::getMaxPhpUploadSize()
90  ),
91  ];
92  }
93  }
94 
95  return parent::verifyUpload();
96  }
97 }
UploadFromFile\$mUpload
WebRequestUpload $mUpload
Definition: UploadFromFile.php:34
UploadFromFile\initializeFromRequest
initializeFromRequest(&$request)
Definition: UploadFromFile.php:39
WebRequestUpload
Object to access the $_FILES array.
Definition: WebRequestUpload.php:30
UploadFromFile\initialize
initialize( $name, $webRequestUpload)
Initialize from a filename and a WebRequestUpload.
Definition: UploadFromFile.php:54
UploadFromFile\isValidRequest
static isValidRequest( $request)
Definition: UploadFromFile.php:64
UploadFromFile\verifyUpload
verifyUpload()
Definition: UploadFromFile.php:80
UploadFromFile\getSourceType
getSourceType()
Definition: UploadFromFile.php:73
UploadFromFile
Implements regular file uploads.
Definition: UploadFromFile.php:30