Convert all array() syntax to []
[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 public function __construct() {
26 parent::__construct( 'Newimages' );
27 }
28
29 public function execute( $par ) {
30 $this->setHeaders();
31 $this->outputHeader();
32
33 $out = $this->getOutput();
34 $this->addHelpLink( 'Help:New images' );
35
36 $pager = new NewFilesPager( $this->getContext(), $par );
37
38 if ( !$this->including() ) {
39 $this->setTopText();
40 $form = $pager->getForm();
41 $form->prepareForm();
42 $form->displayForm( '' );
43 }
44
45 $out->addHTML( $pager->getBody() );
46 if ( !$this->including() ) {
47 $out->addHTML( $pager->getNavigationBar() );
48 }
49 }
50
51 protected function getGroupName() {
52 return 'changes';
53 }
54
55 /**
56 * Send the text to be displayed above the options
57 */
58 function setTopText() {
59 global $wgContLang;
60
61 $message = $this->msg( 'newimagestext' )->inContentLanguage();
62 if ( !$message->isDisabled() ) {
63 $this->getOutput()->addWikiText(
64 Html::rawElement( 'p',
65 [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
66 "\n" . $message->plain() . "\n"
67 ),
68 /* $lineStart */ false,
69 /* $interface */ false
70 );
71 }
72 }
73 }
74
75 /**
76 * @ingroup SpecialPage Pager
77 */
78 class NewFilesPager extends ReverseChronologicalPager {
79 /**
80 * @var ImageGallery
81 */
82 protected $gallery;
83
84 /**
85 * @var bool
86 */
87 protected $showBots;
88
89 /**
90 * @var bool
91 */
92 protected $hidePatrolled;
93
94 function __construct( IContextSource $context, $par = null ) {
95 $this->like = $context->getRequest()->getText( 'like' );
96 $this->showBots = $context->getRequest()->getBool( 'showbots', 0 );
97 $this->hidePatrolled = $context->getRequest()->getBool( 'hidepatrolled', 0 );
98 if ( is_numeric( $par ) ) {
99 $this->setLimit( $par );
100 }
101
102 parent::__construct( $context );
103 }
104
105 function getQueryInfo() {
106 $conds = $jconds = [];
107 $tables = [ 'image' ];
108
109 if ( !$this->showBots ) {
110 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
111
112 if ( count( $groupsWithBotPermission ) ) {
113 $tables[] = 'user_groups';
114 $conds[] = 'ug_group IS NULL';
115 $jconds['user_groups'] = [
116 'LEFT JOIN',
117 [
118 'ug_group' => $groupsWithBotPermission,
119 'ug_user = img_user'
120 ]
121 ];
122 }
123 }
124
125 if ( $this->hidePatrolled ) {
126 $tables[] = 'recentchanges';
127 $conds['rc_type'] = RC_LOG;
128 $conds['rc_log_type'] = 'upload';
129 $conds['rc_patrolled'] = 0;
130 $jconds['recentchanges'] = [
131 'INNER JOIN',
132 [
133 'rc_title = img_name',
134 'rc_user = img_user',
135 'rc_timestamp = img_timestamp'
136 ]
137 ];
138 }
139
140 if ( !$this->getConfig()->get( 'MiserMode' ) && $this->like !== null ) {
141 $dbr = wfGetDB( DB_SLAVE );
142 $likeObj = Title::newFromText( $this->like );
143 if ( $likeObj instanceof Title ) {
144 $like = $dbr->buildLike(
145 $dbr->anyString(),
146 strtolower( $likeObj->getDBkey() ),
147 $dbr->anyString()
148 );
149 $conds[] = "LOWER(img_name) $like";
150 }
151 }
152
153 $query = [
154 'tables' => $tables,
155 'fields' => '*',
156 'join_conds' => $jconds,
157 'conds' => $conds
158 ];
159
160 return $query;
161 }
162
163 function getIndexField() {
164 return 'img_timestamp';
165 }
166
167 function getStartBody() {
168 if ( !$this->gallery ) {
169 // Note that null for mode is taken to mean use default.
170 $mode = $this->getRequest()->getVal( 'gallerymode', null );
171 try {
172 $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
173 } catch ( Exception $e ) {
174 // User specified something invalid, fallback to default.
175 $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
176 }
177 }
178
179 return '';
180 }
181
182 function getEndBody() {
183 return $this->gallery->toHTML();
184 }
185
186 function formatRow( $row ) {
187 $name = $row->img_name;
188 $user = User::newFromId( $row->img_user );
189
190 $title = Title::makeTitle( NS_FILE, $name );
191 $ul = Linker::link( $user->getUserpage(), $user->getName() );
192 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
193
194 $this->gallery->add(
195 $title,
196 "$ul<br />\n<i>"
197 . htmlspecialchars( $time )
198 . "</i><br />\n"
199 );
200 }
201
202 function getForm() {
203 $fields = [
204 'like' => [
205 'type' => 'text',
206 'label-message' => 'newimages-label',
207 'name' => 'like',
208 ],
209 'showbots' => [
210 'type' => 'check',
211 'label-message' => 'newimages-showbots',
212 'name' => 'showbots',
213 ],
214 'hidepatrolled' => [
215 'type' => 'check',
216 'label-message' => 'newimages-hidepatrolled',
217 'name' => 'hidepatrolled',
218 ],
219 'limit' => [
220 'type' => 'hidden',
221 'default' => $this->mLimit,
222 'name' => 'limit',
223 ],
224 'offset' => [
225 'type' => 'hidden',
226 'default' => $this->getRequest()->getText( 'offset' ),
227 'name' => 'offset',
228 ],
229 ];
230
231 if ( $this->getConfig()->get( 'MiserMode' ) ) {
232 unset( $fields['like'] );
233 }
234
235 if ( !$this->getUser()->useFilePatrol() ) {
236 unset( $fields['hidepatrolled'] );
237 }
238
239 $context = new DerivativeContext( $this->getContext() );
240 $context->setTitle( $this->getTitle() ); // Remove subpage
241 $form = new HTMLForm( $fields, $context );
242
243 $form->setSubmitTextMsg( 'ilsubmit' );
244 $form->setSubmitProgressive();
245
246 $form->setMethod( 'get' );
247 $form->setWrapperLegendMsg( 'newimages-legend' );
248
249 return $form;
250 }
251 }