Index: trunk/extensions/Reviews/specials/SpecialMyReviews.php |
— | — | @@ -104,7 +104,8 @@ |
105 | 105 | */ |
106 | 106 | protected function displayEditControl( Review $review ) { |
107 | 107 | $control = new ReviewControl( $review ); |
108 | | - $control->addToContext( $this ); |
| 108 | + $skin = $this->getSkin(); |
| 109 | + $control->addToContext( $skin ); |
109 | 110 | } |
110 | 111 | |
111 | 112 | } |
Index: trunk/extensions/Reviews/includes/ReviewControl.php |
— | — | @@ -9,8 +9,8 @@ |
10 | 10 | $this->review = $review; |
11 | 11 | } |
12 | 12 | |
13 | | - public function addToContext( ContextSource &$context ) { |
14 | | - $this->context = &$context; |
| 13 | + public function addToContext( ContextSource &$context = null ) { |
| 14 | + $this->context = $context; |
15 | 15 | |
16 | 16 | $out = $context->getOutput(); |
17 | 17 | $out->addModules( 'reviews.review.control' ); |
— | — | @@ -19,7 +19,8 @@ |
20 | 20 | 'class' => 'review-control', |
21 | 21 | ); |
22 | 22 | |
23 | | - $types = ReviewRating::getTypesForContext( $this->context ); |
| 23 | + $pageId = is_null( $this->review ) ? $context->getTitle()->getArticleID() : $this->review->getField( 'page_id' ); |
| 24 | + $types = ReviewRating::getTypesForPageID( $pageId ); |
24 | 25 | |
25 | 26 | if ( is_null( $this->review ) ) { |
26 | 27 | $ratings = array(); |
— | — | @@ -29,7 +30,7 @@ |
30 | 31 | } |
31 | 32 | |
32 | 33 | $review = array( |
33 | | - 'page_id' => $context->getTitle()->getArticleID(), |
| 34 | + 'page_id' => $pageId, |
34 | 35 | 'title' => '', |
35 | 36 | 'text' => '', |
36 | 37 | 'rating' => 0, |
Index: trunk/extensions/Reviews/includes/ReviewRating.php |
— | — | @@ -69,21 +69,39 @@ |
70 | 70 | * |
71 | 71 | * @since 0.1 |
72 | 72 | * |
73 | | - * @param ContextSource $context |
| 73 | + * @param integer $pageId |
74 | 74 | * |
75 | 75 | * @return array |
76 | 76 | */ |
77 | | - public static function getTypesForContext( ContextSource $context ) { |
| 77 | + public static function getTypesForPageID( $pageId ) { |
78 | 78 | $ratingsPerCat = ReviewsSettings::get( 'categoryRatings' ); |
79 | 79 | $ratings = array(); |
80 | 80 | |
81 | | - foreach ( $context->getOutput()->getCategories() as $cat ) { |
82 | | - if ( array_key_exists( $cat, $ratingsPerCat ) ) { |
83 | | - $ratings = array_merge( $ratings, $ratingsPerCat[$cat] ); |
| 81 | + $api = new ApiMain( new FauxRequest( array( |
| 82 | + 'action' => 'query', |
| 83 | + 'format' => 'json', |
| 84 | + 'prop' => 'categories', |
| 85 | + 'titles' => Title::newFromID( $pageId )->getFullText(), |
| 86 | + ), true ), true ); |
| 87 | + |
| 88 | + $api->execute(); |
| 89 | + $result = $api->getResultData(); |
| 90 | + |
| 91 | + if ( !array_key_exists( 'query', $result ) || !array_key_exists( 'pages', $result['query'] ) ) { |
| 92 | + return array(); |
| 93 | + } |
| 94 | + |
| 95 | + foreach ( $result['query']['pages'] as $page ) { |
| 96 | + foreach ( $page['categories'] as $cat ) { |
| 97 | + $cat = explode( ':', $cat['title'], 2 ); |
| 98 | + $cat = $cat[1]; |
| 99 | + if ( array_key_exists( $cat, $ratingsPerCat ) ) { |
| 100 | + $ratings = array_merge( $ratings, $ratingsPerCat[$cat] ); |
| 101 | + } |
84 | 102 | } |
85 | 103 | } |
86 | 104 | |
87 | 105 | return $ratings; |
88 | 106 | } |
89 | | - |
| 107 | + |
90 | 108 | } |