MediaWiki  1.28.0
WebRequestUpload.php
Go to the documentation of this file.
1 <?php
29  protected $request;
30  protected $doesExist;
31  protected $fileInfo;
32 
39  public function __construct( $request, $key ) {
40  $this->request = $request;
41  $this->doesExist = isset( $_FILES[$key] );
42  if ( $this->doesExist ) {
43  $this->fileInfo = $_FILES[$key];
44  }
45  }
46 
52  public function exists() {
53  return $this->doesExist;
54  }
55 
61  public function getName() {
62  if ( !$this->exists() ) {
63  return null;
64  }
65 
67  $name = $this->fileInfo['name'];
68 
69  # Safari sends filenames in HTML-encoded Unicode form D...
70  # Horrid and evil! Let's try to make some kind of sense of it.
72  $name = $wgContLang->normalize( $name );
73  wfDebug( __METHOD__ . ": {$this->fileInfo['name']} normalized to '$name'\n" );
74  return $name;
75  }
76 
82  public function getSize() {
83  if ( !$this->exists() ) {
84  return 0;
85  }
86 
87  return $this->fileInfo['size'];
88  }
89 
95  public function getTempName() {
96  if ( !$this->exists() ) {
97  return null;
98  }
99 
100  return $this->fileInfo['tmp_name'];
101  }
102 
109  public function getError() {
110  if ( !$this->exists() ) {
111  return 0; # UPLOAD_ERR_OK
112  }
113 
114  return $this->fileInfo['error'];
115  }
116 
123  public function isIniSizeOverflow() {
124  if ( $this->getError() == UPLOAD_ERR_INI_SIZE ) {
125  # PHP indicated that upload_max_filesize is exceeded
126  return true;
127  }
128 
129  $contentLength = $this->request->getHeader( 'Content-Length' );
130  $maxPostSize = wfShorthandToInteger(
131  ini_get( 'post_max_size' ) ?: ini_get( 'hhvm.server.max_post_size' ),
132  0
133  );
134 
135  if ( $maxPostSize && $contentLength > $maxPostSize ) {
136  # post_max_size is exceeded
137  return true;
138  }
139 
140  return false;
141  }
142 }
__construct($request, $key)
Constructor.
getSize()
Return the file size of the uploaded file.
wfShorthandToInteger($string= '', $default=-1)
Converts shorthand byte notation to integer form.
getName()
Return the original filename of the uploaded file.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
getError()
Return the upload error.
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
getTempName()
Return the path to the temporary file.
static decodeCharReferences($text)
Decode any character references, numeric or named entities, in the text and return a UTF-8 string...
Definition: Sanitizer.php:1500
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging a wrapping ErrorException instead of letting the login form give the generic error message that the account does not exist For when the account has been renamed or deleted or an array to pass a message key and parameters create2 Corresponds to logging log_action database field and which is displayed in the UI similar to $comment this hook should only be used to add variables that depend on the current page request
Definition: hooks.txt:2102
isIniSizeOverflow()
Returns whether this upload failed because of overflow of a maximum set in php.ini.
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
exists()
Return whether a file with this name was uploaded.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition: design.txt:56
Object to access the $_FILES array.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300