jenkins-bot has submitted this change and it was merged.

Change subject: Make Special:GatherLists render through a view
......................................................................


Make Special:GatherLists render through a view

Changes:
* Introduces getModified method on CollectionsInfo
* Allows you to create a CollectionsList which contains collections by
more than one user.

Bug: T93422
Change-Id: I618370bbe9a0a17af3bcfa4a863ac37c03b04320
---
M Gather.php
M includes/models/CollectionInfo.php
M includes/models/CollectionsList.php
M includes/specials/SpecialGatherLists.php
A includes/views/ReportTable.php
M includes/views/ReportTableRow.php
6 files changed, 101 insertions(+), 36 deletions(-)

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



diff --git a/Gather.php b/Gather.php
index 41db2d7..a19f35d 100644
--- a/Gather.php
+++ b/Gather.php
@@ -53,6 +53,7 @@
        'Gather\views\CollectionsListItemCard' => 
'views/CollectionsListItemCard',
        'Gather\views\Pagination' => 'views/Pagination',
        'Gather\views\ReportTableRow' => 'views/ReportTableRow',
+       'Gather\views\ReportTable' => 'views/ReportTable',
 
        'Gather\views\helpers\CSS' => 'views/helpers/CSS',
 
diff --git a/includes/models/CollectionInfo.php 
b/includes/models/CollectionInfo.php
index 8978a96..6b0c577 100644
--- a/includes/models/CollectionInfo.php
+++ b/includes/models/CollectionInfo.php
@@ -6,6 +6,8 @@
 
 namespace Gather\models;
 
+use MWTimestamp;
+
 /**
  * The info of collection of items.
  *
@@ -16,6 +18,8 @@
        protected $knownMembers = array();
        /** @var int $count of items in the collection */
        protected $count;
+       /** @var MWTimestamp $updated Last updated time of the collection */
+       protected $updated;
 
        /**
         * Returns items count
@@ -42,6 +46,20 @@
        }
 
        /**
+        * @param string $updated
+        */
+       public function setUpdated( $updated ) {
+               $this->updated = new MWTimestamp( $updated );
+       }
+
+       /**
+        * @return MWTimestamp
+        */
+       public function getUpdated() {
+               return $this->updated;
+       }
+
+       /**
         * @param string $title
         * @param boolean $isMember whether this title is in the collection or 
not.
         */
diff --git a/includes/models/CollectionsList.php 
b/includes/models/CollectionsList.php
index 1ba6e6b..57c3c34 100644
--- a/includes/models/CollectionsList.php
+++ b/includes/models/CollectionsList.php
@@ -29,7 +29,7 @@
         */
        protected $includePrivate;
 
