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 $this->getHookRunner()->onUploadFormInitDescriptor( $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(
147 UploadBase::getMaxUploadSize(
'file' ),
148 UploadBase::getMaxPhpUploadSize()
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 ) {
176 $this->mMaxUploadSize[
'url'] = UploadBase::getMaxUploadSize(
'url' );
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 $this->getHookRunner()->onUploadFormSourceDescriptors(
194 $descriptor, $radio, $selectedSourceType );
196 $descriptor[
'Extensions'] = [
198 'section' =>
'source',
212 # Print a list of allowed file extensions, if so configured. We ignore
213 # MIME type here, it's incomprehensible to most people and too long.
216 if ( $config->get(
'CheckFileExtensions' ) ) {
217 $fileExtensions = array_unique( $config->get(
'FileExtensions' ) );
218 if ( $config->get(
'StrictFileExtensions' ) ) {
219 # Everything not permitted is banned
221 '<div id="mw-upload-permitted">' .
222 $this->
msg(
'upload-permitted' )
223 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
224 ->numParams( count( $fileExtensions ) )
228 # We have to list both preferred and prohibited
229 $fileBlacklist = array_unique( $config->get(
'FileBlacklist' ) );
231 '<div id="mw-upload-preferred">' .
232 $this->
msg(
'upload-preferred' )
233 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
234 ->numParams( count( $fileExtensions ) )
237 '<div id="mw-upload-prohibited">' .
238 $this->
msg(
'upload-prohibited' )
239 ->params( $this->
getLanguage()->commaList( $fileBlacklist ) )
240 ->numParams( count( $fileBlacklist ) )
245 # Everything is permitted.
246 $extensionsList =
'';
249 return $extensionsList;
260 if ( $this->mSessionKey ) {
261 $stash = MediaWikiServices::getInstance()->getRepoGroup()
262 ->getLocalRepo()->getUploadStash( $this->
getUser() );
264 $file = $stash->getFile( $this->mSessionKey );
265 }
catch ( Exception $e ) {
269 $mto =
$file->transform( [
'width' => 120 ] );
272 '<div class="thumb t' .
273 MediaWikiServices::getInstance()->getContentLanguage()->alignEnd() .
'">' .
274 Html::element(
'img', [
275 'src' => $mto->getUrl(),
276 'class' =>
'thumbimage',
277 ] ) .
'</div>',
'description' );
285 'section' =>
'description',
286 'id' =>
'wpDestFile',
287 'label-message' =>
'destfilename',
290 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
291 'nodata' => strval( $this->mDestFile ) !==
'',
293 'UploadDescription' => [
294 'type' =>
'textarea',
295 'section' =>
'description',
296 'id' =>
'wpUploadDescription',
297 'label-message' => $this->mForReUpload
298 ?
'filereuploadsummary'
299 :
'fileuploadsummary',
305 if ( $this->mTextAfterSummary ) {
306 $descriptor[
'UploadFormTextAfterSummary'] = [
308 'section' =>
'description',
316 'type' =>
'edittools',
317 'section' =>
'description',
318 'message' =>
'edittools-upload',
322 if ( $this->mForReUpload ) {
323 $descriptor[
'DestFile'][
'readonly'] =
true;
325 $descriptor[
'License'] = [
327 'class' => Licenses::class,
328 'section' =>
'description',
330 'label-message' =>
'license',
334 if ( $config->get(
'UseCopyrightUpload' ) ) {
335 $descriptor[
'UploadCopyStatus'] = [
337 'section' =>
'description',
338 'id' =>
'wpUploadCopyStatus',
339 'label-message' =>
'filestatus',
341 $descriptor[
'UploadSource'] = [
343 'section' =>
'description',
344 'id' =>
'wpUploadSource',
345 'label-message' =>
'filesource',
360 if ( $user->isLoggedIn() ) {
364 'id' =>
'wpWatchthis',
365 'label-message' =>
'watchthisupload',
366 'section' =>
'options',
371 if ( !$this->mHideIgnoreWarning ) {
372 $descriptor[
'IgnoreWarning'] = [
374 'id' =>
'wpIgnoreWarning',
375 'label-message' =>
'ignorewarnings',
376 'section' =>
'options',
380 $descriptor[
'DestFileWarningAck'] = [
382 'id' =>
'wpDestFileWarningAck',
383 'default' => $this->mDestWarningAck ?
'1' :
'',
386 if ( $this->mForReUpload ) {
387 $descriptor[
'ForReUpload'] = [
389 'id' =>
'wpForReUpload',
403 return parent::show();
412 $this->mMaxUploadSize[
'*'] = UploadBase::getMaxUploadSize();
415 'wgAjaxUploadDestCheck' => $config->get(
'AjaxUploadDestCheck' ),
416 'wgAjaxLicensePreview' => $config->get(
'AjaxLicensePreview' ),
417 'wgUploadAutoFill' => !$this->mForReUpload &&
420 $this->mDestFile ===
'',
422 'wgCheckFileExtensions' => $config->get(
'CheckFileExtensions' ),
423 'wgStrictFileExtensions' => $config->get(
'StrictFileExtensions' ),
424 'wgFileExtensions' => array_values( array_unique( $config->get(
'FileExtensions' ) ) ),
425 'wgCapitalizeUploads' => MediaWikiServices::getInstance()->getNamespaceInfo()->
428 'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
432 $out->addJsConfigVars( $scriptVars );
435 'mediawiki.special.upload',
getUser()
Stable to override.
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 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.