32use Wikimedia\RequestTimeout\TimeoutException;
65 private Language $contentLanguage;
83 Language $contentLanguage =
null,
91 $services = MediaWikiServices::getInstance();
92 if ( !$linkRenderer ) {
93 $linkRenderer = $services->getLinkRenderer();
96 $localRepo = $services->getRepoGroup()->getLocalRepo();
98 if ( !$contentLanguage ) {
99 $contentLanguage = $services->getContentLanguage();
102 $nsInfo = $services->getNamespaceInfo();
104 $this->localRepo = $localRepo;
105 $this->contentLanguage = $contentLanguage;
106 $this->nsInfo = $nsInfo;
107 $this->hookRunner =
new HookRunner( $hookContainer ?? $services->getHookContainer() );
109 $this->mWatch = !empty( $options[
'watch'] );
110 $this->mForReUpload = !empty( $options[
'forreupload'] );
111 $this->mSessionKey = $options[
'sessionkey'] ??
'';
112 $this->mHideIgnoreWarning = !empty( $options[
'hideignorewarning'] );
113 $this->mDestWarningAck = !empty( $options[
'destwarningack'] );
114 $this->mDestFile = $options[
'destfile'] ??
'';
116 $this->mComment = $options[
'description'] ??
'';
118 $this->mTextTop = $options[
'texttop'] ??
'';
120 $this->mTextAfterSummary = $options[
'textaftersummary'] ??
'';
123 $descriptor = $sourceDescriptor
127 $this->hookRunner->onUploadFormInitDescriptor( $descriptor );
128 parent::__construct( $descriptor, $this->
getContext(),
'upload' );
130 # Add a link to edit MediaWiki:Licenses
131 if ( $this->
getAuthority()->isAllowed(
'editinterface' ) ) {
132 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
133 $licensesLink = $linkRenderer->makeKnownLink(
134 $this->
msg(
'licenses' )->inContentLanguage()->
getTitle(),
135 $this->
msg(
'licenses-edit' )->text(),
137 [
'action' =>
'edit' ]
139 $editLicenses =
'<p class="mw-upload-editlicenses">' . $licensesLink .
'</p>';
143 # Set some form properties
146 # Used message keys: 'accesskey-upload', 'tooltip-upload'
148 $this->
setId(
'mw-upload-form' );
150 # Build a list of IDs for javascript insertion
151 $this->mSourceIds = [];
152 foreach ( $sourceDescriptor as $field ) {
153 if ( !empty( $field[
'id'] ) ) {
154 $this->mSourceIds[] = $field[
'id'];
166 if ( $this->mSessionKey ) {
170 'default' => $this->mSessionKey,
174 'default' =>
'Stash',
181 && $this->
getConfig()->get( MainConfigNames::CopyUploadsFromSpecialUpload );
182 $radio = $canUploadByUrl;
183 $selectedSourceType = strtolower( $this->
getRequest()->getText(
'wpSourceType',
'File' ) );
186 if ( $this->mTextTop ) {
187 $descriptor[
'UploadFormTextTop'] = [
189 'section' =>
'source',
190 'default' => $this->mTextTop,
195 $this->mMaxUploadSize[
'file'] = min(
196 UploadBase::getMaxUploadSize(
'file' ),
197 UploadBase::getMaxPhpUploadSize()
200 $help = $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'file'] )->parse();
204 if ( $canUploadByUrl ) {
205 $help .= $this->
msg(
'word-separator' )->escaped();
206 $help .= $this->
msg(
'upload_source_file' )->parse();
209 $descriptor[
'UploadFile'] = [
210 'class' => UploadSourceField::class,
211 'section' =>
'source',
213 'id' =>
'wpUploadFile',
214 'radio-id' =>
'wpSourceTypeFile',
215 'label-message' =>
'sourcefilename',
216 'upload-type' =>
'File',
219 'checked' => $selectedSourceType ==
'file',
222 if ( $canUploadByUrl ) {
223 $this->mMaxUploadSize[
'url'] = UploadBase::getMaxUploadSize(
'url' );
224 $descriptor[
'UploadFileURL'] = [
225 'class' => UploadSourceField::class,
226 'section' =>
'source',
227 'id' =>
'wpUploadFileURL',
228 'radio-id' =>
'wpSourceTypeurl',
229 'label-message' =>
'sourceurl',
230 'upload-type' =>
'url',
232 'help' => $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'url'] )->parse() .
233 $this->
msg(
'word-separator' )->escaped() .
234 $this->
msg(
'upload_source_url' )->parse(),
235 'checked' => $selectedSourceType ==
'url',
238 $this->hookRunner->onUploadFormSourceDescriptors(
239 $descriptor, $radio, $selectedSourceType );
241 $descriptor[
'Extensions'] = [
243 'section' =>
'source',
257 # Print a list of allowed file extensions, if so configured. We ignore
258 # MIME type here, it's incomprehensible to most people and too long.
261 if ( $config->get( MainConfigNames::CheckFileExtensions ) ) {
262 $fileExtensions = array_unique( $config->get( MainConfigNames::FileExtensions ) );
263 if ( $config->get( MainConfigNames::StrictFileExtensions ) ) {
264 # Everything not permitted is banned
266 '<div id="mw-upload-permitted">' .
267 $this->
msg(
'upload-permitted' )
268 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
269 ->numParams( count( $fileExtensions ) )
273 # We have to list both preferred and prohibited
274 $prohibitedExtensions =
275 array_unique( $config->get( MainConfigNames::ProhibitedFileExtensions ) );
277 '<div id="mw-upload-preferred">' .
278 $this->
msg(
'upload-preferred' )
279 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
280 ->numParams( count( $fileExtensions ) )
283 '<div id="mw-upload-prohibited">' .
284 $this->
msg(
'upload-prohibited' )
285 ->params( $this->
getLanguage()->commaList( $prohibitedExtensions ) )
286 ->numParams( count( $prohibitedExtensions ) )
291 # Everything is permitted.
292 $extensionsList =
'';
295 return $extensionsList;
306 if ( $this->mSessionKey ) {
307 $stash = $this->localRepo->getUploadStash( $this->
getUser() );
309 $file = $stash->getFile( $this->mSessionKey );
310 }
catch ( TimeoutException $e ) {
312 }
catch ( Exception $e ) {
316 $mto = $file->transform( [
'width' => 120 ] );
319 '<div class="thumb t' .
320 $this->contentLanguage->alignEnd() .
'">' .
321 Html::element(
'img', [
322 'src' => $mto->getUrl(),
323 'class' =>
'thumbimage',
324 ] ) .
'</div>',
'description' );
332 'section' =>
'description',
333 'id' =>
'wpDestFile',
334 'label-message' =>
'destfilename',
336 'default' => $this->mDestFile,
337 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
338 'nodata' => strval( $this->mDestFile ) !==
'',
340 'UploadDescription' => [
341 'type' => $this->mForReUpload
344 'section' =>
'description',
345 'id' =>
'wpUploadDescription',
346 'label-message' => $this->mForReUpload
347 ?
'filereuploadsummary'
348 :
'fileuploadsummary',
349 'default' => $this->mComment,
352 if ( $this->mTextAfterSummary ) {
353 $descriptor[
'UploadFormTextAfterSummary'] = [
355 'section' =>
'description',
356 'default' => $this->mTextAfterSummary,
363 'type' =>
'edittools',
364 'section' =>
'description',
365 'message' =>
'edittools-upload',
369 if ( $this->mForReUpload ) {
370 $descriptor[
'DestFile'][
'readonly'] =
true;
371 $descriptor[
'UploadDescription'][
'size'] = 60;
373 $descriptor[
'License'] = [
375 'class' => Licenses::class,
376 'section' =>
'description',
378 'label-message' =>
'license',
380 $descriptor[
'UploadDescription'][
'rows'] = 8;
383 if ( $config->get( MainConfigNames::UseCopyrightUpload ) ) {
384 $descriptor[
'UploadCopyStatus'] = [
386 'section' =>
'description',
387 'id' =>
'wpUploadCopyStatus',
388 'label-message' =>
'filestatus',
390 $descriptor[
'UploadSource'] = [
392 'section' =>
'description',
393 'id' =>
'wpUploadSource',
394 'label-message' =>
'filesource',
409 if ( $user->isRegistered() ) {
413 'id' =>
'wpWatchthis',
414 'label-message' =>
'watchthisupload',
415 'section' =>
'options',
416 'default' => $this->mWatch,
420 if ( !$this->mHideIgnoreWarning ) {
421 $descriptor[
'IgnoreWarning'] = [
423 'id' =>
'wpIgnoreWarning',
424 'label-message' =>
'ignorewarnings',
425 'section' =>
'options',
429 $descriptor[
'DestFileWarningAck'] = [
431 'id' =>
'wpDestFileWarningAck',
432 'default' => $this->mDestWarningAck ?
'1' :
'',
435 if ( $this->mForReUpload ) {
436 $descriptor[
'ForReUpload'] = [
438 'id' =>
'wpForReUpload',
452 return parent::show();
461 $this->mMaxUploadSize[
'*'] = UploadBase::getMaxUploadSize();
464 'wgAjaxLicensePreview' => $config->get( MainConfigNames::AjaxLicensePreview ),
465 'wgUploadAutoFill' => !$this->mForReUpload &&
468 $this->mDestFile ===
'',
469 'wgUploadSourceIds' => $this->mSourceIds,
470 'wgCheckFileExtensions' => $config->get( MainConfigNames::CheckFileExtensions ),
471 'wgStrictFileExtensions' => $config->get( MainConfigNames::StrictFileExtensions ),
472 'wgFileExtensions' =>
473 array_values( array_unique( $config->get( MainConfigNames::FileExtensions ) ) ),
474 'wgMaxUploadSize' => $this->mMaxUploadSize,
475 'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
479 $out->addJsConfigVars( $scriptVars );
482 'mediawiki.special.upload',
Local repository that stores files in the local filesystem and registers them in the wiki's own datab...
setContext(IContextSource $context)
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
A class containing constants representing the names of configuration variables.
static isAllowed(Authority $performer)
Checks if the user is allowed to use the upload-by-URL feature.
static isEnabled()
Checks if the upload from URL feature is enabled.
Interface for objects which can provide a MediaWiki context on request.