70 'img_timestamp' => [
'img_timestamp',
'img_name' ],
71 'img_name' => [
'img_name' ],
72 'img_size' => [
'img_size',
'img_name' ],
103 $this->mIncluding = $including;
104 $this->mShowAll = $showAll;
107 if ( $userName !==
null && $userName !==
'' ) {
109 if ( $nt ===
null ) {
112 $this->mUserName = $nt->getText();
115 $this->mUser = $user;
117 if ( !$user || ( $user->isAnon() && !
User::isIP( $user->getName() ) ) ) {
123 if ( $search !==
'' && !$this->
getConfig()->
get(
'MiserMode' ) ) {
124 $this->mSearch = $search;
128 $this->mQueryConds[] =
'LOWER(img_name)' .
130 strtolower( $nt->getDBkey() ),
$dbr->anyString() );
135 if ( $this->
getRequest()->getText(
'sort',
'img_date' ) ==
'img_date' ) {
169 "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
171 'listfiles-userdoesnotexist',
185 $prefix = $table ===
'image' ?
'img' :
'oi';
188 if ( $this->mUserName !==
null ) {
191 $actorWhere = $this->actorMigration->getWhere(
198 $conds[] = $actorWhere[
'conds'];
201 if ( $this->mSearch !==
'' ) {
205 $conds[] =
'LOWER(' . $prefix .
'_name)' .
207 strtolower( $nt->getDBkey() ),
$dbr->anyString() );
211 if ( $table ===
'oldimage' ) {
215 $conds[
'oi_deleted'] = 0;
229 if ( !$this->mFieldNames ) {
230 $this->mFieldNames = [
231 'img_timestamp' => $this->
msg(
'listfiles_date' )->text(),
232 'img_name' => $this->
msg(
'listfiles_name' )->text(),
233 'thumb' => $this->
msg(
'listfiles_thumb' )->text(),
234 'img_size' => $this->
msg(
'listfiles_size' )->text(),
236 if ( $this->mUserName ===
null ) {
238 $this->mFieldNames[
'img_user_text'] = $this->
msg(
'listfiles_user' )->text();
241 $this->mFieldNames[
'img_description'] = $this->
msg(
'listfiles_description' )->text();
243 if ( !$this->
getConfig()->
get(
'MiserMode' ) && !$this->mShowAll ) {
244 $this->mFieldNames[
'count'] = $this->
msg(
'listfiles_count' )->text();
246 if ( $this->mShowAll ) {
247 $this->mFieldNames[
'top'] = $this->
msg(
'listfiles-latestversion' )->text();
255 if ( $this->mIncluding ) {
258 $sortable = array_keys( self::INDEX_FIELDS );
267 if ( $this->
getConfig()->
get(
'MiserMode' ) && $this->mUserName !==
null ) {
269 if ( $field ===
'img_timestamp' ) {
274 } elseif ( $this->
getConfig()->
get(
'MiserMode' )
278 if ( $field ===
'img_name' ) {
285 return in_array( $field, $sortable );
309 $prefix = $table ===
'oldimage' ?
'oi' :
'img';
311 $tables = [ $table ];
313 $fields = array_combine( $fields, $fields );
314 unset( $fields[
'img_description'] );
315 unset( $fields[
'img_user_text'] );
317 if ( $table ===
'oldimage' ) {
318 foreach ( $fields as $id => $field ) {
319 if ( substr( $id, 0, 4 ) ===
'img_' ) {
320 $fields[$id] = $prefix . substr( $field, 3 );
323 $fields[
'top'] =
$dbr->addQuotes(
'no' );
324 } elseif ( $this->mShowAll ) {
325 $fields[
'top'] =
$dbr->addQuotes(
'yes' );
327 $fields[
'thumb'] = $prefix .
'_name';
329 $options = $join_conds = [];
332 $commentQuery = $this->commentStore->getJoin( $prefix .
'_description' );
333 $tables += $commentQuery[
'tables'];
334 $fields += $commentQuery[
'fields'];
335 $join_conds += $commentQuery[
'joins'];
336 $fields[
'description_field'] =
$dbr->addQuotes(
"{$prefix}_description" );
339 $actorQuery = $this->actorMigration->getJoin( $prefix .
'_user' );
340 $tables += $actorQuery[
'tables'];
341 $join_conds += $actorQuery[
'joins'];
342 $fields[
'img_user'] = $actorQuery[
'fields'][$prefix .
'_user'];
343 $fields[
'img_user_text'] = $actorQuery[
'fields'][$prefix .
'_user_text'];
344 $fields[
'img_actor'] = $actorQuery[
'fields'][$prefix .
'_actor'];
346 # Depends on $wgMiserMode
347 # Will also not happen if mShowAll is true.
348 if ( isset( $fields[
'count'] ) ) {
349 $fields[
'count'] =
$dbr->buildSelectSubquery(
351 'COUNT(oi_archive_name)',
352 'oi_name = img_name',
361 'options' => $options,
362 'join_conds' => $join_conds
378 $this->mTableName =
'image';
379 list( $tables, $fields, $conds, $fname, $options, $join_conds ) =
381 $imageRes =
$dbr->select( $tables, $fields, $conds, $fname, $options, $join_conds );
382 $this->mTableName = $prevTableName;
384 if ( !$this->mShowAll ) {
388 $this->mTableName =
'oldimage';
392 foreach ( $this->mIndexField as &$index ) {
393 if ( substr( $index, 0, 4 ) !==
'img_' ) {
394 throw new MWException(
"Expected to be sorting on an image table field" );
396 $index =
'oi_' . substr( $index, 4 );
399 list( $tables, $fields, $conds, $fname, $options, $join_conds ) =
401 $oldimageRes =
$dbr->select( $tables, $fields, $conds, $fname, $options, $join_conds );
403 $this->mTableName = $prevTableName;
404 $this->mIndexField = $oldIndex;
406 return $this->
combineResult( $imageRes, $oldimageRes, $limit, $order );
423 $topRes1 = $res1->next();
424 $topRes2 = $res2->next();
426 for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
427 if ( strcmp( $topRes1->{$this->mIndexField[0]}, $topRes2->{$this->mIndexField[0]} ) > 0 ) {
429 $resultArray[] = $topRes1;
430 $topRes1 = $res1->next();
432 $resultArray[] = $topRes2;
433 $topRes2 = $res2->next();
436 $resultArray[] = $topRes2;
437 $topRes2 = $res2->next();
439 $resultArray[] = $topRes1;
440 $topRes1 = $res1->next();
444 for ( ; $i < $limit && $topRes1; $i++ ) {
445 $resultArray[] = $topRes1;
446 $topRes1 = $res1->next();
449 for ( ; $i < $limit && $topRes2; $i++ ) {
450 $resultArray[] = $topRes2;
451 $topRes2 = $res2->next();
458 return [ self::INDEX_FIELDS[$this->mSort] ];
462 if ( $this->mShowAll && $this->getConfig()->
get(
'MiserMode' ) && $this->mUserName ===
null ) {
466 return 'img_timestamp';
472 $this->mResult->seek( 0 );
473 foreach ( $this->mResult as $row ) {
474 $userIds[] = $row->img_user;
476 # Do a link batch query for names and userpages
477 $this->userCache->doQuery( $userIds, [
'userpage' ], __METHOD__ );
495 $linkRenderer = $this->getLinkRenderer();
498 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
499 $file = $this->localRepo->findFile( $value, $opt );
502 $thumb =
$file->transform( [
'width' => 180,
'height' => 360 ] );
504 return $thumb->toHtml( [
'desc-link' =>
true ] );
506 return $this->msg(
'thumbnail_error',
'' )->escaped();
509 return htmlspecialchars( $value );
511 case 'img_timestamp':
513 return htmlspecialchars( $this->getLanguage()->userTimeAndDate( $value, $this->getUser() ) );
515 static $imgfile =
null;
516 if ( $imgfile ===
null ) {
517 $imgfile = $this->msg(
'imgfile' )->text();
523 $link = $linkRenderer->makeKnownLink(
529 [
'href' => $this->localRepo->newFile( $filePage )->getUrl() ],
532 $download = $this->msg(
'parentheses' )->rawParams( $download )->escaped();
536 if ( $this->
getAuthority()->probablyCan(
'delete', $filePage ) ) {
537 $deleteMsg = $this->msg(
'listfiles-delete' )->text();
539 $delete = $linkRenderer->makeKnownLink(
540 $filePage, $deleteMsg, [], [
'action' =>
'delete' ]
542 $delete = $this->msg(
'parentheses' )->rawParams( $delete )->escaped();
544 return "$link $download $delete";
547 return "$link $download";
549 return htmlspecialchars( $value );
551 case 'img_user_text':
552 if ( $this->mCurrentRow->img_user ) {
553 $name = $this->userCache->getProp( $this->mCurrentRow->img_user,
'name' );
554 $link = $linkRenderer->makeLink(
559 $link = htmlspecialchars( $value );
564 return htmlspecialchars( $this->getLanguage()->formatSize( $value ) );
565 case 'img_description':
566 $field = $this->mCurrentRow->description_field;
567 $value = $this->commentStore->getComment( $field, $this->mCurrentRow )->text;
570 return $this->getLanguage()->formatNum( intval( $value ) + 1 );
573 return $this->msg(
'listfiles-latestversion-' . $value )->escaped();
580 $formDescriptor = [];
581 $formDescriptor[
'limit'] = [
584 'label-message' =>
'table_pager_limit_label',
585 'options' => $this->getLimitSelectList(),
586 'default' => $this->mLimit,
589 if ( !$this->getConfig()->
get(
'MiserMode' ) ) {
590 $formDescriptor[
'ilsearch'] = [
592 'name' =>
'ilsearch',
593 'id' =>
'mw-ilsearch',
594 'label-message' =>
'listfiles_search_for',
595 'default' => $this->mSearch,
597 'maxlength' =>
'255',
601 $formDescriptor[
'user'] = [
604 'id' =>
'mw-listfiles-user',
605 'label-message' =>
'username',
606 'default' => $this->mUserName,
608 'maxlength' =>
'255',
611 $formDescriptor[
'ilshowall'] = [
613 'name' =>
'ilshowall',
614 'id' =>
'mw-listfiles-show-all',
615 'label-message' =>
'listfiles-show-all',
616 'default' => $this->mShowAll,
619 $query = $this->getRequest()->getQueryValues();
620 unset( $query[
'title'] );
621 unset( $query[
'limit'] );
622 unset( $query[
'ilsearch'] );
623 unset( $query[
'ilshowall'] );
624 unset( $query[
'user'] );
628 ->setId(
'mw-listfiles-form' )
630 ->setSubmitTextMsg(
'table_pager_limit_submit' )
631 ->setWrapperLegendMsg(
'listfiles' )
632 ->addHiddenFields( $query )
638 return parent::getTableClass() .
' listfiles';
642 return parent::getNavClass() .
' listfiles_nav';
646 return parent::getSortHeaderClass() .
' listfiles_sort';
650 $queries = parent::getPagingQueries();
651 if ( $this->mUserName !==
null ) {
652 # Append the username to the query string
653 foreach ( $queries as &$query ) {
654 if ( $query !==
false ) {
655 $query[
'user'] = $this->mUserName;
664 $queries = parent::getDefaultQuery();
665 if ( !isset( $queries[
'user'] ) && $this->mUserName !==
null ) {
666 $queries[
'user'] = $this->mUserName;