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\Linker\LinkRenderer
;
26 use MediaWiki\MediaWikiServices
;
28 class NewFilesPager
extends RangeChronologicalPager
{
31 * @var ImageGalleryBase
41 * @param IContextSource $context
42 * @param FormOptions $opts
43 * @param LinkRenderer $linkRenderer
45 public function __construct( IContextSource
$context, FormOptions
$opts,
46 LinkRenderer
$linkRenderer
48 parent
::__construct( $context, $linkRenderer );
51 $this->setLimit( $opts->getValue( 'limit' ) );
55 if ( $opts->getValue( 'start' ) ) {
56 $startTimestamp = $opts->getValue( 'start' ) . ' 00:00:00';
58 if ( $opts->getValue( 'end' ) ) {
59 $endTimestamp = $opts->getValue( 'end' ) . ' 23:59:59';
61 $this->getDateRangeCond( $startTimestamp, $endTimestamp );
64 function getQueryInfo() {
67 $actorQuery = ActorMigration
::newMigration()->getJoin( 'img_user' );
68 $tables = [ 'image' ] +
$actorQuery['tables'];
69 $fields = [ 'img_name', 'img_timestamp' ] +
$actorQuery['fields'];
71 $jconds = $actorQuery['joins'];
73 $user = $opts->getValue( 'user' );
75 $conds[] = ActorMigration
::newMigration()
76 ->getWhere( wfGetDB( DB_REPLICA
), 'img_user', User
::newFromName( $user, false ) )['conds'];
79 if ( !$opts->getValue( 'showbots' ) ) {
80 $groupsWithBotPermission = MediaWikiServices
::getInstance()
81 ->getPermissionManager()
82 ->getGroupsWithPermission( 'bot' );
84 if ( count( $groupsWithBotPermission ) ) {
85 $dbr = wfGetDB( DB_REPLICA
);
86 $tables[] = 'user_groups';
87 $conds[] = 'ug_group IS NULL';
88 $jconds['user_groups'] = [
91 'ug_group' => $groupsWithBotPermission,
92 'ug_user = ' . $actorQuery['fields']['img_user'],
93 'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
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
;
106 $jconds['recentchanges'] = [
109 'rc_title = img_name',
110 'rc_actor = ' . $actorQuery['fields']['img_actor'],
111 'rc_timestamp = img_timestamp'
114 // We're ordering by img_timestamp, so we have to make sure MariaDB queries `image` first.
115 // It sometimes decides to query `recentchanges` first and filesort the result set later
116 // to get the right ordering. T124205 / https://mariadb.atlassian.net/browse/MDEV-8880
117 $options[] = 'STRAIGHT_JOIN';
120 if ( $opts->getValue( 'mediatype' ) ) {
121 $conds['img_media_type'] = $opts->getValue( 'mediatype' );
124 $likeVal = $opts->getValue( 'like' );
125 if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
126 $dbr = wfGetDB( DB_REPLICA
);
127 $likeObj = Title
::newFromText( $likeVal );
128 if ( $likeObj instanceof Title
) {
129 $like = $dbr->buildLike(
131 strtolower( $likeObj->getDBkey() ),
134 $conds[] = "LOWER(img_name) $like";
141 'join_conds' => $jconds,
143 'options' => $options,
149 function getIndexField() {
150 return 'img_timestamp';
153 protected function getStartBody() {
154 if ( !$this->gallery
) {
155 // Note that null for mode is taken to mean use default.
156 $mode = $this->getRequest()->getVal( 'gallerymode', null );
158 $this->gallery
= ImageGalleryBase
::factory( $mode, $this->getContext() );
159 } catch ( Exception
$e ) {
160 // User specified something invalid, fallback to default.
161 $this->gallery
= ImageGalleryBase
::factory( false, $this->getContext() );
168 protected function getEndBody() {
169 return $this->gallery
->toHTML();
172 function formatRow( $row ) {
173 $name = $row->img_name
;
174 $user = User
::newFromId( $row->img_user
);
176 $title = Title
::makeTitle( NS_FILE
, $name );
177 $ul = $this->getLinkRenderer()->makeLink(
178 $user->getUserPage(),
181 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp
, $this->getUser() );
186 . htmlspecialchars( $time )