8 * implements Special:Upload
11 class UploadForm
extends SpecialPage
{
15 var $mComment, $mLicense, $mIgnoreWarning;
16 var $mCopyrightStatus, $mCopyrightSource, $mReUpload, $mAction, $mUploadClicked;
20 var $mUpload; // Instance of UploadBase or derivative
22 # Placeholders for text injection by hooks (must be HTML)
23 # extensions should take care to _append_ to the present value
24 var $uploadFormTextTop;
25 var $uploadFormTextAfterSummary;
26 var $mTokenOk = false;
27 var $mForReUpload = false;
31 * Constructor : initialise object
32 * Get data POSTed through the form and assign them to the object
33 * @param $request Data posted.
35 function __construct( $request = null ) {
36 parent
::__construct( 'Upload', 'upload' );
37 $this->mRequest
= $request;
40 protected function initForm() {
41 global $wgRequest, $wgUser;
43 if ( is_null( $this->mRequest
) ) {
44 $request = $wgRequest;
46 $request = $this->mRequest
;
48 // Guess the desired name from the filename if not provided
49 $this->mDesiredDestName
= $request->getText( 'wpDestFile' );
50 if( !$this->mDesiredDestName
)
51 $this->mDesiredDestName
= $request->getText( 'wpUploadFile' );
53 $this->mIgnoreWarning
= $request->getCheck( 'wpIgnoreWarning' );
54 $this->mComment
= $request->getText( 'wpUploadDescription' );
56 if( !$request->wasPosted() ) {
57 # GET requests just give the main form; no data except destination
58 # filename and description
61 //if it was posted check for the token (no remote POST'ing with user credentials)
62 $token = $request->getVal( 'wpEditToken' );
63 $this->mTokenOk
= $wgUser->matchEditToken( $token );
65 # Placeholders for text injection by hooks (empty per default)
66 $this->uploadFormTextTop
= "";
67 $this->uploadFormTextAfterSummary
= "";
69 $this->mUploadClicked
= $request->getCheck( 'wpUpload' );
71 $this->mLicense
= $request->getText( 'wpLicense' );
72 $this->mCopyrightStatus
= $request->getText( 'wpUploadCopyStatus' );
73 $this->mCopyrightSource
= $request->getText( 'wpUploadSource' );
74 $this->mWatchthis
= $request->getBool( 'wpWatchthis' );
75 $this->mSourceType
= $request->getText( 'wpSourceType' );
76 $this->mDestWarningAck
= $request->getText( 'wpDestFileWarningAck' );
78 $this->mForReUpload
= $request->getBool( 'wpForReUpload' );
80 $this->mReUpload
= $request->getCheck( 'wpReUpload' );
82 $this->mAction
= $request->getVal( 'action' );
83 $this->mUpload
= UploadBase
::createFromRequest( $request );
86 public function userCanExecute( $user ) {
87 return UploadBase
::isEnabled() && parent
::userCanExecute( $user );
94 function execute( $par ) {
95 global $wgUser, $wgOut, $wgRequest;
98 $this->outputHeader();
102 # Check uploading enabled
103 if( !UploadBase
::isEnabled() ) {
104 $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
109 global $wgGroupPermissions;
110 if( !$wgUser->isAllowed( 'upload' ) ) {
111 if( !$wgUser->isLoggedIn() && ( $wgGroupPermissions['user']['upload']
112 ||
$wgGroupPermissions['autoconfirmed']['upload'] ) ) {
113 // Custom message if logged-in users without any special rights can upload
114 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
116 $wgOut->permissionRequired( 'upload' );
122 if( $wgUser->isBlocked() ) {
123 $wgOut->blockedPage();
128 $wgOut->readOnlyPage();
131 //check token if uploading or reUploading
132 if( !$this->mTokenOk
&& !$this->mReUpload
&& ($this->mUpload
&& (
133 'submit' == $this->mAction ||
$this->mUploadClicked
) )
135 $this->mainUploadForm ( wfMsg( 'session_fail_preview' ) );
140 if( $this->mReUpload
&& $this->mUpload
) {
141 // User choose to cancel upload
142 if( !$this->mUpload
->unsaveUploadedFile() ) {
145 # Because it is probably checked and shouldn't be
146 $this->mIgnoreWarning
= false;
147 $this->mainUploadForm();
148 } elseif( $this->mUpload
&& (
149 'submit' == $this->mAction ||
150 $this->mUploadClicked
152 $this->processUpload();
154 $this->mainUploadForm();
158 $this->mUpload
->cleanupTempFile();
163 * Checks are made in SpecialUpload::execute()
165 * FIXME this should really use the standard Status class (instead of associative array)
166 * FIXME would be nice if we refactored this into the upload api.
167 * (the special upload page is not the only response point that needs clean localized error msgs)
171 function processUpload(){
172 global $wgOut, $wgFileExtensions, $wgLang;
173 $details = $this->internalProcessUpload();
174 switch( $details['status'] ) {
175 case UploadBase
::SUCCESS
:
176 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
179 case UploadBase
::BEFORE_PROCESSING
:
180 $this->uploadError( $details['error'] );
182 case UploadBase
::LARGE_FILE_SERVER
:
183 $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
186 case UploadBase
::EMPTY_FILE
:
187 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
190 case UploadBase
::MIN_LENGTH_PARTNAME
:
191 $this->mainUploadForm( wfMsgHtml( 'minlength1' ) );
194 case UploadBase
::ILLEGAL_FILENAME
:
195 $this->uploadError( wfMsgExt( 'illegalfilename',
196 'parseinline', $details['filtered'] ) );
199 case UploadBase
::PROTECTED_PAGE
:
200 $wgOut->showPermissionsErrorPage( $details['permissionserrors'] );
203 case UploadBase
::OVERWRITE_EXISTING_FILE
:
204 $this->uploadError( wfMsgExt( $details['overwrite'],
208 case UploadBase
::FILETYPE_MISSING
:
209 $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
212 case UploadBase
::FILETYPE_BADTYPE
:
213 $finalExt = $details['finalExt'];
215 wfMsgExt( 'filetype-banned-type',
216 array( 'parseinline' ),
217 htmlspecialchars( $finalExt ),
219 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
222 $wgLang->formatNum( count( $wgFileExtensions ) )
227 case UploadBase
::VERIFICATION_ERROR
:
228 unset( $details['status'] );
229 $code = array_shift( $details );
230 $this->uploadError( wfMsgExt( $code, 'parseinline', $details ) );
233 case UploadBase
::UPLOAD_VERIFICATION_ERROR
:
234 $error = $details['error'];
235 $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
238 case UploadBase
::UPLOAD_WARNING
:
239 unset( $details['status'] );
240 $this->uploadWarning( $details );
243 case UploadBase
::INTERNAL_ERROR
:
244 $status = $details['internal'];
245 $this->showError( $wgOut->parse( $status->getWikiText() ) );
249 throw new MWException( __METHOD__
. ": Unknown value `{$details['status']}`" );
254 * Really do the upload
255 * Checks are made in SpecialUpload::execute()
257 * @param array $resultDetails contains result-specific dict of additional values
261 function internalProcessUpload() {
264 if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
266 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
267 return array( 'status' => UploadBase
::BEFORE_PROCESSING
);
271 * If the image is protected, non-sysop users won't be able
272 * to modify it by uploading a new revision.
274 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
275 if( $permErrors !== true ) {
276 return array( 'status' => UploadBase
::PROTECTED_PAGE
, 'permissionserrors' => $permErrors );
279 // Fetch the file if required
280 $status = $this->mUpload
->fetchFile();
281 if( !$status->isOK() ){
282 return array( 'status' =>UploadBase
::BEFORE_PROCESSING
, 'error'=>$status->getWikiText() );
285 // Check whether this is a sane upload
286 $result = $this->mUpload
->verifyUpload();
287 if( $result != UploadBase
::OK
)
290 $this->mLocalFile
= $this->mUpload
->getLocalFile();
292 if( !$this->mIgnoreWarning
) {
293 $warnings = $this->mUpload
->checkWarnings();
295 if( count( $warnings ) ) {
296 $warnings['status'] = UploadBase
::UPLOAD_WARNING
;
303 * Try actually saving the thing...
304 * It will show an error form on failure. No it will not.
306 if( !$this->mForReUpload
) {
307 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
308 $this->mCopyrightStatus
, $this->mCopyrightSource
);
312 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
314 if ( !$status->isGood() ) {
315 return array( 'status' => UploadBase
::INTERNAL_ERROR
, 'internal' => $status );
317 // Success, redirect to description page
318 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
319 return UploadBase
::SUCCESS
;
324 * Do existence checks on a file and produce a warning
325 * This check is static and can be done pre-upload via AJAX
326 * Returns an HTML fragment consisting of one or more LI elements if there is a warning
327 * Returns an empty string if there is no warning
329 static function getExistsWarning( $exists ) {
330 global $wgUser, $wgContLang;
331 // Check for uppercase extension. We allow these filenames but check if an image
332 // with lowercase extension exists already
334 $align = $wgContLang->isRtl() ?
'left' : 'right';
336 if( $exists === false )
340 $align = $wgContLang->isRtl() ?
'left' : 'right';
342 list( $existsType, $file ) = $exists;
344 $sk = $wgUser->getSkin();
346 if( $existsType == 'exists' ) {
348 $dlink = $sk->linkKnown( $file->getTitle() );
349 if ( $file->allowInlineDisplay() ) {
350 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
351 $file->getName(), $align, array(), false, true );
352 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
353 $icon = $file->iconThumb();
354 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
355 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
360 $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2;
362 } elseif( $existsType == 'page-exists' ) {
363 $lnk = $sk->linkKnown( $file->getTitle(), '', '',array('redirect'=>'no') );
364 $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>';
365 } elseif ( $existsType == 'exists-normalized' ) {
366 # Check if image with lowercase extension exists.
367 # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
368 $dlink = $sk->linkKnown( $nt_lc );
369 if ( $file_lc->allowInlineDisplay() ) {
370 // FIXME: replace deprecated makeImageLinkObj by link()
371 $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline' ),
372 $nt_lc->getText(), $align, array(), false, true );
373 } elseif ( !$file_lc->allowInlineDisplay() && $file_lc->isSafeFile() ) {
374 $icon = $file_lc->iconThumb();
375 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
376 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
382 wfMsgExt( 'fileexists-extension', 'parsemag',
383 $file->getTitle()->getPrefixedText(), $dlink ) .
386 } elseif ( ( substr( $partname , 3, 3 ) == 'px-' ||
substr( $partname , 2, 3 ) == 'px-' )
387 && preg_match( "/[0-9]{2}/" , substr( $partname , 0, 2 ) ) )
389 # Check for filenames like 50px- or 180px-, these are mostly thumbnails
390 $nt_thb = Title
::newFromText( substr( $partname , strpos( $partname , '-' ) +
1 ) . '.' . $rawExtension );
391 $file_thb = wfLocalFile( $nt_thb );
392 if ($file_thb->exists() ) {
393 # Check if an image without leading '180px-' (or similiar) exists
394 $dlink = $sk->linkKnown( $nt_thb );
395 if ( $file_thb->allowInlineDisplay() ) {
396 // FIXME: replace deprecated makeImageLinkObj by link()
397 $dlink2 = $sk->makeImageLinkObj( $nt_thb,
398 wfMsgExt( 'fileexists-thumb', 'parseinline' ),
399 $nt_thb->getText(), $align, array(), false, true );
400 } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) {
401 $icon = $file_thb->iconThumb();
402 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
403 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
409 $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
412 # Image w/o '180px-' does not exists, but we do not like these filenames
413 $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' ,
414 substr( $partname , 0, strpos( $partname , '-' ) +
1 ) ) . '</li>';
418 $filenamePrefixBlacklist = UploadBase
::getFilenamePrefixBlacklist();
420 if(!isset($partname))
422 foreach( $filenamePrefixBlacklist as $prefix ) {
423 if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
424 $warning .= '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $prefix ) . '</li>';
429 if ( $file->wasDeleted() && !$file->exists() ) {
430 # If the file existed before and was deleted, warn the user of this
431 # Don't bother doing so if the file exists now, however
432 $ltitle = SpecialPage
::getTitleFor( 'Log' );
433 $llink = $sk->linkKnown(
435 wfMsgHtml( 'deletionlog' ),
439 'page' => $file->getTitle()->getPrefixedText()
442 $warning .= '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
448 * Get a list of warnings
450 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
451 * @return array list of warning messages
453 static function ajaxGetExistsWarning( $filename ) {
454 $file = wfFindFile( $filename );
456 // Force local file so we have an object to do further checks against
457 // if there isn't an exact match...
458 $file = wfLocalFile( $filename );
462 $exists = UploadBase
::getExistsWarning( $file );
463 $warning = self
::getExistsWarning( $exists );
464 // FIXME: We probably also want the prefix blacklist and the wasdeleted check here
465 if ( $warning !== '' ) {
466 $s = "<ul>$warning</ul>";
473 * Render a preview of a given license for the AJAX preview on upload
475 * @param string $license
478 public static function ajaxGetLicensePreview( $license ) {
479 global $wgParser, $wgUser;
480 $text = '{{' . $license . '}}';
481 $title = Title
::makeTitle( NS_FILE
, 'Sample.jpg' );
482 $options = ParserOptions
::newFromUser( $wgUser );
484 // Expand subst: first, then live templates...
485 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
486 $output = $wgParser->parse( $text, $title, $options );
488 return $output->getText();
492 * Construct the human readable warning message from an array of duplicate files
494 public static function getDupeWarning( $dupes ) {
498 foreach( $dupes as $file ) {
499 $title = $file->getTitle();
500 $msg .= $title->getPrefixedText() .
501 "|" . $title->getText() . "\n";
503 $msg .= "</gallery>";
505 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
506 $wgOut->parse( $msg ) .
515 * Remove a temporarily kept file stashed by saveTempUploadedFile().
519 function unsaveUploadedFile() {
521 $success = $this->mUpload
->unsaveUploadedFile();
523 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
530 /* Interface code starts below this line *
531 * -------------------------------------------------------------- */
535 * @param string $error as HTML
538 function uploadError( $error ) {
540 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
541 $wgOut->addHTML( '<span class="error">' . $error . '</span>' );
545 * There's something wrong with this file, not enough to reject it
546 * totally but we require manual intervention to save it for real.
547 * Stash it away, then present a form asking to confirm or cancel.
549 * @param string $warning as HTML
552 function uploadWarning( $warnings ) {
553 global $wgOut, $wgUser;
554 global $wgUseCopyrightUpload;
556 $this->mSessionKey
= $this->mUpload
->stashSession();
558 if( $this->mSessionKey
=== false ) {
559 # Couldn't save file; an error has been displayed so let's go.
563 $sk = $wgUser->getSkin();
565 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
566 $wgOut->addHTML( '<ul class="warning">' );
567 foreach( $warnings as $warning => $args ) {
569 if( $warning == 'exists' ) {
571 //we should not have produced this warning if the user already acknowledged the destination warning
572 //at any rate I don't see why we should hid this warning if mDestWarningAck has been checked
573 //(it produces an empty warning page when no other warnings are fired)
574 //if ( !$this->mDestWarningAck )
575 $msg = self
::getExistsWarning( $args );
577 } elseif( $warning == 'duplicate' ) {
578 $msg = $this->getDupeWarning( $args );
579 } elseif( $warning == 'duplicate-archive' ) {
580 $titleText = Title
::makeTitle( NS_FILE
, $args )->getPrefixedText();
581 $msg = Xml
::tags( 'li', null, wfMsgExt( 'file-deleted-duplicate', array( 'parseinline' ), array( $titleText ) ) );
582 } elseif( $warning == 'filewasdeleted' ) {
583 $ltitle = SpecialPage
::getTitleFor( 'Log' );
584 $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ),
585 'type=delete&page=' . $args->getPrefixedUrl() );
586 $msg = "\t<li>" . wfMsgWikiHtml( 'filewasdeleted', $llink ) . "</li>\n";
588 if( is_bool( $args ) )
590 elseif( !is_array( $args ) )
591 $args = array( $args );
592 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
595 $wgOut->addHTML( $msg );
598 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
600 if ( $wgUseCopyrightUpload ) {
601 $copyright = Xml
::hidden( 'wpUploadCopyStatus', $this->mCopyrightStatus
) . "\n" .
602 Xml
::hidden( 'wpUploadSource', $this->mCopyrightSource
) . "\n";
607 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
608 'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
609 Xml
::hidden('wpEditToken', $wgUser->editToken()) .
610 Xml
::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
611 Xml
::hidden( 'wpSourceType', 'stash' ) . "\n" .
612 Xml
::hidden( 'wpSessionKey', $this->mSessionKey
) . "\n" .
613 Xml
::hidden( 'wpUploadDescription', $this->mComment
) . "\n" .
614 Xml
::hidden( 'wpLicense', $this->mLicense
) . "\n" .
615 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
) . "\n" .
616 Xml
::hidden( 'wpWatchthis', $this->mWatchthis
) . "\n" .
617 "{$copyright}<br />" .
618 Xml
::submitButton( wfMsg( 'ignorewarning' ), array ( 'name' => 'wpUpload', 'id' => 'wpUpload', 'checked' => 'checked' ) ) . ' ' .
619 Xml
::submitButton( wfMsg( 'reuploaddesc' ), array ( 'name' => 'wpReUpload', 'id' => 'wpReUpload' ) ) .
620 Xml
::closeElement( 'form' ) . "\n"
625 * Displays the main upload form, optionally with a highlighted
626 * error message up at the top.
628 * @param string $msg as HTML
631 function mainUploadForm( $msg='' ) {
632 global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize, $wgEnableFirefogg;
633 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
635 global $wgStylePath, $wgStyleVersion;
636 global $wgEnableJS2system;
638 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
639 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
641 $adc = wfBoolToStr( $useAjaxDestCheck );
642 $alp = wfBoolToStr( $useAjaxLicensePreview );
643 $uef = wfBoolToStr( $wgEnableFirefogg );
644 $autofill = wfBoolToStr( $this->mDesiredDestName
== '' );
647 $wgOut->addScript( "<script type=\"text/javascript\">
648 wgAjaxUploadDestCheck = {$adc};
649 wgAjaxLicensePreview = {$alp};
650 wgEnableFirefogg = {$uef};
651 wgUploadAutoFill = {$autofill};
654 if( $wgEnableJS2system ){
655 //js2version of upload page:
656 $wgOut->addScriptClass( 'uploadPage' );
658 //legacy upload code:
659 $wgOut->addScriptFile( 'upload.js' );
660 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
663 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
665 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
669 if( $this->mDesiredDestName
!= '' ) {
670 $title = Title
::makeTitleSafe( NS_FILE
, $this->mDesiredDestName
);
671 // Show a subtitle link to deleted revisions (to sysops et al only)
672 if( $title instanceof Title
&& ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
674 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
675 array( 'parse', 'replaceafter' ),
676 $wgUser->getSkin()->linkKnown(
677 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
678 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
681 $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
684 // Show the relevant lines from deletion log (for still deleted files only)
685 if( $title instanceof Title
&& $title->isDeletedQuick() && !$title->exists() ) {
686 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
690 $cols = intval($wgUser->getOption( 'cols' ));
692 if( $wgUser->getOption( 'editwidth' ) ) {
693 $width = " style=\"width:100%\"";
699 $sub = wfMsgHtml( 'uploaderror' );
700 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
701 "<span class='error'>{$msg}</span>\n" );
704 $wgOut->addHTML( '<div id="uploadtext">' );
705 $wgOut->addWikiMsg( 'uploadtext', $this->mDesiredDestName
);
706 $wgOut->addHTML( "</div>\n" );
708 # Print a list of allowed file extensions, if so configured. We ignore
709 # MIME type here, it's incomprehensible to most people and too long.
710 global $wgCheckFileExtensions, $wgStrictFileExtensions,
711 $wgFileExtensions, $wgFileBlacklist;
713 $allowedExtensions = '';
714 if( $wgCheckFileExtensions ) {
715 if( $wgStrictFileExtensions ) {
716 # Everything not permitted is banned
718 '<div id="mw-upload-permitted">' .
719 wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
722 # We have to list both preferred and prohibited
724 '<div id="mw-upload-preferred">' .
725 wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
727 '<div id="mw-upload-prohibited">' .
728 wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileExtensions ) ) .
732 # Everything is permitted.
733 $extensionsList = '';
736 # Get the maximum file size from php.ini as $wgMaxUploadSize works for uploads from URL via CURL only
737 # See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize for possible values of upload_max_filesize
738 $val = trim( ini_get( 'upload_max_filesize' ) );
739 $last = strtoupper( ( substr( $val, -1 ) ) );
742 $val2 = substr( $val, 0, -1 ) * 1024 * 1024 * 1024;
745 $val2 = substr( $val, 0, -1 ) * 1024 * 1024;
748 $val2 = substr( $val, 0, -1 ) * 1024;
753 $maxUploadSize = '<div id="mw-upload-maxfilesize">' .
754 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
755 $wgLang->formatSize( $val2 ) ) .
757 //add a hidden filed for upload by url (uses the $wgMaxUploadSize var)
758 if( UploadFromUrl
::isEnabled() ){
759 $maxUploadSize.='<div id="mw-upload-maxfilesize-url" style="display:none">' .
760 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
761 $wgLang->formatSize( $wgMaxUploadSize ) ) .
765 $sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
766 $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
768 $msg = ( $this->mForReUpload
) ?
'filereuploadsummary' : 'fileuploadsummary';
769 $summary = wfMsgExt( $msg, 'parseinline' );
771 $licenses = new Licenses();
772 $license = wfMsgExt( 'license', array( 'parseinline' ) );
773 $nolicense = wfMsgHtml( 'nolicense' );
774 $licenseshtml = $licenses->getHtml();
776 $ulb = wfMsgHtml( 'uploadbtn' );
779 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
781 $encDestName = htmlspecialchars( $this->mDesiredDestName
);
783 $watchChecked = $this->watchCheck() ?
'checked="checked"' : '';
784 # Re-uploads should not need "file exist already" warnings
785 $warningChecked = ($this->mIgnoreWarning ||
$this->mForReUpload
) ?
'checked="checked"' : '';
787 // Prepare form for upload or upload/copy
788 //javascript moved from inline calls to setup:
789 if( UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
790 if($wgEnableJS2system){
792 Xml
::input( 'wpSourceType', false, 'file', array( 'id'=>'wpSourceTypeFile', 'type' => 'radio', 'checked' => 'checked' ) ) .
793 Xml
::input( 'wpUploadFile', 60, false, array( 'id'=>'wpUploadFile', 'type'=>'file', 'tabindex' => '1' ) ) .
794 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
795 Xml
::input( 'wpSourceType', false, 'Url', array( 'id'=>'wpSourceTypeURL', 'type' => 'radio' )) .
796 Xml
::input( 'wpUploadFileURL', 60, false, array( 'id'=>'wpUploadFileURL', 'type' => 'text', 'tabindex' => '1')) .
797 wfMsgHtml( 'upload_source_url' ) ;
799 //@@todo depreciate (not needed once $wgEnableJS2system is turned on)
801 "<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='file' " .
802 "onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" .
803 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
805 "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
806 "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
807 "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
808 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
809 "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='web' " .
810 "onchange='toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\")' />" .
811 "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " .
813 "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" .
814 "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
815 "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' disabled='disabled' />" .
816 wfMsgHtml( 'upload_source_url' ) ;
820 if($wgEnableJS2system){
822 Xml
::input( 'wpUploadFile', 60, false, array( 'id'=>'wpUploadFile', 'type'=>'file', 'tabindex' => '1' ) ) .
823 Xml
::hidden( 'wpSourceType', 'file');
826 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' ".
827 "onchange='fillDestFilename(\"wpUploadFile\")' />" .
828 "<input type='hidden' name='wpSourceType' value='file' />" ;
833 if($wgEnableJS2system){
834 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
836 if ( $useAjaxDestCheck ) {
837 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
838 $destOnkeyup = 'onchange=\'wgUploadWarningObj.checkNow(this.value);\'';
841 # Uploading a new version? If so, the name is fixed.
842 $on = $this->mForReUpload ?
"readonly='readonly'" : "";
844 $encComment = htmlspecialchars( $this->mComment
);
846 //add the wpEditToken
848 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
849 'enctype' => 'multipart/form-data', 'id' => 'mw-upload-form' ) ) .
850 Xml
::hidden('wpEditToken', $wgUser->editToken()) .
851 Xml
::openElement( 'fieldset' ) .
852 Xml
::element( 'legend', null, wfMsg( 'upload' ) ) .
853 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
855 {$this->uploadFormTextTop}
856 <td class='mw-label'>
857 <label for='wpUploadFile'>{$sourcefilename}</label>
859 <td class='mw-input'>
871 <td class='mw-label'>
872 <label for='wpDestFile'>{$destfilename}</label>
874 <td class='mw-input'>"
876 if( $this->mForReUpload
) {
878 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
, array('id'=>'wpDestFile','tabindex'=>2) ) .
886 "<input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
887 value=\"{$encDestName}\" $destOnkeyup />"
896 <td class='mw-label'>
897 <label for='wpUploadDescription'>{$summary}</label>
899 <td class='mw-input'>
900 <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6'
901 cols='{$cols}'{$width}>$encComment</textarea>
902 {$this->uploadFormTextAfterSummary}
908 # Re-uploads should not need license info
909 if ( !$this->mForReUpload
&& $licenseshtml != '' ) {
912 <td class='mw-label'>
913 <label for='wpLicense'>$license</label>
915 <td class='mw-input'>
916 <select name='wpLicense' id='wpLicense' tabindex='4'
917 onchange='licenseSelectorCheck()'>
918 <option value=''>$nolicense</option>
925 if( $useAjaxLicensePreview ) {
928 <td id=\"mw-license-preview\"></td>
935 if ( !$this->mForReUpload
&& $wgUseCopyrightUpload ) {
936 $filestatus = wfMsgExt( 'filestatus', 'escapenoentities' );
937 $copystatus = htmlspecialchars( $this->mCopyrightStatus
);
938 $filesource = wfMsgExt( 'filesource', 'escapenoentities' );
939 $uploadsource = htmlspecialchars( $this->mCopyrightSource
);
942 <td class='mw-label' style='white-space: nowrap;'>
943 <label for='wpUploadCopyStatus'>$filestatus</label></td>
944 <td class='mw-input'>
945 <input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus'
946 value=\"$copystatus\" size='60' />
950 <td class='mw-label'>
951 <label for='wpUploadCopyStatus'>$filesource</label>
953 <td class='mw-input'>
954 <input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus'
955 value=\"$uploadsource\" size='60' />
965 <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
966 <label for='wpWatchthis'>" . wfMsgHtml( 'watchthisupload' ) . "</label>
967 <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' $warningChecked />
968 <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
974 <td class='mw-input'>
975 <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" .
976 $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
981 <td class='mw-input'>"
983 $wgOut->addHTML( '<div class="mw-editTools">' );
984 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
985 $wgOut->addHTML( '</div>' );
989 Xml
::closeElement( 'table' ) .
990 Xml
::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
991 Xml
::hidden( 'wpForReUpload', $this->mForReUpload
, array( 'id' => 'wpForReUpload' ) ) .
992 Xml
::closeElement( 'fieldset' ) .
993 Xml
::closeElement( 'form' )
995 $uploadfooter = wfMsgNoTrans( 'uploadfooter' );
996 if( $uploadfooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadfooter ) ){
997 $wgOut->addWikiText( '<div id="mw-upload-footer-message">' . $uploadfooter . '</div>' );
1001 /* -------------------------------------------------------------- */
1004 * See if we should check the 'watch this page' checkbox on the form
1005 * based on the user's preferences and whether we're being asked
1006 * to create a new file or update an existing one.
1008 * In the case where 'watch edits' is off but 'watch creations' is on,
1009 * we'll leave the box unchecked.
1011 * Note that the page target can be changed *on the form*, so our check
1012 * state can get out of sync.
1014 function watchCheck() {
1016 if( $wgUser->getOption( 'watchdefault' ) ) {
1021 $local = wfLocalFile( $this->mDesiredDestName
);
1022 if( $local && $local->exists() ) {
1023 // We're uploading a new version of an existing file.
1024 // No creation, so don't watch it if we're not already.
1025 return $local->getTitle()->userIsWatching();
1027 // New page should get watched if that's our option.
1028 return $wgUser->getOption( 'watchcreations' );
1033 * Check if a user is the last uploader
1036 * @param string $img, image name
1038 * @deprecated Use UploadBase::userCanReUpload
1040 public static function userCanReUpload( User
$user, $img ) {
1041 wfDeprecated( __METHOD__
);
1043 if( $user->isAllowed( 'reupload' ) )
1044 return true; // non-conditional
1045 if( !$user->isAllowed( 'reupload-own' ) )
1048 $dbr = wfGetDB( DB_SLAVE
);
1049 $row = $dbr->selectRow('image',
1050 /* SELECT */ 'img_user',
1051 /* WHERE */ array( 'img_name' => $img )
1056 return $user->getId() == $row->img_user
;
1060 * Display an error with a wikitext description
1062 function showError( $description ) {
1064 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
1065 $wgOut->setRobotPolicy( "noindex,nofollow" );
1066 $wgOut->setArticleRelated( false );
1067 $wgOut->enableClientCache( false );
1068 $wgOut->addWikiText( $description );
1072 * Get the initial image page text based on a comment and optional file status information
1074 static function getInitialPageText( $comment='', $license='', $copyStatus='', $source='' ) {
1075 global $wgUseCopyrightUpload;
1076 if ( $wgUseCopyrightUpload ) {
1078 if ( $license != '' ) {
1079 $licensetxt = '== ' . wfMsgForContent( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1081 $pageText = '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n" .
1082 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
1084 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
1086 if ( $license != '' ) {
1087 $filedesc = $comment == '' ?
'' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n";
1088 $pageText = $filedesc .
1089 '== ' . wfMsgForContent ( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1091 $pageText = $comment;
1098 * If there are rows in the deletion log for this file, show them,
1099 * along with a nice little note for the user
1101 * @param OutputPage $out
1102 * @param string filename
1104 private function showDeletionLog( $out, $filename ) {
1106 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
1107 $pager = new LogPager( $loglist, 'delete', false, $filename );
1108 if( $pager->getNumRows() > 0 ) {
1109 $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
1110 $out->addWikiMsg( 'upload-wasdeleted' );
1112 $loglist->beginLogEventsList() .
1114 $loglist->endLogEventsList()
1116 $out->addHTML( '</div>' );