r104198 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104197‎ | r104198 | r104199 >
Date:21:43, 24 November 2011
Author:jeroendedauw
Status:reverted
Tags:
Comment:
work on review display
Modified paths:
  • /trunk/extensions/Reviews/Reviews.hooks.php (modified) (history)
  • /trunk/extensions/Reviews/Reviews.php (modified) (history)
  • /trunk/extensions/Reviews/includes/Review.php (modified) (history)
  • /trunk/extensions/Reviews/includes/ReviewsTag.php (added) (history)
  • /trunk/extensions/Reviews/specials/SpecialReviews.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Reviews/specials/SpecialReviews.php
@@ -67,7 +67,12 @@
6868 }
6969 else {
7070 $this->getOutput()->addWikiMsg( 'reviews-reviews-editheader' );
71 - $this->displayEditControl( $review );
 71+
 72+ $this->displaySummary( $review );
 73+
 74+ $this->getOutput()->addHTML( $review->getHTML() );
 75+
 76+ $this->displayAdminControls( $review );
7277 }
7378 }
7479 }
@@ -78,7 +83,7 @@
7984 * @since 0.1
8085 */
8186 protected function displayReviewList() {
82 - $reviewPager = new ReviewPager( array() );
 87+ $reviewPager = new ReviewPager( array(), $this->getName() );
8388
8489 if ( $reviewPager->getNumRows() ) {
8590 $this->getOutput()->addHTML(
@@ -91,5 +96,25 @@
9297 $this->getOutput()->addWikiMsg( 'reviews-pager-no-results' );
9398 }
9499 }
 100+
 101+ /**
 102+ * Display a summary of the review.
 103+ *
 104+ * @since 0.1
 105+ *
 106+ * @param Review $review
 107+ */
 108+ protected function displaySummary( Review $review ) {
 109+ }
 110+
 111+ /**
 112+ * Display a summary of the review.
 113+ *
 114+ * @since 0.1
 115+ *
 116+ * @param Review $review
 117+ */
 118+ protected function displayAdminControls( Review $review ) {
 119+ }
95120
96121 }
Index: trunk/extensions/Reviews/includes/ReviewsTag.php
@@ -0,0 +1,149 @@
 2+<?php
 3+
 4+/**
 5+ * Class to render reviews tags.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file ReviewsTag.php
 10+ * @ingroup Reviews
 11+ *
 12+ * @licence GNU GPL v3+
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class ReviewsTag {
 16+
 17+ /**
 18+ * List of review parameters.
 19+ *
 20+ * @since 0.1
 21+ *
 22+ * @var array
 23+ */
 24+ protected $parameters;
 25+
 26+ protected $contents;
 27+
 28+ /**
 29+ * Constructor.
 30+ *
 31+ * @since 0.1
 32+ *
 33+ * @param array $args
 34+ * @param string|null $contents
 35+ */
 36+ public function __construct( array $args, $contents = null ) {
 37+ $this->contents = $contents;
 38+
 39+ $args = filter_var_array( $args, $this->getTagParameters() );
 40+
 41+ if ( is_array( $args ) ) {
 42+ $this->parameters = $args;
 43+ } else {
 44+ // TODO: nicer handling
 45+ throw new MWException( 'Invalid parameters for reviews tag.' );
 46+ }
 47+ }
 48+
 49+ /**
 50+ * Renrder the survey div.
 51+ *
 52+ * @since 0.1
 53+ *
 54+ * @param Parser $parser
 55+ *
 56+ * @return string
 57+ */
 58+ public function render( Parser $parser ) {
 59+ static $loadedJs = false;
 60+
 61+ if ( !$loadedJs ) {
 62+ $parser->getOutput()->addModules( 'ext.reviews.tag' );
 63+ $parser->getOutput()->addHeadItem(
 64+ Skin::makeVariablesScript( array(
 65+ 'wgReviewsSettings' => ReviewsSettings::getSettings()
 66+ ) )
 67+ );
 68+ }
 69+
 70+ $reviews = $this->getReviews( $parser );
 71+ return $this->getList( $reviews );
 72+ }
 73+
 74+ /**
 75+ *
 76+ *
 77+ * @since 0.1
 78+ *
 79+ * @param Parser $parser
 80+ *
 81+ * @return array of Review
 82+ */
 83+ protected function getReviews( Parser $parser ) {
 84+ $conditions = array(
 85+ 'state' => array( Review::STATUS_NEW, Review::STATUS_REVIEWED )
 86+ );
 87+
 88+ if ( $this->contents['id'] ) {
 89+ $conditions['id'] = $this->contents['id'];
 90+ }
 91+
 92+ if ( $this->contents['page'] ) {
 93+ $title = Title::newFromText( $this->contents['page'] );
 94+
 95+ if ( !is_null( $title ) ) {
 96+ $conditions['page_id'] = $title->getArticleID();
 97+ }
 98+ }
 99+ else {
 100+ $conditions['page_id'] = $parser->getTitle()->getArticleID();
 101+ }
 102+
 103+ if ( $this->contents['user'] ) {
 104+ $user = User::newFromName( $this->contents['user'] );
 105+
 106+ if ( $user !== false ) {
 107+ $conditions['user_id'] = $user->getId();
 108+ }
 109+ }
 110+
 111+ return Review::select( null, $conditions );
 112+ }
 113+
 114+ /**
 115+ *
 116+ *
 117+ * @since 0.1
 118+ *
 119+ * @param array $reviews
 120+ *
 121+ * @return string
 122+ */
 123+ protected function getList( array /* of Review */ $reviews ) {
 124+ $html = '';
 125+
 126+ foreach ( $reviews as /* Review */ $review ) {
 127+ $html .= $review->getHTML();
 128+ }
 129+
 130+ return $html;
 131+ }
 132+
 133+ /**
 134+ *
 135+ *
 136+ * @since 0.1
 137+ *
 138+ * @param array $args
 139+ *
 140+ * @return array
 141+ */
 142+ protected function getTagParameters() {
 143+ return array(
 144+ 'id' => array( 'filter' => FILTER_VALIDATE_INT, 'options' => array( 'min_range' => 1 ) ),
 145+ 'page' => array(),
 146+ 'user' => array(),
 147+ );
 148+ }
 149+
 150+}
