[MediaWiki-commits] [Gerrit] Implements prop=listmembership - change (mediawiki...Gather)

2015-05-04 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Implements prop=listmembership
..


Implements prop=listmembership

Usage examples:

Watchlist (lsmid=0 or missing)
* 
http://localhost:8080/w/api.php?action=query&prop=listmembership&titles=Main_Page&lsmid=0

Specific list, e.g. #7
* 
http://localhost:8080/w/api.php?action=query&prop=listmembership&titles=Main_Page&lsmid=7

Obviously because this is a prop, generators can be used:
* 
http://localhost:8080/w/api.php?action=query&prop=listmembership&generator=allpages&lsmid=0

Bug: T95516
Change-Id: I90b6df0c7a9d69460921e9410284c312b3d09d7b
---
M Gather.php
M i18n/en.json
M i18n/qqq.json
A includes/api/ApiMixinListAccess.php
A includes/api/ApiQueryListMembership.php
M includes/api/ApiQueryListPages.php
M tests/phpunit/api/GatherTests.php
7 files changed, 357 insertions(+), 66 deletions(-)

Approvals:
  Yurik: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Gather.php b/Gather.php
index 28eb272..3eff5f6 100644
--- a/Gather.php
+++ b/Gather.php
@@ -67,8 +67,10 @@
'Gather\SpecialGatherLists' => 'specials/SpecialGatherLists',
'Gather\SpecialGatherEditFeed' => 'specials/SpecialGatherEditFeed',
 
+   'Gather\api\ApiMixinListAccess' => 'api/ApiMixinListAccess',
'Gather\api\ApiEditList' => 'api/ApiEditList',
'Gather\api\ApiQueryLists' => 'api/ApiQueryLists',
+   'Gather\api\ApiQueryListMembership' => 'api/ApiQueryListMembership',
'Gather\api\ApiQueryListPages' => 'api/ApiQueryListPages',
 
 );
@@ -104,6 +106,7 @@
 // Api
 $wgAPIModules['editlist'] = 'Gather\api\ApiEditList';
 $wgAPIListModules['lists'] = 'Gather\api\ApiQueryLists';
+$wgAPIPropModules['listmembership'] = 'Gather\api\ApiQueryListMembership';
 $wgAPIListModules['listpages'] = 'Gather\api\ApiQueryListPages';
 
 // Configuration
diff --git a/i18n/en.json b/i18n/en.json
index d98088b..165a5d5 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -116,5 +116,10 @@
"gather-collection-more": "View more pages in this collection",
"gather-add-to-another": "Show my other collections",
"gather-watchstar-button-label": "Add to collection",
-   "gather-menu-guider": "Tap on the menu icon to take a look at your new 
collection."
+   "gather-menu-guider": "Tap on the menu icon to take a look at your new 
collection.",
+   "gather-api-help-param-listid": "List id; omit or set to 0 to use the 
watchlist.",
+   "gather-api-help-param-listowner": "User ID of the list owner. Only 
makes sense for watchlists.",
+   "gather-api-help-param-listtoken": "Watchlist token (see watchlist 
API); required when looking at someone else's watchlist.",
+   "apihelp-query+listmembership-description": "Returns which of a set of 
pages are in a given list.",
+   "apihelp-query+listmembership-example-1": "Check whether \"Page\" is on 
the watchlist."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 4e888b0..4bf22cc 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -118,5 +118,10 @@
"gather-collection-more": "Label for link at bottom of Gather 
collection when there are more than 50 items.",
"gather-add-to-another": "Label for button at bottom of collection 
overlay for when you have more collections that you could potentially add to.",
"gather-watchstar-button-label": "A label for the button to add to a 
collection.",
-   "gather-menu-guider": "Message that shows up in an overlay pointing at 
the menu button."
+   "gather-menu-guider": "Message that shows up in an overlay pointing at 
the menu button.",
+   "gather-api-help-param-listid": 
"{{doc-apihelp-param|lsm|id|listmembership|query+listmembership}}",
+   "gather-api-help-param-listowner": 
"{{doc-apihelp-param|lsm|owner|listmembership|query+listmembership}}",
+   "gather-api-help-param-listtoken": 
"{{doc-apihelp-param|lsm|token|listmembership|query+listmembership}}",
+   "apihelp-query+listmembership-description": 
"{{doc-apihelp-description|lsm|listmembership|query+listmembership}}",
+   "apihelp-query+listmembership-example-1": 
"{{doc-apihelp-example|lsm|listmembership|query+listmembership}}"
 }
