Index: trunk/phase3/includes/SpecialUpload.php |
— | — | @@ -8,10 +8,10 @@ |
9 | 9 | /** |
10 | 10 | * |
11 | 11 | */ |
12 | | -require_once( "Image.php" ); |
| 12 | +require_once( 'Image.php' ); |
13 | 13 | |
14 | 14 | /** |
15 | | - * Constructor |
| 15 | + * Entry point |
16 | 16 | */ |
17 | 17 | function wfSpecialUpload() { |
18 | 18 | global $wgRequest; |
— | — | @@ -30,6 +30,11 @@ |
31 | 31 | var $mUploadCopyStatus, $mUploadSource, $mReUpload, $mAction, $mUpload; |
32 | 32 | var $mOname, $mSessionKey; |
33 | 33 | |
| 34 | + /** |
| 35 | + * Constructor : initialise object |
| 36 | + * Get data POSTed through the form and assign them to the object |
| 37 | + * @param $request Data posted. |
| 38 | + */ |
34 | 39 | function UploadForm( &$request ) { |
35 | 40 | $this->mUploadAffirm = $request->getVal( 'wpUploadAffirm' ); |
36 | 41 | $this->mUploadFile = $request->getVal( 'wpUploadFile' ); |
— | — | @@ -47,44 +52,58 @@ |
48 | 53 | $this->mUpload = $request->getCheck( 'wpUpload' ); |
49 | 54 | $this->mSessionKey = $request->getVal( 'wpSessionKey' ); |
50 | 55 | |
| 56 | + /** Generate a temporary name if we don't have one yet */ |
51 | 57 | if ( ! $this->mUploadTempName ) { |
52 | 58 | $this->mUploadTempName = $request->getFileTempName( 'wpUploadFile' ); |
53 | 59 | } |
| 60 | + |
| 61 | + /** Get size of file */ |
54 | 62 | if ( ! $this->mUploadSize ) { |
55 | 63 | $this->mUploadSize = $request->getFileSize( 'wpUploadFile' ); |
56 | 64 | } |
57 | 65 | $this->mOname = $request->getFileName( 'wpUploadFile' ); |
58 | | - |
59 | 66 | } |
60 | 67 | |
| 68 | + /** |
| 69 | + * Start doing stuff |
| 70 | + * @access public |
| 71 | + */ |
61 | 72 | function execute() { |
62 | 73 | global $wgUser, $wgOut; |
63 | 74 | global $wgDisableUploads; |
64 | 75 | |
| 76 | + /** Show an error message if file upload is disabled */ |
65 | 77 | if ( $wgDisableUploads ) { |
66 | | - $wgOut->addWikiText( wfMsg( "uploaddisabled" ) ); |
| 78 | + $wgOut->addWikiText( wfMsg( 'uploaddisabled' ) ); |
67 | 79 | return; |
68 | 80 | } |
69 | | - if ( ( 0 == $wgUser->getID() ) |
70 | | - or $wgUser->isBlocked() ) { |
71 | | - $wgOut->errorpage( "uploadnologin", "uploadnologintext" ); |
| 81 | + |
| 82 | + /** Various rights checks */ |
| 83 | + if ( ( $wgUser->getID() == 0 ) |
| 84 | + OR $wgUser->isBlocked() ) { |
| 85 | + $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' ); |
72 | 86 | return; |
73 | 87 | } |
74 | 88 | if ( wfReadOnly() ) { |
75 | 89 | $wgOut->readOnlyPage(); |
76 | 90 | return; |
77 | 91 | } |
| 92 | + |
78 | 93 | if ( $this->mReUpload ) { |
79 | 94 | $this->unsaveUploadedFile(); |
80 | | - $this->mainUploadForm( "" ); |
81 | | - } else if ( "submit" == $this->mAction || $this->mUpload ) { |
| 95 | + $this->mainUploadForm( '' ); |
| 96 | + } else if ( 'submit' == $this->mAction || $this->mUpload ) { |
82 | 97 | $this->processUpload(); |
83 | 98 | } else { |
84 | | - $this->mainUploadForm( "" ); |
| 99 | + $this->mainUploadForm( '' ); |
85 | 100 | } |
86 | 101 | } |
87 | 102 | |
88 | | - |
| 103 | + /** |
| 104 | + * Really do the upload |
| 105 | + * Checks are made in SpecialUpload::execute() |
| 106 | + * @access private |
| 107 | + */ |
89 | 108 | function processUpload() { |
90 | 109 | global $wgUser, $wgOut, $wgLang; |
91 | 110 | global $wgUploadDirectory; |
— | — | @@ -96,32 +115,32 @@ |
97 | 116 | if ( $wgUseCopyrightUpload ) { |
98 | 117 | $this->mUploadAffirm = 1; |
99 | 118 | if ($wgCheckCopyrightUpload && |
100 | | - (trim ( $this->mUploadCopyStatus ) == "" || trim ( $this->mUploadSource ) == "" )) { |
| 119 | + (trim ( $this->mUploadCopyStatus ) == '' || trim ( $this->mUploadSource ) == '' )) { |
101 | 120 | $this->mUploadAffirm = 0; |
102 | 121 | } |
103 | 122 | } |
104 | 123 | |
105 | | - if ( 1 != $this->mUploadAffirm ) { |
106 | | - $this->mainUploadForm( WfMsg( "noaffirmation" ) ); |
| 124 | + if ( $this->mUploadAffirm != 1) { |
| 125 | + $this->mainUploadForm( WfMsg( 'noaffirmation' ) ); |
107 | 126 | return; |
108 | 127 | } |
109 | 128 | |
110 | | - if ( "" != $this->mOname ) { |
111 | | - $basename = strrchr( $this->mOname, "/" ); |
| 129 | + if ( '' != $this->mOname ) { |
| 130 | + $basename = strrchr( $this->mOname, '/' ); |
112 | 131 | |
113 | 132 | if ( false === $basename ) { $basename = $this->mOname; } |
114 | 133 | else ( $basename = substr( $basename, 1 ) ); |
115 | 134 | |
116 | 135 | |
117 | | - $ext = strrchr( $basename, "." ); |
118 | | - if ( false === $ext ) { $ext = ""; } |
| 136 | + $ext = strrchr( $basename, '.' ); |
| 137 | + if ( false === $ext ) { $ext = ''; } |
119 | 138 | else { $ext = substr( $ext, 1 ); } |
120 | 139 | |
121 | | - if ( "" == $ext ) { $xl = 0; } else { $xl = strlen( $ext ) + 1; } |
| 140 | + if ( '' == $ext ) { $xl = 0; } else { $xl = strlen( $ext ) + 1; } |
122 | 141 | $partname = substr( $basename, 0, strlen( $basename ) - $xl ); |
123 | 142 | |
124 | 143 | if ( strlen( $partname ) < 3 ) { |
125 | | - $this->mainUploadForm( WfMsg( "minlength" ) ); |
| 144 | + $this->mainUploadForm( WfMsg( 'minlength' ) ); |
126 | 145 | return; |
127 | 146 | } |
128 | 147 | |
— | — | @@ -136,7 +155,7 @@ |
137 | 156 | |
138 | 157 | $nt = Title::newFromText( $basename ); |
139 | 158 | if( !$nt ) { |
140 | | - return $this->uploadError( wfMsg( "illegalfilename", htmlspecialchars( $basename ) ) ); |
| 159 | + return $this->uploadError( wfMsg( 'illegalfilename', htmlspecialchars( $basename ) ) ); |
141 | 160 | } |
142 | 161 | $nt->setNamespace( Namespace::getImage() ); |
143 | 162 | $this->mUploadSaveName = $nt->getDBkey(); |
— | — | @@ -144,36 +163,36 @@ |
145 | 164 | /* Don't allow users to override the blacklist */ |
146 | 165 | if( $this->checkFileExtension( $ext, $wgFileBlacklist ) || |
147 | 166 | ($wgStrictFileExtensions && !$this->checkFileExtension( $ext, $wgFileExtensions ) ) ) { |
148 | | - return $this->uploadError( wfMsg( "badfiletype", htmlspecialchars( $ext ) ) ); |
| 167 | + return $this->uploadError( wfMsg( 'badfiletype', htmlspecialchars( $ext ) ) ); |
149 | 168 | } |
150 | 169 | |
151 | 170 | $this->saveUploadedFile( $this->mUploadSaveName, $this->mUploadTempName ); |
152 | 171 | if ( !$nt->userCanEdit() ) { |
153 | | - return $this->uploadError( wfMsg( "protectedpage" ) ); |
| 172 | + return $this->uploadError( wfMsg( 'protectedpage' ) ); |
154 | 173 | } |
155 | 174 | |
156 | 175 | if ( ! $this->mIgnoreWarning ) { |
157 | 176 | $warning = ''; |
158 | 177 | if( $changed_name || 0 != strcmp( ucfirst( $basename ), $this->mUploadSaveName ) ) { |
159 | | - $warning .= '<li>'.wfMsg( "badfilename", htmlspecialchars( $this->mUploadSaveName ) ).'</li>'; |
| 178 | + $warning .= '<li>'.wfMsg( 'badfilename', htmlspecialchars( $this->mUploadSaveName ) ).'</li>'; |
160 | 179 | } |
161 | 180 | |
162 | 181 | if ( $wgCheckFileExtensions ) { |
163 | 182 | if ( ! $this->checkFileExtension( $ext, $wgFileExtensions ) ) { |
164 | | - $warning .= '<li>'.wfMsg( "badfiletype", htmlspecialchars( $ext ) ).'</li>'; |
| 183 | + $warning .= '<li>'.wfMsg( 'badfiletype', htmlspecialchars( $ext ) ).'</li>'; |
165 | 184 | } |
166 | 185 | } |
167 | 186 | if ( $wgUploadSizeWarning && ( $this->mUploadSize > $wgUploadSizeWarning ) ) { |
168 | | - $warning .= '<li>'.wfMsg( "largefile" ).'</li>'; |
| 187 | + $warning .= '<li>'.wfMsg( 'largefile' ).'</li>'; |
169 | 188 | } |
170 | 189 | if ( $this->mUploadSize == 0 ) { |
171 | | - $warning .= '<li>'.wfMsg( "emptyfile" ).'</li>'; |
| 190 | + $warning .= '<li>'.wfMsg( 'emptyfile' ).'</li>'; |
172 | 191 | } |
173 | 192 | if( $nt->getArticleID() ) { |
174 | 193 | $sk = $wgUser->getSkin(); |
175 | 194 | $dname = $wgLang->getNsText( Namespace::getImage() ) . ":{$this->mUploadSaveName}"; |
176 | 195 | $dlink = $sk->makeKnownLink( $dname, $dname ); |
177 | | - $warning .= '<li>'.wfMsg( "fileexists", $dlink ).'</li>'; |
| 196 | + $warning .= '<li>'.wfMsg( 'fileexists', $dlink ).'</li>'; |
178 | 197 | } |
179 | 198 | if($warning != '') return $this->uploadWarning($warning); |
180 | 199 | } |
— | — | @@ -189,8 +208,8 @@ |
190 | 209 | $dname = $wgLang->getNsText( Namespace::getImage() ) . ":{$this->mUploadSaveName}"; |
191 | 210 | $dlink = $sk->makeKnownLink( $dname, $dname ); |
192 | 211 | |
193 | | - $wgOut->addHTML( "<h2>" . wfMsg( "successfulupload" ) . "</h2>\n" ); |
194 | | - $text = wfMsg( "fileuploaded", $ilink, $dlink ); |
| 212 | + $wgOut->addHTML( '<h2>' . wfMsg( 'successfulupload' ) . "</h2>\n" ); |
| 213 | + $text = wfMsg( 'fileuploaded', $ilink, $dlink ); |
195 | 214 | $wgOut->addHTML( "<p>{$text}\n" ); |
196 | 215 | $wgOut->returnToMain( false ); |
197 | 216 | } |
— | — | @@ -208,7 +227,7 @@ |
209 | 228 | $wgSavedFile = "{$dest}/{$saveName}"; |
210 | 229 | |
211 | 230 | if ( is_file( $wgSavedFile ) ) { |
212 | | - $wgUploadOldVersion = gmdate( "YmdHis" ) . "!{$saveName}"; |
| 231 | + $wgUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}"; |
213 | 232 | |
214 | 233 | if ( ! rename( $wgSavedFile, "${archive}/{$wgUploadOldVersion}" ) ) { |
215 | 234 | $wgOut->fileRenameError( $wgSavedFile, |
— | — | @@ -216,7 +235,7 @@ |
217 | 236 | return; |
218 | 237 | } |
219 | 238 | } else { |
220 | | - $wgUploadOldVersion = ""; |
| 239 | + $wgUploadOldVersion = ''; |
221 | 240 | } |
222 | 241 | if ( ! move_uploaded_file( $tempName, $wgSavedFile ) ) { |
223 | 242 | $wgOut->fileCopyError( $tempName, $wgSavedFile ); |
— | — | @@ -234,10 +253,10 @@ |
235 | 254 | $wgOut->fileDeleteError( $wgSavedFile ); |
236 | 255 | return; |
237 | 256 | } |
238 | | - if ( "" != $wgUploadOldVersion ) { |
| 257 | + if ( '' != $wgUploadOldVersion ) { |
239 | 258 | $hash = md5( substr( $wgUploadOldVersion, 15 ) ); |
240 | | - $archive = "{$wgUploadDirectory}/archive/" . $hash{0} . |
241 | | - "/" . substr( $hash, 0, 2 ); |
| 259 | + $archive = $wgUploadDirectory.'/archive/' . $hash{0} . |
| 260 | + '/' . substr( $hash, 0, 2 ); |
242 | 261 | |
243 | 262 | if ( ! rename( "{$archive}/{$wgUploadOldVersion}", $wgSavedFile ) ) { |
244 | 263 | $wgOut->fileRenameError( "{$archive}/{$wgUploadOldVersion}", |
— | — | @@ -248,7 +267,7 @@ |
249 | 268 | |
250 | 269 | function uploadError( $error ) { |
251 | 270 | global $wgOut; |
252 | | - $sub = wfMsg( "uploadwarning" ); |
| 271 | + $sub = wfMsg( 'uploadwarning' ); |
253 | 272 | $wgOut->addHTML( "<h2>{$sub}</h2>\n" ); |
254 | 273 | $wgOut->addHTML( "<h4 style='error'>{$error}</h4>\n" ); |
255 | 274 | } |
— | — | @@ -262,16 +281,16 @@ |
263 | 282 | $this->mSessionKey = mt_rand( 0, 0x7fffffff ); |
264 | 283 | $_SESSION['wsUploadFiles'][$this->mSessionKey] = $wgSavedFile; |
265 | 284 | |
266 | | - $sub = wfMsg( "uploadwarning" ); |
| 285 | + $sub = wfMsg( 'uploadwarning' ); |
267 | 286 | $wgOut->addHTML( "<h2>{$sub}</h2>\n" ); |
268 | 287 | $wgOut->addHTML( "<ul class='warning'>{$warning}</ul><br/>\n" ); |
269 | 288 | |
270 | | - $save = wfMsg( "savefile" ); |
271 | | - $reupload = wfMsg( "reupload" ); |
272 | | - $iw = wfMsg( "ignorewarning" ); |
273 | | - $reup = wfMsg( "reuploaddesc" ); |
274 | | - $titleObj = Title::makeTitle( NS_SPECIAL, "Upload" ); |
275 | | - $action = $titleObj->escapeLocalURL( "action=submit" ); |
| 289 | + $save = wfMsg( 'savefile' ); |
| 290 | + $reupload = wfMsg( 'reupload' ); |
| 291 | + $iw = wfMsg( 'ignorewarning' ); |
| 292 | + $reup = wfMsg( 'reuploaddesc' ); |
| 293 | + $titleObj = Title::makeTitle( NS_SPECIAL, 'Upload' ); |
| 294 | + $action = $titleObj->escapeLocalURL( 'action=submit' ); |
276 | 295 | |
277 | 296 | if ( $wgUseCopyrightUpload ) |
278 | 297 | { |
— | — | @@ -308,27 +327,27 @@ |
309 | 328 | global $wgOut, $wgUser, $wgLang, $wgUploadDirectory, $wgRequest; |
310 | 329 | global $wgUseCopyrightUpload; |
311 | 330 | |
312 | | - if ( "" != $msg ) { |
313 | | - $sub = wfMsg( "uploaderror" ); |
| 331 | + if ( '' != $msg ) { |
| 332 | + $sub = wfMsg( 'uploaderror' ); |
314 | 333 | $wgOut->addHTML( "<h2>{$sub}</h2>\n" . |
315 | 334 | "<h4 style='error'>{$msg}</h4>\n" ); |
316 | 335 | } else { |
317 | | - $sub = wfMsg( "uploadfile" ); |
| 336 | + $sub = wfMsg( 'uploadfile' ); |
318 | 337 | $wgOut->addHTML( "<h2>{$sub}</h2>\n" ); |
319 | 338 | } |
320 | | - $wgOut->addWikiText( wfMsg( "uploadtext" ) ); |
| 339 | + $wgOut->addWikiText( wfMsg( 'uploadtext' ) ); |
321 | 340 | $sk = $wgUser->getSkin(); |
322 | 341 | |
323 | | - $fn = wfMsg( "filename" ); |
324 | | - $fd = wfMsg( "filedesc" ); |
325 | | - $ulb = wfMsg( "uploadbtn" ); |
| 342 | + $fn = wfMsg( 'filename' ); |
| 343 | + $fd = wfMsg( 'filedesc' ); |
| 344 | + $ulb = wfMsg( 'uploadbtn' ); |
326 | 345 | |
327 | | - $clink = $sk->makeKnownLink( wfMsg( "copyrightpage" ), |
328 | | - wfMsg( "copyrightpagename" ) ); |
329 | | - $ca = wfMsg( "affirmation", $clink ); |
330 | | - $iw = wfMsg( "ignorewarning" ); |
| 346 | + $clink = $sk->makeKnownLink( wfMsg( 'copyrightpage' ), |
| 347 | + wfMsg( 'copyrightpagename' ) ); |
| 348 | + $ca = wfMsg( 'affirmation', $clink ); |
| 349 | + $iw = wfMsg( 'ignorewarning' ); |
331 | 350 | |
332 | | - $titleObj = Title::makeTitle( NS_SPECIAL, "Upload" ); |
| 351 | + $titleObj = Title::makeTitle( NS_SPECIAL, 'Upload' ); |
333 | 352 | $action = $titleObj->escapeLocalURL(); |
334 | 353 | |
335 | 354 | $source = " |
— | — | @@ -339,11 +358,11 @@ |
340 | 359 | if ( $wgUseCopyrightUpload ) |
341 | 360 | { |
342 | 361 | $source = " |
343 | | - <td align='right' nowrap='nowrap'>" . wfMsg ( "filestatus" ) . ":</td> |
| 362 | + <td align='right' nowrap='nowrap'>" . wfMsg ( 'filestatus' ) . ":</td> |
344 | 363 | <td><input tabindex='3' type='text' name=\"wpUploadCopyStatus\" value=\"" . |
345 | 364 | htmlspecialchars($this->mUploadCopyStatus). "\" size='40' /></td> |
346 | 365 | </tr><tr> |
347 | | - <td align='right'>". wfMsg ( "filesource" ) . ":</td> |
| 366 | + <td align='right'>". wfMsg ( 'filesource' ) . ":</td> |
348 | 367 | <td><input tabindex='4' type='text' name=\"wpUploadSource\" value=\"" . |
349 | 368 | htmlspecialchars($this->mUploadSource). "\" size='40' /></td> |
350 | 369 | " ; |