MediaWiki REL1_40
UploadFromFile.php
Go to the documentation of this file.
1<?php
25
36 protected $mUpload = null;
37
41 public function initializeFromRequest( &$request ) {
42 $upload = $request->getUpload( 'wpUploadFile' );
43 $desiredDestName = $request->getText( 'wpDestFile' );
44 if ( !$desiredDestName ) {
45 $desiredDestName = $upload->getName();
46 }
47
48 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable getName only null on failure
49 $this->initialize( $desiredDestName, $upload );
50 }
51
57 public function initialize( $name, $webRequestUpload ) {
58 $this->mUpload = $webRequestUpload;
59 $this->initializePathInfo( $name,
60 $this->mUpload->getTempName(), $this->mUpload->getSize() );
61 }
62
67 public static function isValidRequest( $request ) {
68 # Allow all requests, even if no file is present, so that an error
69 # because a post_max_size or upload_max_filesize overflow
70 return true;
71 }
72
76 public function getSourceType() {
77 return 'file';
78 }
79
83 public function verifyUpload() {
84 # Check for a post_max_size or upload_max_size overflow, so that a
85 # proper error can be shown to the user
86 if ( $this->mTempPath === null || $this->isEmptyFile() ) {
87 if ( $this->mUpload->isIniSizeOverflow() ) {
88 return [
90 'max' => min(
91 self::getMaxUploadSize( $this->getSourceType() ),
92 self::getMaxPhpUploadSize()
93 ),
94 ];
95 }
96 }
97
98 return parent::verifyUpload();
99 }
100}
Object to access the $_FILES array.
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)