27use Wikimedia\RequestTimeout\TimeoutException;
57 private $contentLanguage;
87 $services = MediaWikiServices::getInstance();
88 if ( !$linkRenderer ) {
89 $linkRenderer = $services->getLinkRenderer();
92 $localRepo = $services->getRepoGroup()->getLocalRepo();
94 if ( !$contentLanguage ) {
95 $contentLanguage = $services->getContentLanguage();
98 $nsInfo = $services->getNamespaceInfo();
100 $this->localRepo = $localRepo;
101 $this->contentLanguage = $contentLanguage;
102 $this->nsInfo = $nsInfo;
103 $this->hookRunner =
new HookRunner( $hookContainer ?? $services->getHookContainer() );
105 $this->mWatch = !empty( $options[
'watch'] );
106 $this->mForReUpload = !empty( $options[
'forreupload'] );
107 $this->mSessionKey = $options[
'sessionkey'] ??
'';
108 $this->mHideIgnoreWarning = !empty( $options[
'hideignorewarning'] );
109 $this->mDestWarningAck = !empty( $options[
'destwarningack'] );
110 $this->mDestFile = $options[
'destfile'] ??
'';
112 $this->mComment = $options[
'description'] ??
'';
114 $this->mTextTop = $options[
'texttop'] ??
'';
116 $this->mTextAfterSummary = $options[
'textaftersummary'] ??
'';
119 $descriptor = $sourceDescriptor
123 $this->hookRunner->onUploadFormInitDescriptor( $descriptor );
124 parent::__construct( $descriptor, $this->
getContext(),
'upload' );
126 # Add a link to edit MediaWiki:Licenses
127 if ( $this->
getAuthority()->isAllowed(
'editinterface' ) ) {
128 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
129 $licensesLink = $linkRenderer->makeKnownLink(
130 $this->
msg(
'licenses' )->inContentLanguage()->
getTitle(),
131 $this->
msg(
'licenses-edit' )->text(),
133 [
'action' =>
'edit' ]
135 $editLicenses =
'<p class="mw-upload-editlicenses">' . $licensesLink .
'</p>';
139 # Set some form properties
142 # Used message keys: 'accesskey-upload', 'tooltip-upload'
144 $this->
setId(
'mw-upload-form' );
146 # Build a list of IDs for javascript insertion
147 $this->mSourceIds = [];
148 foreach ( $sourceDescriptor as $field ) {
149 if ( !empty( $field[
'id'] ) ) {
150 $this->mSourceIds[] = $field[
'id'];
162 if ( $this->mSessionKey ) {
170 'default' =>
'Stash',
177 && $this->
getConfig()->get( MainConfigNames::CopyUploadsFromSpecialUpload );
178 $radio = $canUploadByUrl;
179 $selectedSourceType = strtolower( $this->
getRequest()->getText(
'wpSourceType',
'File' ) );
182 if ( $this->mTextTop ) {
183 $descriptor[
'UploadFormTextTop'] = [
185 'section' =>
'source',
191 $this->mMaxUploadSize[
'file'] = min(
192 UploadBase::getMaxUploadSize(
'file' ),
193 UploadBase::getMaxPhpUploadSize()
196 $help = $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'file'] )->parse();
200 if ( $canUploadByUrl ) {
201 $help .= $this->
msg(
'word-separator' )->escaped();
202 $help .= $this->
msg(
'upload_source_file' )->parse();
205 $descriptor[
'UploadFile'] = [
206 'class' => UploadSourceField::class,
207 'section' =>
'source',
209 'id' =>
'wpUploadFile',
210 'radio-id' =>
'wpSourceTypeFile',
211 'label-message' =>
'sourcefilename',
212 'upload-type' =>
'File',
215 'checked' => $selectedSourceType ==
'file',
218 if ( $canUploadByUrl ) {
219 $this->mMaxUploadSize[
'url'] = UploadBase::getMaxUploadSize(
'url' );
220 $descriptor[
'UploadFileURL'] = [
221 'class' => UploadSourceField::class,
222 'section' =>
'source',
223 'id' =>
'wpUploadFileURL',
224 'radio-id' =>
'wpSourceTypeurl',
225 'label-message' =>
'sourceurl',
226 'upload-type' =>
'url',
228 'help' => $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'url'] )->parse() .
229 $this->
msg(
'word-separator' )->escaped() .
230 $this->
msg(
'upload_source_url' )->parse(),
231 'checked' => $selectedSourceType ==
'url',
234 $this->hookRunner->onUploadFormSourceDescriptors(
235 $descriptor, $radio, $selectedSourceType );
237 $descriptor[
'Extensions'] = [
239 'section' =>
'source',
253 # Print a list of allowed file extensions, if so configured. We ignore
254 # MIME type here, it's incomprehensible to most people and too long.
257 if ( $config->get( MainConfigNames::CheckFileExtensions ) ) {
258 $fileExtensions = array_unique( $config->get( MainConfigNames::FileExtensions ) );
259 if ( $config->get( MainConfigNames::StrictFileExtensions ) ) {
260 # Everything not permitted is banned
262 '<div id="mw-upload-permitted">' .
263 $this->
msg(
'upload-permitted' )
264 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
265 ->numParams( count( $fileExtensions ) )
269 # We have to list both preferred and prohibited
270 $prohibitedExtensions =
271 array_unique( $config->get( MainConfigNames::ProhibitedFileExtensions ) );
273 '<div id="mw-upload-preferred">' .
274 $this->
msg(
'upload-preferred' )
275 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
276 ->numParams( count( $fileExtensions ) )
279 '<div id="mw-upload-prohibited">' .
280 $this->
msg(
'upload-prohibited' )
281 ->params( $this->
getLanguage()->commaList( $prohibitedExtensions ) )
282 ->numParams( count( $prohibitedExtensions ) )
287 # Everything is permitted.
288 $extensionsList =
'';
291 return $extensionsList;
302 if ( $this->mSessionKey ) {
303 $stash = $this->localRepo->getUploadStash( $this->
getUser() );
305 $file = $stash->getFile( $this->mSessionKey );
306 }
catch ( TimeoutException $e ) {
308 }
catch ( Exception $e ) {
312 $mto =
$file->transform( [
'width' => 120 ] );
315 '<div class="thumb t' .
316 $this->contentLanguage->alignEnd() .
'">' .
317 Html::element(
'img', [
318 'src' => $mto->getUrl(),
319 'class' =>
'thumbimage',
320 ] ) .
'</div>',
'description' );
328 'section' =>
'description',
329 'id' =>
'wpDestFile',
330 'label-message' =>
'destfilename',
333 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
334 'nodata' => strval( $this->mDestFile ) !==
'',
336 'UploadDescription' => [
337 'type' => $this->mForReUpload
340 'section' =>
'description',
341 'id' =>
'wpUploadDescription',
342 'label-message' => $this->mForReUpload
343 ?
'filereuploadsummary'
344 :
'fileuploadsummary',
348 if ( $this->mTextAfterSummary ) {
349 $descriptor[
'UploadFormTextAfterSummary'] = [
351 'section' =>
'description',
359 'type' =>
'edittools',
360 'section' =>
'description',
361 'message' =>
'edittools-upload',
365 if ( $this->mForReUpload ) {
366 $descriptor[
'DestFile'][
'readonly'] =
true;
367 $descriptor[
'UploadDescription'][
'size'] = 60;
369 $descriptor[
'License'] = [
371 'class' => Licenses::class,
372 'section' =>
'description',
374 'label-message' =>
'license',
376 $descriptor[
'UploadDescription'][
'rows'] = 8;
379 if ( $config->get( MainConfigNames::UseCopyrightUpload ) ) {
380 $descriptor[
'UploadCopyStatus'] = [
382 'section' =>
'description',
383 'id' =>
'wpUploadCopyStatus',
384 'label-message' =>
'filestatus',
386 $descriptor[
'UploadSource'] = [
388 'section' =>
'description',
389 'id' =>
'wpUploadSource',
390 'label-message' =>
'filesource',
405 if ( $user->isRegistered() ) {
409 'id' =>
'wpWatchthis',
410 'label-message' =>
'watchthisupload',
411 'section' =>
'options',
416 if ( !$this->mHideIgnoreWarning ) {
417 $descriptor[
'IgnoreWarning'] = [
419 'id' =>
'wpIgnoreWarning',
420 'label-message' =>
'ignorewarnings',
421 'section' =>
'options',
425 $descriptor[
'DestFileWarningAck'] = [
427 'id' =>
'wpDestFileWarningAck',
428 'default' => $this->mDestWarningAck ?
'1' :
'',
431 if ( $this->mForReUpload ) {
432 $descriptor[
'ForReUpload'] = [
434 'id' =>
'wpForReUpload',
448 return parent::show();
457 $this->mMaxUploadSize[
'*'] = UploadBase::getMaxUploadSize();
460 'wgAjaxLicensePreview' => $config->get( MainConfigNames::AjaxLicensePreview ),
461 'wgUploadAutoFill' => !$this->mForReUpload &&
464 $this->mDestFile ===
'',
466 'wgCheckFileExtensions' => $config->get( MainConfigNames::CheckFileExtensions ),
467 'wgStrictFileExtensions' => $config->get( MainConfigNames::StrictFileExtensions ),
468 'wgFileExtensions' =>
469 array_values( array_unique( $config->get( MainConfigNames::FileExtensions ) ) ),
471 'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
475 $out->addJsConfigVars( $scriptVars );
478 '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)
Base class for language-specific code.
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 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.