Skip dupe warnings when it's a titles are the same and it's a reupload.
[lhc/web/wiklou.git] / includes / specials / SpecialUpload.php
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
6
7
8 /**
9 * Entry point
10 */
11 function wfSpecialUpload() {
12 global $wgRequest;
13 $form = new UploadForm( $wgRequest );
14 $form->execute();
15 }
16
17 /**
18 * implements Special:Upload
19 * @ingroup SpecialPage
20 */
21 class UploadForm {
22 const SUCCESS = 0;
23 const BEFORE_PROCESSING = 1;
24 const LARGE_FILE_SERVER = 2;
25 const EMPTY_FILE = 3;
26 const MIN_LENGTH_PARTNAME = 4;
27 const ILLEGAL_FILENAME = 5;
28 const PROTECTED_PAGE = 6;
29 const OVERWRITE_EXISTING_FILE = 7;
30 const FILETYPE_MISSING = 8;
31 const FILETYPE_BADTYPE = 9;
32 const VERIFICATION_ERROR = 10;
33 const UPLOAD_VERIFICATION_ERROR = 11;
34 const UPLOAD_WARNING = 12;
35 const INTERNAL_ERROR = 13;
36
37 /**#@+
38 * @access private
39 */
40 var $mComment, $mLicense, $mIgnoreWarning, $mCurlError;
41 var $mDestName, $mTempPath, $mFileSize, $mFileProps;
42 var $mCopyrightStatus, $mCopyrightSource, $mReUpload, $mAction, $mUploadClicked;
43 var $mSrcName, $mSessionKey, $mStashed, $mDesiredDestName, $mRemoveTempFile, $mSourceType;
44 var $mDestWarningAck, $mCurlDestHandle;
45 var $mLocalFile;
46
47 # Placeholders for text injection by hooks (must be HTML)
48 # extensions should take care to _append_ to the present value
49 var $uploadFormTextTop;
50 var $uploadFormTextAfterSummary;
51
52 const SESSION_VERSION = 1;
53 /**#@-*/
54
55 /**
56 * Constructor : initialise object
57 * Get data POSTed through the form and assign them to the object
58 * @param $request Data posted.
59 */
60 function UploadForm( &$request ) {
61 global $wgAllowCopyUploads;
62 $this->mDesiredDestName = $request->getText( 'wpDestFile' );
63 $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' );
64 $this->mComment = $request->getText( 'wpUploadDescription' );
65 $this->mReUpload = $request->getCheck( 'wpReUpload' );
66
67 if( !$request->wasPosted() ) {
68 # GET requests just give the main form; no data except destination
69 # filename and description
70 return;
71 }
72
73 # Placeholders for text injection by hooks (empty per default)
74 $this->uploadFormTextTop = "";
75 $this->uploadFormTextAfterSummary = "";
76
77 $this->mReUpload = $request->getCheck( 'wpReUpload' );
78 $this->mUploadClicked = $request->getCheck( 'wpUpload' );
79
80 $this->mLicense = $request->getText( 'wpLicense' );
81 $this->mCopyrightStatus = $request->getText( 'wpUploadCopyStatus' );
82 $this->mCopyrightSource = $request->getText( 'wpUploadSource' );
83 $this->mWatchthis = $request->getBool( 'wpWatchthis' );
84 $this->mSourceType = $request->getText( 'wpSourceType' );
85 $this->mDestWarningAck = $request->getText( 'wpDestFileWarningAck' );
86
87 $this->mAction = $request->getVal( 'action' );
88
89 $this->mSessionKey = $request->getInt( 'wpSessionKey' );
90 if( !empty( $this->mSessionKey ) &&
91 isset( $_SESSION['wsUploadData'][$this->mSessionKey]['version'] ) &&
92 $_SESSION['wsUploadData'][$this->mSessionKey]['version'] == self::SESSION_VERSION ) {
93 /**
94 * Confirming a temporarily stashed upload.
95 * We don't want path names to be forged, so we keep
96 * them in the session on the server and just give
97 * an opaque key to the user agent.
98 */
99 $data = $_SESSION['wsUploadData'][$this->mSessionKey];
100 $this->mTempPath = $data['mTempPath'];
101 $this->mFileSize = $data['mFileSize'];
102 $this->mSrcName = $data['mSrcName'];
103 $this->mFileProps = $data['mFileProps'];
104 $this->mCurlError = 0/*UPLOAD_ERR_OK*/;
105 $this->mStashed = true;
106 $this->mRemoveTempFile = false;
107 } else {
108 /**
109 *Check for a newly uploaded file.
110 */
111 if( $wgAllowCopyUploads && $this->mSourceType == 'web' ) {
112 $this->initializeFromUrl( $request );
113 } else {
114 $this->initializeFromUpload( $request );
115 }
116 }
117 }
118
119 /**
120 * Initialize the uploaded file from PHP data
121 * @access private
122 */
123 function initializeFromUpload( $request ) {
124 $this->mTempPath = $request->getFileTempName( 'wpUploadFile' );
125 $this->mFileSize = $request->getFileSize( 'wpUploadFile' );
126 $this->mSrcName = $request->getFileName( 'wpUploadFile' );
127 $this->mCurlError = $request->getUploadError( 'wpUploadFile' );
128 $this->mSessionKey = false;
129 $this->mStashed = false;
130 $this->mRemoveTempFile = false; // PHP will handle this
131 }
132
133 /**
134 * Copy a web file to a temporary file
135 * @access private
136 */
137 function initializeFromUrl( $request ) {
138 global $wgTmpDirectory;
139 $url = $request->getText( 'wpUploadFileURL' );
140 $local_file = tempnam( $wgTmpDirectory, 'WEBUPLOAD' );
141
142 $this->mTempPath = $local_file;
143 $this->mFileSize = 0; # Will be set by curlCopy
144 $this->mCurlError = $this->curlCopy( $url, $local_file );
145 $pathParts = explode( '/', $url );
146 $this->mSrcName = array_pop( $pathParts );
147 $this->mSessionKey = false;
148 $this->mStashed = false;
149
150 // PHP won't auto-cleanup the file
151 $this->mRemoveTempFile = file_exists( $local_file );
152 }
153
154 /**
155 * Safe copy from URL
156 * Returns true if there was an error, false otherwise
157 */
158 private function curlCopy( $url, $dest ) {
159 global $wgUser, $wgOut;
160
161 if( !$wgUser->isAllowed( 'upload_by_url' ) ) {
162 $wgOut->permissionRequired( 'upload_by_url' );
163 return true;
164 }
165
166 # Maybe remove some pasting blanks :-)
167 $url = trim( $url );
168 if( stripos($url, 'http://') !== 0 && stripos($url, 'ftp://') !== 0 ) {
169 # Only HTTP or FTP URLs
170 $wgOut->showErrorPage( 'upload-proto-error', 'upload-proto-error-text' );
171 return true;
172 }
173
174 # Open temporary file
175 $this->mCurlDestHandle = @fopen( $this->mTempPath, "wb" );
176 if( $this->mCurlDestHandle === false ) {
177 # Could not open temporary file to write in
178 $wgOut->showErrorPage( 'upload-file-error', 'upload-file-error-text');
179 return true;
180 }
181
182 $ch = curl_init();
183 curl_setopt( $ch, CURLOPT_HTTP_VERSION, 1.0); # Probably not needed, but apparently can work around some bug
184 curl_setopt( $ch, CURLOPT_TIMEOUT, 10); # 10 seconds timeout
185 curl_setopt( $ch, CURLOPT_LOW_SPEED_LIMIT, 512); # 0.5KB per second minimum transfer speed
186 curl_setopt( $ch, CURLOPT_URL, $url);
187 curl_setopt( $ch, CURLOPT_WRITEFUNCTION, array( $this, 'uploadCurlCallback' ) );
188 curl_exec( $ch );
189 $error = curl_errno( $ch ) ? true : false;
190 $errornum = curl_errno( $ch );
191 // if ( $error ) print curl_error ( $ch ) ; # Debugging output
192 curl_close( $ch );
193
194 fclose( $this->mCurlDestHandle );
195 unset( $this->mCurlDestHandle );
196 if( $error ) {
197 unlink( $dest );
198 if( wfEmptyMsg( "upload-curl-error$errornum", wfMsg("upload-curl-error$errornum") ) )
199 $wgOut->showErrorPage( 'upload-misc-error', 'upload-misc-error-text' );
200 else
201 $wgOut->showErrorPage( "upload-curl-error$errornum", "upload-curl-error$errornum-text" );
202 }
203
204 return $error;
205 }
206
207 /**
208 * Callback function for CURL-based web transfer
209 * Write data to file unless we've passed the length limit;
210 * if so, abort immediately.
211 * @access private
212 */
213 function uploadCurlCallback( $ch, $data ) {
214 global $wgMaxUploadSize;
215 $length = strlen( $data );
216 $this->mFileSize += $length;
217 if( $this->mFileSize > $wgMaxUploadSize ) {
218 return 0;
219 }
220 fwrite( $this->mCurlDestHandle, $data );
221 return $length;
222 }
223
224 /**
225 * Start doing stuff
226 * @access public
227 */
228 function execute() {
229 global $wgUser, $wgOut;
230 global $wgEnableUploads;
231
232 # Check php's file_uploads setting
233 if( !wfIniGetBool( 'file_uploads' ) ) {
234 $wgOut->showErrorPage( 'uploaddisabled', 'php-uploaddisabledtext', array( $this->mDesiredDestName ) );
235 return;
236 }
237
238 # Check uploading enabled
239 if( !$wgEnableUploads ) {
240 $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext', array( $this->mDesiredDestName ) );
241 return;
242 }
243
244 # Check permissions
245 if( !$wgUser->isAllowed( 'upload' ) ) {
246 if( !$wgUser->isLoggedIn() ) {
247 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
248 } else {
249 $wgOut->permissionRequired( 'upload' );
250 }
251 return;
252 }
253
254 # Check blocks
255 if( $wgUser->isBlocked() ) {
256 $wgOut->blockedPage();
257 return;
258 }
259
260 if( wfReadOnly() ) {
261 $wgOut->readOnlyPage();
262 return;
263 }
264
265 if( $this->mReUpload ) {
266 if( !$this->unsaveUploadedFile() ) {
267 return;
268 }
269 # Because it is probably checked and shouldn't be
270 $this->mIgnoreWarning = false;
271
272 $this->mainUploadForm();
273 } else if( 'submit' == $this->mAction || $this->mUploadClicked ) {
274 $this->processUpload();
275 } else {
276 $this->mainUploadForm();
277 }
278
279 $this->cleanupTempFile();
280 }
281
282 /**
283 * Do the upload
284 * Checks are made in SpecialUpload::execute()
285 *
286 * @access private
287 */
288 function processUpload(){
289 global $wgUser, $wgOut, $wgFileExtensions, $wgLang;
290 $details = null;
291 $value = null;
292 $value = $this->internalProcessUpload( $details );
293
294 switch($value) {
295 case self::SUCCESS:
296 $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
297 break;
298
299 case self::BEFORE_PROCESSING:
300 break;
301
302 case self::LARGE_FILE_SERVER:
303 $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
304 break;
305
306 case self::EMPTY_FILE:
307 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
308 break;
309
310 case self::MIN_LENGTH_PARTNAME:
311 $this->mainUploadForm( wfMsgHtml( 'minlength1' ) );
312 break;
313
314 case self::ILLEGAL_FILENAME:
315 $filtered = $details['filtered'];
316 $this->uploadError( wfMsgWikiHtml( 'illegalfilename', htmlspecialchars( $filtered ) ) );
317 break;
318
319 case self::PROTECTED_PAGE:
320 $wgOut->showPermissionsErrorPage( $details['permissionserrors'] );
321 break;
322
323 case self::OVERWRITE_EXISTING_FILE:
324 $errorText = $details['overwrite'];
325 $this->uploadError( $wgOut->parse( $errorText ) );
326 break;
327
328 case self::FILETYPE_MISSING:
329 $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
330 break;
331
332 case self::FILETYPE_BADTYPE:
333 $finalExt = $details['finalExt'];
334 $this->uploadError(
335 wfMsgExt( 'filetype-banned-type',
336 array( 'parseinline' ),
337 htmlspecialchars( $finalExt ),
338 $wgLang->commaList( $wgFileExtensions ),
339 $wgLang->formatNum( count($wgFileExtensions) )
340 )
341 );
342 break;
343
344 case self::VERIFICATION_ERROR:
345 $veri = $details['veri'];
346 $this->uploadError( $veri->toString() );
347 break;
348
349 case self::UPLOAD_VERIFICATION_ERROR:
350 $error = $details['error'];
351 $this->uploadError( $error );
352 break;
353
354 case self::UPLOAD_WARNING:
355 $warning = $details['warning'];
356 $this->uploadWarning( $warning );
357 break;
358
359 case self::INTERNAL_ERROR:
360 $internal = $details['internal'];
361 $this->showError( $internal );
362 break;
363
364 default:
365 throw new MWException( __METHOD__ . ": Unknown value `{$value}`" );
366 }
367 }
368
369 /**
370 * Really do the upload
371 * Checks are made in SpecialUpload::execute()
372 *
373 * @param array $resultDetails contains result-specific dict of additional values
374 *
375 * @access private
376 */
377 function internalProcessUpload( &$resultDetails ) {
378 global $wgUser;
379
380 if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
381 {
382 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
383 return self::BEFORE_PROCESSING;
384 }
385
386 /**
387 * If there was no filename or a zero size given, give up quick.
388 */
389 if( trim( $this->mSrcName ) == '' || empty( $this->mFileSize ) ) {
390 return self::EMPTY_FILE;
391 }
392
393 /* Check for curl error */
394 if( $this->mCurlError ) {
395 return self::BEFORE_PROCESSING;
396 }
397
398 /**
399 * Chop off any directories in the given filename. Then
400 * filter out illegal characters, and try to make a legible name
401 * out of it. We'll strip some silently that Title would die on.
402 */
403 if( $this->mDesiredDestName ) {
404 $basename = $this->mDesiredDestName;
405 } else {
406 $basename = $this->mSrcName;
407 }
408 $filtered = wfStripIllegalFilenameChars( $basename );
409
410 /* Normalize to title form before we do any further processing */
411 $nt = Title::makeTitleSafe( NS_FILE, $filtered );
412 if( is_null( $nt ) ) {
413 $resultDetails = array( 'filtered' => $filtered );
414 return self::ILLEGAL_FILENAME;
415 }
416 $filtered = $nt->getDBkey();
417
418 /**
419 * We'll want to blacklist against *any* 'extension', and use
420 * only the final one for the whitelist.
421 */
422 list( $partname, $ext ) = $this->splitExtensions( $filtered );
423
424 if( count( $ext ) ) {
425 $finalExt = $ext[count( $ext ) - 1];
426 } else {
427 $finalExt = '';
428 }
429
430 # If there was more than one "extension", reassemble the base
431 # filename to prevent bogus complaints about length
432 if( count( $ext ) > 1 ) {
433 for( $i = 0; $i < count( $ext ) - 1; $i++ )
434 $partname .= '.' . $ext[$i];
435 }
436
437 if( strlen( $partname ) < 1 ) {
438 return self::MIN_LENGTH_PARTNAME;
439 }
440
441 $this->mLocalFile = wfLocalFile( $nt );
442 $this->mDestName = $this->mLocalFile->getName();
443
444 /**
445 * If the image is protected, non-sysop users won't be able
446 * to modify it by uploading a new revision.
447 */
448 $permErrors = $nt->getUserPermissionsErrors( 'edit', $wgUser );
449 $permErrorsUpload = $nt->getUserPermissionsErrors( 'upload', $wgUser );
450 $permErrorsCreate = ( $nt->exists() ? array() : $nt->getUserPermissionsErrors( 'create', $wgUser ) );
451
452 if( $permErrors || $permErrorsUpload || $permErrorsCreate ) {
453 // merge all the problems into one list, avoiding duplicates
454 $permErrors = array_merge( $permErrors, wfArrayDiff2( $permErrorsUpload, $permErrors ) );
455 $permErrors = array_merge( $permErrors, wfArrayDiff2( $permErrorsCreate, $permErrors ) );
456 $resultDetails = array( 'permissionserrors' => $permErrors );
457 return self::PROTECTED_PAGE;
458 }
459
460 /**
461 * In some cases we may forbid overwriting of existing files.
462 */
463 $overwrite = $this->checkOverwrite( $this->mDestName );
464 if( $overwrite !== true ) {
465 $resultDetails = array( 'overwrite' => $overwrite );
466 return self::OVERWRITE_EXISTING_FILE;
467 }
468
469 /* Don't allow users to override the blacklist (check file extension) */
470 global $wgCheckFileExtensions, $wgStrictFileExtensions;
471 global $wgFileExtensions, $wgFileBlacklist;
472 if ($finalExt == '') {
473 return self::FILETYPE_MISSING;
474 } elseif ( $this->checkFileExtensionList( $ext, $wgFileBlacklist ) ||
475 ($wgCheckFileExtensions && $wgStrictFileExtensions &&
476 !$this->checkFileExtension( $finalExt, $wgFileExtensions ) ) ) {
477 $resultDetails = array( 'finalExt' => $finalExt );
478 return self::FILETYPE_BADTYPE;
479 }
480
481 /**
482 * Look at the contents of the file; if we can recognize the
483 * type but it's corrupt or data of the wrong type, we should
484 * probably not accept it.
485 */
486 if( !$this->mStashed ) {
487 $this->mFileProps = File::getPropsFromPath( $this->mTempPath, $finalExt );
488 $this->checkMacBinary();
489 $veri = $this->verify( $this->mTempPath, $finalExt );
490
491 if( $veri !== true ) { //it's a wiki error...
492 $resultDetails = array( 'veri' => $veri );
493 return self::VERIFICATION_ERROR;
494 }
495
496 /**
497 * Provide an opportunity for extensions to add further checks
498 */
499 $error = '';
500 if( !wfRunHooks( 'UploadVerification',
501 array( $this->mDestName, $this->mTempPath, &$error ) ) ) {
502 $resultDetails = array( 'error' => $error );
503 return self::UPLOAD_VERIFICATION_ERROR;
504 }
505 }
506
507
508 /**
509 * Check for non-fatal conditions
510 */
511 if ( ! $this->mIgnoreWarning ) {
512 $warning = '';
513
514 $comparableName = str_replace( ' ', '_', $basename );
515 global $wgCapitalLinks, $wgContLang;
516 if ( $wgCapitalLinks ) {
517 $comparableName = $wgContLang->ucfirst( $comparableName );
518 }
519
520 if( $comparableName !== $filtered ) {
521 $warning .= '<li>'.wfMsgHtml( 'badfilename', htmlspecialchars( $this->mDestName ) ).'</li>';
522 }
523
524 global $wgCheckFileExtensions;
525 if ( $wgCheckFileExtensions ) {
526 if ( !$this->checkFileExtension( $finalExt, $wgFileExtensions ) ) {
527 global $wgLang;
528 $warning .= '<li>' .
529 wfMsgExt( 'filetype-unwanted-type',
530 array( 'parseinline' ),
531 htmlspecialchars( $finalExt ),
532 $wgLang->commaList( $wgFileExtensions ),
533 $wgLang->formatNum( count($wgFileExtensions) )
534 ) . '</li>';
535 }
536 }
537
538 global $wgUploadSizeWarning;
539 if ( $wgUploadSizeWarning && ( $this->mFileSize > $wgUploadSizeWarning ) ) {
540 $skin = $wgUser->getSkin();
541 $wsize = $skin->formatSize( $wgUploadSizeWarning );
542 $asize = $skin->formatSize( $this->mFileSize );
543 $warning .= '<li>' . wfMsgHtml( 'large-file', $wsize, $asize ) . '</li>';
544 }
545 if ( $this->mFileSize == 0 ) {
546 $warning .= '<li>'.wfMsgHtml( 'emptyfile' ).'</li>';
547 }
548
549 if ( !$this->mDestWarningAck ) {
550 $warning .= self::getExistsWarning( $this->mLocalFile );
551 }
552
553 $warning .= $this->getDupeWarning( $this->mTempPath, $finalExt, $nt );
554
555 if( $warning != '' ) {
556 /**
557 * Stash the file in a temporary location; the user can choose
558 * to let it through and we'll complete the upload then.
559 */
560 $resultDetails = array( 'warning' => $warning );
561 return self::UPLOAD_WARNING;
562 }
563 }
564
565 /**
566 * Try actually saving the thing...
567 * It will show an error form on failure.
568 */
569 $pageText = self::getInitialPageText( $this->mComment, $this->mLicense,
570 $this->mCopyrightStatus, $this->mCopyrightSource );
571
572 $status = $this->mLocalFile->upload( $this->mTempPath, $this->mComment, $pageText,
573 File::DELETE_SOURCE, $this->mFileProps );
574 if ( !$status->isGood() ) {
575 $resultDetails = array( 'internal' => $status->getWikiText() );
576 return self::INTERNAL_ERROR;
577 } else {
578 if ( $this->mWatchthis ) {
579 global $wgUser;
580 $wgUser->addWatch( $this->mLocalFile->getTitle() );
581 }
582 // Success, redirect to description page
583 $img = null; // @todo: added to avoid passing a ref to null - should this be defined somewhere?
584 wfRunHooks( 'UploadComplete', array( &$this ) );
585 return self::SUCCESS;
586 }
587 }
588
589 /**
590 * Do existence checks on a file and produce a warning
591 * This check is static and can be done pre-upload via AJAX
592 * Returns an HTML fragment consisting of one or more LI elements if there is a warning
593 * Returns an empty string if there is no warning
594 */
595 static function getExistsWarning( $file ) {
596 global $wgUser, $wgContLang;
597 // Check for uppercase extension. We allow these filenames but check if an image
598 // with lowercase extension exists already
599 $warning = '';
600 $align = $wgContLang->isRtl() ? 'left' : 'right';
601
602 if( strpos( $file->getName(), '.' ) == false ) {
603 $partname = $file->getName();
604 $rawExtension = '';
605 } else {
606 $n = strrpos( $file->getName(), '.' );
607 $rawExtension = substr( $file->getName(), $n + 1 );
608 $partname = substr( $file->getName(), 0, $n );
609 }
610
611 $sk = $wgUser->getSkin();
612
613 if ( $rawExtension != $file->getExtension() ) {
614 // We're not using the normalized form of the extension.
615 // Normal form is lowercase, using most common of alternate
616 // extensions (eg 'jpg' rather than 'JPEG').
617 //
618 // Check for another file using the normalized form...
619 $nt_lc = Title::makeTitle( NS_FILE, $partname . '.' . $file->getExtension() );
620 $file_lc = wfLocalFile( $nt_lc );
621 } else {
622 $file_lc = false;
623 }
624
625 if( $file->exists() ) {
626 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
627 if ( $file->allowInlineDisplay() ) {
628 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
629 $file->getName(), $align, array(), false, true );
630 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
631 $icon = $file->iconThumb();
632 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
633 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
634 } else {
635 $dlink2 = '';
636 }
637
638 $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2;
639
640 } elseif( $file->getTitle()->getArticleID() ) {
641 $lnk = $sk->makeKnownLinkObj( $file->getTitle(), '', 'redirect=no' );
642 $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>';
643 } elseif ( $file_lc && $file_lc->exists() ) {
644 # Check if image with lowercase extension exists.
645 # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
646 $dlink = $sk->makeKnownLinkObj( $nt_lc );
647 if ( $file_lc->allowInlineDisplay() ) {
648 $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline' ),
649 $nt_lc->getText(), $align, array(), false, true );
650 } elseif ( !$file_lc->allowInlineDisplay() && $file_lc->isSafeFile() ) {
651 $icon = $file_lc->iconThumb();
652 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
653 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
654 } else {
655 $dlink2 = '';
656 }
657
658 $warning .= '<li>' .
659 wfMsgExt( 'fileexists-extension', 'parsemag',
660 $file->getTitle()->getPrefixedText(), $dlink ) .
661 '</li>' . $dlink2;
662
663 } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' )
664 && ereg( "[0-9]{2}" , substr( $partname , 0, 2) ) )
665 {
666 # Check for filenames like 50px- or 180px-, these are mostly thumbnails
667 $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $rawExtension );
668 $file_thb = wfLocalFile( $nt_thb );
669 if ($file_thb->exists() ) {
670 # Check if an image without leading '180px-' (or similiar) exists
671 $dlink = $sk->makeKnownLinkObj( $nt_thb);
672 if ( $file_thb->allowInlineDisplay() ) {
673 $dlink2 = $sk->makeImageLinkObj( $nt_thb,
674 wfMsgExt( 'fileexists-thumb', 'parseinline' ),
675 $nt_thb->getText(), $align, array(), false, true );
676 } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) {
677 $icon = $file_thb->iconThumb();
678 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
679 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
680 $dlink . '</div>';
681 } else {
682 $dlink2 = '';
683 }
684
685 $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
686 '</li>' . $dlink2;
687 } else {
688 # Image w/o '180px-' does not exists, but we do not like these filenames
689 $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' ,
690 substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>';
691 }
692 }
693
694 $filenamePrefixBlacklist = self::getFilenamePrefixBlacklist();
695 # Do the match
696 foreach( $filenamePrefixBlacklist as $prefix ) {
697 if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
698 $warning .= '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $prefix ) . '</li>';
699 break;
700 }
701 }
702
703 if ( $file->wasDeleted() && !$file->exists() ) {
704 # If the file existed before and was deleted, warn the user of this
705 # Don't bother doing so if the file exists now, however
706 $ltitle = SpecialPage::getTitleFor( 'Log' );
707 $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ),
708 'type=delete&page=' . $file->getTitle()->getPrefixedUrl() );
709 $warning .= '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
710 }
711 return $warning;
712 }
713
714 /**
715 * Get a list of warnings
716 *
717 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
718 * @return array list of warning messages
719 */
720 static function ajaxGetExistsWarning( $filename ) {
721 $file = wfFindFile( $filename );
722 if( !$file ) {
723 // Force local file so we have an object to do further checks against
724 // if there isn't an exact match...
725 $file = wfLocalFile( $filename );
726 }
727 $s = '&nbsp;';
728 if ( $file ) {
729 $warning = self::getExistsWarning( $file );
730 if ( $warning !== '' ) {
731 $s = "<ul>$warning</ul>";
732 }
733 }
734 return $s;
735 }
736
737 /**
738 * Render a preview of a given license for the AJAX preview on upload
739 *
740 * @param string $license
741 * @return string
742 */
743 public static function ajaxGetLicensePreview( $license ) {
744 global $wgParser, $wgUser;
745 $text = '{{' . $license . '}}';
746 $title = Title::makeTitle( NS_FILE, 'Sample.jpg' );
747 $options = ParserOptions::newFromUser( $wgUser );
748
749 // Expand subst: first, then live templates...
750 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
751 $output = $wgParser->parse( $text, $title, $options );
752
753 return $output->getText();
754 }
755
756 /**
757 * Check for duplicate files and throw up a warning before the upload
758 * completes.
759 */
760 function getDupeWarning( $tempfile, $extension, $destinationTitle ) {
761 $hash = File::sha1Base36( $tempfile );
762 $dupes = RepoGroup::singleton()->findBySha1( $hash );
763 $archivedImage = new ArchivedFile( null, 0, $hash.".$extension" );
764 if( $dupes ) {
765 global $wgOut;
766 $msg = "<gallery>";
767 foreach( $dupes as $file ) {
768 $title = $file->getTitle();
769 # Don't throw the warning when the titles are the same, it's a reupload
770 # and highly redundant.
771 if ( !$title->equals( $destinationTitle ) || !$this->mIsReUpload ) {
772 $msg .= $title->getPrefixedText() .
773 "|" . $title->getText() . "\n";
774 }
775 }
776 $msg .= "</gallery>";
777 return "<li>" .
778 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
779 $wgOut->parse( $msg ) .
780 "</li>\n";
781 } elseif ( $archivedImage->getID() > 0 ) {
782 global $wgOut;
783 $name = Title::makeTitle( NS_FILE, $archivedImage->getName() )->getPrefixedText();
784 return Xml::tags( 'li', null, wfMsgExt( 'file-deleted-duplicate', array( 'parseinline' ), array( $name ) ) );
785 } else {
786 return '';
787 }
788 }
789
790 /**
791 * Get a list of blacklisted filename prefixes from [[MediaWiki:filename-prefix-blacklist]]
792 *
793 * @return array list of prefixes
794 */
795 public static function getFilenamePrefixBlacklist() {
796 $blacklist = array();
797 $message = wfMsgForContent( 'filename-prefix-blacklist' );
798 if( $message && !( wfEmptyMsg( 'filename-prefix-blacklist', $message ) || $message == '-' ) ) {
799 $lines = explode( "\n", $message );
800 foreach( $lines as $line ) {
801 // Remove comment lines
802 $comment = substr( trim( $line ), 0, 1 );
803 if ( $comment == '#' || $comment == '' ) {
804 continue;
805 }
806 // Remove additional comments after a prefix
807 $comment = strpos( $line, '#' );
808 if ( $comment > 0 ) {
809 $line = substr( $line, 0, $comment-1 );
810 }
811 $blacklist[] = trim( $line );
812 }
813 }
814 return $blacklist;
815 }
816
817 /**
818 * Stash a file in a temporary directory for later processing
819 * after the user has confirmed it.
820 *
821 * If the user doesn't explicitly cancel or accept, these files
822 * can accumulate in the temp directory.
823 *
824 * @param string $saveName - the destination filename
825 * @param string $tempName - the source temporary file to save
826 * @return string - full path the stashed file, or false on failure
827 * @access private
828 */
829 function saveTempUploadedFile( $saveName, $tempName ) {
830 global $wgOut;
831 $repo = RepoGroup::singleton()->getLocalRepo();
832 $status = $repo->storeTemp( $saveName, $tempName );
833 if ( !$status->isGood() ) {
834 $this->showError( $status->getWikiText() );
835 return false;
836 } else {
837 return $status->value;
838 }
839 }
840
841 /**
842 * Stash a file in a temporary directory for later processing,
843 * and save the necessary descriptive info into the session.
844 * Returns a key value which will be passed through a form
845 * to pick up the path info on a later invocation.
846 *
847 * @return int
848 * @access private
849 */
850 function stashSession() {
851 $stash = $this->saveTempUploadedFile( $this->mDestName, $this->mTempPath );
852
853 if( !$stash ) {
854 # Couldn't save the file.
855 return false;
856 }
857
858 $key = mt_rand( 0, 0x7fffffff );
859 $_SESSION['wsUploadData'][$key] = array(
860 'mTempPath' => $stash,
861 'mFileSize' => $this->mFileSize,
862 'mSrcName' => $this->mSrcName,
863 'mFileProps' => $this->mFileProps,
864 'version' => self::SESSION_VERSION,
865 );
866 return $key;
867 }
868
869 /**
870 * Remove a temporarily kept file stashed by saveTempUploadedFile().
871 * @access private
872 * @return success
873 */
874 function unsaveUploadedFile() {
875 global $wgOut;
876 if( !$this->mTempPath ) return true; // nothing to delete
877 $repo = RepoGroup::singleton()->getLocalRepo();
878 $success = $repo->freeTemp( $this->mTempPath );
879 if ( ! $success ) {
880 $wgOut->showFileDeleteError( $this->mTempPath );
881 return false;
882 } else {
883 return true;
884 }
885 }
886
887 /* -------------------------------------------------------------- */
888
889 /**
890 * @param string $error as HTML
891 * @access private
892 */
893 function uploadError( $error ) {
894 global $wgOut;
895 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
896 $wgOut->addHTML( '<span class="error">' . $error . '</span>' );
897 }
898
899 /**
900 * There's something wrong with this file, not enough to reject it
901 * totally but we require manual intervention to save it for real.
902 * Stash it away, then present a form asking to confirm or cancel.
903 *
904 * @param string $warning as HTML
905 * @access private
906 */
907 function uploadWarning( $warning ) {
908 global $wgOut;
909 global $wgUseCopyrightUpload;
910
911 $this->mSessionKey = $this->stashSession();
912 if( !$this->mSessionKey ) {
913 # Couldn't save file; an error has been displayed so let's go.
914 return;
915 }
916
917 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
918 $wgOut->addHTML( '<ul class="warning">' . $warning . "</ul>\n" );
919
920 $titleObj = SpecialPage::getTitleFor( 'Upload' );
921
922 if ( $wgUseCopyrightUpload ) {
923 $copyright = Xml::hidden( 'wpUploadCopyStatus', $this->mCopyrightStatus ) . "\n" .
924 Xml::hidden( 'wpUploadSource', $this->mCopyrightSource ) . "\n";
925 } else {
926 $copyright = '';
927 }
928
929 $wgOut->addHTML(
930 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
931 'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
932 Xml::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
933 Xml::hidden( 'wpSessionKey', $this->mSessionKey ) . "\n" .
934 Xml::hidden( 'wpUploadDescription', $this->mComment ) . "\n" .
935 Xml::hidden( 'wpLicense', $this->mLicense ) . "\n" .
936 Xml::hidden( 'wpDestFile', $this->mDesiredDestName ) . "\n" .
937 Xml::hidden( 'wpWatchthis', $this->mWatchthis ) . "\n" .
938 "{$copyright}<br />" .
939 Xml::submitButton( wfMsg( 'ignorewarning' ), array ( 'name' => 'wpUpload', 'id' => 'wpUpload', 'checked' => 'checked' ) ) . ' ' .
940 Xml::submitButton( wfMsg( 'reuploaddesc' ), array ( 'name' => 'wpReUpload', 'id' => 'wpReUpload' ) ) .
941 Xml::closeElement( 'form' ) . "\n"
942 );
943 }
944
945 /**
946 * Displays the main upload form, optionally with a highlighted
947 * error message up at the top.
948 *
949 * @param string $msg as HTML
950 * @access private
951 */
952 function mainUploadForm( $msg='' ) {
953 global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize;
954 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
955 global $wgRequest, $wgAllowCopyUploads;
956 global $wgStylePath, $wgStyleVersion;
957
958 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
959 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
960
961 $adc = wfBoolToStr( $useAjaxDestCheck );
962 $alp = wfBoolToStr( $useAjaxLicensePreview );
963 $autofill = wfBoolToStr( $this->mDesiredDestName == '' );
964
965 $wgOut->addScript( "<script type=\"text/javascript\">
966 wgAjaxUploadDestCheck = {$adc};
967 wgAjaxLicensePreview = {$alp};
968 wgUploadAutoFill = {$autofill};
969 </script>" );
970 $wgOut->addScriptFile( 'upload.js' );
971 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
972
973 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
974 {
975 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form\n" );
976 return false;
977 }
978
979 if( $this->mDesiredDestName ) {
980 $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
981 // Show a subtitle link to deleted revisions (to sysops et al only)
982 if( $title instanceof Title && ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
983 $link = wfMsgExt(
984 $wgUser->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted',
985 array( 'parse', 'replaceafter' ),
986 $wgUser->getSkin()->makeKnownLinkObj(
987 SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ),
988 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
989 )
990 );
991 $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
992 }
993
994 // Show the relevant lines from deletion log (for still deleted files only)
995 if( $title instanceof Title && $title->isDeleted() > 0 && !$title->exists() ) {
996 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
997 }
998 }
999
1000 $cols = intval($wgUser->getOption( 'cols' ));
1001
1002 if( $wgUser->getOption( 'editwidth' ) ) {
1003 $width = " style=\"width:100%\"";
1004 } else {
1005 $width = '';
1006 }
1007
1008 if ( '' != $msg ) {
1009 $sub = wfMsgHtml( 'uploaderror' );
1010 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
1011 "<span class='error'>{$msg}</span>\n" );
1012 }
1013 $wgOut->addHTML( '<div id="uploadtext">' );
1014 $wgOut->addWikiMsg( 'uploadtext', $this->mDesiredDestName );
1015 $wgOut->addHTML( "</div>\n" );
1016
1017 # Print a list of allowed file extensions, if so configured. We ignore
1018 # MIME type here, it's incomprehensible to most people and too long.
1019 global $wgCheckFileExtensions, $wgStrictFileExtensions,
1020 $wgFileExtensions, $wgFileBlacklist;
1021
1022 $allowedExtensions = '';
1023 if( $wgCheckFileExtensions ) {
1024 if( $wgStrictFileExtensions ) {
1025 # Everything not permitted is banned
1026 $extensionsList =
1027 '<div id="mw-upload-permitted">' .
1028 wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
1029 "</div>\n";
1030 } else {
1031 # We have to list both preferred and prohibited
1032 $extensionsList =
1033 '<div id="mw-upload-preferred">' .
1034 wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
1035 "</div>\n" .
1036 '<div id="mw-upload-prohibited">' .
1037 wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileBlacklist ) ) .
1038 "</div>\n";
1039 }
1040 } else {
1041 # Everything is permitted.
1042 $extensionsList = '';
1043 }
1044
1045 # Get the maximum file size from php.ini as $wgMaxUploadSize works for uploads from URL via CURL only
1046 # See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize for possible values of upload_max_filesize
1047 $val = trim( ini_get( 'upload_max_filesize' ) );
1048 $last = strtoupper( ( substr( $val, -1 ) ) );
1049 switch( $last ) {
1050 case 'G':
1051 $val2 = substr( $val, 0, -1 ) * 1024 * 1024 * 1024;
1052 break;
1053 case 'M':
1054 $val2 = substr( $val, 0, -1 ) * 1024 * 1024;
1055 break;
1056 case 'K':
1057 $val2 = substr( $val, 0, -1 ) * 1024;
1058 break;
1059 default:
1060 $val2 = $val;
1061 }
1062 $val2 = $wgAllowCopyUploads ? min( $wgMaxUploadSize, $val2 ) : $val2;
1063 $maxUploadSize = '<div id="mw-upload-maxfilesize">' .
1064 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
1065 $wgLang->formatSize( $val2 ) ) .
1066 "</div>\n";
1067
1068 $sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
1069 $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
1070
1071 $msg = $this->mReUpload ? 'filereuploadsummary' : 'fileuploadsummary';
1072 $summary = wfMsgExt( $msg, 'parseinline' );
1073
1074 $licenses = new Licenses();
1075 $license = wfMsgExt( 'license', array( 'parseinline' ) );
1076 $nolicense = wfMsgHtml( 'nolicense' );
1077 $licenseshtml = $licenses->getHtml();
1078
1079 $ulb = wfMsgHtml( 'uploadbtn' );
1080
1081
1082 $titleObj = SpecialPage::getTitleFor( 'Upload' );
1083
1084 $encDestName = htmlspecialchars( $this->mDesiredDestName );
1085
1086 $watchChecked = $this->watchCheck() ? 'checked="checked"' : '';
1087 # Re-uploads should not need "file exist already" warnings
1088 $warningChecked = ($this->mIgnoreWarning || $this->mReUpload) ? 'checked="checked"' : '';
1089
1090 // Prepare form for upload or upload/copy
1091 if( $wgAllowCopyUploads && $wgUser->isAllowed( 'upload_by_url' ) ) {
1092 $filename_form =
1093 "<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='file' " .
1094 "onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" .
1095 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
1096 "onfocus='" .
1097 "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
1098 "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
1099 "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
1100 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
1101 "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='web' " .
1102 "onchange='toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\")' />" .
1103 "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " .
1104 "onfocus='" .
1105 "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" .
1106 "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
1107 "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' disabled='disabled' />" .
1108 wfMsgHtml( 'upload_source_url' ) ;
1109 } else {
1110 $filename_form =
1111 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
1112 ($this->mDesiredDestName?"":"onchange='fillDestFilename(\"wpUploadFile\")' ") .
1113 "size='60' />" .
1114 "<input type='hidden' name='wpSourceType' value='file' />" ;
1115 }
1116 if ( $useAjaxDestCheck ) {
1117 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'>&nbsp;</td></tr>";
1118 $destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"';
1119 } else {
1120 $warningRow = '';
1121 $destOnkeyup = '';
1122 }
1123 # Uploading a new version? If so, the name is fixed.
1124 $on = $this->mReUpload ? "disabled='disabled'" : "";
1125
1126 $encComment = htmlspecialchars( $this->mComment );
1127
1128 $wgOut->addHTML(
1129 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL(),
1130 'enctype' => 'multipart/form-data', 'id' => 'mw-upload-form' ) ) .
1131 Xml::openElement( 'fieldset' ) .
1132 Xml::element( 'legend', null, wfMsg( 'upload' ) ) .
1133 Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
1134 "<tr>
1135 {$this->uploadFormTextTop}
1136 <td class='mw-label'>
1137 <label for='wpUploadFile'>{$sourcefilename}</label>
1138 </td>
1139 <td class='mw-input'>
1140 {$filename_form}
1141 </td>
1142 </tr>
1143 <tr>
1144 <td></td>
1145 <td>
1146 {$maxUploadSize}
1147 {$extensionsList}
1148 </td>
1149 </tr>
1150 <tr>
1151 <td class='mw-label'>
1152 <label for='wpDestFile'>{$destfilename}</label>
1153 </td>
1154 <td class='mw-input'>
1155 <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
1156 value=\"{$encDestName}\" onchange='toggleFilenameFiller()' $on $destOnkeyup />
1157 </td>
1158 </tr>
1159 <tr>
1160 <td class='mw-label'>
1161 <label for='wpUploadDescription'>{$summary}</label>
1162 </td>
1163 <td class='mw-input'>
1164 <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6'
1165 cols='{$cols}'{$width}>$encComment</textarea>
1166 {$this->uploadFormTextAfterSummary}
1167 </td>
1168 </tr>
1169 <tr>"
1170 );
1171 # Re-uploads should not need license info
1172 if ( !$this->mReUpload && $licenseshtml != '' ) {
1173 global $wgStylePath;
1174 $wgOut->addHTML( "
1175 <td class='mw-label'>
1176 <label for='wpLicense'>$license</label>
1177 </td>
1178 <td class='mw-input'>
1179 <select name='wpLicense' id='wpLicense' tabindex='4'
1180 onchange='licenseSelectorCheck()'>
1181 <option value=''>$nolicense</option>
1182 $licenseshtml
1183 </select>
1184 </td>
1185 </tr>
1186 <tr>"
1187 );
1188 if( $useAjaxLicensePreview ) {
1189 $wgOut->addHTML( "
1190 <td></td>
1191 <td id=\"mw-license-preview\"></td>
1192 </tr>
1193 <tr>"
1194 );
1195 }
1196 }
1197
1198 if ( !$this->mReUpload && $wgUseCopyrightUpload ) {
1199 $filestatus = wfMsgExt( 'filestatus', 'escapenoentities' );
1200 $copystatus = htmlspecialchars( $this->mCopyrightStatus );
1201 $filesource = wfMsgExt( 'filesource', 'escapenoentities' );
1202 $uploadsource = htmlspecialchars( $this->mCopyrightSource );
1203
1204 $wgOut->addHTML( "
1205 <td class='mw-label' style='white-space: nowrap;'>
1206 <label for='wpUploadCopyStatus'>$filestatus</label></td>
1207 <td class='mw-input'>
1208 <input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus'
1209 value=\"$copystatus\" size='60' />
1210 </td>
1211 </tr>
1212 <tr>
1213 <td class='mw-label'>
1214 <label for='wpUploadCopyStatus'>$filesource</label>
1215 </td>
1216 <td class='mw-input'>
1217 <input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus'
1218 value=\"$uploadsource\" size='60' />
1219 </td>
1220 </tr>
1221 <tr>"
1222 );
1223 }
1224
1225 $wgOut->addHTML( "
1226 <td></td>
1227 <td>
1228 <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
1229 <label for='wpWatchthis'>" . wfMsgHtml( 'watchthisupload' ) . "</label>
1230 <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' $warningChecked />
1231 <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
1232 </td>
1233 </tr>
1234 $warningRow
1235 <tr>
1236 <td></td>
1237 <td class='mw-input'>
1238 <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" . $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
1239 </td>
1240 </tr>
1241 <tr>
1242 <td></td>
1243 <td class='mw-input'>"
1244 );
1245 $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
1246 $wgOut->addHTML( "
1247 </td>
1248 </tr>" .
1249 Xml::closeElement( 'table' ) .
1250 Xml::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
1251 Xml::closeElement( 'fieldset' ) .
1252 Xml::closeElement( 'form' )
1253 );
1254 $uploadfooter = wfMsgNoTrans( 'uploadfooter' );
1255 if( $uploadfooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadfooter ) ){
1256 $wgOut->addWikiText( '<div id="mw-upload-footer-message">' . $uploadfooter . '</div>' );
1257 }
1258 }
1259
1260 /* -------------------------------------------------------------- */
1261
1262 /**
1263 * See if we should check the 'watch this page' checkbox on the form
1264 * based on the user's preferences and whether we're being asked
1265 * to create a new file or update an existing one.
1266 *
1267 * In the case where 'watch edits' is off but 'watch creations' is on,
1268 * we'll leave the box unchecked.
1269 *
1270 * Note that the page target can be changed *on the form*, so our check
1271 * state can get out of sync.
1272 */
1273 function watchCheck() {
1274 global $wgUser;
1275 if( $wgUser->getOption( 'watchdefault' ) ) {
1276 // Watch all edits!
1277 return true;
1278 }
1279
1280 $local = wfLocalFile( $this->mDesiredDestName );
1281 if( $local && $local->exists() ) {
1282 // We're uploading a new version of an existing file.
1283 // No creation, so don't watch it if we're not already.
1284 return $local->getTitle()->userIsWatching();
1285 } else {
1286 // New page should get watched if that's our option.
1287 return $wgUser->getOption( 'watchcreations' );
1288 }
1289 }
1290
1291 /**
1292 * Split a file into a base name and all dot-delimited 'extensions'
1293 * on the end. Some web server configurations will fall back to
1294 * earlier pseudo-'extensions' to determine type and execute
1295 * scripts, so the blacklist needs to check them all.
1296 *
1297 * @return array
1298 */
1299 public function splitExtensions( $filename ) {
1300 $bits = explode( '.', $filename );
1301 $basename = array_shift( $bits );
1302 return array( $basename, $bits );
1303 }
1304
1305 /**
1306 * Perform case-insensitive match against a list of file extensions.
1307 * Returns true if the extension is in the list.
1308 *
1309 * @param string $ext
1310 * @param array $list
1311 * @return bool
1312 */
1313 function checkFileExtension( $ext, $list ) {
1314 return in_array( strtolower( $ext ), $list );
1315 }
1316
1317 /**
1318 * Perform case-insensitive match against a list of file extensions.
1319 * Returns true if any of the extensions are in the list.
1320 *
1321 * @param array $ext
1322 * @param array $list
1323 * @return bool
1324 */
1325 public function checkFileExtensionList( $ext, $list ) {
1326 foreach( $ext as $e ) {
1327 if( in_array( strtolower( $e ), $list ) ) {
1328 return true;
1329 }
1330 }
1331 return false;
1332 }
1333
1334 /**
1335 * Verifies that it's ok to include the uploaded file
1336 *
1337 * @param string $tmpfile the full path of the temporary file to verify
1338 * @param string $extension The filename extension that the file is to be served with
1339 * @return mixed true of the file is verified, a WikiError object otherwise.
1340 */
1341 function verify( $tmpfile, $extension ) {
1342 #magically determine mime type
1343 $magic = MimeMagic::singleton();
1344 $mime = $magic->guessMimeType($tmpfile,false);
1345
1346
1347 #check mime type, if desired
1348 global $wgVerifyMimeType;
1349 if ($wgVerifyMimeType) {
1350 wfDebug ( "\n\nmime: <$mime> extension: <$extension>\n\n");
1351 #check mime type against file extension
1352 if( !self::verifyExtension( $mime, $extension ) ) {
1353 return new WikiErrorMsg( 'uploadcorrupt' );
1354 }
1355
1356 #check mime type blacklist
1357 global $wgMimeTypeBlacklist;
1358 if( isset($wgMimeTypeBlacklist) && !is_null($wgMimeTypeBlacklist) ) {
1359 if ( $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) {
1360 return new WikiErrorMsg( 'filetype-badmime', htmlspecialchars( $mime ) );
1361 }
1362
1363 # Check IE type
1364 $fp = fopen( $tmpfile, 'rb' );
1365 $chunk = fread( $fp, 256 );
1366 fclose( $fp );
1367 $extMime = $magic->guessTypesForExtension( $extension );
1368 $ieTypes = $magic->getIEMimeTypes( $tmpfile, $chunk, $extMime );
1369 foreach ( $ieTypes as $ieType ) {
1370 if ( $this->checkFileExtension( $ieType, $wgMimeTypeBlacklist ) ) {
1371 return new WikiErrorMsg( 'filetype-bad-ie-mime', $ieType );
1372 }
1373 }
1374 }
1375 }
1376
1377 #check for htmlish code and javascript
1378 if( $this->detectScript ( $tmpfile, $mime, $extension ) ) {
1379 return new WikiErrorMsg( 'uploadscripted' );
1380 }
1381 if( $extension == 'svg' || $mime == 'image/svg+xml' ) {
1382 if( $this->detectScriptInSvg( $tmpfile ) ) {
1383 return new WikiErrorMsg( 'uploadscripted' );
1384 }
1385 }
1386
1387 /**
1388 * Scan the uploaded file for viruses
1389 */
1390 $virus= $this->detectVirus($tmpfile);
1391 if ( $virus ) {
1392 return new WikiErrorMsg( 'uploadvirus', htmlspecialchars($virus) );
1393 }
1394
1395 wfDebug( __METHOD__.": all clear; passing.\n" );
1396 return true;
1397 }
1398
1399 /**
1400 * Checks if the mime type of the uploaded file matches the file extension.
1401 *
1402 * @param string $mime the mime type of the uploaded file
1403 * @param string $extension The filename extension that the file is to be served with
1404 * @return bool
1405 */
1406 static function verifyExtension( $mime, $extension ) {
1407 $magic = MimeMagic::singleton();
1408
1409 if ( ! $mime || $mime == 'unknown' || $mime == 'unknown/unknown' )
1410 if ( ! $magic->isRecognizableExtension( $extension ) ) {
1411 wfDebug( __METHOD__.": passing file with unknown detected mime type; " .
1412 "unrecognized extension '$extension', can't verify\n" );
1413 return true;
1414 } else {
1415 wfDebug( __METHOD__.": rejecting file with unknown detected mime type; ".
1416 "recognized extension '$extension', so probably invalid file\n" );
1417 return false;
1418 }
1419
1420 $match= $magic->isMatchingExtension($extension,$mime);
1421
1422 if ($match===NULL) {
1423 wfDebug( __METHOD__.": no file extension known for mime type $mime, passing file\n" );
1424 return true;
1425 } elseif ($match===true) {
1426 wfDebug( __METHOD__.": mime type $mime matches extension $extension, passing file\n" );
1427
1428 #TODO: if it's a bitmap, make sure PHP or ImageMagic resp. can handle it!
1429 return true;
1430
1431 } else {
1432 wfDebug( __METHOD__.": mime type $mime mismatches file extension $extension, rejecting file\n" );
1433 return false;
1434 }
1435 }
1436
1437
1438 /**
1439 * Heuristic for detecting files that *could* contain JavaScript instructions or
1440 * things that may look like HTML to a browser and are thus
1441 * potentially harmful. The present implementation will produce false positives in some situations.
1442 *
1443 * @param string $file Pathname to the temporary upload file
1444 * @param string $mime The mime type of the file
1445 * @param string $extension The extension of the file
1446 * @return bool true if the file contains something looking like embedded scripts
1447 */
1448 function detectScript($file, $mime, $extension) {
1449 global $wgAllowTitlesInSVG;
1450
1451 #ugly hack: for text files, always look at the entire file.
1452 #For binarie field, just check the first K.
1453
1454 if (strpos($mime,'text/')===0) $chunk = file_get_contents( $file );
1455 else {
1456 $fp = fopen( $file, 'rb' );
1457 $chunk = fread( $fp, 1024 );
1458 fclose( $fp );
1459 }
1460
1461 $chunk= strtolower( $chunk );
1462
1463 if (!$chunk) return false;
1464
1465 #decode from UTF-16 if needed (could be used for obfuscation).
1466 if (substr($chunk,0,2)=="\xfe\xff") $enc= "UTF-16BE";
1467 elseif (substr($chunk,0,2)=="\xff\xfe") $enc= "UTF-16LE";
1468 else $enc= NULL;
1469
1470 if ($enc) $chunk= iconv($enc,"ASCII//IGNORE",$chunk);
1471
1472 $chunk= trim($chunk);
1473
1474 #FIXME: convert from UTF-16 if necessarry!
1475
1476 wfDebug("SpecialUpload::detectScript: checking for embedded scripts and HTML stuff\n");
1477
1478 #check for HTML doctype
1479 if (eregi("<!DOCTYPE *X?HTML",$chunk)) return true;
1480
1481 /**
1482 * Internet Explorer for Windows performs some really stupid file type
1483 * autodetection which can cause it to interpret valid image files as HTML
1484 * and potentially execute JavaScript, creating a cross-site scripting
1485 * attack vectors.
1486 *
1487 * Apple's Safari browser also performs some unsafe file type autodetection
1488 * which can cause legitimate files to be interpreted as HTML if the
1489 * web server is not correctly configured to send the right content-type
1490 * (or if you're really uploading plain text and octet streams!)
1491 *
1492 * Returns true if IE is likely to mistake the given file for HTML.
1493 * Also returns true if Safari would mistake the given file for HTML
1494 * when served with a generic content-type.
1495 */
1496
1497 $tags = array(
1498 '<a href',
1499 '<body',
1500 '<head',
1501 '<html', #also in safari
1502 '<img',
1503 '<pre',
1504 '<script', #also in safari
1505 '<table'
1506 );
1507 if( ! $wgAllowTitlesInSVG && $extension !== 'svg' && $mime !== 'image/svg' ) {
1508 $tags[] = '<title';
1509 }
1510
1511 foreach( $tags as $tag ) {
1512 if( false !== strpos( $chunk, $tag ) ) {
1513 return true;
1514 }
1515 }
1516
1517 /*
1518 * look for javascript
1519 */
1520
1521 #resolve entity-refs to look at attributes. may be harsh on big files... cache result?
1522 $chunk = Sanitizer::decodeCharReferences( $chunk );
1523
1524 #look for script-types
1525 if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim',$chunk)) return true;
1526
1527 #look for html-style script-urls
1528 if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) return true;
1529
1530 #look for css-style script-urls
1531 if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) return true;
1532
1533 wfDebug("SpecialUpload::detectScript: no scripts found\n");
1534 return false;
1535 }
1536
1537 function detectScriptInSvg( $filename ) {
1538 $check = new XmlTypeCheck( $filename, array( $this, 'checkSvgScriptCallback' ) );
1539 return $check->filterMatch;
1540 }
1541
1542 /**
1543 * @todo Replace this with a whitelist filter!
1544 */
1545 function checkSvgScriptCallback( $element, $attribs ) {
1546 $stripped = $this->stripXmlNamespace( $element );
1547
1548 if( $stripped == 'script' ) {
1549 wfDebug( __METHOD__ . ": Found script element '$element' in uploaded file.\n" );
1550 return true;
1551 }
1552
1553 foreach( $attribs as $attrib => $value ) {
1554 $stripped = $this->stripXmlNamespace( $attrib );
1555 if( substr( $stripped, 0, 2 ) == 'on' ) {
1556 wfDebug( __METHOD__ . ": Found script attribute '$attrib'='value' in uploaded file.\n" );
1557 return true;
1558 }
1559 if( $stripped == 'href' && strpos( strtolower( $value ), 'javascript:' ) !== false ) {
1560 wfDebug( __METHOD__ . ": Found script href attribute '$attrib'='$value' in uploaded file.\n" );
1561 return true;
1562 }
1563 }
1564 }
1565
1566 private function stripXmlNamespace( $name ) {
1567 // 'http://www.w3.org/2000/svg:script' -> 'script'
1568 $parts = explode( ':', strtolower( $name ) );
1569 return array_pop( $parts );
1570 }
1571
1572 /**
1573 * Generic wrapper function for a virus scanner program.
1574 * This relies on the $wgAntivirus and $wgAntivirusSetup variables.
1575 * $wgAntivirusRequired may be used to deny upload if the scan fails.
1576 *
1577 * @param string $file Pathname to the temporary upload file
1578 * @return mixed false if not virus is found, NULL if the scan fails or is disabled,
1579 * or a string containing feedback from the virus scanner if a virus was found.
1580 * If textual feedback is missing but a virus was found, this function returns true.
1581 */
1582 function detectVirus($file) {
1583 global $wgAntivirus, $wgAntivirusSetup, $wgAntivirusRequired, $wgOut;
1584
1585 if ( !$wgAntivirus ) {
1586 wfDebug( __METHOD__.": virus scanner disabled\n");
1587 return NULL;
1588 }
1589
1590 if ( !$wgAntivirusSetup[$wgAntivirus] ) {
1591 wfDebug( __METHOD__.": unknown virus scanner: $wgAntivirus\n" );
1592 $wgOut->wrapWikiMsg( '<div class="error">$1</div>', array( 'virus-badscanner', $wgAntivirus ) );
1593 return wfMsg('virus-unknownscanner') . " $wgAntivirus";
1594 }
1595
1596 # look up scanner configuration
1597 $command = $wgAntivirusSetup[$wgAntivirus]["command"];
1598 $exitCodeMap = $wgAntivirusSetup[$wgAntivirus]["codemap"];
1599 $msgPattern = isset( $wgAntivirusSetup[$wgAntivirus]["messagepattern"] ) ?
1600 $wgAntivirusSetup[$wgAntivirus]["messagepattern"] : null;
1601
1602 if ( strpos( $command,"%f" ) === false ) {
1603 # simple pattern: append file to scan
1604 $command .= " " . wfEscapeShellArg( $file );
1605 } else {
1606 # complex pattern: replace "%f" with file to scan
1607 $command = str_replace( "%f", wfEscapeShellArg( $file ), $command );
1608 }
1609
1610 wfDebug( __METHOD__.": running virus scan: $command \n" );
1611
1612 # execute virus scanner
1613 $exitCode = false;
1614
1615 #NOTE: there's a 50 line workaround to make stderr redirection work on windows, too.
1616 # that does not seem to be worth the pain.
1617 # Ask me (Duesentrieb) about it if it's ever needed.
1618 $output = array();
1619 if ( wfIsWindows() ) {
1620 exec( "$command", $output, $exitCode );
1621 } else {
1622 exec( "$command 2>&1", $output, $exitCode );
1623 }
1624
1625 # map exit code to AV_xxx constants.
1626 $mappedCode = $exitCode;
1627 if ( $exitCodeMap ) {
1628 if ( isset( $exitCodeMap[$exitCode] ) ) {
1629 $mappedCode = $exitCodeMap[$exitCode];
1630 } elseif ( isset( $exitCodeMap["*"] ) ) {
1631 $mappedCode = $exitCodeMap["*"];
1632 }
1633 }
1634
1635 if ( $mappedCode === AV_SCAN_FAILED ) {
1636 # scan failed (code was mapped to false by $exitCodeMap)
1637 wfDebug( __METHOD__.": failed to scan $file (code $exitCode).\n" );
1638
1639 if ( $wgAntivirusRequired ) {
1640 return wfMsg('virus-scanfailed', array( $exitCode ) );
1641 } else {
1642 return NULL;
1643 }
1644 } else if ( $mappedCode === AV_SCAN_ABORTED ) {
1645 # scan failed because filetype is unknown (probably imune)
1646 wfDebug( __METHOD__.": unsupported file type $file (code $exitCode).\n" );
1647 return NULL;
1648 } else if ( $mappedCode === AV_NO_VIRUS ) {
1649 # no virus found
1650 wfDebug( __METHOD__.": file passed virus scan.\n" );
1651 return false;
1652 } else {
1653 $output = join( "\n", $output );
1654 $output = trim( $output );
1655
1656 if ( !$output ) {
1657 $output = true; #if there's no output, return true
1658 } elseif ( $msgPattern ) {
1659 $groups = array();
1660 if ( preg_match( $msgPattern, $output, $groups ) ) {
1661 if ( $groups[1] ) {
1662 $output = $groups[1];
1663 }
1664 }
1665 }
1666
1667 wfDebug( __METHOD__.": FOUND VIRUS! scanner feedback: $output \n" );
1668 return $output;
1669 }
1670 }
1671
1672 /**
1673 * Check if the temporary file is MacBinary-encoded, as some uploads
1674 * from Internet Explorer on Mac OS Classic and Mac OS X will be.
1675 * If so, the data fork will be extracted to a second temporary file,
1676 * which will then be checked for validity and either kept or discarded.
1677 *
1678 * @access private
1679 */
1680 function checkMacBinary() {
1681 $macbin = new MacBinary( $this->mTempPath );
1682 if( $macbin->isValid() ) {
1683 $dataFile = tempnam( wfTempDir(), "WikiMacBinary" );
1684 $dataHandle = fopen( $dataFile, 'wb' );
1685
1686 wfDebug( "SpecialUpload::checkMacBinary: Extracting MacBinary data fork to $dataFile\n" );
1687 $macbin->extractData( $dataHandle );
1688
1689 $this->mTempPath = $dataFile;
1690 $this->mFileSize = $macbin->dataForkLength();
1691
1692 // We'll have to manually remove the new file if it's not kept.
1693 $this->mRemoveTempFile = true;
1694 }
1695 $macbin->close();
1696 }
1697
1698 /**
1699 * If we've modified the upload file we need to manually remove it
1700 * on exit to clean up.
1701 * @access private
1702 */
1703 function cleanupTempFile() {
1704 if ( $this->mRemoveTempFile && $this->mTempPath && file_exists( $this->mTempPath ) ) {
1705 wfDebug( "SpecialUpload::cleanupTempFile: Removing temporary file {$this->mTempPath}\n" );
1706 unlink( $this->mTempPath );
1707 }
1708 }
1709
1710 /**
1711 * Check if there's an overwrite conflict and, if so, if restrictions
1712 * forbid this user from performing the upload.
1713 *
1714 * @return mixed true on success, WikiError on failure
1715 * @access private
1716 */
1717 function checkOverwrite( $name ) {
1718 $img = wfFindFile( $name );
1719
1720 $error = '';
1721 if( $img ) {
1722 global $wgUser, $wgOut;
1723 if( $img->isLocal() ) {
1724 if( !self::userCanReUpload( $wgUser, $img->name ) ) {
1725 $error = 'fileexists-forbidden';
1726 }
1727 } else {
1728 if( !$wgUser->isAllowed( 'reupload' ) ||
1729 !$wgUser->isAllowed( 'reupload-shared' ) ) {
1730 $error = "fileexists-shared-forbidden";
1731 }
1732 }
1733 }
1734
1735 if( $error ) {
1736 $errorText = wfMsg( $error, wfEscapeWikiText( $img->getName() ) );
1737 return $errorText;
1738 }
1739
1740 // Rockin', go ahead and upload
1741 return true;
1742 }
1743
1744 /**
1745 * Check if a user is the last uploader
1746 *
1747 * @param User $user
1748 * @param string $img, image name
1749 * @return bool
1750 */
1751 public static function userCanReUpload( User $user, $img ) {
1752 if( $user->isAllowed( 'reupload' ) )
1753 return true; // non-conditional
1754 if( !$user->isAllowed( 'reupload-own' ) )
1755 return false;
1756
1757 $dbr = wfGetDB( DB_SLAVE );
1758 $row = $dbr->selectRow('image',
1759 /* SELECT */ 'img_user',
1760 /* WHERE */ array( 'img_name' => $img )
1761 );
1762 if ( !$row )
1763 return false;
1764
1765 return $user->getId() == $row->img_user;
1766 }
1767
1768 /**
1769 * Display an error with a wikitext description
1770 */
1771 function showError( $description ) {
1772 global $wgOut;
1773 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
1774 $wgOut->setRobotPolicy( "noindex,nofollow" );
1775 $wgOut->setArticleRelated( false );
1776 $wgOut->enableClientCache( false );
1777 $wgOut->addWikiText( $description );
1778 }
1779
1780 /**
1781 * Get the initial image page text based on a comment and optional file status information
1782 */
1783 static function getInitialPageText( $comment, $license, $copyStatus, $source ) {
1784 global $wgUseCopyrightUpload;
1785 if ( $wgUseCopyrightUpload ) {
1786 if ( $license != '' ) {
1787 $licensetxt = '== ' . wfMsgForContent( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1788 }
1789 $pageText = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n" .
1790 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
1791 "$licensetxt" .
1792 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
1793 } else {
1794 if ( $license != '' ) {
1795 $filedesc = $comment == '' ? '' : '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n";
1796 $pageText = $filedesc .
1797 '== ' . wfMsgForContent ( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1798 } else {
1799 $pageText = $comment;
1800 }
1801 }
1802 return $pageText;
1803 }
1804
1805 /**
1806 * If there are rows in the deletion log for this file, show them,
1807 * along with a nice little note for the user
1808 *
1809 * @param OutputPage $out
1810 * @param string filename
1811 */
1812 private function showDeletionLog( $out, $filename ) {
1813 global $wgUser;
1814 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
1815 $pager = new LogPager( $loglist, 'delete', false, $filename );
1816 if( $pager->getNumRows() > 0 ) {
1817 $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
1818 $out->addWikiMsg( 'upload-wasdeleted' );
1819 $out->addHTML(
1820 $loglist->beginLogEventsList() .
1821 $pager->getBody() .
1822 $loglist->endLogEventsList()
1823 );
1824 $out->addHTML( '</div>' );
1825 }
1826 }
1827 }