3 * Implements Special:Newimages
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
24 class SpecialNewFiles
extends IncludableSpecialPage
{
25 /** @var FormOptions */
29 protected $mediaTypes;
31 public function __construct() {
32 parent
::__construct( 'Newimages' );
35 public function execute( $par ) {
37 $this->outputHeader();
38 $mimeAnalyzer = MediaWiki\MediaWikiServices
::getInstance()->getMimeAnalyzer();
39 $this->mediaTypes
= $mimeAnalyzer->getMediaTypes();
41 $out = $this->getOutput();
42 $out->addModules( 'mediawiki.special.newFiles' );
43 $this->addHelpLink( 'Help:New images' );
45 $opts = new FormOptions();
47 $opts->add( 'like', '' );
48 $opts->add( 'user', '' );
49 $opts->add( 'showbots', false );
50 $opts->add( 'hidepatrolled', false );
51 $opts->add( 'mediatype', $this->mediaTypes
);
52 $opts->add( 'limit', 50 );
53 $opts->add( 'offset', '' );
54 $opts->add( 'start', '' );
55 $opts->add( 'end', '' );
57 $opts->fetchValuesFromRequest( $this->getRequest() );
59 if ( $par !== null ) {
60 $opts->setValue( is_numeric( $par ) ?
'limit' : 'like', $par );
63 // If start date comes after end date chronologically, swap them.
64 // They are swapped in the interface by JS.
65 $start = $opts->getValue( 'start' );
66 $end = $opts->getValue( 'end' );
67 if ( $start !== '' && $end !== '' && $start > $end ) {
72 $opts->setValue( 'start', $start, true );
73 $opts->setValue( 'end', $end, true );
76 // if all media types have been selected, wipe out the array to prevent
77 // the pointless IN(...) query condition (which would have no effect
78 // because every possible type has been selected)
79 $missingMediaTypes = array_diff( $this->mediaTypes
, $opts->getValue( 'mediatype' ) );
80 if ( empty( $missingMediaTypes ) ) {
81 $opts->setValue( 'mediatype', [] );
84 $opts->validateIntBounds( 'limit', 0, 500 );
88 if ( !$this->including() ) {
93 $pager = new NewFilesPager( $this->getContext(), $opts );
95 $out->addHTML( $pager->getBody() );
96 if ( !$this->including() ) {
97 $out->addHTML( $pager->getNavigationBar() );
101 protected function buildForm() {
102 $mediaTypesText = array_map( function ( $type ) {
103 // mediastatistics-header-unknown, mediastatistics-header-bitmap,
104 // mediastatistics-header-drawing, mediastatistics-header-audio,
105 // mediastatistics-header-video, mediastatistics-header-multimedia,
106 // mediastatistics-header-office, mediastatistics-header-text,
107 // mediastatistics-header-executable, mediastatistics-header-archive,
108 return $this->msg( 'mediastatistics-header-' . strtolower( $type ) )->text();
109 }, $this->mediaTypes
);
110 $mediaTypesOptions = array_combine( $mediaTypesText, $this->mediaTypes
);
111 ksort( $mediaTypesOptions );
116 'label-message' => 'newimages-label',
122 'label-message' => 'newimages-user',
128 'label-message' => 'newimages-showbots',
129 'name' => 'showbots',
134 'label-message' => 'newimages-hidepatrolled',
135 'name' => 'hidepatrolled',
139 'type' => 'multiselect',
142 'name' => 'mediatype',
143 'label-message' => 'newimages-mediatype',
144 'options' => $mediaTypesOptions,
145 'default' => $this->mediaTypes
,
150 'default' => $this->opts
->getValue( 'limit' ),
156 'default' => $this->opts
->getValue( 'offset' ),
162 'label-message' => 'date-range-from',
168 'label-message' => 'date-range-to',
173 if ( $this->getConfig()->get( 'MiserMode' ) ) {
174 unset( $formDescriptor['like'] );
177 if ( !$this->getUser()->useFilePatrol() ) {
178 unset( $formDescriptor['hidepatrolled'] );
181 HTMLForm
::factory( 'ooui', $formDescriptor, $this->getContext() )
182 // For the 'multiselect' field values to be preserved on submit
183 ->setFormIdentifier( 'specialnewimages' )
184 ->setWrapperLegendMsg( 'newimages-legend' )
185 ->setSubmitTextMsg( 'ilsubmit' )
188 ->displayForm( false );
191 protected function getGroupName() {
196 * Send the text to be displayed above the options
198 function setTopText() {
201 $message = $this->msg( 'newimagestext' )->inContentLanguage();
202 if ( !$message->isDisabled() ) {
203 $this->getOutput()->addWikiText(
204 Html
::rawElement( 'p',
205 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
206 "\n" . $message->plain() . "\n"
208 /* $lineStart */ false,
209 /* $interface */ false