r105073 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105072‎ | r105073 | r105074 >
Date:18:48, 3 December 2011
Author:jeroendedauw
Status:reverted
Tags:
Comment:
work on review rating display
Modified paths:
  • /trunk/extensions/Reviews/Reviews.php (modified) (history)
  • /trunk/extensions/Reviews/includes/Review.php (modified) (history)
  • /trunk/extensions/Reviews/includes/ReviewRating.php (modified) (history)
  • /trunk/extensions/Reviews/resources/jquery.reviewRating.css (added) (history)
  • /trunk/extensions/Reviews/resources/jquery.reviewRating.js (modified) (history)
  • /trunk/extensions/Reviews/resources/reviews.special.js (modified) (history)
  • /trunk/extensions/Reviews/resources/reviews.tag.css (modified) (history)
  • /trunk/extensions/Reviews/specials/SpecialReviews.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Reviews/specials/SpecialReviews.php
@@ -169,18 +169,14 @@
170170
171171 $stats['state'] = $review->getStateControl( $this->getUser() );
172172
173 - // TODO: might want to display stars here as well.
174 - $stats['rating'] = htmlspecialchars( $this->getLanguage()->formatNum( $review->getField( 'rating' ) ) );
 173+ $stats['rating'] = $review->getRating()->getDisplayHTML();
175174
176175 if ( $review->hasRatings() ) {
177 - $ratings = array();
178 -
179 - foreach ( $review->getRatings() as /* ReviewRating */ $rating ) {
180 - // TODO: might want to display stars here as well.
181 - $ratings[] = Html::element( 'li', array(), $rating->getField( 'type' ) . ': ' . $rating->getField( 'value' ) );
182 - }
183 -
184 - $stats['ratings'] = Html::rawElement( 'ul', array(), implode( $ratings ) );
 176+ $stats['ratings'] = Html::rawElement(
 177+ 'ul',
 178+ array(),
 179+ implode( array_map( 'ReviewRating::getDisplayHTMLFor', $review->getRatings() ) )
 180+ );
185181 }
186182
187183 return $stats;
Index: trunk/extensions/Reviews/includes/Review.php
@@ -210,6 +210,17 @@
211211 }
212212
213213 /**
 214+ * Get the main rating of this review.
 215+ *
 216+ * @since 0.1
 217+ *
 218+ * @return ReviewRating
 219+ */
 220+ public function getRating() {
 221+ return new ReviewRating( array( 'value' => $this->getField( 'rating' ) ) );
 222+ }
 223+
 224+ /**
214225 * Get if the review has any (non-main) ratings associated with it.
215226 *
216227 * @since 0.1
@@ -357,14 +368,10 @@
358369
359370 $html .= '<tr colspan="2">';
360371
361 - $html .= Html::rawElement( 'td', array(),
362 - array_reduce( $this->getRatings(), function( $html, /* ReviewRating */ $rating ) {
363 - return $html . Html::element( 'div', array(
364 - 'class' => 'review-rating-display',
365 - 'data-type' => $rating->getField( 'type' ),
366 - 'data-value' => $rating->getField( 'value' ),
367 - ) );
368 - }, '' )
 372+ $html .= Html::rawElement(
 373+ 'td',
 374+ array(),
 375+ implode( array_map( 'ReviewRating::getDisplayHTMLFor', $this->getRatings() ) )
369376 );
370377
371378 $html .= '</tr>';
Index: trunk/extensions/Reviews/includes/ReviewRating.php
@@ -106,4 +106,37 @@
107107 return $ratings;
108108 }
109109
 110+ /**
 111+ * Gets the HTML to display this rating.
 112+ *
 113+ * @since 0.1
 114+ *
 115+ * @return string
 116+ */
 117+ public function getDisplayHTML() {
 118+ return self::getDisplayHTMLFor( $this );
 119+ }
 120+
 121+ /**
 122+ * Gets the HTML to display the provided rating.
 123+ *
 124+ * @since 0.1
 125+ *
 126+ * @param ReviewRating $rating
 127+ *
 128+ * @return string
 129+ */
 130+ public static function getDisplayHTMLFor( ReviewRating $rating ) {
 131+ $attribs = array(
 132+ 'class' => 'review-rating-display',
 133+ 'data-value' => $rating->getField( 'value' ),
 134+ );
 135+
 136+ if ( $rating->hasField( 'type' ) ) {
 137+ $attribs['data-type'] = $rating->getField( 'type' );
 138+ }
 139+
 140+ return Html::element( 'div', $attribs );
 141+ }
 142+
