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 global $wgUser, $wgRequest;
38 parent
::__construct( 'Upload' );
41 $this->outputHeader();
43 if ( is_null( $request ) ) {
44 $request = $wgRequest;
47 // Guess the desired name from the filename if not provided
48 $this->mDesiredDestName
= $request->getText( 'wpDestFile' );
49 if( !$this->mDesiredDestName
)
50 $this->mDesiredDestName
= $request->getText( 'wpUploadFile' );
52 $this->mIgnoreWarning
= $request->getCheck( 'wpIgnoreWarning' );
53 $this->mComment
= $request->getText( 'wpUploadDescription' );
55 if( !$request->wasPosted() ) {
56 # GET requests just give the main form; no data except destination
57 # filename and description
60 //if it was posted check for the token (no remote POST'ing with user credentials)
61 $token = $request->getVal( 'wpEditToken' );
62 $this->mTokenOk
= $wgUser->matchEditToken( $token );
64 # Placeholders for text injection by hooks (empty per default)
65 $this->uploadFormTextTop
= "";
66 $this->uploadFormTextAfterSummary
= "";
68 $this->mUploadClicked
= $request->getCheck( 'wpUpload' );
70 $this->mLicense
= $request->getText( 'wpLicense' );
71 $this->mCopyrightStatus
= $request->getText( 'wpUploadCopyStatus' );
72 $this->mCopyrightSource
= $request->getText( 'wpUploadSource' );
73 $this->mWatchthis
= $request->getBool( 'wpWatchthis' );
74 $this->mSourceType
= $request->getText( 'wpSourceType' );
75 $this->mDestWarningAck
= $request->getText( 'wpDestFileWarningAck' );
77 $this->mForReUpload
= $request->getBool( 'wpForReUpload' );
79 $this->mReUpload
= $request->getCheck( 'wpReUpload' );
81 $this->mAction
= $request->getVal( 'action' );
82 $this->mUpload
= UploadBase
::createFromRequest( $request );
90 function execute( $par ) {
91 global $wgUser, $wgOut;
92 # Check uploading enabled
93 if( !UploadBase
::isEnabled() ) {
94 $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
98 if( $this->mUpload
) {
99 $permission = $this->mUpload
->isAllowed( $wgUser );
101 $permission = $wgUser->isAllowed( 'upload' ) ?
true : 'upload';
103 if( $permission !== true ) {
104 if( !$wgUser->isLoggedIn() ) {
105 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
107 $wgOut->permissionRequired( $permission );
113 if( $wgUser->isBlocked() ) {
114 $wgOut->blockedPage();
119 $wgOut->readOnlyPage();
122 //check token if uploading or reUploading
123 if( !$this->mTokenOk
&& !$this->mReUpload
&& ($this->mUpload
&& (
124 'submit' == $this->mAction ||
125 $this->mUploadClicked
129 $this->mainUploadForm ( wfMsg( 'session_fail_preview' ) );
134 if( $this->mReUpload
) {
135 // User choose to cancel upload
136 if( !$this->mUpload
->unsaveUploadedFile() ) {
139 # Because it is probably checked and shouldn't be
140 $this->mIgnoreWarning
= false;
141 $this->mainUploadForm();
142 } elseif( $this->mUpload
&& (
143 'submit' == $this->mAction ||
144 $this->mUploadClicked
146 $this->processUpload();
148 $this->mainUploadForm();
152 $this->mUpload
->cleanupTempFile();
157 * Checks are made in SpecialUpload::execute()
159 * FIXME this should really use the standard Status class (instead of associative array)
160 * FIXME would be nice if we refactored this into the upload api.
161 * (the special upload page is not the only response point that needs clean localized error msgs)
165 function processUpload(){
166 global $wgOut, $wgFileExtensions, $wgLang;
167 $details = $this->internalProcessUpload();
168 switch( $details['status'] ) {
169 case UploadBase
::SUCCESS
:
170 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
173 case UploadBase
::BEFORE_PROCESSING
:
174 $this->uploadError( $details['error'] );
176 case UploadBase
::LARGE_FILE_SERVER
:
177 $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
180 case UploadBase
::EMPTY_FILE
:
181 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
184 case UploadBase
::MIN_LENGTH_PARTNAME
:
185 $this->mainUploadForm( wfMsgHtml( 'minlength1' ) );
188 case UploadBase
::ILLEGAL_FILENAME
:
189 $this->uploadError( wfMsgExt( 'illegalfilename',
190 'parseinline', $details['filtered'] ) );
193 case UploadBase
::PROTECTED_PAGE
:
194 $wgOut->showPermissionsErrorPage( $details['permissionserrors'] );
197 case UploadBase
::OVERWRITE_EXISTING_FILE
:
198 $this->uploadError( wfMsgExt( $details['overwrite'],
202 case UploadBase
::FILETYPE_MISSING
:
203 $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
206 case UploadBase
::FILETYPE_BADTYPE
:
207 $finalExt = $details['finalExt'];
209 wfMsgExt( 'filetype-banned-type',
210 array( 'parseinline' ),
211 htmlspecialchars( $finalExt ),
213 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
216 $wgLang->formatNum( count( $wgFileExtensions ) )
221 case UploadBase
::VERIFICATION_ERROR
:
222 unset( $details['status'] );
223 $code = array_shift( $details );
224 $this->uploadError( wfMsgExt( $code, 'parseinline', $details ) );
227 case UploadBase
::UPLOAD_VERIFICATION_ERROR
:
228 $error = $details['error'];
229 $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
232 case UploadBase
::UPLOAD_WARNING
:
233 unset( $details['status'] );
234 $this->uploadWarning( $details );
237 case UploadBase
::INTERNAL_ERROR
:
238 $status = $details['internal'];
239 $this->showError( $wgOut->parse( $status->getWikiText() ) );
243 throw new MWException( __METHOD__
. ": Unknown value `{$details['status']}`" );
248 * Really do the upload
249 * Checks are made in SpecialUpload::execute()
251 * @param array $resultDetails contains result-specific dict of additional values
255 function internalProcessUpload() {
258 if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
260 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
261 return array( 'status' => UploadBase
::BEFORE_PROCESSING
);
265 * If the image is protected, non-sysop users won't be able
266 * to modify it by uploading a new revision.
268 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
269 if( $permErrors !== true ) {
270 return array( 'status' => UploadBase
::PROTECTED_PAGE
, 'permissionserrors' => $permErrors );
273 // Fetch the file if required
274 $status = $this->mUpload
->fetchFile();
275 if( !$status->isOK() ){
276 return array( 'status' =>UploadBase
::BEFORE_PROCESSING
, 'error'=>$status->getWikiText() );
279 // Check whether this is a sane upload
280 $result = $this->mUpload
->verifyUpload();
281 if( $result != UploadBase
::OK
)
284 $this->mLocalFile
= $this->mUpload
->getLocalFile();
286 if( !$this->mIgnoreWarning
) {
287 $warnings = $this->mUpload
->checkWarnings();
289 if( count( $warnings ) ) {
290 $warnings['status'] = UploadBase
::UPLOAD_WARNING
;
297 * Try actually saving the thing...
298 * It will show an error form on failure. No it will not.
300 if( !$this->mForReUpload
) {
301 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
302 $this->mCopyrightStatus
, $this->mCopyrightSource
);
304 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
306 if ( !$status->isGood() ) {
307 return array( 'status' => UploadBase
::INTERNAL_ERROR
, 'internal' => $status );
309 // Success, redirect to description page
310 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
311 return UploadBase
::SUCCESS
;
316 * Do existence checks on a file and produce a warning
317 * This check is static and can be done pre-upload via AJAX
318 * Returns an HTML fragment consisting of one or more LI elements if there is a warning
319 * Returns an empty string if there is no warning
321 static function getExistsWarning( $exists ) {
322 global $wgUser, $wgContLang;
324 if( $exists === false )
328 $align = $wgContLang->isRtl() ?
'left' : 'right';
330 list( $existsType, $file ) = $exists;
332 $sk = $wgUser->getSkin();
334 if( $existsType == 'exists' ) {
336 $dlink = $sk->makeKnownLinkObj( $file->getTitle() );
337 if ( $file->allowInlineDisplay() ) {
338 $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ),
339 $file->getName(), $align, array(), false, true );
340 } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) {
341 $icon = $file->iconThumb();
342 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
343 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
348 $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2;
350 } elseif( $existsType == 'page-exists' ) {
351 $lnk = $sk->makeKnownLinkObj( $file->getTitle(), '', 'redirect=no' );
352 $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>';
353 } elseif ( $existsType == 'exists-normalized' ) {
354 # Check if image with lowercase extension exists.
355 # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
356 $dlink = $sk->linkKnown( $nt_lc );
357 if ( $file_lc->allowInlineDisplay() ) {
358 // FIXME: replace deprecated makeImageLinkObj by link()
359 $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline' ),
360 $nt_lc->getText(), $align, array(), false, true );
361 } elseif ( !$file_lc->allowInlineDisplay() && $file_lc->isSafeFile() ) {
362 $icon = $file_lc->iconThumb();
363 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
364 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
370 wfMsgExt( 'fileexists-extension', 'parsemag',
371 $file->getTitle()->getPrefixedText(), $dlink ) .
374 } elseif ( ( substr( $partname , 3, 3 ) == 'px-' ||
substr( $partname , 2, 3 ) == 'px-' )
375 && preg_match( "/[0-9]{2}/" , substr( $partname , 0, 2 ) ) )
377 # Check for filenames like 50px- or 180px-, these are mostly thumbnails
378 $nt_thb = Title
::newFromText( substr( $partname , strpos( $partname , '-' ) +
1 ) . '.' . $rawExtension );
379 $file_thb = wfLocalFile( $nt_thb );
380 if ($file_thb->exists() ) {
381 # Check if an image without leading '180px-' (or similiar) exists
382 $dlink = $sk->linkKnown( $nt_thb );
383 if ( $file_thb->allowInlineDisplay() ) {
384 // FIXME: replace deprecated makeImageLinkObj by link()
385 $dlink2 = $sk->makeImageLinkObj( $nt_thb,
386 wfMsgExt( 'fileexists-thumb', 'parseinline' ),
387 $nt_thb->getText(), $align, array(), false, true );
388 } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) {
389 $icon = $file_thb->iconThumb();
390 $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' .
391 $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
397 $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
400 # Image w/o '180px-' does not exists, but we do not like these filenames
401 $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' ,
402 substr( $partname , 0, strpos( $partname , '-' ) +
1 ) ) . '</li>';
406 $filenamePrefixBlacklist = UploadBase
::getFilenamePrefixBlacklist();
408 foreach( $filenamePrefixBlacklist as $prefix ) {
409 if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
410 $warning .= '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $prefix ) . '</li>';
415 if ( $file->wasDeleted() && !$file->exists() ) {
416 # If the file existed before and was deleted, warn the user of this
417 # Don't bother doing so if the file exists now, however
418 $ltitle = SpecialPage
::getTitleFor( 'Log' );
419 $llink = $sk->linkKnown(
421 wfMsgHtml( 'deletionlog' ),
425 'page' => $file->getTitle()->getPrefixedText()
428 $warning .= '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
434 * Get a list of warnings
436 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
437 * @return array list of warning messages
439 static function ajaxGetExistsWarning( $filename ) {
440 $file = wfFindFile( $filename );
442 // Force local file so we have an object to do further checks against
443 // if there isn't an exact match...
444 $file = wfLocalFile( $filename );
448 $exists = UploadBase
::getExistsWarning( $file );
449 $warning = self
::getExistsWarning( $exists );
450 // FIXME: We probably also want the prefix blacklist and the wasdeleted check here
451 if ( $warning !== '' ) {
452 $s = "<ul>$warning</ul>";
459 * Render a preview of a given license for the AJAX preview on upload
461 * @param string $license
464 public static function ajaxGetLicensePreview( $license ) {
465 global $wgParser, $wgUser;
466 $text = '{{' . $license . '}}';
467 $title = Title
::makeTitle( NS_FILE
, 'Sample.jpg' );
468 $options = ParserOptions
::newFromUser( $wgUser );
470 // Expand subst: first, then live templates...
471 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
472 $output = $wgParser->parse( $text, $title, $options );
474 return $output->getText();
478 * Construct the human readable warning message from an array of duplicate files
480 public static function getDupeWarning( $dupes ) {
484 foreach( $dupes as $file ) {
485 $title = $file->getTitle();
486 $msg .= $title->getPrefixedText() .
487 "|" . $title->getText() . "\n";
489 $msg .= "</gallery>";
491 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
492 $wgOut->parse( $msg ) .
501 * Remove a temporarily kept file stashed by saveTempUploadedFile().
505 function unsaveUploadedFile() {
507 $success = $this->mUpload
->unsaveUploadedFile();
509 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
516 /* Interface code starts below this line *
517 * -------------------------------------------------------------- */
521 * @param string $error as HTML
524 function uploadError( $error ) {
526 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
527 $wgOut->addHTML( '<span class="error">' . $error . '</span>' );
531 * There's something wrong with this file, not enough to reject it
532 * totally but we require manual intervention to save it for real.
533 * Stash it away, then present a form asking to confirm or cancel.
535 * @param string $warning as HTML
538 function uploadWarning( $warnings ) {
539 global $wgOut, $wgUser;
540 global $wgUseCopyrightUpload;
542 $this->mSessionKey
= $this->mUpload
->stashSession();
544 if( $sessionData === false ) {
545 # Couldn't save file; an error has been displayed so let's go.
549 $sk = $wgUser->getSkin();
551 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
552 $wgOut->addHTML( '<ul class="warning">' );
553 foreach( $warnings as $warning => $args ) {
555 if( $warning == 'exists' ) {
557 //we should not have produced this warning if the user already acknowledged the destination warning
558 //at any rate I don't see why we should hid this warning if mDestWarningAck has been checked
559 //(it produces an empty warning page when no other warnings are fired)
560 //if ( !$this->mDestWarningAck )
561 $msg = self
::getExistsWarning( $args );
563 } elseif( $warning == 'duplicate' ) {
564 $msg = $this->getDupeWarning( $args );
565 } elseif( $warning == 'duplicate-archive' ) {
566 $titleText = Title
::makeTitle( NS_FILE
, $args )->getPrefixedText();
567 $msg = Xml
::tags( 'li', null, wfMsgExt( 'file-deleted-duplicate', array( 'parseinline' ), array( $titleText ) ) );
568 } elseif( $warning == 'filewasdeleted' ) {
569 $ltitle = SpecialPage
::getTitleFor( 'Log' );
570 $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ),
571 'type=delete&page=' . $args->getPrefixedUrl() );
572 $msg = "\t<li>" . wfMsgWikiHtml( 'filewasdeleted', $llink ) . "</li>\n";
574 if( is_bool( $args ) )
576 elseif( !is_array( $args ) )
577 $args = array( $args );
578 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
581 $wgOut->addHTML( $msg );
584 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
586 if ( $wgUseCopyrightUpload ) {
587 $copyright = Xml
::hidden( 'wpUploadCopyStatus', $this->mCopyrightStatus
) . "\n" .
588 Xml
::hidden( 'wpUploadSource', $this->mCopyrightSource
) . "\n";
592 //add the wpEditToken
593 $token = htmlspecialchars( $wgUser->editToken() );
595 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
596 'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
597 Xml
::hidden('wpEditToken', $token) .
598 Xml
::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
599 Xml
::hidden( 'wpSourceType', 'stash' ) . "\n" .
600 Xml
::hidden( 'wpSessionKey', $this->mSessionKey
) . "\n" .
601 Xml
::hidden( 'wpUploadDescription', $this->mComment
) . "\n" .
602 Xml
::hidden( 'wpLicense', $this->mLicense
) . "\n" .
603 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
) . "\n" .
604 Xml
::hidden( 'wpWatchthis', $this->mWatchthis
) . "\n" .
605 "{$copyright}<br />" .
606 Xml
::submitButton( wfMsg( 'ignorewarning' ), array ( 'name' => 'wpUpload', 'id' => 'wpUpload', 'checked' => 'checked' ) ) . ' ' .
607 Xml
::submitButton( wfMsg( 'reuploaddesc' ), array ( 'name' => 'wpReUpload', 'id' => 'wpReUpload' ) ) .
608 Xml
::closeElement( 'form' ) . "\n"
613 * Displays the main upload form, optionally with a highlighted
614 * error message up at the top.
616 * @param string $msg as HTML
619 function mainUploadForm( $msg='' ) {
620 global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize, $wgEnableFirefogg;
621 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
623 global $wgStylePath, $wgStyleVersion;
624 global $wgEnableJS2system;
626 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
627 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
629 $adc = wfBoolToStr( $useAjaxDestCheck );
630 $alp = wfBoolToStr( $useAjaxLicensePreview );
631 $uef = wfBoolToStr( $wgEnableFirefogg );
632 $autofill = wfBoolToStr( $this->mDesiredDestName
== '' );
635 $wgOut->addScript( "<script type=\"text/javascript\">
636 wgAjaxUploadDestCheck = {$adc};
637 wgAjaxLicensePreview = {$alp};
638 wgEnableFirefogg = {$uef};
639 wgUploadAutoFill = {$autofill};
642 if( $wgEnableJS2system ){
643 //js2version of upload page:
644 $wgOut->addScriptClass( 'uploadPage' );
646 //legacy upload code:
647 $wgOut->addScriptFile( 'upload.js' );
648 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
651 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
653 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
657 if( $this->mDesiredDestName
) {
658 $title = Title
::makeTitleSafe( NS_FILE
, $this->mDesiredDestName
);
659 // Show a subtitle link to deleted revisions (to sysops et al only)
660 if( $title instanceof Title
&& ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
662 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
663 array( 'parse', 'replaceafter' ),
664 $wgUser->getSkin()->makeKnownLinkObj(
665 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
666 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
669 $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
672 // Show the relevant lines from deletion log (for still deleted files only)
673 if( $title instanceof Title
&& $title->isDeletedQuick() && !$title->exists() ) {
674 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
678 $cols = intval($wgUser->getOption( 'cols' ));
680 if( $wgUser->getOption( 'editwidth' ) ) {
681 $width = " style=\"width:100%\"";
687 $sub = wfMsgHtml( 'uploaderror' );
688 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
689 "<span class='error'>{$msg}</span>\n" );
692 $wgOut->addHTML( '<div id="uploadtext">' );
693 $wgOut->addWikiMsg( 'uploadtext', $this->mDesiredDestName
);
694 $wgOut->addHTML( "</div>\n" );
696 # Print a list of allowed file extensions, if so configured. We ignore
697 # MIME type here, it's incomprehensible to most people and too long.
698 global $wgCheckFileExtensions, $wgStrictFileExtensions,
699 $wgFileExtensions, $wgFileBlacklist;
701 $allowedExtensions = '';
702 if( $wgCheckFileExtensions ) {
703 $delim = wfMsgExt( 'comma-separator', array( 'escapenoentities' ) );
704 if( $wgStrictFileExtensions ) {
705 # Everything not permitted is banned
707 '<div id="mw-upload-permitted">' .
708 wfMsgWikiHtml( 'upload-permitted', implode( $wgFileExtensions, $delim ) ) .
711 # We have to list both preferred and prohibited
713 '<div id="mw-upload-preferred">' .
714 wfMsgWikiHtml( 'upload-preferred', implode( $wgFileExtensions, $delim ) ) .
716 '<div id="mw-upload-prohibited">' .
717 wfMsgWikiHtml( 'upload-prohibited', implode( $wgFileBlacklist, $delim ) ) .
721 # Everything is permitted.
722 $extensionsList = '';
725 # Get the maximum file size from php.ini as $wgMaxUploadSize works for uploads from URL via CURL only
726 # See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize for possible values of upload_max_filesize
727 $val = trim( ini_get( 'upload_max_filesize' ) );
728 $last = strtoupper( ( substr( $val, -1 ) ) );
731 $val2 = substr( $val, 0, -1 ) * 1024 * 1024 * 1024;
734 $val2 = substr( $val, 0, -1 ) * 1024 * 1024;
737 $val2 = substr( $val, 0, -1 ) * 1024;
742 $maxUploadSize = '<div id="mw-upload-maxfilesize">' .
743 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
744 $wgLang->formatSize( $val2 ) ) .
746 //add a hidden filed for upload by url (uses the $wgMaxUploadSize var)
747 if( UploadFromUrl
::isEnabled() ){
748 $maxUploadSize.='<div id="mw-upload-maxfilesize-url" style="display:none">' .
749 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
750 $wgLang->formatSize( $wgMaxUploadSize ) ) .
754 $sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
755 $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
757 $msg = ( $this->mForReUpload
) ?
'filereuploadsummary' : 'fileuploadsummary';
758 $summary = wfMsgExt( $msg, 'parseinline' );
760 $licenses = new Licenses();
761 $license = wfMsgExt( 'license', array( 'parseinline' ) );
762 $nolicense = wfMsgHtml( 'nolicense' );
763 $licenseshtml = $licenses->getHtml();
765 $ulb = wfMsgHtml( 'uploadbtn' );
768 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
770 $encDestName = htmlspecialchars( $this->mDesiredDestName
);
772 $watchChecked = $this->watchCheck() ?
'checked="checked"' : '';
773 # Re-uploads should not need "file exist already" warnings
774 $warningChecked = ($this->mIgnoreWarning ||
$this->mForReUpload
) ?
'checked="checked"' : '';
776 // Prepare form for upload or upload/copy
777 //javascript moved from inline calls to setup:
778 if( UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
779 if($wgEnableJS2system){
781 Xml
::input( 'wpSourceType', false, 'file', array( 'id'=>'wpSourceTypeFile', 'type' => 'radio', 'checked' => 'checked' ) ) .
782 Xml
::input( 'wpUploadFile', 60, false, array( 'id'=>'wpUploadFile', 'type'=>'file', 'tabindex' => '1' ) ) .
783 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
784 Xml
::input( 'wpSourceType', false, 'Url', array( 'id'=>'wpSourceTypeURL', 'type' => 'radio' )) .
785 Xml
::input( 'wpUploadFileURL', 60, false, array( 'id'=>'wpUploadFileURL', 'type' => 'text', 'tabindex' => '1')) .
786 wfMsgHtml( 'upload_source_url' ) ;
788 //@@todo depreciate (not needed once $wgEnableJS2system is turned on)
790 "<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='file' " .
791 "onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" .
792 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
794 "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
795 "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
796 "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
797 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
798 "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='Url' " .
799 "onchange='toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\")' />" .
800 "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " .
802 "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" .
803 "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
804 "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' disabled='disabled' />" .
805 wfMsgHtml( 'upload_source_url' ) ;
810 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' />" .
811 "<input type='hidden' name='wpSourceType' value='upload' />" ;
814 if ( $useAjaxDestCheck ) {
815 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
821 # Uploading a new version? If so, the name is fixed.
822 $on = $this->mForReUpload ?
"readonly='readonly'" : "";
824 $encComment = htmlspecialchars( $this->mComment
);
826 //add the wpEditToken
827 $token = htmlspecialchars( $wgUser->editToken() );
829 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
830 'enctype' => 'multipart/form-data', 'id' => 'mw-upload-form' ) ) .
831 Xml
::hidden('wpEditToken', $token) .
832 Xml
::openElement( 'fieldset' ) .
833 Xml
::element( 'legend', null, wfMsg( 'upload' ) ) .
834 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
836 {$this->uploadFormTextTop}
837 <td class='mw-label'>
838 <label for='wpUploadFile'>{$sourcefilename}</label>
840 <td class='mw-input'>
852 <td class='mw-label'>
853 <label for='wpDestFile'>{$destfilename}</label>
855 <td class='mw-input'>"
857 if( $this->mForReUpload
) {
859 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
, array('id'=>'wpDestFile','tabindex'=>2) ) .
867 "<input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
868 value=\"{$encDestName}\" $destOnkeyup />"
877 <td class='mw-label'>
878 <label for='wpUploadDescription'>{$summary}</label>
880 <td class='mw-input'>
881 <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6'
882 cols='{$cols}'{$width}>$encComment</textarea>
883 {$this->uploadFormTextAfterSummary}
889 # Re-uploads should not need license info
890 if ( !$this->mForReUpload
&& $licenseshtml != '' ) {
893 <td class='mw-label'>
894 <label for='wpLicense'>$license</label>
896 <td class='mw-input'>
897 <select name='wpLicense' id='wpLicense' tabindex='4'
898 onchange='licenseSelectorCheck()'>
899 <option value=''>$nolicense</option>
906 if( $useAjaxLicensePreview ) {
909 <td id=\"mw-license-preview\"></td>
916 if ( !$this->mForReUpload
&& $wgUseCopyrightUpload ) {
917 $filestatus = wfMsgExt( 'filestatus', 'escapenoentities' );
918 $copystatus = htmlspecialchars( $this->mCopyrightStatus
);
919 $filesource = wfMsgExt( 'filesource', 'escapenoentities' );
920 $uploadsource = htmlspecialchars( $this->mCopyrightSource
);
923 <td class='mw-label' style='white-space: nowrap;'>
924 <label for='wpUploadCopyStatus'>$filestatus</label></td>
925 <td class='mw-input'>
926 <input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus'
927 value=\"$copystatus\" size='60' />
931 <td class='mw-label'>
932 <label for='wpUploadCopyStatus'>$filesource</label>
934 <td class='mw-input'>
935 <input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus'
936 value=\"$uploadsource\" size='60' />
946 <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
947 <label for='wpWatchthis'>" . wfMsgHtml( 'watchthisupload' ) . "</label>
948 <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' $warningChecked />
949 <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
955 <td class='mw-input'>
956 <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" .
957 $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
962 <td class='mw-input'>"
964 $wgOut->addHTML( '<div class="mw-editTools">' );
965 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
966 $wgOut->addHTML( '</div>' );
970 Xml
::closeElement( 'table' ) .
971 Xml
::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
972 Xml
::hidden( 'wpForReUpload', $this->mForReUpload
, array( 'id' => 'wpForReUpload' ) ) .
973 Xml
::closeElement( 'fieldset' ) .
974 Xml
::closeElement( 'form' )
976 $uploadfooter = wfMsgNoTrans( 'uploadfooter' );
977 if( $uploadfooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadfooter ) ){
978 $wgOut->addWikiText( '<div id="mw-upload-footer-message">' . $uploadfooter . '</div>' );
982 /* -------------------------------------------------------------- */
985 * See if we should check the 'watch this page' checkbox on the form
986 * based on the user's preferences and whether we're being asked
987 * to create a new file or update an existing one.
989 * In the case where 'watch edits' is off but 'watch creations' is on,
990 * we'll leave the box unchecked.
992 * Note that the page target can be changed *on the form*, so our check
993 * state can get out of sync.
995 function watchCheck() {
997 if( $wgUser->getOption( 'watchdefault' ) ) {
1002 $local = wfLocalFile( $this->mDesiredDestName
);
1003 if( $local && $local->exists() ) {
1004 // We're uploading a new version of an existing file.
1005 // No creation, so don't watch it if we're not already.
1006 return $local->getTitle()->userIsWatching();
1008 // New page should get watched if that's our option.
1009 return $wgUser->getOption( 'watchcreations' );
1014 * Check if a user is the last uploader
1017 * @param string $img, image name
1019 * @deprecated Use UploadBase::userCanReUpload
1021 public static function userCanReUpload( User
$user, $img ) {
1022 wfDeprecated( __METHOD__
);
1024 if( $user->isAllowed( 'reupload' ) )
1025 return true; // non-conditional
1026 if( !$user->isAllowed( 'reupload-own' ) )
1029 $dbr = wfGetDB( DB_SLAVE
);
1030 $row = $dbr->selectRow('image',
1031 /* SELECT */ 'img_user',
1032 /* WHERE */ array( 'img_name' => $img )
1037 return $user->getId() == $row->img_user
;
1041 * Display an error with a wikitext description
1043 function showError( $description ) {
1045 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
1046 $wgOut->setRobotPolicy( "noindex,nofollow" );
1047 $wgOut->setArticleRelated( false );
1048 $wgOut->enableClientCache( false );
1049 $wgOut->addWikiText( $description );
1053 * Get the initial image page text based on a comment and optional file status information
1055 static function getInitialPageText( $comment='', $license='', $copyStatus='', $source='' ) {
1056 global $wgUseCopyrightUpload;
1057 if ( $wgUseCopyrightUpload ) {
1058 if ( $license != '' ) {
1059 $licensetxt = '== ' . wfMsgForContent( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1061 $pageText = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n" .
1062 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
1064 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
1066 if ( $license != '' ) {
1067 $filedesc = $comment == '' ?
'' : '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $comment . "\n";
1068 $pageText = $filedesc .
1069 '== ' . wfMsgForContent ( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1071 $pageText = $comment;
1078 * If there are rows in the deletion log for this file, show them,
1079 * along with a nice little note for the user
1081 * @param OutputPage $out
1082 * @param string filename
1084 private function showDeletionLog( $out, $filename ) {
1086 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
1087 $pager = new LogPager( $loglist, 'delete', false, $filename );
1088 if( $pager->getNumRows() > 0 ) {
1089 $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
1090 $out->addWikiMsg( 'upload-wasdeleted' );
1092 $loglist->beginLogEventsList() .
1094 $loglist->endLogEventsList()
1096 $out->addHTML( '</div>' );