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 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() {
62 $conds = $jconds = [];
63 $tables = [ 'image' ];
64 $fields = [ 'img_name', 'img_user', 'img_timestamp' ];
67 $user = $opts->getValue( 'user' );
69 $userId = User
::idFromName( $user );
71 $conds['img_user'] = $userId;
73 $conds['img_user_text'] = $user;
77 if ( !$opts->getValue( 'showbots' ) ) {
78 $groupsWithBotPermission = User
::getGroupsWithPermission( 'bot' );
80 if ( count( $groupsWithBotPermission ) ) {
81 $dbr = wfGetDB( DB_REPLICA
);
82 $tables[] = 'user_groups';
83 $conds[] = 'ug_group IS NULL';
84 $jconds['user_groups'] = [
87 'ug_group' => $groupsWithBotPermission,
89 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
95 if ( $opts->getValue( 'hidepatrolled' ) ) {
96 $tables[] = 'recentchanges';
97 $conds['rc_type'] = RC_LOG
;
98 $conds['rc_log_type'] = 'upload';
99 $conds['rc_patrolled'] = 0;
100 $conds['rc_namespace'] = NS_FILE
;
101 $jconds['recentchanges'] = [
104 'rc_title = img_name',
105 'rc_user = img_user',
106 'rc_timestamp = img_timestamp'
109 // We're ordering by img_timestamp, so we have to make sure MariaDB queries `image` first.
110 // It sometimes decides to query `recentchanges` first and filesort the result set later
111 // to get the right ordering. T124205 / https://mariadb.atlassian.net/browse/MDEV-8880
112 $options[] = 'STRAIGHT_JOIN';
115 $likeVal = $opts->getValue( 'like' );
116 if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
117 $dbr = wfGetDB( DB_REPLICA
);
118 $likeObj = Title
::newFromText( $likeVal );
119 if ( $likeObj instanceof Title
) {
120 $like = $dbr->buildLike(
122 strtolower( $likeObj->getDBkey() ),
125 $conds[] = "LOWER(img_name) $like";
132 'join_conds' => $jconds,
134 'options' => $options,
140 function getIndexField() {
141 return 'img_timestamp';
144 function getStartBody() {
145 if ( !$this->gallery
) {
146 // Note that null for mode is taken to mean use default.
147 $mode = $this->getRequest()->getVal( 'gallerymode', null );
149 $this->gallery
= ImageGalleryBase
::factory( $mode, $this->getContext() );
150 } catch ( Exception
$e ) {
151 // User specified something invalid, fallback to default.
152 $this->gallery
= ImageGalleryBase
::factory( false, $this->getContext() );
159 function getEndBody() {
160 return $this->gallery
->toHTML();
163 function formatRow( $row ) {
164 $name = $row->img_name
;
165 $user = User
::newFromId( $row->img_user
);
167 $title = Title
::makeTitle( NS_FILE
, $name );
168 $ul = MediaWikiServices
::getInstance()->getLinkRenderer()->makeLink(
169 $user->getUserPage(),
172 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp
, $this->getUser() );
177 . htmlspecialchars( $time )