MediaWiki REL1_30
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
66 global $wgContLang;
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.
71 $name = Sanitizer::decodeCharReferences( $name );
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}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfShorthandToInteger( $string='', $default=-1)
Converts shorthand byte notation to integer form.
Object to access the $_FILES array.
getError()
Return the upload error.
isIniSizeOverflow()
Returns whether this upload failed because of overflow of a maximum set in php.ini.
exists()
Return whether a file with this name was uploaded.
__construct( $request, $key)
Constructor.
getSize()
Return the file size of the uploaded file.
getTempName()
Return the path to the temporary file.
getName()
Return the original filename of the uploaded file.
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:57
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302