Jhernandez has uploaded a new change for review.

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

Change subject: Collection::newFromApi Make user optional
......................................................................

Collection::newFromApi Make user optional

User passed in wasn't being used, so make it optional, and actually use it if
passed in for validating the collection.

For getting the collection the id is enough since they are globally unique.

Change-Id: Ic82604ea6b43fa8048fbb706303df9c6bbbddbf5
---
M includes/models/Collection.php
1 file changed, 16 insertions(+), 7 deletions(-)


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

diff --git a/includes/models/Collection.php b/includes/models/Collection.php
index 361fbf8..b688c68 100644
--- a/includes/models/Collection.php
+++ b/includes/models/Collection.php
@@ -118,18 +118,20 @@
        }
 
        /**
-        * Generate UserPageCollectionsList from api result
+        * Generate a Collection from api result
         * @param Integer $id the id of the collection
-        * @param User $user collection list owner (currently unused)
+        * @param User $user optional collection list owner (if present will be
+        * included in the query and validated)
         * @return models\Collections a collection
         */
-       public static function newFromApi( $id, User $user ) {
+       public static function newFromApi( $id, User $user = null ) {
+
                $collection = null;
-               $api = new ApiMain( new FauxRequest( array(
+               $params = array(
                        'action' => 'query',
                        'list' => 'lists',
                        'lstids' => $id,
-                       'lstprop' => 'label|description|public|image',
+                       'lstprop' => 'label|description|public|image|owner',
                        'prop' => 'pageimages|extracts',
                        'generator' => 'listpages',
                        'glspid' => $id,
@@ -141,7 +143,13 @@
                        'pilimit' => 50,
                        // TODO: Pagination
                        'continue' => '',
-               ) ) );
+               );
+               // If user is present, include it in the request. Api will 
return not found
+               // if the specified owner doesn't match the actual collection 
owner.
+               if ( $user ) {
+                       $params['lstowner'] = $user->getName();
+               }
+               $api = new ApiMain( new FauxRequest( $params ) );
 
                try {
                        $api->execute();
@@ -151,7 +159,8 @@
                                if ( count( $lists ) === 1 ) {
                                        $list = $lists[0];
                                        $image = $list['image'] ? wfFindFile( 
$list['image'] ) : null;
-                                       $collection = new Collection( $id, 
$user, $list['label'], $list['description'],
+                                       $owner = User::newFromName( 
$list['owner'] );
+                                       $collection = new Collection( $id, 
$owner, $list['label'], $list['description'],
                                                $list['public'], $image );
                                }
                        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic82604ea6b43fa8048fbb706303df9c6bbbddbf5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <jhernan...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to