From 62dffe283f4fc791a815ea3c5698caf3d27016f3 Mon Sep 17 00:00:00 2001
From: Darian Anthony Patrick <dpatrick@wikimedia.org>
Date: Tue, 13 Oct 2015 14:25:00 -0700
Subject: [PATCH] Prevent article_recent_contributors leaking revdeleted user
 names

This patch depends on a correspoding patch to core, which has been
attached to the bug listed below.

Bug: T71367
Change-Id: I68d38aaed495016ff2fd0c05bee348fc5477ab23
---
 AbuseFilterVariableHolder.php | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/AbuseFilterVariableHolder.php b/AbuseFilterVariableHolder.php
index 1cb1888..ff3c4d3 100644
--- a/AbuseFilterVariableHolder.php
+++ b/AbuseFilterVariableHolder.php
@@ -502,27 +502,30 @@ class AFComputedVariable {
 				}
 
 				$dbr = wfGetDB( DB_SLAVE );
-				$sqlTmp = $dbr->selectSQLText(
+				$limit = 100;
+				$res = $dbr->select(
 					'revision',
-					array( 'rev_user_text', 'rev_timestamp' ),
+					array( 'rev_id' ),
 					array(
 						'rev_page' => $title->getArticleID(),
 						'rev_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( $cutOff ) )
 					),
 					__METHOD__,
 					// Some pages have < 10 authors but many revisions (e.g. bot pages)
-					array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 100 )
+					array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => $limit )
 				);
-				$res = $dbr->query(
-					"SELECT rev_user_text FROM ($sqlTmp) AS tmp " .
-					"GROUP BY rev_user_text ORDER BY MAX(rev_timestamp) DESC LIMIT 10",
-					__METHOD__
+
+				$from = $res->fetchRow();
+				$res->seek($res->numRows());
+				$to = $res->fetchRow();
+
+				$users = $title->getAuthorsBetween(
+					$from['rev_id'],
+					$to['rev_id'],
+					$limit,
+					array( 'include_both' => true, 'visibility' => Revision::FOR_THIS_USER )
 				);
 
-				$users = array();
-				foreach( $res as $row ) {
-					$users[] = $row->rev_user_text;
-				}
 				$result = $users;
 				break;
 			case 'load-first-author':
-- 
2.3.8 (Apple Git-58)

