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 ) ) {
140 if ( $this->mSearch !==
'' ) {
144 $conds[] =
'LOWER(' . $prefix .
'_name)' .
146 strtolower( $nt->getDBkey() ),
$dbr->anyString() );
150 if ( $table ===
'oldimage' ) {
154 $conds[
'oi_deleted'] = 0;
165 if ( !$this->mFieldNames ) {
166 $this->mFieldNames = [
167 'img_timestamp' => $this->
msg(
'listfiles_date' )->text(),
168 'img_name' => $this->
msg(
'listfiles_name' )->text(),
169 'thumb' => $this->
msg(
'listfiles_thumb' )->text(),
170 'img_size' => $this->
msg(
'listfiles_size' )->text(),
172 if ( is_null( $this->mUserName ) ) {
174 $this->mFieldNames[
'img_user_text'] = $this->
msg(
'listfiles_user' )->text();
177 $this->mFieldNames[
'img_description'] = $this->
msg(
'listfiles_description' )->text();
179 if ( !$this->
getConfig()->
get(
'MiserMode' ) && !$this->mShowAll ) {
180 $this->mFieldNames[
'count'] = $this->
msg(
'listfiles_count' )->text();
182 if ( $this->mShowAll ) {
183 $this->mFieldNames[
'top'] = $this->
msg(
'listfiles-latestversion' )->text();
191 if ( $this->mIncluding ) {
194 $sortable = [
'img_timestamp',
'img_name',
'img_size' ];
203 if ( $this->
getConfig()->
get(
'MiserMode' ) && !is_null( $this->mUserName ) ) {
205 if ( $field ===
'img_timestamp' ) {
210 } elseif ( $this->
getConfig()->
get(
'MiserMode' )
214 if ( $field ===
'img_name' ) {
221 return in_array( $field, $sortable );
244 $prefix = $table ===
'oldimage' ?
'oi' :
'img';
248 unset( $fields[
'img_description'] );
249 $fields = array_keys( $fields );
251 if ( $table ===
'oldimage' ) {
252 foreach ( $fields
as $id => &$field ) {
253 if ( substr( $field, 0, 4 ) !==
'img_' ) {
256 $field = $prefix . substr( $field, 3 ) .
' AS ' . $field;
258 $fields[array_search(
'top', $fields )] =
"'no' AS top";
260 if ( $this->mShowAll ) {
261 $fields[array_search(
'top', $fields )] =
"'yes' AS top";
264 $fields[] = $prefix .
'_user AS img_user';
265 $fields[array_search(
'thumb', $fields )] = $prefix .
'_name AS thumb';
271 $tables += $commentQuery[
'tables'];
272 $fields += $commentQuery[
'fields'];
273 $join_conds += $commentQuery[
'joins'];
274 $fields[
'description_field'] =
"'{$prefix}_description'";
276 # Depends on $wgMiserMode
277 # Will also not happen if mShowAll is true.
278 if ( isset( $this->mFieldNames[
'count'] ) ) {
281 # Need to rewrite this one
282 foreach ( $fields
as &$field ) {
283 if ( $field ==
'count' ) {
284 $field =
'COUNT(oi_archive_name) AS count';
289 $columnlist = preg_grep(
'/^img/', array_keys( $this->
getFieldNames() ) );
290 $options = [
'GROUP BY' => array_merge( [
'img_user' ], $columnlist ) ];
291 $join_conds[
'oldimage'] = [
'LEFT JOIN',
'oi_name = img_name' ];
299 'join_conds' => $join_conds
317 $this->mTableName =
'image';
321 $this->mTableName = $prevTableName;
323 if ( !$this->mShowAll ) {
327 $this->mTableName =
'oldimage';
331 if ( substr( $this->mIndexField, 0, 4 ) !==
'img_' ) {
332 throw new MWException(
"Expected to be sorting on an image table field" );
334 $this->mIndexField =
'oi_' . substr( $this->mIndexField, 4 );
340 $this->mTableName = $prevTableName;
341 $this->mIndexField = $oldIndex;
343 return $this->
combineResult( $imageRes, $oldimageRes, $limit, $asc );
360 $topRes1 = $res1->next();
361 $topRes2 = $res2->next();
363 for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
364 if ( strcmp( $topRes1->{$this->mIndexField}, $topRes2->{$this->mIndexField} ) > 0 ) {
366 $resultArray[] = $topRes1;
367 $topRes1 = $res1->next();
369 $resultArray[] = $topRes2;
370 $topRes2 = $res2->next();
374 $resultArray[] = $topRes2;
375 $topRes2 = $res2->next();
377 $resultArray[] = $topRes1;
378 $topRes1 = $res1->next();
384 for ( ; $i < $limit && $topRes1; $i++ ) {
386 $resultArray[] = $topRes1;
387 $topRes1 = $res1->next();
391 for ( ; $i < $limit && $topRes2; $i++ ) {
393 $resultArray[] = $topRes2;
394 $topRes2 = $res2->next();
401 if ( $this->mShowAll && $this->getConfig()->
get(
'MiserMode' ) && is_null( $this->mUserName ) ) {
405 return 'img_timestamp';
411 $this->mResult->seek( 0 );
412 foreach ( $this->mResult
as $row ) {
413 $userIds[] = $row->img_user;
415 # Do a link batch query for names and userpages
434 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
437 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
441 $thumb = $file->transform( [
'width' => 180,
'height' => 360 ] );
443 return $thumb->toHtml( [
'desc-link' =>
true ] );
445 return wfMessage(
'thumbnail_error',
'' )->escaped();
448 return htmlspecialchars(
$value );
450 case 'img_timestamp':
452 return htmlspecialchars( $this->getLanguage()->userTimeAndDate(
$value, $this->getUser() ) );
454 static $imgfile =
null;
455 if ( $imgfile ===
null ) {
456 $imgfile = $this->msg(
'imgfile' )->text();
470 $download = $this->msg(
'parentheses' )->rawParams( $download )->escaped();
474 if ( $filePage->userCan(
'delete', $this->getUser() ) ) {
475 $deleteMsg = $this->msg(
'listfiles-delete' )->text();
478 $filePage, $deleteMsg, [], [
'action' =>
'delete' ]
480 $delete = $this->msg(
'parentheses' )->rawParams( $delete )->escaped();
482 return "$link $download $delete";
485 return "$link $download";
487 return htmlspecialchars(
$value );
489 case 'img_user_text':
490 if ( $this->mCurrentRow->img_user ) {
502 return htmlspecialchars( $this->getLanguage()->formatSize(
$value ) );
503 case 'img_description':
504 $field = $this->mCurrentRow->description_field;
508 return $this->getLanguage()->formatNum( intval(
$value ) + 1 );
511 return $this->msg(
'listfiles-latestversion-' .
$value );
522 'label-message' =>
'table_pager_limit_label',
523 'options' => $this->getLimitSelectList(),
524 'default' => $this->mLimit,
527 if ( !$this->getConfig()->
get(
'MiserMode' ) ) {
528 $fields[
'ilsearch'] = [
530 'name' =>
'ilsearch',
531 'id' =>
'mw-ilsearch',
532 'label-message' =>
'listfiles_search_for',
533 'default' => $this->mSearch,
535 'maxlength' =>
'255',
539 $this->getOutput()->addModules(
'mediawiki.userSuggest' );
543 'id' =>
'mw-listfiles-user',
544 'label-message' =>
'username',
545 'default' => $this->mUserName,
547 'maxlength' =>
'255',
548 'cssclass' =>
'mw-autocomplete-user',
551 $fields[
'ilshowall'] = [
553 'name' =>
'ilshowall',
554 'id' =>
'mw-listfiles-show-all',
555 'label-message' =>
'listfiles-show-all',
556 'default' => $this->mShowAll,
559 $query = $this->getRequest()->getQueryValues();
562 unset(
$query[
'ilsearch'] );
563 unset(
$query[
'ilshowall'] );
568 $form->setMethod(
'get' );
569 $form->setTitle( $this->getTitle() );
570 $form->setId(
'mw-listfiles-form' );
571 $form->setWrapperLegendMsg(
'listfiles' );
572 $form->setSubmitTextMsg(
'table_pager_limit_submit' );
573 $form->addHiddenFields(
$query );
575 $form->prepareForm();
576 $form->displayForm(
'' );
580 return parent::getTableClass() .
' listfiles';
584 return parent::getNavClass() .
' listfiles_nav';
588 return parent::getSortHeaderClass() .
' listfiles_sort';
592 $queries = parent::getPagingQueries();
593 if ( !is_null( $this->mUserName ) ) {
594 # Append the username to the query string
597 $query[
'user'] = $this->mUserName;
606 $queries = parent::getDefaultQuery();
607 if ( !isset(
$queries[
'user'] ) && !is_null( $this->mUserName ) ) {
608 $queries[
'user'] = $this->mUserName;