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;
172 if ( !$this->mFieldNames ) {
173 $this->mFieldNames = [
174 'img_timestamp' => $this->
msg(
'listfiles_date' )->text(),
175 'img_name' => $this->
msg(
'listfiles_name' )->text(),
176 'thumb' => $this->
msg(
'listfiles_thumb' )->text(),
177 'img_size' => $this->
msg(
'listfiles_size' )->text(),
179 if ( is_null( $this->mUserName ) ) {
181 $this->mFieldNames[
'img_user_text'] = $this->
msg(
'listfiles_user' )->text();
184 $this->mFieldNames[
'img_description'] = $this->
msg(
'listfiles_description' )->text();
186 if ( !$this->
getConfig()->
get(
'MiserMode' ) && !$this->mShowAll ) {
187 $this->mFieldNames[
'count'] = $this->
msg(
'listfiles_count' )->text();
189 if ( $this->mShowAll ) {
190 $this->mFieldNames[
'top'] = $this->
msg(
'listfiles-latestversion' )->text();
198 if ( $this->mIncluding ) {
201 $sortable = [
'img_timestamp',
'img_name',
'img_size' ];
210 if ( $this->
getConfig()->
get(
'MiserMode' ) && !is_null( $this->mUserName ) ) {
212 if ( $field ===
'img_timestamp' ) {
217 } elseif ( $this->
getConfig()->
get(
'MiserMode' )
221 if ( $field ===
'img_name' ) {
228 return in_array( $field, $sortable );
251 $prefix = $table ===
'oldimage' ?
'oi' :
'img';
255 unset( $fields[
'img_description'] );
256 unset( $fields[
'img_user_text'] );
257 $fields = array_keys( $fields );
259 if ( $table ===
'oldimage' ) {
260 foreach ( $fields
as $id => &$field ) {
261 if ( substr( $field, 0, 4 ) !==
'img_' ) {
264 $field = $prefix . substr( $field, 3 ) .
' AS ' . $field;
266 $fields[array_search(
'top', $fields )] =
"'no' AS top";
268 if ( $this->mShowAll ) {
269 $fields[array_search(
'top', $fields )] =
"'yes' AS top";
272 $fields[array_search(
'thumb', $fields )] = $prefix .
'_name AS thumb';
278 $tables += $commentQuery[
'tables'];
279 $fields += $commentQuery[
'fields'];
280 $join_conds += $commentQuery[
'joins'];
281 $fields[
'description_field'] =
"'{$prefix}_description'";
285 $tables += $actorQuery[
'tables'];
286 $join_conds += $actorQuery[
'joins'];
287 $fields[
'img_user'] = $actorQuery[
'fields'][$prefix .
'_user'];
288 $fields[
'img_user_text'] = $actorQuery[
'fields'][$prefix .
'_user_text'];
289 $fields[
'img_actor'] = $actorQuery[
'fields'][$prefix .
'_actor'];
291 # Depends on $wgMiserMode
292 # Will also not happen if mShowAll is true.
293 if ( isset( $this->mFieldNames[
'count'] ) ) {
296 # Need to rewrite this one
297 foreach ( $fields
as &$field ) {
298 if ( $field ==
'count' ) {
299 $field =
'COUNT(oi_archive_name) AS count';
304 $columnlist = preg_grep(
'/^img/', array_keys( $this->
getFieldNames() ) );
305 $options = [
'GROUP BY' => array_merge( [ $fields[
'img_user'] ], $columnlist ) ];
306 $join_conds[
'oldimage'] = [
'LEFT JOIN',
'oi_name = img_name' ];
314 'join_conds' => $join_conds
332 $this->mTableName =
'image';
336 $this->mTableName = $prevTableName;
338 if ( !$this->mShowAll ) {
342 $this->mTableName =
'oldimage';
346 if ( substr( $this->mIndexField, 0, 4 ) !==
'img_' ) {
347 throw new MWException(
"Expected to be sorting on an image table field" );
349 $this->mIndexField =
'oi_' . substr( $this->mIndexField, 4 );
355 $this->mTableName = $prevTableName;
356 $this->mIndexField = $oldIndex;
358 return $this->
combineResult( $imageRes, $oldimageRes, $limit, $asc );
375 $topRes1 = $res1->next();
376 $topRes2 = $res2->next();
378 for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
379 if ( strcmp( $topRes1->{$this->mIndexField}, $topRes2->{$this->mIndexField} ) > 0 ) {
381 $resultArray[] = $topRes1;
382 $topRes1 = $res1->next();
384 $resultArray[] = $topRes2;
385 $topRes2 = $res2->next();
389 $resultArray[] = $topRes2;
390 $topRes2 = $res2->next();
392 $resultArray[] = $topRes1;
393 $topRes1 = $res1->next();
398 for ( ; $i < $limit && $topRes1; $i++ ) {
399 $resultArray[] = $topRes1;
400 $topRes1 = $res1->next();
403 for ( ; $i < $limit && $topRes2; $i++ ) {
404 $resultArray[] = $topRes2;
405 $topRes2 = $res2->next();
412 if ( $this->mShowAll && $this->getConfig()->
get(
'MiserMode' ) && is_null( $this->mUserName ) ) {
416 return 'img_timestamp';
422 $this->mResult->seek( 0 );
423 foreach ( $this->mResult
as $row ) {
424 $userIds[] = $row->img_user;
426 # Do a link batch query for names and userpages
445 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
448 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
452 $thumb = $file->transform( [
'width' => 180,
'height' => 360 ] );
454 return $thumb->toHtml( [
'desc-link' =>
true ] );
456 return wfMessage(
'thumbnail_error',
'' )->escaped();
459 return htmlspecialchars(
$value );
461 case 'img_timestamp':
463 return htmlspecialchars( $this->getLanguage()->userTimeAndDate(
$value, $this->getUser() ) );
465 static $imgfile =
null;
466 if ( $imgfile ===
null ) {
467 $imgfile = $this->msg(
'imgfile' )->text();
481 $download = $this->msg(
'parentheses' )->rawParams( $download )->escaped();
485 if ( $filePage->userCan(
'delete', $this->getUser() ) ) {
486 $deleteMsg = $this->msg(
'listfiles-delete' )->text();
489 $filePage, $deleteMsg, [], [
'action' =>
'delete' ]
491 $delete = $this->msg(
'parentheses' )->rawParams( $delete )->escaped();
493 return "$link $download $delete";
496 return "$link $download";
498 return htmlspecialchars(
$value );
500 case 'img_user_text':
501 if ( $this->mCurrentRow->img_user ) {
513 return htmlspecialchars( $this->getLanguage()->formatSize(
$value ) );
514 case 'img_description':
515 $field = $this->mCurrentRow->description_field;
519 return $this->getLanguage()->formatNum( intval(
$value ) + 1 );
522 return $this->msg(
'listfiles-latestversion-' .
$value );
533 'label-message' =>
'table_pager_limit_label',
534 'options' => $this->getLimitSelectList(),
535 'default' => $this->mLimit,
538 if ( !$this->getConfig()->
get(
'MiserMode' ) ) {
539 $fields[
'ilsearch'] = [
541 'name' =>
'ilsearch',
542 'id' =>
'mw-ilsearch',
543 'label-message' =>
'listfiles_search_for',
544 'default' => $this->mSearch,
546 'maxlength' =>
'255',
550 $this->getOutput()->addModules(
'mediawiki.userSuggest' );
554 'id' =>
'mw-listfiles-user',
555 'label-message' =>
'username',
556 'default' => $this->mUserName,
558 'maxlength' =>
'255',
559 'cssclass' =>
'mw-autocomplete-user',
562 $fields[
'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();
573 unset(
$query[
'ilsearch'] );
574 unset(
$query[
'ilshowall'] );
579 $form->setMethod(
'get' );
580 $form->setTitle( $this->getTitle() );
581 $form->setId(
'mw-listfiles-form' );
582 $form->setWrapperLegendMsg(
'listfiles' );
583 $form->setSubmitTextMsg(
'table_pager_limit_submit' );
584 $form->addHiddenFields(
$query );
586 $form->prepareForm();
587 $form->displayForm(
'' );
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;