Merge "Add ss_active_users in SiteStats::isSane"
[mediawiki.git] / includes / upload / UploadFromFile.php
bloba00ed327a6d972b4ff2848c6d5a071405ac833b4
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 /**
25 * Implements regular file uploads
27 * @ingroup Upload
28 * @author Bryan Tong Minh
30 class UploadFromFile extends UploadBase {
32 /**
33 * @var WebRequestUpload
35 protected $mUpload = null;
37 /**
38 * @param $request WebRequest
40 function initializeFromRequest( &$request ) {
41 $upload = $request->getUpload( 'wpUploadFile' );
42 $desiredDestName = $request->getText( 'wpDestFile' );
43 if ( !$desiredDestName ) {
44 $desiredDestName = $upload->getName();
47 $this->initialize( $desiredDestName, $upload );
50 /**
51 * Initialize from a filename and a WebRequestUpload
52 * @param $name
53 * @param $webRequestUpload
55 function initialize( $name, $webRequestUpload ) {
56 $this->mUpload = $webRequestUpload;
57 $this->initializePathInfo( $name,
58 $this->mUpload->getTempName(), $this->mUpload->getSize() );
61 /**
62 * @param $request
63 * @return bool
65 static function isValidRequest( $request ) {
66 # Allow all requests, even if no file is present, so that an error
67 # because a post_max_size or upload_max_filesize overflow
68 return true;
71 /**
72 * @return string
74 public function getSourceType() {
75 return 'file';
78 /**
79 * @return array
81 public function verifyUpload() {
82 # Check for a post_max_size or upload_max_size overflow, so that a
83 # proper error can be shown to the user
84 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
85 if ( $this->mUpload->isIniSizeOverflow() ) {
86 return array(
87 'status' => UploadBase::FILE_TOO_LARGE,
88 'max' => min(
89 self::getMaxUploadSize( $this->getSourceType() ),
90 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
91 wfShorthandToInteger( ini_get( 'post_max_size' ) )
97 return parent::verifyUpload();