MediaWiki  master
UploadFromFile.php
Go to the documentation of this file.
1 <?php
30 class UploadFromFile extends UploadBase {
34  protected $mUpload = null;
35 
39  public 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  public function initialize( $name, $webRequestUpload ) {
55  $this->mUpload = $webRequestUpload;
56  // @phan-suppress-next-line SecurityCheck-PathTraversal False positive T268920
57  $this->initializePathInfo( $name,
58  $this->mUpload->getTempName(), $this->mUpload->getSize() );
59  }
60 
65  public static function isValidRequest( $request ) {
66  # Allow all requests, even if no file is present, so that an error
67  # because a post_max_size or upload_max_filesize overflow
68  return true;
69  }
70 
74  public function getSourceType() {
75  return 'file';
76  }
77 
81  public function verifyUpload() {
82  # Check for a post_max_size or upload_max_size overflow, so that a
83  # proper error can be shown to the user
84  if ( $this->mTempPath === null || $this->isEmptyFile() ) {
85  if ( $this->mUpload->isIniSizeOverflow() ) {
86  return [
87  'status' => UploadBase::FILE_TOO_LARGE,
88  'max' => min(
89  self::getMaxUploadSize( $this->getSourceType() ),
90  self::getMaxPhpUploadSize()
91  ),
92  ];
93  }
94  }
95 
96  return parent::verifyUpload();
97  }
98 }
UploadBase
UploadBase and subclasses are the backend of MediaWiki's file uploads.
Definition: UploadBase.php:45
UploadBase\FILE_TOO_LARGE
const FILE_TOO_LARGE
Definition: UploadBase.php:110
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
UploadBase\isEmptyFile
isEmptyFile()
Return true if the file is empty.
Definition: UploadBase.php:306
UploadBase\initializePathInfo
initializePathInfo( $name, $tempPath, $fileSize, $removeTempFile=false)
Definition: UploadBase.php:259
UploadFromFile\isValidRequest
static isValidRequest( $request)
Definition: UploadFromFile.php:65
UploadFromFile\verifyUpload
verifyUpload()
Definition: UploadFromFile.php:81
UploadFromFile\getSourceType
getSourceType()
Definition: UploadFromFile.php:74
UploadFromFile
Implements regular file uploads.
Definition: UploadFromFile.php:30