diff --git a/includes/api/ApiMixinListAccess.php 
b/includes/api/ApiMixinListAccess.php
new file mode 100644
index 000..ddea2dc
--- /dev/null
+++ b/includes/api/ApiMixinListAccess.php
@@ -0,0 +1,123 @@
+@gmail.com",
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Y

[MediaWiki-commits] [Gerrit] Implements prop=listmembership - change (mediawiki...Gather)

2015-04-09 Thread Yurik (Code Review)
Yurik has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/203003

Change subject: Implements prop=listmembership
..

Implements prop=listmembership

Code-complete alpha code, might need more debugging, my vagrat broke

Bug: T95516
Change-Id: I90b6df0c7a9d69460921e9410284c312b3d09d7b
---
M Gather.php
A includes/api/ApiQueryListMembership.php
M includes/api/ApiQueryListPages.php
A includes/api/ApiShared.php
4 files changed, 260 insertions(+), 62 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather 
refs/changes/03/203003/1

diff --git a/Gather.php b/Gather.php
index b506820..37b7cbc 100644
--- a/Gather.php
+++ b/Gather.php
@@ -63,8 +63,10 @@
'Gather\SpecialGatherLists' => 'specials/SpecialGatherLists',
'Gather\SpecialGatherEditFeed' => 'specials/SpecialGatherEditFeed',
 
+   'Gather\api\ApiShared' => 'api/ApiShared',
'Gather\api\ApiEditList' => 'api/ApiEditList',
'Gather\api\ApiQueryLists' => 'api/ApiQueryLists',
+   'Gather\api\ApiQueryListMembership' => 'api/ApiQueryListMembership',
'Gather\api\ApiQueryListPages' => 'api/ApiQueryListPages',
 
 );
@@ -95,6 +97,7 @@
 // Api
 $wgAPIModules['editlist'] = 'Gather\api\ApiEditList';
 $wgAPIListModules['lists'] = 'Gather\api\ApiQueryLists';
+$wgAPIPropModules['listmembership'] = 'Gather\api\ApiQueryListMembership';
 $wgAPIListModules['listpages'] = 'Gather\api\ApiQueryListPages';
 
 // Configuration
diff --git a/includes/api/ApiQueryListMembership.php 
b/includes/api/ApiQueryListMembership.php
new file mode 100644
index 000..780278f
--- /dev/null
+++ b/includes/api/ApiQueryListMembership.php
@@ -0,0 +1,136 @@
+@gmail.com",
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+namespace Gather\api;
+
+use ApiQueryBase;
+use ApiQuery;
+use LinkBatch;
+use ApiBase;
+
+/**
+ * A query prop module to show if pages belong to a specific list
+ *
+ * @ingroup API
+ */
+class ApiQueryListMembership extends ApiQueryBase {
+
+   public function __construct( ApiQuery $query, $moduleName ) {
+   parent::__construct( $query, $moduleName, 'lsm' );
+   }
+
+   public function execute() {
+   $titles = $this->getPageSet()->getGoodAndMissingTitles();
+   $titleLookup = 
$this->getPageSet()->getGoodAndMissingTitlesByNamespace();
+
+   if ( !count( $titles ) ) {
+   # Nothing to do
+   return;
+   }
+
+   $params = $this->extractRequestParams();
+
+   $db = $this->getDB();
+
+   $userId = ApiShared::checkListAccess( $this->getDB(), $this, 
$params );
+
+   if ( $userId !== 0 ) {
+   // This is a watchlist
+   $pfx = 'wl';
+   $this->selectNamedDB( 'watchlist', DB_SLAVE, 
'watchlist' );
+   $db = $this->getDB(); // TODO: selectNamedDB should 
return this value
+   $this->addTables( 'watchlist' );
+   $this->addWhereFld( 'wl_user', $userId );
+   } else {
+   // This is a gather list
+   $pfx = 'gli';
+   $this->addTables( 'gather_list_item' );
+   $this->addWhereFld( 'gli_gl_id', $params['id'] );
+   }
+
+   $this->addFields( array( 'ns' => "{$pfx}_namespace", 'title' => 
"{$pfx}_title" ) );
+
+   $lb = new LinkBatch( $titles );
+   $this->addWhere( $lb->constructSet( $pfx, $db ) );
+
+   if ( $params['continue'] !== null ) {
+   $cont = explode( '|', $params['continue'] );
+   $this->dieContinueUsageIf( count( $cont ) != 2 );
+   $contNs = intval( $cont[0] );
+   $this->dieContinueUsageIf( strval( $contNs ) !== 
$cont[0] );
+   $contTitle = $db->addQuotes( $cont[1] );
+   $this->addWhere( "{$pfx}_namespace > $contNs OR " . 
"({$pfx}_namespace = $contNs AND " .
+"{$pfx}_title >= 
$contTitl