113 $this->mIncluding = $including;
114 $this->mShowAll = $showAll;
116 if ( $userName !==
null && $userName !==
'' ) {
117 $nt = Title::makeTitleSafe(
NS_USER, $userName );
118 if ( $nt ===
null ) {
121 $this->mUserName = $nt->getText();
122 $user = User::newFromName( $this->mUserName,
false );
124 $this->mUser = $user;
126 if ( !$user || ( $user->isAnon() && !$userNameUtils->
isIP( $user->getName() ) ) ) {
133 $this->
getRequest()->getText(
'sort',
'img_date' ) ===
'img_date'
142 parent::__construct( $context, $linkRenderer );
143 $this->commentStore = $commentStore;
145 $this->commentFormatter = $commentFormatter;
146 $this->linkBatchFactory = $linkBatchFactory;
264 $prefix = $table ===
'oldimage' ?
'oi' :
'img';
266 $tables = [ $table,
'actor' ];
269 if ( $table ===
'oldimage' ) {
271 'img_timestamp' =>
'oi_timestamp',
272 'img_name' =>
'oi_name',
273 'img_size' =>
'oi_size',
274 'top' => $dbr->addQuotes(
'no' )
276 $join_conds[
'actor'] = [
'JOIN',
'actor_id=oi_actor' ];
282 'top' => $dbr->addQuotes(
'yes' )
284 $join_conds[
'actor'] = [
'JOIN',
'actor_id=img_actor' ];
288 $commentQuery = $this->commentStore->getJoin( $prefix .
'_description' );
289 $tables += $commentQuery[
'tables'];
290 $fields += $commentQuery[
'fields'];
291 $join_conds += $commentQuery[
'joins'];
292 $fields[
'description_field'] = $dbr->addQuotes(
"{$prefix}_description" );
295 $fields[] =
'actor_user';
296 $fields[] =
'actor_name';
298 # Depends on $wgMiserMode
299 # Will also not happen if mShowAll is true.
301 $fields[
'count'] =
new Subquery( $dbr->newSelectQueryBuilder()
302 ->select(
'COUNT(oi_archive_name)' )
304 ->where(
'oi_name = img_name' )
305 ->caller( __METHOD__ )
315 'join_conds' => $join_conds
330 $this->mTableName =
'image';
331 [ $tables, $fields, $conds, $fname, $options, $join_conds ] =
333 $imageRes = $dbr->newSelectQueryBuilder()
334 ->tables( is_array( $tables ) ? $tables : [ $tables ] )
338 ->options( $options )
339 ->joinConds( $join_conds )
341 $this->mTableName = $prevTableName;
343 if ( !$this->mShowAll ) {
347 $this->mTableName =
'oldimage';
351 foreach ( $this->mIndexField as &$index ) {
352 if ( !str_starts_with( $index,
'img_' ) ) {
353 throw new UnexpectedValueException(
"Expected to be sorting on an image table field" );
355 $index =
'oi_' . substr( $index, 4 );
359 [ $tables, $fields, $conds, $fname, $options, $join_conds ] =
361 $oldimageRes = $dbr->newSelectQueryBuilder()
362 ->tables( is_array( $tables ) ? $tables : [ $tables ] )
366 ->options( $options )
367 ->joinConds( $join_conds )
370 $this->mTableName = $prevTableName;
371 $this->mIndexField = $oldIndex;
373 return $this->
combineResult( $imageRes, $oldimageRes, $limit, $order );
390 $topRes1 = $res1->fetchObject();
391 $topRes2 = $res2->fetchObject();
393 for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
394 if ( strcmp( $topRes1->{$this->mIndexField[0]}, $topRes2->{$this->mIndexField[0]} ) > 0 ) {
396 $resultArray[] = $topRes1;
397 $topRes1 = $res1->fetchObject();
399 $resultArray[] = $topRes2;
400 $topRes2 = $res2->fetchObject();
403 $resultArray[] = $topRes2;
404 $topRes2 = $res2->fetchObject();
406 $resultArray[] = $topRes1;
407 $topRes1 = $res1->fetchObject();
411 for ( ; $i < $limit && $topRes1; $i++ ) {
412 $resultArray[] = $topRes1;
413 $topRes1 = $res1->fetchObject();
416 for ( ; $i < $limit && $topRes2; $i++ ) {
417 $resultArray[] = $topRes2;
418 $topRes2 = $res2->fetchObject();
421 return new FakeResultWrapper( $resultArray );
457 $linkRenderer = $this->getLinkRenderer();
460 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
461 $file = $this->localRepo->findFile( $this->getCurrentRow()->img_name, $opt );
464 $thumb = $file->transform( [
'width' => 180,
'height' => 360 ] );
466 return $thumb->toHtml( [
'desc-link' =>
true,
'loading' =>
'lazy' ] );
468 return $this->msg(
'thumbnail_error',
'' )->escaped();
470 return htmlspecialchars( $this->getCurrentRow()->img_name );
472 case 'img_timestamp':
474 return htmlspecialchars( $this->getLanguage()->userTimeAndDate( $value, $this->
getUser() ) );
476 static $imgfile =
null;
477 if ( $imgfile ===
null ) {
478 $imgfile = $this->msg(
'imgfile' )->text();
482 $filePage = Title::makeTitleSafe(
NS_FILE, $value );
484 $html = $linkRenderer->makeKnownLink(
488 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
489 $file = $this->localRepo->findFile( $value, $opt );
491 $download = Xml::element(
493 [
'href' => $file->getUrl() ],
496 $html .=
' ' . $this->msg(
'parentheses' )->rawParams( $download )->escaped();
501 if ( $this->
getAuthority()->probablyCan(
'delete', $filePage ) ) {
502 $deleteMsg = $this->msg(
'listfiles-delete' )->text();
504 $delete = $linkRenderer->makeKnownLink(
505 $filePage, $deleteMsg, [], [
'action' =>
'delete' ]
507 $html .=
' ' . $this->msg(
'parentheses' )->rawParams( $delete )->escaped();
512 return htmlspecialchars( $value );
515 $userId = (int)$this->mCurrentRow->actor_user;
516 $userName = $this->mCurrentRow->actor_name;
517 return Linker::userLink( $userId, $userName )
518 . Linker::userToolLinks( $userId, $userName );
520 return htmlspecialchars( $this->getLanguage()->formatSize( (
int)$value ) );
521 case 'img_description':
522 $field = $this->mCurrentRow->description_field;
523 $value = $this->commentStore->getComment( $field, $this->mCurrentRow )->text;
524 return $this->commentFormatter->format( $value );
526 return htmlspecialchars( $this->getLanguage()->formatNum( intval( $value ) + 1 ) );
529 return $this->msg(
'listfiles-latestversion-' . $value )->escaped();
531 throw new UnexpectedValueException(
"Unknown field '$field'" );