[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/upload/ -> UploadFromFile.php (source)

   1  <?php
   2  /**
   3   * Backend for regular file upload.
   4   *
   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.
   9   *
  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.
  14   *
  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
  19   *
  20   * @file
  21   * @ingroup Upload
  22   */
  23  
  24  /**
  25   * Implements regular file uploads
  26   *
  27   * @ingroup Upload
  28   * @author Bryan Tong Minh
  29   */
  30  class UploadFromFile extends UploadBase {
  31      /**
  32       * @var WebRequestUpload
  33       */
  34      protected $mUpload = null;
  35  
  36      /**
  37       * @param WebRequest $request
  38       */
  39  	function initializeFromRequest( &$request ) {
  40          $upload = $request->getUpload( 'wpUploadFile' );
  41          $desiredDestName = $request->getText( 'wpDestFile' );
  42          if ( !$desiredDestName ) {
  43              $desiredDestName = $upload->getName();
  44          }
  45  
  46          $this->initialize( $desiredDestName, $upload );
  47      }
  48  
  49      /**
  50       * Initialize from a filename and a WebRequestUpload
  51       * @param string $name
  52       * @param WebRequestUpload $webRequestUpload
  53       */
  54  	function initialize( $name, $webRequestUpload ) {
  55          $this->mUpload = $webRequestUpload;
  56          $this->initializePathInfo( $name,
  57              $this->mUpload->getTempName(), $this->mUpload->getSize() );
  58      }
  59  
  60      /**
  61       * @param WebRequest $request
  62       * @return bool
  63       */
  64  	static function isValidRequest( $request ) {
  65          # Allow all requests, even if no file is present, so that an error
  66          # because a post_max_size or upload_max_filesize overflow
  67          return true;
  68      }
  69  
  70      /**
  71       * @return string
  72       */
  73  	public function getSourceType() {
  74          return 'file';
  75      }
  76  
  77      /**
  78       * @return array
  79       */
  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 ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
  84              if ( $this->mUpload->isIniSizeOverflow() ) {
  85                  return array(
  86                      'status' => UploadBase::FILE_TOO_LARGE,
  87                      'max' => min(
  88                          self::getMaxUploadSize( $this->getSourceType() ),
  89                          wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
  90                          wfShorthandToInteger( ini_get( 'post_max_size' ) )
  91                      ),
  92                  );
  93              }
  94          }
  95  
  96          return parent::verifyUpload();
  97      }
  98  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1