-       public function __construct( $user, $includePrivate = false ) {
+       public function __construct( $user = false, $includePrivate = false ) {
                $this->user = $user;
                $this->includePrivate = $includePrivate;
        }
@@ -123,11 +123,10 @@
 
        /**
         * Generate UserPageCollectionsList from api result
-        * FIXME: $user parameter currently ignored
         * @param User $user collection list owner (currently ignored)
         * @param boolean [$includePrivate] if the list should show private 
collections or not
-        * @param string [$memberTitle] title of member to check for
-        * @param string [$continue] generate collection list from continue 
parameter
+        * @param string|boolean [$memberTitle] title of member to check for
+        * @param array [$continue] generate collection list from continue 
parameter
         * @return models\CollectionsList List of collections.
         */
        public static function newFromApi( User $user, $includePrivate = false,
diff --git a/includes/specials/SpecialGatherLists.php 
b/includes/specials/SpecialGatherLists.php
index d70d167..accb646 100644
--- a/includes/specials/SpecialGatherLists.php
+++ b/includes/specials/SpecialGatherLists.php
@@ -9,10 +9,8 @@
 use SpecialPage;
 use ApiMain;
 use FauxRequest;
-use Html;
 use Linker;
 use Gather\views;
-use Gather\views\helpers\CSS;
 use Exception;
 
 /**
@@ -114,40 +112,19 @@
                $data = array(
                        'canHide' => $this->canHideLists(),
                        'action' => $action,
+                       'nextPageUrl' => $nextPageUrl,
                );
 
-               // FIXME: Move below to View.
-               $html = '';
-               $html .= Html::openElement( 'div', array( 'class' => 'content 
gather-lists' ) );
-               $html .= Html::openElement( 'ul', array() );
-               $html .= Html::openElement( 'li', array( 'class' => 'heading' ) 
)
-               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-title' ) )
-               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-description' ) )
-               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-count' ) )
-               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-owner' ) )
-               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-last-updated' ) );
-               if ( $this->canHideLists() ) {
-                       $html .= Html::element( 'span', array(), '' );
-               }
-               $html .= Html::closeElement( 'li' );
-               $out->addHTML( $html );
+               $cList = new models\CollectionsList();
                foreach ( $lists as $list ) {
                        $collection = new models\CollectionInfo( $list['id'], 
User::newFromName( $list['owner'] ),
-                        $list['label'], $list['description'] );
+                               $list['label'], $list['description'] );
                        $collection->setCount( $list['count'] );
-                       $this->row( $collection, $data + array(
-                               // FIXME: Should be part of the CollectionInfo 
model.
-                               'updated' => $list['updated'],
-                       ) );
+                       $collection->setUpdated( $list['updated'] );
+                       $cList->add( $collection );
                }
-               $html = Html::closeElement( 'ul' );
-               if ( $nextPageUrl ) {
-                       $html .= views\Pagination::more(
-                               $nextPageUrl, wfMessage( 
'gather-lists-collection-more-link-label' ) );
-               }
-               $html .= Html::closeElement( 'div' );
-
-               $out->addHTML( $html );
+               $view = new views\ReportTable( $this->getUser(), 
$this->getLanguage(), $cList );
+               $view->render( $this->getOutput(), $data );
        }
 
        /**
diff --git a/includes/views/ReportTable.php b/includes/views/ReportTable.php
new file mode 100644
index 0000000..2dc7bba
--- /dev/null
+++ b/includes/views/ReportTable.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * ReportTable.php
+ */
+
+namespace Gather\views;
+
+use User;
+use Language;
+use Gather\models;
+use Html;
+
+/**
+ * Render a view.
+ */
+class ReportTable extends View {
+       /**
+        * @param User $user that is viewing the collection
+        * @param Language $language
+        * @param models\CollectionsList $collectionList
+        */
+       public function __construct( User $user, Language $language,
+               models\CollectionsList $collectionList ) {
+               $this->user = $user;
+               $this->language = $language;
+               $this->collectionList = $collectionList;
+       }
+
+       /**
+        * Returns the html for the view
+        *
+        * @param array $data
+        * @return string Html
+        */
+       protected function getHtml( $data = array() ) {
+               $html = '';
+               $html .= Html::openElement( 'div', array( 'class' => 'content 
gather-lists' ) );
+               $html .= Html::openElement( 'ul', array() );
+               $html .= Html::openElement( 'li', array( 'class' => 'heading' ) 
)
+               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-title' ) )
+               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-description' ) )
+               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-count' ) )
+               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-owner' ) )
+               . Html::element( 'span', array(), wfMessage( 
'gather-lists-collection-last-updated' ) );
+               if ( $data['canHide'] ) {
+                       $html .= Html::element( 'span', array(), '' );
+               }
+               $html .= Html::closeElement( 'li' );
+               foreach ( $this->collectionList as $collection ) {
+                       $partial = new ReportTableRow( $this->user, 
$this->language, $collection );
+                       $html .= $partial->getHtml( $data );
+               }
+               $html .= Html::closeElement( 'ul' );
+               if ( $data['nextPageUrl'] ) {
+                       $html .= Pagination::more(
+                               $data['nextPageUrl'], wfMessage( 
'gather-lists-collection-more-link-label' ) );
+               }
+               $html .= Html::closeElement( 'div' );
+               return $html;
+       }
+
+       /**
+        * Returns the title for the view
+        *
+        * @private
+        * @return string Html
+        */
+       public function getTitle() {
+               return '';
+       }
+}
diff --git a/includes/views/ReportTableRow.php 
b/includes/views/ReportTableRow.php
index 602489b..7c3f2a3 100644
--- a/includes/views/ReportTableRow.php
+++ b/includes/views/ReportTableRow.php
@@ -8,7 +8,6 @@
 use User;
 use Language;
 use Gather\models;
-use MWTimestamp;
 use Html;
 use SpecialPage;
 use Gather\views\helpers\CSS;
@@ -63,7 +62,7 @@
                $collection = $this->collection;
                $action = isset( $data['action'] ) ? $data['action'] : 'hide';
 
-               $ts = $lang->userTimeAndDate( new MWTimestamp( $data['updated'] 
), $user );
+               $ts = $lang->userTimeAndDate( $collection->getUpdated(), $user 
);
                $owner = $collection->getOwner();
                $label = $collection->getTitle();
                $id = $collection->getId();

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I618370bbe9a0a17af3bcfa4a863ac37c03b04320
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to