53 if ( !$linkRenderer ) {
54 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
57 $this->mWatch = !empty( $options[
'watch'] );
58 $this->mForReUpload = !empty( $options[
'forreupload'] );
59 $this->mSessionKey = $options[
'sessionkey'] ??
'';
60 $this->mHideIgnoreWarning = !empty( $options[
'hideignorewarning'] );
61 $this->mDestWarningAck = !empty( $options[
'destwarningack'] );
62 $this->mDestFile = $options[
'destfile'] ??
'';
64 $this->mComment = $options[
'description'] ??
'';
66 $this->mTextTop = $options[
'texttop'] ??
'';
68 $this->mTextAfterSummary = $options[
'textaftersummary'] ??
'';
71 $descriptor = $sourceDescriptor
75 Hooks::run(
'UploadFormInitDescriptor', [ &$descriptor ] );
76 parent::__construct( $descriptor,
$context,
'upload' );
78 # Add a link to edit MediaWiki:Licenses
79 if ( MediaWikiServices::getInstance()
81 ->userHasRight( $this->
getUser(),
'editinterface' )
83 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
84 $licensesLink = $linkRenderer->makeKnownLink(
85 $this->
msg(
'licenses' )->inContentLanguage()->
getTitle(),
86 $this->
msg(
'licenses-edit' )->text(),
88 [
'action' =>
'edit' ]
90 $editLicenses =
'<p class="mw-upload-editlicenses">' . $licensesLink .
'</p>';
94 # Set some form properties
97 # Used message keys: 'accesskey-upload', 'tooltip-upload'
99 $this->
setId(
'mw-upload-form' );
101 # Build a list of IDs for javascript insertion
102 $this->mSourceIds = [];
103 foreach ( $sourceDescriptor as $field ) {
104 if ( !empty( $field[
'id'] ) ) {
105 $this->mSourceIds[] = $field[
'id'];
117 if ( $this->mSessionKey ) {
125 'default' =>
'Stash',
132 && $this->
getConfig()->get(
'CopyUploadsFromSpecialUpload' );
133 $radio = $canUploadByUrl;
134 $selectedSourceType = strtolower( $this->
getRequest()->getText(
'wpSourceType',
'File' ) );
137 if ( $this->mTextTop ) {
138 $descriptor[
'UploadFormTextTop'] = [
140 'section' =>
'source',
146 $this->mMaxUploadSize[
'file'] = min(
151 $help = $this->
msg(
'upload-maxfilesize',
157 if ( $canUploadByUrl ) {
158 $help .= $this->
msg(
'word-separator' )->escaped();
159 $help .= $this->
msg(
'upload_source_file' )->parse();
162 $descriptor[
'UploadFile'] = [
163 'class' => UploadSourceField::class,
164 'section' =>
'source',
166 'id' =>
'wpUploadFile',
167 'radio-id' =>
'wpSourceTypeFile',
168 'label-message' =>
'sourcefilename',
169 'upload-type' =>
'File',
172 'checked' => $selectedSourceType ==
'file',
175 if ( $canUploadByUrl ) {
177 $descriptor[
'UploadFileURL'] = [
178 'class' => UploadSourceField::class,
179 'section' =>
'source',
180 'id' =>
'wpUploadFileURL',
181 'radio-id' =>
'wpSourceTypeurl',
182 'label-message' =>
'sourceurl',
183 'upload-type' =>
'url',
185 'help' => $this->
msg(
'upload-maxfilesize',
188 $this->
msg(
'word-separator' )->escaped() .
189 $this->
msg(
'upload_source_url' )->parse(),
190 'checked' => $selectedSourceType ==
'url',
193 Hooks::run(
'UploadFormSourceDescriptors', [ &$descriptor, &$radio, $selectedSourceType ] );
195 $descriptor[
'Extensions'] = [
197 'section' =>
'source',
211 # Print a list of allowed file extensions, if so configured. We ignore
212 # MIME type here, it's incomprehensible to most people and too long.
215 if ( $config->get(
'CheckFileExtensions' ) ) {
216 $fileExtensions = array_unique( $config->get(
'FileExtensions' ) );
217 if ( $config->get(
'StrictFileExtensions' ) ) {
218 # Everything not permitted is banned
220 '<div id="mw-upload-permitted">' .
221 $this->
msg(
'upload-permitted' )
222 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
223 ->numParams( count( $fileExtensions ) )
227 # We have to list both preferred and prohibited
228 $fileBlacklist = array_unique( $config->get(
'FileBlacklist' ) );
230 '<div id="mw-upload-preferred">' .
231 $this->
msg(
'upload-preferred' )
232 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
233 ->numParams( count( $fileExtensions ) )
236 '<div id="mw-upload-prohibited">' .
237 $this->
msg(
'upload-prohibited' )
238 ->params( $this->
getLanguage()->commaList( $fileBlacklist ) )
239 ->numParams( count( $fileBlacklist ) )
244 # Everything is permitted.
245 $extensionsList =
'';
248 return $extensionsList;
259 if ( $this->mSessionKey ) {
260 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $this->
getUser() );
262 $file = $stash->getFile( $this->mSessionKey );
263 }
catch ( Exception $e ) {
267 $mto =
$file->transform( [
'width' => 120 ] );
270 '<div class="thumb t' .
271 MediaWikiServices::getInstance()->getContentLanguage()->alignEnd() .
'">' .
272 Html::element(
'img', [
273 'src' => $mto->getUrl(),
274 'class' =>
'thumbimage',
275 ] ) .
'</div>',
'description' );
283 'section' =>
'description',
284 'id' =>
'wpDestFile',
285 'label-message' =>
'destfilename',
288 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
289 'nodata' => strval( $this->mDestFile ) !==
'',
291 'UploadDescription' => [
292 'type' =>
'textarea',
293 'section' =>
'description',
294 'id' =>
'wpUploadDescription',
295 'label-message' => $this->mForReUpload
296 ?
'filereuploadsummary'
297 :
'fileuploadsummary',
303 if ( $this->mTextAfterSummary ) {
304 $descriptor[
'UploadFormTextAfterSummary'] = [
306 'section' =>
'description',
314 'type' =>
'edittools',
315 'section' =>
'description',
316 'message' =>
'edittools-upload',
320 if ( $this->mForReUpload ) {
321 $descriptor[
'DestFile'][
'readonly'] =
true;
323 $descriptor[
'License'] = [
325 'class' => Licenses::class,
326 'section' =>
'description',
328 'label-message' =>
'license',
332 if ( $config->get(
'UseCopyrightUpload' ) ) {
333 $descriptor[
'UploadCopyStatus'] = [
335 'section' =>
'description',
336 'id' =>
'wpUploadCopyStatus',
337 'label-message' =>
'filestatus',
339 $descriptor[
'UploadSource'] = [
341 'section' =>
'description',
342 'id' =>
'wpUploadSource',
343 'label-message' =>
'filesource',
358 if ( $user->isLoggedIn() ) {
362 'id' =>
'wpWatchthis',
363 'label-message' =>
'watchthisupload',
364 'section' =>
'options',
369 if ( !$this->mHideIgnoreWarning ) {
370 $descriptor[
'IgnoreWarning'] = [
372 'id' =>
'wpIgnoreWarning',
373 'label-message' =>
'ignorewarnings',
374 'section' =>
'options',
378 $descriptor[
'DestFileWarningAck'] = [
380 'id' =>
'wpDestFileWarningAck',
381 'default' => $this->mDestWarningAck ?
'1' :
'',
384 if ( $this->mForReUpload ) {
385 $descriptor[
'ForReUpload'] = [
387 'id' =>
'wpForReUpload',
400 return parent::show();
412 'wgAjaxUploadDestCheck' => $config->get(
'AjaxUploadDestCheck' ),
413 'wgAjaxLicensePreview' => $config->get(
'AjaxLicensePreview' ),
414 'wgUploadAutoFill' => !$this->mForReUpload &&
417 $this->mDestFile ===
'',
419 'wgCheckFileExtensions' => $config->get(
'CheckFileExtensions' ),
420 'wgStrictFileExtensions' => $config->get(
'StrictFileExtensions' ),
421 'wgFileExtensions' => array_values( array_unique( $config->get(
'FileExtensions' ) ) ),
422 'wgCapitalizeUploads' => MediaWikiServices::getInstance()->getNamespaceInfo()->
429 $out->addJsConfigVars( $scriptVars );
432 '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)
static rotationEnabled()
Should we rotate images in the preview on Special:Upload.
static getMaxUploadSize( $forType=null)
Get the MediaWiki maximum uploaded file size for given type of upload, based on $wgMaxUploadSize.
static getMaxPhpUploadSize()
Get the PHP maximum uploaded file size, based on ini settings.
static isAllowed(UserIdentity $user)
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.