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 $this->addHelpLink( 'Help:New images' );
44 $opts = new FormOptions();
46 $opts->add( 'like', '' );
47 $opts->add( 'user', '' );
48 $opts->add( 'showbots', false );
49 $opts->add( 'newbies', 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-newbies',
134 'label-message' => 'newimages-showbots',
135 'name' => 'showbots',
140 'label-message' => 'newimages-hidepatrolled',
141 'name' => 'hidepatrolled',
145 'type' => 'multiselect',
148 'name' => 'mediatype',
149 'label-message' => 'newimages-mediatype',
150 'options' => $mediaTypesOptions,
151 'default' => $this->mediaTypes
,
156 'default' => $this->opts
->getValue( 'limit' ),
162 'default' => $this->opts
->getValue( 'offset' ),
168 'label-message' => 'date-range-from',
174 'label-message' => 'date-range-to',
179 if ( $this->getConfig()->get( 'MiserMode' ) ) {
180 unset( $formDescriptor['like'] );
183 if ( !$this->getUser()->useFilePatrol() ) {
184 unset( $formDescriptor['hidepatrolled'] );
187 HTMLForm
::factory( 'ooui', $formDescriptor, $this->getContext() )
188 // For the 'multiselect' field values to be preserved on submit
189 ->setFormIdentifier( 'specialnewimages' )
190 ->setWrapperLegendMsg( 'newimages-legend' )
191 ->setSubmitTextMsg( 'ilsubmit' )
194 ->displayForm( false );
196 $this->getOutput()->addModules( 'mediawiki.special.newFiles' );
199 protected function getGroupName() {
204 * Send the text to be displayed above the options
206 function setTopText() {
209 $message = $this->msg( 'newimagestext' )->inContentLanguage();
210 if ( !$message->isDisabled() ) {
211 $this->getOutput()->addWikiText(
212 Html
::rawElement( 'p',
213 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
214 "\n" . $message->plain() . "\n"
216 /* $lineStart */ false,
217 /* $interface */ false