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 ) ) );
515 } elseif( $warning == 'filewasdeleted' ) {
516 $ltitle = SpecialPage
::getTitleFor( 'Log' );
517 $llink = $sk->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ),
518 'type=delete&page=' . $args->getPrefixedUrl() );
519 $msg = "\t<li>" . wfMsgWikiHtml( 'filewasdeleted', $llink ) . "</li>\n";
521 if( is_bool( $args ) )
523 elseif( !is_array( $args ) )
524 $args = array( $args );
525 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
528 $wgOut->addHTML( $msg );
531 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
533 if ( $wgUseCopyrightUpload ) {
534 $copyright = Xml
::hidden( 'wpUploadCopyStatus', $this->mCopyrightStatus
) . "\n" .
535 Xml
::hidden( 'wpUploadSource', $this->mCopyrightSource
) . "\n";
540 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
541 'enctype' => 'multipart/form-data', 'id' => 'uploadwarning' ) ) . "\n" .
542 Xml
::hidden('wpEditToken', $wgUser->editToken(), array("id" => 'wpEditToken')) .
543 Xml
::hidden( 'wpIgnoreWarning', '1' ) . "\n" .
544 Xml
::hidden( 'wpSourceType', 'stash' ) . "\n" .
545 Xml
::hidden( 'wpSessionKey', $this->mSessionKey
) . "\n" .
546 Xml
::hidden( 'wpUploadDescription', $this->mComment
) . "\n" .
547 Xml
::hidden( 'wpLicense', $this->mLicense
) . "\n" .
548 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
) . "\n" .
549 Xml
::hidden( 'wpWatchthis', $this->mWatchthis
) . "\n" .
550 "{$copyright}<br />" .
551 Xml
::submitButton( wfMsg( 'ignorewarning' ), array ( 'name' => 'wpUpload', 'id' => 'wpUpload', 'checked' => 'checked' ) ) . ' ' .
552 Xml
::submitButton( wfMsg( 'reuploaddesc' ), array ( 'name' => 'wpReUpload', 'id' => 'wpReUpload' ) ) .
553 Xml
::closeElement( 'form' ) . "\n"
558 * Displays the main upload form, optionally with a highlighted
559 * error message up at the top.
561 * @param string $msg as HTML
564 function mainUploadForm( $msg='' ) {
565 global $wgOut, $wgUser, $wgLang, $wgMaxUploadSize, $wgEnableFirefogg;
566 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
568 global $wgStylePath, $wgStyleVersion;
569 global $wgEnableJS2system;
571 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
572 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
574 $adc = wfBoolToStr( $useAjaxDestCheck );
575 $alp = wfBoolToStr( $useAjaxLicensePreview );
576 $uef = wfBoolToStr( $wgEnableFirefogg );
577 $autofill = wfBoolToStr( $this->mDesiredDestName
== '' );
580 $wgOut->addScript( "<script type=\"text/javascript\">
581 wgAjaxUploadDestCheck = {$adc};
582 wgAjaxLicensePreview = {$alp};
583 wgEnableFirefogg = {$uef};
584 wgUploadAutoFill = {$autofill};
587 if( $wgEnableJS2system ) {
588 //js2version of upload page:
589 $wgOut->addScriptClass( 'uploadPage' );
591 //legacy upload code:
592 $wgOut->addScriptFile( 'upload.js' );
593 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
596 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
598 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
602 if( $this->mDesiredDestName
!= '' ) {
603 $title = Title
::makeTitleSafe( NS_FILE
, $this->mDesiredDestName
);
604 // Show a subtitle link to deleted revisions (to sysops et al only)
605 if( $title instanceof Title
&& ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
607 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
608 array( 'parse', 'replaceafter' ),
609 $wgUser->getSkin()->linkKnown(
610 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
611 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
614 $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
617 // Show the relevant lines from deletion log (for still deleted files only)
618 if( $title instanceof Title
&& $title->isDeletedQuick() && !$title->exists() ) {
619 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
623 $cols = intval($wgUser->getOption( 'cols' ));
625 if( $wgUser->getOption( 'editwidth' ) ) {
626 $width = " style=\"width:100%\"";
632 $sub = wfMsgHtml( 'uploaderror' );
633 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
634 "<span class='error'>{$msg}</span>\n" );
637 $wgOut->addHTML( '<div id="uploadtext">' );
638 $wgOut->addWikiMsg( 'uploadtext', $this->mDesiredDestName
);
639 $wgOut->addHTML( "</div>\n" );
641 # Print a list of allowed file extensions, if so configured. We ignore
642 # MIME type here, it's incomprehensible to most people and too long.
643 global $wgCheckFileExtensions, $wgStrictFileExtensions,
644 $wgFileExtensions, $wgFileBlacklist;
646 $allowedExtensions = '';
647 if( $wgCheckFileExtensions ) {
648 if( $wgStrictFileExtensions ) {
649 # Everything not permitted is banned
651 '<div id="mw-upload-permitted">' .
652 wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
655 # We have to list both preferred and prohibited
657 '<div id="mw-upload-preferred">' .
658 wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
660 '<div id="mw-upload-prohibited">' .
661 wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileExtensions ) ) .
665 # Everything is permitted.
666 $extensionsList = '';
669 # Get the maximum file size from php.ini as $wgMaxUploadSize works for uploads from URL via CURL only
670 # See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize for possible values of upload_max_filesize
671 $val = wfShorthandToInteger( ini_get( 'upload_max_filesize' ) );
672 $maxUploadSize = '<div id="mw-upload-maxfilesize">' .
673 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
674 $wgLang->formatSize( $val ) ) .
676 //add a hidden filed for upload by url (uses the $wgMaxUploadSize var)
677 if( UploadFromUrl
::isEnabled() ) {
678 $maxUploadSize.='<div id="mw-upload-maxfilesize-url" style="display:none">' .
679 wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ),
680 $wgLang->formatSize( $wgMaxUploadSize ) ) .
684 $sourcefilename = wfMsgExt( 'sourcefilename', array( 'parseinline', 'escapenoentities' ) );
685 $destfilename = wfMsgExt( 'destfilename', array( 'parseinline', 'escapenoentities' ) );
687 $msg = ( $this->mForReUpload
) ?
'filereuploadsummary' : 'fileuploadsummary';
688 $summary = wfMsgExt( $msg, 'parseinline' );
690 $licenses = new Licenses();
691 $license = wfMsgExt( 'license', array( 'parseinline' ) );
692 $nolicense = wfMsgHtml( 'nolicense' );
693 $licenseshtml = $licenses->getHtml();
695 $ulb = wfMsgHtml( 'uploadbtn' );
698 $titleObj = SpecialPage
::getTitleFor( 'Upload' );
700 $encDestName = htmlspecialchars( $this->mDesiredDestName
);
702 $watchChecked = $this->watchCheck() ?
'checked="checked"' : '';
703 # Re-uploads should not need "file exist already" warnings
704 $warningChecked = ($this->mIgnoreWarning ||
$this->mForReUpload
) ?
'checked="checked"' : '';
706 // Prepare form for upload or upload/copy
707 //javascript moved from inline calls to setup:
708 if( UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
709 if( $wgEnableJS2system ) {
711 Xml
::input( 'wpSourceType', false, 'file',
712 array( 'id' => 'wpSourceTypeFile', 'type' => 'radio', 'checked' => 'checked' ) ) .
713 Xml
::input( 'wpUploadFile', 60, false,
714 array( 'id' => 'wpUploadFile', 'type' => 'file', 'tabindex' => '1' ) ) .
715 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
716 Xml
::input( 'wpSourceType', false, 'Url',
717 array( 'id' => 'wpSourceTypeURL', 'type' => 'radio' ) ) .
718 Xml
::input( 'wpUploadFileURL', 60, false,
719 array( 'id' => 'wpUploadFileURL', 'type' => 'text', 'tabindex' => '1' ) ) .
720 wfMsgHtml( 'upload_source_url' ) ;
722 //@@todo deprecate (not needed once $wgEnableJS2system is turned on)
724 "<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='file' " .
725 "onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" .
726 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " .
728 "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" .
729 "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " .
730 "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" .
731 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
732 "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='Url' " .
733 "onchange='toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\")' />" .
734 "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " .
736 "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" .
737 "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " .
738 "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' />" .
739 wfMsgHtml( 'upload_source_url' ) ;
743 if( $wgEnableJS2system ) {
745 Xml
::input( 'wpUploadFile', 60, false,
746 array( 'id' => 'wpUploadFile', 'type' => 'file', 'tabindex' => '1' ) ) .
747 Xml
::hidden( 'wpSourceType', 'file');
750 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' ".
751 "onchange='fillDestFilename(\"wpUploadFile\")' />" .
752 "<input type='hidden' name='wpSourceType' value='file' />" ;
757 if( $wgEnableJS2system ) {
758 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
760 if ( $useAjaxDestCheck ) {
761 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
762 $destOnkeyup = 'onchange=\'wgUploadWarningObj.checkNow(this.value);\'';
765 # Uploading a new version? If so, the name is fixed.
766 $on = $this->mForReUpload ?
"readonly='readonly'" : "";
768 $encComment = htmlspecialchars( $this->mComment
);
770 //add the wpEditToken
772 Xml
::openElement( 'form',
773 array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ),
774 'enctype' => 'multipart/form-data', 'id' => 'mw-upload-form' ) ) .
775 Xml
::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) .
776 Xml
::openElement( 'fieldset' ) .
777 Xml
::element( 'legend', null, wfMsg( 'upload' ) ) .
778 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-upload-table' ) ) .
780 {$this->uploadFormTextTop}
781 <td class='mw-label'>
782 <label for='wpUploadFile'>{$sourcefilename}</label>
784 <td class='mw-input'>
796 <td class='mw-label'>
797 <label for='wpDestFile'>{$destfilename}</label>
799 <td class='mw-input'>"
801 if( $this->mForReUpload
) {
803 Xml
::hidden( 'wpDestFile', $this->mDesiredDestName
, array('id'=>'wpDestFile','tabindex'=>2) ) .
811 "<input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='60'
812 value=\"{$encDestName}\" $destOnkeyup />"
821 <td class='mw-label'>
822 <label for='wpUploadDescription'>{$summary}</label>
824 <td class='mw-input'>
825 <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6'
826 cols='{$cols}'{$width}>$encComment</textarea>
827 {$this->uploadFormTextAfterSummary}
833 # Re-uploads should not need license info
834 if ( !$this->mForReUpload
&& $licenseshtml != '' ) {
837 <td class='mw-label'>
838 <label for='wpLicense'>$license</label>
840 <td class='mw-input'>
841 <select name='wpLicense' id='wpLicense' tabindex='4'
842 onchange='licenseSelectorCheck()'>
843 <option value=''>$nolicense</option>
850 if( $useAjaxLicensePreview ) {
853 <td id=\"mw-license-preview\"></td>
860 if ( !$this->mForReUpload
&& $wgUseCopyrightUpload ) {
861 $filestatus = wfMsgExt( 'filestatus', 'escapenoentities' );
862 $copystatus = htmlspecialchars( $this->mCopyrightStatus
);
863 $filesource = wfMsgExt( 'filesource', 'escapenoentities' );
864 $uploadsource = htmlspecialchars( $this->mCopyrightSource
);
867 <td class='mw-label' style='white-space: nowrap;'>
868 <label for='wpUploadCopyStatus'>$filestatus</label></td>
869 <td class='mw-input'>
870 <input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus'
871 value=\"$copystatus\" size='60' />
875 <td class='mw-label'>
876 <label for='wpUploadCopyStatus'>$filesource</label>
878 <td class='mw-input'>
879 <input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus'
880 value=\"$uploadsource\" size='60' />
890 <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
891 <label for='wpWatchthis'>" . wfMsgHtml( 'watchthisupload' ) . "</label>
892 <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' $warningChecked />
893 <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
899 <td class='mw-input'>
900 <input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\"" .
901 $wgUser->getSkin()->tooltipAndAccesskey( 'upload' ) . " />
906 <td class='mw-input'>"
908 $wgOut->addHTML( '<div class="mw-editTools">' );
909 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
910 $wgOut->addHTML( '</div>' );
914 Xml
::closeElement( 'table' ) .
915 Xml
::hidden( 'wpDestFileWarningAck', '', array( 'id' => 'wpDestFileWarningAck' ) ) .
916 Xml
::hidden( 'wpForReUpload', $this->mForReUpload
, array( 'id' => 'wpForReUpload' ) ) .
917 Xml
::closeElement( 'fieldset' ) .
918 Xml
::closeElement( 'form' )
920 $uploadfooter = wfMsgNoTrans( 'uploadfooter' );
921 if( $uploadfooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadfooter ) ){
922 $wgOut->addWikiText( '<div id="mw-upload-footer-message">' . $uploadfooter . '</div>' );
926 /* -------------------------------------------------------------- */
929 * See if we should check the 'watch this page' checkbox on the form
930 * based on the user's preferences and whether we're being asked
931 * to create a new file or update an existing one.
933 * In the case where 'watch edits' is off but 'watch creations' is on,
934 * we'll leave the box unchecked.
936 * Note that the page target can be changed *on the form*, so our check
937 * state can get out of sync.
939 function watchCheck() {
941 if( $wgUser->getOption( 'watchdefault' ) ) {
946 $local = wfLocalFile( $this->mDesiredDestName
);
947 if( $local && $local->exists() ) {
948 // We're uploading a new version of an existing file.
949 // No creation, so don't watch it if we're not already.
950 return $local->getTitle()->userIsWatching();
952 // New page should get watched if that's our option.
953 return $wgUser->getOption( 'watchcreations' );
958 * Check if a user is the last uploader
961 * @param string $img, image name
963 * @deprecated Use UploadBase::userCanReUpload
965 public static function userCanReUpload( User
$user, $img ) {
966 wfDeprecated( __METHOD__
);
968 if( $user->isAllowed( 'reupload' ) )
969 return true; // non-conditional
970 if( !$user->isAllowed( 'reupload-own' ) )
973 $dbr = wfGetDB( DB_SLAVE
);
974 $row = $dbr->selectRow('image',
975 /* SELECT */ 'img_user',
976 /* WHERE */ array( 'img_name' => $img )
981 return $user->getId() == $row->img_user
;
985 * Display an error with a wikitext description
987 function showError( $description ) {
989 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
990 $wgOut->setRobotPolicy( "noindex,nofollow" );
991 $wgOut->setArticleRelated( false );
992 $wgOut->enableClientCache( false );
993 $wgOut->addWikiText( $description );
997 * Get the initial image page text based on a comment and optional file status information
999 static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) {
1000 global $wgUseCopyrightUpload;
1001 if ( $wgUseCopyrightUpload ) {
1003 if ( $license != '' ) {
1004 $licensetxt = '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1006 $pageText = '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n" .
1007 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
1009 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
1011 if ( $license != '' ) {
1012 $filedesc = $comment == '' ?
'' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n";
1013 $pageText = $filedesc .
1014 '== ' . wfMsgForContent ( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
1016 $pageText = $comment;
1023 * If there are rows in the deletion log for this file, show them,
1024 * along with a nice little note for the user
1026 * @param OutputPage $out
1027 * @param string filename
1029 private function showDeletionLog( $out, $filename ) {
1031 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
1032 $pager = new LogPager( $loglist, 'delete', false, $filename );
1033 if( $pager->getNumRows() > 0 ) {
1034 $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
1035 $out->addWikiMsg( 'upload-wasdeleted' );
1037 $loglist->beginLogEventsList() .
1039 $loglist->endLogEventsList()
1041 $out->addHTML( '</div>' );