r104186 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104185‎ | r104186 | r104187 >
Date:18:15, 24 November 2011
Author:jeroendedauw
Status:reverted
Tags:
Comment:
work on myreviews
Modified paths:
  • /trunk/extensions/Reviews/includes/ReviewControl.php (modified) (history)
  • /trunk/extensions/Reviews/includes/ReviewRating.php (modified) (history)
  • /trunk/extensions/Reviews/specials/SpecialMyReviews.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Reviews/specials/SpecialMyReviews.php
@@ -104,7 +104,8 @@
105105 */
106106 protected function displayEditControl( Review $review ) {
107107 $control = new ReviewControl( $review );
108 - $control->addToContext( $this );
 108+ $skin = $this->getSkin();
 109+ $control->addToContext( $skin );
109110 }
110111
111112 }
Index: trunk/extensions/Reviews/includes/ReviewControl.php
@@ -9,8 +9,8 @@
1010 $this->review = $review;
1111 }
1212
13 - public function addToContext( ContextSource &$context ) {
14 - $this->context = &$context;
 13+ public function addToContext( ContextSource &$context = null ) {
 14+ $this->context = $context;
1515
1616 $out = $context->getOutput();
1717 $out->addModules( 'reviews.review.control' );
@@ -19,7 +19,8 @@
2020 'class' => 'review-control',
2121 );
2222
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 );
2425
2526 if ( is_null( $this->review ) ) {
2627 $ratings = array();
@@ -29,7 +30,7 @@
3031 }
3132
3233 $review = array(
33 - 'page_id' => $context->getTitle()->getArticleID(),
 34+ 'page_id' => $pageId,
3435 'title' => '',
3536 'text' => '',
3637 'rating' => 0,
Index: trunk/extensions/Reviews/includes/ReviewRating.php
@@ -69,21 +69,39 @@
7070 *
7171 * @since 0.1
7272 *
73 - * @param ContextSource $context
 73+ * @param integer $pageId
7474 *
7575 * @return array
7676 */
77 - public static function getTypesForContext( ContextSource $context ) {
 77+ public static function getTypesForPageID( $pageId ) {
7878 $ratingsPerCat = ReviewsSettings::get( 'categoryRatings' );
7979 $ratings = array();
8080
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+ }
84102 }
85103 }
86104
87105 return $ratings;
88106 }
89 -
 107+
90108 }

Status & tagging log