Index: trunk/extensions/Reviews/includes/Review.php
@@ -19,7 +19,7 @@
2020 const STATUS_REVIEWED = 2;
2121
2222 /**
23 - *
 23+ * The ratings that are part of this review.
2424 *
2525 * @since 0.1
2626 * @var array of ReviewRating
@@ -277,5 +277,36 @@
278278
279279 return wfMsg( 'reviews-state-' . $map[$state] );
280280 }
 281+
 282+ /**
 283+ * Get HTML to represent the review.
 284+ *
 285+ * @since 0.1
 286+ *
 287+ * @return string
 288+ */
 289+ public function getHTML() {
 290+ $html = '<table>';
 291+
 292+ $html .= '<tr><th colspan="2">' . htmlspecialchars( $this->getField( 'title' ) ) . '</th></tr>';
 293+
 294+ $html .= '<tr>';
 295+
 296+ $html .= '<td>...</td>';
 297+
 298+ $html .= Html::element( 'td', array(), $this->getField( 'text' ) );
 299+
 300+ $html .= '</tr>';
 301+
 302+ $html .= '</table>';
 303+
 304+ return Html::openElement(
 305+ 'div',
 306+ array(
 307+ 'class' => 'reviews-review',
 308+ 'id' => 'reviews-review-' . $this->getId()
 309+ )
 310+ ) . $html . '</div>';
 311+ }
281312
282313 }
Index: trunk/extensions/Reviews/Reviews.php
@@ -59,6 +59,7 @@
6060 $wgAutoloadClasses['ReviewPager'] = dirname( __FILE__ ) . '/includes/ReviewPager.php';
6161 $wgAutoloadClasses['ReviewRating'] = dirname( __FILE__ ) . '/includes/ReviewRating.php';
6262 $wgAutoloadClasses['ReviewsDBObject'] = dirname( __FILE__ ) . '/includes/ReviewsDBObject.php';
 63+$wgAutoloadClasses['ReviewsTag'] = dirname( __FILE__ ) . '/includes/ReviewsTag.php';
6364
6465 $wgAutoloadClasses['SpecialMyReviews'] = dirname( __FILE__ ) . '/specials/SpecialMyReviews.php';
6566 $wgAutoloadClasses['SpecialReviews'] = dirname( __FILE__ ) . '/specials/SpecialReviews.php';
@@ -81,6 +82,7 @@
8283 $wgHooks['PersonalUrls'][] = 'ReviewsHooks::onPersonalUrls';
8384 $wgHooks['GetPreferences'][] = 'ReviewsHooks::onGetPreferences';
8485 $wgHooks['BeforePageDisplay'][] = 'ReviewsHooks::onBeforePageDisplay';
 86+$wgHooks['ParserFirstCallInit'][] = 'ReviewsHooks::onParserFirstCallInit';
8587
8688 // Rights
8789 $wgAvailableRights[] = 'reviewsadmin';
Index: trunk/extensions/Reviews/Reviews.hooks.php
@@ -151,5 +151,34 @@
152152
153153 return true;
154154 }
 155+
 156+ /**
 157+ * Render the reviews tag.
 158+ *
 159+ * @since 0.1
 160+ *
 161+ * @param mixed $input
 162+ * @param array $args
 163+ * @param Parser $parser
 164+ * @param PPFrame $frame
 165+ */
 166+ public static function onReviewsRender( $input, array $args, Parser $parser, PPFrame $frame ) {
 167+ $tag = new ReviewsTag( $args, $input );
 168+ return $tag->render( $parser );
 169+ }
 170+
 171+ /**
 172+ * Register the reviews tag extension when the parser initializes.
 173+ *
 174+ * @since 0.1
 175+ *
 176+ * @param Parser $parser
 177+ *
 178+ * @return true
 179+ */
 180+ public static function onParserFirstCallInit( Parser &$parser ) {
 181+ $parser->setHook( 'reviews', __CLASS__ . '::onReviewsRender' );
 182+ return true;
 183+ }
155184
156185 }

Status & tagging log