MediaWiki master
UploadFromFile.php
Go to the documentation of this file.
1<?php
10namespace MediaWiki\Upload;
11
14
25 protected $mUpload = null;
26
30 public function initializeFromRequest( &$request ) {
31 $upload = $request->getUpload( 'wpUploadFile' );
32 $desiredDestName = $request->getText( 'wpDestFile' );
33 if ( !$desiredDestName ) {
34 $desiredDestName = $upload->getName();
35 }
36
37 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable getName only null on failure
38 $this->initialize( $desiredDestName, $upload );
39 }
40
46 public function initialize( $name, $webRequestUpload ) {
47 $this->mUpload = $webRequestUpload;
48 $this->initializePathInfo( $name,
49 $this->mUpload->getTempName(), $this->mUpload->getSize() );
50 }
51
56 public static function isValidRequest( $request ) {
57 # Allow all requests, even if no file is present, so that an error
58 # because a post_max_size or upload_max_filesize overflow
59 return true;
60 }
61
65 public function getSourceType() {
66 return 'file';
67 }
68
69 public function skipStashFileAttempt(): bool {
70 $tempName = $this->mUpload?->getTempName();
71 if ( $tempName !== null ) {
72 return !file_exists( $tempName );
73 }
74 return parent::skipStashFileAttempt();
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 ( $this->mTempPath === null || $this->isEmptyFile() ) {
84 if ( $this->mUpload->isIniSizeOverflow() ) {
85 return [
87 'max' => min(
88 self::getMaxUploadSize( $this->getSourceType() ),
89 self::getMaxPhpUploadSize()
90 ),
91 ];
92 }
93 }
94
95 return parent::verifyUpload();
96 }
97}
98
100class_alias( UploadFromFile::class, 'UploadFromFile' );
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.
initializePathInfo( $name, $tempPath, $fileSize, $removeTempFile=false)
Implements regular file uploads.
skipStashFileAttempt()
Check, if stash file attempt should be skipped, for example when the file is already known to stash.
initialize( $name, $webRequestUpload)
Initialize from a filename and a MediaWiki\Request\WebRequestUpload.