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->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->showUploadForm( $this->getUploadForm( $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->showUploadForm( $this->getUploadForm( 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 if ( is_array( $details['error'] ) ) { # allow hooks to return error details in an array
478 $args = $details['error'];
479 $error = array_shift( $args );
481 $error = $details['error'];
485 $this->uploadError( wfMsgExt( $error, 'parseinline', $args ) );
488 throw new MWException( __METHOD__
. ": Unknown value `{$details['status']}`" );
493 * Remove a temporarily kept file stashed by saveTempUploadedFile().
497 protected function unsaveUploadedFile() {
499 if ( !( $this->mUpload
instanceof UploadFromStash
) )
501 $success = $this->mUpload
->unsaveUploadedFile();
503 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
510 /*** Functions for formatting warnings ***/
513 * Formats a result of UploadBase::getExistsWarning as HTML
514 * This check is static and can be done pre-upload via AJAX
516 * @param array $exists The result of UploadBase::getExistsWarning
517 * @return string Empty string if there is no warning or an HTML fragment
518 * consisting of one or more <li> elements if there is a warning.
520 public static function getExistsWarning( $exists ) {
521 global $wgUser, $wgContLang;
526 $file = $exists['file'];
527 $filename = $file->getTitle()->getPrefixedText();
530 $sk = $wgUser->getSkin();
532 if( $exists['warning'] == 'exists' ) {
534 $warning[] = '<li>' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '</li>';
535 } elseif( $exists['warning'] == 'page-exists' ) {
536 // Page exists but file does not
537 $warning[] = '<li>' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '</li>';
538 } elseif ( $exists['warning'] == 'exists-normalized' ) {
539 $warning[] = '<li>' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename,
540 $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '</li>';
541 } elseif ( $exists['warning'] == 'thumb' ) {
542 // Swapped argument order compared with other messages for backwards compatibility
543 $warning[] = '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline',
544 $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '</li>';
545 } elseif ( $exists['warning'] == 'thumb-name' ) {
546 // Image w/o '180px-' does not exists, but we do not like these filenames
547 $name = $file->getName();
548 $badPart = substr( $name, 0, strpos( $name, '-' ) +
1 );
549 $warning[] = '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '</li>';
550 } elseif ( $exists['warning'] == 'bad-prefix' ) {
551 $warning[] = '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '</li>';
552 } elseif ( $exists['warning'] == 'was-deleted' ) {
553 # If the file existed before and was deleted, warn the user of this
554 $ltitle = SpecialPage
::getTitleFor( 'Log' );
555 $llink = $sk->linkKnown(
557 wfMsgHtml( 'deletionlog' ),
564 $warning[] = '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
567 return implode( "\n", $warning );
571 * Get a list of warnings
573 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
574 * @return array list of warning messages
576 public static function ajaxGetExistsWarning( $filename ) {
577 $file = wfFindFile( $filename );
579 // Force local file so we have an object to do further checks against
580 // if there isn't an exact match...
581 $file = wfLocalFile( $filename );
585 $exists = UploadBase
::getExistsWarning( $file );
586 $warning = self
::getExistsWarning( $exists );
587 if ( $warning !== '' ) {
588 $s = "<ul>$warning</ul>";
595 * Render a preview of a given license for the AJAX preview on upload
597 * @param string $license
600 public static function ajaxGetLicensePreview( $license ) {
601 global $wgParser, $wgUser;
602 $text = '{{' . $license . '}}';
603 $title = Title
::makeTitle( NS_FILE
, 'Sample.jpg' );
604 $options = ParserOptions
::newFromUser( $wgUser );
606 // Expand subst: first, then live templates...
607 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
608 $output = $wgParser->parse( $text, $title, $options );
610 return $output->getText();
614 * Construct a warning and a gallery from an array of duplicate files.
616 public static function getDupeWarning( $dupes ) {
620 foreach( $dupes as $file ) {
621 $title = $file->getTitle();
622 $msg .= $title->getPrefixedText() .
623 "|" . $title->getText() . "\n";
625 $msg .= "</gallery>";
627 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
628 $wgOut->parse( $msg ) .
638 * Sub class of HTMLForm that provides the form section of SpecialUpload
640 class UploadForm
extends HTMLForm
{
642 protected $mForReUpload;
643 protected $mSessionKey;
644 protected $mHideIgnoreWarning;
646 protected $mSourceIds;
648 public function __construct( $options = array() ) {
651 $this->mWatch
= !empty( $options['watch'] );
652 $this->mForReUpload
= !empty( $options['forreupload'] );
653 $this->mSessionKey
= isset( $options['sessionkey'] )
654 ?
$options['sessionkey'] : '';
655 $this->mHideIgnoreWarning
= !empty( $options['hideignorewarning'] );
657 $sourceDescriptor = $this->getSourceSection();
658 $descriptor = $sourceDescriptor
659 +
$this->getDescriptionSection()
660 +
$this->getOptionsSection();
662 wfRunHooks( 'UploadFormInitDescriptor', array( $descriptor ) );
663 parent
::__construct( $descriptor, 'upload' );
665 # Set some form properties
666 $this->setSubmitText( wfMsg( 'uploadbtn' ) );
667 $this->setSubmitName( 'wpUpload' );
668 $this->setSubmitTooltip( 'upload' );
669 $this->setId( 'mw-upload-form' );
671 # Build a list of IDs for javascript insertion
672 $this->mSourceIds
= array();
673 foreach ( $sourceDescriptor as $key => $field ) {
674 if ( !empty( $field['id'] ) )
675 $this->mSourceIds
[] = $field['id'];
681 * Get the descriptor of the fieldset that contains the file source
682 * selection. The section is 'source'
684 * @return array Descriptor array
686 protected function getSourceSection() {
687 global $wgLang, $wgUser, $wgRequest;
689 if ( $this->mSessionKey
) {
691 'wpSessionKey' => array(
693 'default' => $this->mSessionKey
,
695 'wpSourceType' => array(
697 'default' => 'Stash',
702 $canUploadByUrl = UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' );
703 $radio = $canUploadByUrl;
704 $selectedSourceType = strtolower( $wgRequest->getText( 'wpSourceType', 'File' ) );
706 $descriptor = array();
707 $descriptor['UploadFile'] = array(
708 'class' => 'UploadSourceField',
709 'section' => 'source',
711 'id' => 'wpUploadFile',
712 'label-message' => 'sourcefilename',
713 'upload-type' => 'File',
715 'help' => wfMsgExt( 'upload-maxfilesize',
716 array( 'parseinline', 'escapenoentities' ),
718 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) )
720 ) . ' ' . wfMsgHtml( 'upload_source_file' ),
721 'checked' => $selectedSourceType == 'file',
723 if ( $canUploadByUrl ) {
724 global $wgMaxUploadSize;
725 $descriptor['UploadFileURL'] = array(
726 'class' => 'UploadSourceField',
727 'section' => 'source',
728 'id' => 'wpUploadFileURL',
729 'label-message' => 'sourceurl',
730 'upload-type' => 'URL',
732 'help' => wfMsgExt( 'upload-maxfilesize',
733 array( 'parseinline', 'escapenoentities' ),
734 $wgLang->formatSize( $wgMaxUploadSize )
735 ) . ' ' . wfMsgHtml( 'upload_source_url' ),
736 'checked' => $selectedSourceType == 'url',
739 wfRunHooks( 'UploadFormSourceDescriptors', array( &$descriptor, &$radio, $selectedSourceType ) );
741 $descriptor['Extensions'] = array(
743 'section' => 'source',
744 'default' => $this->getExtensionsMessage(),
752 * Get the messages indicating which extensions are preferred and prohibitted.
754 * @return string HTML string containing the message
756 protected function getExtensionsMessage() {
757 # Print a list of allowed file extensions, if so configured. We ignore
758 # MIME type here, it's incomprehensible to most people and too long.
759 global $wgLang, $wgCheckFileExtensions, $wgStrictFileExtensions,
760 $wgFileExtensions, $wgFileBlacklist;
762 $allowedExtensions = '';
763 if( $wgCheckFileExtensions ) {
764 if( $wgStrictFileExtensions ) {
765 # Everything not permitted is banned
767 '<div id="mw-upload-permitted">' .
768 wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
771 # We have to list both preferred and prohibited
773 '<div id="mw-upload-preferred">' .
774 wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
776 '<div id="mw-upload-prohibited">' .
777 wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileBlacklist ) ) .
781 # Everything is permitted.
782 $extensionsList = '';
784 return $extensionsList;
788 * Get the descriptor of the fieldset that contains the file description
789 * input. The section is 'description'
791 * @return array Descriptor array
793 protected function getDescriptionSection() {
794 global $wgUser, $wgOut;
796 $cols = intval( $wgUser->getOption( 'cols' ) );
797 if( $wgUser->getOption( 'editwidth' ) ) {
798 $wgOut->addInlineStyle( '#mw-htmlform-description { width: 100%; }' );
804 'section' => 'description',
805 'id' => 'wpDestFile',
806 'label-message' => 'destfilename',
809 'UploadDescription' => array(
810 'type' => 'textarea',
811 'section' => 'description',
812 'id' => 'wpUploadDescription',
813 'label-message' => $this->mForReUpload
814 ?
'filereuploadsummary'
815 : 'fileuploadsummary',
819 'EditTools' => array(
820 'type' => 'edittools',
821 'section' => 'description',
825 'class' => 'Licenses',
826 'section' => 'description',
828 'label-message' => 'license',
831 if ( $this->mForReUpload
)
832 $descriptor['DestFile']['readonly'] = true;
834 global $wgUseCopyrightUpload;
835 if ( $wgUseCopyrightUpload ) {
836 $descriptor['UploadCopyStatus'] = array(
838 'section' => 'description',
839 'id' => 'wpUploadCopyStatus',
840 'label-message' => 'filestatus',
842 $descriptor['UploadSource'] = array(
844 'section' => 'description',
845 'id' => 'wpUploadSource',
846 'label-message' => 'filesource',
854 * Get the descriptor of the fieldset that contains the upload options,
855 * such as "watch this file". The section is 'options'
857 * @return array Descriptor array
859 protected function getOptionsSection() {
860 global $wgUser, $wgOut;
862 if( $wgUser->isLoggedIn() ) {
864 'Watchthis' => array(
866 'id' => 'wpWatchthis',
867 'label-message' => 'watchthisupload',
868 'section' => 'options',
872 if( !$this->mHideIgnoreWarning
) {
873 $descriptor['IgnoreWarning'] = array(
875 'id' => 'wpIgnoreWarning',
876 'label-message' => 'ignorewarnings',
877 'section' => 'options',
886 * Add the upload JS and show the form.
888 public function show() {
889 $this->addUploadJS();
894 * Add upload JS to $wgOut
896 * @param bool $autofill Whether or not to autofill the destination
899 protected function addUploadJS( ) {
900 global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
901 global $wgEnableFirefogg, $wgEnableJS2system;
904 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
905 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
908 'wgAjaxUploadDestCheck' => $wgUseAjax && $wgAjaxUploadDestCheck,
909 'wgAjaxLicensePreview' => $wgUseAjax && $wgAjaxLicensePreview,
910 'wgEnableFirefogg' => (bool)$wgEnableFirefogg,
911 'wgUploadAutoFill' => !$this->mForReUpload
,
912 'wgUploadSourceIds' => $this->mSourceIds
,
915 $wgOut->addScript( Skin
::makeVariablesScript( $scriptVars ) );
917 // For <charinsert> support; not provided by js2 yet
918 $wgOut->addScriptFile( 'edit.js' );
920 if ( $wgEnableJS2system ) {
921 // JS2 upload scripts
922 $wgOut->addScriptClass( 'uploadPage' );
924 // Legacy upload javascript
925 $wgOut->addScriptFile( 'upload.js' );
930 * Empty function; submission is handled elsewhere.
934 function trySubmit() {
941 * A form field that contains a radio box in the label
943 class UploadSourceField
extends HTMLTextField
{
944 function getLabelHtml() {
945 $id = "wpSourceType{$this->mParams['upload-type']}";
946 $label = Html
::rawElement( 'label', array( 'for' => $id ), $this->mLabel
);
948 if ( !empty( $this->mParams
['radio'] ) ) {
950 'name' => 'wpSourceType',
953 'value' => $this->mParams
['upload-type'],
955 if ( !empty( $this->mParams
['checked'] ) )
956 $attribs['checked'] = 'checked';
957 $label .= Html
::element( 'input', $attribs );
960 return Html
::rawElement( 'td', array( 'class' => 'mw-label' ), $label );
963 return isset( $this->mParams
['size'] )
964 ?
$this->mParams
['size']