jenkins-bot has submitted this change and it was merged.
Change subject: Filter lists by item count
......................................................................
Filter lists by item count
Add minitems parameter to the lists API, which will exclude lists
with less items from the results. Watchlists are not affected by
the presence of this parameter (it would be a lot of work and
there is no strong use case for it).
Bug: T97061
Change-Id: Ic85bcded0216ae2fd457222e379d9bd17f3afc53
---
M i18n/en.json
M i18n/qqq.json
M includes/api/ApiQueryListPages.php
M includes/api/ApiQueryLists.php
A tests/phpunit/api/ApiQueryListsTest.php
M tests/phpunit/api/GatherTestCase.php
6 files changed, 57 insertions(+), 4 deletions(-)
Approvals:
Jdlrobson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/i18n/en.json b/i18n/en.json
index 8dce782..f8e3985 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -139,5 +139,6 @@
"apihelp-query+listpages-paramvalue-dir-descending": "Reversed.",
"apihelp-query+listpages-param-limit": "Limit the number of returned
pages.",
"apihelp-query+listpages-paramvalue-sort-position": "Use manual
ordering.",
- "apihelp-query+listpages-paramvalue-sort-namespace": "Sort by
namespace, title."
+ "apihelp-query+listpages-paramvalue-sort-namespace": "Sort by
namespace, title.",
+ "apihelp-query+lists-param-minitems": "Show only lists which have at
least this many items. (Ignored for watchlists.)"
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index fd8b809..bb3052a 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -145,5 +145,6 @@
"apihelp-query+listpages-paramvalue-dir-descending":
"{{doc-apihelp-paramvalue|lsp|dir|listpages|query+listpages|descending}}",
"apihelp-query+listpages-param-limit":
"{{doc-apihelp-param|lsp|limit|listpages|query+listpages}}",
"apihelp-query+listpages-paramvalue-sort-position":
"{{doc-apihelp-paramvalue|lsp|sort|listpages|query+listpages|sortkey}}",
- "apihelp-query+listpages-paramvalue-sort-namespace":
"{{doc-apihelp-paramvalue|lsp|sort|listpages|query+listpages|namespace}}"
+ "apihelp-query+listpages-paramvalue-sort-namespace":
"{{doc-apihelp-paramvalue|lsp|sort|listpages|query+listpages|namespace}}",
+ "apihelp-query+lists-param-minitems":
"{{doc-apihelp-param|lst|minitems|lists|query+lists}}"
}
diff --git a/includes/api/ApiQueryListPages.php
b/includes/api/ApiQueryListPages.php
index 14b5def..d7e252b 100644
--- a/includes/api/ApiQueryListPages.php
+++ b/includes/api/ApiQueryListPages.php
@@ -35,7 +35,7 @@
use Title;
/**
- * Query module to enumerate all available lists
+ * Query module to enumerate pages in a list
*
* @ingroup API
*/
diff --git a/includes/api/ApiQueryLists.php b/includes/api/ApiQueryLists.php
index 99eda7a..5facdce 100644
--- a/includes/api/ApiQueryLists.php
+++ b/includes/api/ApiQueryLists.php
@@ -159,6 +159,10 @@
$this->addWhere( $db->makeList( $cond, LIST_OR ) );
}
+ if ( $params['minitems'] ) {
+ $this->addWhere( '(gl_label = \'\' OR gl_item_count >=
' . $params['minitems'] . ')' );
+ }
+
if ( $continue ) {
if ( $singleUser ) {
// Single value continue
@@ -382,6 +386,9 @@
'owner',
)
),
+ 'minitems' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
'ids' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => 'integer',
diff --git a/tests/phpunit/api/ApiQueryListsTest.php
b/tests/phpunit/api/ApiQueryListsTest.php
new file mode 100644
index 0000000..74b075f
--- /dev/null
+++ b/tests/phpunit/api/ApiQueryListsTest.php
@@ -0,0 +1,38 @@
+<?php
+
+require_once ( __DIR__ . '/GatherTestCase.php' );
+
+/**
+ * @group API
+ * @group Database
+ * @group medium
+ */
+class ApiQueryListsTest extends GatherTestCase {
+ protected $tablesUsed = array( 'gather_list', 'gather_list_item' );
+
+ public function testMinitems() {
+ $list1 = $this->createList( 'gatherUser', array( 'P1', 'P2' ) );
+ $list2 = $this->createList( 'gatherUser', array( 'P1', 'P2',
'P3' ) );
+ $list3 = $this->createList( 'gatherUser', array( 'P1', 'P2',
'P3', 'P4', 'P5' ) );
+
+ $minitems3 = $this->getListIdsFromResults( $this->doApiRequest(
array(
+ 'action' => 'query',
+ 'list' => 'lists',
+ 'lstminitems' => 3,
+ ) ) );
+ unset( $minitems3[0] ); // we don't care about the watchlist
+ $this->assertArrayEquals( array( $list2, $list3 ), $minitems3 );
+ }
+
+ /**
+ * Returns Gather list IDs from a lists API query result
+ * @param array $ret Return value of doApiRequest()
+ * @return array
+ */
+ protected function getListIdsFromResults( $ret ) {
+ $results = $this->getFromResults( $ret, 'lists' );
+ return array_map( function ( $list ) {
+ return $list['id'];
+ }, $results );
+ }
+}
diff --git a/tests/phpunit/api/GatherTestCase.php
b/tests/phpunit/api/GatherTestCase.php
index 2604bb2..61d7165 100644
--- a/tests/phpunit/api/GatherTestCase.php
+++ b/tests/phpunit/api/GatherTestCase.php
@@ -2,6 +2,7 @@
class GatherTestCase extends ApiTestCase {
private static $gatherUsers = array();
+ private static $listCount = 0;
public function setUp() {
parent::setUp();
@@ -33,10 +34,14 @@
* @return int List ID
*/
protected function createList(
- $user, array $pages = array(), $label = 'New list', array
$properties = array()
+ $user, array $pages = array(), $label = null, array $properties
= array()
) {
if ( is_string( $user ) ) {
$user = static::$users[$user]->getUser();
+ }
+ self::$listCount += 1;
+ if ( $label === null ) { // labels must be unique
+ $label = 'New list ' . self::$listCount;
}
$params = array_merge( array(
@@ -60,6 +65,7 @@
$fullResults = $ret[0];
switch ( $module ) {
case 'tokens':
+ case 'lists':
case 'listpages':
return $fullResults['query'][$module];
case 'editlist':
--
To view, visit https://gerrit.wikimedia.org/r/210885
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic85bcded0216ae2fd457222e379d9bd17f3afc53
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>
Gerrit-Reviewer: Gergő Tisza <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits