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
25 use MediaWiki\MediaWikiServices
;
27 class NewFilesPager
extends RangeChronologicalPager
{
30 * @var ImageGalleryBase
40 * @param IContextSource $context
41 * @param FormOptions $opts
43 public function __construct( IContextSource
$context, FormOptions
$opts ) {
44 parent
::__construct( $context );
47 $this->setLimit( $opts->getValue( 'limit' ) );
51 if ( $opts->getValue( 'start' ) ) {
52 $startTimestamp = $opts->getValue( 'start' ) . ' 00:00:00';
54 if ( $opts->getValue( 'end' ) ) {
55 $endTimestamp = $opts->getValue( 'end' ) . ' 23:59:59';
57 $this->getDateRangeCond( $startTimestamp, $endTimestamp );
60 function getQueryInfo() {
63 $imgQuery = LocalFile
::getQueryInfo();
64 $tables = $imgQuery['tables'];
65 $fields = [ 'img_name', 'img_timestamp' ] +
$imgQuery['fields'];
67 $jconds = $imgQuery['joins'];
69 $user = $opts->getValue( 'user' );
71 $conds[] = ActorMigration
::newMigration()
72 ->getWhere( wfGetDB( DB_REPLICA
), 'img_user', User
::newFromName( $user, false ) )['conds'];
75 if ( $opts->getValue( 'newbies' ) ) {
76 // newbie = most recent 1% of users
77 $dbr = wfGetDB( DB_REPLICA
);
78 $max = $dbr->selectField( 'user', 'max(user_id)', '', __METHOD__
);
79 $conds[] = $imgQuery['fields']['img_user'] . ' >' . (int)( $max - $max / 100 );
81 // there's no point in looking for new user activity in a far past;
82 // beyond a certain point, we'd just end up scanning the rest of the
83 // table even though the users we're looking for didn't yet exist...
84 // see T140537, (for ContribsPages, but similar to this)
85 $conds[] = 'img_timestamp > ' .
86 $dbr->addQuotes( $dbr->timestamp( wfTimestamp() - 30 * 24 * 60 * 60 ) );
89 if ( !$opts->getValue( 'showbots' ) ) {
90 $groupsWithBotPermission = MediaWikiServices
::getInstance()
91 ->getPermissionManager()
92 ->getGroupsWithPermission( 'bot' );
94 if ( count( $groupsWithBotPermission ) ) {
95 $dbr = wfGetDB( DB_REPLICA
);
96 $tables[] = 'user_groups';
97 $conds[] = 'ug_group IS NULL';
98 $jconds['user_groups'] = [
101 'ug_group' => $groupsWithBotPermission,
102 'ug_user = ' . $imgQuery['fields']['img_user'],
103 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
109 if ( $opts->getValue( 'hidepatrolled' ) ) {
110 global $wgActorTableSchemaMigrationStage;
112 $tables[] = 'recentchanges';
113 $conds['rc_type'] = RC_LOG
;
114 $conds['rc_log_type'] = 'upload';
115 $conds['rc_patrolled'] = RecentChange
::PRC_UNPATROLLED
;
116 $conds['rc_namespace'] = NS_FILE
;
118 if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW
) {
119 $jcond = 'rc_actor = ' . $imgQuery['fields']['img_actor'];
121 $rcQuery = ActorMigration
::newMigration()->getJoin( 'rc_user' );
122 $tables +
= $rcQuery['tables'];
123 $jconds +
= $rcQuery['joins'];
124 $jcond = $rcQuery['fields']['rc_user'] . ' = ' . $imgQuery['fields']['img_user'];
126 $jconds['recentchanges'] = [
129 'rc_title = img_name',
131 'rc_timestamp = img_timestamp'
134 // We're ordering by img_timestamp, so we have to make sure MariaDB queries `image` first.
135 // It sometimes decides to query `recentchanges` first and filesort the result set later
136 // to get the right ordering. T124205 / https://mariadb.atlassian.net/browse/MDEV-8880
137 $options[] = 'STRAIGHT_JOIN';
140 if ( $opts->getValue( 'mediatype' ) ) {
141 $conds['img_media_type'] = $opts->getValue( 'mediatype' );
144 $likeVal = $opts->getValue( 'like' );
145 if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
146 $dbr = wfGetDB( DB_REPLICA
);
147 $likeObj = Title
::newFromText( $likeVal );
148 if ( $likeObj instanceof Title
) {
149 $like = $dbr->buildLike(
151 strtolower( $likeObj->getDBkey() ),
154 $conds[] = "LOWER(img_name) $like";
161 'join_conds' => $jconds,
163 'options' => $options,
169 function getIndexField() {
170 return 'img_timestamp';
173 protected function getStartBody() {
174 if ( !$this->gallery
) {
175 // Note that null for mode is taken to mean use default.
176 $mode = $this->getRequest()->getVal( 'gallerymode', null );
178 $this->gallery
= ImageGalleryBase
::factory( $mode, $this->getContext() );
179 } catch ( Exception
$e ) {
180 // User specified something invalid, fallback to default.
181 $this->gallery
= ImageGalleryBase
::factory( false, $this->getContext() );
188 protected function getEndBody() {
189 return $this->gallery
->toHTML();
192 function formatRow( $row ) {
193 $name = $row->img_name
;
194 $user = User
::newFromId( $row->img_user
);
196 $title = Title
::makeTitle( NS_FILE
, $name );
197 $ul = MediaWikiServices
::getInstance()->getLinkRenderer()->makeLink(
198 $user->getUserPage(),
201 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp
, $this->getUser() );
206 . htmlspecialchars( $time )