b9bd277602d83de773c0c378830447631c2950a8
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' ) && $wgUser->isLoggedIn();
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->getWatchCheck(),
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' ) );
207 $form->addPreText( '<div id="uploadtext">' . wfMsgExt( 'uploadtext', 'parse' ) . '</div>');
208 # Add upload error message
209 $form->addPreText( $message );
212 $uploadFooter = wfMsgNoTrans( 'uploadfooter' );
213 if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) ) {
214 $form->addPostText( '<div id="mw-upload-footer-message">'
215 . $wgOut->parse( $uploadFooter ) . "</div>\n" );
223 * Shows the "view X deleted revivions link""
225 protected function showViewDeletedLinks() {
226 global $wgOut, $wgUser;
228 $title = Title
::makeTitleSafe( NS_FILE
, $this->mDesiredDestName
);
229 // Show a subtitle link to deleted revisions (to sysops et al only)
230 if( $title instanceof Title
) {
231 $count = $title->isDeleted();
232 if ( $count > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
234 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
235 array( 'parse', 'replaceafter' ),
236 $wgUser->getSkin()->linkKnown(
237 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
238 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
241 $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
245 // Show the relevant lines from deletion log (for still deleted files only)
246 if( $title instanceof Title
&& $title->isDeletedQuick() && !$title->exists() ) {
247 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
252 * Stashes the upload and shows the main upload form.
254 * Note: only errors that can be handled by changing the name or
255 * description should be redirected here. It should be assumed that the
256 * file itself is sane and has passed UploadBase::verifyFile. This
257 * essentially means that UploadBase::VERIFICATION_ERROR and
258 * UploadBase::EMPTY_FILE should not be passed here.
260 * @param string $message HTML message to be passed to mainUploadForm
262 protected function showRecoverableUploadError( $message ) {
263 $sessionKey = $this->mUpload
->stashSession();
264 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
265 '<div class="error">' . $message . "</div>\n";
267 $form = $this->getUploadForm( $message, $sessionKey );
268 $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
269 $this->showUploadForm( $form );
272 * Stashes the upload, shows the main form, but adds an "continue anyway button"
274 * @param array $warnings
276 protected function showUploadWarning( $warnings ) {
279 $sessionKey = $this->mUpload
->stashSession();
281 $sk = $wgUser->getSkin();
283 $warningHtml = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n"
284 . '<ul class="warning">';
285 foreach( $warnings as $warning => $args ) {
287 if( $warning == 'exists' ) {
288 $msg = self
::getExistsWarning( $args );
289 } elseif( $warning == 'duplicate' ) {
290 $msg = self
::getDupeWarning( $args );
291 } elseif( $warning == 'duplicate-archive' ) {
292 $msg = "\t<li>" . wfMsgExt( 'file-deleted-duplicate', 'parseinline',
293 array( Title
::makeTitle( NS_FILE
, $args )->getPrefixedText() ) )
296 if ( is_bool( $args ) )
298 elseif ( !is_array( $args ) )
299 $args = array( $args );
300 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
302 $warningHtml .= $msg;
304 $warningHtml .= "</ul>\n";
305 $warningHtml .= wfMsgExt( 'uploadwarning-text', 'parse' );
307 $form = $this->getUploadForm( $warningHtml, $sessionKey, /* $hideIgnoreWarning */ true );
308 $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
309 $form->addButton( 'wpUploadIgnoreWarning', wfMsg( 'ignorewarning' ) );
310 $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) );
312 $this->showUploadForm( $form );
316 * Show the upload form with error message, but do not stash the file.
318 * @param string $message
320 protected function showUploadError( $message ) {
321 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
322 '<div class="error">' . $message . "</div>\n";
323 $this->showUploadForm( $this->getUploadForm( $message ) );
328 * Checks are made in SpecialUpload::execute()
330 protected function processUpload() {
331 global $wgUser, $wgOut;
333 // Verify permissions
334 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
335 if( $permErrors !== true ) {
336 $wgOut->showPermissionsErrorPage( $permErrors );
340 // Fetch the file if required
341 $status = $this->mUpload
->fetchFile();
342 if( !$status->isOK() ) {
343 $this->showUploadForm( $this->getUploadForm( $wgOut->parse( $status->getWikiText() ) ) );
347 // Upload verification
348 $details = $this->mUpload
->verifyUpload();
349 if ( $details['status'] != UploadBase
::OK
) {
350 $this->processVerificationError( $details );
354 $this->mLocalFile
= $this->mUpload
->getLocalFile();
356 // Check warnings if necessary
357 if( !$this->mIgnoreWarning
) {
358 $warnings = $this->mUpload
->checkWarnings();
359 if( count( $warnings ) ) {
360 $this->showUploadWarning( $warnings );
365 // Get the page text if this is not a reupload
366 if( !$this->mForReUpload
) {
367 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
368 $this->mCopyrightStatus
, $this->mCopyrightSource
);
372 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
373 if ( !$status->isGood() ) {
374 $this->showUploadError( $wgOut->parse( $status->getWikiText() ) );
378 // Success, redirect to description page
379 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
380 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
385 * Get the initial image page text based on a comment and optional file status information
387 public static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) {
388 global $wgUseCopyrightUpload;
389 if ( $wgUseCopyrightUpload ) {
391 if ( $license != '' ) {
392 $licensetxt = '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
394 $pageText = '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n" .
395 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
397 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
399 if ( $license != '' ) {
400 $filedesc = $comment == '' ?
'' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n";
401 $pageText = $filedesc .
402 '== ' . wfMsgForContent ( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
404 $pageText = $comment;
411 * See if we should check the 'watch this page' checkbox on the form
412 * based on the user's preferences and whether we're being asked
413 * to create a new file or update an existing one.
415 * In the case where 'watch edits' is off but 'watch creations' is on,
416 * we'll leave the box unchecked.
418 * Note that the page target can be changed *on the form*, so our check
419 * state can get out of sync.
421 protected function getWatchCheck() {
423 if( $wgUser->getOption( 'watchdefault' ) ) {
428 $local = wfLocalFile( $this->mDesiredDestName
);
429 if( $local && $local->exists() ) {
430 // We're uploading a new version of an existing file.
431 // No creation, so don't watch it if we're not already.
432 return $local->getTitle()->userIsWatching();
434 // New page should get watched if that's our option.
435 return $wgUser->getOption( 'watchcreations' );
441 * Provides output to the user for a result of UploadBase::verifyUpload
443 * @param array $details Result of UploadBase::verifyUpload
445 protected function processVerificationError( $details ) {
446 global $wgFileExtensions, $wgLang;
448 switch( $details['status'] ) {
450 /** Statuses that only require name changing **/
451 case UploadBase
::MIN_LENGTH_PARTNAME
:
452 $this->showRecoverableUploadError( wfMsgHtml( 'minlength1' ) );
454 case UploadBase
::ILLEGAL_FILENAME
:
455 $this->showRecoverableUploadError( wfMsgExt( 'illegalfilename',
456 'parseinline', $details['filtered'] ) );
458 case UploadBase
::OVERWRITE_EXISTING_FILE
:
459 $this->showRecoverableUploadError( wfMsgExt( $details['overwrite'],
462 case UploadBase
::FILETYPE_MISSING
:
463 $this->showRecoverableUploadError( wfMsgExt( 'filetype-missing',
467 /** Statuses that require reuploading **/
468 case UploadBase
::EMPTY_FILE
:
469 $this->showUploadForm( $this->getUploadForm( wfMsgHtml( 'emptyfile' ) ) );
471 case UploadBase
::FILETYPE_BADTYPE
:
472 $finalExt = $details['finalExt'];
473 $this->showUploadError(
474 wfMsgExt( 'filetype-banned-type',
475 array( 'parseinline' ),
476 htmlspecialchars( $finalExt ),
478 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
481 $wgLang->formatNum( count( $wgFileExtensions ) )
485 case UploadBase
::VERIFICATION_ERROR
:
486 unset( $details['status'] );
487 $code = array_shift( $details['details'] );
488 $this->showUploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
490 case UploadBase
::HOOK_ABORTED
:
491 if ( is_array( $details['error'] ) ) { # allow hooks to return error details in an array
492 $args = $details['error'];
493 $error = array_shift( $args );
495 $error = $details['error'];
499 $this->showUploadError( wfMsgExt( $error, 'parseinline', $args ) );
502 throw new MWException( __METHOD__
. ": Unknown value `{$details['status']}`" );
507 * Remove a temporarily kept file stashed by saveTempUploadedFile().
511 protected function unsaveUploadedFile() {
513 if ( !( $this->mUpload
instanceof UploadFromStash
) )
515 $success = $this->mUpload
->unsaveUploadedFile();
517 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
524 /*** Functions for formatting warnings ***/
527 * Formats a result of UploadBase::getExistsWarning as HTML
528 * This check is static and can be done pre-upload via AJAX
530 * @param array $exists The result of UploadBase::getExistsWarning
531 * @return string Empty string if there is no warning or an HTML fragment
532 * consisting of one or more <li> elements if there is a warning.
534 public static function getExistsWarning( $exists ) {
535 global $wgUser, $wgContLang;
540 $file = $exists['file'];
541 $filename = $file->getTitle()->getPrefixedText();
544 $sk = $wgUser->getSkin();
546 if( $exists['warning'] == 'exists' ) {
548 $warning[] = '<li>' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '</li>';
549 } elseif( $exists['warning'] == 'page-exists' ) {
550 // Page exists but file does not
551 $warning[] = '<li>' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '</li>';
552 } elseif ( $exists['warning'] == 'exists-normalized' ) {
553 $warning[] = '<li>' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename,
554 $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '</li>';
555 } elseif ( $exists['warning'] == 'thumb' ) {
556 // Swapped argument order compared with other messages for backwards compatibility
557 $warning[] = '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline',
558 $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '</li>';
559 } elseif ( $exists['warning'] == 'thumb-name' ) {
560 // Image w/o '180px-' does not exists, but we do not like these filenames
561 $name = $file->getName();
562 $badPart = substr( $name, 0, strpos( $name, '-' ) +
1 );
563 $warning[] = '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '</li>';
564 } elseif ( $exists['warning'] == 'bad-prefix' ) {
565 $warning[] = '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '</li>';
566 } elseif ( $exists['warning'] == 'was-deleted' ) {
567 # If the file existed before and was deleted, warn the user of this
568 $ltitle = SpecialPage
::getTitleFor( 'Log' );
569 $llink = $sk->linkKnown(
571 wfMsgHtml( 'deletionlog' ),
578 $warning[] = '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
581 return implode( "\n", $warning );
585 * Get a list of warnings
587 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
588 * @return array list of warning messages
590 public static function ajaxGetExistsWarning( $filename ) {
591 $file = wfFindFile( $filename );
593 // Force local file so we have an object to do further checks against
594 // if there isn't an exact match...
595 $file = wfLocalFile( $filename );
599 $exists = UploadBase
::getExistsWarning( $file );
600 $warning = self
::getExistsWarning( $exists );
601 if ( $warning !== '' ) {
602 $s = "<ul>$warning</ul>";
609 * Render a preview of a given license for the AJAX preview on upload
611 * @param string $license
614 public static function ajaxGetLicensePreview( $license ) {
615 global $wgParser, $wgUser;
616 $text = '{{' . $license . '}}';
617 $title = Title
::makeTitle( NS_FILE
, 'Sample.jpg' );
618 $options = ParserOptions
::newFromUser( $wgUser );
620 // Expand subst: first, then live templates...
621 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
622 $output = $wgParser->parse( $text, $title, $options );
624 return $output->getText();
628 * Construct a warning and a gallery from an array of duplicate files.
630 public static function getDupeWarning( $dupes ) {
634 foreach( $dupes as $file ) {
635 $title = $file->getTitle();
636 $msg .= $title->getPrefixedText() .
637 "|" . $title->getText() . "\n";
639 $msg .= "</gallery>";
641 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
642 $wgOut->parse( $msg ) .
652 * Sub class of HTMLForm that provides the form section of SpecialUpload
654 class UploadForm
extends HTMLForm
{
656 protected $mForReUpload;
657 protected $mSessionKey;
658 protected $mHideIgnoreWarning;
660 protected $mSourceIds;
662 public function __construct( $options = array() ) {
665 $this->mWatch
= !empty( $options['watch'] );
666 $this->mForReUpload
= !empty( $options['forreupload'] );
667 $this->mSessionKey
= isset( $options['sessionkey'] )
668 ?
$options['sessionkey'] : '';
669 $this->mHideIgnoreWarning
= !empty( $options['hideignorewarning'] );
671 $sourceDescriptor = $this->getSourceSection();
672 $descriptor = $sourceDescriptor
673 +
$this->getDescriptionSection()
674 +
$this->getOptionsSection();
676 wfRunHooks( 'UploadFormInitDescriptor', array( $descriptor ) );
677 parent
::__construct( $descriptor, 'upload' );
679 # Set some form properties
680 $this->setSubmitText( wfMsg( 'uploadbtn' ) );
681 $this->setSubmitName( 'wpUpload' );
682 $this->setSubmitTooltip( 'upload' );
683 $this->setId( 'mw-upload-form' );
685 # Build a list of IDs for javascript insertion
686 $this->mSourceIds
= array();
687 foreach ( $sourceDescriptor as $key => $field ) {
688 if ( !empty( $field['id'] ) )
689 $this->mSourceIds
[] = $field['id'];
695 * Get the descriptor of the fieldset that contains the file source
696 * selection. The section is 'source'
698 * @return array Descriptor array
700 protected function getSourceSection() {
701 global $wgLang, $wgUser, $wgRequest;
703 if ( $this->mSessionKey
) {
705 'wpSessionKey' => array(
707 'default' => $this->mSessionKey
,
709 'wpSourceType' => array(
711 'default' => 'Stash',
716 $canUploadByUrl = UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' );
717 $radio = $canUploadByUrl;
718 $selectedSourceType = strtolower( $wgRequest->getText( 'wpSourceType', 'File' ) );
720 $descriptor = array();
721 $descriptor['UploadFile'] = array(
722 'class' => 'UploadSourceField',
723 'section' => 'source',
725 'id' => 'wpUploadFile',
726 'label-message' => 'sourcefilename',
727 'upload-type' => 'File',
729 'help' => wfMsgExt( 'upload-maxfilesize',
730 array( 'parseinline', 'escapenoentities' ),
732 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) )
734 ) . ' ' . wfMsgHtml( 'upload_source_file' ),
735 'checked' => $selectedSourceType == 'file',
737 if ( $canUploadByUrl ) {
738 global $wgMaxUploadSize;
739 $descriptor['UploadFileURL'] = array(
740 'class' => 'UploadSourceField',
741 'section' => 'source',
742 'id' => 'wpUploadFileURL',
743 'label-message' => 'sourceurl',
744 'upload-type' => 'url',
746 'help' => wfMsgExt( 'upload-maxfilesize',
747 array( 'parseinline', 'escapenoentities' ),
748 $wgLang->formatSize( $wgMaxUploadSize )
749 ) . ' ' . wfMsgHtml( 'upload_source_url' ),
750 'checked' => $selectedSourceType == 'url',
753 wfRunHooks( 'UploadFormSourceDescriptors', array( &$descriptor, &$radio, $selectedSourceType ) );
755 $descriptor['Extensions'] = array(
757 'section' => 'source',
758 'default' => $this->getExtensionsMessage(),
766 * Get the messages indicating which extensions are preferred and prohibitted.
768 * @return string HTML string containing the message
770 protected function getExtensionsMessage() {
771 # Print a list of allowed file extensions, if so configured. We ignore
772 # MIME type here, it's incomprehensible to most people and too long.
773 global $wgLang, $wgCheckFileExtensions, $wgStrictFileExtensions,
774 $wgFileExtensions, $wgFileBlacklist;
776 $allowedExtensions = '';
777 if( $wgCheckFileExtensions ) {
778 if( $wgStrictFileExtensions ) {
779 # Everything not permitted is banned
781 '<div id="mw-upload-permitted">' .
782 wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
785 # We have to list both preferred and prohibited
787 '<div id="mw-upload-preferred">' .
788 wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
790 '<div id="mw-upload-prohibited">' .
791 wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileBlacklist ) ) .
795 # Everything is permitted.
796 $extensionsList = '';
798 return $extensionsList;
802 * Get the descriptor of the fieldset that contains the file description
803 * input. The section is 'description'
805 * @return array Descriptor array
807 protected function getDescriptionSection() {
808 global $wgUser, $wgOut;
810 $cols = intval( $wgUser->getOption( 'cols' ) );
811 if( $wgUser->getOption( 'editwidth' ) ) {
812 $wgOut->addInlineStyle( '#mw-htmlform-description { width: 100%; }' );
818 'section' => 'description',
819 'id' => 'wpDestFile',
820 'label-message' => 'destfilename',
823 'UploadDescription' => array(
824 'type' => 'textarea',
825 'section' => 'description',
826 'id' => 'wpUploadDescription',
827 'label-message' => $this->mForReUpload
828 ?
'filereuploadsummary'
829 : 'fileuploadsummary',
833 'EditTools' => array(
834 'type' => 'edittools',
835 'section' => 'description',
839 'class' => 'Licenses',
840 'section' => 'description',
842 'label-message' => 'license',
845 if ( $this->mForReUpload
)
846 $descriptor['DestFile']['readonly'] = true;
848 global $wgUseCopyrightUpload;
849 if ( $wgUseCopyrightUpload ) {
850 $descriptor['UploadCopyStatus'] = array(
852 'section' => 'description',
853 'id' => 'wpUploadCopyStatus',
854 'label-message' => 'filestatus',
856 $descriptor['UploadSource'] = array(
858 'section' => 'description',
859 'id' => 'wpUploadSource',
860 'label-message' => 'filesource',
868 * Get the descriptor of the fieldset that contains the upload options,
869 * such as "watch this file". The section is 'options'
871 * @return array Descriptor array
873 protected function getOptionsSection() {
874 global $wgUser, $wgOut;
876 if( $wgUser->isLoggedIn() ) {
878 'Watchthis' => array(
880 'id' => 'wpWatchthis',
881 'label-message' => 'watchthisupload',
882 'section' => 'options',
886 if( !$this->mHideIgnoreWarning
) {
887 $descriptor['IgnoreWarning'] = array(
889 'id' => 'wpIgnoreWarning',
890 'label-message' => 'ignorewarnings',
891 'section' => 'options',
900 * Add the upload JS and show the form.
902 public function show() {
903 $this->addUploadJS();
908 * Add upload JS to $wgOut
910 * @param bool $autofill Whether or not to autofill the destination
913 protected function addUploadJS( ) {
914 global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
917 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
918 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
921 'wgAjaxUploadDestCheck' => $wgUseAjax && $wgAjaxUploadDestCheck,
922 'wgAjaxLicensePreview' => $wgUseAjax && $wgAjaxLicensePreview,
923 'wgUploadAutoFill' => !$this->mForReUpload
,
924 'wgUploadSourceIds' => $this->mSourceIds
,
927 $wgOut->addScript( Skin
::makeVariablesScript( $scriptVars ) );
929 // For <charinsert> support
930 $wgOut->addScriptFile( 'edit.js' );
931 $wgOut->addScriptFile( 'upload.js' );
935 * Empty function; submission is handled elsewhere.
939 function trySubmit() {
946 * A form field that contains a radio box in the label
948 class UploadSourceField
extends HTMLTextField
{
949 function getLabelHtml() {
950 $id = "wpSourceType{$this->mParams['upload-type']}";
951 $label = Html
::rawElement( 'label', array( 'for' => $id ), $this->mLabel
);
953 if ( !empty( $this->mParams
['radio'] ) ) {
955 'name' => 'wpSourceType',
958 'value' => $this->mParams
['upload-type'],
960 if ( !empty( $this->mParams
['checked'] ) )
961 $attribs['checked'] = 'checked';
962 $label .= Html
::element( 'input', $attribs );
965 return Html
::rawElement( 'td', array( 'class' => 'mw-label' ), $label );
968 return isset( $this->mParams
['size'] )
969 ?
$this->mParams
['size']