https://www.mediawiki.org/wiki/Special:Code/MediaWiki/105456
Revision: 105456 Author: jeroendedauw Date: 2011-12-07 19:55:08 +0000 (Wed, 07 Dec 2011) Log Message: ----------- follow up to r105455 Modified Paths: -------------- trunk/extensions/Reviews/includes/Review.php trunk/extensions/Reviews/includes/ReviewPager.php Added Paths: ----------- trunk/extensions/Reviews/includes/ReviewsList.php Modified: trunk/extensions/Reviews/includes/Review.php =================================================================== --- trunk/extensions/Reviews/includes/Review.php 2011-12-07 19:41:06 UTC (rev 105455) +++ trunk/extensions/Reviews/includes/Review.php 2011-12-07 19:55:08 UTC (rev 105456) @@ -353,7 +353,7 @@ * * @return string */ - public function getHTML() { + public function getHTML( User $user ) { $ratings = $this->getRatings( true ); $html = '<table class="review-table">'; @@ -362,8 +362,7 @@ $html .= '<tr>'; - // ' . $this->hasRatings() ? '2' : '1' . ' - $html .= '<td rowspan="2" class="review-author-box">'; + $html .= '<td rowspan="' . ( $this->hasRatings() ? 3 : 2 ) . '" class="review-author-box">'; $html .= ReviewRating::getDisplayHTMLFor( $this->getRating() ); @@ -397,6 +396,14 @@ $html .= '</tr>'; } + $html .= '<tr><td>'; + + $html .= $this->getStateControl( $user ); + + $html .= " ( View details | Edit )"; + + $html .= '</td></tr>'; + $html .= '</table>'; return Html::openElement( @@ -478,6 +485,7 @@ 'div', array( 'class' => 'reviews-state-controls', + 'style' => 'display:inline;', 'data-review-id' => $this->getId(), 'data-review-state' => self::getStateString( $this->getField( 'state' ) ), 'data-review-states' => FormatJson::encode( $states ), Modified: trunk/extensions/Reviews/includes/ReviewPager.php =================================================================== --- trunk/extensions/Reviews/includes/ReviewPager.php 2011-12-07 19:41:06 UTC (rev 105455) +++ trunk/extensions/Reviews/includes/ReviewPager.php 2011-12-07 19:55:08 UTC (rev 105456) @@ -128,7 +128,7 @@ */ function formatRow( $row ) { $this->currentReview = Review::newFromDBResult( $row ); - return '<tr><td>' . $this->currentReview->getHTML() . '</td></tr>'; + return '<tr><td>' . $this->currentReview->getHTML( $this->getUser() ) . '</td></tr>'; } /** Added: trunk/extensions/Reviews/includes/ReviewsList.php =================================================================== --- trunk/extensions/Reviews/includes/ReviewsList.php (rev 0) +++ trunk/extensions/Reviews/includes/ReviewsList.php 2011-12-07 19:55:08 UTC (rev 105456) @@ -0,0 +1,189 @@ +<?php + +/** + * Class to render review lists. + * + * @since 0.1 + * + * @file ReviewsList.php + * @ingroup Reviews + * + * @licence GNU GPL v3+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class ReviewsList { + + /** + * List of review parameters. + * + * @since 0.1 + * + * @var array + */ + protected $parameters; + + protected $contents; + + protected $titleCondition = false; + + /** + * Constructor. + * + * @since 0.1 + * + * @param array $args + * @param string|null $contents + */ + public function __construct( array $args = array(), $contents = null ) { + $this->contents = $contents; + + $args = filter_var_array( $args, $this->getTagParameters() ); + + if ( is_array( $args ) ) { + $this->parameters = $args; + } else { + // TODO: nicer handling + throw new MWException( 'Invalid parameters for reviews tag.' ); + } + } + + /** + * Renrder the reviews div. + * + * @since 0.1 + * + * @param IContextSource $contextSource + * @param Parser $parser + * + * @return string + */ + public function render( IContextSource $contextSource = null, Parser $parser = null ) { + static $loadedJs = false; + + $source = false; + + if ( !is_null( $contextSource ) ) { + $source = $contextSource; + } + + if ( !is_null( $parser ) ) { + $source = $parser; + } + + if ( !$loadedJs ) { + $js = Skin::makeVariablesScript( array( + 'wgReviewsSettings' => ReviewsSettings::getSettings() + ) ); + + $source->getOutput()->addModules( 'ext.reviews.list' ); + + if ( is_null( $contextSource ) ) { + $source->getOutput()->addHeadItem( $js ); + } + else { + $source->getOutput()->addHeadItem( 'wgReviewsSettings', $js ); + } + } + + $reviews = $this->getReviews( $source->getTitle() ); + + if ( count( $reviews ) > 0 ) { + return $this->getList( $reviews, $source->getUser() ); + } + else { + return is_null( $this->contents['default'] ) ? '' : $this->contents['default']; + } + } + + /** + * Get the reviews to display based on the provided arguments that are selection criteria. + * + * @since 0.1 + * + * @param Title $title + * + * @return array of Review + */ + protected function getReviews( Title $title ) { + $conditions = array( + 'state' => array( Review::STATUS_NEW, Review::STATUS_REVIEWED ) + ); + + if ( $this->parameters['id'] ) { + $conditions['id'] = $this->parameters['id']; + } + + if ( $this->parameters['page'] ) { + $ids = array(); + + if ( $this->titleCondition !== false ) { + $ids[] = $this->titleCondition->getArticleID(); + } + + $title = Title::newFromText( $this->parameters['page'] ); + + if ( !is_null( $title ) ) { + $ids[] = $title->getArticleID(); + } + + if ( count( $ids ) > 0 ) { + $conditions['page_id'] = $ids; + } + } + else { + $conditions['page_id'] = $title->getArticleID(); + } + + if ( $this->parameters['user'] ) { + $user = User::newFromName( $this->parameters['user'] ); + + if ( $user !== false ) { + $conditions['user_id'] = $user->getId(); + } + } + + return Review::select( null, $conditions ); + } + + public function limitToTitle( Title $title ) { + $this->titleCondition = $title; + } + + /** + * Get the HTML for a list of reviews. + * + * @since 0.1 + * + * @param array $reviews + * + * @return string + */ + protected function getList( array /* of Review */ $reviews, User $user ) { + $html = ''; + + foreach ( $reviews as /* Review */ $review ) { + $html .= $review->getHTML( $user ); + } + + return $html; + } + + /** + * Gets the parameters accepted by this tag extension. + * + * @since 0.1 + * + * @param array $args + * + * @return array + */ + protected function getTagParameters() { + return array( + 'id' => array( 'filter' => FILTER_VALIDATE_INT, 'options' => array( 'min_range' => 1 ) ), + 'page' => array(), + 'user' => array(), + 'default' => array(), + ); + } + +} Property changes on: trunk/extensions/Reviews/includes/ReviewsList.php ___________________________________________________________________ Added: svn:eol-style + native _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs