Allow filtering on newbies in Special:NewFiles
[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 public function __construct() {
29 parent::__construct( 'Newimages' );
30 }
31
32 public function execute( $par ) {
33 $this->setHeaders();
34 $this->outputHeader();
35
36 $out = $this->getOutput();
37 $out->addModules( 'mediawiki.special.newFiles' );
38 $this->addHelpLink( 'Help:New images' );
39
40 $opts = new FormOptions();
41
42 $opts->add( 'like', '' );
43 $opts->add( 'user', '' );
44 $opts->add( 'showbots', false );
45 $opts->add( 'newbies', false );
46 $opts->add( 'hidepatrolled', false );
47 $opts->add( 'limit', 50 );
48 $opts->add( 'offset', '' );
49 $opts->add( 'start', '' );
50 $opts->add( 'end', '' );
51
52 $opts->fetchValuesFromRequest( $this->getRequest() );
53
54 if ( $par !== null ) {
55 $opts->setValue( is_numeric( $par ) ? 'limit' : 'like', $par );
56 }
57
58 // If start date comes after end date chronologically, swap them.
59 // They are swapped in the interface by JS.
60 $start = $opts->getValue( 'start' );
61 $end = $opts->getValue( 'end' );
62 if ( $start !== '' && $end !== '' && $start > $end ) {
63 $temp = $end;
64 $end = $start;
65 $start = $temp;
66
67 $opts->setValue( 'start', $start, true );
68 $opts->setValue( 'end', $end, true );
69 }
70
71 $opts->validateIntBounds( 'limit', 0, 500 );
72
73 $this->opts = $opts;
74
75 if ( !$this->including() ) {
76 $this->setTopText();
77 $this->buildForm();
78 }
79
80 $pager = new NewFilesPager( $this->getContext(), $opts );
81
82 $out->addHTML( $pager->getBody() );
83 if ( !$this->including() ) {
84 $out->addHTML( $pager->getNavigationBar() );
85 }
86 }
87
88 protected function buildForm() {
89 $formDescriptor = [
90 'like' => [
91 'type' => 'text',
92 'label-message' => 'newimages-label',
93 'name' => 'like',
94 ],
95
96 'user' => [
97 'type' => 'text',
98 'label-message' => 'newimages-user',
99 'name' => 'user',
100 ],
101
102 'newbies' => [
103 'type' => 'check',
104 'label-message' => 'newimages-newbies',
105 'name' => 'newbies',
106 ],
107
108 'showbots' => [
109 'type' => 'check',
110 'label-message' => 'newimages-showbots',
111 'name' => 'showbots',
112 ],
113
114 'hidepatrolled' => [
115 'type' => 'check',
116 'label-message' => 'newimages-hidepatrolled',
117 'name' => 'hidepatrolled',
118 ],
119
120 'limit' => [
121 'type' => 'hidden',
122 'default' => $this->opts->getValue( 'limit' ),
123 'name' => 'limit',
124 ],
125
126 'offset' => [
127 'type' => 'hidden',
128 'default' => $this->opts->getValue( 'offset' ),
129 'name' => 'offset',
130 ],
131
132 'start' => [
133 'type' => 'date',
134 'label-message' => 'date-range-from',
135 'name' => 'start',
136 ],
137
138 'end' => [
139 'type' => 'date',
140 'label-message' => 'date-range-to',
141 'name' => 'end',
142 ],
143 ];
144
145 if ( $this->getConfig()->get( 'MiserMode' ) ) {
146 unset( $formDescriptor['like'] );
147 }
148
149 if ( !$this->getUser()->useFilePatrol() ) {
150 unset( $formDescriptor['hidepatrolled'] );
151 }
152
153 HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
154 ->setWrapperLegendMsg( 'newimages-legend' )
155 ->setSubmitTextMsg( 'ilsubmit' )
156 ->setMethod( 'get' )
157 ->prepareForm()
158 ->displayForm( false );
159 }
160
161 protected function getGroupName() {
162 return 'changes';
163 }
164
165 /**
166 * Send the text to be displayed above the options
167 */
168 function setTopText() {
169 global $wgContLang;
170
171 $message = $this->msg( 'newimagestext' )->inContentLanguage();
172 if ( !$message->isDisabled() ) {
173 $this->getOutput()->addWikiText(
174 Html::rawElement( 'p',
175 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
176 "\n" . $message->plain() . "\n"
177 ),
178 /* $lineStart */ false,
179 /* $interface */ false
180 );
181 }
182 }
183 }