MediaWiki REL1_30
NewFilesPager.php
Go to the documentation of this file.
1<?php
26
28
32 protected $gallery;
33
37 protected $opts;
38
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() {
62 $conds = $jconds = [];
63 $tables = [ 'image' ];
64 $fields = [ 'img_name', 'img_user', 'img_timestamp' ];
65 $options = [];
66
67 $user = $opts->getValue( 'user' );
68 if ( $user !== '' ) {
69 $userId = User::idFromName( $user );
70 if ( $userId ) {
71 $conds['img_user'] = $userId;
72 } else {
73 $conds['img_user_text'] = $user;
74 }
75 }
76
77 if ( $opts->getValue( 'newbies' ) ) {
78 // newbie = most recent 1% of users
80 $max = $dbr->selectField( 'user', 'max(user_id)', false, __METHOD__ );
81 $conds[] = 'img_user >' . (int)( $max - $max / 100 );
82
83 // there's no point in looking for new user activity in a far past;
84 // beyond a certain point, we'd just end up scanning the rest of the
85 // table even though the users we're looking for didn't yet exist...
86 // see T140537, (for ContribsPages, but similar to this)
87 $conds[] = 'img_timestamp > ' .
88 $dbr->addQuotes( $dbr->timestamp( wfTimestamp() - 30 * 24 * 60 * 60 ) );
89 }
90
91 if ( !$opts->getValue( 'showbots' ) ) {
92 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
93
94 if ( count( $groupsWithBotPermission ) ) {
96 $tables[] = 'user_groups';
97 $conds[] = 'ug_group IS NULL';
98 $jconds['user_groups'] = [
99 'LEFT JOIN',
100 [
101 'ug_group' => $groupsWithBotPermission,
102 'ug_user = img_user',
103 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
104 ]
105 ];
106 }
107 }
108
109 if ( $opts->getValue( 'hidepatrolled' ) ) {
110 $tables[] = 'recentchanges';
111 $conds['rc_type'] = RC_LOG;
112 $conds['rc_log_type'] = 'upload';
113 $conds['rc_patrolled'] = 0;
114 $conds['rc_namespace'] = NS_FILE;
115 $jconds['recentchanges'] = [
116 'INNER JOIN',
117 [
118 'rc_title = img_name',
119 'rc_user = img_user',
120 'rc_timestamp = img_timestamp'
121 ]
122 ];
123 // We're ordering by img_timestamp, so we have to make sure MariaDB queries `image` first.
124 // It sometimes decides to query `recentchanges` first and filesort the result set later
125 // to get the right ordering. T124205 / https://mariadb.atlassian.net/browse/MDEV-8880
126 $options[] = 'STRAIGHT_JOIN';
127 }
128
129 if ( $opts->getValue( 'mediatype' ) ) {
130 $conds['img_media_type'] = $opts->getValue( 'mediatype' );
131 }
132
133 $likeVal = $opts->getValue( 'like' );
134 if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
136 $likeObj = Title::newFromText( $likeVal );
137 if ( $likeObj instanceof Title ) {
138 $like = $dbr->buildLike(
139 $dbr->anyString(),
140 strtolower( $likeObj->getDBkey() ),
141 $dbr->anyString()
142 );
143 $conds[] = "LOWER(img_name) $like";
144 }
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 function getIndexField() {
159 return 'img_timestamp';
160 }
161
162 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 ( Exception $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 function getEndBody() {
178 return $this->gallery->toHTML();
179 }
180
181 function formatRow( $row ) {
182 $name = $row->img_name;
183 $user = User::newFromId( $row->img_user );
184
185 $title = Title::makeTitle( NS_FILE, $name );
186 $ul = MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
187 $user->getUserPage(),
188 $user->getName()
189 );
190 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
191
192 $this->gallery->add(
193 $title,
194 "$ul<br />\n<i>"
195 . htmlspecialchars( $time )
196 . "</i><br />\n"
197 );
198 }
199}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getContext()
getRequest()
Get the WebRequest object.
getConfig()
Get the Config object.
getLanguage()
Get the Language object.
Helper class to keep track of options when mixing links and form elements.
getValue( $name)
Get the value for the given option name.
static factory( $mode=false, IContextSource $context=null)
Get a new image gallery.
setLimit( $limit)
Set the limit from an other source than the request.
MediaWikiServices is the service locator for the application scope of MediaWiki.
getIndexField()
This function should be overridden to return the name of the index fi- eld.
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
getEndBody()
Hook into getBody() for the end of the list.
formatRow( $row)
Abstract formatting function.
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
__construct(IContextSource $context, FormOptions $opts)
FormOptions $opts
ImageGalleryBase $gallery
Pager for filtering by a range of dates.
getDateRangeCond( $startStamp, $endStamp)
Set and return a date range condition using timestamps provided by the user.
Represents a title within MediaWiki.
Definition Title.php:39
if(! $regexes) $dbr
Definition cleanup.php:94
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition hooks.txt:1778
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition hooks.txt:1013
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:1971
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2780
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1610
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
returning false will NOT prevent logging $e
Definition hooks.txt:2146
const NS_FILE
Definition Defines.php:71
const RC_LOG
Definition Defines.php:145
Interface for objects which can provide a MediaWiki context on request.
const DB_REPLICA
Definition defines.php:25