Pagers: Drop 'newbie' feature
[lhc/web/wiklou.git] / includes / specials / pagers / NewFilesPager.php
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.
7 *
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.
12 *
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
17 *
18 * @file
19 * @ingroup Pager
20 */
21
22 /**
23 * @ingroup Pager
24 */
25 use MediaWiki\MediaWikiServices;
26
27 class NewFilesPager extends RangeChronologicalPager {
28
29 /**
30 * @var ImageGalleryBase
31 */
32 protected $gallery;
33
34 /**
35 * @var FormOptions
36 */
37 protected $opts;
38
39 /**
40 * @param IContextSource $context
41 * @param FormOptions $opts
42 */
43 public function __construct( IContextSource $context, FormOptions $opts ) {
44 parent::__construct( $context );
45
46 $this->opts = $opts;
47 $this->setLimit( $opts->getValue( 'limit' ) );
48
49 $startTimestamp = '';
50 $endTimestamp = '';
51 if ( $opts->getValue( 'start' ) ) {
52 $startTimestamp = $opts->getValue( 'start' ) . ' 00:00:00';
53 }
54 if ( $opts->getValue( 'end' ) ) {
55 $endTimestamp = $opts->getValue( 'end' ) . ' 23:59:59';
56 }
57 $this->getDateRangeCond( $startTimestamp, $endTimestamp );
58 }
59
60 function getQueryInfo() {
61 $opts = $this->opts;
62 $conds = [];
63 $imgQuery = LocalFile::getQueryInfo();
64 $tables = $imgQuery['tables'];
65 $fields = [ 'img_name', 'img_timestamp' ] + $imgQuery['fields'];
66 $options = [];
67 $jconds = $imgQuery['joins'];
68
69 $user = $opts->getValue( 'user' );
70 if ( $user !== '' ) {
71 $conds[] = ActorMigration::newMigration()
72 ->getWhere( wfGetDB( DB_REPLICA ), 'img_user', User::newFromName( $user, false ) )['conds'];
73 }
74
75 if ( !$opts->getValue( 'showbots' ) ) {
76 $groupsWithBotPermission = MediaWikiServices::getInstance()
77 ->getPermissionManager()
78 ->getGroupsWithPermission( 'bot' );
79
80 if ( count( $groupsWithBotPermission ) ) {
81 $dbr = wfGetDB( DB_REPLICA );
82 $tables[] = 'user_groups';
83 $conds[] = 'ug_group IS NULL';
84 $jconds['user_groups'] = [
85 'LEFT JOIN',
86 [
87 'ug_group' => $groupsWithBotPermission,
88 'ug_user = ' . $imgQuery['fields']['img_user'],
89 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
90 ]
91 ];
92 }
93 }
94
95 if ( $opts->getValue( 'hidepatrolled' ) ) {
96 global $wgActorTableSchemaMigrationStage;
97
98 $tables[] = 'recentchanges';
99 $conds['rc_type'] = RC_LOG;
100 $conds['rc_log_type'] = 'upload';
101 $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
102 $conds['rc_namespace'] = NS_FILE;
103
104 if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
105 $jcond = 'rc_actor = ' . $imgQuery['fields']['img_actor'];
106 } else {
107 $rcQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
108 $tables += $rcQuery['tables'];
109 $jconds += $rcQuery['joins'];
110 $jcond = $rcQuery['fields']['rc_user'] . ' = ' . $imgQuery['fields']['img_user'];
111 }
112 $jconds['recentchanges'] = [
113 'JOIN',
114 [
115 'rc_title = img_name',
116 $jcond,
117 'rc_timestamp = img_timestamp'
118 ]
119 ];
120 // We're ordering by img_timestamp, so we have to make sure MariaDB queries `image` first.
121 // It sometimes decides to query `recentchanges` first and filesort the result set later
122 // to get the right ordering. T124205 / https://mariadb.atlassian.net/browse/MDEV-8880
123 $options[] = 'STRAIGHT_JOIN';
124 }
125
126 if ( $opts->getValue( 'mediatype' ) ) {
127 $conds['img_media_type'] = $opts->getValue( 'mediatype' );
128 }
129
130 $likeVal = $opts->getValue( 'like' );
131 if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
132 $dbr = wfGetDB( DB_REPLICA );
133 $likeObj = Title::newFromText( $likeVal );
134 if ( $likeObj instanceof Title ) {
135 $like = $dbr->buildLike(
136 $dbr->anyString(),
137 strtolower( $likeObj->getDBkey() ),
138 $dbr->anyString()
139 );
140 $conds[] = "LOWER(img_name) $like";
141 }
142 }
143
144 $query = [
145 'tables' => $tables,
146 'fields' => $fields,
147 'join_conds' => $jconds,
148 'conds' => $conds,
149 'options' => $options,
150 ];
151
152 return $query;
153 }
154
155 function getIndexField() {
156 return 'img_timestamp';
157 }
158
159 protected function getStartBody() {
160 if ( !$this->gallery ) {
161 // Note that null for mode is taken to mean use default.
162 $mode = $this->getRequest()->getVal( 'gallerymode', null );
163 try {
164 $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
165 } catch ( Exception $e ) {
166 // User specified something invalid, fallback to default.
167 $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
168 }
169 }
170
171 return '';
172 }
173
174 protected function getEndBody() {
175 return $this->gallery->toHTML();
176 }
177
178 function formatRow( $row ) {
179 $name = $row->img_name;
180 $user = User::newFromId( $row->img_user );
181
182 $title = Title::makeTitle( NS_FILE, $name );
183 $ul = $this->getLinkRenderer()->makeLink(
184 $user->getUserPage(),
185 $user->getName()
186 );
187 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
188
189 $this->gallery->add(
190 $title,
191 "$ul<br />\n<i>"
192 . htmlspecialchars( $time )
193 . "</i><br />\n"
194 );
195 return '';
196 }
197 }