jenkins-bot has submitted this change and it was merged. Change subject: Create Special:Gather/<user>/<id> via api ......................................................................
Create Special:Gather/<user>/<id> via api Note: This patch: * Disables access of user other than yourself. * Page image currently not working on collection Bug: T92418 Change-Id: I8a2a3e4400f1431f472abcf8e56ec7b51571e91b --- M includes/Gather.hooks.php M includes/models/Collection.php M includes/specials/SpecialGather.php 3 files changed, 67 insertions(+), 3 deletions(-) Approvals: Robmoen: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/Gather.hooks.php b/includes/Gather.hooks.php index 0cba4b5..1789a2d 100644 --- a/includes/Gather.hooks.php +++ b/includes/Gather.hooks.php @@ -135,7 +135,7 @@ $gatherCollections = array(); foreach ( $collectionsList as $collectionInfo ) { $id = $collectionInfo->getId(); - $collection = stores\UserPageCollection::newFromUserAndId( $user, $id ); + $collection = models\Collection::newFromApi( $id, $user ); if ( $collection !== null ) { $gatherCollections[] = array( 'id' => $id, diff --git a/includes/models/Collection.php b/includes/models/Collection.php index c752f9f..8ef87c2 100644 --- a/includes/models/Collection.php +++ b/includes/models/Collection.php @@ -9,12 +9,15 @@ use \IteratorAggregate; use \ArrayIterator; use \User; +use \ApiMain; +use \FauxRequest; +use \Gather\stores\ItemExtracts; +use \Title; /** * A collection with a list of items, which are represented by the CollectionItem class. */ class Collection extends CollectionBase implements IteratorAggregate { - /** * The internal collection of items. * @@ -92,4 +95,60 @@ } return $data; } + + /** + * Generate UserPageCollectionsList from api result + * @param Integer $id the id of the collection + * @param User $user collection list owner (currently unused) + * @return models\Collections a collection + */ + public static function newFromApi( $id, User $user ) { + // Work out meta data for this collection + $cl = CollectionsList::newFromApi( $user ); + $collection = null; + foreach ( $cl as $c ) { + if ( $c->getId() === $id ) { + $collection = self::newFromCollectionInfo( $c ); + } + } + if ( $collection ) { + $api = new ApiMain( new FauxRequest( array( + 'action' => 'query', + 'prop' => 'pageimages|extracts', + 'generator' => 'listpages', + 'glspid' => $id, + 'explaintext' => true, + 'exintro' => true, + 'exchars' => ItemExtracts::CHAR_LIMIT, + 'exlimit' => 50, + ) ) ); + try { + $api->execute(); + $data = $api->getResultData(); + if ( isset( $data['query']['pages'] ) ) { + $pages = $data['query']['pages']; + foreach ( $pages as $page ) { + $title = Title::newFromText( $page['title'], $page['ns'] ); + // FIXME: Make use of the page image + $pi = false; + $extract = isset( $page['extract'][0] ) ? $page['extract'][0] : ''; + $collection->add( new CollectionItem( $title, $pi, $extract ) ); + } + } + } catch ( Exception $e ) { + // just return collection + } + } + + return $collection; + } + + /** + * @param CollectionInfo $info + * @return models\Collection + */ + public static function newFromCollectionInfo( $info ) { + return new Collection( $info->getId(), $info->getOwner(), + $info->getTitle(), $info->getDescription(), $info->isPublic(), $info->getFile()); + } } diff --git a/includes/specials/SpecialGather.php b/includes/specials/SpecialGather.php index dfdd0c4..b141559 100644 --- a/includes/specials/SpecialGather.php +++ b/includes/specials/SpecialGather.php @@ -84,7 +84,12 @@ * @param int $id collection id */ public function renderUserCollection( User $user, $id ) { - $collection = stores\UserPageCollection::newFromUserAndId( $user, $id ); + $collection = null; + // FIXME: It should be possible to view public lists by other user. Limitation with API stops this. + if ( $this->isOwner( $user ) ) { + $collection = models\Collection::newFromApi( $id, $user ); + } + if ( $collection === null || ( !$collection->isPublic() && !$this->isOwner( $user ) ) ) { // FIXME: No permissions to visit this. Showing not found ATM. -- To view, visit https://gerrit.wikimedia.org/r/195965 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I8a2a3e4400f1431f472abcf8e56ec7b51571e91b Gerrit-PatchSet: 10 Gerrit-Project: mediawiki/extensions/Gather Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Jhernandez <jhernan...@wikimedia.org> Gerrit-Reviewer: Robmoen <rm...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits