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->getCheck( 'wpUpload' ) && $request->wasPosted();
61 // Guess the desired name from the filename if not provided
62 $this->mDesiredDestName
= $request->getText( 'wpDestFile' );
63 if( !$this->mDesiredDestName
)
64 $this->mDesiredDestName
= $request->getText( 'wpUploadFile' );
65 $this->mComment
= $request->getText( 'wpUploadDescription' );
66 $this->mLicense
= $request->getText( 'wpLicense' );
69 $this->mIgnoreWarning
= $request->getCheck( 'wpIgnoreWarning' );
70 $this->mWatchthis
= $request->getBool( 'wpWatchthis' );
71 $this->mCopyrightStatus
= $request->getText( 'wpUploadCopyStatus' );
72 $this->mCopyrightSource
= $request->getText( 'wpUploadSource' );
75 $this->mForReUpload
= $request->getBool( 'wpForReUpload' ); // updating a file
76 $this->mCancelUpload
= $request->getCheck( 'wpCancelUpload' )
77 ||
$request->getCheck( 'wpReUpload' ); // b/w compat
79 // If it was posted check for the token (no remote POST'ing with user credentials)
80 $token = $request->getVal( 'wpEditToken' );
81 if( $this->mSourceType
== 'file' && $token == null ) {
82 // Skip token check for file uploads as that can't be faked via JS...
83 // Some client-side tools don't expect to need to send wpEditToken
84 // with their submissions, as that's new in 1.16.
85 $this->mTokenOk
= true;
87 $this->mTokenOk
= $wgUser->matchEditToken( $token );
92 * This page can be shown if uploading is enabled.
93 * Handle permission checking elsewhere in order to be able to show
94 * custom error messages.
99 public function userCanExecute( $user ) {
100 return UploadBase
::isEnabled() && parent
::userCanExecute( $user );
104 * Special page entry point
106 public function execute( $par ) {
107 global $wgUser, $wgOut, $wgRequest;
110 $this->outputHeader();
112 # Check uploading enabled
113 if( !UploadBase
::isEnabled() ) {
114 $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
119 global $wgGroupPermissions;
120 if( !$wgUser->isAllowed( 'upload' ) ) {
121 if( !$wgUser->isLoggedIn() && ( $wgGroupPermissions['user']['upload']
122 ||
$wgGroupPermissions['autoconfirmed']['upload'] ) ) {
123 // Custom message if logged-in users without any special rights can upload
124 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
126 $wgOut->permissionRequired( 'upload' );
132 if( $wgUser->isBlocked() ) {
133 $wgOut->blockedPage();
137 # Check whether we actually want to allow changing stuff
139 $wgOut->readOnlyPage();
143 # Unsave the temporary file in case this was a cancelled upload
144 if ( $this->mCancelUpload
) {
145 if ( !$this->unsaveUploadedFile() )
146 # Something went wrong, so unsaveUploadedFile showed a warning
150 # Process upload or show a form
151 if ( $this->mTokenOk
&& !$this->mCancelUpload
152 && ( $this->mUpload
&& $this->mUploadClicked
) ) {
153 $this->processUpload();
155 $this->showUploadForm( $this->getUploadForm() );
159 if ( $this->mUpload
)
160 $this->mUpload
->cleanupTempFile();
164 * Show the main upload form and optionally add the session key to the
165 * output. This hides the source selection.
167 * @param string $message HTML message to be shown at top of form
168 * @param string $sessionKey Session key of the stashed upload
170 protected function showUploadForm( $form ) {
171 # Add links if file was previously deleted
172 if ( !$this->mDesiredDestName
)
173 $this->showViewDeletedLinks();
179 * Get an UploadForm instance with title and text properly set.
181 * @param string $message HTML string to add to the form
182 * @param string $sessionKey Session key in case this is a stashed upload
185 protected function getUploadForm( $message = '', $sessionKey = '' ) {
189 $form = new UploadForm( $this->watchCheck(), $this->mForReUpload
, $sessionKey );
190 $form->setTitle( $this->getTitle() );
192 # Check the token, but only if necessary
193 if( !$this->mTokenOk
&& !$this->mCancelUpload
194 && ( $this->mUpload
&& $this->mUploadClicked
) )
195 $form->addPreText( wfMsgExt( 'session_fail_preview', 'parseinline' ) );
198 $form->addPreText( '<div id="uploadtext">' . wfMsgExt( 'uploadtext', 'parse' ) . '</div>');
199 # Add upload error message
200 $form->addPreText( $message );
203 $uploadFooter = wfMsgNoTrans( 'uploadfooter' );
204 if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) ) {
205 $form->addPostText( '<div id="mw-upload-footer-message">'
206 . $wgOut->parse( $uploadFooter ) . "</div>\n" );
214 * Shows the "view X deleted revivions link""
216 protected function showViewDeletedLinks() {
217 global $wgOut, $wgUser;
219 $title = Title
::makeTitleSafe( NS_FILE
, $this->mDesiredDestName
);
220 // Show a subtitle link to deleted revisions (to sysops et al only)
221 if( $title instanceof Title
&& ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
223 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
224 array( 'parse', 'replaceafter' ),
225 $wgUser->getSkin()->linkKnown(
226 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
227 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
230 $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
233 // Show the relevant lines from deletion log (for still deleted files only)
234 if( $title instanceof Title
&& $title->isDeletedQuick() && !$title->exists() ) {
235 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
240 * Stashes the upload and shows the main upload form.
242 * Note: only errors that can be handled by changing the name or
243 * description should be redirected here. It should be assumed that the
244 * file itself is sane and has passed UploadBase::verifyFile. This
245 * essentially means that UploadBase::VERIFICATION_ERROR and
246 * UploadBase::EMPTY_FILE should not be passed here.
248 * @param string $message HTML message to be passed to mainUploadForm
250 protected function recoverableUploadError( $message ) {
251 $sessionKey = $this->mUpload
->stashSession();
252 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
253 '<div class="error">' . $message . "</div>\n";
254 $this->showUploadForm( $this->getUploadForm( $message, $sessionKey ) );
257 * Stashes the upload, shows the main form, but adds an "continue anyway button"
259 * @param array $warnings
261 protected function uploadWarning( $warnings ) {
264 $sessionKey = $this->mUpload
->stashSession();
266 $sk = $wgUser->getSkin();
268 $warningHtml = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n"
269 . '<ul class="warning">';
270 foreach( $warnings as $warning => $args ) {
272 if( $warning == 'exists' ) {
273 $msg = self
::getExistsWarning( $args );
274 } elseif( $warning == 'duplicate' ) {
275 $msg = self
::getDupeWarning( $args );
276 } elseif( $warning == 'duplicate-archive' ) {
277 $msg = "\t<li>" . wfMsgExt( 'file-deleted-duplicate', 'parseinline',
278 array( Title
::makeTitle( NS_FILE
, $args )->getPrefixedText() ) )
281 if ( is_bool( $args ) )
283 elseif ( !is_array( $args ) )
284 $args = array( $args );
285 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
287 $warningHtml .= $msg;
289 $warningHtml .= '</ul>';
291 $form = $this->getUploadForm( $warningHtml, $sessionKey );
292 $form->setSubmitText( wfMsg( 'ignorewarning' ) );
293 $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) );
295 $this->showUploadForm( $form );
299 * Show the upload form with error message, but do not stash the file.
301 * @param string $message
303 protected function uploadError( $message ) {
304 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
305 '<div class="error">' . $message . "</div>\n";
306 $this->showUploadForm( $this->getUploadForm( $message ) );
311 * Checks are made in SpecialUpload::execute()
313 protected function processUpload() {
314 global $wgUser, $wgOut;
316 // Verify permissions
317 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
318 if( $permErrors !== true )
319 return $wgOut->showPermissionsErrorPage( $permErrors );
321 // Fetch the file if required
322 $status = $this->mUpload
->fetchFile();
323 if( !$status->isOK() )
324 return $this->mainUploadForm( $wgOut->parse( $status->getWikiText() ) );
326 // Upload verification
327 $details = $this->mUpload
->verifyUpload();
328 if ( $details['status'] != UploadBase
::OK
)
329 return $this->processVerificationError( $details );
331 $this->mLocalFile
= $this->mUpload
->getLocalFile();
333 // Check warnings if necessary
334 if( !$this->mIgnoreWarning
) {
335 $warnings = $this->mUpload
->checkWarnings();
336 if( count( $warnings ) )
337 return $this->uploadWarning( $warnings );
340 // Get the page text if this is not a reupload
341 if( !$this->mForReUpload
) {
342 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
343 $this->mCopyrightStatus
, $this->mCopyrightSource
);
347 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
348 if ( !$status->isGood() )
349 return $this->uploadError( $wgOut->parse( $status->getWikiText() ) );
351 // Success, redirect to description page
352 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
353 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
358 * Get the initial image page text based on a comment and optional file status information
360 public static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) {
361 global $wgUseCopyrightUpload;
362 if ( $wgUseCopyrightUpload ) {
364 if ( $license != '' ) {
365 $licensetxt = '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
367 $pageText = '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n" .
368 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
370 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
372 if ( $license != '' ) {
373 $filedesc = $comment == '' ?
'' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n";
374 $pageText = $filedesc .
375 '== ' . wfMsgForContent ( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
377 $pageText = $comment;
384 * See if we should check the 'watch this page' checkbox on the form
385 * based on the user's preferences and whether we're being asked
386 * to create a new file or update an existing one.
388 * In the case where 'watch edits' is off but 'watch creations' is on,
389 * we'll leave the box unchecked.
391 * Note that the page target can be changed *on the form*, so our check
392 * state can get out of sync.
394 protected function watchCheck() {
396 if( $wgUser->getOption( 'watchdefault' ) ) {
401 $local = wfLocalFile( $this->mDesiredDestName
);
402 if( $local && $local->exists() ) {
403 // We're uploading a new version of an existing file.
404 // No creation, so don't watch it if we're not already.
405 return $local->getTitle()->userIsWatching();
407 // New page should get watched if that's our option.
408 return $wgUser->getOption( 'watchcreations' );
414 * Provides output to the user for a result of UploadBase::verifyUpload
416 * @param array $details Result of UploadBase::verifyUpload
418 protected function processVerificationError( $details ) {
419 global $wgFileExtensions, $wgLang;
421 switch( $details['status'] ) {
423 /** Statuses that only require name changing **/
424 case UploadBase
::MIN_LENGTH_PARTNAME
:
425 $this->recoverableUploadError( wfMsgHtml( 'minlength1' ) );
427 case UploadBase
::ILLEGAL_FILENAME
:
428 $this->recoverableUploadError( wfMsgExt( 'illegalfilename',
429 'parseinline', $details['filtered'] ) );
431 case UploadBase
::OVERWRITE_EXISTING_FILE
:
432 $this->recoverableUploadError( wfMsgExt( $details['overwrite'],
435 case UploadBase
::FILETYPE_MISSING
:
436 $this->recoverableUploadError( wfMsgExt( 'filetype-missing',
440 /** Statuses that require reuploading **/
441 case UploadBase
::EMPTY_FILE
:
442 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
444 case UploadBase
::FILETYPE_BADTYPE
:
445 $finalExt = $details['finalExt'];
447 wfMsgExt( 'filetype-banned-type',
448 array( 'parseinline' ),
449 htmlspecialchars( $finalExt ),
451 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
454 $wgLang->formatNum( count( $wgFileExtensions ) )
458 case UploadBase
::VERIFICATION_ERROR
:
459 unset( $details['status'] );
460 $code = array_shift( $details['details'] );
461 $this->uploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
463 case UploadBase
::HOOK_ABORTED
:
464 $error = $details['error'];
465 $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
468 throw new MWException( __METHOD__
. ": Unknown value `{$details['status']}`" );
473 * Remove a temporarily kept file stashed by saveTempUploadedFile().
477 protected function unsaveUploadedFile() {
479 if ( !( $this->mUpload
instanceof UploadFromStash
) )
481 $success = $this->mUpload
->unsaveUploadedFile();
483 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
490 /*** Functions for formatting warnings ***/
493 * Formats a result of UploadBase::getExistsWarning as HTML
494 * This check is static and can be done pre-upload via AJAX
496 * @param array $exists The result of UploadBase::getExistsWarning
497 * @return string Empty string if there is no warning or an HTML fragment
498 * consisting of one or more <li> elements if there is a warning.
500 public static function getExistsWarning( $exists ) {
501 global $wgUser, $wgContLang;
506 $file = $exists['file'];
507 $filename = $file->getTitle()->getPrefixedText();
510 $sk = $wgUser->getSkin();
512 if( $exists['warning'] == 'exists' ) {
514 $warning[] = '<li>' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '</li>';
515 } elseif( $exists['warning'] == 'page-exists' ) {
516 // Page exists but file does not
517 $warning[] = '<li>' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '</li>';
518 } elseif ( $exists['warning'] == 'exists-normalized' ) {
519 $warning[] = '<li>' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename,
520 $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '</li>';
521 } elseif ( $exists['warning'] == 'thumb' ) {
522 // Swapped argument order compared with other messages for backwards compatibility
523 $warning[] = '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline',
524 $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '</li>';
525 } elseif ( $exists['warning'] == 'thumb-name' ) {
526 // Image w/o '180px-' does not exists, but we do not like these filenames
527 $name = $file->getName();
528 $badPart = substr( $name, 0, strpos( $name, '-' ) +
1 );
529 $warning[] = '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '</li>';
530 } elseif ( $exists['warning'] == 'bad-prefix' ) {
531 $warning[] = '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '</li>';
532 } elseif ( $exists['warning'] == 'was-deleted' ) {
533 # If the file existed before and was deleted, warn the user of this
534 $ltitle = SpecialPage
::getTitleFor( 'Log' );
535 $llink = $sk->linkKnown(
537 wfMsgHtml( 'deletionlog' ),
544 $warning[] = '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
547 return implode( "\n", $warning );
551 * Get a list of warnings
553 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
554 * @return array list of warning messages
556 public static function ajaxGetExistsWarning( $filename ) {
557 $file = wfFindFile( $filename );
559 // Force local file so we have an object to do further checks against
560 // if there isn't an exact match...
561 $file = wfLocalFile( $filename );
565 $exists = UploadBase
::getExistsWarning( $file );
566 $warning = self
::getExistsWarning( $exists );
567 if ( $warning !== '' ) {
568 $s = "<ul>$warning</ul>";
575 * Render a preview of a given license for the AJAX preview on upload
577 * @param string $license
580 public static function ajaxGetLicensePreview( $license ) {
581 global $wgParser, $wgUser;
582 $text = '{{' . $license . '}}';
583 $title = Title
::makeTitle( NS_FILE
, 'Sample.jpg' );
584 $options = ParserOptions
::newFromUser( $wgUser );
586 // Expand subst: first, then live templates...
587 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
588 $output = $wgParser->parse( $text, $title, $options );
590 return $output->getText();
594 * Construct a warning and a gallery from an array of duplicate files.
596 public static function getDupeWarning( $dupes ) {
600 foreach( $dupes as $file ) {
601 $title = $file->getTitle();
602 $msg .= $title->getPrefixedText() .
603 "|" . $title->getText() . "\n";
605 $msg .= "</gallery>";
607 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
608 $wgOut->parse( $msg ) .
618 * Sub class of HTMLForm that provides the form section of SpecialUpload
620 class UploadForm
extends HTMLForm
{
622 protected $mForReUpload;
623 protected $mSessionKey;
624 protected $mSourceIds;
626 public function __construct( $watch, $forReUpload = false, $sessionKey = '' ) {
629 $this->mWatch
= $watch;
630 $this->mForReUpload
= $forReUpload;
631 $this->mSessionKey
= $sessionKey;
633 $sourceDescriptor = $this->getSourceSection();
634 $descriptor = $sourceDescriptor
635 +
$this->getDescriptionSection()
636 +
$this->getOptionsSection();
638 wfRunHooks( 'UploadFormInitDescriptor', array( $descriptor ) );
639 parent
::__construct( $descriptor, 'upload' );
641 # Set some form properties
642 $this->setSubmitText( wfMsg( 'uploadbtn' ) );
643 $this->setSubmitName( 'wpUpload' );
644 $this->setSubmitTooltip( 'upload' );
645 $this->setId( 'mw-upload-form' );
647 # Build a list of IDs for javascript insertion
648 $this->mSourceIds
= array();
649 foreach ( $sourceDescriptor as $key => $field ) {
650 if ( !empty( $field['id'] ) )
651 $this->mSourceIds
[] = $field['id'];
657 * Get the descriptor of the fieldset that contains the file source
658 * selection. The section is 'source'
660 * @return array Descriptor array
662 protected function getSourceSection() {
663 global $wgLang, $wgUser, $wgRequest;
665 if ( $this->mSessionKey
) {
667 'wpSessionKey' => array(
669 'default' => $this->mSessionKey
,
671 'wpSourceType' => array(
673 'default' => 'Stash',
678 $canUploadByUrl = UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' );
679 $radio = $canUploadByUrl;
680 $selectedSourceType = strtolower( $wgRequest->getText( 'wpSourceType', 'File' ) );
682 $descriptor = array();
683 $descriptor['UploadFile'] = array(
684 'class' => 'UploadSourceField',
685 'section' => 'source',
687 'id' => 'wpUploadFile',
688 'label-message' => 'sourcefilename',
689 'upload-type' => 'File',
691 'help' => wfMsgExt( 'upload-maxfilesize',
692 array( 'parseinline', 'escapenoentities' ),
694 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) )
696 ) . ' ' . wfMsgHtml( 'upload_source_file' ),
697 'checked' => $selectedSourceType == 'file',
699 if ( $canUploadByUrl ) {
700 global $wgMaxUploadSize;
701 $descriptor['UploadFileURL'] = array(
702 'class' => 'UploadSourceField',
703 'section' => 'source',
704 'id' => 'wpUploadFileURL',
705 'label-message' => 'sourceurl',
706 'upload-type' => 'Url',
708 'help' => wfMsgExt( 'upload-maxfilesize',
709 array( 'parseinline', 'escapenoentities' ),
710 $wgLang->formatSize( $wgMaxUploadSize )
711 ) . ' ' . wfMsgHtml( 'upload_source_url' ),
712 'checked' => $selectedSourceType == 'url',
715 wfRunHooks( 'UploadFormSourceDescriptors', array( $descriptor, &$radio, $selectedSourceType ) );
717 $descriptor['Extensions'] = array(
719 'section' => 'source',
720 'default' => $this->getExtensionsMessage(),
728 * Get the messages indicating which extensions are preferred and prohibitted.
730 * @return string HTML string containing the message
732 protected function getExtensionsMessage() {
733 # Print a list of allowed file extensions, if so configured. We ignore
734 # MIME type here, it's incomprehensible to most people and too long.
735 global $wgLang, $wgCheckFileExtensions, $wgStrictFileExtensions,
736 $wgFileExtensions, $wgFileBlacklist;
738 $allowedExtensions = '';
739 if( $wgCheckFileExtensions ) {
740 if( $wgStrictFileExtensions ) {
741 # Everything not permitted is banned
743 '<div id="mw-upload-permitted">' .
744 wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
747 # We have to list both preferred and prohibited
749 '<div id="mw-upload-preferred">' .
750 wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
752 '<div id="mw-upload-prohibited">' .
753 wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileBlacklist ) ) .
757 # Everything is permitted.
758 $extensionsList = '';
760 return $extensionsList;
764 * Get the descriptor of the fieldset that contains the file description
765 * input. The section is 'description'
767 * @return array Descriptor array
769 protected function getDescriptionSection() {
770 global $wgUser, $wgOut;
772 $cols = intval( $wgUser->getOption( 'cols' ) );
773 if( $wgUser->getOption( 'editwidth' ) ) {
774 $wgOut->addInlineStyle( '#mw-htmlform-description { width: 100%; }' );
780 'section' => 'description',
781 'id' => 'wpDestFile',
782 'label-message' => 'destfilename',
785 'UploadDescription' => array(
786 'type' => 'textarea',
787 'section' => 'description',
788 'id' => 'wpUploadDescription',
789 'label-message' => $this->mForReUpload
790 ?
'filereuploadsummary'
791 : 'fileuploadsummary',
795 'EditTools' => array(
796 'type' => 'edittools',
797 'section' => 'description',
801 'class' => 'Licenses',
802 'section' => 'description',
804 'label-message' => 'license',
807 if ( $this->mForReUpload
)
808 $descriptor['DestFile']['readonly'] = true;
810 global $wgUseCopyrightUpload;
811 if ( $wgUseCopyrightUpload ) {
812 $descriptor['UploadCopyStatus'] = array(
814 'section' => 'description',
815 'id' => 'wpUploadCopyStatus',
816 'label-message' => 'filestatus',
818 $descriptor['UploadSource'] = array(
820 'section' => 'description',
821 'id' => 'wpUploadSource',
822 'label-message' => 'filesource',
830 * Get the descriptor of the fieldset that contains the upload options,
831 * such as "watch this file". The section is 'options'
833 * @return array Descriptor array
835 protected function getOptionsSection() {
839 'Watchthis' => array(
841 'id' => 'wpWatchthis',
842 'label-message' => 'watchthisupload',
843 'section' => 'options',
845 'IgnoreWarning' => array(
847 'id' => 'wpIgnoreWarning',
848 'label-message' => 'ignorewarnings',
849 'section' => 'options',
858 * Add the upload JS and show the form.
860 public function show() {
861 $this->addUploadJS();
866 * Add upload JS to $wgOut
868 * @param bool $autofill Whether or not to autofill the destination
871 protected function addUploadJS( $autofill = true ) {
872 global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
873 global $wgEnableFirefogg, $wgEnableJS2system;
876 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
877 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
880 'wgAjaxUploadDestCheck' => $wgUseAjax && $wgAjaxUploadDestCheck,
881 'wgAjaxLicensePreview' => $wgUseAjax && $wgAjaxLicensePreview,
882 'wgEnableFirefogg' => (bool)$wgEnableFirefogg,
883 'wgUploadAutoFill' => (bool)$autofill,
884 'wgUploadSourceIds' => $this->mSourceIds
,
887 $wgOut->addScript( Skin
::makeVariablesScript( $scriptVars ) );
889 if ( $wgEnableJS2system ) {
890 //js2version of upload page:
891 $wgOut->addScriptClass( 'uploadPage' );
893 //legacy upload code:
894 $wgOut->addScriptFile( 'upload.js' );
895 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
900 * Empty function; submission is handled elsewhere.
904 function trySubmit() {
911 * A form field that contains a radio box in the label
913 class UploadSourceField
extends HTMLTextField
{
914 function getLabelHtml() {
915 $id = "wpSourceType{$this->mParams['upload-type']}";
916 $label = Html
::rawElement( 'label', array( 'for' => $id ), $this->mLabel
);
918 if ( !empty( $this->mParams
['radio'] ) ) {
920 'name' => 'wpSourceType',
923 'value' => $this->mParams
['upload-type'],
925 if ( !empty( $this->mParams
['checked'] ) )
926 $attribs['checked'] = 'checked';
927 $label .= Html
::element( 'input', $attribs );
930 return Html
::rawElement( 'td', array( 'class' => 'mw-label' ), $label );
933 return isset( $this->mParams
['size'] )
934 ?
$this->mParams
['size']