Allow filtering by username on Special:NewFiles
authorMatthias Mullie <git@mullie.eu>
Tue, 14 Mar 2017 14:20:06 +0000 (15:20 +0100)
committerMatthias Mullie <mmullie@wikimedia.org>
Tue, 14 Mar 2017 14:38:41 +0000 (14:38 +0000)
Meanwhile, also change ApiQueryAllImages to search by
user ID instead of username. This is also how ContribsPages,
LogPager, ... work already.

This will use the new index on img_user. The old index is still
around, but is likely not going to be used in practice (users
have to logged in to upload)

Do not merge until I4db7bd0f917a428f40eb315246f89d49c7ae5b6a has
been deployed.

Bug: T125071
Bug: T121865
Change-Id: Ida22555f00530f393e739366fa9e79ecabf3c0eb

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 ef6bb6a..0c1648f 100644 (file)
@@ -85,6 +85,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' );
@@ -189,7 +190,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' );
@@ -269,7 +274,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 2816f31..dbdaaa6 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 c3a871f..1f8deb2 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.",