/** @var FormOptions */
protected $opts;
+ /** @var string[] */
+ protected $mediaTypes;
+
public function __construct() {
parent::__construct( 'Newimages' );
}
public function execute( $par ) {
$this->setHeaders();
$this->outputHeader();
+ $mimeAnalyzer = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
+ $this->mediaTypes = $mimeAnalyzer->getMediaTypes();
$out = $this->getOutput();
$out->addModules( 'mediawiki.special.newFiles' );
$opts->add( 'user', '' );
$opts->add( 'showbots', false );
$opts->add( 'hidepatrolled', false );
+ $opts->add( 'mediatype', $this->mediaTypes );
$opts->add( 'limit', 50 );
$opts->add( 'offset', '' );
$opts->add( 'start', '' );
$opts->setValue( 'end', $end, true );
}
+ // if all media types have been selected, wipe out the array to prevent
+ // the pointless IN(...) query condition (which would have no effect
+ // because every possible type has been selected)
+ $missingMediaTypes = array_diff( $this->mediaTypes, $opts->getValue( 'mediatype' ) );
+ if ( empty( $missingMediaTypes ) ) {
+ $opts->setValue( 'mediatype', [] );
+ }
+
$opts->validateIntBounds( 'limit', 0, 500 );
$this->opts = $opts;
}
protected function buildForm() {
+ $mediaTypesText = array_map( function ( $type ) {
+ // mediastatistics-header-unknown, mediastatistics-header-bitmap,
+ // mediastatistics-header-drawing, mediastatistics-header-audio,
+ // mediastatistics-header-video, mediastatistics-header-multimedia,
+ // mediastatistics-header-office, mediastatistics-header-text,
+ // mediastatistics-header-executable, mediastatistics-header-archive,
+ return $this->msg( 'mediastatistics-header-' . strtolower( $type ) )->text();
+ }, $this->mediaTypes );
+ $mediaTypesOptions = array_combine( $mediaTypesText, $this->mediaTypes );
+ ksort( $mediaTypesOptions );
+
$formDescriptor = [
'like' => [
'type' => 'text',
'name' => 'hidepatrolled',
],
+ 'mediatype' => [
+ 'type' => 'multiselect',
+ 'dropdown' => true,
+ 'flatlist' => true,
+ 'name' => 'mediatype',
+ 'label-message' => 'newimages-mediatype',
+ 'options' => $mediaTypesOptions,
+ 'default' => $this->mediaTypes,
+ ],
+
'limit' => [
'type' => 'hidden',
'default' => $this->opts->getValue( 'limit' ),
}
HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
+ // For the 'multiselect' field values to be preserved on submit
+ ->setFormIdentifier( 'specialnewimages' )
->setWrapperLegendMsg( 'newimages-legend' )
->setSubmitTextMsg( 'ilsubmit' )
->setMethod( 'get' )
"newimages-user": "Caption of the username/IP address editbox on [[Special:NewImages]]",
"newimages-showbots": "Used as label for a checkbox. When checked, [[Special:NewImages]] will also display uploads by users in the bots group.",
"newimages-hidepatrolled": "Used as label for a checkbox. When checked, [[Special:NewImages]] will not display patrolled uploads.\n\nCf. {{msg-mw|tog-hidepatrolled}} and {{msg-mw|apihelp-feedrecentchanges-param-hidepatrolled}}.",
+ "newimages-mediatype": "Used as label for a multiselect where users can select the media types to display.",
"noimages": "This is shown on the special page [[Special:NewImages]], when there aren't any recently uploaded files.",
"gallery-slideshow-toggle": "Tooltip for the icon that toggles thumbnails on a slideshow gallery.",
"ilsubmit": "Search button in [[Special:MIMESearch]].\n\nStrings on the page:\n* {{msg-mw|Mimesearch|page title, legend of input form, link in special pages}}\n* {{msg-mw|Mimesearch-summary|page summary}}\n* {{msg-mw|Mimetype|label for input box}}\n* {{msg-mw|Ilsubmit|search button}}\n\nCheck [[mw:Manual:MIME_type_detection]] for MIME types.\n\n{{Identical|Search}}",