MediaWiki  1.33.0
WebRequestUpload.php
Go to the documentation of this file.
1 <?php
24 
31  protected $request;
32  protected $doesExist;
33  protected $fileInfo;
34 
41  public function __construct( $request, $key ) {
42  $this->request = $request;
43  $this->doesExist = isset( $_FILES[$key] );
44  if ( $this->doesExist ) {
45  $this->fileInfo = $_FILES[$key];
46  }
47  }
48 
54  public function exists() {
55  return $this->doesExist;
56  }
57 
63  public function getName() {
64  if ( !$this->exists() ) {
65  return null;
66  }
67 
68  $name = $this->fileInfo['name'];
69 
70  # Safari sends filenames in HTML-encoded Unicode form D...
71  # Horrid and evil! Let's try to make some kind of sense of it.
72  $name = Sanitizer::decodeCharReferences( $name );
73  $name = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $name );
74  wfDebug( __METHOD__ . ": {$this->fileInfo['name']} normalized to '$name'\n" );
75  return $name;
76  }
77 
83  public function getSize() {
84  if ( !$this->exists() ) {
85  return 0;
86  }
87 
88  return $this->fileInfo['size'];
89  }
90 
96  public function getTempName() {
97  if ( !$this->exists() ) {
98  return null;
99  }
100 
101  return $this->fileInfo['tmp_name'];
102  }
103 
110  public function getError() {
111  if ( !$this->exists() ) {
112  return 0; # UPLOAD_ERR_OK
113  }
114 
115  return $this->fileInfo['error'];
116  }
117 
124  public function isIniSizeOverflow() {
125  if ( $this->getError() == UPLOAD_ERR_INI_SIZE ) {
126  # PHP indicated that upload_max_filesize is exceeded
127  return true;
128  }
129 
130  $contentLength = $this->request->getHeader( 'Content-Length' );
131  $maxPostSize = wfShorthandToInteger(
132  ini_get( 'post_max_size' ) ?: ini_get( 'hhvm.server.max_post_size' ),
133  0
134  );
135 
136  if ( $maxPostSize && $contentLength > $maxPostSize ) {
137  # post_max_size is exceeded
138  return true;
139  }
140 
141  return false;
142  }
143 }
WebRequestUpload\getError
getError()
Return the upload error.
Definition: WebRequestUpload.php:110
WebRequestUpload\$doesExist
$doesExist
Definition: WebRequestUpload.php:32
WebRequestUpload\__construct
__construct( $request, $key)
Constructor.
Definition: WebRequestUpload.php:41
request
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging a wrapping ErrorException create2 Corresponds to logging log_action database field and which is displayed in the UI similar to $comment or false if none Defaults to false if not set multiOccurrence Can this option be passed multiple times Defaults to false if not set this hook should only be used to add variables that depend on the current page request
Definition: hooks.txt:2162
WebRequestUpload\isIniSizeOverflow
isIniSizeOverflow()
Returns whether this upload failed because of overflow of a maximum set in php.ini.
Definition: WebRequestUpload.php:124
php
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
WebRequestUpload\exists
exists()
Return whether a file with this name was uploaded.
Definition: WebRequestUpload.php:54
WebRequestUpload\$fileInfo
$fileInfo
Definition: WebRequestUpload.php:33
WebRequestUpload\getName
getName()
Return the original filename of the uploaded file.
Definition: WebRequestUpload.php:63
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
WebRequestUpload\$request
$request
Definition: WebRequestUpload.php:31
WebRequestUpload
Object to access the $_FILES array.
Definition: WebRequestUpload.php:30
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:949
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
WebRequestUpload\getTempName
getTempName()
Return the path to the temporary file.
Definition: WebRequestUpload.php:96
wfShorthandToInteger
wfShorthandToInteger( $string='', $default=-1)
Converts shorthand byte notation to integer form.
Definition: GlobalFunctions.php:2916
WebRequestUpload\getSize
getSize()
Return the file size of the uploaded file.
Definition: WebRequestUpload.php:83
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23