Jhernandez has uploaded a new change for review. https://gerrit.wikimedia.org/r/189948
Change subject: Add text extracts support for collection items. ...................................................................... Add text extracts support for collection items. https://trello.com/c/EjeXwekz/5-3-show-extracts-in-collections-page Change-Id: I73401aad1ddbfcd41428967626946083985c26e5 --- M Gather.php M includes/models/CollectionItem.php A includes/stores/ItemExtractsStore.php M includes/stores/WatchlistCollectionStore.php M includes/views/CollectionItemCardView.php 5 files changed, 61 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather refs/changes/48/189948/1 diff --git a/Gather.php b/Gather.php index a8d5be0..74fc22d 100644 --- a/Gather.php +++ b/Gather.php @@ -49,6 +49,7 @@ 'Gather\WatchlistCollectionStore' => 'stores/WatchlistCollectionStore', 'Gather\CollectionsListStore' => 'stores/CollectionsListStore', 'Gather\DumbWatchlistOnlyCollectionsListStore' => 'stores/DumbWatchlistOnlyCollectionsListStore', + 'Gather\ItemExtractsStore' => 'stores/ItemExtractsStore', 'Gather\View' => 'views/View', 'Gather\UserNotFoundView' => 'views/UserNotFoundView', diff --git a/includes/models/CollectionItem.php b/includes/models/CollectionItem.php index 069f1e1..131176c 100644 --- a/includes/models/CollectionItem.php +++ b/includes/models/CollectionItem.php @@ -65,4 +65,11 @@ public function getTitle() { return $this->title; } + + /** + * @return string extract of the item + */ + public function getExtract() { + return $this->extract; + } } diff --git a/includes/stores/ItemExtractsStore.php b/includes/stores/ItemExtractsStore.php new file mode 100644 index 0000000..3fcdfcc --- /dev/null +++ b/includes/stores/ItemExtractsStore.php @@ -0,0 +1,43 @@ +<?php + +namespace Gather; + +use \ApiQuery; +use \ApiMain; +use \FauxRequest; + +/** + * Loading extracts for titles + */ +class ItemExtractsStore { + const CHAR_LIMIT=140; + + /** + * Load extracts for a collection of titles + * @param Title[] $titles + * + * @return string[] + */ + public static function loadExtracts( $titles ) { + $api = new ApiMain( new FauxRequest( array( + 'action' => 'query', + 'prop' => 'extracts', + 'explaintext' => true, + 'exintro' => true, + 'exchars' => ItemExtractsStore::CHAR_LIMIT, + 'titles' => implode( '|', $titles ), + 'exlimit' => count( $titles ), + ) ) ); + $api->execute(); + $data = $api->getResultData(); + $pages = $data['query']['pages']; + + $extracts = array(); + foreach ( $pages as $page ) { + $extracts[] = $page['extract']['*']; + } + return $extracts; + } + +} + diff --git a/includes/stores/WatchlistCollectionStore.php b/includes/stores/WatchlistCollectionStore.php index 505ff65..ca88feb 100644 --- a/includes/stores/WatchlistCollectionStore.php +++ b/includes/stores/WatchlistCollectionStore.php @@ -38,10 +38,10 @@ */ public function __construct( User $user ) { $titles = $this->loadTitles( $user ); - // FIXME: Load here extracts and images from titles. + $extracts = ItemExtractsStore::loadExtracts( $titles ); - foreach ( $titles as $title ) { - $this->items[] = new CollectionItem( $title, false, false ); + foreach ( $titles as $key=>$title ) { + $this->items[] = new CollectionItem( $title, false, $extracts[$key] ); } } diff --git a/includes/views/CollectionItemCardView.php b/includes/views/CollectionItemCardView.php index bb53066..bf5dd7b 100644 --- a/includes/views/CollectionItemCardView.php +++ b/includes/views/CollectionItemCardView.php @@ -34,15 +34,18 @@ * @inheritdoc */ protected function getHtml() { - $page = $this->item; - $title = $page->getTitle(); + $item = $this->item; + $title = $item->getTitle(); $html = Html::openElement( 'div', array( 'class' => 'collection-item' ) ) . Html::openElement( 'h2', array( 'class' => 'collection-item-title' ) ) . Html::element( 'a', array( 'href' => $title->getLocalUrl() ), $this->getTitle() ). - Html::closeElement( 'h2' ) . - Html::openElement( 'div', array( 'class' => 'collection-item-footer' ) ) . + Html::closeElement( 'h2' ); + if ( $item->hasExtract() ) { + $html .= Html::element( 'p', array( 'class' => 'collection-item-excerpt' ), $item->getExtract() ); + } + $html .= Html::openElement( 'div', array( 'class' => 'collection-item-footer' ) ) . Html::openElement( 'a', array( 'href' => $title->getLocalUrl(), -- To view, visit https://gerrit.wikimedia.org/r/189948 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I73401aad1ddbfcd41428967626946083985c26e5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Gather Gerrit-Branch: master Gerrit-Owner: Jhernandez <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
