MediaWiki
1.40.4
NewFilesPager.php
Go to the documentation of this file.
1
<?php
22
use
MediaWiki\Cache\LinkBatchFactory
;
23
use
MediaWiki\Html\FormOptions
;
24
use
MediaWiki\Linker\LinkRenderer
;
25
use
MediaWiki\Permissions\GroupPermissionsLookup
;
26
use
MediaWiki\Title\Title
;
27
use
Wikimedia\Rdbms\ILoadBalancer
;
28
32
class
NewFilesPager
extends
RangeChronologicalPager
{
33
37
protected
$gallery
;
38
42
protected
$opts
;
43
45
private
$groupPermissionsLookup;
46
48
private
$linkBatchFactory;
49
58
public
function
__construct
(
59
IContextSource
$context,
60
GroupPermissionsLookup
$groupPermissionsLookup,
61
LinkBatchFactory
$linkBatchFactory,
62
LinkRenderer
$linkRenderer,
63
ILoadBalancer
$loadBalancer,
64
FormOptions
$opts
65
) {
66
// Set database before parent constructor to avoid setting it there with wfGetDB
67
$this->mDb = $loadBalancer->
getConnectionRef
( ILoadBalancer::DB_REPLICA );
68
69
parent::__construct( $context, $linkRenderer );
70
71
$this->opts =
$opts
;
72
$this->groupPermissionsLookup = $groupPermissionsLookup;
73
$this->linkBatchFactory = $linkBatchFactory;
74
$this->
setLimit
( $opts->
getValue
(
'limit'
) );
75
76
$startTimestamp =
''
;
77
$endTimestamp =
''
;
78
if
(
$opts
->
getValue
(
'start'
) ) {
79
$startTimestamp =
$opts
->
getValue
(
'start'
) .
' 00:00:00'
;
80
}
81
if
(
$opts
->
getValue
(
'end'
) ) {
82
$endTimestamp =
$opts
->
getValue
(
'end'
) .
' 23:59:59'
;
83
}
84
$this->
getDateRangeCond
( $startTimestamp, $endTimestamp );
85
}
86
87
public
function
getQueryInfo
() {
88
$opts
=
$this->opts
;
89
$conds = [];
90
$dbr
= $this->
getDatabase
();
91
$tables = [
'image'
,
'actor'
];
92
$fields = [
'img_name'
,
'img_timestamp'
,
'actor_user'
,
'actor_name'
];
93
$options = [];
94
$jconds = [
'actor'
=> [
'JOIN'
,
'actor_id=img_actor'
] ];
95
96
$user =
$opts
->
getValue
(
'user'
);
97
if
( $user !==
''
) {
98
$conds[
'actor_name'
] = $user;
99
}
100
101
if
( !
$opts
->
getValue
(
'showbots'
) ) {
102
$groupsWithBotPermission = $this->groupPermissionsLookup->getGroupsWithPermission(
'bot'
);
103
104
if
( count( $groupsWithBotPermission ) ) {
105
$tables[] =
'user_groups'
;
106
$conds[] =
'ug_group IS NULL'
;
107
$jconds[
'user_groups'
] = [
108
'LEFT JOIN'
,
109
[
110
'ug_group'
=> $groupsWithBotPermission,
111
'ug_user = actor_user'
,
112
'ug_expiry IS NULL OR ug_expiry >= '
.
$dbr
->addQuotes(
$dbr
->timestamp() )
113
]
114
];
115
}
116
}
117
118
if
(
$opts
->
getValue
(
'hidepatrolled'
) ) {
119
$tables[] =
'recentchanges'
;
120
$conds[
'rc_type'
] =
RC_LOG
;
121
$conds[
'rc_log_type'
] =
'upload'
;
122
$conds[
'rc_patrolled'
] = RecentChange::PRC_UNPATROLLED;
123
$conds[
'rc_namespace'
] =
NS_FILE
;
124
125
$jconds[
'recentchanges'
] = [
126
'JOIN'
,
127
[
128
'rc_title = img_name'
,
129
'rc_actor = img_actor'
,
130
'rc_timestamp = img_timestamp'
131
]
132
];
133
}
134
135
if
(
$opts
->
getValue
(
'mediatype'
) ) {
136
$conds[
'img_media_type'
] =
$opts
->
getValue
(
'mediatype'
);
137
}
138
139
// We're ordering by img_timestamp, but MariaDB sometimes likes to query other tables first
140
// and filesort the result set later.
141
// See T124205 / https://mariadb.atlassian.net/browse/MDEV-8880, and T244533
142
// Twist: This would cause issues if the user is set and we need to check user existence first
143
if
( $user ===
''
) {
144
$options[] =
'STRAIGHT_JOIN'
;
145
}
146
147
$query = [
148
'tables'
=> $tables,
149
'fields'
=> $fields,
150
'join_conds'
=> $jconds,
151
'conds'
=> $conds,
152
'options'
=> $options,
153
];
154
155
return
$query;
156
}
157
158
public
function
getIndexField
() {
159
return
[ [
'img_timestamp'
,
'img_name'
] ];
160
}
161
162
protected
function
getStartBody
() {
163
if
( !$this->gallery ) {
164
// Note that null for mode is taken to mean use default.
165
$mode = $this->
getRequest
()->getVal(
'gallerymode'
,
null
);
166
try
{
167
$this->gallery = ImageGalleryBase::factory( $mode, $this->
getContext
() );
168
}
catch
(
ImageGalleryClassNotFoundException
$e ) {
169
// User specified something invalid, fallback to default.
170
$this->gallery = ImageGalleryBase::factory(
false
, $this->
getContext
() );
171
}
172
}
173
174
return
''
;
175
}
176
177
protected
function
getEndBody
() {
178
return
$this->gallery->toHTML();
179
}
180
181
protected
function
doBatchLookups
() {
182
$this->mResult->seek( 0 );
183
$lb = $this->linkBatchFactory->newLinkBatch();
184
foreach
( $this->mResult as $row ) {
185
if
( $row->actor_user ) {
186
$lb->add(
NS_USER
, $row->actor_name );
187
}
188
}
189
$lb->execute();
190
}
191
192
public
function
formatRow
( $row ) {
193
$username = $row->actor_name;
194
195
if
( ExternalUserNames::isExternal( $username ) ) {
196
$ul = htmlspecialchars( $username );
197
}
else
{
198
$ul = $this->
getLinkRenderer
()->makeLink(
199
new
TitleValue
(
NS_USER
, $username ),
200
$username
201
);
202
}
203
$time = $this->
getLanguage
()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
204
205
$this->gallery->add(
206
Title::makeTitle(
NS_FILE
, $row->img_name ),
207
"$ul<br />\n<i>"
208
. htmlspecialchars( $time )
209
.
"</i><br />\n"
,
210
''
,
211
''
,
212
[],
213
ImageGalleryBase::LOADING_LAZY
214
);
215
216
return
''
;
217
}
218
}
NS_USER
const NS_USER
Definition
Defines.php:66
NS_FILE
const NS_FILE
Definition
Defines.php:70
RC_LOG
const RC_LOG
Definition
Defines.php:118
getContext
getContext()
ContextSource\getRequest
getRequest()
Definition
ContextSource.php:82
ContextSource\getLanguage
getLanguage()
Definition
ContextSource.php:165
ImageGalleryBase
Image gallery.
Definition
ImageGalleryBase.php:35
ImageGalleryClassNotFoundException
Class for exceptions thrown by ImageGalleryBase::factory().
Definition
ImageGalleryClassNotFoundException.php:8
IndexPager\getLinkRenderer
getLinkRenderer()
Definition
IndexPager.php:1042
IndexPager\getDatabase
getDatabase()
Get the Database object in use.
Definition
IndexPager.php:250
IndexPager\setLimit
setLimit( $limit)
Set the limit from an other source than the request.
Definition
IndexPager.php:337
MediaWiki\Cache\LinkBatchFactory
Definition
LinkBatchFactory.php:41
MediaWiki\Html\FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition
FormOptions.php:41
MediaWiki\Html\FormOptions\getValue
getValue( $name)
Get the value for the given option name.
Definition
FormOptions.php:188
MediaWiki\Linker\LinkRenderer
Class that generates HTML for internal links.
Definition
LinkRenderer.php:44
MediaWiki\Permissions\GroupPermissionsLookup
Definition
GroupPermissionsLookup.php:31
MediaWiki\Title\Title
Represents a title within MediaWiki.
Definition
Title.php:82
NewFilesPager
Definition
NewFilesPager.php:32
NewFilesPager\getIndexField
getIndexField()
Returns the name of the index field.
Definition
NewFilesPager.php:158
NewFilesPager\getQueryInfo
getQueryInfo()
Provides all parameters needed for the main paged query.
Definition
NewFilesPager.php:87
NewFilesPager\getEndBody
getEndBody()
Hook into getBody() for the end of the list.
Definition
NewFilesPager.php:177
NewFilesPager\__construct
__construct(IContextSource $context, GroupPermissionsLookup $groupPermissionsLookup, LinkBatchFactory $linkBatchFactory, LinkRenderer $linkRenderer, ILoadBalancer $loadBalancer, FormOptions $opts)
Definition
NewFilesPager.php:58
NewFilesPager\formatRow
formatRow( $row)
Returns an HTML string representing the result row $row.
Definition
NewFilesPager.php:192
NewFilesPager\getStartBody
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition
NewFilesPager.php:162
NewFilesPager\doBatchLookups
doBatchLookups()
Called from getBody(), before getStartBody() is called and after doQuery() was called.
Definition
NewFilesPager.php:181
NewFilesPager\$opts
FormOptions $opts
Definition
NewFilesPager.php:42
NewFilesPager\$gallery
ImageGalleryBase $gallery
Definition
NewFilesPager.php:37
RangeChronologicalPager
Pager for filtering by a range of dates.
Definition
RangeChronologicalPager.php:28
RangeChronologicalPager\getDateRangeCond
getDateRangeCond( $startTime, $endTime)
Set and return a date range condition using timestamps provided by the user.
Definition
RangeChronologicalPager.php:52
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition
TitleValue.php:40
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition
IContextSource.php:60
Wikimedia\Rdbms\ILoadBalancer
This class is a delegate to ILBFactory for a given database cluster.
Definition
ILoadBalancer.php:113
Wikimedia\Rdbms\ILoadBalancer\getConnectionRef
getConnectionRef( $i, $groups=[], $domain=false, $flags=0)
$dbr
$dbr
Definition
testCompression.php:55
includes
specials
pagers
NewFilesPager.php
Generated on Thu Jun 27 2024 15:52:19 for MediaWiki by
1.10.0