r103707 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103706‎ | r103707 | r103708 >
Date:20:35, 19 November 2011
Author:jeroendedauw
Status:reverted
Tags:
Comment:
added some preliminary code to add review controls
Modified paths:
  • /trunk/extensions/Reviews/Reviews.hooks.php (modified) (history)
  • /trunk/extensions/Reviews/Reviews.php (modified) (history)
  • /trunk/extensions/Reviews/Reviews.settings.php (modified) (history)
  • /trunk/extensions/Reviews/includes/ReviewControl.php (added) (history)
  • /trunk/extensions/Reviews/includes/ReviewRating.php (modified) (history)
  • /trunk/extensions/Reviews/resources/jquery.reviewControl.css (added) (history)
  • /trunk/extensions/Reviews/resources/jquery.reviewControl.js (added) (history)
  • /trunk/extensions/Reviews/resources/reviews.review.control.js (added) (history)

Diff [purge]

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 @@
6161 return array(
6262 );
6363 }
 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+ }
6477
6578 }
Index: trunk/extensions/Reviews/Reviews.settings.php
@@ -30,6 +30,7 @@
3131 return array(
3232 'reviewDeletionEnabled' => true,
3333 'enableTopLink' => true,
 34+ 'categoryRatings' => array()
3435 );
3536 }
3637
Index: trunk/extensions/Reviews/Reviews.php
@@ -55,6 +55,7 @@
5656 $wgAutoloadClasses['ApiSubmitReview'] = dirname( __FILE__ ) . '/api/ApiSubmitReview.php';
5757
5858 $wgAutoloadClasses['Review'] = dirname( __FILE__ ) . '/includes/Review.php';
 59+$wgAutoloadClasses['ReviewControl'] = dirname( __FILE__ ) . '/includes/ReviewControl.php';
5960 $wgAutoloadClasses['ReviewPager'] = dirname( __FILE__ ) . '/includes/ReviewPager.php';
6061 $wgAutoloadClasses['ReviewRating'] = dirname( __FILE__ ) . '/includes/ReviewRating.php';
6162 $wgAutoloadClasses['ReviewsDBObject'] = dirname( __FILE__ ) . '/includes/ReviewsDBObject.php';
@@ -79,6 +80,7 @@
8081 $wgHooks['UnitTestsList'][] = 'ReviewsHooks::registerUnitTests';
8182 $wgHooks['PersonalUrls'][] = 'ReviewsHooks::onPersonalUrls';
8283 $wgHooks['GetPreferences'][] = 'ReviewsHooks::onGetPreferences';
 84+$wgHooks['BeforePageDisplay'][] = 'ReviewsHooks::onBeforePageDisplay';
8385
8486 // Rights
8587 $wgAvailableRights[] = 'reviewsadmin';
@@ -107,6 +109,23 @@
108110 'remoteExtPath' => 'Reviews/resources'
109111 );
110112
 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+
111130 unset( $moduleTemplate );
112131
113132 $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 @@
103103
104104 return true;
105105 }
 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+ }
106115
107116 }

Status & tagging log