Merge "Allow filtering by username on Special:NewFiles"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 29 Mar 2017 14:11:40 +0000 (14:11 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 29 Mar 2017 14:11:40 +0000 (14:11 +0000)
includes/api/ApiQueryAllImages.php
includes/specials/SpecialNewimages.php
includes/specials/pagers/ImageListPager.php
includes/specials/pagers/NewFilesPager.php
languages/i18n/en.json
languages/i18n/qqq.json

index a40511c..8ce122c 100644 (file)
@@ -87,6 +87,7 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
                $db = $this->getDB();
 
                $params = $this->extractRequestParams();
+               $userId = !is_null( $params['user'] ) ? User::idFromName( $params['user'] ) : null;
 
                // Table and return fields
                $this->addTables( 'image' );
@@ -191,7 +192,11 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
 
                        // Image filters
                        if ( !is_null( $params['user'] ) ) {
-                               $this->addWhereFld( 'img_user_text', $params['user'] );
+                               if ( $userId ) {
+                                       $this->addWhereFld( 'img_user', $userId );
+                               } else {
+                                       $this->addWhereFld( 'img_user_text', $params['user'] );
+                               }
                        }
                        if ( $params['filterbots'] != 'all' ) {
                                $this->addTables( 'user_groups' );
@@ -271,7 +276,11 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
                if ( $params['sort'] == 'timestamp' ) {
                        $this->addOption( 'ORDER BY', 'img_timestamp' . $sortFlag );
                        if ( !is_null( $params['user'] ) ) {
-                               $this->addOption( 'USE INDEX', [ 'image' => 'img_usertext_timestamp' ] );
+                               if ( $userId ) {
+                                       $this->addOption( 'USE INDEX', [ 'image' => 'img_user_timestamp' ] );
+                               } else {
+                                       $this->addOption( 'USE INDEX', [ 'image' => 'img_usertext_timestamp' ] );
+                               }
                        } else {
                                $this->addOption( 'USE INDEX', [ 'image' => 'img_timestamp' ] );
                        }
index 9e3a750..12dae8b 100644 (file)
@@ -39,6 +39,7 @@ class SpecialNewFiles extends IncludableSpecialPage {
                $opts = new FormOptions();
 
                $opts->add( 'like', '' );
+               $opts->add( 'user', '' );
                $opts->add( 'showbots', false );
                $opts->add( 'hidepatrolled', false );
                $opts->add( 'limit', 50 );
@@ -75,6 +76,12 @@ class SpecialNewFiles extends IncludableSpecialPage {
                                'name' => 'like',
                        ],
 
+                       'user' => [
+                               'type' => 'text',
+                               'label-message' => 'newimages-user',
+                               'name' => 'user',
+                       ],
+
                        'showbots' => [
                                'type' => 'check',
                                'label-message' => 'newimages-showbots',
index 3789dfa..47b059b 100644 (file)
@@ -193,7 +193,8 @@ class ImageListPager extends TablePager {
                }
                $sortable = [ 'img_timestamp', 'img_name', 'img_size' ];
                /* For reference, the indicies we can use for sorting are:
-                * On the image table: img_usertext_timestamp, img_size, img_timestamp
+                * On the image table: img_user_timestamp, img_usertext_timestamp,
+                * img_size, img_timestamp
                 * On oldimage: oi_usertext_timestamp, oi_name_timestamp
                 *
                 * In particular that means we cannot sort by timestamp when not filtering
index 4bf5dff..b781930 100644 (file)
@@ -55,6 +55,16 @@ class NewFilesPager extends ReverseChronologicalPager {
                $fields = [ 'img_name', 'img_user', 'img_timestamp' ];
                $options = [];
 
+               $user = $opts->getValue( 'user' );
+               if ( $user !== '' ) {
+                       $userId = User::idFromName( $user );
+                       if ( $userId ) {
+                               $conds['img_user'] = $userId;
+                       } else {
+                               $conds['img_user_text'] = $user;
+                       }
+               }
+
                if ( !$opts->getValue( 'showbots' ) ) {
                        $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
 
index 0c8bf21..1cd4391 100644 (file)
        "newimages-summary": "This special page shows the last uploaded files.",
        "newimages-legend": "Filter",
        "newimages-label": "Filename (or a part of it):",
+       "newimages-user": "IP address or username",
        "newimages-showbots": "Show uploads by bots",
        "newimages-hidepatrolled": "Hide patrolled uploads",
        "noimages": "Nothing to see.",
index 2951a4c..d1e6f08 100644 (file)
        "newimages-summary": "This message is displayed at the top of [[Special:NewImages]] to explain what is shown on that special page.",
        "newimages-legend": "Caption of the fieldset for the filter on [[Special:NewImages]]\n\n{{Identical|Filter}}",
        "newimages-label": "Caption of the filter editbox on [[Special:NewImages]]",
+       "newimages-user": "Caption of the username/IP address editbox on [[Special:NewImages]]",
        "newimages-showbots": "Used as label for a checkbox. When checked, [[Special:NewImages]] will also display uploads by users in the bots group.",
        "newimages-hidepatrolled": "Used as label for a checkbox. When checked, [[Special:NewImages]] will not display patrolled uploads.\n\nCf. {{msg-mw|tog-hidepatrolled}} and {{msg-mw|apihelp-feedrecentchanges-param-hidepatrolled}}.",
        "noimages": "This is shown on the special page [[Special:NewImages]], when there aren't any recently uploaded files.",