Index: trunk/extensions/Reviews/specials/SpecialReviews.php |
— | — | @@ -169,18 +169,14 @@ |
170 | 170 | |
171 | 171 | $stats['state'] = $review->getStateControl( $this->getUser() ); |
172 | 172 | |
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(); |
175 | 174 | |
176 | 175 | 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 | + ); |
185 | 181 | } |
186 | 182 | |
187 | 183 | return $stats; |
Index: trunk/extensions/Reviews/includes/Review.php |
— | — | @@ -210,6 +210,17 @@ |
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
| 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 | + /** |
214 | 225 | * Get if the review has any (non-main) ratings associated with it. |
215 | 226 | * |
216 | 227 | * @since 0.1 |
— | — | @@ -357,14 +368,10 @@ |
358 | 369 | |
359 | 370 | $html .= '<tr colspan="2">'; |
360 | 371 | |
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() ) ) |
369 | 376 | ); |
370 | 377 | |
371 | 378 | $html .= '</tr>'; |
Index: trunk/extensions/Reviews/includes/ReviewRating.php |
— | — | @@ -106,4 +106,37 @@ |
107 | 107 | return $ratings; |
108 | 108 | } |
109 | 109 | |
| 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 | + |
110 | 143 | } |
Index: trunk/extensions/Reviews/Reviews.php |
— | — | @@ -178,6 +178,9 @@ |
179 | 179 | 'scripts' => array( |
180 | 180 | 'jquery.reviewRating.js', |
181 | 181 | ), |
| 182 | + 'styles' => array( |
| 183 | + 'jquery.reviewRating.css', |
| 184 | + ), |
182 | 185 | 'dependencies' => array( |
183 | 186 | 'ext.reviews', 'jquery.ui.stars', |
184 | 187 | ), |
— | — | @@ -212,7 +215,7 @@ |
213 | 216 | 'reviews.pager.js', |
214 | 217 | ), |
215 | 218 | 'dependencies' => array( |
216 | | - 'jquery.reviewState' |
| 219 | + 'jquery.reviewState', |
217 | 220 | ), |
218 | 221 | ); |
219 | 222 | |
— | — | @@ -239,10 +242,10 @@ |
240 | 243 | 'reviews.special.js', |
241 | 244 | ), |
242 | 245 | 'dependencies' => array( |
243 | | - 'jquery.reviewState', 'jquery.ui.button', 'ext.reviews' |
| 246 | + 'jquery.reviewState', 'jquery.ui.button', 'ext.reviews', 'jquery.reviewRating', |
244 | 247 | ), |
245 | 248 | 'messages' => array( |
246 | | - 'reviews-reviews-delete-confirm' |
| 249 | + 'reviews-reviews-delete-confirm', |
247 | 250 | ), |
248 | 251 | ); |
249 | 252 | |
Index: trunk/extensions/Reviews/resources/jquery.reviewRating.js |
— | — | @@ -18,7 +18,12 @@ |
19 | 19 | var $this = $( _this ); |
20 | 20 | |
21 | 21 | 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 | + } |
23 | 28 | |
24 | 29 | $this.append( reviews.htmlSelect( |
25 | 30 | { 1: 1, 2: 2, 3: 3, 4: 4, 5: 5 }, // TODO |
Index: trunk/extensions/Reviews/resources/reviews.tag.css |
— | — | @@ -18,16 +18,3 @@ |
19 | 19 | text-align: left; |
20 | 20 | padding-left: 5px; |
21 | 21 | } |
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 |
1 | 22 | + native |
Index: trunk/extensions/Reviews/resources/reviews.special.js |
— | — | @@ -33,6 +33,8 @@ |
34 | 34 | } |
35 | 35 | } ); |
36 | 36 | |
| 37 | + $( '.review-rating-display' ).reviewRating(); |
| 38 | + |
37 | 39 | } ); |
38 | 40 | |
39 | 41 | })( window.jQuery, window.mediaWiki, window.reviews ); |