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