r105052 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105051‎ | r105052 | r105053 >
Date:03:46, 3 December 2011
Author:jeroendedauw
Status:reverted
Tags:
Comment:
work on rating display
Modified paths:
  • /trunk/extensions/Reviews/Reviews.php (modified) (history)
  • /trunk/extensions/Reviews/includes/Review.php (modified) (history)
  • /trunk/extensions/Reviews/includes/ReviewsTag.php (modified) (history)
  • /trunk/extensions/Reviews/resources/jquery.reviewRating.js (added) (history)
  • /trunk/extensions/Reviews/resources/reviews.tag.css (modified) (history)
  • /trunk/extensions/Reviews/resources/reviews.tag.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Reviews/includes/ReviewsTag.php
@@ -67,12 +67,18 @@
6868 }
6969
7070 $reviews = $this->getReviews( $parser );
71 - return $this->getList( $reviews );
 71+
 72+ if ( count( $reviews ) > 0 ) {
 73+ return $this->getList( $reviews );
 74+ }
 75+ else {
 76+ return is_null( $this->contents['default'] ) ? '' : $this->contents['default'];
 77+ }
7278 }
7379
7480 /**
 81+ * Get the reviews to display based on the provided arguments that are selection criteria.
7582 *
76 - *
7783 * @since 0.1
7884 *
7985 * @param Parser $parser
@@ -111,8 +117,8 @@
112118 }
113119
114120 /**
 121+ * Get the HTML for a list of reviews.
115122 *
116 - *
117123 * @since 0.1
118124 *
119125 * @param array $reviews
@@ -130,8 +136,8 @@
131137 }
132138
133139 /**
 140+ * Gets the parameters accepted by this tag extension.
134141 *
135 - *
136142 * @since 0.1
137143 *
138144 * @param array $args
@@ -143,6 +149,7 @@
144150 'id' => array( 'filter' => FILTER_VALIDATE_INT, 'options' => array( 'min_range' => 1 ) ),
145151 'page' => array(),
146152 'user' => array(),
 153+ 'default' => array(),
147154 );
148155 }
149156
Index: trunk/extensions/Reviews/includes/Review.php
@@ -345,16 +345,30 @@
346346 public function getHTML() {
347347 $html = '<table class="review-table">';
348348
349 - $html .= '<tr><th colspan="2">' . htmlspecialchars( $this->getField( 'title' ) ) . '</th></tr>';
 349+ $html .= '<tr><th colspan="2" class="review-table-title">' . htmlspecialchars( $this->getField( 'title' ) ) . '</th></tr>';
350350
351351 $html .= '<tr>';
352352
353 - $html .= '<td>...</td>';
 353+ $html .= '<td rowspan="2">author stuff be here</td>';
354354
355355 $html .= Html::element( 'td', array(), $this->getField( 'text' ) );
356356
357357 $html .= '</tr>';
358358
 359+ $html .= '<tr colspan="2">';
 360+
 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+ }, '' )
 369+ );
 370+
 371+ $html .= '</tr>';
 372+
359373 $html .= '</table>';
360374
361375 return Html::openElement(
Index: trunk/extensions/Reviews/Reviews.php
@@ -174,6 +174,15 @@
175175 ),
176176 );
177177
 178+$wgResourceModules['jquery.reviewRating'] = $moduleTemplate + array(
 179+ 'scripts' => array(
 180+ 'jquery.reviewRating.js',
 181+ ),
 182+ 'dependencies' => array(
 183+ 'ext.reviews', 'jquery.ui.stars',
 184+ ),
 185+);
 186+
178187 $wgResourceModules['jquery.ui.stars'] = $moduleTemplate + array(
179188 'scripts' => array(
180189 'jquery.ui.stars/jquery.ui.stars.js',
@@ -193,6 +202,9 @@
194203 'styles' => array(
195204 'reviews.tag.css',
196205 ),
 206+ 'dependencies' => array(
 207+ 'jquery.reviewRating',
 208+ ),
197209 );
198210
199211 $wgResourceModules['ext.reviews.pager'] = $moduleTemplate + array(
Index: trunk/extensions/Reviews/resources/jquery.reviewRating.js
@@ -0,0 +1,39 @@
 2+/**
 3+ * JavasSript 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+(function( $, mw, reviews ) { $.fn.reviewRating = function( options ) {
 11+
 12+ var settings = $.extend( {
 13+
 14+ } );
 15+
 16+ return this.each( function() {
 17+
 18+ var _this = this;
 19+ var $this = $( _this );
 20+
 21+ this.setup = function() {
 22+ $this.html( $( '<p>' ).text( $this.attr( 'data-type' ) + ': ' ) );
 23+
 24+ $this.append( reviews.htmlSelect(
 25+ { 1: 1, 2: 2, 3: 3, 4: 4, 5: 5 }, // TODO
 26+ parseInt( $this.attr( 'data-value' ) ), { }
 27+ ) );
 28+
 29+ $this.stars( {
 30+ inputType: 'select',
 31+ cancelShow: false,
 32+ disabled: true
 33+ } );
 34+ };
 35+
 36+ this.setup();
 37+
 38+ });
 39+
 40+}; })( window.jQuery, window.mediaWiki, window.reviews );
Property changes on: trunk/extensions/Reviews/resources/jquery.reviewRating.js
___________________________________________________________________
Added: svn:eol-style
141 + native
Index: trunk/extensions/Reviews/resources/reviews.tag.css
@@ -8,4 +8,26 @@
99
1010 .review-table {
1111 width: 100%;
12 -}
\ No newline at end of file
 12+}
 13+
 14+table.review-table, table.review-table td, table.review-table th {
 15+ border: 1px solid gray;
 16+}
 17+
 18+.review-table-title {
 19+ text-align: left;
 20+ padding-left: 5px;
 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/reviews.tag.js
@@ -6,8 +6,14 @@
77 * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
88 */
99
10 -(function( $, mw ) { $( document ).ready( function() {
 10+(function( $, mw ) {
1111
1212 var _this = this;
 13+
 14+ $( document ).ready( function() {
1315
14 -} ); })( window.jQuery, window.mediaWiki );
 16+ $( '.review-rating-display' ).reviewRating();
 17+
 18+ } );
 19+
 20+})( window.jQuery, window.mediaWiki );

Status & tagging log