33use Wikimedia\RequestTimeout\TimeoutException;
92 $services = MediaWikiServices::getInstance();
93 if ( !$linkRenderer ) {
94 $linkRenderer = $services->getLinkRenderer();
97 $localRepo = $services->getRepoGroup()->getLocalRepo();
99 if ( !$contentLanguage ) {
100 $contentLanguage = $services->getContentLanguage();
103 $nsInfo = $services->getNamespaceInfo();
105 $this->localRepo = $localRepo;
106 $this->contentLanguage = $contentLanguage;
107 $this->nsInfo = $nsInfo;
108 $this->hookRunner =
new HookRunner( $hookContainer ?? $services->getHookContainer() );
110 $this->mWatch = !empty( $options[
'watch'] );
111 $this->mForReUpload = !empty( $options[
'forreupload'] );
112 $this->mSessionKey = $options[
'sessionkey'] ??
'';
113 $this->mHideIgnoreWarning = !empty( $options[
'hideignorewarning'] );
114 $this->mDestWarningAck = !empty( $options[
'destwarningack'] );
115 $this->mDestFile = $options[
'destfile'] ??
'';
117 $this->mComment = $options[
'description'] ??
'';
119 $this->mTextTop = $options[
'texttop'] ??
'';
121 $this->mTextAfterSummary = $options[
'textaftersummary'] ??
'';
124 $descriptor = $sourceDescriptor
128 $this->hookRunner->onUploadFormInitDescriptor( $descriptor );
129 parent::__construct( $descriptor, $this->
getContext(),
'upload' );
131 # Add a link to edit MediaWiki:Licenses
132 if ( $this->
getAuthority()->isAllowed(
'editinterface' ) ) {
133 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
134 $licensesLink = $linkRenderer->makeKnownLink(
135 $this->
msg(
'licenses' )->inContentLanguage()->
getTitle(),
136 $this->
msg(
'licenses-edit' )->text(),
138 [
'action' =>
'edit' ]
140 $editLicenses =
'<p class="mw-upload-editlicenses">' . $licensesLink .
'</p>';
144 # Set some form properties
147 # Used message keys: 'accesskey-upload', 'tooltip-upload'
149 $this->
setId(
'mw-upload-form' );
151 # Build a list of IDs for javascript insertion
152 $this->mSourceIds = [];
153 foreach ( $sourceDescriptor as $field ) {
154 if ( !empty( $field[
'id'] ) ) {
155 $this->mSourceIds[] = $field[
'id'];
167 if ( $this->mSessionKey ) {
171 'default' => $this->mSessionKey,
175 'default' =>
'Stash',
180 $canUploadByUrl = UploadFromUrl::isEnabled()
181 && ( UploadFromUrl::isAllowed( $this->
getAuthority() ) === true )
182 && $this->
getConfig()->get( MainConfigNames::CopyUploadsFromSpecialUpload );
183 $radio = $canUploadByUrl;
184 $selectedSourceType = strtolower( $this->
getRequest()->getText(
'wpSourceType',
'File' ) );
187 if ( $this->mTextTop ) {
188 $descriptor[
'UploadFormTextTop'] = [
190 'section' =>
'source',
191 'default' => $this->mTextTop,
196 $this->mMaxUploadSize[
'file'] = min(
197 UploadBase::getMaxUploadSize(
'file' ),
198 UploadBase::getMaxPhpUploadSize()
201 $help = $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'file'] )->parse();
205 if ( $canUploadByUrl ) {
206 $help .= $this->
msg(
'word-separator' )->escaped();
207 $help .= $this->
msg(
'upload_source_file' )->parse();
210 $descriptor[
'UploadFile'] = [
211 'class' => UploadSourceField::class,
212 'section' =>
'source',
214 'id' =>
'wpUploadFile',
215 'radio-id' =>
'wpSourceTypeFile',
216 'label-message' =>
'sourcefilename',
217 'upload-type' =>
'File',
220 'checked' => $selectedSourceType ==
'file',
223 if ( $canUploadByUrl ) {
224 $this->mMaxUploadSize[
'url'] = UploadBase::getMaxUploadSize(
'url' );
225 $descriptor[
'UploadFileURL'] = [
226 'class' => UploadSourceField::class,
227 'section' =>
'source',
228 'id' =>
'wpUploadFileURL',
229 'radio-id' =>
'wpSourceTypeurl',
230 'label-message' =>
'sourceurl',
231 'upload-type' =>
'url',
233 'help' => $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'url'] )->parse() .
234 $this->
msg(
'word-separator' )->escaped() .
235 $this->
msg(
'upload_source_url' )->parse(),
236 'checked' => $selectedSourceType ==
'url',
239 $this->hookRunner->onUploadFormSourceDescriptors(
240 $descriptor, $radio, $selectedSourceType );
242 $descriptor[
'Extensions'] = [
244 'section' =>
'source',
258 # Print a list of allowed file extensions, if so configured. We ignore
259 # MIME type here, it's incomprehensible to most people and too long.
262 if ( $config->get( MainConfigNames::CheckFileExtensions ) ) {
263 $fileExtensions = array_unique( $config->get( MainConfigNames::FileExtensions ) );
264 if ( $config->get( MainConfigNames::StrictFileExtensions ) ) {
265 # Everything not permitted is banned
267 '<div id="mw-upload-permitted">' .
268 $this->
msg(
'upload-permitted' )
269 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
270 ->numParams( count( $fileExtensions ) )
274 # We have to list both preferred and prohibited
275 $prohibitedExtensions =
276 array_unique( $config->get( MainConfigNames::ProhibitedFileExtensions ) );
278 '<div id="mw-upload-preferred">' .
279 $this->
msg(
'upload-preferred' )
280 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
281 ->numParams( count( $fileExtensions ) )
284 '<div id="mw-upload-prohibited">' .
285 $this->
msg(
'upload-prohibited' )
286 ->params( $this->
getLanguage()->commaList( $prohibitedExtensions ) )
287 ->numParams( count( $prohibitedExtensions ) )
292 # Everything is permitted.
293 $extensionsList =
'';
296 return $extensionsList;
307 if ( $this->mSessionKey ) {
308 $stash = $this->localRepo->getUploadStash( $this->
getUser() );
310 $file = $stash->getFile( $this->mSessionKey );
311 }
catch ( TimeoutException $e ) {
313 }
catch ( Exception $e ) {
317 $mto = $file->transform( [
'width' => 120 ] );
320 '<div class="thumb t' .
321 $this->contentLanguage->alignEnd() .
'">' .
322 Html::element(
'img', [
323 'src' => $mto->getUrl(),
324 'class' =>
'thumbimage',
325 ] ) .
'</div>',
'description' );
333 'section' =>
'description',
334 'id' =>
'wpDestFile',
335 'label-message' =>
'destfilename',
337 'default' => $this->mDestFile,
338 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
339 'nodata' => strval( $this->mDestFile ) !==
'',
341 'UploadDescription' => [
342 'type' => $this->mForReUpload
345 'section' =>
'description',
346 'id' =>
'wpUploadDescription',
347 'label-message' => $this->mForReUpload
348 ?
'filereuploadsummary'
349 :
'fileuploadsummary',
350 'default' => $this->mComment,
353 if ( $this->mTextAfterSummary ) {
354 $descriptor[
'UploadFormTextAfterSummary'] = [
356 'section' =>
'description',
357 'default' => $this->mTextAfterSummary,
364 'type' =>
'edittools',
365 'section' =>
'description',
366 'message' =>
'edittools-upload',
370 if ( $this->mForReUpload ) {
371 $descriptor[
'DestFile'][
'readonly'] =
true;
372 $descriptor[
'UploadDescription'][
'size'] = 60;
374 $descriptor[
'License'] = [
376 'class' => Licenses::class,
377 'section' =>
'description',
379 'label-message' =>
'license',
381 $descriptor[
'UploadDescription'][
'rows'] = 8;
384 if ( $config->get( MainConfigNames::UseCopyrightUpload ) ) {
385 $descriptor[
'UploadCopyStatus'] = [
387 'section' =>
'description',
388 'id' =>
'wpUploadCopyStatus',
389 'label-message' =>
'filestatus',
391 $descriptor[
'UploadSource'] = [
393 'section' =>
'description',
394 'id' =>
'wpUploadSource',
395 'label-message' =>
'filesource',
410 if ( $user->isRegistered() ) {
414 'id' =>
'wpWatchthis',
415 'label-message' =>
'watchthisupload',
416 'section' =>
'options',
417 'default' => $this->mWatch,
421 if ( !$this->mHideIgnoreWarning ) {
422 $descriptor[
'IgnoreWarning'] = [
424 'id' =>
'wpIgnoreWarning',
425 'label-message' =>
'ignorewarnings',
426 'section' =>
'options',
430 $descriptor[
'DestFileWarningAck'] = [
432 'id' =>
'wpDestFileWarningAck',
433 'default' => $this->mDestWarningAck ?
'1' :
'',
436 if ( $this->mForReUpload ) {
437 $descriptor[
'ForReUpload'] = [
439 'id' =>
'wpForReUpload',
453 return parent::show();
462 $this->mMaxUploadSize[
'*'] = UploadBase::getMaxUploadSize();
465 'wgAjaxLicensePreview' => $config->get( MainConfigNames::AjaxLicensePreview ),
466 'wgUploadAutoFill' => !$this->mForReUpload &&
469 $this->mDestFile ===
'',
470 'wgUploadSourceIds' => $this->mSourceIds,
471 'wgCheckFileExtensions' => $config->get( MainConfigNames::CheckFileExtensions ),
472 'wgStrictFileExtensions' => $config->get( MainConfigNames::StrictFileExtensions ),
473 'wgFileExtensions' =>
474 array_values( array_unique( $config->get( MainConfigNames::FileExtensions ) ) ),
475 'wgMaxUploadSize' => $this->mMaxUploadSize,
476 'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
480 $out->addJsConfigVars( $scriptVars );
483 'mediawiki.special.upload',
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()
getContext()
Get the base IContextSource object.
A class containing constants representing the names of configuration variables.
Interface for objects which can provide a MediaWiki context on request.