59 $this->mIncluding = $including;
60 $this->mShowAll = $showAll;
62 if ( $userName !==
null && $userName !==
'' ) {
63 $nt = Title::makeTitleSafe(
NS_USER, $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;
80 $nt = Title::newFromText( $this->mSearch );
84 $this->mQueryConds[] =
'LOWER(img_name)' .
86 strtolower( $nt->getDBkey() ),
$dbr->anyString() );
91 if ( $this->
getRequest()->getText(
'sort',
'img_date' ) ==
'img_date' ) {
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 = [];
282 $commentQuery = CommentStore::getStore()->getJoin( $prefix .
'_description' );
283 $tables += $commentQuery[
'tables'];
284 $fields += $commentQuery[
'fields'];
285 $join_conds += $commentQuery[
'joins'];
286 $fields[
'description_field'] =
$dbr->addQuotes(
"{$prefix}_description" );
289 $actorQuery = ActorMigration::newMigration()->getJoin( $prefix .
'_user' );
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();
441 $services = MediaWikiServices::getInstance();
442 $linkRenderer = $this->getLinkRenderer();
445 $opt = [
'time' =>
wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
446 $file = RepoGroup::singleton()->getLocalRepo()->findFile( $value, $opt );
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();
468 $filePage = Title::makeTitleSafe(
NS_FILE, $value );
470 $link = $linkRenderer->makeKnownLink(
474 $download = Xml::element(
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(
504 Title::makeTitle(
NS_USER, $name ),
508 $link = htmlspecialchars( $value );
513 return htmlspecialchars( $this->getLanguage()->formatSize( $value ) );
514 case 'img_description':
515 $field = $this->mCurrentRow->description_field;
516 $value = CommentStore::getStore()->getComment( $field, $this->mCurrentRow )->text;
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'] );
575 $htmlForm = HTMLForm::factory(
'ooui', $formDescriptor, $this->
getContext() );
578 ->setId(
'mw-listfiles-form' )
580 ->setSubmitTextMsg(
'table_pager_limit_submit' )
581 ->setWrapperLegendMsg(
'listfiles' )
582 ->addHiddenFields( $query )