MediaWiki
fundraising/REL1_35
NewFilesPager.php
Go to the documentation of this file.
1
<?php
25
use
MediaWiki\Linker\LinkRenderer
;
26
use
MediaWiki\MediaWikiServices
;
27
28
class
NewFilesPager
extends
RangeChronologicalPager
{
29
33
protected
$gallery
;
34
38
protected
$opts
;
39
45
public
function
__construct
(
IContextSource
$context
,
FormOptions
$opts
,
46
LinkRenderer
$linkRenderer
47
) {
48
parent::__construct(
$context
,
$linkRenderer
);
49
50
$this->opts =
$opts
;
51
$this->
setLimit
( $opts->
getValue
(
'limit'
) );
52
53
$startTimestamp =
''
;
54
$endTimestamp =
''
;
55
if
(
$opts
->
getValue
(
'start'
) ) {
56
$startTimestamp =
$opts
->
getValue
(
'start'
) .
' 00:00:00'
;
57
}
58
if
(
$opts
->
getValue
(
'end'
) ) {
59
$endTimestamp =
$opts
->
getValue
(
'end'
) .
' 23:59:59'
;
60
}
61
$this->
getDateRangeCond
( $startTimestamp, $endTimestamp );
62
}
63
64
public
function
getQueryInfo
() {
65
$opts
=
$this->opts
;
66
$conds = [];
67
$actorQuery = ActorMigration::newMigration()->getJoin(
'img_user'
);
68
$tables = [
'image'
] + $actorQuery[
'tables'
];
69
$fields = [
'img_name'
,
'img_timestamp'
] + $actorQuery[
'fields'
];
70
$options = [];
71
$jconds = $actorQuery[
'joins'
];
72
73
$user =
$opts
->
getValue
(
'user'
);
74
if
( $user !==
''
) {
75
$conds[] = ActorMigration::newMigration()
76
->getWhere(
wfGetDB
(
DB_REPLICA
),
'img_user'
, User::newFromName( $user,
false
) )[
'conds'
];
77
}
78
79
if
( !
$opts
->
getValue
(
'showbots'
) ) {
80
$groupsWithBotPermission = MediaWikiServices::getInstance()
81
->getPermissionManager()
82
->getGroupsWithPermission(
'bot'
);
83
84
if
( count( $groupsWithBotPermission ) ) {
85
$dbr
=
wfGetDB
(
DB_REPLICA
);
86
$tables[] =
'user_groups'
;
87
$conds[] =
'ug_group IS NULL'
;
88
$jconds[
'user_groups'
] = [
89
'LEFT JOIN'
,
90
[
91
'ug_group'
=> $groupsWithBotPermission,
92
'ug_user = '
. $actorQuery[
'fields'
][
'img_user'
],
93
'ug_expiry IS NULL OR ug_expiry >= '
.
$dbr
->addQuotes(
$dbr
->timestamp() )
94
]
95
];
96
}
97
}
98
99
if
(
$opts
->
getValue
(
'hidepatrolled'
) ) {
100
$tables[] =
'recentchanges'
;
101
$conds[
'rc_type'
] =
RC_LOG
;
102
$conds[
'rc_log_type'
] =
'upload'
;
103
$conds[
'rc_patrolled'
] = RecentChange::PRC_UNPATROLLED;
104
$conds[
'rc_namespace'
] =
NS_FILE
;
105
106
$jconds[
'recentchanges'
] = [
107
'JOIN'
,
108
[
109
'rc_title = img_name'
,
110
'rc_actor = '
. $actorQuery[
'fields'
][
'img_actor'
],
111
'rc_timestamp = img_timestamp'
112
]
113
];
114
}
115
116
if
(
$opts
->
getValue
(
'mediatype'
) ) {
117
$conds[
'img_media_type'
] =
$opts
->
getValue
(
'mediatype'
);
118
}
119
120
$likeVal =
$opts
->
getValue
(
'like'
);
121
if
( !$this->
getConfig
()->
get
(
'MiserMode'
) && $likeVal !==
''
) {
122
$dbr
=
wfGetDB
(
DB_REPLICA
);
123
$likeObj = Title::newFromText( $likeVal );
124
if
( $likeObj instanceof
Title
) {
125
$like =
$dbr
->buildLike(
126
$dbr
->anyString(),
127
strtolower( $likeObj->getDBkey() ),
128
$dbr
->anyString()
129
);
130
$conds[] =
"LOWER(img_name) $like"
;
131
}
132
}
133
134
// We're ordering by img_timestamp, but MariaDB sometimes likes to query other tables first
135
// and filesort the result set later.
136
// See T124205 / https://mariadb.atlassian.net/browse/MDEV-8880, and T244533
137
// Twist: This would cause issues if the user is set and we need to check user existence first
138
if
( $user ===
''
) {
139
$options[] =
'STRAIGHT_JOIN'
;
140
}
141
142
$query = [
143
'tables'
=> $tables,
144
'fields'
=> $fields,
145
'join_conds'
=> $jconds,
146
'conds'
=> $conds,
147
'options'
=> $options,
148
];
149
150
return
$query;
151
}
152
153
public
function
getIndexField
() {
154
return
'img_timestamp'
;
155
}
156
157
protected
function
getStartBody
() {
158
if
( !$this->gallery ) {
159
// Note that null for mode is taken to mean use default.
160
$mode = $this->
getRequest
()->getVal(
'gallerymode'
,
null
);
161
try
{
162
$this->gallery = ImageGalleryBase::factory( $mode, $this->
getContext
() );
163
}
catch
( Exception $e ) {
164
// User specified something invalid, fallback to default.
165
$this->gallery = ImageGalleryBase::factory(
false
, $this->
getContext
() );
166
}
167
}
168
169
return
''
;
170
}
171
172
protected
function
getEndBody
() {
173
return
$this->gallery->toHTML();
174
}
175
176
protected
function
doBatchLookups
() {
177
$userIds = [];
178
$this->mResult->seek( 0 );
179
foreach
( $this->mResult as $row ) {
180
$userIds[] = $row->img_user;
181
}
182
// Do a link batch query for names and userpages
183
UserCache::singleton
()->doQuery( $userIds, [
'userpage'
], __METHOD__ );
184
}
185
186
public
function
formatRow
( $row ) {
187
$name = $row->img_name;
188
$username =
UserCache::singleton
()->getUserName( $row->img_user, $row->img_user_text );
189
190
$title
= Title::makeTitle(
NS_FILE
, $name );
191
if
( ExternalUserNames::isExternal( $username ) ) {
192
$ul
= htmlspecialchars( $username );
193
}
else
{
194
$ul
= $this->
getLinkRenderer
()->makeLink(
195
Title::makeTitle(
NS_USER
, $username ),
196
$username
197
);
198
}
199
$time = $this->
getLanguage
()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
200
201
$this->gallery->add(
202
$title
,
203
"$ul<br />\n<i>"
204
. htmlspecialchars( $time )
205
.
"</i><br />\n"
,
206
''
,
207
''
,
208
[],
209
ImageGalleryBase::LOADING_LAZY
210
);
211
return
''
;
212
}
213
}
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition
GlobalFunctions.php:2462
getContext
getContext()
ContextSource\getRequest
getRequest()
Definition
ContextSource.php:76
ContextSource\getConfig
getConfig()
Definition
ContextSource.php:67
ContextSource\$context
IContextSource $context
Definition
ContextSource.php:34
ContextSource\getLanguage
getLanguage()
Definition
ContextSource.php:140
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition
FormOptions.php:35
FormOptions\getValue
getValue( $name)
Get the value for the given option name.
Definition
FormOptions.php:182
ImageGalleryBase
Image gallery.
Definition
ImageGalleryBase.php:32
IndexPager\getLinkRenderer
getLinkRenderer()
Definition
IndexPager.php:976
IndexPager\$linkRenderer
LinkRenderer $linkRenderer
Definition
IndexPager.php:167
IndexPager\setLimit
setLimit( $limit)
Set the limit from an other source than the request.
Definition
IndexPager.php:325
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition
LinkRenderer.php:43
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition
MediaWikiServices.php:152
NewFilesPager
Definition
NewFilesPager.php:28
NewFilesPager\getIndexField
getIndexField()
Returns the name of the index field.
Definition
NewFilesPager.php:153
NewFilesPager\getQueryInfo
getQueryInfo()
Provides all parameters needed for the main paged query.
Definition
NewFilesPager.php:64
NewFilesPager\getEndBody
getEndBody()
Hook into getBody() for the end of the list.
Definition
NewFilesPager.php:172
NewFilesPager\__construct
__construct(IContextSource $context, FormOptions $opts, LinkRenderer $linkRenderer)
Definition
NewFilesPager.php:45
NewFilesPager\formatRow
formatRow( $row)
Returns an HTML string representing the result row $row.
Definition
NewFilesPager.php:186
NewFilesPager\getStartBody
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition
NewFilesPager.php:157
NewFilesPager\doBatchLookups
doBatchLookups()
Called from getBody(), before getStartBody() is called and after doQuery() was called.
Definition
NewFilesPager.php:176
NewFilesPager\$opts
FormOptions $opts
Definition
NewFilesPager.php:38
NewFilesPager\$gallery
ImageGalleryBase $gallery
Definition
NewFilesPager.php:33
RangeChronologicalPager
Pager for filtering by a range of dates.
Definition
RangeChronologicalPager.php:28
RangeChronologicalPager\getDateRangeCond
getDateRangeCond( $startStamp, $endStamp)
Set and return a date range condition using timestamps provided by the user.
Definition
RangeChronologicalPager.php:46
Title
Represents a title within MediaWiki.
Definition
Title.php:42
UserCache\singleton
static singleton()
Definition
UserCache.php:34
NS_USER
const NS_USER
Definition
Defines.php:72
NS_FILE
const NS_FILE
Definition
Defines.php:76
RC_LOG
const RC_LOG
Definition
Defines.php:134
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition
IContextSource.php:55
DB_REPLICA
const DB_REPLICA
Definition
defines.php:25
$dbr
$dbr
Definition
testCompression.php:54
$title
$title
Definition
testCompression.php:38
$ul
$ul
Definition
upgradeLogging.php:222
includes
specials
pagers
NewFilesPager.php
Generated on Mon Nov 25 2024 16:15:48 for MediaWiki by
1.10.0