Index: trunk/extensions/Reviews/includes/ReviewPager.php |
— | — | @@ -38,6 +38,8 @@ |
39 | 39 | |
40 | 40 | // when MW 1.19 becomes min, we want to pass an IContextSource $context here. |
41 | 41 | parent::__construct(); |
| 42 | + |
| 43 | + $this->getOutput()->addModules( 'ext.reviews.pager' ); |
42 | 44 | } |
43 | 45 | |
44 | 46 | /** |
— | — | @@ -121,10 +123,17 @@ |
122 | 124 | $value = $this->getLang()->timeanddate( $value, true ); |
123 | 125 | break; |
124 | 126 | case 'review_state': |
125 | | - $value = Review::getStateMessage( $value ); |
| 127 | + $value = htmlspecialchars( Review::getStateMessage( $value ) ); |
126 | 128 | if ( $this->getUser()->isAllowed( 'reviewsadmin' ) ) { |
127 | | - $action = $this->mCurrentRow->review_state == Review::STATUS_FLAGGED ? 'unflag' : 'flag'; |
128 | | - $value .= ' (' . wfMsgHtml( 'reviews-pager-' . $action ) . ')'; |
| 129 | + $value = Html::element( |
| 130 | + 'div', |
| 131 | + array( |
| 132 | + 'class' => 'reviews-state-controls', |
| 133 | + 'data-review-id' => $this->mCurrentRow->review_id, |
| 134 | + 'data-review-state' => Review::getStateString( $this->mCurrentRow->review_state ), |
| 135 | + ), |
| 136 | + $value |
| 137 | + ); |
129 | 138 | } |
130 | 139 | break; |
131 | 140 | case 'review_page_id': |
Index: trunk/extensions/Reviews/includes/Review.php |
— | — | @@ -18,6 +18,12 @@ |
19 | 19 | const STATUS_FLAGGED = 1; |
20 | 20 | const STATUS_REVIEWED = 2; |
21 | 21 | |
| 22 | + protected static $stateStringMap = array( |
| 23 | + self::STATUS_NEW => 'new', |
| 24 | + self::STATUS_FLAGGED => 'flagged', |
| 25 | + self::STATUS_REVIEWED => 'reviewed', |
| 26 | + ); |
| 27 | + |
22 | 28 | /** |
23 | 29 | * The ratings that are part of this review. |
24 | 30 | * |
— | — | @@ -269,13 +275,31 @@ |
270 | 276 | * @return string |
271 | 277 | */ |
272 | 278 | public static function getStateMessage( $state ) { |
273 | | - $map = array( |
274 | | - self::STATUS_NEW => 'new', |
275 | | - self::STATUS_FLAGGED => 'flagged', |
276 | | - self::STATUS_REVIEWED => 'reviewed', |
277 | | - ); |
| 279 | + return wfMsg( 'reviews-state-' . self::getStateString( $state ) ); |
| 280 | + } |
| 281 | + |
| 282 | + /** |
| 283 | + * Get a string constant for the state, rather then it's usual |
| 284 | + * integer value. |
| 285 | + * |
| 286 | + * @since 0.1 |
| 287 | + * |
| 288 | + * @param Review::STATE_ $state |
| 289 | + * |
| 290 | + * @return string |
| 291 | + */ |
| 292 | + public static function getStateString( $state ) { |
| 293 | + return self::$stateStringMap[$state]; |
| 294 | + } |
| 295 | + |
| 296 | + public static function getStateForString( $string ) { |
| 297 | + static $map = false; |
278 | 298 | |
279 | | - return wfMsg( 'reviews-state-' . $map[$state] ); |
| 299 | + if ( $map === false ) { |
| 300 | + $map = array_flip( self::$stateStringMap ); |
| 301 | + } |
| 302 | + |
| 303 | + return $map[$string]; |
280 | 304 | } |
281 | 305 | |
282 | 306 | /** |
Index: trunk/extensions/Reviews/Reviews.i18n.php |
— | — | @@ -46,7 +46,7 @@ |
47 | 47 | // Review states |
48 | 48 | 'reviews-state-new' => 'New', |
49 | 49 | 'reviews-state-flagged' => 'Flagged', |
50 | | - 'reviews-state-reviewed' => 'Reviewed', |
| 50 | + 'reviews-state-reviewed' => 'Approved', |
51 | 51 | |
52 | 52 | // Preferences |
53 | 53 | 'prefs-reviews' => 'Reviews', |
— | — | @@ -85,8 +85,13 @@ |
86 | 86 | 'reviews-pager-page' => 'For page', |
87 | 87 | 'reviews-pager-rating' => 'Rating', |
88 | 88 | 'reviews-pager-deleted' => 'The page was deleted', |
89 | | - 'reviews-pager-flag' => 'Flag', |
90 | | - 'reviews-pager-unflag' => 'Unflag', |
| 89 | + 'reviews-pager-change-new' => 'Unflag', |
| 90 | + 'reviews-pager-change-flagged' => 'Flag', |
| 91 | + 'reviews-pager-change-reviewed' => 'Approve', |
| 92 | + 'reviews-pager-confirm-flagged' => 'Are you sure you want to flag this review?', |
| 93 | + 'reviews-pager-confirm-new' => 'Are you sure you want to unflag this review?', |
| 94 | + 'reviews-pager-confirm-reviewed' => 'Are you sure you want to mark this review as reviewed?', |
| 95 | + 'reviews-pager-updating' => 'Updating...', |
91 | 96 | ); |
92 | 97 | |
93 | 98 | /** Message documentation (Message documentation) |
— | — | @@ -142,4 +147,7 @@ |
143 | 148 | 'reviews-pager-deleted' => 'Informs the user a page was deleted', |
144 | 149 | 'reviews-pager-flag' => 'Link text to flag a review', |
145 | 150 | 'reviews-pager-unflag' => 'Link text to unflag a review', |
| 151 | + 'reviews-pager-confirm-flag' => 'Confirmation dialog message', |
| 152 | + 'reviews-pager-confirm-unflag' => 'Confirmation dialog message', |
| 153 | + 'reviews-pager-updating' => 'Message indicating the status is being updated', |
146 | 154 | ); |
Index: trunk/extensions/Reviews/api/ApiFlagReview.php |
— | — | @@ -1,93 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * API module to delete reviews. |
6 | | - * |
7 | | - * @since 0.1 |
8 | | - * |
9 | | - * @file ApiDeleteReviews.php |
10 | | - * @ingroup Reviews |
11 | | - * @ingroup API |
12 | | - * |
13 | | - * @licence GNU GPL v3+ |
14 | | - * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | | - */ |
16 | | -class ApiDeleteReviews extends ApiBase { |
17 | | - |
18 | | - public function execute() { |
19 | | - |
20 | | - if ( !$this->getUser()->isAllowed( 'reviewadmin' ) || $this->getUser()->isBlocked() ) { |
21 | | - $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
22 | | - } |
23 | | - |
24 | | - $params = $this->extractRequestParams(); |
25 | | - |
26 | | - $everythingOk = true; |
27 | | - |
28 | | - foreach ( $params['ids'] as $id ) { |
29 | | - $review = new Review( array( 'id' => $id ) ); |
30 | | - $everythingOk = $review->removeAllFromDB() && $everythingOk; |
31 | | - } |
32 | | - |
33 | | - $this->getResult()->addValue( |
34 | | - null, |
35 | | - 'success', |
36 | | - $everythingOk |
37 | | - ); |
38 | | - } |
39 | | - |
40 | | - public function needsToken() { |
41 | | - return true; |
42 | | - } |
43 | | - |
44 | | - public function mustBePosted() { |
45 | | - return true; |
46 | | - } |
47 | | - |
48 | | - public function getAllowedParams() { |
49 | | - return array( |
50 | | - 'ids' => array( |
51 | | - ApiBase::PARAM_TYPE => 'integer', |
52 | | - ApiBase::PARAM_REQUIRED => true, |
53 | | - ApiBase::PARAM_ISMULTI => true, |
54 | | - ), |
55 | | - 'state' => array( |
56 | | - ApiBase::PARAM_TYPE => array( 'flagged', 'reviewed', 'new' ), |
57 | | - ApiBase::PARAM_DFLT => 'flagged', |
58 | | - ), |
59 | | - 'token' => null, |
60 | | - ); |
61 | | - } |
62 | | - |
63 | | - public function getParamDescription() { |
64 | | - return array( |
65 | | - 'ids' => 'The IDs of the reviews to flag', |
66 | | - 'state' => 'The state to set for the review.', |
67 | | - 'token' => 'Edit token. You can get one of these through prop=info.', |
68 | | - ); |
69 | | - } |
70 | | - |
71 | | - public function getDescription() { |
72 | | - return array( |
73 | | - 'API module for flagging reviews. By default their state will be changed to flagged, but using the state parameter, other states can also be set.' |
74 | | - ); |
75 | | - } |
76 | | - |
77 | | - public function getPossibleErrors() { |
78 | | - return array_merge( parent::getPossibleErrors(), array( |
79 | | - ) ); |
80 | | - } |
81 | | - |
82 | | - protected function getExamples() { |
83 | | - return array( |
84 | | - 'api.php?action=flagreview&ids=42', |
85 | | - 'api.php?action=flagreview&ids=4|2', |
86 | | - 'api.php?action=flagreview&ids=42&state=reviewed', |
87 | | - ); |
88 | | - } |
89 | | - |
90 | | - public function getVersion() { |
91 | | - return __CLASS__ . ': $Id$'; |
92 | | - } |
93 | | - |
94 | | -} |
Index: trunk/extensions/Reviews/api/ApiFlagReviews.php |
— | — | @@ -0,0 +1,98 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to flag reviews. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ApiFlagReviews.php |
| 10 | + * @ingroup Reviews |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiFlagReviews extends ApiBase { |
| 17 | + |
| 18 | + public function execute() { |
| 19 | + |
| 20 | + if ( $this->getUser()->isBlocked() ) { |
| 21 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 22 | + } |
| 23 | + |
| 24 | + $params = $this->extractRequestParams(); |
| 25 | + |
| 26 | + $state = Review::getStateForString( $params['state'] ); |
| 27 | + |
| 28 | + if ( $state == Review::STATUS_FLAGGED && !$this->getUser()->isAllowed( 'flagreview' ) ) { |
| 29 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 30 | + } |
| 31 | + |
| 32 | + if ( in_array( $state, array( Review::STATUS_REVIEWED, Review::STATUS_NEW ) ) |
| 33 | + && !$this->getUser()->isAllowed( 'reviewreview' ) ) { |
| 34 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 35 | + } |
| 36 | + |
| 37 | + $this->getResult()->addValue( |
| 38 | + null, |
| 39 | + 'success', |
| 40 | + Review::update( array( 'state' => $state ), array( 'id' => $params['ids'] ) ) |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + public function needsToken() { |
| 45 | + return true; |
| 46 | + } |
| 47 | + |
| 48 | + public function mustBePosted() { |
| 49 | + return true; |
| 50 | + } |
| 51 | + |
| 52 | + public function getAllowedParams() { |
| 53 | + return array( |
| 54 | + 'ids' => array( |
| 55 | + ApiBase::PARAM_TYPE => 'integer', |
| 56 | + ApiBase::PARAM_REQUIRED => true, |
| 57 | + ApiBase::PARAM_ISMULTI => true, |
| 58 | + ), |
| 59 | + 'state' => array( |
| 60 | + ApiBase::PARAM_TYPE => array( 'flagged', 'reviewed', 'new' ), |
| 61 | + ApiBase::PARAM_DFLT => 'flagged', |
| 62 | + ), |
| 63 | + 'token' => null, |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + public function getParamDescription() { |
| 68 | + return array( |
| 69 | + 'ids' => 'The IDs of the reviews to flag', |
| 70 | + 'state' => 'The state to set for the review.', |
| 71 | + 'token' => 'Edit token. You can get one of these through prop=info.', |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + public function getDescription() { |
| 76 | + return array( |
| 77 | + 'API module for flagging reviews. By default their state will be changed to flagged, but using the state parameter, other states can also be set.' |
| 78 | + ); |
| 79 | + } |
| 80 | + |
| 81 | + public function getPossibleErrors() { |
| 82 | + return array_merge( parent::getPossibleErrors(), array( |
| 83 | + ) ); |
| 84 | + } |
| 85 | + |
| 86 | + protected function getExamples() { |
| 87 | + return array( |
| 88 | + 'api.php?action=flagreview&ids=42', |
| 89 | + 'api.php?action=flagreview&ids=4|2', |
| 90 | + 'api.php?action=flagreview&ids=42&state=reviewed', |
| 91 | + 'api.php?action=flagreview&ids=4|2&state=new', |
| 92 | + ); |
| 93 | + } |
| 94 | + |
| 95 | + public function getVersion() { |
| 96 | + return __CLASS__ . ': $Id$'; |
| 97 | + } |
| 98 | + |
| 99 | +} |
Property changes on: trunk/extensions/Reviews/api/ApiFlagReviews.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 100 | + Id |
Index: trunk/extensions/Reviews/Reviews.php |
— | — | @@ -195,6 +195,24 @@ |
196 | 196 | ), |
197 | 197 | ); |
198 | 198 | |
| 199 | +$wgResourceModules['ext.reviews.pager'] = $moduleTemplate + array( |
| 200 | + 'scripts' => array( |
| 201 | + 'reviews.pager.js', |
| 202 | + ), |
| 203 | + 'messages' => array( |
| 204 | + 'reviews-pager-change-new', |
| 205 | + 'reviews-pager-change-flagged', |
| 206 | + 'reviews-pager-change-reviewed', |
| 207 | + 'reviews-pager-confirm-flagged', |
| 208 | + 'reviews-pager-confirm-new', |
| 209 | + 'reviews-pager-confirm-reviewed', |
| 210 | + 'reviews-pager-updating', |
| 211 | + 'reviews-state-new', |
| 212 | + 'reviews-state-flagged' , |
| 213 | + 'reviews-state-reviewed', |
| 214 | + ), |
| 215 | +); |
| 216 | + |
199 | 217 | unset( $moduleTemplate ); |
200 | 218 | |
201 | 219 | $egReviewsSettings = array(); |