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