53 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
56 $this->mWatch = !empty(
$options[
'watch'] );
57 $this->mForReUpload = !empty(
$options[
'forreupload'] );
58 $this->mSessionKey =
$options[
'sessionkey'] ??
'';
59 $this->mHideIgnoreWarning = !empty(
$options[
'hideignorewarning'] );
60 $this->mDestWarningAck = !empty(
$options[
'destwarningack'] );
61 $this->mDestFile =
$options[
'destfile'] ??
'';
63 $this->mComment =
$options[
'description'] ??
'';
65 $this->mTextTop =
$options[
'texttop'] ??
'';
67 $this->mTextAfterSummary =
$options[
'textaftersummary'] ??
'';
70 $descriptor = $sourceDescriptor
74 Hooks::run(
'UploadFormInitDescriptor', [ &$descriptor ] );
75 parent::__construct( $descriptor,
$context,
'upload' );
77 # Add a link to edit MediaWiki:Licenses
78 if ( $this->
getUser()->isAllowed(
'editinterface' ) ) {
79 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
81 $this->
msg(
'licenses' )->inContentLanguage()->
getTitle(),
82 $this->
msg(
'licenses-edit' )->
text(),
84 [
'action' =>
'edit' ]
86 $editLicenses =
'<p class="mw-upload-editlicenses">' . $licensesLink .
'</p>';
90 # Set some form properties
93 # Used message keys: 'accesskey-upload', 'tooltip-upload'
95 $this->
setId(
'mw-upload-form' );
97 # Build a list of IDs for javascript insertion
98 $this->mSourceIds = [];
99 foreach ( $sourceDescriptor as $field ) {
100 if ( !empty( $field[
'id'] ) ) {
101 $this->mSourceIds[] = $field[
'id'];
113 if ( $this->mSessionKey ) {
121 'default' =>
'Stash',
128 && $this->
getConfig()->get(
'CopyUploadsFromSpecialUpload' );
129 $radio = $canUploadByUrl;
130 $selectedSourceType = strtolower( $this->
getRequest()->getText(
'wpSourceType',
'File' ) );
133 if ( $this->mTextTop ) {
134 $descriptor[
'UploadFormTextTop'] = [
136 'section' =>
'source',
142 $this->mMaxUploadSize[
'file'] = min(
147 $help = $this->
msg(
'upload-maxfilesize',
153 if ( $canUploadByUrl ) {
154 $help .= $this->
msg(
'word-separator' )->escaped();
155 $help .= $this->
msg(
'upload_source_file' )->parse();
158 $descriptor[
'UploadFile'] = [
159 'class' => UploadSourceField::class,
160 'section' =>
'source',
162 'id' =>
'wpUploadFile',
163 'radio-id' =>
'wpSourceTypeFile',
164 'label-message' =>
'sourcefilename',
165 'upload-type' =>
'File',
168 'checked' => $selectedSourceType ==
'file',
171 if ( $canUploadByUrl ) {
173 $descriptor[
'UploadFileURL'] = [
174 'class' => UploadSourceField::class,
175 'section' =>
'source',
176 'id' =>
'wpUploadFileURL',
177 'radio-id' =>
'wpSourceTypeurl',
178 'label-message' =>
'sourceurl',
179 'upload-type' =>
'url',
181 'help' => $this->
msg(
'upload-maxfilesize',
184 $this->
msg(
'word-separator' )->escaped() .
185 $this->
msg(
'upload_source_url' )->parse(),
186 'checked' => $selectedSourceType ==
'url',
189 Hooks::run(
'UploadFormSourceDescriptors', [ &$descriptor, &$radio, $selectedSourceType ] );
191 $descriptor[
'Extensions'] = [
193 'section' =>
'source',
207 # Print a list of allowed file extensions, if so configured. We ignore
208 # MIME type here, it's incomprehensible to most people and too long.
211 if ( $config->get(
'CheckFileExtensions' ) ) {
212 $fileExtensions = array_unique( $config->get(
'FileExtensions' ) );
213 if ( $config->get(
'StrictFileExtensions' ) ) {
214 # Everything not permitted is banned
216 '<div id="mw-upload-permitted">' .
217 $this->
msg(
'upload-permitted' )
218 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
219 ->numParams( count( $fileExtensions ) )
223 # We have to list both preferred and prohibited
224 $fileBlacklist = array_unique( $config->get(
'FileBlacklist' ) );
226 '<div id="mw-upload-preferred">' .
227 $this->
msg(
'upload-preferred' )
228 ->params( $this->
getLanguage()->commaList( $fileExtensions ) )
229 ->numParams( count( $fileExtensions ) )
232 '<div id="mw-upload-prohibited">' .
233 $this->
msg(
'upload-prohibited' )
234 ->params( $this->
getLanguage()->commaList( $fileBlacklist ) )
235 ->numParams( count( $fileBlacklist ) )
240 # Everything is permitted.
241 $extensionsList =
'';
244 return $extensionsList;
255 if ( $this->mSessionKey ) {
258 $file = $stash->getFile( $this->mSessionKey );
259 }
catch ( Exception
$e ) {
263 $mto = $file->transform( [
'width' => 120 ] );
266 '<div class="thumb t' .
267 MediaWikiServices::getInstance()->getContentLanguage()->alignEnd() .
'">' .
268 Html::element(
'img', [
269 'src' => $mto->getUrl(),
270 'class' =>
'thumbimage',
271 ] ) .
'</div>',
'description' );
279 'section' =>
'description',
280 'id' =>
'wpDestFile',
281 'label-message' =>
'destfilename',
284 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
285 'nodata' => strval( $this->mDestFile ) !==
'',
287 'UploadDescription' => [
288 'type' =>
'textarea',
289 'section' =>
'description',
290 'id' =>
'wpUploadDescription',
291 'label-message' => $this->mForReUpload
292 ?
'filereuploadsummary'
293 :
'fileuploadsummary',
299 if ( $this->mTextAfterSummary ) {
300 $descriptor[
'UploadFormTextAfterSummary'] = [
302 'section' =>
'description',
310 'type' =>
'edittools',
311 'section' =>
'description',
312 'message' =>
'edittools-upload',
316 if ( $this->mForReUpload ) {
317 $descriptor[
'DestFile'][
'readonly'] =
true;
319 $descriptor[
'License'] = [
321 'class' => Licenses::class,
322 'section' =>
'description',
324 'label-message' =>
'license',
328 if ( $config->get(
'UseCopyrightUpload' ) ) {
329 $descriptor[
'UploadCopyStatus'] = [
331 'section' =>
'description',
332 'id' =>
'wpUploadCopyStatus',
333 'label-message' =>
'filestatus',
335 $descriptor[
'UploadSource'] = [
337 'section' =>
'description',
338 'id' =>
'wpUploadSource',
339 'label-message' =>
'filesource',
354 if ( $user->isLoggedIn() ) {
358 'id' =>
'wpWatchthis',
359 'label-message' =>
'watchthisupload',
360 'section' =>
'options',
365 if ( !$this->mHideIgnoreWarning ) {
366 $descriptor[
'IgnoreWarning'] = [
368 'id' =>
'wpIgnoreWarning',
369 'label-message' =>
'ignorewarnings',
370 'section' =>
'options',
374 $descriptor[
'DestFileWarningAck'] = [
376 'id' =>
'wpDestFileWarningAck',
377 'default' => $this->mDestWarningAck ?
'1' :
'',
380 if ( $this->mForReUpload ) {
381 $descriptor[
'ForReUpload'] = [
383 'id' =>
'wpForReUpload',
408 'wgAjaxUploadDestCheck' => $config->get(
'AjaxUploadDestCheck' ),
409 'wgAjaxLicensePreview' => $config->get(
'AjaxLicensePreview' ),
410 'wgUploadAutoFill' => !$this->mForReUpload &&
413 $this->mDestFile ===
'',
415 'wgCheckFileExtensions' => $config->get(
'CheckFileExtensions' ),
416 'wgStrictFileExtensions' => $config->get(
'StrictFileExtensions' ),
417 'wgFileExtensions' => array_values( array_unique( $config->get(
'FileExtensions' ) ) ),
418 'wgCapitalizeUploads' => MWNamespace::isCapitalized(
NS_FILE ),
424 $out->addJsConfigVars( $scriptVars );
427 'mediawiki.special.upload',
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
getContext()
Get the base IContextSource object.
setContext(IContextSource $context)
static singleton()
Get a RepoGroup instance.
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( $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.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
returning false will NOT prevent logging $e
Interface for objects which can provide a MediaWiki context on request.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))