MediaWiki  master
UploadFromFile.php
Go to the documentation of this file.
1 <?php
30 class UploadFromFile extends UploadBase {
34  protected $mUpload = null;
35 
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 
54  function initialize( $name, $webRequestUpload ) {
55  $this->mUpload = $webRequestUpload;
56  $this->initializePathInfo( $name,
57  $this->mUpload->getTempName(), $this->mUpload->getSize() );
58  }
59 
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 
73  public function getSourceType() {
74  return 'file';
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 ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
84  if ( $this->mUpload->isIniSizeOverflow() ) {
85  return [
86  'status' => UploadBase::FILE_TOO_LARGE,
87  'max' => min(
88  self::getMaxUploadSize( $this->getSourceType() ),
89  self::getMaxPhpUploadSize()
90  ),
91  ];
92  }
93  }
94 
95  return parent::verifyUpload();
96  }
97 }
WebRequestUpload $mUpload
initializePathInfo( $name, $tempPath, $fileSize, $removeTempFile=false)
Initialize the path information.
Definition: UploadBase.php:250
initializeFromRequest(&$request)
isEmptyFile()
Return true if the file is empty.
Definition: UploadBase.php:296
Implements regular file uploads.
UploadBase and subclasses are the backend of MediaWiki&#39;s file uploads.
Definition: UploadBase.php:39
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
const FILE_TOO_LARGE
Definition: UploadBase.php:102
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
initialize( $name, $webRequestUpload)
Initialize from a filename and a WebRequestUpload.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
static isValidRequest( $request)
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2620