MediaWiki master
UploadFromFile.php
Go to the documentation of this file.
1<?php
26
37 protected $mUpload = null;
38
42 public function initializeFromRequest( &$request ) {
43 $upload = $request->getUpload( 'wpUploadFile' );
44 $desiredDestName = $request->getText( 'wpDestFile' );
45 if ( !$desiredDestName ) {
46 $desiredDestName = $upload->getName();
47 }
48
49 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable getName only null on failure
50 $this->initialize( $desiredDestName, $upload );
51 }
52
58 public function initialize( $name, $webRequestUpload ) {
59 $this->mUpload = $webRequestUpload;
60 $this->initializePathInfo( $name,
61 $this->mUpload->getTempName(), $this->mUpload->getSize() );
62 }
63
68 public static function isValidRequest( $request ) {
69 # Allow all requests, even if no file is present, so that an error
70 # because a post_max_size or upload_max_filesize overflow
71 return true;
72 }
73
77 public function getSourceType() {
78 return 'file';
79 }
80
84 public function verifyUpload() {
85 # Check for a post_max_size or upload_max_size overflow, so that a
86 # proper error can be shown to the user
87 if ( $this->mTempPath === null || $this->isEmptyFile() ) {
88 if ( $this->mUpload->isIniSizeOverflow() ) {
89 return [
91 'max' => min(
92 self::getMaxUploadSize( $this->getSourceType() ),
93 self::getMaxPhpUploadSize()
94 ),
95 ];
96 }
97 }
98
99 return parent::verifyUpload();
100 }
101}
Object to access the $_FILES array.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form,...
UploadBase and subclasses are the backend of MediaWiki's file uploads.
isEmptyFile()
Return true if the file is empty.
initializePathInfo( $name, $tempPath, $fileSize, $removeTempFile=false)
const FILE_TOO_LARGE
Implements regular file uploads.
initialize( $name, $webRequestUpload)
Initialize from a filename and a MediaWiki\Request\WebRequestUpload.
static isValidRequest( $request)
WebRequestUpload $mUpload
initializeFromRequest(&$request)