jenkins-bot has submitted this change and it was merged.
Change subject: Hygiene: Introduce ReportTableRow view
......................................................................
Hygiene: Introduce ReportTableRow view
Changes:
* Allow getHtml to pass data, this will allow us to switch to templates in
future.
Change-Id: Id17fa0278729c33779da3ad2e2eb3a80d014c842
---
M Gather.php
M includes/specials/SpecialGatherLists.php
M includes/views/Collection.php
M includes/views/CollectionItemCard.php
M includes/views/CollectionsList.php
M includes/views/CollectionsListItemCard.php
M includes/views/Image.php
M includes/views/NoPublic.php
M includes/views/NotFound.php
A includes/views/ReportTableRow.php
M includes/views/View.php
11 files changed, 139 insertions(+), 72 deletions(-)
Approvals:
Jhernandez: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Gather.php b/Gather.php
index 71c4fa3..41db2d7 100644
--- a/Gather.php
+++ b/Gather.php
@@ -52,6 +52,7 @@
'Gather\views\CollectionsList' => 'views/CollectionsList',
'Gather\views\CollectionsListItemCard' =>
'views/CollectionsListItemCard',
'Gather\views\Pagination' => 'views/Pagination',
+ 'Gather\views\ReportTableRow' => 'views/ReportTableRow',
'Gather\views\helpers\CSS' => 'views/helpers/CSS',
diff --git a/includes/specials/SpecialGatherLists.php
b/includes/specials/SpecialGatherLists.php
index 7082b8a..d70d167 100644
--- a/includes/specials/SpecialGatherLists.php
+++ b/includes/specials/SpecialGatherLists.php
@@ -13,7 +13,6 @@
use Linker;
use Gather\views;
use Gather\views\helpers\CSS;
-use MWTimestamp;
use Exception;
/**
@@ -112,6 +111,10 @@
$this->setHeaders();
$out->setProperty( 'unstyledContent', true );
$out->setPageTitle( wfMessage( 'gather-lists-title' ) );
+ $data = array(
+ 'canHide' => $this->canHideLists(),
+ 'action' => $action,
+ );
// FIXME: Move below to View.
$html = '';
@@ -127,10 +130,17 @@
$html .= Html::element( 'span', array(), '' );
}
$html .= Html::closeElement( 'li' );
+ $out->addHTML( $html );
foreach ( $lists as $list ) {
- $html .= $this->row( $list, $action );
+ $collection = new models\CollectionInfo( $list['id'],
User::newFromName( $list['owner'] ),
+ $list['label'], $list['description'] );
+ $collection->setCount( $list['count'] );
+ $this->row( $collection, $data + array(
+ // FIXME: Should be part of the CollectionInfo
model.
+ 'updated' => $list['updated'],
+ ) );
}
- $html .= Html::closeElement( 'ul' );
+ $html = Html::closeElement( 'ul' );
if ( $nextPageUrl ) {
$html .= views\Pagination::more(
$nextPageUrl, wfMessage(
'gather-lists-collection-more-link-label' ) );
@@ -150,67 +160,13 @@
/**
* Renders a html row of data
- * @param array $data
+ * @param models\CollectionInfo $collection
* @param string [$action] hide or show - action to associate with the
row.
* @return string
*/
- private function row( $data, $action = 'hide' ) {
- $lang = $this->getLanguage();
- $user = $this->getUser();
- $ts = $lang->userTimeAndDate( new MWTimestamp( $data['updated']
), $user );
-
- $html = Html::openElement( 'li' )
- . $this->collectionLink( $data['label'],
$data['owner'], $data['id'] )
- . Html::element( 'span', array(), $data['description'] )
- . Html::element( 'span', array(), $data['count'] )
- . $this->userLink( $data['owner'] )
- . Html::element( 'span', array(), $ts );
-
- if ( $this->canHideLists() ) {
- $className = CSS::buttonClass(
- $action === 'hide' ? 'destructive':
'constructive',
- 'moderate-collection'
- );
-
- $label = $action === 'hide' ? $this->msg(
'gather-lists-hide-collection-label' ) :
- $this->msg(
'gather-lists-show-collection-label' );
-
- $html .= Html::openElement( 'span', array() )
- . Html::element( 'button', array(
- 'class' => $className,
- 'data-id' => $data['id'],
- 'data-action' => $action,
- 'data-label' => $data['label'],
- 'data-owner' => $data['owner']
- ), $label )
- . Html::closeElement( 'span' );
- }
- $html .= Html::closeElement( 'li' );
- return $html;
- }
-
- /**
- * Renders a html link for the user's gather page
- * @param User $user
- * @return string
- */
- private function userLink( $user ) {
- return Html::element( 'a', array(
- 'href' => SpecialPage::getTitleFor( 'Gather', 'by/' .
$user )->getLocalUrl()
- ), $user );
- }
-
- /**
- * Renders a html link for a collection page
- * @param string $text of the link
- * @param User $user owner of the collection
- * @param int $id of the collection
- * @return string
- */
- private function collectionLink( $text, $user, $id ) {
- return Html::element( 'a', array(
- 'href' => SpecialPage::getTitleFor( 'Gather', 'by/' .
$user.'/'.$id )->getLocalUrl()
- ), $text );
+ private function row( $collection, $data ) {
+ $view = new views\ReportTableRow( $this->getUser(),
$this->getLanguage(), $collection );
+ $view->render( $this->getOutput(), $data );
}
}
diff --git a/includes/views/Collection.php b/includes/views/Collection.php
index ca59750..504cd35 100644
--- a/includes/views/Collection.php
+++ b/includes/views/Collection.php
@@ -169,7 +169,7 @@
/**
* @inheritdoc
*/
- protected function getHtml() {
+ protected function getHtml( $data = array() ) {
$collection = $this->collection;
$html = Html::openElement( 'div', array( 'class' => 'collection
content' ) ) .
diff --git a/includes/views/CollectionItemCard.php
b/includes/views/CollectionItemCard.php
index bc0a162..3320d5d 100644
--- a/includes/views/CollectionItemCard.php
+++ b/includes/views/CollectionItemCard.php
@@ -44,7 +44,7 @@
/**
* @inheritdoc
*/
- protected function getHtml() {
+ protected function getHtml( $data = array() ) {
$item = $this->item;
$title = $item->getTitle();
$img = $this->image->getHtml();
diff --git a/includes/views/CollectionsList.php
b/includes/views/CollectionsList.php
index 04b2844..12db333 100644
--- a/includes/views/CollectionsList.php
+++ b/includes/views/CollectionsList.php
@@ -53,7 +53,7 @@
/**
* @inheritdoc
*/
- public function getHtml() {
+ public function getHtml( $data = array() ) {
$html = Html::openElement(
'div',
array( 'class' => 'collections-list content
view-border-box' )
diff --git a/includes/views/CollectionsListItemCard.php
b/includes/views/CollectionsListItemCard.php
index 2bfa093..d264148 100644
--- a/includes/views/CollectionsListItemCard.php
+++ b/includes/views/CollectionsListItemCard.php
@@ -51,7 +51,7 @@
/**
* @inheritdoc
*/
- public function getHtml() {
+ public function getHtml( $data = array() ) {
$articleCountMsg = wfMessage(
'gather-article-count',
$this->collection->getCount()
diff --git a/includes/views/Image.php b/includes/views/Image.php
index 762f2e7..79689e2 100644
--- a/includes/views/Image.php
+++ b/includes/views/Image.php
@@ -26,7 +26,7 @@
/**
* Get the view html
*/
- public function getHtml() {
+ public function getHtml( $data = array() ) {
// FIXME: magic number
return $this->getPageImageHtml( 750, true );
}
diff --git a/includes/views/NoPublic.php b/includes/views/NoPublic.php
index b3b2383..9474f40 100644
--- a/includes/views/NoPublic.php
+++ b/includes/views/NoPublic.php
@@ -22,7 +22,7 @@
/**
* @inheritdoc
*/
- public function getHtml() {
+ public function getHtml( $data = array() ) {
$html = Html::openElement( 'div', array( 'class' => 'collection
not-found content' ) );
$html .= Html::element( 'span', array( 'class' => 'mw-ui-anchor
mw-ui-destructive' ),
wfMessage( 'gather-no-public-lists-description'
)->text() );
diff --git a/includes/views/NotFound.php b/includes/views/NotFound.php
index b7b2c31..2eeab10 100644
--- a/includes/views/NotFound.php
+++ b/includes/views/NotFound.php
@@ -22,7 +22,7 @@
/**
* @inheritdoc
*/
- public function getHtml() {
+ public function getHtml( $data = array() ) {
// FIXME: Showing generic not found error right now. Show user
not found instead
$html = Html::openElement( 'div', array( 'class' => 'collection
not-found content' ) );
$html .= Html::element( 'span', array( 'class' => 'mw-ui-anchor
mw-ui-destructive' ),
diff --git a/includes/views/ReportTableRow.php
b/includes/views/ReportTableRow.php
new file mode 100644
index 0000000..602489b
--- /dev/null
+++ b/includes/views/ReportTableRow.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * View.php
+ */
+
+namespace Gather\views;
+
+use User;
+use Language;
+use Gather\models;
+use MWTimestamp;
+use Html;
+use SpecialPage;
+use Gather\views\helpers\CSS;
+
+/**
+ * Render a view.
+ */
+class ReportTableRow extends View {
+ /**
+ * Renders a html link for the user's gather page
+ * @param User $user
+ * @return string
+ */
+ private function userLink( $user ) {
+ return Html::element( 'a', array(
+ 'href' => SpecialPage::getTitleFor( 'Gather', 'by/' .
$user )->getLocalUrl()
+ ), $user );
+ }
+
+ /**
+ * Renders a html link for a collection page
+ * @param string $text of the link
+ * @param User $user owner of the collection
+ * @param int $id of the collection
+ * @return string
+ */
+ private function collectionLink( $text, $user, $id ) {
+ return Html::element( 'a', array(
+ 'href' => SpecialPage::getTitleFor( 'Gather', 'by/' .
$user.'/'.$id )->getLocalUrl()
+ ), $text );
+ }
+
+ /**
+ * @param User $user that is viewing the collection
+ * @param models\CollectionInfo $collection
+ */
+ public function __construct( User $user, Language $language,
models\CollectionInfo $collection ) {
+ $this->user = $user;
+ $this->language = $language;
+ $this->collection = $collection;
+ }
+
+ /**
+ * Returns the html for the view
+ *
+ * @param array $data
+ * @return string Html
+ */
+ public function getHtml( $data = array() ) {
+ $lang = $this->language;
+ $user = $this->user;
+ $collection = $this->collection;
+ $action = isset( $data['action'] ) ? $data['action'] : 'hide';
+
+ $ts = $lang->userTimeAndDate( new MWTimestamp( $data['updated']
), $user );
+ $owner = $collection->getOwner();
+ $label = $collection->getTitle();
+ $id = $collection->getId();
+
+ $html = Html::openElement( 'li' )
+ . $this->collectionLink( $label, $owner, $id )
+ . Html::element( 'span', array(),
$collection->getDescription() )
+ . Html::element( 'span', array(),
$collection->getCount() )
+ . $this->userLink( $owner )
+ . Html::element( 'span', array(), $ts );
+
+ if ( $data['canHide'] ) {
+ $className = CSS::buttonClass(
+ $action === 'hide' ? 'destructive':
'constructive',
+ 'moderate-collection'
+ );
+
+ $label = $action === 'hide' ? wfMessage(
'gather-lists-hide-collection-label' )->text() :
+ wfMessage( 'gather-lists-show-collection-label'
)->text();
+
+ $html .= Html::openElement( 'span', array() )
+ . Html::element( 'button', array(
+ 'class' => $className,
+ 'data-id' => $id,
+ 'data-action' => $action,
+ 'data-label' => $label,
+ 'data-owner' => $owner->getName(),
+ ), $label )
+ . Html::closeElement( 'span' );
+ }
+ $html .= Html::closeElement( 'li' );
+ return $html;
+ }
+
+ /**
+ * Returns the title for the view
+ *
+ * @private
+ * @return string Html
+ */
+ public function getTitle() {
+ return '';
+ }
+}
diff --git a/includes/views/View.php b/includes/views/View.php
index 440b075..aeed2d5 100644
--- a/includes/views/View.php
+++ b/includes/views/View.php
@@ -14,10 +14,10 @@
/**
* Returns the html for the view
*
- * @private
+ * @param array additional $data to help construct the view
* @return string Html
*/
- abstract protected function getHtml();
+ abstract protected function getHtml( $data = array() );
/**
* Returns the title for the view
@@ -32,7 +32,7 @@
*
* @param OutputPage $out
*/
- public function render( OutputPage $out ) {
- $out->addHTML( $this->getHtml() );
+ public function render( OutputPage $out, $data = array() ) {
+ $out->addHTML( $this->getHtml( $data ) );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/201744
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id17fa0278729c33779da3ad2e2eb3a80d014c842
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: 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