30use Wikimedia\RequestTimeout\TimeoutException;
83 $services = MediaWikiServices::getInstance();
84 if ( !$linkRenderer ) {
85 $linkRenderer = $services->getLinkRenderer();
88 $localRepo = $services->getRepoGroup()->getLocalRepo();
90 if ( !$contentLanguage ) {
91 $contentLanguage = $services->getContentLanguage();
94 $nsInfo = $services->getNamespaceInfo();
96 $this->localRepo = $localRepo;
97 $this->contentLanguage = $contentLanguage;
98 $this->nsInfo = $nsInfo;
99 $this->hookRunner =
new HookRunner( $hookContainer ?? $services->getHookContainer() );
101 $this->mWatch = !empty( $options[
'watch'] );
102 $this->mForReUpload = !empty( $options[
'forreupload'] );
103 $this->mSessionKey = $options[
'sessionkey'] ??
'';
104 $this->mHideIgnoreWarning = !empty( $options[
'hideignorewarning'] );
105 $this->mDestWarningAck = !empty( $options[
'destwarningack'] );
106 $this->mDestFile = $options[
'destfile'] ??
'';
108 $this->mComment = $options[
'description'] ??
'';
110 $this->mTextTop = $options[
'texttop'] ??
'';
112 $this->mTextAfterSummary = $options[
'textaftersummary'] ??
'';
115 $descriptor = $sourceDescriptor
119 $this->hookRunner->onUploadFormInitDescriptor( $descriptor );
120 parent::__construct( $descriptor, $this->
getContext(),
'upload' );
122 # Add a link to edit MediaWiki:Licenses
123 if ( $this->
getAuthority()->isAllowed(
'editinterface' ) ) {
124 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
125 $licensesLink = $linkRenderer->makeKnownLink(
126 $this->
msg(
'licenses' )->inContentLanguage()->
getTitle(),
127 $this->
msg(
'licenses-edit' )->text(),
129 [
'action' =>
'edit' ]
131 $editLicenses =
'<p class="mw-upload-editlicenses">' . $licensesLink .
'</p>';
135 # Set some form properties
138 # Used message keys: 'accesskey-upload', 'tooltip-upload'
140 $this->
setId(
'mw-upload-form' );
142 # Build a list of IDs for javascript insertion
143 $this->mSourceIds = [];
144 foreach ( $sourceDescriptor as $field ) {
145 if ( !empty( $field[
'id'] ) ) {
146 $this->mSourceIds[] = $field[
'id'];
158 if ( $this->mSessionKey ) {
162 'default' => $this->mSessionKey,
166 'default' =>
'Stash',
173 && $this->
getConfig()->get( MainConfigNames::CopyUploadsFromSpecialUpload );
174 $radio = $canUploadByUrl;
175 $selectedSourceType = strtolower( $this->
getRequest()->getText(
'wpSourceType',
'File' ) );
178 if ( $this->mTextTop ) {
179 $descriptor[
'UploadFormTextTop'] = [
181 'section' =>
'source',
182 'default' => $this->mTextTop,
187 $this->mMaxUploadSize[
'file'] = min(
188 UploadBase::getMaxUploadSize(
'file' ),
189 UploadBase::getMaxPhpUploadSize()
192 $help = $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'file'] )->parse();
196 if ( $canUploadByUrl ) {
197 $help .= $this->
msg(
'word-separator' )->escaped();
198 $help .= $this->
msg(
'upload_source_file' )->parse();
201 $descriptor[
'UploadFile'] = [
202 'class' => UploadSourceField::class,
203 'section' =>
'source',
205 'id' =>
'wpUploadFile',
206 'radio-id' =>
'wpSourceTypeFile',
207 'label-message' =>
'sourcefilename',
208 'upload-type' =>
'File',
211 'checked' => $selectedSourceType ==
'file',
214 if ( $canUploadByUrl ) {
215 $this->mMaxUploadSize[
'url'] = UploadBase::getMaxUploadSize(
'url' );
216 $descriptor[
'UploadFileURL'] = [
217 'class' => UploadSourceField::class,
218 'section' =>
'source',
219 'id' =>
'wpUploadFileURL',
220 'radio-id' =>
'wpSourceTypeurl',
221 'label-message' =>
'sourceurl',
222 'upload-type' =>
'url',
224 'help' => $this->
msg(
'upload-maxfilesize' )->sizeParams( $this->mMaxUploadSize[
'url'] )->parse() .
225 $this->
msg(
'word-separator' )->escaped() .
226 $this->
msg(
'upload_source_url' )->parse(),
227 'checked' => $selectedSourceType ==
'url',
230 $this->hookRunner->onUploadFormSourceDescriptors(
231 $descriptor, $radio, $selectedSourceType );
233 $descriptor[
'Extensions'] = [
235 'section' =>
'source',
249 # Print a list of allowed file extensions, if so configured. We ignore
250 # MIME type here, it's incomprehensible to most people and too long.
253 if ( $config->get( MainConfigNames::CheckFileExtensions ) ) {
254 $fileExtensions = array_unique( $config->get( MainConfigNames::FileExtensions ) );
255 if ( $config->get( MainConfigNames::StrictFileExtensions ) ) {
256 # Everything not permitted is banned
258 '<div id="mw-upload-permitted">' .
259 $this->
msg(
'upload-permitted' )
260 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
261 ->numParams( count( $fileExtensions ) )
265 # We have to list both preferred and prohibited
266 $prohibitedExtensions =
267 array_unique( $config->get( MainConfigNames::ProhibitedFileExtensions ) );
269 '<div id="mw-upload-preferred">' .
270 $this->
msg(
'upload-preferred' )
271 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
272 ->numParams( count( $fileExtensions ) )
275 '<div id="mw-upload-prohibited">' .
276 $this->
msg(
'upload-prohibited' )
277 ->params( $this->
getLanguage()->commaList( $prohibitedExtensions ) )
278 ->numParams( count( $prohibitedExtensions ) )
283 # Everything is permitted.
284 $extensionsList =
'';
287 return $extensionsList;
298 if ( $this->mSessionKey ) {
299 $stash = $this->localRepo->getUploadStash( $this->
getUser() );
301 $file = $stash->getFile( $this->mSessionKey );
302 }
catch ( TimeoutException $e ) {
304 }
catch ( Exception $e ) {
308 $mto =
$file->transform( [
'width' => 120 ] );
311 '<div class="thumb t' .
312 $this->contentLanguage->alignEnd() .
'">' .
313 Html::element(
'img', [
314 'src' => $mto->getUrl(),
315 'class' =>
'thumbimage',
316 ] ) .
'</div>',
'description' );
324 'section' =>
'description',
325 'id' =>
'wpDestFile',
326 'label-message' =>
'destfilename',
328 'default' => $this->mDestFile,
329 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
330 'nodata' => strval( $this->mDestFile ) !==
'',
332 'UploadDescription' => [
333 'type' => $this->mForReUpload
336 'section' =>
'description',
337 'id' =>
'wpUploadDescription',
338 'label-message' => $this->mForReUpload
339 ?
'filereuploadsummary'
340 :
'fileuploadsummary',
341 'default' => $this->mComment,
344 if ( $this->mTextAfterSummary ) {
345 $descriptor[
'UploadFormTextAfterSummary'] = [
347 'section' =>
'description',
348 'default' => $this->mTextAfterSummary,
355 'type' =>
'edittools',
356 'section' =>
'description',
357 'message' =>
'edittools-upload',
361 if ( $this->mForReUpload ) {
362 $descriptor[
'DestFile'][
'readonly'] =
true;
363 $descriptor[
'UploadDescription'][
'size'] = 60;
365 $descriptor[
'License'] = [
367 'class' => Licenses::class,
368 'section' =>
'description',
370 'label-message' =>
'license',
372 $descriptor[
'UploadDescription'][
'rows'] = 8;
375 if ( $config->get( MainConfigNames::UseCopyrightUpload ) ) {
376 $descriptor[
'UploadCopyStatus'] = [
378 'section' =>
'description',
379 'id' =>
'wpUploadCopyStatus',
380 'label-message' =>
'filestatus',
382 $descriptor[
'UploadSource'] = [
384 'section' =>
'description',
385 'id' =>
'wpUploadSource',
386 'label-message' =>
'filesource',
401 if ( $user->isRegistered() ) {
405 'id' =>
'wpWatchthis',
406 'label-message' =>
'watchthisupload',
407 'section' =>
'options',
408 'default' => $this->mWatch,
412 if ( !$this->mHideIgnoreWarning ) {
413 $descriptor[
'IgnoreWarning'] = [
415 'id' =>
'wpIgnoreWarning',
416 'label-message' =>
'ignorewarnings',
417 'section' =>
'options',
421 $descriptor[
'DestFileWarningAck'] = [
423 'id' =>
'wpDestFileWarningAck',
424 'default' => $this->mDestWarningAck ?
'1' :
'',
427 if ( $this->mForReUpload ) {
428 $descriptor[
'ForReUpload'] = [
430 'id' =>
'wpForReUpload',
444 return parent::show();
453 $this->mMaxUploadSize[
'*'] = UploadBase::getMaxUploadSize();
456 'wgAjaxLicensePreview' => $config->get( MainConfigNames::AjaxLicensePreview ),
457 'wgUploadAutoFill' => !$this->mForReUpload &&
460 $this->mDestFile ===
'',
461 'wgUploadSourceIds' => $this->mSourceIds,
462 'wgCheckFileExtensions' => $config->get( MainConfigNames::CheckFileExtensions ),
463 'wgStrictFileExtensions' => $config->get( MainConfigNames::StrictFileExtensions ),
464 'wgFileExtensions' =>
465 array_values( array_unique( $config->get( MainConfigNames::FileExtensions ) ) ),
466 'wgMaxUploadSize' => $this->mMaxUploadSize,
467 'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
471 $out->addJsConfigVars( $scriptVars );
474 'mediawiki.special.upload',
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
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.
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.