59 $this->mIncluding = $including;
60 $this->mShowAll = $showAll;
62 if ( $userName !==
null && $userName !==
'' ) {
64 if ( is_null( $nt ) ) {
67 $this->mUserName = $nt->getText();
72 if ( !$user || ( $user->isAnon() && !
User::isIP( $user->getName() ) ) ) {
78 if ( $search !==
'' && !$this->
getConfig()->
get(
'MiserMode' ) ) {
79 $this->mSearch = $search;
84 $this->mQueryConds[] =
'LOWER(img_name)' .
86 strtolower( $nt->getDBkey() ),
$dbr->anyString() );
91 if ( $this->
getRequest()->getText(
'sort',
'img_date' ) ==
'img_date' ) {
119 "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
121 'listfiles-userdoesnotexist',
135 $prefix = $table ===
'image' ?
'img' :
'oi';
138 if ( !is_null( $this->mUserName ) ) {
148 $conds[] = $actorWhere[
'conds'];
151 if ( $this->mSearch !==
'' ) {
155 $conds[] =
'LOWER(' . $prefix .
'_name)' .
157 strtolower( $nt->getDBkey() ),
$dbr->anyString() );
161 if ( $table ===
'oldimage' ) {
165 $conds[
'oi_deleted'] = 0;
179 if ( !$this->mFieldNames ) {
180 $this->mFieldNames = [
181 'img_timestamp' => $this->
msg(
'listfiles_date' )->text(),
182 'img_name' => $this->
msg(
'listfiles_name' )->text(),
183 'thumb' => $this->
msg(
'listfiles_thumb' )->text(),
184 'img_size' => $this->
msg(
'listfiles_size' )->text(),
186 if ( is_null( $this->mUserName ) ) {
188 $this->mFieldNames[
'img_user_text'] = $this->
msg(
'listfiles_user' )->text();
191 $this->mFieldNames[
'img_description'] = $this->
msg(
'listfiles_description' )->text();
193 if ( !$this->
getConfig()->
get(
'MiserMode' ) && !$this->mShowAll ) {
194 $this->mFieldNames[
'count'] = $this->
msg(
'listfiles_count' )->text();
196 if ( $this->mShowAll ) {
197 $this->mFieldNames[
'top'] = $this->
msg(
'listfiles-latestversion' )->text();
205 if ( $this->mIncluding ) {
208 $sortable = [
'img_timestamp',
'img_name',
'img_size' ];
217 if ( $this->
getConfig()->
get(
'MiserMode' ) && !is_null( $this->mUserName ) ) {
219 if ( $field ===
'img_timestamp' ) {
224 } elseif ( $this->
getConfig()->
get(
'MiserMode' )
228 if ( $field ===
'img_name' ) {
235 return in_array( $field, $sortable );
259 $prefix = $table ===
'oldimage' ?
'oi' :
'img';
261 $tables = [ $table ];
263 $fields = array_combine( $fields, $fields );
264 unset( $fields[
'img_description'] );
265 unset( $fields[
'img_user_text'] );
267 if ( $table ===
'oldimage' ) {
268 foreach ( $fields as $id => $field ) {
269 if ( substr( $id, 0, 4 ) ===
'img_' ) {
270 $fields[$id] = $prefix . substr( $field, 3 );
273 $fields[
'top'] =
$dbr->addQuotes(
'no' );
274 } elseif ( $this->mShowAll ) {
275 $fields[
'top'] =
$dbr->addQuotes(
'yes' );
277 $fields[
'thumb'] = $prefix .
'_name';
279 $options = $join_conds = [];
283 $tables += $commentQuery[
'tables'];
284 $fields += $commentQuery[
'fields'];
285 $join_conds += $commentQuery[
'joins'];
286 $fields[
'description_field'] =
$dbr->addQuotes(
"{$prefix}_description" );
290 $tables += $actorQuery[
'tables'];
291 $join_conds += $actorQuery[
'joins'];
292 $fields[
'img_user'] = $actorQuery[
'fields'][$prefix .
'_user'];
293 $fields[
'img_user_text'] = $actorQuery[
'fields'][$prefix .
'_user_text'];
294 $fields[
'img_actor'] = $actorQuery[
'fields'][$prefix .
'_actor'];
296 # Depends on $wgMiserMode
297 # Will also not happen if mShowAll is true.
298 if ( isset( $fields[
'count'] ) ) {
299 $fields[
'count'] =
$dbr->buildSelectSubquery(
301 'COUNT(oi_archive_name)',
302 'oi_name = img_name',
311 'options' => $options,
312 'join_conds' => $join_conds
330 $this->mTableName =
'image';
331 list( $tables, $fields, $conds, $fname, $options, $join_conds ) =
333 $imageRes = $this->mDb->select( $tables, $fields, $conds, $fname, $options, $join_conds );
334 $this->mTableName = $prevTableName;
336 if ( !$this->mShowAll ) {
340 $this->mTableName =
'oldimage';
344 if ( substr( $this->mIndexField, 0, 4 ) !==
'img_' ) {
345 throw new MWException(
"Expected to be sorting on an image table field" );
347 $this->mIndexField =
'oi_' . substr( $this->mIndexField, 4 );
349 list( $tables, $fields, $conds, $fname, $options, $join_conds ) =
351 $oldimageRes = $this->mDb->select( $tables, $fields, $conds, $fname, $options, $join_conds );
353 $this->mTableName = $prevTableName;
354 $this->mIndexField = $oldIndex;
356 return $this->
combineResult( $imageRes, $oldimageRes, $limit, $order );
373 $topRes1 = $res1->next();
374 $topRes2 = $res2->next();
376 for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
377 if ( strcmp( $topRes1->{$this->mIndexField}, $topRes2->{$this->mIndexField} ) > 0 ) {
379 $resultArray[] = $topRes1;
380 $topRes1 = $res1->next();
382 $resultArray[] = $topRes2;
383 $topRes2 = $res2->next();
385 } elseif ( !$ascending ) {
386 $resultArray[] = $topRes2;
387 $topRes2 = $res2->next();
389 $resultArray[] = $topRes1;
390 $topRes1 = $res1->next();
394 for ( ; $i < $limit && $topRes1; $i++ ) {
395 $resultArray[] = $topRes1;
396 $topRes1 = $res1->next();
399 for ( ; $i < $limit && $topRes2; $i++ ) {
400 $resultArray[] = $topRes2;
401 $topRes2 = $res2->next();
408 if ( $this->mShowAll && $this->getConfig()->
get(
'MiserMode' ) && is_null( $this->mUserName ) ) {
412 return 'img_timestamp';
418 $this->mResult->seek( 0 );
419 foreach ( $this->mResult as $row ) {
420 $userIds[] = $row->img_user;
422 # Do a link batch query for names and userpages
441 $services = MediaWikiServices::getInstance();
442 $linkRenderer = $this->getLinkRenderer();
445 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
449 $thumb =
$file->transform( [
'width' => 180,
'height' => 360 ] );
451 return $thumb->toHtml( [
'desc-link' =>
true ] );
453 return $this->msg(
'thumbnail_error',
'' )->escaped();
456 return htmlspecialchars( $value );
458 case 'img_timestamp':
460 return htmlspecialchars( $this->getLanguage()->userTimeAndDate( $value, $this->
getUser() ) );
462 static $imgfile =
null;
463 if ( $imgfile ===
null ) {
464 $imgfile = $this->msg(
'imgfile' )->text();
470 $link = $linkRenderer->makeKnownLink(
476 [
'href' => $services->getRepoGroup()->getLocalRepo()->newFile( $filePage )->getUrl() ],
479 $download = $this->msg(
'parentheses' )->rawParams( $download )->escaped();
483 $permissionManager = $services->getPermissionManager();
485 if ( $permissionManager->userCan(
'delete', $this->getUser(), $filePage ) ) {
486 $deleteMsg = $this->msg(
'listfiles-delete' )->text();
488 $delete = $linkRenderer->makeKnownLink(
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 ) {
502 $name =
User::whoIs( $this->mCurrentRow->img_user );
503 $link = $linkRenderer->makeLink(
508 $link = htmlspecialchars( $value );
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 )->escaped();
529 $formDescriptor = [];
530 $formDescriptor[
'limit'] = [
533 'label-message' =>
'table_pager_limit_label',
534 'options' => $this->getLimitSelectList(),
535 'default' => $this->mLimit,
538 if ( !$this->getConfig()->
get(
'MiserMode' ) ) {
539 $formDescriptor[
'ilsearch'] = [
541 'name' =>
'ilsearch',
542 'id' =>
'mw-ilsearch',
543 'label-message' =>
'listfiles_search_for',
544 'default' => $this->mSearch,
546 'maxlength' =>
'255',
550 $formDescriptor[
'user'] = [
553 'id' =>
'mw-listfiles-user',
554 'label-message' =>
'username',
555 'default' => $this->mUserName,
557 'maxlength' =>
'255',
560 $formDescriptor[
'ilshowall'] = [
562 'name' =>
'ilshowall',
563 'id' =>
'mw-listfiles-show-all',
564 'label-message' =>
'listfiles-show-all',
565 'default' => $this->mShowAll,
568 $query = $this->getRequest()->getQueryValues();
569 unset( $query[
'title'] );
570 unset( $query[
'limit'] );
571 unset( $query[
'ilsearch'] );
572 unset( $query[
'ilshowall'] );
573 unset( $query[
'user'] );
578 ->setId(
'mw-listfiles-form' )
580 ->setSubmitTextMsg(
'table_pager_limit_submit' )
581 ->setWrapperLegendMsg(
'listfiles' )
582 ->addHiddenFields( $query )
588 return parent::getTableClass() .
' listfiles';
592 return parent::getNavClass() .
' listfiles_nav';
596 return parent::getSortHeaderClass() .
' listfiles_sort';
600 $queries = parent::getPagingQueries();
601 if ( !is_null( $this->mUserName ) ) {
602 # Append the username to the query string
604 if ( $query !==
false ) {
605 $query[
'user'] = $this->mUserName;
614 $queries = parent::getDefaultQuery();
615 if ( !isset(
$queries[
'user'] ) && !is_null( $this->mUserName ) ) {
616 $queries[
'user'] = $this->mUserName;