24use Wikimedia\RequestTimeout\TimeoutException;
54 private $contentLanguage;
79 $services = MediaWikiServices::getInstance();
80 if ( !$linkRenderer ) {
81 $linkRenderer = $services->getLinkRenderer();
84 $localRepo = $services->getRepoGroup()->getLocalRepo();
86 if ( !$contentLanguage ) {
87 $contentLanguage = $services->getContentLanguage();
90 $nsInfo = $services->getNamespaceInfo();
92 $this->localRepo = $localRepo;
93 $this->contentLanguage = $contentLanguage;
94 $this->nsInfo = $nsInfo;
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'] = [
176 'section' =>
'source',
182 $this->mMaxUploadSize[
'file'] = min(
183 UploadBase::getMaxUploadSize(
'file' ),
184 UploadBase::getMaxPhpUploadSize()
187 $help = $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'file'] )->parse();
191 if ( $canUploadByUrl ) {
192 $help .= $this->
msg(
'word-separator' )->escaped();
193 $help .= $this->
msg(
'upload_source_file' )->parse();
196 $descriptor[
'UploadFile'] = [
197 'class' => UploadSourceField::class,
198 'section' =>
'source',
200 'id' =>
'wpUploadFile',
201 'radio-id' =>
'wpSourceTypeFile',
202 'label-message' =>
'sourcefilename',
203 'upload-type' =>
'File',
206 'checked' => $selectedSourceType ==
'file',
209 if ( $canUploadByUrl ) {
210 $this->mMaxUploadSize[
'url'] = UploadBase::getMaxUploadSize(
'url' );
211 $descriptor[
'UploadFileURL'] = [
212 'class' => UploadSourceField::class,
213 'section' =>
'source',
214 'id' =>
'wpUploadFileURL',
215 'radio-id' =>
'wpSourceTypeurl',
216 'label-message' =>
'sourceurl',
217 'upload-type' =>
'url',
219 'help' => $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'url'] )->parse() .
220 $this->
msg(
'word-separator' )->escaped() .
221 $this->
msg(
'upload_source_url' )->parse(),
222 'checked' => $selectedSourceType ==
'url',
225 $this->getHookRunner()->onUploadFormSourceDescriptors(
226 $descriptor, $radio, $selectedSourceType );
228 $descriptor[
'Extensions'] = [
230 'section' =>
'source',
244 # Print a list of allowed file extensions, if so configured. We ignore
245 # MIME type here, it's incomprehensible to most people and too long.
248 if ( $config->get( MainConfigNames::CheckFileExtensions ) ) {
249 $fileExtensions = array_unique( $config->get( MainConfigNames::FileExtensions ) );
250 if ( $config->get( MainConfigNames::StrictFileExtensions ) ) {
251 # Everything not permitted is banned
253 '<div id="mw-upload-permitted">' .
254 $this->
msg(
'upload-permitted' )
255 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
256 ->numParams( count( $fileExtensions ) )
260 # We have to list both preferred and prohibited
261 $prohibitedExtensions =
262 array_unique( $config->get( MainConfigNames::ProhibitedFileExtensions ) );
264 '<div id="mw-upload-preferred">' .
265 $this->
msg(
'upload-preferred' )
266 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
267 ->numParams( count( $fileExtensions ) )
270 '<div id="mw-upload-prohibited">' .
271 $this->
msg(
'upload-prohibited' )
272 ->params( $this->
getLanguage()->commaList( $prohibitedExtensions ) )
273 ->numParams( count( $prohibitedExtensions ) )
278 # Everything is permitted.
279 $extensionsList =
'';
282 return $extensionsList;
293 if ( $this->mSessionKey ) {
294 $stash = $this->localRepo->getUploadStash( $this->
getUser() );
296 $file = $stash->getFile( $this->mSessionKey );
297 }
catch ( TimeoutException $e ) {
299 }
catch ( Exception $e ) {
303 $mto =
$file->transform( [
'width' => 120 ] );
306 '<div class="thumb t' .
307 $this->contentLanguage->alignEnd() .
'">' .
308 Html::element(
'img', [
309 'src' => $mto->getUrl(),
310 'class' =>
'thumbimage',
311 ] ) .
'</div>',
'description' );
319 'section' =>
'description',
320 'id' =>
'wpDestFile',
321 'label-message' =>
'destfilename',
324 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
325 'nodata' => strval( $this->mDestFile ) !==
'',
327 'UploadDescription' => [
328 'type' => $this->mForReUpload
331 'section' =>
'description',
332 'id' =>
'wpUploadDescription',
333 'label-message' => $this->mForReUpload
334 ?
'filereuploadsummary'
335 :
'fileuploadsummary',
339 if ( $this->mTextAfterSummary ) {
340 $descriptor[
'UploadFormTextAfterSummary'] = [
342 'section' =>
'description',
350 'type' =>
'edittools',
351 'section' =>
'description',
352 'message' =>
'edittools-upload',
356 if ( $this->mForReUpload ) {
357 $descriptor[
'DestFile'][
'readonly'] =
true;
358 $descriptor[
'UploadDescription'][
'size'] = 60;
360 $descriptor[
'License'] = [
362 'class' => Licenses::class,
363 'section' =>
'description',
365 'label-message' =>
'license',
367 $descriptor[
'UploadDescription'][
'rows'] = 8;
370 if ( $config->get( MainConfigNames::UseCopyrightUpload ) ) {
371 $descriptor[
'UploadCopyStatus'] = [
373 'section' =>
'description',
374 'id' =>
'wpUploadCopyStatus',
375 'label-message' =>
'filestatus',
377 $descriptor[
'UploadSource'] = [
379 'section' =>
'description',
380 'id' =>
'wpUploadSource',
381 'label-message' =>
'filesource',
396 if ( $user->isRegistered() ) {
400 'id' =>
'wpWatchthis',
401 'label-message' =>
'watchthisupload',
402 'section' =>
'options',
407 if ( !$this->mHideIgnoreWarning ) {
408 $descriptor[
'IgnoreWarning'] = [
410 'id' =>
'wpIgnoreWarning',
411 'label-message' =>
'ignorewarnings',
412 'section' =>
'options',
416 $descriptor[
'DestFileWarningAck'] = [
418 'id' =>
'wpDestFileWarningAck',
419 'default' => $this->mDestWarningAck ?
'1' :
'',
422 if ( $this->mForReUpload ) {
423 $descriptor[
'ForReUpload'] = [
425 'id' =>
'wpForReUpload',
439 return parent::show();
448 $this->mMaxUploadSize[
'*'] = UploadBase::getMaxUploadSize();
451 'wgAjaxLicensePreview' => $config->get( MainConfigNames::AjaxLicensePreview ),
452 'wgUploadAutoFill' => !$this->mForReUpload &&
455 $this->mDestFile ===
'',
457 'wgCheckFileExtensions' => $config->get( MainConfigNames::CheckFileExtensions ),
458 'wgStrictFileExtensions' => $config->get( MainConfigNames::StrictFileExtensions ),
459 'wgFileExtensions' =>
460 array_values( array_unique( $config->get( MainConfigNames::FileExtensions ) ) ),
462 'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
466 $out->addJsConfigVars( $scriptVars );
469 '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.