7 * Form for handling uploads and special page.
11 class SpecialUpload
extends SpecialPage
{
13 * Constructor : initialise object
14 * Get data POSTed through the form and assign them to the object
15 * @param WebRequest $request Data posted.
17 public function __construct( $request = null ) {
20 parent
::__construct( 'Upload', 'upload' );
22 $this->loadRequest( is_null( $request ) ?
$wgRequest : $request );
25 /** Misc variables **/
26 protected $mRequest; // The WebRequest or FauxRequest this form is supposed to handle
27 protected $mSourceType;
29 protected $mLocalFile;
30 protected $mUploadClicked;
32 /** User input variables from the "description" section **/
33 protected $mDesiredDestName; // The requested target file name
37 /** User input variables from the root section **/
38 protected $mIgnoreWarning;
39 protected $mWatchThis;
40 protected $mCopyrightStatus;
41 protected $mCopyrightSource;
43 /** Hidden variables **/
44 protected $mForReUpload; // The user followed an "overwrite this file" link
45 protected $mCancelUpload; // The user clicked "Cancel and return to upload form" button
49 * Initialize instance variables from request and create an Upload handler
51 * @param WebRequest $request The request to extract variables from
53 protected function loadRequest( $request ) {
56 $this->mRequest
= $request;
57 $this->mSourceType
= $request->getVal( 'wpSourceType', 'file' );
58 $this->mUpload
= UploadBase
::createFromRequest( $request );
59 $this->mUploadClicked
= $request->wasPosted()
60 && ( $request->getCheck( 'wpUpload' )
61 ||
$request->getCheck( 'wpUploadIgnoreWarning' ) );
63 // Guess the desired name from the filename if not provided
64 $this->mDesiredDestName
= $request->getText( 'wpDestFile' );
65 if( !$this->mDesiredDestName
)
66 $this->mDesiredDestName
= $request->getText( 'wpUploadFile' );
67 $this->mComment
= $request->getText( 'wpUploadDescription' );
68 $this->mLicense
= $request->getText( 'wpLicense' );
71 $this->mIgnoreWarning
= $request->getCheck( 'wpIgnoreWarning' )
72 ||
$request->getCheck( 'wpUploadIgnoreWarning' );
73 $this->mWatchthis
= $request->getBool( 'wpWatchthis' );
74 $this->mCopyrightStatus
= $request->getText( 'wpUploadCopyStatus' );
75 $this->mCopyrightSource
= $request->getText( 'wpUploadSource' );
78 $this->mForReUpload
= $request->getBool( 'wpForReUpload' ); // updating a file
79 $this->mCancelUpload
= $request->getCheck( 'wpCancelUpload' )
80 ||
$request->getCheck( 'wpReUpload' ); // b/w compat
82 // If it was posted check for the token (no remote POST'ing with user credentials)
83 $token = $request->getVal( 'wpEditToken' );
84 if( $this->mSourceType
== 'file' && $token == null ) {
85 // Skip token check for file uploads as that can't be faked via JS...
86 // Some client-side tools don't expect to need to send wpEditToken
87 // with their submissions, as that's new in 1.16.
88 $this->mTokenOk
= true;
90 $this->mTokenOk
= $wgUser->matchEditToken( $token );
95 * This page can be shown if uploading is enabled.
96 * Handle permission checking elsewhere in order to be able to show
97 * custom error messages.
102 public function userCanExecute( $user ) {
103 return UploadBase
::isEnabled() && parent
::userCanExecute( $user );
107 * Special page entry point
109 public function execute( $par ) {
110 global $wgUser, $wgOut, $wgRequest;
113 $this->outputHeader();
115 # Check uploading enabled
116 if( !UploadBase
::isEnabled() ) {
117 $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
122 global $wgGroupPermissions;
123 if( !$wgUser->isAllowed( 'upload' ) ) {
124 if( !$wgUser->isLoggedIn() && ( $wgGroupPermissions['user']['upload']
125 ||
$wgGroupPermissions['autoconfirmed']['upload'] ) ) {
126 // Custom message if logged-in users without any special rights can upload
127 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
129 $wgOut->permissionRequired( 'upload' );
135 if( $wgUser->isBlocked() ) {
136 $wgOut->blockedPage();
140 # Check whether we actually want to allow changing stuff
142 $wgOut->readOnlyPage();
146 # Unsave the temporary file in case this was a cancelled upload
147 if ( $this->mCancelUpload
) {
148 if ( !$this->unsaveUploadedFile() )
149 # Something went wrong, so unsaveUploadedFile showed a warning
153 # Process upload or show a form
154 if ( $this->mTokenOk
&& !$this->mCancelUpload
155 && ( $this->mUpload
&& $this->mUploadClicked
) ) {
156 $this->processUpload();
158 $this->showUploadForm( $this->getUploadForm() );
162 if ( $this->mUpload
)
163 $this->mUpload
->cleanupTempFile();
167 * Show the main upload form and optionally add the session key to the
168 * output. This hides the source selection.
170 * @param string $message HTML message to be shown at top of form
171 * @param string $sessionKey Session key of the stashed upload
173 protected function showUploadForm( $form ) {
174 # Add links if file was previously deleted
175 if ( !$this->mDesiredDestName
)
176 $this->showViewDeletedLinks();
182 * Get an UploadForm instance with title and text properly set.
184 * @param string $message HTML string to add to the form
185 * @param string $sessionKey Session key in case this is a stashed upload
188 protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) {
192 $form = new UploadForm( array(
193 'watch' => $this->watchCheck(),
194 'forreupload' => $this->mForReUpload
,
195 'sessionkey' => $sessionKey,
196 'hideignorewarning' => $hideIgnoreWarning,
198 $form->setTitle( $this->getTitle() );
200 # Check the token, but only if necessary
201 if( !$this->mTokenOk
&& !$this->mCancelUpload
202 && ( $this->mUpload
&& $this->mUploadClicked
) )
203 $form->addPreText( wfMsgExt( 'session_fail_preview', 'parseinline' ) );
206 $form->addPreText( '<div id="uploadtext">' . wfMsgExt( 'uploadtext', 'parse' ) . '</div>');
207 # Add upload error message
208 $form->addPreText( $message );
211 $uploadFooter = wfMsgNoTrans( 'uploadfooter' );
212 if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) ) {
213 $form->addPostText( '<div id="mw-upload-footer-message">'
214 . $wgOut->parse( $uploadFooter ) . "</div>\n" );
222 * Shows the "view X deleted revivions link""
224 protected function showViewDeletedLinks() {
225 global $wgOut, $wgUser;
227 $title = Title
::makeTitleSafe( NS_FILE
, $this->mDesiredDestName
);
228 // Show a subtitle link to deleted revisions (to sysops et al only)
229 if( $title instanceof Title
&& ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
231 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
232 array( 'parse', 'replaceafter' ),
233 $wgUser->getSkin()->linkKnown(
234 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
235 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
238 $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
241 // Show the relevant lines from deletion log (for still deleted files only)
242 if( $title instanceof Title
&& $title->isDeletedQuick() && !$title->exists() ) {
243 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
248 * Stashes the upload and shows the main upload form.
250 * Note: only errors that can be handled by changing the name or
251 * description should be redirected here. It should be assumed that the
252 * file itself is sane and has passed UploadBase::verifyFile. This
253 * essentially means that UploadBase::VERIFICATION_ERROR and
254 * UploadBase::EMPTY_FILE should not be passed here.
256 * @param string $message HTML message to be passed to mainUploadForm
258 protected function recoverableUploadError( $message ) {
259 $sessionKey = $this->mUpload
->stashSession();
260 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
261 '<div class="error">' . $message . "</div>\n";
263 $form = $this->getUploadForm( $message, $sessionKey );
264 $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
265 $this->showUploadForm( $form );
268 * Stashes the upload, shows the main form, but adds an "continue anyway button"
270 * @param array $warnings
272 protected function uploadWarning( $warnings ) {
275 $sessionKey = $this->mUpload
->stashSession();
277 $sk = $wgUser->getSkin();
279 $warningHtml = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n"
280 . '<ul class="warning">';
281 foreach( $warnings as $warning => $args ) {
283 if( $warning == 'exists' ) {
284 $msg = self
::getExistsWarning( $args );
285 } elseif( $warning == 'duplicate' ) {
286 $msg = self
::getDupeWarning( $args );
287 } elseif( $warning == 'duplicate-archive' ) {
288 $msg = "\t<li>" . wfMsgExt( 'file-deleted-duplicate', 'parseinline',
289 array( Title
::makeTitle( NS_FILE
, $args )->getPrefixedText() ) )
292 if ( is_bool( $args ) )
294 elseif ( !is_array( $args ) )
295 $args = array( $args );
296 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
298 $warningHtml .= $msg;
300 $warningHtml .= "</ul>\n";
301 $warningHtml .= wfMsgExt( 'uploadwarning-text', 'parse' );
303 $form = $this->getUploadForm( $warningHtml, $sessionKey, /* $hideIgnoreWarning */ true );
304 $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
305 $form->addButton( 'wpUploadIgnoreWarning', wfMsg( 'ignorewarning' ) );
306 $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) );
308 $this->showUploadForm( $form );
312 * Show the upload form with error message, but do not stash the file.
314 * @param string $message
316 protected function uploadError( $message ) {
317 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
318 '<div class="error">' . $message . "</div>\n";
319 $this->showUploadForm( $this->getUploadForm( $message ) );
324 * Checks are made in SpecialUpload::execute()
326 protected function processUpload() {
327 global $wgUser, $wgOut;
329 // Verify permissions
330 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
331 if( $permErrors !== true )
332 return $wgOut->showPermissionsErrorPage( $permErrors );
334 // Fetch the file if required
335 $status = $this->mUpload
->fetchFile();
336 if( !$status->isOK() )
337 return $this->mainUploadForm( $wgOut->parse( $status->getWikiText() ) );
339 // Upload verification
340 $details = $this->mUpload
->verifyUpload();
341 if ( $details['status'] != UploadBase
::OK
)
342 return $this->processVerificationError( $details );
344 $this->mLocalFile
= $this->mUpload
->getLocalFile();
346 // Check warnings if necessary
347 if( !$this->mIgnoreWarning
) {
348 $warnings = $this->mUpload
->checkWarnings();
349 if( count( $warnings ) )
350 return $this->uploadWarning( $warnings );
353 // Get the page text if this is not a reupload
354 if( !$this->mForReUpload
) {
355 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
356 $this->mCopyrightStatus
, $this->mCopyrightSource
);
360 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
361 if ( !$status->isGood() )
362 return $this->uploadError( $wgOut->parse( $status->getWikiText() ) );
364 // Success, redirect to description page
365 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
366 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
371 * Get the initial image page text based on a comment and optional file status information
373 public static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) {
374 global $wgUseCopyrightUpload;
375 if ( $wgUseCopyrightUpload ) {
377 if ( $license != '' ) {
378 $licensetxt = '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
380 $pageText = '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n" .
381 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
383 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
385 if ( $license != '' ) {
386 $filedesc = $comment == '' ?
'' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n";
387 $pageText = $filedesc .
388 '== ' . wfMsgForContent ( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
390 $pageText = $comment;
397 * See if we should check the 'watch this page' checkbox on the form
398 * based on the user's preferences and whether we're being asked
399 * to create a new file or update an existing one.
401 * In the case where 'watch edits' is off but 'watch creations' is on,
402 * we'll leave the box unchecked.
404 * Note that the page target can be changed *on the form*, so our check
405 * state can get out of sync.
407 protected function watchCheck() {
409 if( $wgUser->getOption( 'watchdefault' ) ) {
414 $local = wfLocalFile( $this->mDesiredDestName
);
415 if( $local && $local->exists() ) {
416 // We're uploading a new version of an existing file.
417 // No creation, so don't watch it if we're not already.
418 return $local->getTitle()->userIsWatching();
420 // New page should get watched if that's our option.
421 return $wgUser->getOption( 'watchcreations' );
427 * Provides output to the user for a result of UploadBase::verifyUpload
429 * @param array $details Result of UploadBase::verifyUpload
431 protected function processVerificationError( $details ) {
432 global $wgFileExtensions, $wgLang;
434 switch( $details['status'] ) {
436 /** Statuses that only require name changing **/
437 case UploadBase
::MIN_LENGTH_PARTNAME
:
438 $this->recoverableUploadError( wfMsgHtml( 'minlength1' ) );
440 case UploadBase
::ILLEGAL_FILENAME
:
441 $this->recoverableUploadError( wfMsgExt( 'illegalfilename',
442 'parseinline', $details['filtered'] ) );
444 case UploadBase
::OVERWRITE_EXISTING_FILE
:
445 $this->recoverableUploadError( wfMsgExt( $details['overwrite'],
448 case UploadBase
::FILETYPE_MISSING
:
449 $this->recoverableUploadError( wfMsgExt( 'filetype-missing',
453 /** Statuses that require reuploading **/
454 case UploadBase
::EMPTY_FILE
:
455 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
457 case UploadBase
::FILETYPE_BADTYPE
:
458 $finalExt = $details['finalExt'];
460 wfMsgExt( 'filetype-banned-type',
461 array( 'parseinline' ),
462 htmlspecialchars( $finalExt ),
464 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
467 $wgLang->formatNum( count( $wgFileExtensions ) )
471 case UploadBase
::VERIFICATION_ERROR
:
472 unset( $details['status'] );
473 $code = array_shift( $details['details'] );
474 $this->uploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
476 case UploadBase
::HOOK_ABORTED
:
477 $error = $details['error'];
478 $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
481 throw new MWException( __METHOD__
. ": Unknown value `{$details['status']}`" );
486 * Remove a temporarily kept file stashed by saveTempUploadedFile().
490 protected function unsaveUploadedFile() {
492 if ( !( $this->mUpload
instanceof UploadFromStash
) )
494 $success = $this->mUpload
->unsaveUploadedFile();
496 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
503 /*** Functions for formatting warnings ***/
506 * Formats a result of UploadBase::getExistsWarning as HTML
507 * This check is static and can be done pre-upload via AJAX
509 * @param array $exists The result of UploadBase::getExistsWarning
510 * @return string Empty string if there is no warning or an HTML fragment
511 * consisting of one or more <li> elements if there is a warning.
513 public static function getExistsWarning( $exists ) {
514 global $wgUser, $wgContLang;
519 $file = $exists['file'];
520 $filename = $file->getTitle()->getPrefixedText();
523 $sk = $wgUser->getSkin();
525 if( $exists['warning'] == 'exists' ) {
527 $warning[] = '<li>' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '</li>';
528 } elseif( $exists['warning'] == 'page-exists' ) {
529 // Page exists but file does not
530 $warning[] = '<li>' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '</li>';
531 } elseif ( $exists['warning'] == 'exists-normalized' ) {
532 $warning[] = '<li>' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename,
533 $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '</li>';
534 } elseif ( $exists['warning'] == 'thumb' ) {
535 // Swapped argument order compared with other messages for backwards compatibility
536 $warning[] = '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline',
537 $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '</li>';
538 } elseif ( $exists['warning'] == 'thumb-name' ) {
539 // Image w/o '180px-' does not exists, but we do not like these filenames
540 $name = $file->getName();
541 $badPart = substr( $name, 0, strpos( $name, '-' ) +
1 );
542 $warning[] = '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '</li>';
543 } elseif ( $exists['warning'] == 'bad-prefix' ) {
544 $warning[] = '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '</li>';
545 } elseif ( $exists['warning'] == 'was-deleted' ) {
546 # If the file existed before and was deleted, warn the user of this
547 $ltitle = SpecialPage
::getTitleFor( 'Log' );
548 $llink = $sk->linkKnown(
550 wfMsgHtml( 'deletionlog' ),
557 $warning[] = '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
560 return implode( "\n", $warning );
564 * Get a list of warnings
566 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
567 * @return array list of warning messages
569 public static function ajaxGetExistsWarning( $filename ) {
570 $file = wfFindFile( $filename );
572 // Force local file so we have an object to do further checks against
573 // if there isn't an exact match...
574 $file = wfLocalFile( $filename );
578 $exists = UploadBase
::getExistsWarning( $file );
579 $warning = self
::getExistsWarning( $exists );
580 if ( $warning !== '' ) {
581 $s = "<ul>$warning</ul>";
588 * Render a preview of a given license for the AJAX preview on upload
590 * @param string $license
593 public static function ajaxGetLicensePreview( $license ) {
594 global $wgParser, $wgUser;
595 $text = '{{' . $license . '}}';
596 $title = Title
::makeTitle( NS_FILE
, 'Sample.jpg' );
597 $options = ParserOptions
::newFromUser( $wgUser );
599 // Expand subst: first, then live templates...
600 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
601 $output = $wgParser->parse( $text, $title, $options );
603 return $output->getText();
607 * Construct a warning and a gallery from an array of duplicate files.
609 public static function getDupeWarning( $dupes ) {
613 foreach( $dupes as $file ) {
614 $title = $file->getTitle();
615 $msg .= $title->getPrefixedText() .
616 "|" . $title->getText() . "\n";
618 $msg .= "</gallery>";
620 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
621 $wgOut->parse( $msg ) .
631 * Sub class of HTMLForm that provides the form section of SpecialUpload
633 class UploadForm
extends HTMLForm
{
635 protected $mForReUpload;
636 protected $mSessionKey;
637 protected $mHideIgnoreWarning;
639 protected $mSourceIds;
641 public function __construct( $options = array() ) {
644 $this->mWatch
= !empty( $options['watch'] );
645 $this->mForReUpload
= !empty( $options['forreupload'] );
646 $this->mSessionKey
= isset( $options['sessionkey'] )
647 ?
$options['sessionkey'] : '';
648 $this->mHideIgnoreWarning
= !empty( $options['hideignorewarning'] );
650 $sourceDescriptor = $this->getSourceSection();
651 $descriptor = $sourceDescriptor
652 +
$this->getDescriptionSection()
653 +
$this->getOptionsSection();
655 wfRunHooks( 'UploadFormInitDescriptor', array( $descriptor ) );
656 parent
::__construct( $descriptor, 'upload' );
658 # Set some form properties
659 $this->setSubmitText( wfMsg( 'uploadbtn' ) );
660 $this->setSubmitName( 'wpUpload' );
661 $this->setSubmitTooltip( 'upload' );
662 $this->setId( 'mw-upload-form' );
664 # Build a list of IDs for javascript insertion
665 $this->mSourceIds
= array();
666 foreach ( $sourceDescriptor as $key => $field ) {
667 if ( !empty( $field['id'] ) )
668 $this->mSourceIds
[] = $field['id'];
674 * Get the descriptor of the fieldset that contains the file source
675 * selection. The section is 'source'
677 * @return array Descriptor array
679 protected function getSourceSection() {
680 global $wgLang, $wgUser, $wgRequest;
682 if ( $this->mSessionKey
) {
684 'wpSessionKey' => array(
686 'default' => $this->mSessionKey
,
688 'wpSourceType' => array(
690 'default' => 'Stash',
695 $canUploadByUrl = UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' );
696 $radio = $canUploadByUrl;
697 $selectedSourceType = strtolower( $wgRequest->getText( 'wpSourceType', 'File' ) );
699 $descriptor = array();
700 $descriptor['UploadFile'] = array(
701 'class' => 'UploadSourceField',
702 'section' => 'source',
704 'id' => 'wpUploadFile',
705 'label-message' => 'sourcefilename',
706 'upload-type' => 'File',
708 'help' => wfMsgExt( 'upload-maxfilesize',
709 array( 'parseinline', 'escapenoentities' ),
711 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) )
713 ) . ' ' . wfMsgHtml( 'upload_source_file' ),
714 'checked' => $selectedSourceType == 'file',
716 if ( $canUploadByUrl ) {
717 global $wgMaxUploadSize;
718 $descriptor['UploadFileURL'] = array(
719 'class' => 'UploadSourceField',
720 'section' => 'source',
721 'id' => 'wpUploadFileURL',
722 'label-message' => 'sourceurl',
723 'upload-type' => 'Url',
725 'help' => wfMsgExt( 'upload-maxfilesize',
726 array( 'parseinline', 'escapenoentities' ),
727 $wgLang->formatSize( $wgMaxUploadSize )
728 ) . ' ' . wfMsgHtml( 'upload_source_url' ),
729 'checked' => $selectedSourceType == 'url',
732 wfRunHooks( 'UploadFormSourceDescriptors', array( $descriptor, &$radio, $selectedSourceType ) );
734 $descriptor['Extensions'] = array(
736 'section' => 'source',
737 'default' => $this->getExtensionsMessage(),
745 * Get the messages indicating which extensions are preferred and prohibitted.
747 * @return string HTML string containing the message
749 protected function getExtensionsMessage() {
750 # Print a list of allowed file extensions, if so configured. We ignore
751 # MIME type here, it's incomprehensible to most people and too long.
752 global $wgLang, $wgCheckFileExtensions, $wgStrictFileExtensions,
753 $wgFileExtensions, $wgFileBlacklist;
755 $allowedExtensions = '';
756 if( $wgCheckFileExtensions ) {
757 if( $wgStrictFileExtensions ) {
758 # Everything not permitted is banned
760 '<div id="mw-upload-permitted">' .
761 wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
764 # We have to list both preferred and prohibited
766 '<div id="mw-upload-preferred">' .
767 wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
769 '<div id="mw-upload-prohibited">' .
770 wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileBlacklist ) ) .
774 # Everything is permitted.
775 $extensionsList = '';
777 return $extensionsList;
781 * Get the descriptor of the fieldset that contains the file description
782 * input. The section is 'description'
784 * @return array Descriptor array
786 protected function getDescriptionSection() {
787 global $wgUser, $wgOut;
789 $cols = intval( $wgUser->getOption( 'cols' ) );
790 if( $wgUser->getOption( 'editwidth' ) ) {
791 $wgOut->addInlineStyle( '#mw-htmlform-description { width: 100%; }' );
797 'section' => 'description',
798 'id' => 'wpDestFile',
799 'label-message' => 'destfilename',
802 'UploadDescription' => array(
803 'type' => 'textarea',
804 'section' => 'description',
805 'id' => 'wpUploadDescription',
806 'label-message' => $this->mForReUpload
807 ?
'filereuploadsummary'
808 : 'fileuploadsummary',
812 'EditTools' => array(
813 'type' => 'edittools',
814 'section' => 'description',
818 'class' => 'Licenses',
819 'section' => 'description',
821 'label-message' => 'license',
824 if ( $this->mForReUpload
)
825 $descriptor['DestFile']['readonly'] = true;
827 global $wgUseCopyrightUpload;
828 if ( $wgUseCopyrightUpload ) {
829 $descriptor['UploadCopyStatus'] = array(
831 'section' => 'description',
832 'id' => 'wpUploadCopyStatus',
833 'label-message' => 'filestatus',
835 $descriptor['UploadSource'] = array(
837 'section' => 'description',
838 'id' => 'wpUploadSource',
839 'label-message' => 'filesource',
847 * Get the descriptor of the fieldset that contains the upload options,
848 * such as "watch this file". The section is 'options'
850 * @return array Descriptor array
852 protected function getOptionsSection() {
856 'Watchthis' => array(
858 'id' => 'wpWatchthis',
859 'label-message' => 'watchthisupload',
860 'section' => 'options',
863 if ( !$this->mHideIgnoreWarning
) {
864 $descriptor['IgnoreWarning'] = array(
866 'id' => 'wpIgnoreWarning',
867 'label-message' => 'ignorewarnings',
868 'section' => 'options',
877 * Add the upload JS and show the form.
879 public function show() {
880 $this->addUploadJS();
885 * Add upload JS to $wgOut
887 * @param bool $autofill Whether or not to autofill the destination
890 protected function addUploadJS( $autofill = true ) {
891 global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
892 global $wgEnableFirefogg, $wgEnableJS2system;
895 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
896 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
899 'wgAjaxUploadDestCheck' => $wgUseAjax && $wgAjaxUploadDestCheck,
900 'wgAjaxLicensePreview' => $wgUseAjax && $wgAjaxLicensePreview,
901 'wgEnableFirefogg' => (bool)$wgEnableFirefogg,
902 'wgUploadAutoFill' => (bool)$autofill,
903 'wgUploadSourceIds' => $this->mSourceIds
,
906 $wgOut->addScript( Skin
::makeVariablesScript( $scriptVars ) );
908 if ( $wgEnableJS2system ) {
909 //js2version of upload page:
910 $wgOut->addScriptClass( 'uploadPage' );
912 //legacy upload code:
913 $wgOut->addScriptFile( 'upload.js' );
914 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
919 * Empty function; submission is handled elsewhere.
923 function trySubmit() {
930 * A form field that contains a radio box in the label
932 class UploadSourceField
extends HTMLTextField
{
933 function getLabelHtml() {
934 $id = "wpSourceType{$this->mParams['upload-type']}";
935 $label = Html
::rawElement( 'label', array( 'for' => $id ), $this->mLabel
);
937 if ( !empty( $this->mParams
['radio'] ) ) {
939 'name' => 'wpSourceType',
942 'value' => $this->mParams
['upload-type'],
944 if ( !empty( $this->mParams
['checked'] ) )
945 $attribs['checked'] = 'checked';
946 $label .= Html
::element( 'input', $attribs );
949 return Html
::rawElement( 'td', array( 'class' => 'mw-label' ), $label );
952 return isset( $this->mParams
['size'] )
953 ?
$this->mParams
['size']