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 = '' ) {
187 $form = new UploadForm( $this->watchCheck(), $this->mForReUpload
, $sessionKey );
188 $form->setTitle( $this->getTitle() );
190 # Check the token, but only if necessary
191 if( !$this->mTokenOk
&& !$this->mCancelUpload
192 && ( $this->mUpload
&& $this->mUploadClicked
) )
193 $form->addPreText( wfMsgExt( 'session_fail_preview', 'parseinline' ) );
196 $form->addPreText( '<div id="uploadtext">' . wfMsgExt( 'uploadtext', 'parse' ) . '</div>');
197 # Add upload error message
198 $form->addPreText( $message );
206 protected function showViewDeletedLinks() {
207 global $wgOut, $wgUser;
209 $title = Title
::makeTitleSafe( NS_FILE
, $this->mDesiredDestName
);
210 // Show a subtitle link to deleted revisions (to sysops et al only)
211 if( $title instanceof Title
&& ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
213 $wgUser->isAllowed( 'delete' ) ?
'thisisdeleted' : 'viewdeleted',
214 array( 'parse', 'replaceafter' ),
215 $wgUser->getSkin()->linkKnown(
216 SpecialPage
::getTitleFor( 'Undelete', $title->getPrefixedText() ),
217 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
220 $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
223 // Show the relevant lines from deletion log (for still deleted files only)
224 if( $title instanceof Title
&& $title->isDeletedQuick() && !$title->exists() ) {
225 $this->showDeletionLog( $wgOut, $title->getPrefixedText() );
230 * Stashes the upload and shows the main upload form.
232 * Note: only errors that can be handled by changing the name or
233 * description should be redirected here. It should be assumed that the
234 * file itself is sane and has passed UploadBase::verifyFile. This
235 * essentially means that UploadBase::VERIFICATION_ERROR and
236 * UploadBase::EMPTY_FILE should not be passed here.
238 * @param string $message HTML message to be passed to mainUploadForm
240 protected function recoverableUploadError( $message ) {
241 $sessionKey = $this->mUpload
->stashSession();
242 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
243 '<div class="error">' . $message . "</div>\n";
244 $this->showUploadForm( $this->getUploadForm( $message, $sessionKey ) );
247 * Stashes the upload, shows the main form, but adds an "continue anyway button"
249 * @param array $warnings
251 protected function uploadWarning( $warnings ) {
254 $sessionKey = $this->mUpload
->stashSession();
256 $sk = $wgUser->getSkin();
258 $warningHtml = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n"
259 . '<ul class="warning">';
260 foreach( $warnings as $warning => $args ) {
262 if( $warning == 'exists' ) {
263 $msg = self
::getExistsWarning( $args );
264 } elseif( $warning == 'duplicate' ) {
265 $msg = self
::getDupeWarning( $args );
266 } elseif( $warning == 'duplicate-archive' ) {
267 $msg = "\t<li>" . wfMsgExt( 'file-deleted-duplicate', 'parseinline',
268 array( Title
::makeTitle( NS_FILE
, $args )->getPrefixedText() ) )
271 if ( is_bool( $args ) )
273 elseif ( !is_array( $args ) )
274 $args = array( $args );
275 $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
277 $warningHtml .= $msg;
279 $warningHtml .= '</ul>';
281 $form = $this->getUploadForm( $warningHtml, $sessionKey );
282 $form->setSubmitText( wfMsg( 'ignorewarning' ) );
283 $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) );
285 $this->showUploadForm( $form );
289 * Show the upload form with error message, but do not stash the file.
291 * @param string $message
293 protected function uploadError( $message ) {
294 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
295 '<div class="error">' . $message . "</div>\n";
296 $this->showUploadForm( $this->getUploadForm( $message ) );
301 * Checks are made in SpecialUpload::execute()
303 protected function processUpload() {
304 global $wgUser, $wgOut;
306 // Verify permissions
307 $permErrors = $this->mUpload
->verifyPermissions( $wgUser );
308 if( $permErrors !== true )
309 return $wgOut->showPermissionsErrorPage( $permErrors );
311 // Fetch the file if required
312 $status = $this->mUpload
->fetchFile();
313 if( !$status->isOK() )
314 return $this->mainUploadForm( $wgOut->parse( $status->getWikiText() ) );
316 // Upload verification
317 $details = $this->mUpload
->verifyUpload();
318 if ( $details['status'] != UploadBase
::OK
)
319 return $this->processVerificationError( $details );
321 $this->mLocalFile
= $this->mUpload
->getLocalFile();
323 // Check warnings if necessary
324 if( !$this->mIgnoreWarning
) {
325 $warnings = $this->mUpload
->checkWarnings();
326 if( count( $warnings ) )
327 return $this->uploadWarning( $warnings );
330 // Get the page text if this is not a reupload
331 if( !$this->mForReUpload
) {
332 $pageText = self
::getInitialPageText( $this->mComment
, $this->mLicense
,
333 $this->mCopyrightStatus
, $this->mCopyrightSource
);
337 $status = $this->mUpload
->performUpload( $this->mComment
, $pageText, $this->mWatchthis
, $wgUser );
338 if ( !$status->isGood() )
339 return $this->uploadError( $wgOut->parse( $status->getWikiText() ) );
341 // Success, redirect to description page
342 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
343 $wgOut->redirect( $this->mLocalFile
->getTitle()->getFullURL() );
348 * Get the initial image page text based on a comment and optional file status information
350 public static function getInitialPageText( $comment = '', $license = '', $copyStatus = '', $source = '' ) {
351 global $wgUseCopyrightUpload;
352 if ( $wgUseCopyrightUpload ) {
354 if ( $license != '' ) {
355 $licensetxt = '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
357 $pageText = '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n" .
358 '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
360 '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
362 if ( $license != '' ) {
363 $filedesc = $comment == '' ?
'' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n";
364 $pageText = $filedesc .
365 '== ' . wfMsgForContent ( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
367 $pageText = $comment;
374 * See if we should check the 'watch this page' checkbox on the form
375 * based on the user's preferences and whether we're being asked
376 * to create a new file or update an existing one.
378 * In the case where 'watch edits' is off but 'watch creations' is on,
379 * we'll leave the box unchecked.
381 * Note that the page target can be changed *on the form*, so our check
382 * state can get out of sync.
384 protected function watchCheck() {
386 if( $wgUser->getOption( 'watchdefault' ) ) {
391 $local = wfLocalFile( $this->mDesiredDestName
);
392 if( $local && $local->exists() ) {
393 // We're uploading a new version of an existing file.
394 // No creation, so don't watch it if we're not already.
395 return $local->getTitle()->userIsWatching();
397 // New page should get watched if that's our option.
398 return $wgUser->getOption( 'watchcreations' );
404 * Provides output to the user for a result of UploadBase::verifyUpload
406 * @param array $details Result of UploadBase::verifyUpload
408 protected function processVerificationError( $details ) {
409 global $wgFileExtensions, $wgLang;
411 switch( $details['status'] ) {
413 /** Statuses that only require name changing **/
414 case UploadBase
::MIN_LENGTH_PARTNAME
:
415 $this->recoverableUploadError( wfMsgHtml( 'minlength1' ) );
417 case UploadBase
::ILLEGAL_FILENAME
:
418 $this->recoverableUploadError( wfMsgExt( 'illegalfilename',
419 'parseinline', $details['filtered'] ) );
421 case UploadBase
::OVERWRITE_EXISTING_FILE
:
422 $this->recoverableUploadError( wfMsgExt( $details['overwrite'],
425 case UploadBase
::FILETYPE_MISSING
:
426 $this->recoverableUploadError( wfMsgExt( 'filetype-missing',
430 /** Statuses that require reuploading **/
431 case UploadBase
::EMPTY_FILE
:
432 $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
434 case UploadBase
::FILETYPE_BADTYPE
:
435 $finalExt = $details['finalExt'];
437 wfMsgExt( 'filetype-banned-type',
438 array( 'parseinline' ),
439 htmlspecialchars( $finalExt ),
441 wfMsgExt( 'comma-separator', array( 'escapenoentities' ) ),
444 $wgLang->formatNum( count( $wgFileExtensions ) )
448 case UploadBase
::VERIFICATION_ERROR
:
449 unset( $details['status'] );
450 $code = array_shift( $details['details'] );
451 $this->uploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
453 case UploadBase
::HOOK_ABORTED
:
454 $error = $details['error'];
455 $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
458 throw new MWException( __METHOD__
. ": Unknown value `{$details['status']}`" );
463 * Remove a temporarily kept file stashed by saveTempUploadedFile().
467 protected function unsaveUploadedFile() {
469 if ( !( $this->mUpload
instanceof UploadFromStash
) )
471 $success = $this->mUpload
->unsaveUploadedFile();
473 $wgOut->showFileDeleteError( $this->mUpload
->getTempPath() );
480 /*** Functions for formatting warnings ***/
483 * Formats a result of UploadBase::getExistsWarning as HTML
484 * This check is static and can be done pre-upload via AJAX
486 * @param array $exists The result of UploadBase::getExistsWarning
487 * @return string Empty string if there is no warning or an HTML fragment
488 * consisting of one or more <li> elements if there is a warning.
490 public static function getExistsWarning( $exists ) {
491 global $wgUser, $wgContLang;
496 $file = $exists['file'];
497 $filename = $file->getTitle()->getPrefixedText();
500 $sk = $wgUser->getSkin();
502 if( $exists['warning'] == 'exists' ) {
504 $warning[] = '<li>' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '</li>';
505 } elseif( $exists['warning'] == 'page-exists' ) {
506 // Page exists but file does not
507 $warning[] = '<li>' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '</li>';
508 } elseif ( $exists['warning'] == 'exists-normalized' ) {
509 $warning[] = '<li>' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename,
510 $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '</li>';
511 } elseif ( $exists['warning'] == 'thumb' ) {
512 // Swapped argument order compared with other messages for backwards compatibility
513 $warning[] = '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline',
514 $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '</li>';
515 } elseif ( $exists['warning'] == 'thumb-name' ) {
516 // Image w/o '180px-' does not exists, but we do not like these filenames
517 $name = $file->getName();
518 $badPart = substr( $name, 0, strpos( $name, '-' ) +
1 );
519 $warning[] = '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '</li>';
520 } elseif ( $exists['warning'] == 'bad-prefix' ) {
521 $warning[] = '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '</li>';
522 } elseif ( $exists['warning'] == 'was-deleted' ) {
523 # If the file existed before and was deleted, warn the user of this
524 $ltitle = SpecialPage
::getTitleFor( 'Log' );
525 $llink = $sk->linkKnown(
527 wfMsgHtml( 'deletionlog' ),
534 $warning[] = '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
537 return implode( "\n", $warning );
541 * Get a list of warnings
543 * @param string local filename, e.g. 'file exists', 'non-descriptive filename'
544 * @return array list of warning messages
546 public static function ajaxGetExistsWarning( $filename ) {
547 $file = wfFindFile( $filename );
549 // Force local file so we have an object to do further checks against
550 // if there isn't an exact match...
551 $file = wfLocalFile( $filename );
555 $exists = UploadBase
::getExistsWarning( $file );
556 $warning = self
::getExistsWarning( $exists );
557 if ( $warning !== '' ) {
558 $s = "<ul>$warning</ul>";
565 * Render a preview of a given license for the AJAX preview on upload
567 * @param string $license
570 public static function ajaxGetLicensePreview( $license ) {
571 global $wgParser, $wgUser;
572 $text = '{{' . $license . '}}';
573 $title = Title
::makeTitle( NS_FILE
, 'Sample.jpg' );
574 $options = ParserOptions
::newFromUser( $wgUser );
576 // Expand subst: first, then live templates...
577 $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
578 $output = $wgParser->parse( $text, $title, $options );
580 return $output->getText();
584 * Construct a warning and a gallery from an array of duplicate files.
586 public static function getDupeWarning( $dupes ) {
590 foreach( $dupes as $file ) {
591 $title = $file->getTitle();
592 $msg .= $title->getPrefixedText() .
593 "|" . $title->getText() . "\n";
595 $msg .= "</gallery>";
597 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
598 $wgOut->parse( $msg ) .
608 * Sub class of HTMLForm that provides the form section of SpecialUpload
610 class UploadForm
extends HTMLForm
{
612 protected $mForReUpload;
613 protected $mSessionKey;
614 protected $mSourceIds;
616 public function __construct( $watch, $forReUpload = false, $sessionKey = '' ) {
619 $this->mWatch
= $watch;
620 $this->mForReUpload
= $forReUpload;
621 $this->mSessionKey
= $sessionKey;
623 $sourceDescriptor = $this->getSourceSection();
624 $descriptor = $sourceDescriptor
625 +
$this->getDescriptionSection()
626 +
$this->getOptionsSection();
628 wfRunHooks( 'UploadFormInitDescriptor', array( $descriptor ) );
629 parent
::__construct( $descriptor, 'upload' );
631 # Set some form properties
632 $this->setSubmitText( wfMsg( 'uploadbtn' ) );
633 $this->setSubmitName( 'wpUpload' );
634 $this->setSubmitTooltip( 'upload' );
635 $this->setId( 'mw-upload-form' );
637 # Build a list of IDs for javascript insertion
638 $this->mSourceIds
= array();
639 foreach ( $sourceDescriptor as $key => $field ) {
640 if ( !empty( $field['id'] ) )
641 $this->mSourceIds
[] = $field['id'];
649 protected function getSourceSection() {
650 global $wgLang, $wgUser, $wgRequest;
652 if ( $this->mSessionKey
) {
654 'wpSessionKey' => array(
656 'default' => $this->mSessionKey
,
658 'wpSourceType' => array(
660 'default' => 'Stash',
665 $canUploadByUrl = UploadFromUrl
::isEnabled() && $wgUser->isAllowed( 'upload_by_url' );
666 $radio = $canUploadByUrl;
667 $selectedSourceType = strtolower( $wgRequest->getText( 'wpSourceType', 'File' ) );
669 $descriptor = array();
670 $descriptor['UploadFile'] = array(
671 'class' => 'UploadSourceField',
672 'section' => 'source',
674 'id' => 'wpUploadFile',
675 'label-message' => 'sourcefilename',
676 'upload-type' => 'File',
678 'help' => wfMsgExt( 'upload-maxfilesize',
679 array( 'parseinline', 'escapenoentities' ),
681 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) )
683 ) . ' ' . wfMsgHtml( 'upload_source_file' ),
684 'checked' => $selectedSourceType == 'file',
686 if ( $canUploadByUrl ) {
687 global $wgMaxUploadSize;
688 $descriptor['UploadFileURL'] = array(
689 'class' => 'UploadSourceField',
690 'section' => 'source',
691 'id' => 'wpUploadFileURL',
692 'label-message' => 'sourceurl',
693 'upload-type' => 'Url',
695 'help' => wfMsgExt( 'upload-maxfilesize',
696 array( 'parseinline', 'escapenoentities' ),
697 $wgLang->formatSize( $wgMaxUploadSize )
698 ) . ' ' . wfMsgHtml( 'upload_source_url' ),
699 'checked' => $selectedSourceType == 'url',
702 wfRunHooks( 'UploadFormSourceDescriptors', array( $descriptor, &$radio, $selectedSourceType ) );
704 $descriptor['Extensions'] = array(
706 'section' => 'source',
707 'default' => $this->getExtensionsMessage(),
716 protected function getExtensionsMessage() {
717 # Print a list of allowed file extensions, if so configured. We ignore
718 # MIME type here, it's incomprehensible to most people and too long.
719 global $wgLang, $wgCheckFileExtensions, $wgStrictFileExtensions,
720 $wgFileExtensions, $wgFileBlacklist;
722 $allowedExtensions = '';
723 if( $wgCheckFileExtensions ) {
724 if( $wgStrictFileExtensions ) {
725 # Everything not permitted is banned
727 '<div id="mw-upload-permitted">' .
728 wfMsgWikiHtml( 'upload-permitted', $wgLang->commaList( $wgFileExtensions ) ) .
731 # We have to list both preferred and prohibited
733 '<div id="mw-upload-preferred">' .
734 wfMsgWikiHtml( 'upload-preferred', $wgLang->commaList( $wgFileExtensions ) ) .
736 '<div id="mw-upload-prohibited">' .
737 wfMsgWikiHtml( 'upload-prohibited', $wgLang->commaList( $wgFileBlacklist ) ) .
741 # Everything is permitted.
742 $extensionsList = '';
744 return $extensionsList;
750 protected function getDescriptionSection() {
751 global $wgUser, $wgOut;
753 $cols = intval( $wgUser->getOption( 'cols' ) );
754 if( $wgUser->getOption( 'editwidth' ) ) {
755 $wgOut->addInlineStyle( '#mw-htmlform-description { width: 100%; }' );
761 'section' => 'description',
762 'id' => 'wpDestFile',
763 'label-message' => 'destfilename',
766 'UploadDescription' => array(
767 'type' => 'textarea',
768 'section' => 'description',
769 'id' => 'wpUploadDescription',
770 'label-message' => $this->mForReUpload
771 ?
'filereuploadsummary'
772 : 'fileuploadsummary',
778 'class' => 'Licenses',
779 'section' => 'description',
781 'label-message' => 'license',
784 if ( $this->mForReUpload
)
785 $descriptor['DestFile']['readonly'] = true;
787 global $wgUseAjax, $wgAjaxLicensePreview;
788 if ( $wgUseAjax && $wgAjaxLicensePreview )
789 $descriptor['AjaxLicensePreview'] = array(
790 'class' => 'UploadAjaxLicensePreview',
791 'section' => 'description'
794 global $wgUseCopyrightUpload;
795 if ( $wgUseCopyrightUpload ) {
796 $descriptor['UploadCopyStatus'] = array(
798 'section' => 'description',
799 'id' => 'wpUploadCopyStatus',
800 'label-message' => 'filestatus',
802 $descriptor['UploadSource'] = array(
804 'section' => 'description',
805 'id' => 'wpUploadSource',
806 'label-message' => 'filesource',
816 protected function getOptionsSection() {
820 'Watchthis' => array(
822 'id' => 'wpWatchthis',
823 'label-message' => 'watchthisupload',
824 'section' => 'options',
826 'IgnoreWarning' => array(
828 'id' => 'wpIgnoreWarning',
829 'label-message' => 'ignorewarnings',
830 'section' => 'options',
832 'EditTools' => array(
833 'type' => 'edittools',
834 'section' => 'options',
838 $uploadFooter = wfMsgNoTrans( 'uploadfooter' );
839 if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) )
840 $descriptor['UploadFooter'] = array(
842 'id' => 'mw-upload-footer-message',
843 'default' => $wgOut->parse( $uploadFooter ),
853 public function show() {
854 $this->addUploadJS();
861 protected function addUploadJS( $autofill = true ) {
862 global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
863 global $wgEnableFirefogg, $wgEnableJS2system;
866 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
867 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
870 'wgAjaxUploadDestCheck' => $wgUseAjax && $wgAjaxUploadDestCheck,
871 'wgAjaxLicensePreview' => $wgUseAjax && $wgAjaxLicensePreview,
872 'wgEnableFirefogg' => (bool)$wgEnableFirefogg,
873 'wgUploadAutoFill' => (bool)$autofill,
874 'wgUploadSourceIds' => $this->mSourceIds
,
877 $wgOut->addScript( Skin
::makeVariablesScript( $scriptVars ) );
879 if ( $wgEnableJS2system ) {
880 //js2version of upload page:
881 $wgOut->addScriptClass( 'uploadPage' );
883 //legacy upload code:
884 $wgOut->addScriptFile( 'upload.js' );
885 $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
889 function trySubmit() {
898 class UploadSourceField
extends HTMLTextField
{
899 function getLabelHtml() {
900 $id = "wpSourceType{$this->mParams['upload-type']}";
901 $label = Html
::rawElement( 'label', array( 'for' => $id ), $this->mLabel
);
903 if ( !empty( $this->mParams
['radio'] ) ) {
905 'name' => 'wpSourceType',
908 'value' => $this->mParams
['upload-type'],
910 if ( !empty( $this->mParams
['checked'] ) )
911 $attribs['checked'] = 'checked';
912 $label .= Html
::element( 'input', $attribs );
915 return Html
::rawElement( 'td', array( 'class' => 'mw-label' ), $label );
918 return isset( $this->mParams
['size'] )
919 ?
$this->mParams
['size']
926 * TODO: This can be migrated to JS only
928 class UploadAjaxLicensePreview
extends HTMLFormField
{
929 public function getTableRow( $value ) {
930 return "<tr><td></td><td id=\"mw-license-preview\"></td></tr>\n";
932 public function getInputHTML( $value ) {