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 unset( $fields[
'img_user_text'] );
250 $fields = array_keys( $fields );
252 if ( $table ===
'oldimage' ) {
253 foreach ( $fields
as $id => &$field ) {
254 if ( substr( $field, 0, 4 ) !==
'img_' ) {
257 $field = $prefix . substr( $field, 3 ) .
' AS ' . $field;
259 $fields[array_search(
'top', $fields )] =
"'no' AS top";
261 if ( $this->mShowAll ) {
262 $fields[array_search(
'top', $fields )] =
"'yes' AS top";
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'";
278 $tables += $actorQuery[
'tables'];
279 $join_conds += $actorQuery[
'joins'];
280 $fields[
'img_user'] = $actorQuery[
'fields'][$prefix .
'_user'];
281 $fields[
'img_user_text'] = $actorQuery[
'fields'][$prefix .
'_user_text'];
282 $fields[
'img_actor'] = $actorQuery[
'fields'][$prefix .
'_actor'];
284 # Depends on $wgMiserMode
285 # Will also not happen if mShowAll is true.
286 if ( isset( $this->mFieldNames[
'count'] ) ) {
289 # Need to rewrite this one
290 foreach ( $fields
as &$field ) {
291 if ( $field ==
'count' ) {
292 $field =
'COUNT(oi_archive_name) AS count';
297 $columnlist = preg_grep(
'/^img/', array_keys( $this->
getFieldNames() ) );
298 $options = [
'GROUP BY' => array_merge( [ $fields[
'img_user'] ], $columnlist ) ];
299 $join_conds[
'oldimage'] = [
'LEFT JOIN',
'oi_name = img_name' ];
307 'join_conds' => $join_conds
325 $this->mTableName =
'image';
329 $this->mTableName = $prevTableName;
331 if ( !$this->mShowAll ) {
335 $this->mTableName =
'oldimage';
339 if ( substr( $this->mIndexField, 0, 4 ) !==
'img_' ) {
340 throw new MWException(
"Expected to be sorting on an image table field" );
342 $this->mIndexField =
'oi_' . substr( $this->mIndexField, 4 );
348 $this->mTableName = $prevTableName;
349 $this->mIndexField = $oldIndex;
351 return $this->
combineResult( $imageRes, $oldimageRes, $limit, $asc );
368 $topRes1 = $res1->next();
369 $topRes2 = $res2->next();
371 for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
372 if ( strcmp( $topRes1->{$this->mIndexField}, $topRes2->{$this->mIndexField} ) > 0 ) {
374 $resultArray[] = $topRes1;
375 $topRes1 = $res1->next();
377 $resultArray[] = $topRes2;
378 $topRes2 = $res2->next();
382 $resultArray[] = $topRes2;
383 $topRes2 = $res2->next();
385 $resultArray[] = $topRes1;
386 $topRes1 = $res1->next();
391 for ( ; $i < $limit && $topRes1; $i++ ) {
392 $resultArray[] = $topRes1;
393 $topRes1 = $res1->next();
396 for ( ; $i < $limit && $topRes2; $i++ ) {
397 $resultArray[] = $topRes2;
398 $topRes2 = $res2->next();
405 if ( $this->mShowAll && $this->getConfig()->
get(
'MiserMode' ) && is_null( $this->mUserName ) ) {
409 return 'img_timestamp';
415 $this->mResult->seek( 0 );
416 foreach ( $this->mResult
as $row ) {
417 $userIds[] = $row->img_user;
419 # Do a link batch query for names and userpages
438 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
441 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
445 $thumb = $file->transform( [
'width' => 180,
'height' => 360 ] );
447 return $thumb->toHtml( [
'desc-link' =>
true ] );
449 return wfMessage(
'thumbnail_error',
'' )->escaped();
452 return htmlspecialchars(
$value );
454 case 'img_timestamp':
456 return htmlspecialchars( $this->getLanguage()->userTimeAndDate(
$value, $this->getUser() ) );
458 static $imgfile =
null;
459 if ( $imgfile ===
null ) {
460 $imgfile = $this->msg(
'imgfile' )->text();
474 $download = $this->msg(
'parentheses' )->rawParams( $download )->escaped();
478 if ( $filePage->userCan(
'delete', $this->getUser() ) ) {
479 $deleteMsg = $this->msg(
'listfiles-delete' )->text();
482 $filePage, $deleteMsg, [], [
'action' =>
'delete' ]
484 $delete = $this->msg(
'parentheses' )->rawParams( $delete )->escaped();
486 return "$link $download $delete";
489 return "$link $download";
491 return htmlspecialchars(
$value );
493 case 'img_user_text':
494 if ( $this->mCurrentRow->img_user ) {
506 return htmlspecialchars( $this->getLanguage()->formatSize(
$value ) );
507 case 'img_description':
508 $field = $this->mCurrentRow->description_field;
512 return $this->getLanguage()->formatNum( intval(
$value ) + 1 );
515 return $this->msg(
'listfiles-latestversion-' .
$value );
526 'label-message' =>
'table_pager_limit_label',
527 'options' => $this->getLimitSelectList(),
528 'default' => $this->mLimit,
531 if ( !$this->getConfig()->
get(
'MiserMode' ) ) {
532 $fields[
'ilsearch'] = [
534 'name' =>
'ilsearch',
535 'id' =>
'mw-ilsearch',
536 'label-message' =>
'listfiles_search_for',
537 'default' => $this->mSearch,
539 'maxlength' =>
'255',
543 $this->getOutput()->addModules(
'mediawiki.userSuggest' );
547 'id' =>
'mw-listfiles-user',
548 'label-message' =>
'username',
549 'default' => $this->mUserName,
551 'maxlength' =>
'255',
552 'cssclass' =>
'mw-autocomplete-user',
555 $fields[
'ilshowall'] = [
557 'name' =>
'ilshowall',
558 'id' =>
'mw-listfiles-show-all',
559 'label-message' =>
'listfiles-show-all',
560 'default' => $this->mShowAll,
563 $query = $this->getRequest()->getQueryValues();
566 unset(
$query[
'ilsearch'] );
567 unset(
$query[
'ilshowall'] );
572 $form->setMethod(
'get' );
573 $form->setTitle( $this->getTitle() );
574 $form->setId(
'mw-listfiles-form' );
575 $form->setWrapperLegendMsg(
'listfiles' );
576 $form->setSubmitTextMsg(
'table_pager_limit_submit' );
577 $form->addHiddenFields(
$query );
579 $form->prepareForm();
580 $form->displayForm(
'' );
584 return parent::getTableClass() .
' listfiles';
588 return parent::getNavClass() .
' listfiles_nav';
592 return parent::getSortHeaderClass() .
' listfiles_sort';
596 $queries = parent::getPagingQueries();
597 if ( !is_null( $this->mUserName ) ) {
598 # Append the username to the query string
601 $query[
'user'] = $this->mUserName;
610 $queries = parent::getDefaultQuery();
611 if ( !isset(
$queries[
'user'] ) && !is_null( $this->mUserName ) ) {
612 $queries[
'user'] = $this->mUserName;