Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
4.39% |
13 / 296 |
|
0.00% |
0 / 22 |
CRAP | |
0.00% |
0 / 1 |
ImageListPager | |
4.41% |
13 / 295 |
|
0.00% |
0 / 22 |
6396.30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
110 | |||
getRelevantUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
outputUserDoesNotExist | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
buildQueryConds | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
getFieldNames | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
30 | |||
isFieldSortable | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
30 | |||
getQueryInfo | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfoReal | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
20 | |||
reallyDoQuery | |
0.00% |
0 / 36 |
|
0.00% |
0 / 1 |
42 | |||
combineResult | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
132 | |||
getIndexField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultSort | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
doBatchLookups | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
20 | |||
formatValue | |
25.00% |
13 / 52 |
|
0.00% |
0 / 1 |
109.92 | |||
getEscapedLimitSelectList | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getForm | |
0.00% |
0 / 40 |
|
0.00% |
0 / 1 |
2 | |||
getTableClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getNavClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSortHeaderClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPagingQueries | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
getDefaultQuery | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
getTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | * @ingroup Pager |
20 | */ |
21 | |
22 | namespace MediaWiki\Pager; |
23 | |
24 | use LocalRepo; |
25 | use MediaWiki\Cache\LinkBatchFactory; |
26 | use MediaWiki\CommentFormatter\RowCommentFormatter; |
27 | use MediaWiki\CommentStore\CommentStore; |
28 | use MediaWiki\Context\IContextSource; |
29 | use MediaWiki\Html\Html; |
30 | use MediaWiki\HTMLForm\HTMLForm; |
31 | use MediaWiki\Linker\Linker; |
32 | use MediaWiki\Linker\LinkRenderer; |
33 | use MediaWiki\MainConfigNames; |
34 | use MediaWiki\SpecialPage\SpecialPage; |
35 | use MediaWiki\Title\Title; |
36 | use MediaWiki\User\User; |
37 | use MediaWiki\User\UserNameUtils; |
38 | use MediaWiki\Xml\Xml; |
39 | use RepoGroup; |
40 | use UnexpectedValueException; |
41 | use Wikimedia\Rdbms\FakeResultWrapper; |
42 | use Wikimedia\Rdbms\IConnectionProvider; |
43 | use Wikimedia\Rdbms\IResultWrapper; |
44 | use Wikimedia\Rdbms\Subquery; |
45 | |
46 | /** |
47 | * @ingroup Pager |
48 | */ |
49 | class ImageListPager extends TablePager { |
50 | |
51 | /** @var string[]|null */ |
52 | protected $mFieldNames = null; |
53 | /** |
54 | * @deprecated Subclasses should override {@see buildQueryConds} instead |
55 | * @var array |
56 | */ |
57 | protected $mQueryConds = []; |
58 | /** @var string|null */ |
59 | protected $mUserName = null; |
60 | /** @var User|null The relevant user */ |
61 | protected $mUser = null; |
62 | /** @var bool */ |
63 | protected $mIncluding = false; |
64 | /** @var bool */ |
65 | protected $mShowAll = false; |
66 | /** @var string */ |
67 | protected $mTableName = 'image'; |
68 | |
69 | private CommentStore $commentStore; |
70 | private LocalRepo $localRepo; |
71 | private RowCommentFormatter $rowCommentFormatter; |
72 | private LinkBatchFactory $linkBatchFactory; |
73 | |
74 | /** @var string[] */ |
75 | private $formattedComments = []; |
76 | |
77 | /** |
78 | * The unique sort fields for the sort options for unique paginate |
79 | */ |
80 | private const INDEX_FIELDS = [ |
81 | 'img_timestamp' => [ 'img_timestamp', 'img_name' ], |
82 | 'img_name' => [ 'img_name' ], |
83 | 'img_size' => [ 'img_size', 'img_name' ], |
84 | ]; |
85 | |
86 | /** |
87 | * @param IContextSource $context |
88 | * @param CommentStore $commentStore |
89 | * @param LinkRenderer $linkRenderer |
90 | * @param IConnectionProvider $dbProvider |
91 | * @param RepoGroup $repoGroup |
92 | * @param UserNameUtils $userNameUtils |
93 | * @param RowCommentFormatter $rowCommentFormatter |
94 | * @param LinkBatchFactory $linkBatchFactory |
95 | * @param string $userName |
96 | * @param string $search |
97 | * @param bool $including |
98 | * @param bool $showAll |
99 | */ |
100 | public function __construct( |
101 | IContextSource $context, |
102 | CommentStore $commentStore, |
103 | LinkRenderer $linkRenderer, |
104 | IConnectionProvider $dbProvider, |
105 | RepoGroup $repoGroup, |
106 | UserNameUtils $userNameUtils, |
107 | RowCommentFormatter $rowCommentFormatter, |
108 | LinkBatchFactory $linkBatchFactory, |
109 | $userName, |
110 | $search, |
111 | $including, |
112 | $showAll |
113 | ) { |
114 | $this->setContext( $context ); |
115 | |
116 | $this->mIncluding = $including; |
117 | $this->mShowAll = $showAll; |
118 | |
119 | if ( $userName !== null && $userName !== '' ) { |
120 | $nt = Title::makeTitleSafe( NS_USER, $userName ); |
121 | if ( $nt === null ) { |
122 | $this->outputUserDoesNotExist( $userName ); |
123 | } else { |
124 | $this->mUserName = $nt->getText(); |
125 | $user = User::newFromName( $this->mUserName, false ); |
126 | if ( $user ) { |
127 | $this->mUser = $user; |
128 | } |
129 | if ( !$user || ( $user->isAnon() && !$userNameUtils->isIP( $user->getName() ) ) ) { |
130 | $this->outputUserDoesNotExist( $userName ); |
131 | } |
132 | } |
133 | } |
134 | |
135 | if ( $including || |
136 | $this->getRequest()->getText( 'sort', 'img_date' ) === 'img_date' |
137 | ) { |
138 | $this->mDefaultDirection = IndexPager::DIR_DESCENDING; |
139 | } else { |
140 | $this->mDefaultDirection = IndexPager::DIR_ASCENDING; |
141 | } |
142 | // Set database before parent constructor to avoid setting it there |
143 | $this->mDb = $dbProvider->getReplicaDatabase(); |
144 | |
145 | parent::__construct( $context, $linkRenderer ); |
146 | $this->commentStore = $commentStore; |
147 | $this->localRepo = $repoGroup->getLocalRepo(); |
148 | $this->rowCommentFormatter = $rowCommentFormatter; |
149 | $this->linkBatchFactory = $linkBatchFactory; |
150 | } |
151 | |
152 | /** |
153 | * Get the user relevant to the ImageList |
154 | * |
155 | * @return User|null |
156 | */ |
157 | public function getRelevantUser() { |
158 | return $this->mUser; |
159 | } |
160 | |
161 | /** |
162 | * Add a message to the output stating that the user doesn't exist |
163 | * |
164 | * @param string $userName Unescaped user name |
165 | */ |
166 | protected function outputUserDoesNotExist( $userName ) { |
167 | $this->getOutput()->addHTML( Html::warningBox( |
168 | $this->getOutput()->msg( 'listfiles-userdoesnotexist', wfEscapeWikiText( $userName ) )->parse(), |
169 | 'mw-userpage-userdoesnotexist' |
170 | ) ); |
171 | } |
172 | |
173 | /** |
174 | * Build the where clause of the query. |
175 | * |
176 | * Replaces the older mQueryConds member variable. |
177 | * @param string $table Either "image" or "oldimage" |
178 | * @return array The query conditions. |
179 | */ |
180 | protected function buildQueryConds( $table ) { |
181 | $conds = []; |
182 | |
183 | if ( $this->mUserName !== null ) { |
184 | // getQueryInfoReal() should have handled the tables and joins. |
185 | $conds['actor_name'] = $this->mUserName; |
186 | } |
187 | |
188 | if ( $table === 'oldimage' ) { |
189 | // Don't want to deal with revdel. |
190 | // Future fixme: Show partial information as appropriate. |
191 | // Would have to be careful about filtering by username when username is deleted. |
192 | $conds['oi_deleted'] = 0; |
193 | } |
194 | |
195 | // Add mQueryConds in case anyone was subclassing and using the old variable. |
196 | return $conds + $this->mQueryConds; |
197 | } |
198 | |
199 | protected function getFieldNames() { |
200 | if ( !$this->mFieldNames ) { |
201 | $this->mFieldNames = [ |
202 | 'img_timestamp' => $this->msg( 'listfiles_date' )->text(), |
203 | 'img_name' => $this->msg( 'listfiles_name' )->text(), |
204 | 'thumb' => $this->msg( 'listfiles_thumb' )->text(), |
205 | 'img_size' => $this->msg( 'listfiles_size' )->text(), |
206 | ]; |
207 | if ( $this->mUserName === null ) { |
208 | // Do not show username if filtering by username |
209 | $this->mFieldNames['img_actor'] = $this->msg( 'listfiles_user' )->text(); |
210 | } |
211 | // img_description down here, in order so that its still after the username field. |
212 | $this->mFieldNames['img_description'] = $this->msg( 'listfiles_description' )->text(); |
213 | |
214 | if ( $this->mShowAll ) { |
215 | $this->mFieldNames['top'] = $this->msg( 'listfiles-latestversion' )->text(); |
216 | } elseif ( !$this->getConfig()->get( MainConfigNames::MiserMode ) ) { |
217 | $this->mFieldNames['count'] = $this->msg( 'listfiles_count' )->text(); |
218 | } |
219 | } |
220 | |
221 | return $this->mFieldNames; |
222 | } |
223 | |
224 | protected function isFieldSortable( $field ) { |
225 | if ( $this->mIncluding ) { |
226 | return false; |
227 | } |
228 | /* For reference, the indices we can use for sorting are: |
229 | * On the image table: img_actor_timestamp, img_size, img_timestamp |
230 | * On oldimage: oi_actor_timestamp, oi_name_timestamp |
231 | * |
232 | * In particular that means we cannot sort by timestamp when not filtering |
233 | * by user and including old images in the results. Which is sad. (T279982) |
234 | */ |
235 | if ( $this->getConfig()->get( MainConfigNames::MiserMode ) ) { |
236 | if ( $this->mUserName !== null ) { |
237 | // If we're sorting by user, the index only supports sorting by time. |
238 | return $field === 'img_timestamp'; |
239 | } elseif ( $this->mShowAll ) { |
240 | // no oi_timestamp index, so only alphabetical sorting in this case. |
241 | return $field === 'img_name'; |
242 | } |
243 | } |
244 | |
245 | return isset( self::INDEX_FIELDS[$field] ); |
246 | } |
247 | |
248 | public function getQueryInfo() { |
249 | // Hacky Hacky Hacky - I want to get query info |
250 | // for two different tables, without reimplementing |
251 | // the pager class. |
252 | return $this->getQueryInfoReal( $this->mTableName ); |
253 | } |
254 | |
255 | /** |
256 | * Actually get the query info. |
257 | * |
258 | * This is to allow displaying both stuff from image and oldimage table. |
259 | * |
260 | * This is a bit hacky. |
261 | * |
262 | * @param string $table Either 'image' or 'oldimage' |
263 | * @return array Query info |
264 | */ |
265 | protected function getQueryInfoReal( $table ) { |
266 | $dbr = $this->getDatabase(); |
267 | $prefix = $table === 'oldimage' ? 'oi' : 'img'; |
268 | |
269 | $tables = [ $table, 'actor' ]; |
270 | $join_conds = []; |
271 | |
272 | if ( $table === 'oldimage' ) { |
273 | $fields = [ |
274 | 'img_timestamp' => 'oi_timestamp', |
275 | 'img_name' => 'oi_name', |
276 | 'img_size' => 'oi_size', |
277 | 'top' => $dbr->addQuotes( 'no' ) |
278 | ]; |
279 | $join_conds['actor'] = [ 'JOIN', 'actor_id=oi_actor' ]; |
280 | } else { |
281 | $fields = [ |
282 | 'img_timestamp', |
283 | 'img_name', |
284 | 'img_size', |
285 | 'top' => $dbr->addQuotes( 'yes' ) |
286 | ]; |
287 | $join_conds['actor'] = [ 'JOIN', 'actor_id=img_actor' ]; |
288 | } |
289 | |
290 | # Description field |
291 | $commentQuery = $this->commentStore->getJoin( $prefix . '_description' ); |
292 | $tables += $commentQuery['tables']; |
293 | $fields += $commentQuery['fields']; |
294 | $join_conds += $commentQuery['joins']; |
295 | $fields['description_field'] = $dbr->addQuotes( "{$prefix}_description" ); |
296 | |
297 | # Actor fields |
298 | $fields[] = 'actor_user'; |
299 | $fields[] = 'actor_name'; |
300 | |
301 | # Depends on $wgMiserMode |
302 | # Will also not happen if mShowAll is true. |
303 | if ( array_key_exists( 'count', $this->getFieldNames() ) ) { |
304 | $fields['count'] = new Subquery( $dbr->newSelectQueryBuilder() |
305 | ->select( 'COUNT(oi_archive_name)' ) |
306 | ->from( 'oldimage' ) |
307 | ->where( 'oi_name = img_name' ) |
308 | ->caller( __METHOD__ ) |
309 | ->getSQL() |
310 | ); |
311 | } |
312 | |
313 | return [ |
314 | 'tables' => $tables, |
315 | 'fields' => $fields, |
316 | 'conds' => $this->buildQueryConds( $table ), |
317 | 'options' => [], |
318 | 'join_conds' => $join_conds |
319 | ]; |
320 | } |
321 | |
322 | /** |
323 | * Override reallyDoQuery to mix together two queries. |
324 | * |
325 | * @param string $offset |
326 | * @param int $limit |
327 | * @param bool $order IndexPager::QUERY_ASCENDING or IndexPager::QUERY_DESCENDING |
328 | * @return IResultWrapper |
329 | */ |
330 | public function reallyDoQuery( $offset, $limit, $order ) { |
331 | $dbr = $this->getDatabase(); |
332 | $prevTableName = $this->mTableName; |
333 | $this->mTableName = 'image'; |
334 | [ $tables, $fields, $conds, $fname, $options, $join_conds ] = |
335 | $this->buildQueryInfo( $offset, $limit, $order ); |
336 | $imageRes = $dbr->newSelectQueryBuilder() |
337 | ->tables( is_array( $tables ) ? $tables : [ $tables ] ) |
338 | ->fields( $fields ) |
339 | ->conds( $conds ) |
340 | ->caller( $fname ) |
341 | ->options( $options ) |
342 | ->joinConds( $join_conds ) |
343 | ->fetchResultSet(); |
344 | $this->mTableName = $prevTableName; |
345 | |
346 | if ( !$this->mShowAll ) { |
347 | return $imageRes; |
348 | } |
349 | |
350 | $this->mTableName = 'oldimage'; |
351 | |
352 | # Hacky... |
353 | $oldIndex = $this->mIndexField; |
354 | foreach ( $this->mIndexField as &$index ) { |
355 | if ( !str_starts_with( $index, 'img_' ) ) { |
356 | throw new UnexpectedValueException( "Expected to be sorting on an image table field" ); |
357 | } |
358 | $index = 'oi_' . substr( $index, 4 ); |
359 | } |
360 | unset( $index ); |
361 | |
362 | [ $tables, $fields, $conds, $fname, $options, $join_conds ] = |
363 | $this->buildQueryInfo( $offset, $limit, $order ); |
364 | $oldimageRes = $dbr->newSelectQueryBuilder() |
365 | ->tables( is_array( $tables ) ? $tables : [ $tables ] ) |
366 | ->fields( $fields ) |
367 | ->conds( $conds ) |
368 | ->caller( $fname ) |
369 | ->options( $options ) |
370 | ->joinConds( $join_conds ) |
371 | ->fetchResultSet(); |
372 | |
373 | $this->mTableName = $prevTableName; |
374 | $this->mIndexField = $oldIndex; |
375 | |
376 | return $this->combineResult( $imageRes, $oldimageRes, $limit, $order ); |
377 | } |
378 | |
379 | /** |
380 | * Combine results from 2 tables. |
381 | * |
382 | * Note: This will throw away some results |
383 | * |
384 | * @param IResultWrapper $res1 |
385 | * @param IResultWrapper $res2 |
386 | * @param int $limit |
387 | * @param bool $order IndexPager::QUERY_ASCENDING or IndexPager::QUERY_DESCENDING |
388 | * @return IResultWrapper $res1 and $res2 combined |
389 | */ |
390 | protected function combineResult( $res1, $res2, $limit, $order ) { |
391 | $res1->rewind(); |
392 | $res2->rewind(); |
393 | $topRes1 = $res1->fetchObject(); |
394 | $topRes2 = $res2->fetchObject(); |
395 | $resultArray = []; |
396 | for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) { |
397 | if ( strcmp( $topRes1->{$this->mIndexField[0]}, $topRes2->{$this->mIndexField[0]} ) > 0 ) { |
398 | if ( $order !== IndexPager::QUERY_ASCENDING ) { |
399 | $resultArray[] = $topRes1; |
400 | $topRes1 = $res1->fetchObject(); |
401 | } else { |
402 | $resultArray[] = $topRes2; |
403 | $topRes2 = $res2->fetchObject(); |
404 | } |
405 | } elseif ( $order !== IndexPager::QUERY_ASCENDING ) { |
406 | $resultArray[] = $topRes2; |
407 | $topRes2 = $res2->fetchObject(); |
408 | } else { |
409 | $resultArray[] = $topRes1; |
410 | $topRes1 = $res1->fetchObject(); |
411 | } |
412 | } |
413 | |
414 | for ( ; $i < $limit && $topRes1; $i++ ) { |
415 | $resultArray[] = $topRes1; |
416 | $topRes1 = $res1->fetchObject(); |
417 | } |
418 | |
419 | for ( ; $i < $limit && $topRes2; $i++ ) { |
420 | $resultArray[] = $topRes2; |
421 | $topRes2 = $res2->fetchObject(); |
422 | } |
423 | |
424 | return new FakeResultWrapper( $resultArray ); |
425 | } |
426 | |
427 | public function getIndexField() { |
428 | return [ self::INDEX_FIELDS[$this->mSort] ]; |
429 | } |
430 | |
431 | public function getDefaultSort() { |
432 | if ( $this->mShowAll && |
433 | $this->getConfig()->get( MainConfigNames::MiserMode ) && |
434 | $this->mUserName === null |
435 | ) { |
436 | // Unfortunately no index on oi_timestamp. |
437 | return 'img_name'; |
438 | } else { |
439 | return 'img_timestamp'; |
440 | } |
441 | } |
442 | |
443 | protected function doBatchLookups() { |
444 | $this->mResult->seek( 0 ); |
445 | $batch = $this->linkBatchFactory->newLinkBatch(); |
446 | $rowsWithComments = [ 'img_description' => [], 'oi_description' => [] ]; |
447 | foreach ( $this->mResult as $i => $row ) { |
448 | $batch->add( NS_USER, $row->actor_name ); |
449 | $batch->add( NS_USER_TALK, $row->actor_name ); |
450 | $batch->add( NS_FILE, $row->img_name ); |
451 | $rowsWithComments[$row->description_field][$i] = $row; |
452 | } |
453 | $batch->execute(); |
454 | |
455 | // Format the comments |
456 | if ( $rowsWithComments['img_description'] ) { |
457 | $this->formattedComments += $this->rowCommentFormatter->formatRows( |
458 | $rowsWithComments['img_description'], |
459 | 'img_description' |
460 | ); |
461 | } |
462 | if ( $rowsWithComments['oi_description'] ) { |
463 | $this->formattedComments += $this->rowCommentFormatter->formatRows( |
464 | $rowsWithComments['oi_description'], |
465 | 'oi_description' |
466 | ); |
467 | } |
468 | } |
469 | |
470 | /** |
471 | * @param string $field |
472 | * @param string|null $value |
473 | * @return string |
474 | */ |
475 | public function formatValue( $field, $value ) { |
476 | $linkRenderer = $this->getLinkRenderer(); |
477 | switch ( $field ) { |
478 | case 'thumb': |
479 | $opt = [ 'time' => wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ]; |
480 | $file = $this->localRepo->findFile( $this->getCurrentRow()->img_name, $opt ); |
481 | // If statement for paranoia |
482 | if ( $file ) { |
483 | $thumb = $file->transform( [ 'width' => 180, 'height' => 360 ] ); |
484 | if ( $thumb ) { |
485 | return $thumb->toHtml( [ 'desc-link' => true, 'loading' => 'lazy' ] ); |
486 | } |
487 | return $this->msg( 'thumbnail_error', '' )->escaped(); |
488 | } else { |
489 | return htmlspecialchars( $this->getCurrentRow()->img_name ); |
490 | } |
491 | case 'img_timestamp': |
492 | // We may want to make this a link to the "old" version when displaying old files |
493 | return htmlspecialchars( $this->getLanguage()->userTimeAndDate( $value, $this->getUser() ) ); |
494 | case 'img_name': |
495 | static $imgfile = null; |
496 | $imgfile ??= $this->msg( 'imgfile' )->text(); |
497 | |
498 | // Weird files can maybe exist? T24227 |
499 | $filePage = Title::makeTitleSafe( NS_FILE, $value ); |
500 | if ( $filePage ) { |
501 | $html = $linkRenderer->makeKnownLink( |
502 | $filePage, |
503 | $filePage->getText() |
504 | ); |
505 | $opt = [ 'time' => wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ]; |
506 | $file = $this->localRepo->findFile( $value, $opt ); |
507 | if ( $file ) { |
508 | $download = Xml::element( |
509 | 'a', |
510 | [ 'href' => $file->getUrl() ], |
511 | $imgfile |
512 | ); |
513 | $html .= ' ' . $this->msg( 'parentheses' )->rawParams( $download )->escaped(); |
514 | } |
515 | |
516 | // Add delete links if allowed |
517 | // From https://github.com/Wikia/app/pull/3859 |
518 | if ( $this->getAuthority()->probablyCan( 'delete', $filePage ) ) { |
519 | $deleteMsg = $this->msg( 'listfiles-delete' )->text(); |
520 | |
521 | $delete = $linkRenderer->makeKnownLink( |
522 | $filePage, $deleteMsg, [], [ 'action' => 'delete' ] |
523 | ); |
524 | $html .= ' ' . $this->msg( 'parentheses' )->rawParams( $delete )->escaped(); |
525 | } |
526 | |
527 | return $html; |
528 | } else { |
529 | return htmlspecialchars( $value ); |
530 | } |
531 | case 'img_actor': |
532 | $userId = (int)$this->mCurrentRow->actor_user; |
533 | $userName = $this->mCurrentRow->actor_name; |
534 | return Linker::userLink( $userId, $userName ) |
535 | . Linker::userToolLinks( $userId, $userName ); |
536 | case 'img_size': |
537 | return htmlspecialchars( $this->getLanguage()->formatSize( (int)$value ) ); |
538 | case 'img_description': |
539 | return $this->formattedComments[$this->getResultOffset()]; |
540 | case 'count': |
541 | return htmlspecialchars( $this->getLanguage()->formatNum( intval( $value ) + 1 ) ); |
542 | case 'top': |
543 | // Messages: listfiles-latestversion-yes, listfiles-latestversion-no |
544 | return $this->msg( 'listfiles-latestversion-' . $value )->escaped(); |
545 | default: |
546 | throw new UnexpectedValueException( "Unknown field '$field'" ); |
547 | } |
548 | } |
549 | |
550 | /** |
551 | * Escape the options list |
552 | */ |
553 | private function getEscapedLimitSelectList(): array { |
554 | $list = $this->getLimitSelectList(); |
555 | $result = []; |
556 | foreach ( $list as $key => $value ) { |
557 | $result[htmlspecialchars( $key )] = $value; |
558 | } |
559 | return $result; |
560 | } |
561 | |
562 | public function getForm() { |
563 | $formDescriptor = []; |
564 | $formDescriptor['limit'] = [ |
565 | 'type' => 'radio', |
566 | 'name' => 'limit', |
567 | 'label-message' => 'table_pager_limit_label', |
568 | 'options' => $this->getEscapedLimitSelectList(), |
569 | 'flatlist' => true, |
570 | 'default' => $this->mLimit |
571 | ]; |
572 | |
573 | $formDescriptor['user'] = [ |
574 | 'type' => 'user', |
575 | 'name' => 'user', |
576 | 'id' => 'mw-listfiles-user', |
577 | 'label-message' => 'username', |
578 | 'default' => $this->mUserName, |
579 | 'size' => '40', |
580 | 'maxlength' => '255', |
581 | ]; |
582 | |
583 | $formDescriptor['ilshowall'] = [ |
584 | 'type' => 'check', |
585 | 'name' => 'ilshowall', |
586 | 'id' => 'mw-listfiles-show-all', |
587 | 'label-message' => 'listfiles-show-all', |
588 | 'default' => $this->mShowAll, |
589 | ]; |
590 | |
591 | $query = $this->getRequest()->getQueryValues(); |
592 | unset( $query['title'] ); |
593 | unset( $query['limit'] ); |
594 | unset( $query['ilsearch'] ); |
595 | unset( $query['ilshowall'] ); |
596 | unset( $query['user'] ); |
597 | |
598 | HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) |
599 | ->setMethod( 'get' ) |
600 | ->setId( 'mw-listfiles-form' ) |
601 | ->setTitle( $this->getTitle() ) |
602 | ->setSubmitTextMsg( 'listfiles-pager-submit' ) |
603 | ->setWrapperLegendMsg( 'listfiles' ) |
604 | ->addHiddenFields( $query ) |
605 | ->prepareForm() |
606 | ->displayForm( '' ); |
607 | } |
608 | |
609 | protected function getTableClass() { |
610 | return parent::getTableClass() . ' listfiles'; |
611 | } |
612 | |
613 | protected function getNavClass() { |
614 | return parent::getNavClass() . ' listfiles_nav'; |
615 | } |
616 | |
617 | protected function getSortHeaderClass() { |
618 | return parent::getSortHeaderClass() . ' listfiles_sort'; |
619 | } |
620 | |
621 | public function getPagingQueries() { |
622 | $queries = parent::getPagingQueries(); |
623 | if ( $this->mUserName !== null ) { |
624 | # Append the username to the query string |
625 | foreach ( $queries as &$query ) { |
626 | if ( $query !== false ) { |
627 | $query['user'] = $this->mUserName; |
628 | } |
629 | } |
630 | } |
631 | |
632 | return $queries; |
633 | } |
634 | |
635 | public function getDefaultQuery() { |
636 | $queries = parent::getDefaultQuery(); |
637 | if ( !isset( $queries['user'] ) && $this->mUserName !== null ) { |
638 | $queries['user'] = $this->mUserName; |
639 | } |
640 | |
641 | return $queries; |
642 | } |
643 | |
644 | public function getTitle() { |
645 | return SpecialPage::getTitleFor( 'Listfiles' ); |
646 | } |
647 | } |
648 | |
649 | /** |
650 | * Retain the old class name for backwards compatibility. |
651 | * @deprecated since 1.41 |
652 | */ |
653 | class_alias( ImageListPager::class, 'ImageListPager' ); |