3 * Backend for regular file upload.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 use MediaWiki\Request\WebRequest
;
25 use MediaWiki\Request\WebRequestUpload
;
28 * Implements regular file uploads
31 * @author Bryan Tong Minh
33 class UploadFromFile
extends UploadBase
{
35 * @var WebRequestUpload
37 protected $mUpload = null;
40 * @param WebRequest &$request
42 public function initializeFromRequest( &$request ) {
43 $upload = $request->getUpload( 'wpUploadFile' );
44 $desiredDestName = $request->getText( 'wpDestFile' );
45 if ( !$desiredDestName ) {
46 $desiredDestName = $upload->getName();
49 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable getName only null on failure
50 $this->initialize( $desiredDestName, $upload );
54 * Initialize from a filename and a MediaWiki\Request\WebRequestUpload
56 * @param WebRequestUpload $webRequestUpload
58 public function initialize( $name, $webRequestUpload ) {
59 $this->mUpload
= $webRequestUpload;
60 $this->initializePathInfo( $name,
61 $this->mUpload
->getTempName(), $this->mUpload
->getSize() );
65 * @param WebRequest $request
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
77 public function getSourceType() {
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() ) {
90 'status' => UploadBase
::FILE_TOO_LARGE
,
92 self
::getMaxUploadSize( $this->getSourceType() ),
93 self
::getMaxPhpUploadSize()
99 return parent
::verifyUpload();