111 $this->mIncluding = $including;
112 $this->mShowAll = $showAll;
114 if ( $userName !==
null && $userName !==
'' ) {
115 $nt = Title::makeTitleSafe(
NS_USER, $userName );
116 if ( $nt ===
null ) {
119 $this->mUserName = $nt->getText();
120 $user = User::newFromName( $this->mUserName,
false );
122 $this->mUser = $user;
124 if ( !$user || ( $user->isAnon() && !$userNameUtils->
isIP( $user->getName() ) ) ) {
131 $this->
getRequest()->getText(
'sort',
'img_date' ) ===
'img_date'
140 parent::__construct( $context, $linkRenderer );
141 $this->commentStore = $commentStore;
143 $this->userCache = $userCache;
144 $this->commentFormatter = $commentFormatter;
262 $prefix = $table ===
'oldimage' ?
'oi' :
'img';
264 $tables = [ $table,
'actor' ];
267 if ( $table ===
'oldimage' ) {
269 'img_timestamp' =>
'oi_timestamp',
270 'img_name' =>
'oi_name',
271 'img_size' =>
'oi_size',
272 'top' => $dbr->addQuotes(
'no' )
274 $join_conds[
'actor'] = [
'JOIN',
'actor_id=oi_actor' ];
280 'top' => $dbr->addQuotes(
'yes' )
282 $join_conds[
'actor'] = [
'JOIN',
'actor_id=img_actor' ];
286 $commentQuery = $this->commentStore->getJoin( $prefix .
'_description' );
287 $tables += $commentQuery[
'tables'];
288 $fields += $commentQuery[
'fields'];
289 $join_conds += $commentQuery[
'joins'];
290 $fields[
'description_field'] = $dbr->addQuotes(
"{$prefix}_description" );
293 $fields[] =
'actor_user';
294 $fields[] =
'actor_name';
296 # Depends on $wgMiserMode
297 # Will also not happen if mShowAll is true.
299 $fields[
'count'] = $dbr->buildSelectSubquery(
301 'COUNT(oi_archive_name)',
302 'oi_name = img_name',
312 'join_conds' => $join_conds
328 $this->mTableName =
'image';
329 [ $tables, $fields, $conds, $fname, $options, $join_conds ] =
331 $imageRes = $dbr->select( $tables, $fields, $conds, $fname, $options, $join_conds );
332 $this->mTableName = $prevTableName;
334 if ( !$this->mShowAll ) {
338 $this->mTableName =
'oldimage';
342 foreach ( $this->mIndexField as &$index ) {
343 if ( !str_starts_with( $index,
'img_' ) ) {
344 throw new MWException(
"Expected to be sorting on an image table field" );
346 $index =
'oi_' . substr( $index, 4 );
349 [ $tables, $fields, $conds, $fname, $options, $join_conds ] =
351 $oldimageRes = $dbr->select( $tables, $fields, $conds, $fname, $options, $join_conds );
353 $this->mTableName = $prevTableName;
354 $this->mIndexField = $oldIndex;
356 return $this->
combineResult( $imageRes, $oldimageRes, $limit, $order );
373 $topRes1 = $res1->fetchObject();
374 $topRes2 = $res2->fetchObject();
376 for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
377 if ( strcmp( $topRes1->{$this->mIndexField[0]}, $topRes2->{$this->mIndexField[0]} ) > 0 ) {
379 $resultArray[] = $topRes1;
380 $topRes1 = $res1->fetchObject();
382 $resultArray[] = $topRes2;
383 $topRes2 = $res2->fetchObject();
386 $resultArray[] = $topRes2;
387 $topRes2 = $res2->fetchObject();
389 $resultArray[] = $topRes1;
390 $topRes1 = $res1->fetchObject();
394 for ( ; $i < $limit && $topRes1; $i++ ) {
395 $resultArray[] = $topRes1;
396 $topRes1 = $res1->fetchObject();
399 for ( ; $i < $limit && $topRes2; $i++ ) {
400 $resultArray[] = $topRes2;
401 $topRes2 = $res2->fetchObject();
404 return new FakeResultWrapper( $resultArray );
442 $linkRenderer = $this->getLinkRenderer();
445 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
446 $file = $this->localRepo->findFile( $this->getCurrentRow()->img_name, $opt );
449 $thumb =
$file->transform( [
'width' => 180,
'height' => 360,
'loading' =>
'lazy' ] );
451 return $thumb->toHtml( [
'desc-link' =>
true ] );
453 return $this->msg(
'thumbnail_error',
'' )->escaped();
456 return htmlspecialchars( $this->getCurrentRow()->img_name );
458 case 'img_timestamp':
460 return htmlspecialchars( $this->getLanguage()->userTimeAndDate( $value, $this->
getUser() ) );
462 static $imgfile =
null;
463 if ( $imgfile ===
null ) {
464 $imgfile = $this->msg(
'imgfile' )->text();
468 $filePage = Title::makeTitleSafe(
NS_FILE, $value );
470 $html = $linkRenderer->makeKnownLink(
474 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
475 $file = $this->localRepo->findFile( $value, $opt );
477 $download = Xml::element(
479 [
'href' =>
$file->getUrl() ],
482 $html .=
' ' . $this->msg(
'parentheses' )->rawParams( $download )->escaped();
487 if ( $this->
getAuthority()->probablyCan(
'delete', $filePage ) ) {
488 $deleteMsg = $this->msg(
'listfiles-delete' )->text();
490 $delete = $linkRenderer->makeKnownLink(
491 $filePage, $deleteMsg, [], [
'action' =>
'delete' ]
493 $html .=
' ' . $this->msg(
'parentheses' )->rawParams( $delete )->escaped();
498 return htmlspecialchars( $value );
501 if ( $this->mCurrentRow->actor_user ) {
502 $name = $this->mCurrentRow->actor_name;
503 $link = $linkRenderer->makeLink(
504 Title::makeTitle(
NS_USER, $name ),
508 $link = $value !==
null ? htmlspecialchars( $value ) :
'';
513 return htmlspecialchars( $this->getLanguage()->formatSize( (
int)$value ) );
514 case 'img_description':
515 $field = $this->mCurrentRow->description_field;
516 $value = $this->commentStore->getComment( $field, $this->mCurrentRow )->text;
517 return $this->commentFormatter->format( $value );
519 return htmlspecialchars( $this->getLanguage()->formatNum( intval( $value ) + 1 ) );
522 return $this->msg(
'listfiles-latestversion-' . $value )->escaped();
542 $formDescriptor = [];
543 $formDescriptor[
'limit'] = [
546 'label-message' =>
'table_pager_limit_label',
547 'options' => $this->getEscapedLimitSelectList(),
549 'default' => $this->mLimit
552 $formDescriptor[
'user'] = [
555 'id' =>
'mw-listfiles-user',
556 'label-message' =>
'username',
557 'default' => $this->mUserName,
559 'maxlength' =>
'255',
562 $formDescriptor[
'ilshowall'] = [
564 'name' =>
'ilshowall',
565 'id' =>
'mw-listfiles-show-all',
566 'label-message' =>
'listfiles-show-all',
567 'default' => $this->mShowAll,
570 $query = $this->getRequest()->getQueryValues();
571 unset( $query[
'title'] );
572 unset( $query[
'limit'] );
573 unset( $query[
'ilsearch'] );
574 unset( $query[
'ilshowall'] );
575 unset( $query[
'user'] );
577 HTMLForm::factory(
'ooui', $formDescriptor, $this->
getContext() )
579 ->setId(
'mw-listfiles-form' )
581 ->setSubmitTextMsg(
'listfiles-pager-submit' )
582 ->setWrapperLegendMsg(
'listfiles' )
583 ->addHiddenFields( $query )