Add mediastatistics-header-3d
[lhc/web/wiklou.git] / includes / specials / SpecialNewimages.php
1 <?php
2 /**
3 * Implements Special:Newimages
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 class SpecialNewFiles extends IncludableSpecialPage {
25 /** @var FormOptions */
26 protected $opts;
27
28 /** @var string[] */
29 protected $mediaTypes;
30
31 public function __construct() {
32 parent::__construct( 'Newimages' );
33 }
34
35 public function execute( $par ) {
36 $this->setHeaders();
37 $this->outputHeader();
38 $mimeAnalyzer = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
39 $this->mediaTypes = $mimeAnalyzer->getMediaTypes();
40
41 $out = $this->getOutput();
42 $this->addHelpLink( 'Help:New images' );
43
44 $opts = new FormOptions();
45
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', '' );
56
57 $opts->fetchValuesFromRequest( $this->getRequest() );
58
59 if ( $par !== null ) {
60 $opts->setValue( is_numeric( $par ) ? 'limit' : 'like', $par );
61 }
62
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 ) {
68 $temp = $end;
69 $end = $start;
70 $start = $temp;
71
72 $opts->setValue( 'start', $start, true );
73 $opts->setValue( 'end', $end, true );
74 }
75
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', [] );
82 }
83
84 $opts->validateIntBounds( 'limit', 0, 500 );
85
86 $this->opts = $opts;
87
88 if ( !$this->including() ) {
89 $this->setTopText();
90 $this->buildForm();
91 }
92
93 $pager = new NewFilesPager( $this->getContext(), $opts );
94
95 $out->addHTML( $pager->getBody() );
96 if ( !$this->including() ) {
97 $out->addHTML( $pager->getNavigationBar() );
98 }
99 }
100
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 // mediastatistics-header-3d,
109 return $this->msg( 'mediastatistics-header-' . strtolower( $type ) )->text();
110 }, $this->mediaTypes );
111 $mediaTypesOptions = array_combine( $mediaTypesText, $this->mediaTypes );
112 ksort( $mediaTypesOptions );
113
114 $formDescriptor = [
115 'like' => [
116 'type' => 'text',
117 'label-message' => 'newimages-label',
118 'name' => 'like',
119 ],
120
121 'user' => [
122 'type' => 'text',
123 'label-message' => 'newimages-user',
124 'name' => 'user',
125 ],
126
127 'newbies' => [
128 'type' => 'check',
129 'label-message' => 'newimages-newbies',
130 'name' => 'newbies',
131 ],
132
133 'showbots' => [
134 'type' => 'check',
135 'label-message' => 'newimages-showbots',
136 'name' => 'showbots',
137 ],
138
139 'hidepatrolled' => [
140 'type' => 'check',
141 'label-message' => 'newimages-hidepatrolled',
142 'name' => 'hidepatrolled',
143 ],
144
145 'mediatype' => [
146 'type' => 'multiselect',
147 'dropdown' => true,
148 'flatlist' => true,
149 'name' => 'mediatype',
150 'label-message' => 'newimages-mediatype',
151 'options' => $mediaTypesOptions,
152 'default' => $this->mediaTypes,
153 ],
154
155 'limit' => [
156 'type' => 'hidden',
157 'default' => $this->opts->getValue( 'limit' ),
158 'name' => 'limit',
159 ],
160
161 'offset' => [
162 'type' => 'hidden',
163 'default' => $this->opts->getValue( 'offset' ),
164 'name' => 'offset',
165 ],
166
167 'start' => [
168 'type' => 'date',
169 'label-message' => 'date-range-from',
170 'name' => 'start',
171 ],
172
173 'end' => [
174 'type' => 'date',
175 'label-message' => 'date-range-to',
176 'name' => 'end',
177 ],
178 ];
179
180 if ( $this->getConfig()->get( 'MiserMode' ) ) {
181 unset( $formDescriptor['like'] );
182 }
183
184 if ( !$this->getUser()->useFilePatrol() ) {
185 unset( $formDescriptor['hidepatrolled'] );
186 }
187
188 HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
189 // For the 'multiselect' field values to be preserved on submit
190 ->setFormIdentifier( 'specialnewimages' )
191 ->setWrapperLegendMsg( 'newimages-legend' )
192 ->setSubmitTextMsg( 'ilsubmit' )
193 ->setMethod( 'get' )
194 ->prepareForm()
195 ->displayForm( false );
196
197 $this->getOutput()->addModules( 'mediawiki.special.newFiles' );
198 }
199
200 protected function getGroupName() {
201 return 'changes';
202 }
203
204 /**
205 * Send the text to be displayed above the options
206 */
207 function setTopText() {
208 global $wgContLang;
209
210 $message = $this->msg( 'newimagestext' )->inContentLanguage();
211 if ( !$message->isDisabled() ) {
212 $this->getOutput()->addWikiText(
213 Html::rawElement( 'p',
214 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
215 "\n" . $message->plain() . "\n"
216 ),
217 /* $lineStart */ false,
218 /* $interface */ false
219 );
220 }
221 }
222 }