setContext( $context ); } $services = MediaWikiServices::getInstance(); if ( !$linkRenderer ) { $linkRenderer = $services->getLinkRenderer(); } if ( !$localRepo ) { $localRepo = $services->getRepoGroup()->getLocalRepo(); } if ( !$contentLanguage ) { $contentLanguage = $services->getContentLanguage(); } if ( !$nsInfo ) { $nsInfo = $services->getNamespaceInfo(); } $this->localRepo = $localRepo; $this->contentLanguage = $contentLanguage; $this->nsInfo = $nsInfo; $this->mWatch = !empty( $options['watch'] ); $this->mForReUpload = !empty( $options['forreupload'] ); $this->mSessionKey = $options['sessionkey'] ?? ''; $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] ); $this->mDestWarningAck = !empty( $options['destwarningack'] ); $this->mDestFile = $options['destfile'] ?? ''; $this->mComment = $options['description'] ?? ''; $this->mTextTop = $options['texttop'] ?? ''; $this->mTextAfterSummary = $options['textaftersummary'] ?? ''; $sourceDescriptor = $this->getSourceSection(); $descriptor = $sourceDescriptor + $this->getDescriptionSection() + $this->getOptionsSection(); $this->getHookRunner()->onUploadFormInitDescriptor( $descriptor ); parent::__construct( $descriptor, $context, 'upload' ); # Add a link to edit MediaWiki:Licenses if ( $this->getAuthority()->isAllowed( 'editinterface' ) ) { $this->getOutput()->addModuleStyles( 'mediawiki.special' ); $licensesLink = $linkRenderer->makeKnownLink( $this->msg( 'licenses' )->inContentLanguage()->getTitle(), $this->msg( 'licenses-edit' )->text(), [], [ 'action' => 'edit' ] ); $editLicenses = '
' . $licensesLink . '
'; $this->addFooterText( $editLicenses, 'description' ); } # Set some form properties $this->setSubmitTextMsg( 'uploadbtn' ); $this->setSubmitName( 'wpUpload' ); # Used message keys: 'accesskey-upload', 'tooltip-upload' $this->setSubmitTooltip( 'upload' ); $this->setId( 'mw-upload-form' ); # Build a list of IDs for javascript insertion $this->mSourceIds = []; foreach ( $sourceDescriptor as $field ) { if ( !empty( $field['id'] ) ) { $this->mSourceIds[] = $field['id']; } } } /** * Get the descriptor of the fieldset that contains the file source * selection. The section is 'source' * * @return array Descriptor array */ protected function getSourceSection() { if ( $this->mSessionKey ) { return [ 'SessionKey' => [ 'type' => 'hidden', 'default' => $this->mSessionKey, ], 'SourceType' => [ 'type' => 'hidden', 'default' => 'Stash', ], ]; } $canUploadByUrl = UploadFromUrl::isEnabled() && ( UploadFromUrl::isAllowed( $this->getUser() ) === true ) && $this->getConfig()->get( 'CopyUploadsFromSpecialUpload' ); $radio = $canUploadByUrl; $selectedSourceType = strtolower( $this->getRequest()->getText( 'wpSourceType', 'File' ) ); $descriptor = []; if ( $this->mTextTop ) { $descriptor['UploadFormTextTop'] = [ // @phan-suppress-next-line SecurityCheck-XSS mTextTop is raw html 'type' => 'info', 'section' => 'source', 'default' => $this->mTextTop, 'raw' => true, ]; } $this->mMaxUploadSize['file'] = min( UploadBase::getMaxUploadSize( 'file' ), UploadBase::getMaxPhpUploadSize() ); $help = $this->msg( 'upload-maxfilesize', $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['file'] ) )->parse(); // If the user can also upload by URL, there are 2 different file size limits. // This extra message helps stress which limit corresponds to what. if ( $canUploadByUrl ) { $help .= $this->msg( 'word-separator' )->escaped(); $help .= $this->msg( 'upload_source_file' )->parse(); } $descriptor['UploadFile'] = [ 'class' => UploadSourceField::class, 'section' => 'source', 'type' => 'file', 'id' => 'wpUploadFile', 'radio-id' => 'wpSourceTypeFile', 'label-message' => 'sourcefilename', 'upload-type' => 'File', 'radio' => &$radio, 'help' => $help, 'checked' => $selectedSourceType == 'file', ]; if ( $canUploadByUrl ) { $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize( 'url' ); $descriptor['UploadFileURL'] = [ 'class' => UploadSourceField::class, 'section' => 'source', 'id' => 'wpUploadFileURL', 'radio-id' => 'wpSourceTypeurl', 'label-message' => 'sourceurl', 'upload-type' => 'url', 'radio' => &$radio, 'help' => $this->msg( 'upload-maxfilesize', $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['url'] ) )->parse() . $this->msg( 'word-separator' )->escaped() . $this->msg( 'upload_source_url' )->parse(), 'checked' => $selectedSourceType == 'url', ]; } $this->getHookRunner()->onUploadFormSourceDescriptors( $descriptor, $radio, $selectedSourceType ); $descriptor['Extensions'] = [ 'type' => 'info', 'section' => 'source', 'default' => $this->getExtensionsMessage(), 'raw' => true, ]; return $descriptor; } /** * Get the messages indicating which extensions are preferred and prohibitted. * * @return string HTML string containing the message */ protected function getExtensionsMessage() { # Print a list of allowed file extensions, if so configured. We ignore # MIME type here, it's incomprehensible to most people and too long. $config = $this->getConfig(); if ( $config->get( 'CheckFileExtensions' ) ) { $fileExtensions = array_unique( $config->get( 'FileExtensions' ) ); if ( $config->get( 'StrictFileExtensions' ) ) { # Everything not permitted is banned $extensionsList = '