77 $services = MediaWikiServices::getInstance();
78 if ( !$linkRenderer ) {
79 $linkRenderer = $services->getLinkRenderer();
82 $localRepo = $services->getRepoGroup()->getLocalRepo();
88 $nsInfo = $services->getNamespaceInfo();
94 $this->mWatch = !empty( $options[
'watch'] );
95 $this->mForReUpload = !empty( $options[
'forreupload'] );
96 $this->mSessionKey = $options[
'sessionkey'] ??
'';
97 $this->mHideIgnoreWarning = !empty( $options[
'hideignorewarning'] );
98 $this->mDestWarningAck = !empty( $options[
'destwarningack'] );
99 $this->mDestFile = $options[
'destfile'] ??
'';
101 $this->mComment = $options[
'description'] ??
'';
103 $this->mTextTop = $options[
'texttop'] ??
'';
105 $this->mTextAfterSummary = $options[
'textaftersummary'] ??
'';
108 $descriptor = $sourceDescriptor
112 $this->getHookRunner()->onUploadFormInitDescriptor( $descriptor );
113 parent::__construct( $descriptor,
$context,
'upload' );
115 # Add a link to edit MediaWiki:Licenses
116 if ( $this->
getAuthority()->isAllowed(
'editinterface' ) ) {
117 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
118 $licensesLink = $linkRenderer->makeKnownLink(
119 $this->
msg(
'licenses' )->inContentLanguage()->
getTitle(),
120 $this->
msg(
'licenses-edit' )->text(),
122 [
'action' =>
'edit' ]
124 $editLicenses =
'<p class="mw-upload-editlicenses">' . $licensesLink .
'</p>';
128 # Set some form properties
131 # Used message keys: 'accesskey-upload', 'tooltip-upload'
133 $this->
setId(
'mw-upload-form' );
135 # Build a list of IDs for javascript insertion
136 $this->mSourceIds = [];
137 foreach ( $sourceDescriptor as $field ) {
138 if ( !empty( $field[
'id'] ) ) {
139 $this->mSourceIds[] = $field[
'id'];
151 if ( $this->mSessionKey ) {
159 'default' =>
'Stash',
166 && $this->
getConfig()->get(
'CopyUploadsFromSpecialUpload' );
167 $radio = $canUploadByUrl;
168 $selectedSourceType = strtolower( $this->
getRequest()->getText(
'wpSourceType',
'File' ) );
171 if ( $this->mTextTop ) {
172 $descriptor[
'UploadFormTextTop'] = [
175 'section' =>
'source',
181 $this->mMaxUploadSize[
'file'] = min(
182 UploadBase::getMaxUploadSize(
'file' ),
183 UploadBase::getMaxPhpUploadSize()
186 $help = $this->
msg(
'upload-maxfilesize',
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 ) {
211 $this->mMaxUploadSize[
'url'] = UploadBase::getMaxUploadSize(
'url' );
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',
223 $this->
msg(
'word-separator' )->escaped() .
224 $this->
msg(
'upload_source_url' )->parse(),
225 'checked' => $selectedSourceType ==
'url',
228 $this->getHookRunner()->onUploadFormSourceDescriptors(
229 $descriptor, $radio, $selectedSourceType );
231 $descriptor[
'Extensions'] = [
233 'section' =>
'source',
247 # Print a list of allowed file extensions, if so configured. We ignore
248 # MIME type here, it's incomprehensible to most people and too long.
251 if ( $config->get(
'CheckFileExtensions' ) ) {
252 $fileExtensions = array_unique( $config->get(
'FileExtensions' ) );
253 if ( $config->get(
'StrictFileExtensions' ) ) {
254 # Everything not permitted is banned
256 '<div id="mw-upload-permitted">' .
257 $this->
msg(
'upload-permitted' )
258 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
259 ->numParams( count( $fileExtensions ) )
263 # We have to list both preferred and prohibited
264 $prohibitedExtensions = array_unique( $config->get(
'ProhibitedFileExtensions' ) );
266 '<div id="mw-upload-preferred">' .
267 $this->
msg(
'upload-preferred' )
268 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
269 ->numParams( count( $fileExtensions ) )
272 '<div id="mw-upload-prohibited">' .
273 $this->
msg(
'upload-prohibited' )
274 ->params( $this->
getLanguage()->commaList( $prohibitedExtensions ) )
275 ->numParams( count( $prohibitedExtensions ) )
280 # Everything is permitted.
281 $extensionsList =
'';
284 return $extensionsList;
295 if ( $this->mSessionKey ) {
296 $stash = $this->localRepo->getUploadStash( $this->
getUser() );
298 $file = $stash->getFile( $this->mSessionKey );
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'] = [
343 'section' =>
'description',
351 'type' =>
'edittools',
352 'section' =>
'description',
353 'message' =>
'edittools-upload',
357 if ( $this->mForReUpload ) {
358 $descriptor[
'DestFile'][
'readonly'] =
true;
359 $descriptor[
'UploadDescription'][
'size'] = 60;
361 $descriptor[
'License'] = [
363 'class' => Licenses::class,
364 'section' =>
'description',
366 'label-message' =>
'license',
368 $descriptor[
'UploadDescription'][
'rows'] = 8;
371 if ( $config->get(
'UseCopyrightUpload' ) ) {
372 $descriptor[
'UploadCopyStatus'] = [
374 'section' =>
'description',
375 'id' =>
'wpUploadCopyStatus',
376 'label-message' =>
'filestatus',
378 $descriptor[
'UploadSource'] = [
380 'section' =>
'description',
381 'id' =>
'wpUploadSource',
382 'label-message' =>
'filesource',
397 if ( $user->isRegistered() ) {
401 'id' =>
'wpWatchthis',
402 'label-message' =>
'watchthisupload',
403 'section' =>
'options',
408 if ( !$this->mHideIgnoreWarning ) {
409 $descriptor[
'IgnoreWarning'] = [
411 'id' =>
'wpIgnoreWarning',
412 'label-message' =>
'ignorewarnings',
413 'section' =>
'options',
417 $descriptor[
'DestFileWarningAck'] = [
419 'id' =>
'wpDestFileWarningAck',
420 'default' => $this->mDestWarningAck ?
'1' :
'',
423 if ( $this->mForReUpload ) {
424 $descriptor[
'ForReUpload'] = [
426 'id' =>
'wpForReUpload',
440 return parent::show();
449 $this->mMaxUploadSize[
'*'] = UploadBase::getMaxUploadSize();
452 'wgAjaxUploadDestCheck' => $config->get(
'AjaxUploadDestCheck' ),
453 'wgAjaxLicensePreview' => $config->get(
'AjaxLicensePreview' ),
454 'wgUploadAutoFill' => !$this->mForReUpload &&
457 $this->mDestFile ===
'',
459 'wgCheckFileExtensions' => $config->get(
'CheckFileExtensions' ),
460 'wgStrictFileExtensions' => $config->get(
'StrictFileExtensions' ),
461 'wgFileExtensions' => array_values( array_unique( $config->get(
'FileExtensions' ) ) ),
462 'wgCapitalizeUploads' => $this->nsInfo->isCapitalized(
NS_FILE ),
464 'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
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)
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
A repository that stores files in the local filesystem and registers them in the wiki's own database.
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.