34use Wikimedia\RequestTimeout\TimeoutException;
84 $services = MediaWikiServices::getInstance();
85 if ( !$linkRenderer ) {
86 $linkRenderer = $services->getLinkRenderer();
89 $localRepo = $services->getRepoGroup()->getLocalRepo();
91 if ( !$contentLanguage ) {
92 $contentLanguage = $services->getContentLanguage();
95 $nsInfo = $services->getNamespaceInfo();
97 $this->localRepo = $localRepo;
98 $this->contentLanguage = $contentLanguage;
99 $this->nsInfo = $nsInfo;
100 $this->hookRunner =
new HookRunner( $hookContainer ?? $services->getHookContainer() );
102 $this->mWatch = !empty( $options[
'watch'] );
103 $this->mForReUpload = !empty( $options[
'forreupload'] );
104 $this->mSessionKey = $options[
'sessionkey'] ??
'';
105 $this->mHideIgnoreWarning = !empty( $options[
'hideignorewarning'] );
106 $this->mDestWarningAck = !empty( $options[
'destwarningack'] );
107 $this->mDestFile = $options[
'destfile'] ??
'';
109 $this->mComment = $options[
'description'] ??
'';
111 $this->mTextTop = $options[
'texttop'] ??
'';
113 $this->mTextAfterSummary = $options[
'textaftersummary'] ??
'';
116 $descriptor = $sourceDescriptor
120 $this->hookRunner->onUploadFormInitDescriptor( $descriptor );
121 parent::__construct( $descriptor, $this->
getContext(),
'upload' );
123 # Add a link to edit MediaWiki:Licenses
124 if ( $this->
getAuthority()->isAllowed(
'editinterface' ) ) {
125 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
126 $licensesLink = $linkRenderer->makeKnownLink(
127 $this->
msg(
'licenses' )->inContentLanguage()->
getTitle(),
128 $this->
msg(
'licenses-edit' )->text(),
130 [
'action' =>
'edit' ]
132 $editLicenses =
'<p class="mw-upload-editlicenses">' . $licensesLink .
'</p>';
136 # Set some form properties
139 # Used message keys: 'accesskey-upload', 'tooltip-upload'
141 $this->
setId(
'mw-upload-form' );
143 # Build a list of IDs for javascript insertion
144 $this->mSourceIds = [];
145 foreach ( $sourceDescriptor as $field ) {
146 if ( !empty( $field[
'id'] ) ) {
147 $this->mSourceIds[] = $field[
'id'];
159 if ( $this->mSessionKey ) {
163 'default' => $this->mSessionKey,
167 'default' =>
'Stash',
172 $canUploadByUrl = UploadFromUrl::isEnabled()
173 && ( UploadFromUrl::isAllowed( $this->
getAuthority() ) === true )
174 && $this->
getConfig()->get( MainConfigNames::CopyUploadsFromSpecialUpload );
175 $radio = $canUploadByUrl;
176 $selectedSourceType = strtolower( $this->
getRequest()->getText(
'wpSourceType',
'File' ) );
179 if ( $this->mTextTop ) {
180 $descriptor[
'UploadFormTextTop'] = [
182 'section' =>
'source',
183 'default' => $this->mTextTop,
188 $this->mMaxUploadSize[
'file'] = min(
189 UploadBase::getMaxUploadSize(
'file' ),
190 UploadBase::getMaxPhpUploadSize()
193 $help = $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'file'] )->parse();
197 if ( $canUploadByUrl ) {
198 $help .= $this->
msg(
'word-separator' )->escaped();
199 $help .= $this->
msg(
'upload_source_file' )->parse();
202 $descriptor[
'UploadFile'] = [
203 'class' => UploadSourceField::class,
204 'section' =>
'source',
206 'id' =>
'wpUploadFile',
207 'radio-id' =>
'wpSourceTypeFile',
208 'label-message' =>
'sourcefilename',
209 'upload-type' =>
'File',
212 'checked' => $selectedSourceType ==
'file',
215 if ( $canUploadByUrl ) {
216 $this->mMaxUploadSize[
'url'] = UploadBase::getMaxUploadSize(
'url' );
217 $descriptor[
'UploadFileURL'] = [
218 'class' => UploadSourceField::class,
219 'section' =>
'source',
220 'id' =>
'wpUploadFileURL',
221 'radio-id' =>
'wpSourceTypeurl',
222 'label-message' =>
'sourceurl',
223 'upload-type' =>
'url',
225 'help-raw' => $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'url'] )->parse() .
226 $this->
msg(
'word-separator' )->escaped() .
227 $this->
msg(
'upload_source_url' )->parse(),
228 'checked' => $selectedSourceType ==
'url',
231 $this->hookRunner->onUploadFormSourceDescriptors(
232 $descriptor, $radio, $selectedSourceType );
234 $descriptor[
'Extensions'] = [
236 'section' =>
'source',
250 # Print a list of allowed file extensions, if so configured. We ignore
251 # MIME type here, it's incomprehensible to most people and too long.
254 if ( $config->get( MainConfigNames::CheckFileExtensions ) ) {
255 $fileExtensions = array_unique( $config->get( MainConfigNames::FileExtensions ) );
256 if ( $config->get( MainConfigNames::StrictFileExtensions ) ) {
257 # Everything not permitted is banned
259 '<div id="mw-upload-permitted">' .
260 $this->
msg(
'upload-permitted' )
261 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
262 ->numParams( count( $fileExtensions ) )
266 # We have to list both preferred and prohibited
267 $prohibitedExtensions =
268 array_unique( $config->get( MainConfigNames::ProhibitedFileExtensions ) );
270 '<div id="mw-upload-preferred">' .
271 $this->
msg(
'upload-preferred' )
272 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
273 ->numParams( count( $fileExtensions ) )
276 '<div id="mw-upload-prohibited">' .
277 $this->
msg(
'upload-prohibited' )
278 ->params( $this->
getLanguage()->commaList( $prohibitedExtensions ) )
279 ->numParams( count( $prohibitedExtensions ) )
284 # Everything is permitted.
285 $extensionsList =
'';
288 return $extensionsList;
299 if ( $this->mSessionKey ) {
300 $stash = $this->localRepo->getUploadStash( $this->
getUser() );
302 $file = $stash->getFile( $this->mSessionKey );
303 }
catch ( TimeoutException $e ) {
305 }
catch ( Exception ) {
309 $mto = $file->transform( [
'width' => 120 ] );
312 '<div class="thumb t' .
313 $this->contentLanguage->alignEnd() .
'">' .
314 Html::element(
'img', [
315 'src' => $mto->getUrl(),
316 'class' =>
'thumbimage',
317 ] ) .
'</div>',
'description' );
325 'section' =>
'description',
326 'id' =>
'wpDestFile',
327 'label-message' =>
'destfilename',
329 'default' => $this->mDestFile,
330 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
331 'nodata' => strval( $this->mDestFile ) !==
'',
333 'UploadDescription' => [
334 'type' => $this->mForReUpload
337 'section' =>
'description',
338 'id' =>
'wpUploadDescription',
339 'label-message' => $this->mForReUpload
340 ?
'filereuploadsummary'
341 :
'fileuploadsummary',
342 'default' => $this->mComment,
345 if ( $this->mTextAfterSummary ) {
346 $descriptor[
'UploadFormTextAfterSummary'] = [
348 'section' =>
'description',
349 'default' => $this->mTextAfterSummary,
356 'type' =>
'edittools',
357 'section' =>
'description',
358 'message' =>
'edittools-upload',
362 if ( $this->mForReUpload ) {
363 $descriptor[
'DestFile'][
'readonly'] =
true;
364 $descriptor[
'UploadDescription'][
'size'] = 60;
366 $descriptor[
'License'] = [
368 'class' => Licenses::class,
369 'section' =>
'description',
371 'label-message' =>
'license',
373 $descriptor[
'UploadDescription'][
'rows'] = 8;
376 if ( $config->get( MainConfigNames::UseCopyrightUpload ) ) {
377 $descriptor[
'UploadCopyStatus'] = [
379 'section' =>
'description',
380 'id' =>
'wpUploadCopyStatus',
381 'label-message' =>
'filestatus',
383 $descriptor[
'UploadSource'] = [
385 'section' =>
'description',
386 'id' =>
'wpUploadSource',
387 'label-message' =>
'filesource',
402 if ( $user->isRegistered() ) {
406 'id' =>
'wpWatchthis',
407 'label-message' =>
'watchthisupload',
408 'section' =>
'options',
409 'default' => $this->mWatch,
413 if ( !$this->mHideIgnoreWarning ) {
414 $descriptor[
'IgnoreWarning'] = [
416 'id' =>
'wpIgnoreWarning',
417 'label-message' =>
'ignorewarnings',
418 'section' =>
'options',
422 $descriptor[
'DestFileWarningAck'] = [
424 'id' =>
'wpDestFileWarningAck',
425 'default' => $this->mDestWarningAck ?
'1' :
'',
428 if ( $this->mForReUpload ) {
429 $descriptor[
'ForReUpload'] = [
431 'id' =>
'wpForReUpload',
445 return parent::show();
454 $this->mMaxUploadSize[
'*'] = UploadBase::getMaxUploadSize();
457 'wgAjaxLicensePreview' => $config->get( MainConfigNames::AjaxLicensePreview ),
458 'wgUploadAutoFill' => !$this->mForReUpload &&
461 $this->mDestFile ===
'',
462 'wgUploadSourceIds' => $this->mSourceIds,
463 'wgCheckFileExtensions' => $config->get( MainConfigNames::CheckFileExtensions ),
464 'wgStrictFileExtensions' => $config->get( MainConfigNames::StrictFileExtensions ),
465 'wgFileExtensions' =>
466 array_values( array_unique( $config->get( MainConfigNames::FileExtensions ) ) ),
467 'wgMaxUploadSize' => $this->mMaxUploadSize,
468 'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
472 $out->addJsConfigVars( $scriptVars );
475 'mediawiki.special.upload',
setContext(IContextSource $context)
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getContext()
Get the base IContextSource object.
A class containing constants representing the names of configuration variables.
Interface for objects which can provide a MediaWiki context on request.