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->mForReUpload
= $request->getBool( 'wpForReUpload' ); // updating a file
54 $this->mIgnoreWarning
= $request->getCheck( 'wpIgnoreWarning' );
55 $this->mComment
= $request->getText( 'wpUploadDescription' );
57 if( !$request->wasPosted() ) {
58 # GET requests just give the main form; no data except destination
59 # filename and description
63 # Placeholders for text injection by hooks (empty per default)
64 $this->uploadFormTextTop
= "";
65 $this->uploadFormTextAfterSummary
= "";
67 $this->mUploadClicked
= $request->getCheck( 'wpUpload' );
69 $this->mLicense
= $request->getText( 'wpLicense' );
70 $this->mCopyrightStatus
= $request->getText( 'wpUploadCopyStatus' );
71 $this->mCopyrightSource
= $request->getText( 'wpUploadSource' );
72 $this->mWatchthis
= $request->getBool( 'wpWatchthis' );
73 $this->mSourceType
= $request->getVal( 'wpSourceType', 'file' );
74 $this->mDestWarningAck
= $request->getText( 'wpDestFileWarningAck' );
76 $this->mReUpload
= $request->getCheck( 'wpReUpload' ); // retrying upload
78 $this->mAction
= $request->getVal( 'action' );
79 $this->mUpload
= UploadBase
::createFromRequest( $request );
81 // If it was posted check for the token (no remote POST'ing with user credentials)
82 $token = $request->getVal( 'wpEditToken' );
83 if( $this->mSourceType
== 'file' && $token == null ) {
84 // Skip token check for file uploads as that can't be faked via JS...
85 // Some client-side tools don't expect to need to send wpEditToken
86 // with their submissions, as that's new in 1.16.
87 $this->mTokenOk
= true;
89 $this->mTokenOk
= $wgUser->matchEditToken( $token );
93 public function userCanExecute( $user ) {
94 return UploadBase
::isEnabled() && parent
::userCanExecute( $user );
101 function execute( $par ) {
102 global $wgUser, $wgOut, $wgRequest;
105 $this->outputHeader();
109 # Check uploading enabled
110 if( !UploadBase
::isEnabled() ) {
111 $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
116 global $wgGroupPermissions;
117 if( !$wgUser->isAllowed( 'upload' ) ) {
118 if( !$wgUser->isLoggedIn() && ( $wgGroupPermissions['user']['upload']
119 ||
$wgGroupPermissions['autoconfirmed']['upload'] ) ) {
120 // Custom message if logged-in users without any special rights can upload
121 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
123 $wgOut->permissionRequired( 'upload' );
129 if( $wgUser->isBlocked() ) {
130 $wgOut->blockedPage();
135 $wgOut->readOnlyPage();
138 //check token if uploading or reUploading
139 if( !$this->mTokenOk
&& !$this->mReUpload
&& ($this->mUpload
&& (
140 'submit' == $this->mAction ||
$this->mUploadClicked
) ) )
142 $this->mainUploadForm ( wfMsgExt( 'session_fail_preview', 'parseinline' ) );
147 if( $this->mReUpload
&& $this->mUpload
) {
148 // User choose to cancel upload
149 if( !$this->mUpload
->unsaveUploadedFile() ) {
152 # Because it is probably checked and shouldn't be
153 $this->mIgnoreWarning
= false;
154 $this->mainUploadForm();
155 } elseif( $this->mUpload
&& (
156 'submit' == $this->mAction ||
157 $this->mUploadClicked
159 $this->processUpload();
161 $this->mainUploadForm();
165 $this->mUpload
->cleanupTempFile();
170 * Checks are made in SpecialUpload::execute()
172 * FIXME this should really use the standard Status class (instead of associative array)
173 * FIXME would be nice if we refactored this into the upload api.
174 * (the special upload page is not the only response point that needs clean localized error msgs)
178 function processUpload() {
179 global $wgOut, $wgFileExtensions, $wgLang;
180 $details = $this->internalProcessUpload();
181 switch( $details['status'] ) {
182 case UploadBase
::SUCCESS
:
183 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
186 case UploadBase
::BEFORE_PROCESSING
:
187 $this->uploadError( $details['error'] );
189 case UploadBase
::LARGE_FILE_SERVER
:
190 $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
193 case UploadBase
::EMPTY_FILE
:
194 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
197 case UploadBase
::MIN_LENGTH_PARTNAME
:
198 $this->mainUploadForm( wfMsgHtml( 'minlength1' ) );
201 case UploadBase
::ILLEGAL_FILENAME
:
202 $this->uploadError( wfMsgExt( 'illegalfilename',
203 'parseinline', $details['filtered'] ) );
206 case UploadBase
::PROTECTED_PAGE
:
207 $wgOut->showPermissionsErrorPage( $details['permissionserrors'] );
210 case UploadBase
::OVERWRITE_EXISTING_FILE
:
211 $this->uploadError( wfMsgExt( $details['overwrite'],
215 case UploadBase
::FILETYPE_MISSING
:
216 $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
219 case UploadBase
::FILETYPE_BADTYPE
:
220 $finalExt = $details['finalExt'];
222 wfMsgExt( 'filetype-banned-type',
223 array( 'parseinline' ),
224 htmlspecialchars( $finalExt ),
226 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
229 $wgLang->formatNum( count( $wgFileExtensions ) )
234 case UploadBase
::VERIFICATION_ERROR
:
235 unset( $details['status'] );
236 $code = array_shift( $details['details'] );
237 $this->uploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
240 case UploadBase
::UPLOAD_VERIFICATION_ERROR
:
241 $error = $details['error'];
242 $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
245 case UploadBase
::UPLOAD_WARNING
:
246 unset( $details['status'] );
247 $this->uploadWarning( $details );
250 case UploadBase
::INTERNAL_ERROR
:
251 $status = $details['internal'];
252 $this->showError( $wgOut->parse( $status->getWikiText() ) );
256 throw new MWException( __METHOD__
. ": Unknown value `{$details['status']}`" );
261 * Really do the upload
262 * Checks are made in SpecialUpload::execute()
264 * @param array $resultDetails contains result-specific dict of additional values
268 function internalProcessUpload() {
271 if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
273 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
274 return array( 'status' => UploadBase
::BEFORE_PROCESSING
);
278 * If the image is protected, non-sysop users won't be able
279 * to modify it by uploading a new revision.
281 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
282 if( $permErrors !== true ) {
283 return array( 'status' => UploadBase
::PROTECTED_PAGE
, 'permissionserrors' => $permErrors );
286 // Fetch the file if required
287 $status = $this->mUpload
->fetchFile();
288 if( !$status->isOK() ) {
289 return array( 'status' => UploadBase
::BEFORE_PROCESSING
, 'error'=> $status->getWikiText() );
292 // Check whether this is a sane upload
293 $result = $this->mUpload
->verifyUpload();
294 if( $result['status'] != UploadBase
::OK
)
297 $this->mLocalFile
= $this->mUpload
->getLocalFile();
299 if( !$this->mIgnoreWarning
) {
300 $warnings = $this->mUpload
->checkWarnings();
302 if( count( $warnings ) ) {
303 $warnings['status'] = UploadBase
::UPLOAD_WARNING
;
310 * Try actually saving the thing...
311 * It will show an error form on failure. No it will not.
313 if( !$this->mForReUpload
) {
314 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
315 $this->mCopyrightStatus
, $this->mCopyrightSource
);
319 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
321 if ( !$status->isGood() ) {
322 return array( 'status' => UploadBase
::INTERNAL_ERROR
, 'internal' => $status );
324 // Success, redirect to description page
325 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
326 return UploadBase
::SUCCESS
;
331 * Formats a result of UploadBase::getExistsWarning as HTML
332 * This check is static and can be done pre-upload via AJAX
334 * @param array $exists The result of UploadBase::getExistsWarning
335 * @return string Empty string if there is no warning or an HTML fragment
336 * consisting of one or more <li> elements if there is a warning.
338 public static function getExistsWarning( $exists ) {
339 global $wgUser, $wgContLang;
344 $file = $exists['file'];
345 $filename = $file->getTitle()->getPrefixedText();
348 $sk = $wgUser->getSkin();
350 if( $exists['warning'] == 'exists' ) {
352 $warning[] = '<li>' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '</li>';
353 } elseif( $exists['warning'] == 'page-exists' ) {
354 // Page exists but file does not
355 $warning[] = '<li>' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '</li>';
356 } elseif ( $exists['warning'] == 'exists-normalized' ) {
357 $warning[] = '<li>' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename,
358 $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '</li>';
359 } elseif ( $exists['warning'] == 'thumb' ) {
360 // Swapped argument order compared with other messages for backwards compatibility
361 $warning[] = '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline',
362 $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '</li>';
363 } elseif ( $exists['warning'] == 'thumb-name' ) {
364 # Image w/o '180px-' does not exists, but we do not like these filenames
365 $name = $file->getName();
366 $badPart = substr( $name, 0, strpos( $name, '-' ) +
1 );
367 $warning[] = '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '</li>';
368 } elseif ( $exists['warning'] == 'bad-prefix' ) {
369 $warning[] = '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '</li>';
370 } elseif ( $exists['warning'] == 'was-deleted' ) {
371 # If the file existed before and was deleted, warn the user of this
372 $ltitle = SpecialPage
::getTitleFor( 'Log' );
373 $llink = $sk->linkKnown(
375 wfMsgHtml( 'deletionlog' ),
382 $warning[] = '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
385 return implode( "\n", $warning );
389 * Get a list of warnings
391 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
392 * @return array list of warning messages
394 static function ajaxGetExistsWarning( $filename ) {
395 $file = wfFindFile( $filename );
397 // Force local file so we have an object to do further checks against
398 // if there isn't an exact match...
399 $file = wfLocalFile( $filename );
403 $exists = UploadBase
::getExistsWarning( $file );
404 $warning = self
::getExistsWarning( $exists );
405 // FIXME: We probably also want the prefix blacklist and the wasdeleted check here
406 if ( $warning !== '' ) {
407 $s = "<ul>$warning</ul>";
414 * Render a preview of a given license for the AJAX preview on upload
416 * @param string $license
419 public static function ajaxGetLicensePreview( $license ) {
420 global $wgParser, $wgUser;
421 $text = '{{' . $license . '}}';
422 $title = Title
::makeTitle( NS_FILE
, 'Sample.jpg' );
423 $options = ParserOptions
::newFromUser( $wgUser );
425 // Expand subst: first, then live templates...
426 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
427 $output = $wgParser->parse( $text, $title, $options );
429 return $output->getText();
433 * Construct the human readable warning message from an array of duplicate files
435 public static function getDupeWarning( $dupes ) {
439 foreach( $dupes as $file ) {
440 $title = $file->getTitle();
441 $msg .= $title->getPrefixedText() .
442 "|" . $title->getText() . "\n";
444 $msg .= "</gallery>";
446 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
447 $wgOut->parse( $msg ) .
456 * Remove a temporarily kept file stashed by saveTempUploadedFile().
460 function unsaveUploadedFile() {
462 $success = $this->mUpload
->unsaveUploadedFile();
464 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
471 /* Interface code starts below this line *
472 * -------------------------------------------------------------- */
476 * @param string $error as HTML
479 function uploadError( $error ) {
481 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
482 $wgOut->addHTML( '<span class="error">' . $error . '</span>' );
486 * There's something wrong with this file, not enough to reject it
487 * totally but we require manual intervention to save it for real.
488 * Stash it away, then present a form asking to confirm or cancel.
490 * @param string $warning as HTML
493 function uploadWarning( $warnings ) {
494 global $wgOut, $wgUser;
495 global $wgUseCopyrightUpload;
497 $this->mSessionKey
= $this->mUpload
->stashSession();
499 if( $this->mSessionKey
=== false ) {
500 # Couldn't save file; an error has been displayed so let's go.
504 $sk = $wgUser->getSkin();
506 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
507 $wgOut->addHTML( '<ul class="warning">' );
508 foreach( $warnings as $warning => $args ) {
510 if( $warning == 'exists' ) {
512 //we should not have produced this warning if the user already acknowledged the destination warning
513 //at any rate I don't see why we should hid this warning if mDestWarningAck has been checked
514 //(it produces an empty warning page when no other warnings are fired)
515 //if ( !$this->mDestWarningAck )
516 $msg = self
::getExistsWarning( $args );
518 } elseif( $warning == 'duplicate' ) {
519 $msg = $this->getDupeWarning( $args );
520 } elseif( $warning == 'duplicate-archive' ) {
521 $titleText = Title
::makeTitle( NS_FILE
, $args )->getPrefixedText();
522 $msg = Xml
::tags( 'li', null, wfMsgExt( 'file-deleted-duplicate', array( 'parseinline' ), array( $titleText ) ) );
524 if( is_bool( $args ) )
526 elseif( !is_array( $args ) )
527 $args = array( $args );
528 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
531 $wgOut->addHTML( $msg );
534 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
536 if ( $wgUseCopyrightUpload ) {
537 $copyright = Xml
::hidden( 'wpUploadCopyStatus', $this->mCopyrightStatus
) . "\n" .
538 Xml
::hidden( 'wpUploadSource', $this->mCopyrightSource
) . "\n";
543 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
544 'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
545 Xml
::hidden('wpEditToken', $wgUser->editToken(), array("id" => 'wpEditToken')) .
546 Xml
::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
547 Xml
::hidden( 'wpSourceType', 'stash' ) . "\n" .
548 Xml
::hidden( 'wpSessionKey', $this->mSessionKey
) . "\n" .
549 Xml
::hidden( 'wpUploadDescription', $this->mComment
) . "\n" .
550 Xml
::hidden( 'wpLicense', $this->mLicense
) . "\n" .
551 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
) . "\n" .
552 Xml
::hidden( 'wpWatchthis', $this->mWatchthis
) . "\n" .
553 "{$copyright}<br />" .
554 Xml
::submitButton( wfMsg( 'ignorewarning' ), array ( 'name' => 'wpUpload', 'id' => 'wpUpload', 'checked' => 'checked' ) ) . ' ' .
555 Xml
::submitButton( wfMsg( 'reuploaddesc' ), array ( 'name' => 'wpReUpload', 'id' => 'wpReUpload' ) ) .
556 Xml
::closeElement( 'form' ) . "\n"
561 * Displays the main upload form, optionally with a highlighted
562 * error message up at the top.
564 * @param string $msg as HTML
567 function mainUploadForm( $msg='' ) {
568 global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize, $wgEnableFirefogg;
569 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
571 global $wgStylePath, $wgStyleVersion;
572 global $wgEnableJS2system;
574 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
575 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
577 $adc = wfBoolToStr( $useAjaxDestCheck );
578 $alp = wfBoolToStr( $useAjaxLicensePreview );
579 $uef = wfBoolToStr( $wgEnableFirefogg );
580 $autofill = wfBoolToStr( $this->mDesiredDestName
== '' );
583 $wgOut->addScript( "<script type=\"text/javascript\">
584 wgAjaxUploadDestCheck = {$adc};
585 wgAjaxLicensePreview = {$alp};
586 wgEnableFirefogg = {$uef};
587 wgUploadAutoFill = {$autofill};
590 if( $wgEnableJS2system ) {
591 //js2version of upload page:
592 $wgOut->addScriptClass( 'uploadPage' );
594 //legacy upload code:
595 $wgOut->addScriptFile( 'upload.js' );
596 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
599 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
601 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
605 if( $this->mDesiredDestName
!= '' ) {
606 $title = Title
::makeTitleSafe( NS_FILE
, $this->mDesiredDestName
);
607 // Show a subtitle link to deleted revisions (to sysops et al only)
608 if( $title instanceof Title
&& ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
610 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
611 array( 'parse', 'replaceafter' ),
612 $wgUser->getSkin()->linkKnown(
613 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
614 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
617 $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
620 // Show the relevant lines from deletion log (for still deleted files only)
621 if( $title instanceof Title
&& $title->isDeletedQuick() && !$title->exists() ) {
622 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
626 $cols = intval($wgUser->getOption( 'cols' ));
628 if( $wgUser->getOption( 'editwidth' ) ) {
629 $width = " style=\"width:100%\"";
635 $sub = wfMsgHtml( 'uploaderror' );
636 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
637 "<span class='error'>{$msg}</span>\n" );
640 $wgOut->addHTML( '<div id="uploadtext">' );
641 $wgOut->addWikiMsg( 'uploadtext', $this->mDesiredDestName
);
642 $wgOut->addHTML( "</div>\n" );
644 # Print a list of allowed file extensions, if so configured. We ignore
645 # MIME type here, it's incomprehensible to most people and too long.
646 global $wgCheckFileExtensions, $wgStrictFileExtensions,
647 $wgFileExtensions, $wgFileBlacklist;
649 $allowedExtensions = '';
650 if( $wgCheckFileExtensions ) {
651 if( $wgStrictFileExtensions ) {
652 # Everything not permitted is banned
654 '<div id="mw-upload-permitted">' .
655 wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
658 # We have to list both preferred and prohibited
660 '<div id="mw-upload-preferred">' .
661 wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
663 '<div id="mw-upload-prohibited">' .
664 wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileExtensions ) ) .
668 # Everything is permitted.
669 $extensionsList = '';
672 # Get the maximum file size from php.ini as $wgMaxUploadSize works for uploads from URL via CURL only
673 # See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize for possible values of upload_max_filesize
674 $val = wfShorthandToInteger( ini_get( 'upload_max_filesize' ) );
675 $maxUploadSize = '<div id="mw-upload-maxfilesize">' .
676 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
677 $wgLang->formatSize( $val ) ) .
679 //add a hidden filed for upload by url (uses the $wgMaxUploadSize var)
680 if( UploadFromUrl
::isEnabled() ) {
681 $maxUploadSize.='<div id="mw-upload-maxfilesize-url" style="display:none">' .
682 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
683 $wgLang->formatSize( $wgMaxUploadSize ) ) .
687 $sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
688 $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
690 $msg = ( $this->mForReUpload
) ?
'filereuploadsummary' : 'fileuploadsummary';
691 $summary = wfMsgExt( $msg, 'parseinline' );
693 $licenses = new Licenses();
694 $license = wfMsgExt( 'license', array( 'parseinline' ) );
695 $nolicense = wfMsgHtml( 'nolicense' );
696 $licenseshtml = $licenses->getHtml();
698 $ulb = wfMsgHtml( 'uploadbtn' );
701 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
703 $encDestName = htmlspecialchars( $this->mDesiredDestName
);
705 $watchChecked = $this->watchCheck() ?
'checked="checked"' : '';
706 # Re-uploads should not need "file exist already" warnings
707 $warningChecked = ($this->mIgnoreWarning ||
$this->mForReUpload
) ?
'checked="checked"' : '';
709 // Prepare form for upload or upload/copy
710 //javascript moved from inline calls to setup:
711 if( UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
712 if( $wgEnableJS2system ) {
714 Xml
::input( 'wpSourceType', false, 'file',
715 array( 'id' => 'wpSourceTypeFile', 'type' => 'radio', 'checked' => 'checked' ) ) .
716 Xml
::input( 'wpUploadFile', 60, false,
717 array( 'id' => 'wpUploadFile', 'type' => 'file', 'tabindex' => '1' ) ) .
718 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
719 Xml
::input( 'wpSourceType', false, 'Url',
720 array( 'id' => 'wpSourceTypeURL', 'type' => 'radio' ) ) .
721 Xml
::input( 'wpUploadFileURL', 60, false,
722 array( 'id' => 'wpUploadFileURL', 'type' => 'text', 'tabindex' => '1' ) ) .
723 wfMsgHtml( 'upload_source_url' ) ;
725 //@@todo deprecate (not needed once $wgEnableJS2system is turned on)
727 "<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='file' " .
728 "onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" .
729 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
731 "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
732 "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
733 "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
734 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
735 "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='Url' " .
736 "onchange='toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\")' />" .
737 "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " .
739 "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" .
740 "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
741 "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' />" .
742 wfMsgHtml( 'upload_source_url' ) ;
746 if( $wgEnableJS2system ) {
748 Xml
::input( 'wpUploadFile', 60, false,
749 array( 'id' => 'wpUploadFile', 'type' => 'file', 'tabindex' => '1' ) ) .
750 Xml
::hidden( 'wpSourceType', 'file');
753 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' ".
754 "onchange='fillDestFilename(\"wpUploadFile\")' />" .
755 "<input type='hidden' name='wpSourceType' value='file' />" ;
760 if( $wgEnableJS2system ) {
761 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
763 if ( $useAjaxDestCheck ) {
764 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
765 $destOnkeyup = 'onchange=\'wgUploadWarningObj.checkNow(this.value);\'';
768 # Uploading a new version? If so, the name is fixed.
769 $on = $this->mForReUpload ?
"readonly='readonly'" : "";
771 $encComment = htmlspecialchars( $this->mComment
);
773 //add the wpEditToken
775 Xml
::openElement( 'form',
776 array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
777 'enctype' => 'multipart/form-data', 'id' => 'mw-upload-form' ) ) .
778 Xml
::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) .
779 Xml
::openElement( 'fieldset' ) .
780 Xml
::element( 'legend', null, wfMsg( 'upload' ) ) .
781 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
783 {$this->uploadFormTextTop}
784 <td class='mw-label'>
785 <label for='wpUploadFile'>{$sourcefilename}</label>
787 <td class='mw-input'>
799 <td class='mw-label'>
800 <label for='wpDestFile'>{$destfilename}</label>
802 <td class='mw-input'>"
804 if( $this->mForReUpload
) {
806 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
, array('id'=>'wpDestFile','tabindex'=>2) ) .
814 "<input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
815 value=\"{$encDestName}\" $destOnkeyup />"
824 <td class='mw-label'>
825 <label for='wpUploadDescription'>{$summary}</label>
827 <td class='mw-input'>
828 <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6'
829 cols='{$cols}'{$width}>$encComment</textarea>
830 {$this->uploadFormTextAfterSummary}
836 # Re-uploads should not need license info
837 if ( !$this->mForReUpload
&& $licenseshtml != '' ) {
840 <td class='mw-label'>
841 <label for='wpLicense'>$license</label>
843 <td class='mw-input'>
844 <select name='wpLicense' id='wpLicense' tabindex='4'
845 onchange='licenseSelectorCheck()'>
846 <option value=''>$nolicense</option>
853 if( $useAjaxLicensePreview ) {
856 <td id=\"mw-license-preview\"></td>
863 if ( !$this->mForReUpload
&& $wgUseCopyrightUpload ) {
864 $filestatus = wfMsgExt( 'filestatus', 'escapenoentities' );
865 $copystatus = htmlspecialchars( $this->mCopyrightStatus
);
866 $filesource = wfMsgExt( 'filesource', 'escapenoentities' );
867 $uploadsource = htmlspecialchars( $this->mCopyrightSource
);
870 <td class='mw-label' style='white-space: nowrap;'>
871 <label for='wpUploadCopyStatus'>$filestatus</label></td>
872 <td class='mw-input'>
873 <input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus'
874 value=\"$copystatus\" size='60' />
878 <td class='mw-label'>
879 <label for='wpUploadCopyStatus'>$filesource</label>
881 <td class='mw-input'>
882 <input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus'
883 value=\"$uploadsource\" size='60' />
893 <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
894 <label for='wpWatchthis'>" . wfMsgHtml( 'watchthisupload' ) . "</label>
895 <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' $warningChecked />
896 <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
902 <td class='mw-input'>
903 <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" .
904 $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
909 <td class='mw-input'>"
911 $wgOut->addHTML( '<div class="mw-editTools">' );
912 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
913 $wgOut->addHTML( '</div>' );
917 Xml
::closeElement( 'table' ) .
918 Xml
::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
919 Xml
::hidden( 'wpForReUpload', $this->mForReUpload
, array( 'id' => 'wpForReUpload' ) ) .
920 Xml
::closeElement( 'fieldset' ) .
921 Xml
::closeElement( 'form' )
923 $uploadfooter = wfMsgNoTrans( 'uploadfooter' );
924 if( $uploadfooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadfooter ) ){
925 $wgOut->addWikiText( '<div id="mw-upload-footer-message">' . $uploadfooter . '</div>' );
929 /* -------------------------------------------------------------- */
932 * See if we should check the 'watch this page' checkbox on the form
933 * based on the user's preferences and whether we're being asked
934 * to create a new file or update an existing one.
936 * In the case where 'watch edits' is off but 'watch creations' is on,
937 * we'll leave the box unchecked.
939 * Note that the page target can be changed *on the form*, so our check
940 * state can get out of sync.
942 function watchCheck() {
944 if( $wgUser->getOption( 'watchdefault' ) ) {
949 $local = wfLocalFile( $this->mDesiredDestName
);
950 if( $local && $local->exists() ) {
951 // We're uploading a new version of an existing file.
952 // No creation, so don't watch it if we're not already.
953 return $local->getTitle()->userIsWatching();
955 // New page should get watched if that's our option.
956 return $wgUser->getOption( 'watchcreations' );
961 * Check if a user is the last uploader
964 * @param string $img, image name
966 * @deprecated Use UploadBase::userCanReUpload
968 public static function userCanReUpload( User
$user, $img ) {
969 wfDeprecated( __METHOD__
);
971 if( $user->isAllowed( 'reupload' ) )
972 return true; // non-conditional
973 if( !$user->isAllowed( 'reupload-own' ) )
976 $dbr = wfGetDB( DB_SLAVE
);
977 $row = $dbr->selectRow('image',
978 /* SELECT */ 'img_user',
979 /* WHERE */ array( 'img_name' => $img )
984 return $user->getId() == $row->img_user
;
988 * Display an error with a wikitext description
990 function showError( $description ) {
992 $wgOut->setPageTitle( wfMsg( "upload-file-error" ) );
993 $wgOut->setRobotPolicy( "noindex,nofollow" );
994 $wgOut->setArticleRelated( false );
995 $wgOut->enableClientCache( false );
996 $wgOut->addWikiText( $description );
1000 * Get the initial image page text based on a comment and optional file status information
1002 static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) {
1003 global $wgUseCopyrightUpload;
1004 if ( $wgUseCopyrightUpload ) {
1006 if ( $license != '' ) {
1007 $licensetxt = '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1009 $pageText = '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n" .
1010 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
1012 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
1014 if ( $license != '' ) {
1015 $filedesc = $comment == '' ?
'' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n";
1016 $pageText = $filedesc .
1017 '== ' . wfMsgForContent ( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1019 $pageText = $comment;
1026 * If there are rows in the deletion log for this file, show them,
1027 * along with a nice little note for the user
1029 * @param OutputPage $out
1030 * @param string filename
1032 private function showDeletionLog( $out, $filename ) {
1034 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
1035 $pager = new LogPager( $loglist, 'delete', false, $filename );
1036 if( $pager->getNumRows() > 0 ) {
1037 $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
1038 $out->addWikiMsg( 'upload-wasdeleted' );
1040 $loglist->beginLogEventsList() .
1042 $loglist->endLogEventsList()
1044 $out->addHTML( '</div>' );