68 $this->mIncluding = $including;
69 $this->mShowAll = $showAll;
71 if ( $userName !==
null && $userName !==
'' ) {
72 $nt = Title::makeTitleSafe(
NS_USER, $userName );
76 $this->mUserName = $nt->getText();
77 $user = User::newFromName( $this->mUserName,
false );
81 if ( !$user || ( $user->isAnon() && !User::isIP( $user->getName() ) ) ) {
87 if ( $search !==
'' && !$this->
getConfig()->
get(
'MiserMode' ) ) {
88 $this->mSearch = $search;
89 $nt = Title::newFromText( $this->mSearch );
93 $this->mQueryConds[] =
'LOWER(img_name)' .
95 strtolower( $nt->getDBkey() ),
$dbr->anyString() );
100 if ( $this->
getRequest()->getText(
'sort',
'img_date' ) ==
'img_date' ) {
268 $prefix = $table ===
'oldimage' ?
'oi' :
'img';
270 $tables = [ $table ];
272 $fields = array_combine( $fields, $fields );
273 unset( $fields[
'img_description'] );
274 unset( $fields[
'img_user_text'] );
276 if ( $table ===
'oldimage' ) {
277 foreach ( $fields as $id => $field ) {
278 if ( substr( $id, 0, 4 ) ===
'img_' ) {
279 $fields[$id] = $prefix . substr( $field, 3 );
282 $fields[
'top'] =
$dbr->addQuotes(
'no' );
283 } elseif ( $this->mShowAll ) {
284 $fields[
'top'] =
$dbr->addQuotes(
'yes' );
286 $fields[
'thumb'] = $prefix .
'_name';
288 $options = $join_conds = [];
291 $commentQuery = CommentStore::getStore()->getJoin( $prefix .
'_description' );
292 $tables += $commentQuery[
'tables'];
293 $fields += $commentQuery[
'fields'];
294 $join_conds += $commentQuery[
'joins'];
295 $fields[
'description_field'] =
$dbr->addQuotes(
"{$prefix}_description" );
298 $actorQuery = ActorMigration::newMigration()->getJoin( $prefix .
'_user' );
299 $tables += $actorQuery[
'tables'];
300 $join_conds += $actorQuery[
'joins'];
301 $fields[
'img_user'] = $actorQuery[
'fields'][$prefix .
'_user'];
302 $fields[
'img_user_text'] = $actorQuery[
'fields'][$prefix .
'_user_text'];
303 $fields[
'img_actor'] = $actorQuery[
'fields'][$prefix .
'_actor'];
305 # Depends on $wgMiserMode
306 # Will also not happen if mShowAll is true.
307 if ( isset( $fields[
'count'] ) ) {
308 $fields[
'count'] =
$dbr->buildSelectSubquery(
310 'COUNT(oi_archive_name)',
311 'oi_name = img_name',
320 'options' => $options,
321 'join_conds' => $join_conds
339 $this->mTableName =
'image';
340 list( $tables, $fields, $conds, $fname, $options, $join_conds ) =
342 $imageRes = $this->mDb->select( $tables, $fields, $conds, $fname, $options, $join_conds );
343 $this->mTableName = $prevTableName;
345 if ( !$this->mShowAll ) {
349 $this->mTableName =
'oldimage';
353 foreach ( $this->mIndexField as &$index ) {
354 if ( substr( $index, 0, 4 ) !==
'img_' ) {
355 throw new MWException(
"Expected to be sorting on an image table field" );
357 $index =
'oi_' . substr( $index, 4 );
360 list( $tables, $fields, $conds, $fname, $options, $join_conds ) =
362 $oldimageRes = $this->mDb->select( $tables, $fields, $conds, $fname, $options, $join_conds );
364 $this->mTableName = $prevTableName;
365 $this->mIndexField = $oldIndex;
367 return $this->
combineResult( $imageRes, $oldimageRes, $limit, $order );
384 $topRes1 = $res1->next();
385 $topRes2 = $res2->next();
387 for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
388 if ( strcmp( $topRes1->{$this->mIndexField[0]}, $topRes2->{$this->mIndexField[0]} ) > 0 ) {
390 $resultArray[] = $topRes1;
391 $topRes1 = $res1->next();
393 $resultArray[] = $topRes2;
394 $topRes2 = $res2->next();
396 } elseif ( !$ascending ) {
397 $resultArray[] = $topRes2;
398 $topRes2 = $res2->next();
400 $resultArray[] = $topRes1;
401 $topRes1 = $res1->next();
405 for ( ; $i < $limit && $topRes1; $i++ ) {
406 $resultArray[] = $topRes1;
407 $topRes1 = $res1->next();
410 for ( ; $i < $limit && $topRes2; $i++ ) {
411 $resultArray[] = $topRes2;
412 $topRes2 = $res2->next();
456 $services = MediaWikiServices::getInstance();
457 $linkRenderer = $this->getLinkRenderer();
460 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
461 $file = $services->getRepoGroup()->getLocalRepo()->findFile( $value, $opt );
464 $thumb =
$file->transform( [
'width' => 180,
'height' => 360 ] );
466 return $thumb->toHtml( [
'desc-link' =>
true ] );
468 return $this->msg(
'thumbnail_error',
'' )->escaped();
471 return htmlspecialchars( $value );
473 case 'img_timestamp':
475 return htmlspecialchars( $this->getLanguage()->userTimeAndDate( $value, $this->
getUser() ) );
477 static $imgfile =
null;
478 if ( $imgfile ===
null ) {
479 $imgfile = $this->msg(
'imgfile' )->text();
483 $filePage = Title::makeTitleSafe(
NS_FILE, $value );
485 $link = $linkRenderer->makeKnownLink(
489 $download = Xml::element(
491 [
'href' => $services->getRepoGroup()->getLocalRepo()->newFile( $filePage )->getUrl() ],
494 $download = $this->msg(
'parentheses' )->rawParams( $download )->escaped();
498 $permissionManager = $services->getPermissionManager();
500 if ( $permissionManager->userCan(
'delete', $this->getUser(), $filePage ) ) {
501 $deleteMsg = $this->msg(
'listfiles-delete' )->text();
503 $delete = $linkRenderer->makeKnownLink(
504 $filePage, $deleteMsg, [], [
'action' =>
'delete' ]
506 $delete = $this->msg(
'parentheses' )->rawParams( $delete )->escaped();
508 return "$link $download $delete";
511 return "$link $download";
513 return htmlspecialchars( $value );
515 case 'img_user_text':
516 if ( $this->mCurrentRow->img_user ) {
517 $name = User::whoIs( $this->mCurrentRow->img_user );
518 $link = $linkRenderer->makeLink(
519 Title::makeTitle(
NS_USER, $name ),
523 $link = $value !==
null ? htmlspecialchars( $value ) :
'';
528 return htmlspecialchars( $this->getLanguage()->formatSize( $value ) );
529 case 'img_description':
530 $field = $this->mCurrentRow->description_field;
531 $value = CommentStore::getStore()->getComment( $field, $this->mCurrentRow )->text;
534 return $this->getLanguage()->formatNum( intval( $value ) + 1 );
537 return $this->msg(
'listfiles-latestversion-' . $value )->escaped();
544 $formDescriptor = [];
545 $formDescriptor[
'limit'] = [
548 'label-message' =>
'table_pager_limit_label',
549 'options' => $this->getLimitSelectList(),
550 'default' => $this->mLimit,
553 if ( !$this->getConfig()->
get(
'MiserMode' ) ) {
554 $formDescriptor[
'ilsearch'] = [
556 'name' =>
'ilsearch',
557 'id' =>
'mw-ilsearch',
558 'label-message' =>
'listfiles_search_for',
559 'default' => $this->mSearch,
561 'maxlength' =>
'255',
565 $formDescriptor[
'user'] = [
568 'id' =>
'mw-listfiles-user',
569 'label-message' =>
'username',
570 'default' => $this->mUserName,
572 'maxlength' =>
'255',
575 $formDescriptor[
'ilshowall'] = [
577 'name' =>
'ilshowall',
578 'id' =>
'mw-listfiles-show-all',
579 'label-message' =>
'listfiles-show-all',
580 'default' => $this->mShowAll,
583 $query = $this->getRequest()->getQueryValues();
584 unset( $query[
'title'] );
585 unset( $query[
'limit'] );
586 unset( $query[
'ilsearch'] );
587 unset( $query[
'ilshowall'] );
588 unset( $query[
'user'] );
590 $htmlForm = HTMLForm::factory(
'ooui', $formDescriptor, $this->
getContext() );
593 ->setId(
'mw-listfiles-form' )
595 ->setSubmitTextMsg(
'table_pager_limit_submit' )
596 ->setWrapperLegendMsg(
'listfiles' )
597 ->addHiddenFields( $query )