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
62 //if it was posted check for the token (no remote POST'ing with user credentials)
63 $token = $request->getVal( 'wpEditToken' );
64 $this->mTokenOk
= $wgUser->matchEditToken( $token );
66 # Placeholders for text injection by hooks (empty per default)
67 $this->uploadFormTextTop
= "";
68 $this->uploadFormTextAfterSummary
= "";
70 $this->mUploadClicked
= $request->getCheck( 'wpUpload' );
72 $this->mLicense
= $request->getText( 'wpLicense' );
73 $this->mCopyrightStatus
= $request->getText( 'wpUploadCopyStatus' );
74 $this->mCopyrightSource
= $request->getText( 'wpUploadSource' );
75 $this->mWatchthis
= $request->getBool( 'wpWatchthis' );
76 $this->mSourceType
= $request->getText( 'wpSourceType' );
77 $this->mDestWarningAck
= $request->getText( 'wpDestFileWarningAck' );
79 $this->mReUpload
= $request->getCheck( 'wpReUpload' ); // retrying upload
81 $this->mAction
= $request->getVal( 'action' );
82 $this->mUpload
= UploadBase
::createFromRequest( $request );
85 public function userCanExecute( $user ) {
86 return UploadBase
::isEnabled() && parent
::userCanExecute( $user );
93 function execute( $par ) {
94 global $wgUser, $wgOut, $wgRequest;
97 $this->outputHeader();
101 # Check uploading enabled
102 if( !UploadBase
::isEnabled() ) {
103 $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
108 global $wgGroupPermissions;
109 if( !$wgUser->isAllowed( 'upload' ) ) {
110 if( !$wgUser->isLoggedIn() && ( $wgGroupPermissions['user']['upload']
111 ||
$wgGroupPermissions['autoconfirmed']['upload'] ) ) {
112 // Custom message if logged-in users without any special rights can upload
113 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
115 $wgOut->permissionRequired( 'upload' );
121 if( $wgUser->isBlocked() ) {
122 $wgOut->blockedPage();
127 $wgOut->readOnlyPage();
130 //check token if uploading or reUploading
131 if( !$this->mTokenOk
&& !$this->mReUpload
&& ($this->mUpload
&& (
132 'submit' == $this->mAction ||
$this->mUploadClicked
) ) )
134 $this->mainUploadForm ( wfMsg( 'session_fail_preview', 'parseinline' ) );
139 if( $this->mReUpload
&& $this->mUpload
) {
140 // User choose to cancel upload
141 if( !$this->mUpload
->unsaveUploadedFile() ) {
144 # Because it is probably checked and shouldn't be
145 $this->mIgnoreWarning
= false;
146 $this->mainUploadForm();
147 } elseif( $this->mUpload
&& (
148 'submit' == $this->mAction ||
149 $this->mUploadClicked
151 $this->processUpload();
153 $this->mainUploadForm();
157 $this->mUpload
->cleanupTempFile();
162 * Checks are made in SpecialUpload::execute()
164 * FIXME this should really use the standard Status class (instead of associative array)
165 * FIXME would be nice if we refactored this into the upload api.
166 * (the special upload page is not the only response point that needs clean localized error msgs)
170 function processUpload() {
171 global $wgOut, $wgFileExtensions, $wgLang;
172 $details = $this->internalProcessUpload();
173 switch( $details['status'] ) {
174 case UploadBase
::SUCCESS
:
175 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
178 case UploadBase
::BEFORE_PROCESSING
:
179 $this->uploadError( $details['error'] );
181 case UploadBase
::LARGE_FILE_SERVER
:
182 $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
185 case UploadBase
::EMPTY_FILE
:
186 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
189 case UploadBase
::MIN_LENGTH_PARTNAME
:
190 $this->mainUploadForm( wfMsgHtml( 'minlength1' ) );
193 case UploadBase
::ILLEGAL_FILENAME
:
194 $this->uploadError( wfMsgExt( 'illegalfilename',
195 'parseinline', $details['filtered'] ) );
198 case UploadBase
::PROTECTED_PAGE
:
199 $wgOut->showPermissionsErrorPage( $details['permissionserrors'] );
202 case UploadBase
::OVERWRITE_EXISTING_FILE
:
203 $this->uploadError( wfMsgExt( $details['overwrite'],
207 case UploadBase
::FILETYPE_MISSING
:
208 $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );
211 case UploadBase
::FILETYPE_BADTYPE
:
212 $finalExt = $details['finalExt'];
214 wfMsgExt( 'filetype-banned-type',
215 array( 'parseinline' ),
216 htmlspecialchars( $finalExt ),
218 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
221 $wgLang->formatNum( count( $wgFileExtensions ) )
226 case UploadBase
::VERIFICATION_ERROR
:
227 unset( $details['status'] );
228 $code = array_shift( $details['details'] );
229 $this->uploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
232 case UploadBase
::UPLOAD_VERIFICATION_ERROR
:
233 $error = $details['error'];
234 $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
237 case UploadBase
::UPLOAD_WARNING
:
238 unset( $details['status'] );
239 $this->uploadWarning( $details );
242 case UploadBase
::INTERNAL_ERROR
:
243 $status = $details['internal'];
244 $this->showError( $wgOut->parse( $status->getWikiText() ) );
248 throw new MWException( __METHOD__
. ": Unknown value `{$details['status']}`" );
253 * Really do the upload
254 * Checks are made in SpecialUpload::execute()
256 * @param array $resultDetails contains result-specific dict of additional values
260 function internalProcessUpload() {
263 if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
265 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
266 return array( 'status' => UploadBase
::BEFORE_PROCESSING
);
270 * If the image is protected, non-sysop users won't be able
271 * to modify it by uploading a new revision.
273 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
274 if( $permErrors !== true ) {
275 return array( 'status' => UploadBase
::PROTECTED_PAGE
, 'permissionserrors' => $permErrors );
278 // Fetch the file if required
279 $status = $this->mUpload
->fetchFile();
280 if( !$status->isOK() ) {
281 return array( 'status' => UploadBase
::BEFORE_PROCESSING
, 'error'=> $status->getWikiText() );
284 // Check whether this is a sane upload
285 $result = $this->mUpload
->verifyUpload();
286 if( $result['status'] != UploadBase
::OK
)
289 $this->mLocalFile
= $this->mUpload
->getLocalFile();
291 if( !$this->mIgnoreWarning
) {
292 $warnings = $this->mUpload
->checkWarnings();
294 if( count( $warnings ) ) {
295 $warnings['status'] = UploadBase
::UPLOAD_WARNING
;
302 * Try actually saving the thing...
303 * It will show an error form on failure. No it will not.
305 if( !$this->mForReUpload
) {
306 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
307 $this->mCopyrightStatus
, $this->mCopyrightSource
);
311 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
313 if ( !$status->isGood() ) {
314 return array( 'status' => UploadBase
::INTERNAL_ERROR
, 'internal' => $status );
316 // Success, redirect to description page
317 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
318 return UploadBase
::SUCCESS
;
323 * Formats a result of UploadBase::getExistsWarning as HTML
324 * This check is static and can be done pre-upload via AJAX
326 * @param array $exists The result of UploadBase::getExistsWarning
327 * @return string Empty string if there is no warning or an HTML fragment
328 * consisting of one or more <li> elements if there is a warning.
330 public static function getExistsWarning( $exists ) {
331 global $wgUser, $wgContLang;
336 $file = $exists['file'];
337 $filename = $file->getTitle()->getPrefixedText();
340 $sk = $wgUser->getSkin();
342 if( $exists['warning'] == 'exists' ) {
344 $warning[] = '<li>' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '</li>';
345 } elseif( $exists['warning'] == 'page-exists' ) {
346 // Page exists but file does not
347 $warning[] = '<li>' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '</li>';
348 } elseif ( $exists['warning'] == 'exists-normalized' ) {
349 $warning[] = '<li>' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename,
350 $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '</li>';
351 } elseif ( $exists['warning'] == 'thumb' ) {
352 // Swapped argument order compared with other messages for backwards compatibility
353 $warning[] = '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline',
354 $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '</li>';
355 } elseif ( $exists['warning'] == 'thumb-name' ) {
356 # Image w/o '180px-' does not exists, but we do not like these filenames
357 $name = $file->getName();
358 $badPart = substr( $name, 0, strpos( $name, '-' ) +
1 );
359 $warning[] = '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '</li>';
360 } elseif ( $exists['warning'] == 'bad-prefix' ) {
361 $warning[] = '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '</li>';
362 } elseif ( $exists['warning'] == 'was-deleted' ) {
363 # If the file existed before and was deleted, warn the user of this
364 $ltitle = SpecialPage
::getTitleFor( 'Log' );
365 $llink = $sk->linkKnown(
367 wfMsgHtml( 'deletionlog' ),
374 $warning[] = '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
377 return implode( "\n", $warning );
381 * Get a list of warnings
383 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
384 * @return array list of warning messages
386 static function ajaxGetExistsWarning( $filename ) {
387 $file = wfFindFile( $filename );
389 // Force local file so we have an object to do further checks against
390 // if there isn't an exact match...
391 $file = wfLocalFile( $filename );
395 $exists = UploadBase
::getExistsWarning( $file );
396 $warning = self
::getExistsWarning( $exists );
397 // FIXME: We probably also want the prefix blacklist and the wasdeleted check here
398 if ( $warning !== '' ) {
399 $s = "<ul>$warning</ul>";
406 * Render a preview of a given license for the AJAX preview on upload
408 * @param string $license
411 public static function ajaxGetLicensePreview( $license ) {
412 global $wgParser, $wgUser;
413 $text = '{{' . $license . '}}';
414 $title = Title
::makeTitle( NS_FILE
, 'Sample.jpg' );
415 $options = ParserOptions
::newFromUser( $wgUser );
417 // Expand subst: first, then live templates...
418 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
419 $output = $wgParser->parse( $text, $title, $options );
421 return $output->getText();
425 * Construct the human readable warning message from an array of duplicate files
427 public static function getDupeWarning( $dupes ) {
431 foreach( $dupes as $file ) {
432 $title = $file->getTitle();
433 $msg .= $title->getPrefixedText() .
434 "|" . $title->getText() . "\n";
436 $msg .= "</gallery>";
438 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
439 $wgOut->parse( $msg ) .
448 * Remove a temporarily kept file stashed by saveTempUploadedFile().
452 function unsaveUploadedFile() {
454 $success = $this->mUpload
->unsaveUploadedFile();
456 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
463 /* Interface code starts below this line *
464 * -------------------------------------------------------------- */
468 * @param string $error as HTML
471 function uploadError( $error ) {
473 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
474 $wgOut->addHTML( '<span class="error">' . $error . '</span>' );
478 * There's something wrong with this file, not enough to reject it
479 * totally but we require manual intervention to save it for real.
480 * Stash it away, then present a form asking to confirm or cancel.
482 * @param string $warning as HTML
485 function uploadWarning( $warnings ) {
486 global $wgOut, $wgUser;
487 global $wgUseCopyrightUpload;
489 $this->mSessionKey
= $this->mUpload
->stashSession();
491 if( $this->mSessionKey
=== false ) {
492 # Couldn't save file; an error has been displayed so let's go.
496 $sk = $wgUser->getSkin();
498 $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" );
499 $wgOut->addHTML( '<ul class="warning">' );
500 foreach( $warnings as $warning => $args ) {
502 if( $warning == 'exists' ) {
504 //we should not have produced this warning if the user already acknowledged the destination warning
505 //at any rate I don't see why we should hid this warning if mDestWarningAck has been checked
506 //(it produces an empty warning page when no other warnings are fired)
507 //if ( !$this->mDestWarningAck )
508 $msg = self
::getExistsWarning( $args );
510 } elseif( $warning == 'duplicate' ) {
511 $msg = $this->getDupeWarning( $args );
512 } elseif( $warning == 'duplicate-archive' ) {
513 $titleText = Title
::makeTitle( NS_FILE
, $args )->getPrefixedText();
514 $msg = Xml
::tags( 'li', null, wfMsgExt( 'file-deleted-duplicate', array( 'parseinline' ), array( $titleText ) ) );
516 if( is_bool( $args ) )
518 elseif( !is_array( $args ) )
519 $args = array( $args );
520 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
523 $wgOut->addHTML( $msg );
526 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
528 if ( $wgUseCopyrightUpload ) {
529 $copyright = Xml
::hidden( 'wpUploadCopyStatus', $this->mCopyrightStatus
) . "\n" .
530 Xml
::hidden( 'wpUploadSource', $this->mCopyrightSource
) . "\n";
535 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
536 'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
537 Xml
::hidden('wpEditToken', $wgUser->editToken(), array("id" => 'wpEditToken')) .
538 Xml
::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
539 Xml
::hidden( 'wpSourceType', 'stash' ) . "\n" .
540 Xml
::hidden( 'wpSessionKey', $this->mSessionKey
) . "\n" .
541 Xml
::hidden( 'wpUploadDescription', $this->mComment
) . "\n" .
542 Xml
::hidden( 'wpLicense', $this->mLicense
) . "\n" .
543 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
) . "\n" .
544 Xml
::hidden( 'wpWatchthis', $this->mWatchthis
) . "\n" .
545 "{$copyright}<br />" .
546 Xml
::submitButton( wfMsg( 'ignorewarning' ), array ( 'name' => 'wpUpload', 'id' => 'wpUpload', 'checked' => 'checked' ) ) . ' ' .
547 Xml
::submitButton( wfMsg( 'reuploaddesc' ), array ( 'name' => 'wpReUpload', 'id' => 'wpReUpload' ) ) .
548 Xml
::closeElement( 'form' ) . "\n"
553 * Displays the main upload form, optionally with a highlighted
554 * error message up at the top.
556 * @param string $msg as HTML
559 function mainUploadForm( $msg='' ) {
560 global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize, $wgEnableFirefogg;
561 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
563 global $wgStylePath, $wgStyleVersion;
564 global $wgEnableJS2system;
566 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
567 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
569 $adc = wfBoolToStr( $useAjaxDestCheck );
570 $alp = wfBoolToStr( $useAjaxLicensePreview );
571 $uef = wfBoolToStr( $wgEnableFirefogg );
572 $autofill = wfBoolToStr( $this->mDesiredDestName
== '' );
575 $wgOut->addScript( "<script type=\"text/javascript\">
576 wgAjaxUploadDestCheck = {$adc};
577 wgAjaxLicensePreview = {$alp};
578 wgEnableFirefogg = {$uef};
579 wgUploadAutoFill = {$autofill};
582 if( $wgEnableJS2system ) {
583 //js2version of upload page:
584 $wgOut->addScriptClass( 'uploadPage' );
586 //legacy upload code:
587 $wgOut->addScriptFile( 'upload.js' );
588 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
591 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
593 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
597 if( $this->mDesiredDestName
!= '' ) {
598 $title = Title
::makeTitleSafe( NS_FILE
, $this->mDesiredDestName
);
599 // Show a subtitle link to deleted revisions (to sysops et al only)
600 if( $title instanceof Title
&& ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
602 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
603 array( 'parse', 'replaceafter' ),
604 $wgUser->getSkin()->linkKnown(
605 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
606 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
609 $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
612 // Show the relevant lines from deletion log (for still deleted files only)
613 if( $title instanceof Title
&& $title->isDeletedQuick() && !$title->exists() ) {
614 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
618 $cols = intval($wgUser->getOption( 'cols' ));
620 if( $wgUser->getOption( 'editwidth' ) ) {
621 $width = " style=\"width:100%\"";
627 $sub = wfMsgHtml( 'uploaderror' );
628 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
629 "<span class='error'>{$msg}</span>\n" );
632 $wgOut->addHTML( '<div id="uploadtext">' );
633 $wgOut->addWikiMsg( 'uploadtext', $this->mDesiredDestName
);
634 $wgOut->addHTML( "</div>\n" );
636 # Print a list of allowed file extensions, if so configured. We ignore
637 # MIME type here, it's incomprehensible to most people and too long.
638 global $wgCheckFileExtensions, $wgStrictFileExtensions,
639 $wgFileExtensions, $wgFileBlacklist;
641 $allowedExtensions = '';
642 if( $wgCheckFileExtensions ) {
643 if( $wgStrictFileExtensions ) {
644 # Everything not permitted is banned
646 '<div id="mw-upload-permitted">' .
647 wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
650 # We have to list both preferred and prohibited
652 '<div id="mw-upload-preferred">' .
653 wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
655 '<div id="mw-upload-prohibited">' .
656 wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileExtensions ) ) .
660 # Everything is permitted.
661 $extensionsList = '';
664 # Get the maximum file size from php.ini as $wgMaxUploadSize works for uploads from URL via CURL only
665 # See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize for possible values of upload_max_filesize
666 $val = wfShorthandToInteger( ini_get( 'upload_max_filesize' ) );
667 $maxUploadSize = '<div id="mw-upload-maxfilesize">' .
668 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
669 $wgLang->formatSize( $val ) ) .
671 //add a hidden filed for upload by url (uses the $wgMaxUploadSize var)
672 if( UploadFromUrl
::isEnabled() ) {
673 $maxUploadSize.='<div id="mw-upload-maxfilesize-url" style="display:none">' .
674 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
675 $wgLang->formatSize( $wgMaxUploadSize ) ) .
679 $sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
680 $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
682 $msg = ( $this->mForReUpload
) ?
'filereuploadsummary' : 'fileuploadsummary';
683 $summary = wfMsgExt( $msg, 'parseinline' );
685 $licenses = new Licenses();
686 $license = wfMsgExt( 'license', array( 'parseinline' ) );
687 $nolicense = wfMsgHtml( 'nolicense' );
688 $licenseshtml = $licenses->getHtml();
690 $ulb = wfMsgHtml( 'uploadbtn' );
693 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
695 $encDestName = htmlspecialchars( $this->mDesiredDestName
);
697 $watchChecked = $this->watchCheck() ?
'checked="checked"' : '';
698 # Re-uploads should not need "file exist already" warnings
699 $warningChecked = ($this->mIgnoreWarning ||
$this->mForReUpload
) ?
'checked="checked"' : '';
701 // Prepare form for upload or upload/copy
702 //javascript moved from inline calls to setup:
703 if( UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
704 if( $wgEnableJS2system ) {
706 Xml
::input( 'wpSourceType', false, 'file',
707 array( 'id' => 'wpSourceTypeFile', 'type' => 'radio', 'checked' => 'checked' ) ) .
708 Xml
::input( 'wpUploadFile', 60, false,
709 array( 'id' => 'wpUploadFile', 'type' => 'file', 'tabindex' => '1' ) ) .
710 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
711 Xml
::input( 'wpSourceType', false, 'Url',
712 array( 'id' => 'wpSourceTypeURL', 'type' => 'radio' ) ) .
713 Xml
::input( 'wpUploadFileURL', 60, false,
714 array( 'id' => 'wpUploadFileURL', 'type' => 'text', 'tabindex' => '1' ) ) .
715 wfMsgHtml( 'upload_source_url' ) ;
717 //@@todo deprecate (not needed once $wgEnableJS2system is turned on)
719 "<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='file' " .
720 "onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" .
721 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
723 "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
724 "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
725 "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
726 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
727 "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='Url' " .
728 "onchange='toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\")' />" .
729 "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " .
731 "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" .
732 "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
733 "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' />" .
734 wfMsgHtml( 'upload_source_url' ) ;
738 if( $wgEnableJS2system ) {
740 Xml
::input( 'wpUploadFile', 60, false,
741 array( 'id' => 'wpUploadFile', 'type' => 'file', 'tabindex' => '1' ) ) .
742 Xml
::hidden( 'wpSourceType', 'file');
745 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' ".
746 "onchange='fillDestFilename(\"wpUploadFile\")' />" .
747 "<input type='hidden' name='wpSourceType' value='file' />" ;
752 if( $wgEnableJS2system ) {
753 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
755 if ( $useAjaxDestCheck ) {
756 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
757 $destOnkeyup = 'onchange=\'wgUploadWarningObj.checkNow(this.value);\'';
760 # Uploading a new version? If so, the name is fixed.
761 $on = $this->mForReUpload ?
"readonly='readonly'" : "";
763 $encComment = htmlspecialchars( $this->mComment
);
765 //add the wpEditToken
767 Xml
::openElement( 'form',
768 array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
769 'enctype' => 'multipart/form-data', 'id' => 'mw-upload-form' ) ) .
770 Xml
::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) .
771 Xml
::openElement( 'fieldset' ) .
772 Xml
::element( 'legend', null, wfMsg( 'upload' ) ) .
773 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
775 {$this->uploadFormTextTop}
776 <td class='mw-label'>
777 <label for='wpUploadFile'>{$sourcefilename}</label>
779 <td class='mw-input'>
791 <td class='mw-label'>
792 <label for='wpDestFile'>{$destfilename}</label>
794 <td class='mw-input'>"
796 if( $this->mForReUpload
) {
798 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
, array('id'=>'wpDestFile','tabindex'=>2) ) .
806 "<input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
807 value=\"{$encDestName}\" $destOnkeyup />"
816 <td class='mw-label'>
817 <label for='wpUploadDescription'>{$summary}</label>
819 <td class='mw-input'>
820 <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6'
821 cols='{$cols}'{$width}>$encComment</textarea>
822 {$this->uploadFormTextAfterSummary}
828 # Re-uploads should not need license info
829 if ( !$this->mForReUpload
&& $licenseshtml != '' ) {
832 <td class='mw-label'>
833 <label for='wpLicense'>$license</label>
835 <td class='mw-input'>
836 <select name='wpLicense' id='wpLicense' tabindex='4'
837 onchange='licenseSelectorCheck()'>
838 <option value=''>$nolicense</option>
845 if( $useAjaxLicensePreview ) {
848 <td id=\"mw-license-preview\"></td>
855 if ( !$this->mForReUpload
&& $wgUseCopyrightUpload ) {
856 $filestatus = wfMsgExt( 'filestatus', 'escapenoentities' );
857 $copystatus = htmlspecialchars( $this->mCopyrightStatus
);
858 $filesource = wfMsgExt( 'filesource', 'escapenoentities' );
859 $uploadsource = htmlspecialchars( $this->mCopyrightSource
);
862 <td class='mw-label' style='white-space: nowrap;'>
863 <label for='wpUploadCopyStatus'>$filestatus</label></td>
864 <td class='mw-input'>
865 <input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus'
866 value=\"$copystatus\" size='60' />
870 <td class='mw-label'>
871 <label for='wpUploadCopyStatus'>$filesource</label>
873 <td class='mw-input'>
874 <input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus'
875 value=\"$uploadsource\" size='60' />
885 <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
886 <label for='wpWatchthis'>" . wfMsgHtml( 'watchthisupload' ) . "</label>
887 <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' $warningChecked />
888 <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
894 <td class='mw-input'>
895 <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" .
896 $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
901 <td class='mw-input'>"
903 $wgOut->addHTML( '<div class="mw-editTools">' );
904 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
905 $wgOut->addHTML( '</div>' );
909 Xml
::closeElement( 'table' ) .
910 Xml
::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
911 Xml
::hidden( 'wpForReUpload', $this->mForReUpload
, array( 'id' => 'wpForReUpload' ) ) .
912 Xml
::closeElement( 'fieldset' ) .
913 Xml
::closeElement( 'form' )
915 $uploadfooter = wfMsgNoTrans( 'uploadfooter' );
916 if( $uploadfooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadfooter ) ){
917 $wgOut->addWikiText( '<div id="mw-upload-footer-message">' . $uploadfooter . '</div>' );
921 /* -------------------------------------------------------------- */
924 * See if we should check the 'watch this page' checkbox on the form
925 * based on the user's preferences and whether we're being asked
926 * to create a new file or update an existing one.
928 * In the case where 'watch edits' is off but 'watch creations' is on,
929 * we'll leave the box unchecked.
931 * Note that the page target can be changed *on the form*, so our check
932 * state can get out of sync.
934 function watchCheck() {
936 if( $wgUser->getOption( 'watchdefault' ) ) {
941 $local = wfLocalFile( $this->mDesiredDestName
);
942 if( $local && $local->exists() ) {
943 // We're uploading a new version of an existing file.
944 // No creation, so don't watch it if we're not already.
945 return $local->getTitle()->userIsWatching();
947 // New page should get watched if that's our option.
948 return $wgUser->getOption( 'watchcreations' );
953 * Check if a user is the last uploader
956 * @param string $img, image name
958 * @deprecated Use UploadBase::userCanReUpload
960 public static function userCanReUpload( User
$user, $img ) {
961 wfDeprecated( __METHOD__
);
963 if( $user->isAllowed( 'reupload' ) )
964 return true; // non-conditional
965 if( !$user->isAllowed( 'reupload-own' ) )
968 $dbr = wfGetDB( DB_SLAVE
);
969 $row = $dbr->selectRow('image',
970 /* SELECT */ 'img_user',
971 /* WHERE */ array( 'img_name' => $img )
976 return $user->getId() == $row->img_user
;
980 * Display an error with a wikitext description
982 function showError( $description ) {
984 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
985 $wgOut->setRobotPolicy( "noindex,nofollow" );
986 $wgOut->setArticleRelated( false );
987 $wgOut->enableClientCache( false );
988 $wgOut->addWikiText( $description );
992 * Get the initial image page text based on a comment and optional file status information
994 static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) {
995 global $wgUseCopyrightUpload;
996 if ( $wgUseCopyrightUpload ) {
998 if ( $license != '' ) {
999 $licensetxt = '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1001 $pageText = '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n" .
1002 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
1004 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
1006 if ( $license != '' ) {
1007 $filedesc = $comment == '' ?
'' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n";
1008 $pageText = $filedesc .
1009 '== ' . wfMsgForContent ( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1011 $pageText = $comment;
1018 * If there are rows in the deletion log for this file, show them,
1019 * along with a nice little note for the user
1021 * @param OutputPage $out
1022 * @param string filename
1024 private function showDeletionLog( $out, $filename ) {
1026 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
1027 $pager = new LogPager( $loglist, 'delete', false, $filename );
1028 if( $pager->getNumRows() > 0 ) {
1029 $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
1030 $out->addWikiMsg( 'upload-wasdeleted' );
1032 $loglist->beginLogEventsList() .
1034 $loglist->endLogEventsList()
1036 $out->addHTML( '</div>' );