Merge "Special:Newpages feed now shows first revision instead of latest revision"
[lhc/web/wiklou.git] / includes / specials / pagers / NewFilesPager.php
index b781930..001c296 100644 (file)
@@ -24,7 +24,7 @@
  */
 use MediaWiki\MediaWikiServices;
 
-class NewFilesPager extends ReverseChronologicalPager {
+class NewFilesPager extends RangeChronologicalPager {
 
        /**
         * @var ImageGalleryBase
@@ -41,11 +41,20 @@ class NewFilesPager extends ReverseChronologicalPager {
         * @param FormOptions $opts
         */
        function __construct( IContextSource $context, FormOptions $opts ) {
-               $this->opts = $opts;
+               parent::__construct( $context );
 
+               $this->opts = $opts;
                $this->setLimit( $opts->getValue( 'limit' ) );
 
-               parent::__construct( $context );
+               $startTimestamp = '';
+               $endTimestamp = '';
+               if ( $opts->getValue( 'start' ) ) {
+                       $startTimestamp = $opts->getValue( 'start' ) . ' 00:00:00';
+               }
+               if ( $opts->getValue( 'end' ) ) {
+                       $endTimestamp = $opts->getValue( 'end' ) . ' 23:59:59';
+               }
+               $this->getDateRangeCond( $startTimestamp, $endTimestamp );
        }
 
        function getQueryInfo() {
@@ -65,6 +74,20 @@ class NewFilesPager extends ReverseChronologicalPager {
                        }
                }
 
+               if ( $opts->getValue( 'newbies' ) ) {
+                       // newbie = most recent 1% of users
+                       $dbr = wfGetDB( DB_REPLICA );
+                       $max = $dbr->selectField( 'user', 'max(user_id)', false, __METHOD__ );
+                       $conds[] = 'img_user >' . (int)( $max - $max / 100 );
+
+                       // there's no point in looking for new user activity in a far past;
+                       // beyond a certain point, we'd just end up scanning the rest of the
+                       // table even though the users we're looking for didn't yet exist...
+                       // see T140537, (for ContribsPages, but similar to this)
+                       $conds[] = 'img_timestamp > ' .
+                               $dbr->addQuotes( $dbr->timestamp( wfTimestamp() - 30 * 24 * 60 * 60 ) );
+               }
+
                if ( !$opts->getValue( 'showbots' ) ) {
                        $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
 
@@ -77,9 +100,7 @@ class NewFilesPager extends ReverseChronologicalPager {
                                        [
                                                'ug_group' => $groupsWithBotPermission,
                                                'ug_user = img_user',
-                                               $this->getConfig()->get( 'DisableUserGroupExpiry' ) ?
-                                                       '1' :
-                                                       'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
+                                               'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
                                        ]
                                ];
                        }
@@ -105,6 +126,10 @@ class NewFilesPager extends ReverseChronologicalPager {
                        $options[] = 'STRAIGHT_JOIN';
                }
 
+               if ( $opts->getValue( 'mediatype' ) ) {
+                       $conds['img_media_type'] = $opts->getValue( 'mediatype' );
+               }
+
                $likeVal = $opts->getValue( 'like' );
                if ( !$this->getConfig()->get( 'MiserMode' ) && $likeVal !== '' ) {
                        $dbr = wfGetDB( DB_REPLICA );