Update docs/hooks.txt for ShowSearchHitTitle
[mediawiki.git] / includes / specials / pagers / NewFilesPager.php
blobe22b939fd676316d0d4d5b12137c39341ebc77fd
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup Pager
22 /**
23 * @ingroup Pager
25 use MediaWiki\MediaWikiServices;
27 class NewFilesPager extends ReverseChronologicalPager {
29 /**
30 * @var ImageGalleryBase
32 protected $gallery;
34 /**
35 * @var FormOptions
37 protected $opts;
39 /**
40 * @param IContextSource $context
41 * @param FormOptions $opts
43 function __construct( IContextSource $context, FormOptions $opts ) {
44 $this->opts = $opts;
46 $this->setLimit( $opts->getValue( 'limit' ) );
48 parent::__construct( $context );
51 function getQueryInfo() {
52 $opts = $this->opts;
53 $conds = $jconds = [];
54 $tables = [ 'image' ];
55 $fields = [ 'img_name', 'img_user', 'img_timestamp' ];
56 $options = [];
58 if ( !$opts->getValue( 'showbots' ) ) {
59 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
61 if ( count( $groupsWithBotPermission ) ) {
62 $tables[] = 'user_groups';
63 $conds[] = 'ug_group IS NULL';
64 $jconds['user_groups'] = [
65 'LEFT JOIN',
67 'ug_group' => $groupsWithBotPermission,
68 'ug_user = img_user'
74 if ( $opts->getValue( 'hidepatrolled' ) ) {
75 $tables[] = 'recentchanges';
76 $conds['rc_type'] = RC_LOG;
77 $conds['rc_log_type'] = 'upload';
78 $conds['rc_patrolled'] = 0;
79 $conds['rc_namespace'] = NS_FILE;
80 $jconds['recentchanges'] = [
81 'INNER JOIN',
83 'rc_title = img_name',
84 'rc_user = img_user',
85 'rc_timestamp = img_timestamp'
88 // We're ordering by img_timestamp, so we have to make sure MariaDB queries `image` first.
89 // It sometimes decides to query `recentchanges` first and filesort the result set later
90 // to get the right ordering. T124205 / https://mariadb.atlassian.net/browse/MDEV-8880
91 $options[] = 'STRAIGHT_JOIN';
94 $likeVal = $opts->getValue( 'like' );
95 if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
96 $dbr = wfGetDB( DB_REPLICA );
97 $likeObj = Title::newFromText( $likeVal );
98 if ( $likeObj instanceof Title ) {
99 $like = $dbr->buildLike(
100 $dbr->anyString(),
101 strtolower( $likeObj->getDBkey() ),
102 $dbr->anyString()
104 $conds[] = "LOWER(img_name) $like";
108 $query = [
109 'tables' => $tables,
110 'fields' => $fields,
111 'join_conds' => $jconds,
112 'conds' => $conds,
113 'options' => $options,
116 return $query;
119 function getIndexField() {
120 return 'img_timestamp';
123 function getStartBody() {
124 if ( !$this->gallery ) {
125 // Note that null for mode is taken to mean use default.
126 $mode = $this->getRequest()->getVal( 'gallerymode', null );
127 try {
128 $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
129 } catch ( Exception $e ) {
130 // User specified something invalid, fallback to default.
131 $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
135 return '';
138 function getEndBody() {
139 return $this->gallery->toHTML();
142 function formatRow( $row ) {
143 $name = $row->img_name;
144 $user = User::newFromId( $row->img_user );
146 $title = Title::makeTitle( NS_FILE, $name );
147 $ul = MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
148 $user->getUserPage(),
149 $user->getName()
151 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
153 $this->gallery->add(
154 $title,
155 "$ul<br />\n<i>"
156 . htmlspecialchars( $time )
157 . "</i><br />\n"