Jdlrobson has uploaded a new change for review.

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

Change subject: Hygiene: Generalise API query in preparation for future work.
......................................................................

Hygiene: Generalise API query in preparation for future work.

Changes:
* Clarify this is not fit for production and will need a rewrite
* Drop unnecessary List and Api from name
* Create ACTION_LIST constant

Change-Id: I63c646ac6a44b5be285cf9dd53cb7a0da8194f6f
---
M Gather.php
M extension.json
R includes/api/ApiGather.php
3 files changed, 31 insertions(+), 20 deletions(-)


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

diff --git a/Gather.php b/Gather.php
index 64f74e8..5a9979c 100644
--- a/Gather.php
+++ b/Gather.php
@@ -63,7 +63,7 @@
 
        'Gather\SpecialGather' => 'specials/SpecialGather',
 
-       'Gather\api\CollectionsListApi' => 'api/CollectionsListApi',
+       'Gather\api\ApiGather' => 'api/ApiGather',
 
 );
 
@@ -83,7 +83,7 @@
 $wgHooks['SkinMinervaDefaultModules'][] = 
'Gather\Hooks::onSkinMinervaDefaultModules';
 
 // Api
-$wgAPIModules['gather'] = 'Gather\api\CollectionsListApi';
+$wgAPIModules['gather'] = 'Gather\api\ApiGather';
 
 // ResourceLoader modules
 require_once __DIR__ . "/resources/Resources.php";
diff --git a/extension.json b/extension.json
index f4b2aea..18cedff 100644
--- a/extension.json
+++ b/extension.json
@@ -47,7 +47,7 @@
                "Gather\\views\\CollectionsListItemCard": 
"includes/views/CollectionsListItemCard.php",
                "Gather\\views\\helpers\\CSS": "includes/views/helpers/CSS.php",
                "Gather\\SpecialGather": "includes/specials/SpecialGather.php",
-               "Gather\\api\\CollectionsListApi": 
"includes/api/CollectionsListApi.php"
+               "Gather\\api\\ApiGather": "includes/api/ApiGather.php"
        },
        "ResourceModules": {
                "ext.gather.icons": {
diff --git a/includes/api/CollectionsListApi.php b/includes/api/ApiGather.php
similarity index 66%
rename from includes/api/CollectionsListApi.php
rename to includes/api/ApiGather.php
index b4d86a9..bc1a122 100644
--- a/includes/api/CollectionsListApi.php
+++ b/includes/api/ApiGather.php
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * CollectionsListApi.php
+ * api\Gather.php
  */
 
 namespace Gather\api;
@@ -11,8 +11,10 @@
 use ApiBase;
 use User;
 
-// FIXME: ApiQueryGeneratorBase should be used here in future.
-class CollectionsListApi extends ApiBase {
+// FIXME: Rewrite before productionising.
+class ApiGather extends ApiBase {
+       const ACTION_LIST = 'list';
+
        /**
         * Execute the requested api actions
         */
@@ -22,19 +24,28 @@
                $action = $params['gather'];
 
                // Get the list of collections for a user
-               if ( $action === 'list' ) {
-                       // If an owner wasn't specified, then get the 
collections of the current user
-                       $owner = isset( $params['owner'] ) ?
-                               User::newFromName( $params['owner'] ) : 
$this->getUser();
-                       // If the name is invalid – it contains illegal 
characters then this'll return false
-                       if ( $owner !== false ) {
-                               $collections = $this->getCollectionsList( 
$owner );
-                               $res = array();
-                               foreach ( $collections as $collection ) {
-                                       $res[] = $collection->toArray();
-                               }
-                               $this->addResult( $res, 'collection' );
+               if ( $action === self::ACTION_LIST ) {
+                       $this->listCollections( $params );
+               }
+       }
+
+       /**
+        * Runs the list query.
+        * FIXME: Before productionising should be moved into separate API 
Query module.
+        * @param array $params
+        */
+       private function listCollections( $params ) {
+               // If an owner wasn't specified, then get the collections of 
the current user
+               $owner = isset( $params[self::PARAM_OWNER] ) ?
+                       User::newFromName( $params[self::PARAM_OWNER] ) : 
$this->getUser();
+               // If the name is invalid – it contains illegal characters then 
this'll return false
+               if ( $owner !== false ) {
+                       $collections = $this->getCollectionsList( $owner );
+                       $res = array();
+                       foreach ( $collections as $collection ) {
+                               $res[] = $collection->toArray();
                        }
+                       $this->addResult( $res, 'collection' );
                }
        }
 
@@ -89,9 +100,9 @@
        public function getAllowedParams() {
                return array(
                        'gather' => array(
-                               ApiBase::PARAM_DFLT => 'list',
+                               ApiBase::PARAM_DFLT => self::ACTION_LIST,
                                ApiBase::PARAM_TYPE => array(
-                                       'list'
+                                       self::ACTION_LIST,
                                )
                        ),
                        'owner' => array(

-- 
To view, visit https://gerrit.wikimedia.org/r/194415
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I63c646ac6a44b5be285cf9dd53cb7a0da8194f6f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to