From de36abea5f00fa31abf3d78909661b6efae81343 Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Tue, 14 Mar 2017 15:20:06 +0100 Subject: [PATCH] Allow filtering by username on Special:NewFiles 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 | 13 +++++++++++-- includes/specials/SpecialNewimages.php | 7 +++++++ includes/specials/pagers/ImageListPager.php | 3 ++- includes/specials/pagers/NewFilesPager.php | 10 ++++++++++ languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + 6 files changed, 32 insertions(+), 3 deletions(-) diff --git a/includes/api/ApiQueryAllImages.php b/includes/api/ApiQueryAllImages.php index ef6bb6ad99..0c1648f9a5 100644 --- a/includes/api/ApiQueryAllImages.php +++ b/includes/api/ApiQueryAllImages.php @@ -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' ] ); } diff --git a/includes/specials/SpecialNewimages.php b/includes/specials/SpecialNewimages.php index 9e3a7509bc..12dae8b8db 100644 --- a/includes/specials/SpecialNewimages.php +++ b/includes/specials/SpecialNewimages.php @@ -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', diff --git a/includes/specials/pagers/ImageListPager.php b/includes/specials/pagers/ImageListPager.php index 3789dfa6e8..47b059b765 100644 --- a/includes/specials/pagers/ImageListPager.php +++ b/includes/specials/pagers/ImageListPager.php @@ -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 diff --git a/includes/specials/pagers/NewFilesPager.php b/includes/specials/pagers/NewFilesPager.php index 4bf5dff667..b78193002a 100644 --- a/includes/specials/pagers/NewFilesPager.php +++ b/includes/specials/pagers/NewFilesPager.php @@ -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' ); diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 2816f310cb..dbdaaa67e4 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3001,6 +3001,7 @@ "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.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index c3a871f881..1f8deb212e 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3188,6 +3188,7 @@ "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.", -- 2.20.1