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 ) ) {
144 $conds[] = $actorWhere[
'conds'];
147 if ( $this->mSearch !==
'' ) {
151 $conds[] =
'LOWER(' . $prefix .
'_name)' .
153 strtolower( $nt->getDBkey() ),
$dbr->anyString() );
157 if ( $table ===
'oldimage' ) {
161 $conds[
'oi_deleted'] = 0;
175 if ( !$this->mFieldNames ) {
176 $this->mFieldNames = [
177 'img_timestamp' => $this->
msg(
'listfiles_date' )->text(),
178 'img_name' => $this->
msg(
'listfiles_name' )->text(),
179 'thumb' => $this->
msg(
'listfiles_thumb' )->text(),
180 'img_size' => $this->
msg(
'listfiles_size' )->text(),
182 if ( is_null( $this->mUserName ) ) {
184 $this->mFieldNames[
'img_user_text'] = $this->
msg(
'listfiles_user' )->text();
187 $this->mFieldNames[
'img_description'] = $this->
msg(
'listfiles_description' )->text();
189 if ( !$this->
getConfig()->
get(
'MiserMode' ) && !$this->mShowAll ) {
190 $this->mFieldNames[
'count'] = $this->
msg(
'listfiles_count' )->text();
192 if ( $this->mShowAll ) {
193 $this->mFieldNames[
'top'] = $this->
msg(
'listfiles-latestversion' )->text();
201 if ( $this->mIncluding ) {
204 $sortable = [
'img_timestamp',
'img_name',
'img_size' ];
213 if ( $this->
getConfig()->
get(
'MiserMode' ) && !is_null( $this->mUserName ) ) {
215 if ( $field ===
'img_timestamp' ) {
220 } elseif ( $this->
getConfig()->
get(
'MiserMode' )
224 if ( $field ===
'img_name' ) {
231 return in_array( $field, $sortable );
254 $prefix = $table ===
'oldimage' ?
'oi' :
'img';
258 unset( $fields[
'img_description'] );
259 unset( $fields[
'img_user_text'] );
260 $fields = array_keys( $fields );
262 if ( $table ===
'oldimage' ) {
263 foreach ( $fields
as $id => &$field ) {
264 if ( substr( $field, 0, 4 ) !==
'img_' ) {
267 $field = $prefix . substr( $field, 3 ) .
' AS ' . $field;
269 $fields[array_search(
'top', $fields )] =
"'no' AS top";
271 if ( $this->mShowAll ) {
272 $fields[array_search(
'top', $fields )] =
"'yes' AS top";
275 $fields[array_search(
'thumb', $fields )] = $prefix .
'_name AS thumb';
281 $tables += $commentQuery[
'tables'];
282 $fields += $commentQuery[
'fields'];
283 $join_conds += $commentQuery[
'joins'];
284 $fields[
'description_field'] =
"'{$prefix}_description'";
288 $tables += $actorQuery[
'tables'];
289 $join_conds += $actorQuery[
'joins'];
290 $fields[
'img_user'] = $actorQuery[
'fields'][$prefix .
'_user'];
291 $fields[
'img_user_text'] = $actorQuery[
'fields'][$prefix .
'_user_text'];
292 $fields[
'img_actor'] = $actorQuery[
'fields'][$prefix .
'_actor'];
294 # Depends on $wgMiserMode
295 # Will also not happen if mShowAll is true.
296 if ( isset( $this->mFieldNames[
'count'] ) ) {
299 # Need to rewrite this one
300 foreach ( $fields
as &$field ) {
301 if ( $field ==
'count' ) {
302 $field =
'COUNT(oi_archive_name) AS count';
307 $columnlist = preg_grep(
'/^img/', array_keys( $this->
getFieldNames() ) );
308 $options = [
'GROUP BY' => array_merge( [ $fields[
'img_user'] ], $columnlist ) ];
309 $join_conds[
'oldimage'] = [
'LEFT JOIN',
'oi_name = img_name' ];
317 'join_conds' => $join_conds
335 $this->mTableName =
'image';
339 $this->mTableName = $prevTableName;
341 if ( !$this->mShowAll ) {
345 $this->mTableName =
'oldimage';
349 if ( substr( $this->mIndexField, 0, 4 ) !==
'img_' ) {
350 throw new MWException(
"Expected to be sorting on an image table field" );
352 $this->mIndexField =
'oi_' . substr( $this->mIndexField, 4 );
358 $this->mTableName = $prevTableName;
359 $this->mIndexField = $oldIndex;
361 return $this->
combineResult( $imageRes, $oldimageRes, $limit, $asc );
378 $topRes1 = $res1->next();
379 $topRes2 = $res2->next();
381 for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
382 if ( strcmp( $topRes1->{$this->mIndexField}, $topRes2->{$this->mIndexField} ) > 0 ) {
384 $resultArray[] = $topRes1;
385 $topRes1 = $res1->next();
387 $resultArray[] = $topRes2;
388 $topRes2 = $res2->next();
392 $resultArray[] = $topRes2;
393 $topRes2 = $res2->next();
395 $resultArray[] = $topRes1;
396 $topRes1 = $res1->next();
401 for ( ; $i < $limit && $topRes1; $i++ ) {
402 $resultArray[] = $topRes1;
403 $topRes1 = $res1->next();
406 for ( ; $i < $limit && $topRes2; $i++ ) {
407 $resultArray[] = $topRes2;
408 $topRes2 = $res2->next();
415 if ( $this->mShowAll && $this->getConfig()->
get(
'MiserMode' ) && is_null( $this->mUserName ) ) {
419 return 'img_timestamp';
425 $this->mResult->seek( 0 );
426 foreach ( $this->mResult
as $row ) {
427 $userIds[] = $row->img_user;
429 # Do a link batch query for names and userpages
448 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
451 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
455 $thumb = $file->transform( [
'width' => 180,
'height' => 360 ] );
457 return $thumb->toHtml( [
'desc-link' =>
true ] );
459 return $this->msg(
'thumbnail_error',
'' )->escaped();
462 return htmlspecialchars(
$value );
464 case 'img_timestamp':
466 return htmlspecialchars( $this->getLanguage()->userTimeAndDate(
$value, $this->getUser() ) );
468 static $imgfile =
null;
469 if ( $imgfile ===
null ) {
470 $imgfile = $this->msg(
'imgfile' )->text();
484 $download = $this->msg(
'parentheses' )->rawParams( $download )->escaped();
488 if ( $filePage->userCan(
'delete', $this->getUser() ) ) {
489 $deleteMsg = $this->msg(
'listfiles-delete' )->text();
492 $filePage, $deleteMsg, [], [
'action' =>
'delete' ]
494 $delete = $this->msg(
'parentheses' )->rawParams( $delete )->escaped();
496 return "$link $download $delete";
499 return "$link $download";
501 return htmlspecialchars(
$value );
503 case 'img_user_text':
504 if ( $this->mCurrentRow->img_user ) {
516 return htmlspecialchars( $this->getLanguage()->formatSize(
$value ) );
517 case 'img_description':
518 $field = $this->mCurrentRow->description_field;
522 return $this->getLanguage()->formatNum( intval(
$value ) + 1 );
525 return $this->msg(
'listfiles-latestversion-' .
$value );
536 'label-message' =>
'table_pager_limit_label',
537 'options' => $this->getLimitSelectList(),
538 'default' => $this->mLimit,
541 if ( !$this->getConfig()->
get(
'MiserMode' ) ) {
544 'name' =>
'ilsearch',
545 'id' =>
'mw-ilsearch',
546 'label-message' =>
'listfiles_search_for',
547 'default' => $this->mSearch,
549 'maxlength' =>
'255',
556 'id' =>
'mw-listfiles-user',
557 'label-message' =>
'username',
558 'default' => $this->mUserName,
560 'maxlength' =>
'255',
565 'name' =>
'ilshowall',
566 'id' =>
'mw-listfiles-show-all',
567 'label-message' =>
'listfiles-show-all',
568 'default' => $this->mShowAll,
571 $query = $this->getRequest()->getQueryValues();
574 unset(
$query[
'ilsearch'] );
575 unset(
$query[
'ilshowall'] );
581 ->setId(
'mw-listfiles-form' )
582 ->setTitle( $this->getTitle() )
583 ->setSubmitTextMsg(
'table_pager_limit_submit' )
584 ->setWrapperLegendMsg(
'listfiles' )
585 ->addHiddenFields(
$query )
591 return parent::getTableClass() .
' listfiles';
595 return parent::getNavClass() .
' listfiles_nav';
599 return parent::getSortHeaderClass() .
' listfiles_sort';
603 $queries = parent::getPagingQueries();
604 if ( !is_null( $this->mUserName ) ) {
605 # Append the username to the query string
608 $query[
'user'] = $this->mUserName;
617 $queries = parent::getDefaultQuery();
618 if ( !isset(
$queries[
'user'] ) && !is_null( $this->mUserName ) ) {
619 $queries[
'user'] = $this->mUserName;