@@ -122,6 +122,16 @@ public function getTopEditsNamespace(
122122 LIMIT 1
123123 ) AS pa_class "
124124 : '' ;
125+ $ paProjectsTable = $ project ->getTableName ('page_assessments_projects ' );
126+ $ paProjectsSelect = $ hasPageAssessments
127+ ? ", (
128+ SELECT JSON_ARRAYAGG(pap_project_title)
129+ FROM $ paTable
130+ JOIN $ paProjectsTable
131+ ON pa_project_id = pap_project_id
132+ WHERE pa_page_id = page_id
133+ ) AS pap_project_title "
134+ : '' ;
125135
126136 $ ipcJoin = '' ;
127137 $ whereClause = 'rev_actor = :actorId ' ;
@@ -137,7 +147,9 @@ public function getTopEditsNamespace(
137147 $ sql = "SELECT page_namespace AS `namespace`, page_title,
138148 page_is_redirect AS `redirect`, COUNT(page_title) AS `count`
139149 $ paSelect
150+ $ paProjectsSelect
140151 FROM $ pageTable
152+
141153 JOIN $ revisionTable ON page_id = rev_page
142154 $ ipcJoin
143155 WHERE $ whereClause
@@ -200,6 +212,66 @@ public function countEditsNamespace(Project $project, User $user, $namespace, $s
200212 return $ this ->setCache ($ cacheKey , $ resultQuery ->fetchOne ());
201213 }
202214
215+ /**
216+ * Get the 10 Wikiprojects within which the user has the most edits.
217+ * @param Project $project
218+ * @param User $user
219+ * @param int $ns
220+ * @param int|false $start
221+ * @param int|false $end
222+ */
223+ public function getProjectTotals (
224+ Project $ project ,
225+ User $ user ,
226+ int $ ns ,
227+ $ start = false ,
228+ $ end = false
229+ ): array {
230+ $ cacheKey = $ this ->getCacheKey (func_get_args (), 'top_edits_wikiprojects ' );
231+ if ($ this ->cache ->hasItem ($ cacheKey )) {
232+ return $ this ->cache ->getItem ($ cacheKey )->get ();
233+ }
234+
235+ $ revDateConditions = $ this ->getDateConditions ($ start , $ end );
236+ $ pageTable = $ project ->getTableName ('page ' );
237+ $ revisionTable = $ project ->getTableName ('revision ' );
238+ $ pageAssessmentsTable = $ project ->getTableName ('page_assessments ' );
239+ $ paProjectsTable = $ project ->getTableName ('page_assessments_projects ' );
240+
241+ $ ipcJoin = '' ;
242+ $ whereClause = 'rev_actor = :actorId ' ;
243+ $ params = [];
244+ if ($ user ->isIpRange ()) {
245+ $ ipcTable = $ project ->getTableName ('ip_changes ' );
246+ $ ipcJoin = "JOIN $ ipcTable ON rev_id = ipc_rev_id " ;
247+ $ whereClause = 'ipc_hex BETWEEN :startIp AND :endIp ' ;
248+ [$ params ['startIp ' ], $ params ['endIp ' ]] = IPUtils::parseRange ($ user ->getUsername ());
249+ }
250+
251+ $ sql = "SELECT pap_project_title, SUM(`edit_count`) AS `count`
252+ FROM (
253+ SELECT page_id, COUNT(page_id) AS `edit_count`
254+ FROM $ revisionTable
255+ $ ipcJoin
256+ JOIN $ pageTable ON page_id = rev_page
257+ WHERE $ whereClause
258+ AND page_namespace = :namespace
259+ $ revDateConditions
260+ GROUP BY page_id
261+ ) a
262+ JOIN $ pageAssessmentsTable ON pa_page_id = page_id
263+ JOIN $ paProjectsTable ON pa_project_id = pap_project_id
264+ GROUP BY pap_project_title
265+ ORDER BY `count` DESC
266+ LIMIT 10 " ;
267+
268+ $ totals = $ this ->executeQuery ($ sql , $ project , $ user , $ ns )
269+ ->fetchAllAssociative ();
270+
271+ // Cache and return.
272+ return $ this ->setCache ($ cacheKey , $ totals );
273+ }
274+
203275 /**
204276 * Get the top edits by a user across all namespaces.
205277 * @param Project $project
@@ -236,6 +308,17 @@ public function getTopEditsAllNamespaces(
236308 LIMIT 1
237309 ) AS pa_class "
238310 : '' ;
311+ $ paProjectsTable = $ project ->getTableName ('page_assessments_projects ' );
312+ $ paProjectsSelect = $ hasPageAssessments
313+ ? ", (
314+ SELECT JSON_ARRAYAGG(pap_project_title)
315+ FROM $ pageAssessmentsTable
316+ JOIN $ paProjectsTable
317+ ON pa_project_id = pap_project_id
318+ WHERE pa_page_id = e.page_id
319+ ) AS pap_project_title "
320+ : '' ;
321+
239322
240323 $ ipcJoin = '' ;
241324 $ whereClause = 'rev_actor = :actorId ' ;
@@ -248,7 +331,7 @@ public function getTopEditsAllNamespaces(
248331 }
249332
250333 $ sql = "SELECT c.page_namespace AS `namespace`, e.page_title,
251- c.page_is_redirect AS `redirect`, c.count $ paSelect
334+ c.page_is_redirect AS `redirect`, c.count $ paSelect $ paProjectsSelect
252335 FROM
253336 (
254337 SELECT b.page_namespace, b.page_is_redirect, b.rev_page, b.count
0 commit comments