24 use Wikimedia\RequestTimeout\TimeoutException;
79 $services = MediaWikiServices::getInstance();
80 if ( !$linkRenderer ) {
81 $linkRenderer = $services->getLinkRenderer();
84 $localRepo = $services->getRepoGroup()->getLocalRepo();
90 $nsInfo = $services->getNamespaceInfo();
96 $this->mWatch = !empty( $options[
'watch'] );
97 $this->mForReUpload = !empty( $options[
'forreupload'] );
98 $this->mSessionKey = $options[
'sessionkey'] ??
'';
99 $this->mHideIgnoreWarning = !empty( $options[
'hideignorewarning'] );
100 $this->mDestWarningAck = !empty( $options[
'destwarningack'] );
101 $this->mDestFile = $options[
'destfile'] ??
'';
103 $this->mComment = $options[
'description'] ??
'';
105 $this->mTextTop = $options[
'texttop'] ??
'';
107 $this->mTextAfterSummary = $options[
'textaftersummary'] ??
'';
110 $descriptor = $sourceDescriptor
114 $this->getHookRunner()->onUploadFormInitDescriptor( $descriptor );
115 parent::__construct( $descriptor, $this->
getContext(),
'upload' );
117 # Add a link to edit MediaWiki:Licenses
118 if ( $this->
getAuthority()->isAllowed(
'editinterface' ) ) {
119 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
120 $licensesLink = $linkRenderer->makeKnownLink(
121 $this->
msg(
'licenses' )->inContentLanguage()->
getTitle(),
122 $this->
msg(
'licenses-edit' )->text(),
124 [
'action' =>
'edit' ]
126 $editLicenses =
'<p class="mw-upload-editlicenses">' . $licensesLink .
'</p>';
130 # Set some form properties
133 # Used message keys: 'accesskey-upload', 'tooltip-upload'
135 $this->
setId(
'mw-upload-form' );
137 # Build a list of IDs for javascript insertion
138 $this->mSourceIds = [];
139 foreach ( $sourceDescriptor as $field ) {
140 if ( !empty( $field[
'id'] ) ) {
141 $this->mSourceIds[] = $field[
'id'];
153 if ( $this->mSessionKey ) {
161 'default' =>
'Stash',
168 && $this->
getConfig()->get( MainConfigNames::CopyUploadsFromSpecialUpload );
169 $radio = $canUploadByUrl;
170 $selectedSourceType = strtolower( $this->
getRequest()->getText(
'wpSourceType',
'File' ) );
173 if ( $this->mTextTop ) {
174 $descriptor[
'UploadFormTextTop'] = [
177 'section' =>
'source',
183 $this->mMaxUploadSize[
'file'] = min(
188 $help = $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'file'] )->parse();
192 if ( $canUploadByUrl ) {
193 $help .= $this->
msg(
'word-separator' )->escaped();
194 $help .= $this->
msg(
'upload_source_file' )->parse();
197 $descriptor[
'UploadFile'] = [
198 'class' => UploadSourceField::class,
199 'section' =>
'source',
201 'id' =>
'wpUploadFile',
202 'radio-id' =>
'wpSourceTypeFile',
203 'label-message' =>
'sourcefilename',
204 'upload-type' =>
'File',
207 'checked' => $selectedSourceType ==
'file',
210 if ( $canUploadByUrl ) {
212 $descriptor[
'UploadFileURL'] = [
213 'class' => UploadSourceField::class,
214 'section' =>
'source',
215 'id' =>
'wpUploadFileURL',
216 'radio-id' =>
'wpSourceTypeurl',
217 'label-message' =>
'sourceurl',
218 'upload-type' =>
'url',
220 'help' => $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'url'] )->parse() .
221 $this->
msg(
'word-separator' )->escaped() .
222 $this->
msg(
'upload_source_url' )->parse(),
223 'checked' => $selectedSourceType ==
'url',
226 $this->getHookRunner()->onUploadFormSourceDescriptors(
227 $descriptor, $radio, $selectedSourceType );
229 $descriptor[
'Extensions'] = [
231 'section' =>
'source',
245 # Print a list of allowed file extensions, if so configured. We ignore
246 # MIME type here, it's incomprehensible to most people and too long.
249 if ( $config->get( MainConfigNames::CheckFileExtensions ) ) {
250 $fileExtensions = array_unique( $config->get( MainConfigNames::FileExtensions ) );
251 if ( $config->get( MainConfigNames::StrictFileExtensions ) ) {
252 # Everything not permitted is banned
254 '<div id="mw-upload-permitted">' .
255 $this->
msg(
'upload-permitted' )
256 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
257 ->numParams( count( $fileExtensions ) )
261 # We have to list both preferred and prohibited
262 $prohibitedExtensions =
263 array_unique( $config->get( MainConfigNames::ProhibitedFileExtensions ) );
265 '<div id="mw-upload-preferred">' .
266 $this->
msg(
'upload-preferred' )
267 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
268 ->numParams( count( $fileExtensions ) )
271 '<div id="mw-upload-prohibited">' .
272 $this->
msg(
'upload-prohibited' )
273 ->params( $this->
getLanguage()->commaList( $prohibitedExtensions ) )
274 ->numParams( count( $prohibitedExtensions ) )
279 # Everything is permitted.
280 $extensionsList =
'';
283 return $extensionsList;
294 if ( $this->mSessionKey ) {
295 $stash = $this->localRepo->getUploadStash( $this->
getUser() );
297 $file = $stash->getFile( $this->mSessionKey );
298 }
catch ( TimeoutException $e ) {
300 }
catch ( Exception $e ) {
304 $mto =
$file->transform( [
'width' => 120 ] );
307 '<div class="thumb t' .
308 $this->contentLanguage->alignEnd() .
'">' .
310 'src' => $mto->getUrl(),
311 'class' =>
'thumbimage',
312 ] ) .
'</div>',
'description' );
320 'section' =>
'description',
321 'id' =>
'wpDestFile',
322 'label-message' =>
'destfilename',
325 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
326 'nodata' => strval( $this->mDestFile ) !==
'',
328 'UploadDescription' => [
329 'type' => $this->mForReUpload
332 'section' =>
'description',
333 'id' =>
'wpUploadDescription',
334 'label-message' => $this->mForReUpload
335 ?
'filereuploadsummary'
336 :
'fileuploadsummary',
340 if ( $this->mTextAfterSummary ) {
341 $descriptor[
'UploadFormTextAfterSummary'] = [
344 'section' =>
'description',
352 'type' =>
'edittools',
353 'section' =>
'description',
354 'message' =>
'edittools-upload',
358 if ( $this->mForReUpload ) {
359 $descriptor[
'DestFile'][
'readonly'] =
true;
360 $descriptor[
'UploadDescription'][
'size'] = 60;
362 $descriptor[
'License'] = [
364 'class' => Licenses::class,
365 'section' =>
'description',
367 'label-message' =>
'license',
369 $descriptor[
'UploadDescription'][
'rows'] = 8;
372 if ( $config->get( MainConfigNames::UseCopyrightUpload ) ) {
373 $descriptor[
'UploadCopyStatus'] = [
375 'section' =>
'description',
376 'id' =>
'wpUploadCopyStatus',
377 'label-message' =>
'filestatus',
379 $descriptor[
'UploadSource'] = [
381 'section' =>
'description',
382 'id' =>
'wpUploadSource',
383 'label-message' =>
'filesource',
398 if ( $user->isRegistered() ) {
402 'id' =>
'wpWatchthis',
403 'label-message' =>
'watchthisupload',
404 'section' =>
'options',
409 if ( !$this->mHideIgnoreWarning ) {
410 $descriptor[
'IgnoreWarning'] = [
412 'id' =>
'wpIgnoreWarning',
413 'label-message' =>
'ignorewarnings',
414 'section' =>
'options',
418 $descriptor[
'DestFileWarningAck'] = [
420 'id' =>
'wpDestFileWarningAck',
421 'default' => $this->mDestWarningAck ?
'1' :
'',
424 if ( $this->mForReUpload ) {
425 $descriptor[
'ForReUpload'] = [
427 'id' =>
'wpForReUpload',
441 return parent::show();
453 'wgAjaxLicensePreview' => $config->get( MainConfigNames::AjaxLicensePreview ),
454 'wgUploadAutoFill' => !$this->mForReUpload &&
457 $this->mDestFile ===
'',
459 'wgCheckFileExtensions' => $config->get( MainConfigNames::CheckFileExtensions ),
460 'wgStrictFileExtensions' => $config->get( MainConfigNames::StrictFileExtensions ),
461 'wgFileExtensions' =>
462 array_values( array_unique( $config->get( MainConfigNames::FileExtensions ) ) ),
468 $out->addJsConfigVars( $scriptVars );
471 'mediawiki.special.upload',
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getContext()
Get the base IContextSource object.
setContext(IContextSource $context)
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Local repository that stores files in the local filesystem and registers them in the wiki's own datab...
A class containing constants representing the names of configuration variables.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
static rotationEnabled()
Should we rotate images in the preview on Special:Upload.
static getMaxUploadSize( $forType=null)
Get MediaWiki's maximum uploaded file size for given type of upload, based on $wgMaxUploadSize.
static getMaxPhpUploadSize()
Get the PHP maximum uploaded file size, based on ini settings.
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.