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
327 $this->mTableName =
'image';
328 [ $tables, $fields, $conds, $fname, $options, $join_conds ] =
330 $imageRes = $dbr->newSelectQueryBuilder()
331 ->tables( is_array( $tables ) ? $tables : [ $tables ] )
335 ->options( $options )
336 ->joinConds( $join_conds )
338 $this->mTableName = $prevTableName;
340 if ( !$this->mShowAll ) {
344 $this->mTableName =
'oldimage';
348 foreach ( $this->mIndexField as &$index ) {
349 if ( !str_starts_with( $index,
'img_' ) ) {
350 throw new UnexpectedValueException(
"Expected to be sorting on an image table field" );
352 $index =
'oi_' . substr( $index, 4 );
356 [ $tables, $fields, $conds, $fname, $options, $join_conds ] =
358 $oldimageRes = $dbr->newSelectQueryBuilder()
359 ->tables( is_array( $tables ) ? $tables : [ $tables ] )
363 ->options( $options )
364 ->joinConds( $join_conds )
367 $this->mTableName = $prevTableName;
368 $this->mIndexField = $oldIndex;
370 return $this->
combineResult( $imageRes, $oldimageRes, $limit, $order );
387 $topRes1 = $res1->fetchObject();
388 $topRes2 = $res2->fetchObject();
390 for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
391 if ( strcmp( $topRes1->{$this->mIndexField[0]}, $topRes2->{$this->mIndexField[0]} ) > 0 ) {
393 $resultArray[] = $topRes1;
394 $topRes1 = $res1->fetchObject();
396 $resultArray[] = $topRes2;
397 $topRes2 = $res2->fetchObject();
400 $resultArray[] = $topRes2;
401 $topRes2 = $res2->fetchObject();
403 $resultArray[] = $topRes1;
404 $topRes1 = $res1->fetchObject();
408 for ( ; $i < $limit && $topRes1; $i++ ) {
409 $resultArray[] = $topRes1;
410 $topRes1 = $res1->fetchObject();
413 for ( ; $i < $limit && $topRes2; $i++ ) {
414 $resultArray[] = $topRes2;
415 $topRes2 = $res2->fetchObject();
418 return new FakeResultWrapper( $resultArray );
455 $linkRenderer = $this->getLinkRenderer();
458 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
459 $file = $this->localRepo->findFile( $this->getCurrentRow()->img_name, $opt );
462 $thumb = $file->transform( [
'width' => 180,
'height' => 360 ] );
464 return $thumb->toHtml( [
'desc-link' =>
true,
'loading' =>
'lazy' ] );
466 return $this->msg(
'thumbnail_error',
'' )->escaped();
468 return htmlspecialchars( $this->getCurrentRow()->img_name );
470 case 'img_timestamp':
472 return htmlspecialchars( $this->getLanguage()->userTimeAndDate( $value, $this->
getUser() ) );
474 static $imgfile =
null;
475 if ( $imgfile ===
null ) {
476 $imgfile = $this->msg(
'imgfile' )->text();
480 $filePage = Title::makeTitleSafe(
NS_FILE, $value );
482 $html = $linkRenderer->makeKnownLink(
486 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
487 $file = $this->localRepo->findFile( $value, $opt );
489 $download = Xml::element(
491 [
'href' => $file->getUrl() ],
494 $html .=
' ' . $this->msg(
'parentheses' )->rawParams( $download )->escaped();
499 if ( $this->
getAuthority()->probablyCan(
'delete', $filePage ) ) {
500 $deleteMsg = $this->msg(
'listfiles-delete' )->text();
502 $delete = $linkRenderer->makeKnownLink(
503 $filePage, $deleteMsg, [], [
'action' =>
'delete' ]
505 $html .=
' ' . $this->msg(
'parentheses' )->rawParams( $delete )->escaped();
510 return htmlspecialchars( $value );
513 if ( $this->mCurrentRow->actor_user ) {
514 $name = $this->mCurrentRow->actor_name;
515 $link = $linkRenderer->makeLink(
516 Title::makeTitle(
NS_USER, $name ),
520 $link = $value !==
null ? htmlspecialchars( $value ) :
'';
525 return htmlspecialchars( $this->getLanguage()->formatSize( (
int)$value ) );
526 case 'img_description':
527 $field = $this->mCurrentRow->description_field;
528 $value = $this->commentStore->getComment( $field, $this->mCurrentRow )->text;
529 return $this->commentFormatter->format( $value );
531 return htmlspecialchars( $this->getLanguage()->formatNum( intval( $value ) + 1 ) );
534 return $this->msg(
'listfiles-latestversion-' . $value )->escaped();
536 throw new UnexpectedValueException(
"Unknown field '$field'" );