27use Wikimedia\RequestTimeout\TimeoutException;
75 if ( !$linkRenderer ) {
76 $linkRenderer = $services->getLinkRenderer();
79 $localRepo = $services->getRepoGroup()->getLocalRepo();
82 $nsInfo = $services->getNamespaceInfo();
85 $this->hookRunner =
new HookRunner( $hookContainer ?? $services->getHookContainer() );
87 $this->mWatch = !empty( $options[
'watch'] );
88 $this->mForReUpload = !empty( $options[
'forreupload'] );
89 $this->mSessionKey = $options[
'sessionkey'] ??
'';
90 $this->mHideIgnoreWarning = !empty( $options[
'hideignorewarning'] );
91 $this->mDestWarningAck = !empty( $options[
'destwarningack'] );
92 $this->mDestFile = $options[
'destfile'] ??
'';
94 $this->mComment = $options[
'description'] ??
'';
96 $this->mTextTop = $options[
'texttop'] ??
'';
98 $this->mTextAfterSummary = $options[
'textaftersummary'] ??
'';
101 $descriptor = $sourceDescriptor
105 $this->hookRunner->onUploadFormInitDescriptor( $descriptor );
106 parent::__construct( $descriptor, $this->
getContext(),
'upload' );
108 # Add a link to edit MediaWiki:Licenses
109 if ( $this->
getAuthority()->isAllowed(
'editinterface' ) ) {
110 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
111 $licensesLink = $linkRenderer->makeKnownLink(
112 $this->
msg(
'licenses' )->inContentLanguage()->
getTitle(),
113 $this->
msg(
'licenses-edit' )->text(),
115 [
'action' =>
'edit' ]
117 $editLicenses =
'<p class="mw-upload-editlicenses">' . $licensesLink .
'</p>';
121 # Set some form properties
124 # Used message keys: 'accesskey-upload', 'tooltip-upload'
126 $this->
setId(
'mw-upload-form' );
128 # Build a list of IDs for javascript insertion
129 $this->mSourceIds = [];
130 foreach ( $sourceDescriptor as $field ) {
131 if ( !empty( $field[
'id'] ) ) {
132 $this->mSourceIds[] = $field[
'id'];
144 if ( $this->mSessionKey ) {
152 'default' =>
'Stash',
157 $canUploadByUrl = UploadFromUrl::isEnabled()
158 && ( UploadFromUrl::isAllowed( $this->
getAuthority() ) === true )
160 $radio = $canUploadByUrl;
161 $selectedSourceType = strtolower( $this->
getRequest()->getText(
'wpSourceType',
'File' ) );
164 if ( $this->mTextTop ) {
165 $descriptor[
'UploadFormTextTop'] = [
167 'section' =>
'source',
173 $this->mMaxUploadSize[
'file'] = min(
174 UploadBase::getMaxUploadSize(
'file' ),
175 UploadBase::getMaxPhpUploadSize()
178 $help = $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'file'] )->parse();
182 if ( $canUploadByUrl ) {
183 $help .= $this->
msg(
'word-separator' )->escaped();
184 $help .= $this->
msg(
'upload_source_file' )->parse();
187 $descriptor[
'UploadFile'] = [
188 'class' => UploadSourceField::class,
189 'section' =>
'source',
191 'id' =>
'wpUploadFile',
192 'radio-id' =>
'wpSourceTypeFile',
193 'label-message' =>
'sourcefilename',
194 'upload-type' =>
'File',
197 'checked' => $selectedSourceType ==
'file',
200 if ( $canUploadByUrl ) {
201 $this->mMaxUploadSize[
'url'] = UploadBase::getMaxUploadSize(
'url' );
202 $descriptor[
'UploadFileURL'] = [
203 'class' => UploadSourceField::class,
204 'section' =>
'source',
205 'id' =>
'wpUploadFileURL',
206 'radio-id' =>
'wpSourceTypeurl',
207 'label-message' =>
'sourceurl',
208 'upload-type' =>
'url',
210 'help-raw' => $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'url'] )->parse() .
211 $this->
msg(
'word-separator' )->escaped() .
212 $this->
msg(
'upload_source_url' )->parse(),
213 'checked' => $selectedSourceType ==
'url',
216 $this->hookRunner->onUploadFormSourceDescriptors(
217 $descriptor, $radio, $selectedSourceType );
219 $descriptor[
'Extensions'] = [
221 'section' =>
'source',
235 # Print a list of allowed file extensions, if so configured. We ignore
236 # MIME type here, it's incomprehensible to most people and too long.
242 # Everything not permitted is banned
244 '<div id="mw-upload-permitted">' .
245 $this->
msg(
'upload-permitted' )
246 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
247 ->numParams( count( $fileExtensions ) )
251 # We have to list both preferred and prohibited
252 $prohibitedExtensions =
255 '<div id="mw-upload-preferred">' .
256 $this->
msg(
'upload-preferred' )
257 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
258 ->numParams( count( $fileExtensions ) )
261 '<div id="mw-upload-prohibited">' .
262 $this->
msg(
'upload-prohibited' )
263 ->params( $this->
getLanguage()->commaList( $prohibitedExtensions ) )
264 ->numParams( count( $prohibitedExtensions ) )
269 # Everything is permitted.
270 $extensionsList =
'';
273 return $extensionsList;
284 if ( $this->mSessionKey ) {
285 $stash = $this->localRepo->getUploadStash( $this->
getUser() );
287 $file = $stash->getFile( $this->mSessionKey );
288 }
catch ( TimeoutException $e ) {
290 }
catch ( Exception ) {
294 $mto = $file->transform( [
'width' => 120 ] );
295 if ( $mto && !$mto->isError() ) {
300 'typeof' =>
'mw:File',
301 'class' =>
'mw-upload-halign-end',
314 'section' =>
'description',
315 'id' =>
'wpDestFile',
316 'label-message' =>
'destfilename',
319 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
320 'nodata' => strval( $this->mDestFile ) !==
'',
322 'UploadDescription' => [
323 'type' => $this->mForReUpload
326 'section' =>
'description',
327 'id' =>
'wpUploadDescription',
328 'label-message' => $this->mForReUpload
329 ?
'filereuploadsummary'
330 :
'fileuploadsummary',
334 if ( $this->mTextAfterSummary ) {
335 $descriptor[
'UploadFormTextAfterSummary'] = [
337 'section' =>
'description',
345 'type' =>
'edittools',
346 'section' =>
'description',
347 'message' =>
'edittools-upload',
351 if ( $this->mForReUpload ) {
352 $descriptor[
'DestFile'][
'readonly'] =
true;
353 $descriptor[
'UploadDescription'][
'size'] = 60;
355 $descriptor[
'License'] = [
357 'class' => Licenses::class,
358 'section' =>
'description',
360 'label-message' =>
'license',
362 $descriptor[
'UploadDescription'][
'rows'] = 8;
366 $descriptor[
'UploadCopyStatus'] = [
368 'section' =>
'description',
369 'id' =>
'wpUploadCopyStatus',
370 'label-message' =>
'filestatus',
372 $descriptor[
'UploadSource'] = [
374 'section' =>
'description',
375 'id' =>
'wpUploadSource',
376 'label-message' =>
'filesource',
391 if ( $user->isRegistered() ) {
395 'id' =>
'wpWatchthis',
396 'label-message' =>
'watchthisupload',
397 'section' =>
'options',
402 if ( !$this->mHideIgnoreWarning ) {
403 $descriptor[
'IgnoreWarning'] = [
405 'id' =>
'wpIgnoreWarning',
406 'label-message' =>
'ignorewarnings',
407 'section' =>
'options',
411 $descriptor[
'DestFileWarningAck'] = [
413 'id' =>
'wpDestFileWarningAck',
414 'default' => $this->mDestWarningAck ?
'1' :
'',
417 if ( $this->mForReUpload ) {
418 $descriptor[
'ForReUpload'] = [
420 'id' =>
'wpForReUpload',
434 return parent::show();
443 $this->mMaxUploadSize[
'*'] = UploadBase::getMaxUploadSize();
447 'wgUploadAutoFill' => !$this->mForReUpload &&
450 $this->mDestFile ===
'',
454 'wgFileExtensions' =>
461 $out->addJsConfigVars( $scriptVars );
464 'mediawiki.special.upload',
479class_alias( UploadForm::class,
'UploadForm' );
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.
const AjaxLicensePreview
Name constant for the AjaxLicensePreview setting, for use with Config::get()
const ProhibitedFileExtensions
Name constant for the ProhibitedFileExtensions setting, for use with Config::get()
const StrictFileExtensions
Name constant for the StrictFileExtensions setting, for use with Config::get()
const CopyUploadsFromSpecialUpload
Name constant for the CopyUploadsFromSpecialUpload setting, for use with Config::get()
const UseCopyrightUpload
Name constant for the UseCopyrightUpload setting, for use with Config::get()
const FileExtensions
Name constant for the FileExtensions setting, for use with Config::get()
const CheckFileExtensions
Name constant for the CheckFileExtensions setting, for use with Config::get()
Interface for objects which can provide a MediaWiki context on request.