110143 }
Index: trunk/extensions/Reviews/Reviews.php
@@ -178,6 +178,9 @@
179179 'scripts' => array(
180180 'jquery.reviewRating.js',
181181 ),
 182+ 'styles' => array(
 183+ 'jquery.reviewRating.css',
 184+ ),
182185 'dependencies' => array(
183186 'ext.reviews', 'jquery.ui.stars',
184187 ),
@@ -212,7 +215,7 @@
213216 'reviews.pager.js',
214217 ),
215218 'dependencies' => array(
216 - 'jquery.reviewState'
 219+ 'jquery.reviewState',
217220 ),
218221 );
219222
@@ -239,10 +242,10 @@
240243 'reviews.special.js',
241244 ),
242245 'dependencies' => array(
243 - 'jquery.reviewState', 'jquery.ui.button', 'ext.reviews'
 246+ 'jquery.reviewState', 'jquery.ui.button', 'ext.reviews', 'jquery.reviewRating',
244247 ),
245248 'messages' => array(
246 - 'reviews-reviews-delete-confirm'
 249+ 'reviews-reviews-delete-confirm',
247250 ),
248251 );
249252
Index: trunk/extensions/Reviews/resources/jquery.reviewRating.js
@@ -18,7 +18,12 @@
1919 var $this = $( _this );
2020
2121 this.setup = function() {
22 - $this.html( $( '<p>' ).text( $this.attr( 'data-type' ) + ': ' ) );
 22+ if ( $this.attr( 'data-type' ) === undefined ) {
 23+ $this.html( '' );
 24+ }
 25+ else {
 26+ $this.html( $( '<p>' ).text( $this.attr( 'data-type' ) + ': ' ) );
 27+ }
2328
2429 $this.append( reviews.htmlSelect(
2530 { 1: 1, 2: 2, 3: 3, 4: 4, 5: 5 }, // TODO
Index: trunk/extensions/Reviews/resources/reviews.tag.css
@@ -18,16 +18,3 @@
1919 text-align: left;
2020 padding-left: 5px;
2121 }
22 -
23 -.review-rating-display {
24 - display: block;
25 - clear: both;
26 -}
27 -
28 -.review-rating-display > * {
29 - float: left;
30 -}
31 -
32 -.review-rating-display > p {
33 - line-height: 1.4em;
34 -}
Index: trunk/extensions/Reviews/resources/jquery.reviewRating.css
@@ -0,0 +1,20 @@
 2+/**
 3+ * CSS for the Reviews MediaWiki extension.
 4+ * @see https://www.mediawiki.org/wiki/Extension:Reviews
 5+ *
 6+ * @licence GNU GPL v3 or later
 7+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
 8+ */
 9+
 10+.review-rating-display {
 11+ display: block;
 12+ clear: both;
 13+}
 14+
 15+.review-rating-display > * {
 16+ float: left;
 17+}
 18+
 19+.review-rating-display > p {
 20+ line-height: 1.4em;
 21+}
Property changes on: trunk/extensions/Reviews/resources/jquery.reviewRating.css
___________________________________________________________________
Added: svn:eol-style
122 + native
Index: trunk/extensions/Reviews/resources/reviews.special.js
@@ -33,6 +33,8 @@
3434 }
3535 } );
3636
 37+ $( '.review-rating-display' ).reviewRating();
 38+
3739 } );
3840
3941 })( window.jQuery, window.mediaWiki, window.reviews );

Follow-up revisions

RevisionCommit summaryAuthorDate
r105074Follow up to r105073;jeroendedauw19:02, 3 December 2011

Status & tagging log