| Index: trunk/extensions/Reviews/includes/ReviewControl.php |
| — | — | @@ -0,0 +1,31 @@ |
| | 2 | +<?php |
| | 3 | + |
| | 4 | +class ReviewControl { |
| | 5 | + |
| | 6 | + protected $review; |
| | 7 | + protected $context; |
| | 8 | + |
| | 9 | + public function __construct( Review $review = null ) { |
| | 10 | + $this->review = $review; |
| | 11 | + } |
| | 12 | + |
| | 13 | + public function addToContext( ContextSource &$context ) { |
| | 14 | + $this->context = &$context; |
| | 15 | + |
| | 16 | + $out = $context->getOutput(); |
| | 17 | + $out->addModules( 'foo' ); |
| | 18 | + |
| | 19 | + $ratings = ReviewRating::getTypesForContext( $this->context ); |
| | 20 | + |
| | 21 | + $attribs = array( |
| | 22 | + 'class' => 'review-control', |
| | 23 | + ); |
| | 24 | + |
| | 25 | + if ( !is_null( $this->review ) ) { |
| | 26 | + $attribs['data-review'] = FormatJson::encode( $this->review->toArray() ); |
| | 27 | + } |
| | 28 | + |
| | 29 | + $out->addHTML( Html::element( 'div', $attribs ) ); |
| | 30 | + } |
| | 31 | + |
| | 32 | +} |
| \ No newline at end of file |
| Index: trunk/extensions/Reviews/includes/ReviewRating.php |
| — | — | @@ -60,5 +60,18 @@ |
| 61 | 61 | return array( |
| 62 | 62 | ); |
| 63 | 63 | } |
| | 64 | + |
| | 65 | + public static function getTypesForContext( ContextSource $context ) { |
| | 66 | + $ratingsPerCat = ReviewsSettings::get( 'categoryRatings' ); |
| | 67 | + $ratings = array(); |
| | 68 | + |
| | 69 | + foreach ( $context->getOutput()->getCategories() as $cat ) { |
| | 70 | + if ( array_key_exists( $cat, $ratingsPerCat ) ) { |
| | 71 | + $ratings = array_merge( $ratings, $ratingsPerCat[$cat] ); |
| | 72 | + } |
| | 73 | + } |
| | 74 | + |
| | 75 | + return $ratings; |
| | 76 | + } |
| 64 | 77 | |
| 65 | 78 | } |
| Index: trunk/extensions/Reviews/Reviews.settings.php |
| — | — | @@ -30,6 +30,7 @@ |
| 31 | 31 | return array( |
| 32 | 32 | 'reviewDeletionEnabled' => true, |
| 33 | 33 | 'enableTopLink' => true, |
| | 34 | + 'categoryRatings' => array() |
| 34 | 35 | ); |
| 35 | 36 | } |
| 36 | 37 | |
| Index: trunk/extensions/Reviews/Reviews.php |
| — | — | @@ -55,6 +55,7 @@ |
| 56 | 56 | $wgAutoloadClasses['ApiSubmitReview'] = dirname( __FILE__ ) . '/api/ApiSubmitReview.php'; |
| 57 | 57 | |
| 58 | 58 | $wgAutoloadClasses['Review'] = dirname( __FILE__ ) . '/includes/Review.php'; |
| | 59 | +$wgAutoloadClasses['ReviewControl'] = dirname( __FILE__ ) . '/includes/ReviewControl.php'; |
| 59 | 60 | $wgAutoloadClasses['ReviewPager'] = dirname( __FILE__ ) . '/includes/ReviewPager.php'; |
| 60 | 61 | $wgAutoloadClasses['ReviewRating'] = dirname( __FILE__ ) . '/includes/ReviewRating.php'; |
| 61 | 62 | $wgAutoloadClasses['ReviewsDBObject'] = dirname( __FILE__ ) . '/includes/ReviewsDBObject.php'; |
| — | — | @@ -79,6 +80,7 @@ |
| 80 | 81 | $wgHooks['UnitTestsList'][] = 'ReviewsHooks::registerUnitTests'; |
| 81 | 82 | $wgHooks['PersonalUrls'][] = 'ReviewsHooks::onPersonalUrls'; |
| 82 | 83 | $wgHooks['GetPreferences'][] = 'ReviewsHooks::onGetPreferences'; |
| | 84 | +$wgHooks['BeforePageDisplay'][] = 'ReviewsHooks::onBeforePageDisplay'; |
| 83 | 85 | |
| 84 | 86 | // Rights |
| 85 | 87 | $wgAvailableRights[] = 'reviewsadmin'; |
| — | — | @@ -107,6 +109,23 @@ |
| 108 | 110 | 'remoteExtPath' => 'Reviews/resources' |
| 109 | 111 | ); |
| 110 | 112 | |
| | 113 | +$wgResourceModules['jquery.reviewControl'] = $moduleTemplate + array( |
| | 114 | + 'scripts' => array( |
| | 115 | + 'jquery.reviewControl.js' |
| | 116 | + ), |
| | 117 | + 'styles' => array( |
| | 118 | + 'jquery.reviewControl.css' |
| | 119 | + ), |
| | 120 | + 'messages' => array( |
| | 121 | + ) |
| | 122 | +); |
| | 123 | + |
| | 124 | +$wgResourceModules['reviews.review.control'] = $moduleTemplate + array( |
| | 125 | + 'scripts' => array( |
| | 126 | + 'reviews.review.control.js' |
| | 127 | + ), |
| | 128 | +); |
| | 129 | + |
| 111 | 130 | unset( $moduleTemplate ); |
| 112 | 131 | |
| 113 | 132 | $egReviewsSettings = array(); |
| Index: trunk/extensions/Reviews/resources/reviews.review.control.js |
| — | — | @@ -0,0 +1,3 @@ |
| | 2 | +/** |
| | 3 | + * |
| | 4 | + */ |
| \ No newline at end of file |
| Index: trunk/extensions/Reviews/resources/jquery.reviewControl.css |
| — | — | @@ -0,0 +1 @@ |
| | 2 | +@CHARSET "UTF-8"; |
| \ No newline at end of file |
| Index: trunk/extensions/Reviews/resources/jquery.reviewControl.js |
| — | — | @@ -0,0 +1,3 @@ |
| | 2 | +/** |
| | 3 | + * |
| | 4 | + */ |
| \ No newline at end of file |
| Index: trunk/extensions/Reviews/Reviews.hooks.php |
| — | — | @@ -102,5 +102,14 @@ |
| 103 | 103 | |
| 104 | 104 | return true; |
| 105 | 105 | } |
| | 106 | + |
| | 107 | + public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) { |
| | 108 | + if ( $out->isArticle() && $skin->getRequest()->getText( 'action' ) !== 'edit' ) { |
| | 109 | + $control = new ReviewControl(); |
| | 110 | + $control->addToContext( $skin ); |
| | 111 | + } |
| | 112 | + |
| | 113 | + return true; |
| | 114 | + } |
| 106 | 115 | |
| 107 | 116 | } |