54 $including =
false, $showAll =
false
57 $this->mIncluding = $including;
58 $this->mShowAll = $showAll;
60 if ( $userName !==
null && $userName !==
'' ) {
62 if ( is_null( $nt ) ) {
65 $this->mUserName = $nt->getText();
76 if ( $search !==
'' && !$this->
getConfig()->
get(
'MiserMode' ) ) {
77 $this->mSearch = $search;
82 $this->mQueryConds[] =
'LOWER(img_name)' .
84 strtolower( $nt->getDBkey() ),
$dbr->anyString() );
89 if ( $this->
getRequest()->getText(
'sort',
'img_date' ) ==
'img_date' ) {
117 "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
119 'listfiles-userdoesnotexist',
133 $prefix = $table ===
'image' ?
'img' :
'oi';
136 if ( !is_null( $this->mUserName ) ) {
140 if ( $this->mSearch !==
'' ) {
144 $conds[] =
'LOWER(' . $prefix .
'_name)' .
146 strtolower( $nt->getDBkey() ),
$dbr->anyString() );
150 if ( $table ===
'oldimage' ) {
154 $conds[
'oi_deleted'] = 0;
165 if ( !$this->mFieldNames ) {
166 $this->mFieldNames = [
167 'img_timestamp' => $this->
msg(
'listfiles_date' )->text(),
168 'img_name' => $this->
msg(
'listfiles_name' )->text(),
169 'thumb' => $this->
msg(
'listfiles_thumb' )->text(),
170 'img_size' => $this->
msg(
'listfiles_size' )->text(),
172 if ( is_null( $this->mUserName ) ) {
174 $this->mFieldNames[
'img_user_text'] = $this->
msg(
'listfiles_user' )->text();
177 $this->mFieldNames[
'img_description'] = $this->
msg(
'listfiles_description' )->text();
179 if ( !$this->
getConfig()->
get(
'MiserMode' ) && !$this->mShowAll ) {
180 $this->mFieldNames[
'count'] = $this->
msg(
'listfiles_count' )->text();
182 if ( $this->mShowAll ) {
183 $this->mFieldNames[
'top'] = $this->
msg(
'listfiles-latestversion' )->text();
191 if ( $this->mIncluding ) {
194 $sortable = [
'img_timestamp',
'img_name',
'img_size' ];
203 if ( $this->
getConfig()->
get(
'MiserMode' ) && !is_null( $this->mUserName ) ) {
205 if ( $field ===
'img_timestamp' ) {
210 } elseif ( $this->
getConfig()->
get(
'MiserMode' )
214 if ( $field ===
'img_name' ) {
221 return in_array( $field, $sortable );
244 $prefix = $table ===
'oldimage' ?
'oi' :
'img';
249 if ( $table ===
'oldimage' ) {
250 foreach ( $fields
as $id => &$field ) {
251 if ( substr( $field, 0, 4 ) !==
'img_' ) {
254 $field = $prefix . substr( $field, 3 ) .
' AS ' . $field;
256 $fields[array_search(
'top', $fields )] =
"'no' AS top";
258 if ( $this->mShowAll ) {
259 $fields[array_search(
'top', $fields )] =
"'yes' AS top";
262 $fields[] = $prefix .
'_user AS img_user';
263 $fields[array_search(
'thumb', $fields )] = $prefix .
'_name AS thumb';
267 # Depends on $wgMiserMode
268 # Will also not happen if mShowAll is true.
269 if ( isset( $this->mFieldNames[
'count'] ) ) {
272 # Need to rewrite this one
273 foreach ( $fields
as &$field ) {
274 if ( $field ==
'count' ) {
275 $field =
'COUNT(oi_archive_name) AS count';
281 if (
$dbr->implicitGroupby() ) {
282 $options = [
'GROUP BY' =>
'img_name' ];
284 $columnlist = preg_grep(
'/^img/', array_keys( $this->
getFieldNames() ) );
285 $options = [
'GROUP BY' => array_merge( [
'img_user' ], $columnlist ) ];
287 $join_conds = [
'oldimage' => [
'LEFT JOIN',
'oi_name = img_name' ] ];
295 'join_conds' => $join_conds
313 $this->mTableName =
'image';
317 $this->mTableName = $prevTableName;
319 if ( !$this->mShowAll ) {
323 $this->mTableName =
'oldimage';
327 if ( substr( $this->mIndexField, 0, 4 ) !==
'img_' ) {
328 throw new MWException(
"Expected to be sorting on an image table field" );
330 $this->mIndexField =
'oi_' . substr( $this->mIndexField, 4 );
336 $this->mTableName = $prevTableName;
337 $this->mIndexField = $oldIndex;
356 $topRes1 = $res1->next();
357 $topRes2 = $res2->next();
359 for ( $i = 0; $i <
$limit && $topRes1 && $topRes2; $i++ ) {
360 if ( strcmp( $topRes1->{$this->mIndexField}, $topRes2->{$this->mIndexField} ) > 0 ) {
362 $resultArray[] = $topRes1;
363 $topRes1 = $res1->next();
365 $resultArray[] = $topRes2;
366 $topRes2 = $res2->next();
370 $resultArray[] = $topRes2;
371 $topRes2 = $res2->next();
373 $resultArray[] = $topRes1;
374 $topRes1 = $res1->next();
380 for ( ; $i <
$limit && $topRes1; $i++ ) {
382 $resultArray[] = $topRes1;
383 $topRes1 = $res1->next();
387 for ( ; $i <
$limit && $topRes2; $i++ ) {
389 $resultArray[] = $topRes2;
390 $topRes2 = $res2->next();
397 if ( $this->mShowAll && $this->getConfig()->
get(
'MiserMode' ) && is_null( $this->mUserName ) ) {
401 return 'img_timestamp';
407 $this->mResult->seek( 0 );
408 foreach ( $this->mResult
as $row ) {
409 $userIds[] = $row->img_user;
411 # Do a link batch query for names and userpages
430 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
433 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
437 $thumb = $file->transform( [
'width' => 180,
'height' => 360 ] );
439 return $thumb->toHtml( [
'desc-link' =>
true ] );
441 return wfMessage(
'thumbnail_error',
'' )->escaped();
444 return htmlspecialchars(
$value );
446 case 'img_timestamp':
448 return htmlspecialchars( $this->getLanguage()->userTimeAndDate(
$value, $this->getUser() ) );
450 static $imgfile =
null;
451 if ( $imgfile ===
null ) {
452 $imgfile = $this->msg(
'imgfile' )->text();
466 $download = $this->msg(
'parentheses' )->rawParams( $download )->escaped();
470 if ( $filePage->userCan(
'delete', $this->getUser() ) ) {
471 $deleteMsg = $this->msg(
'listfiles-delete' )->text();
474 $filePage, $deleteMsg, [], [
'action' =>
'delete' ]
476 $delete = $this->msg(
'parentheses' )->rawParams( $delete )->escaped();
478 return "$link $download $delete";
481 return "$link $download";
483 return htmlspecialchars(
$value );
485 case 'img_user_text':
486 if ( $this->mCurrentRow->img_user ) {
498 return htmlspecialchars( $this->getLanguage()->formatSize(
$value ) );
499 case 'img_description':
502 return $this->getLanguage()->formatNum( intval(
$value ) + 1 );
505 return $this->msg(
'listfiles-latestversion-' .
$value );
516 'label-message' =>
'table_pager_limit_label',
517 'options' => $this->getLimitSelectList(),
518 'default' => $this->mLimit,
521 if ( !$this->getConfig()->
get(
'MiserMode' ) ) {
522 $fields[
'ilsearch'] = [
524 'name' =>
'ilsearch',
525 'id' =>
'mw-ilsearch',
526 'label-message' =>
'listfiles_search_for',
527 'default' => $this->mSearch,
529 'maxlength' =>
'255',
533 $this->getOutput()->addModules(
'mediawiki.userSuggest' );
537 'id' =>
'mw-listfiles-user',
538 'label-message' =>
'username',
539 'default' => $this->mUserName,
541 'maxlength' =>
'255',
542 'cssclass' =>
'mw-autocomplete-user',
545 $fields[
'ilshowall'] = [
547 'name' =>
'ilshowall',
548 'id' =>
'mw-listfiles-show-all',
549 'label-message' =>
'listfiles-show-all',
550 'default' => $this->mShowAll,
553 $query = $this->getRequest()->getQueryValues();
556 unset(
$query[
'ilsearch'] );
557 unset(
$query[
'ilshowall'] );
562 $form->setMethod(
'get' );
563 $form->setTitle( $this->getTitle() );
564 $form->setId(
'mw-listfiles-form' );
565 $form->setWrapperLegendMsg(
'listfiles' );
566 $form->setSubmitTextMsg(
'table_pager_limit_submit' );
567 $form->addHiddenFields(
$query );
569 $form->prepareForm();
570 $form->displayForm(
'' );
574 return parent::getTableClass() .
' listfiles';
578 return parent::getNavClass() .
' listfiles_nav';
582 return parent::getSortHeaderClass() .
' listfiles_sort';
586 $queries = parent::getPagingQueries();
587 if ( !is_null( $this->mUserName ) ) {
588 # Append the username to the query string
591 $query[
'user'] = $this->mUserName;
600 $queries = parent::getDefaultQuery();
601 if ( !isset(
$queries[
'user'] ) && !is_null( $this->mUserName ) ) {
602 $queries[
'user'] = $this->mUserName;