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
45 public function initialize( $name, $webRequestUpload ) {
46 $this->mUpload = $webRequestUpload;
47 $this->initializePathInfo( $name,
48 $this->mUpload->getTempName(), $this->mUpload->getSize() );
49 }
50
55 public static function isValidRequest( $request ) {
56 // Allow all requests, even if no file is present, so that an error
57 // due to a post_max_size or upload_max_filesize overflow will be
58 // shown.
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)