Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / upload / UploadFromFile.php
bloba9972c2d939fd89fe21f27aa65d1ebcf17a70421
1 <?php
2 /**
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
20 * @file
21 * @ingroup Upload
24 use MediaWiki\Request\WebRequest;
25 use MediaWiki\Request\WebRequestUpload;
27 /**
28 * Implements regular file uploads
30 * @ingroup Upload
31 * @author Bryan Tong Minh
33 class UploadFromFile extends UploadBase {
34 /**
35 * @var WebRequestUpload
37 protected $mUpload = null;
39 /**
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 );
53 /**
54 * Initialize from a filename and a MediaWiki\Request\WebRequestUpload
55 * @param string $name
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() );
64 /**
65 * @param WebRequest $request
66 * @return bool
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;
74 /**
75 * @return string
77 public function getSourceType() {
78 return 'file';
81 /**
82 * @return array
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 [
90 'status' => UploadBase::FILE_TOO_LARGE,
91 'max' => min(
92 self::getMaxUploadSize( $this->getSourceType() ),
93 self::getMaxPhpUploadSize()
99 return parent::verifyUpload();