32use Wikimedia\RequestTimeout\TimeoutException;
85 $services = MediaWikiServices::getInstance();
86 if ( !$linkRenderer ) {
87 $linkRenderer = $services->getLinkRenderer();
90 $localRepo = $services->getRepoGroup()->getLocalRepo();
92 if ( !$contentLanguage ) {
93 $contentLanguage = $services->getContentLanguage();
96 $nsInfo = $services->getNamespaceInfo();
98 $this->localRepo = $localRepo;
99 $this->contentLanguage = $contentLanguage;
100 $this->nsInfo = $nsInfo;
101 $this->hookRunner =
new HookRunner( $hookContainer ?? $services->getHookContainer() );
103 $this->mWatch = !empty( $options[
'watch'] );
104 $this->mForReUpload = !empty( $options[
'forreupload'] );
105 $this->mSessionKey = $options[
'sessionkey'] ??
'';
106 $this->mHideIgnoreWarning = !empty( $options[
'hideignorewarning'] );
107 $this->mDestWarningAck = !empty( $options[
'destwarningack'] );
108 $this->mDestFile = $options[
'destfile'] ??
'';
110 $this->mComment = $options[
'description'] ??
'';
112 $this->mTextTop = $options[
'texttop'] ??
'';
114 $this->mTextAfterSummary = $options[
'textaftersummary'] ??
'';
117 $descriptor = $sourceDescriptor
121 $this->hookRunner->onUploadFormInitDescriptor( $descriptor );
122 parent::__construct( $descriptor, $this->
getContext(),
'upload' );
124 # Add a link to edit MediaWiki:Licenses
125 if ( $this->
getAuthority()->isAllowed(
'editinterface' ) ) {
126 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
127 $licensesLink = $linkRenderer->makeKnownLink(
128 $this->
msg(
'licenses' )->inContentLanguage()->
getTitle(),
129 $this->
msg(
'licenses-edit' )->text(),
131 [
'action' =>
'edit' ]
133 $editLicenses =
'<p class="mw-upload-editlicenses">' . $licensesLink .
'</p>';
137 # Set some form properties
140 # Used message keys: 'accesskey-upload', 'tooltip-upload'
142 $this->
setId(
'mw-upload-form' );
144 # Build a list of IDs for javascript insertion
145 $this->mSourceIds = [];
146 foreach ( $sourceDescriptor as $field ) {
147 if ( !empty( $field[
'id'] ) ) {
148 $this->mSourceIds[] = $field[
'id'];
160 if ( $this->mSessionKey ) {
164 'default' => $this->mSessionKey,
168 'default' =>
'Stash',
175 && $this->
getConfig()->get( MainConfigNames::CopyUploadsFromSpecialUpload );
176 $radio = $canUploadByUrl;
177 $selectedSourceType = strtolower( $this->
getRequest()->getText(
'wpSourceType',
'File' ) );
180 if ( $this->mTextTop ) {
181 $descriptor[
'UploadFormTextTop'] = [
183 'section' =>
'source',
184 'default' => $this->mTextTop,
189 $this->mMaxUploadSize[
'file'] = min(
190 UploadBase::getMaxUploadSize(
'file' ),
191 UploadBase::getMaxPhpUploadSize()
194 $help = $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'file'] )->parse();
198 if ( $canUploadByUrl ) {
199 $help .= $this->
msg(
'word-separator' )->escaped();
200 $help .= $this->
msg(
'upload_source_file' )->parse();
203 $descriptor[
'UploadFile'] = [
204 'class' => UploadSourceField::class,
205 'section' =>
'source',
207 'id' =>
'wpUploadFile',
208 'radio-id' =>
'wpSourceTypeFile',
209 'label-message' =>
'sourcefilename',
210 'upload-type' =>
'File',
213 'checked' => $selectedSourceType ==
'file',
216 if ( $canUploadByUrl ) {
217 $this->mMaxUploadSize[
'url'] = UploadBase::getMaxUploadSize(
'url' );
218 $descriptor[
'UploadFileURL'] = [
219 'class' => UploadSourceField::class,
220 'section' =>
'source',
221 'id' =>
'wpUploadFileURL',
222 'radio-id' =>
'wpSourceTypeurl',
223 'label-message' =>
'sourceurl',
224 'upload-type' =>
'url',
226 'help' => $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'url'] )->parse() .
227 $this->
msg(
'word-separator' )->escaped() .
228 $this->
msg(
'upload_source_url' )->parse(),
229 'checked' => $selectedSourceType ==
'url',
232 $this->hookRunner->onUploadFormSourceDescriptors(
233 $descriptor, $radio, $selectedSourceType );
235 $descriptor[
'Extensions'] = [
237 'section' =>
'source',
251 # Print a list of allowed file extensions, if so configured. We ignore
252 # MIME type here, it's incomprehensible to most people and too long.
255 if ( $config->get( MainConfigNames::CheckFileExtensions ) ) {
256 $fileExtensions = array_unique( $config->get( MainConfigNames::FileExtensions ) );
257 if ( $config->get( MainConfigNames::StrictFileExtensions ) ) {
258 # Everything not permitted is banned
260 '<div id="mw-upload-permitted">' .
261 $this->
msg(
'upload-permitted' )
262 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
263 ->numParams( count( $fileExtensions ) )
267 # We have to list both preferred and prohibited
268 $prohibitedExtensions =
269 array_unique( $config->get( MainConfigNames::ProhibitedFileExtensions ) );
271 '<div id="mw-upload-preferred">' .
272 $this->
msg(
'upload-preferred' )
273 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
274 ->numParams( count( $fileExtensions ) )
277 '<div id="mw-upload-prohibited">' .
278 $this->
msg(
'upload-prohibited' )
279 ->params( $this->
getLanguage()->commaList( $prohibitedExtensions ) )
280 ->numParams( count( $prohibitedExtensions ) )
285 # Everything is permitted.
286 $extensionsList =
'';
289 return $extensionsList;
300 if ( $this->mSessionKey ) {
301 $stash = $this->localRepo->getUploadStash( $this->
getUser() );
303 $file = $stash->getFile( $this->mSessionKey );
304 }
catch ( TimeoutException $e ) {
306 }
catch ( Exception $e ) {
310 $mto = $file->transform( [
'width' => 120 ] );
313 '<div class="thumb t' .
314 $this->contentLanguage->alignEnd() .
'">' .
315 Html::element(
'img', [
316 'src' => $mto->getUrl(),
317 'class' =>
'thumbimage',
318 ] ) .
'</div>',
'description' );
326 'section' =>
'description',
327 'id' =>
'wpDestFile',
328 'label-message' =>
'destfilename',
330 'default' => $this->mDestFile,
331 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
332 'nodata' => strval( $this->mDestFile ) !==
'',
334 'UploadDescription' => [
335 'type' => $this->mForReUpload
338 'section' =>
'description',
339 'id' =>
'wpUploadDescription',
340 'label-message' => $this->mForReUpload
341 ?
'filereuploadsummary'
342 :
'fileuploadsummary',
343 'default' => $this->mComment,
346 if ( $this->mTextAfterSummary ) {
347 $descriptor[
'UploadFormTextAfterSummary'] = [
349 'section' =>
'description',
350 'default' => $this->mTextAfterSummary,
357 'type' =>
'edittools',
358 'section' =>
'description',
359 'message' =>
'edittools-upload',
363 if ( $this->mForReUpload ) {
364 $descriptor[
'DestFile'][
'readonly'] =
true;
365 $descriptor[
'UploadDescription'][
'size'] = 60;
367 $descriptor[
'License'] = [
369 'class' => Licenses::class,
370 'section' =>
'description',
372 'label-message' =>
'license',
374 $descriptor[
'UploadDescription'][
'rows'] = 8;
377 if ( $config->get( MainConfigNames::UseCopyrightUpload ) ) {
378 $descriptor[
'UploadCopyStatus'] = [
380 'section' =>
'description',
381 'id' =>
'wpUploadCopyStatus',
382 'label-message' =>
'filestatus',
384 $descriptor[
'UploadSource'] = [
386 'section' =>
'description',
387 'id' =>
'wpUploadSource',
388 'label-message' =>
'filesource',
403 if ( $user->isRegistered() ) {
407 'id' =>
'wpWatchthis',
408 'label-message' =>
'watchthisupload',
409 'section' =>
'options',
410 'default' => $this->mWatch,
414 if ( !$this->mHideIgnoreWarning ) {
415 $descriptor[
'IgnoreWarning'] = [
417 'id' =>
'wpIgnoreWarning',
418 'label-message' =>
'ignorewarnings',
419 'section' =>
'options',
423 $descriptor[
'DestFileWarningAck'] = [
425 'id' =>
'wpDestFileWarningAck',
426 'default' => $this->mDestWarningAck ?
'1' :
'',
429 if ( $this->mForReUpload ) {
430 $descriptor[
'ForReUpload'] = [
432 'id' =>
'wpForReUpload',
446 return parent::show();
455 $this->mMaxUploadSize[
'*'] = UploadBase::getMaxUploadSize();
458 'wgAjaxLicensePreview' => $config->get( MainConfigNames::AjaxLicensePreview ),
459 'wgUploadAutoFill' => !$this->mForReUpload &&
462 $this->mDestFile ===
'',
463 'wgUploadSourceIds' => $this->mSourceIds,
464 'wgCheckFileExtensions' => $config->get( MainConfigNames::CheckFileExtensions ),
465 'wgStrictFileExtensions' => $config->get( MainConfigNames::StrictFileExtensions ),
466 'wgFileExtensions' =>
467 array_values( array_unique( $config->get( MainConfigNames::FileExtensions ) ) ),
468 'wgMaxUploadSize' => $this->mMaxUploadSize,
469 'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
473 $out->addJsConfigVars( $scriptVars );
476 'mediawiki.special.upload',
Base class for language-specific code.
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.