Index: trunk/extensions/Reviews/specials/SpecialReviews.php |
— | — | @@ -67,7 +67,12 @@ |
68 | 68 | } |
69 | 69 | else { |
70 | 70 | $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 ); |
72 | 77 | } |
73 | 78 | } |
74 | 79 | } |
— | — | @@ -78,7 +83,7 @@ |
79 | 84 | * @since 0.1 |
80 | 85 | */ |
81 | 86 | protected function displayReviewList() { |
82 | | - $reviewPager = new ReviewPager( array() ); |
| 87 | + $reviewPager = new ReviewPager( array(), $this->getName() ); |
83 | 88 | |
84 | 89 | if ( $reviewPager->getNumRows() ) { |
85 | 90 | $this->getOutput()->addHTML( |
— | — | @@ -91,5 +96,25 @@ |
92 | 97 | $this->getOutput()->addWikiMsg( 'reviews-pager-no-results' ); |
93 | 98 | } |
94 | 99 | } |
| 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 | + } |
95 | 120 | |
96 | 121 | } |
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 @@ |
20 | 20 | const STATUS_REVIEWED = 2; |
21 | 21 | |
22 | 22 | /** |
23 | | - * |
| 23 | + * The ratings that are part of this review. |
24 | 24 | * |
25 | 25 | * @since 0.1 |
26 | 26 | * @var array of ReviewRating |
— | — | @@ -277,5 +277,36 @@ |
278 | 278 | |
279 | 279 | return wfMsg( 'reviews-state-' . $map[$state] ); |
280 | 280 | } |
| 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 | + } |
281 | 312 | |
282 | 313 | } |
Index: trunk/extensions/Reviews/Reviews.php |
— | — | @@ -59,6 +59,7 @@ |
60 | 60 | $wgAutoloadClasses['ReviewPager'] = dirname( __FILE__ ) . '/includes/ReviewPager.php'; |
61 | 61 | $wgAutoloadClasses['ReviewRating'] = dirname( __FILE__ ) . '/includes/ReviewRating.php'; |
62 | 62 | $wgAutoloadClasses['ReviewsDBObject'] = dirname( __FILE__ ) . '/includes/ReviewsDBObject.php'; |
| 63 | +$wgAutoloadClasses['ReviewsTag'] = dirname( __FILE__ ) . '/includes/ReviewsTag.php'; |
63 | 64 | |
64 | 65 | $wgAutoloadClasses['SpecialMyReviews'] = dirname( __FILE__ ) . '/specials/SpecialMyReviews.php'; |
65 | 66 | $wgAutoloadClasses['SpecialReviews'] = dirname( __FILE__ ) . '/specials/SpecialReviews.php'; |
— | — | @@ -81,6 +82,7 @@ |
82 | 83 | $wgHooks['PersonalUrls'][] = 'ReviewsHooks::onPersonalUrls'; |
83 | 84 | $wgHooks['GetPreferences'][] = 'ReviewsHooks::onGetPreferences'; |
84 | 85 | $wgHooks['BeforePageDisplay'][] = 'ReviewsHooks::onBeforePageDisplay'; |
| 86 | +$wgHooks['ParserFirstCallInit'][] = 'ReviewsHooks::onParserFirstCallInit'; |
85 | 87 | |
86 | 88 | // Rights |
87 | 89 | $wgAvailableRights[] = 'reviewsadmin'; |
Index: trunk/extensions/Reviews/Reviews.hooks.php |
— | — | @@ -151,5 +151,34 @@ |
152 | 152 | |
153 | 153 | return true; |
154 | 154 | } |
| 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 | + } |
155 | 184 | |
156 | 185 | } |