Index: trunk/extensions/Reviews/specials/SpecialReviews.php |
— | — | @@ -54,25 +54,38 @@ |
55 | 55 | return false; |
56 | 56 | } |
57 | 57 | |
| 58 | + $out = $this->getOutput(); |
| 59 | + |
| 60 | + if ( $this->getRequest()->getInt( 'deleted' ) === 1 ) { |
| 61 | + $out->addHTML( |
| 62 | + '<div class="successbox"><strong><p>' |
| 63 | + . wfMsgExt( 'reviews-reviews-deleted', array( 'parseinline' ) ) |
| 64 | + . '</p></strong></div><hr style="display: block; clear: both; visibility: hidden;" />' |
| 65 | + ); |
| 66 | + } |
| 67 | + |
58 | 68 | if ( $subPage === '' ) { |
59 | | - $this->getOutput()->addWikiMsg( 'reviews-reviews-header' ); |
| 69 | + $out->addWikiMsg( 'reviews-reviews-header' ); |
60 | 70 | $this->displayReviewList(); |
61 | 71 | } |
62 | 72 | else { |
63 | 73 | $review = Review::selectRow( null, array( 'id' => $subPage ) ); |
64 | 74 | |
65 | 75 | if ( $review === false ) { |
66 | | - $this->getOutput()->addWikiMsg( 'reviews-reviews-nosuchreview' ); |
| 76 | + $out->addWikiMsg( 'reviews-reviews-nosuchreview' ); |
67 | 77 | $this->displayReviewList(); |
68 | 78 | } |
69 | 79 | else { |
70 | | - $this->getOutput()->addModules( 'ext.reviews.special.reviews' ); |
| 80 | + $out->addModules( 'ext.reviews.special.reviews' ); |
71 | 81 | |
72 | | - $this->getOutput()->addWikiMsg( 'reviews-reviews-editheader' ); |
| 82 | + $out->addWikiMsg( 'reviews-reviews-editheader' ); |
73 | 83 | |
74 | 84 | $this->displaySummary( $review ); |
75 | 85 | |
76 | | - $this->getOutput()->addHTML( $review->getHTML() ); |
| 86 | + $out->addHTML( |
| 87 | + Html::element( 'h3', array(), wfMsg( 'reviews-reviews-reviewtext' ) ) . |
| 88 | + '<div class="review-text-content"><p>' . htmlspecialchars( $review->getField( 'text' ) ) . '</p></div>' |
| 89 | + ); |
77 | 90 | |
78 | 91 | $this->displayAdminControls( $review ); |
79 | 92 | } |
— | — | @@ -170,6 +183,22 @@ |
171 | 184 | * @param Review $review |
172 | 185 | */ |
173 | 186 | protected function displayAdminControls( Review $review ) { |
| 187 | + $out = $this->getOutput(); |
| 188 | + |
| 189 | + $out->addHTML( Html::element( 'h3', array(), wfMsg( 'reviews-reviews-controls' ) ) ); |
| 190 | + |
| 191 | + if ( ReviewsSettings::get( 'reviewDeletionEnabled' ) ) { |
| 192 | + $out->addHTML( Html::element( |
| 193 | + 'button', |
| 194 | + array( |
| 195 | + 'class' => 'reviews-delete-button', |
| 196 | + 'data-review-id' => $review->getId(), |
| 197 | + // TODO: might want to add invalidation sign here so master db can be used on target page and we don't get rep lag ghosts. |
| 198 | + 'data-completion-url' => $this->getTitle()->getLocalURL( array( 'deleted' => 1 ) ) |
| 199 | + ), |
| 200 | + wfMsg( 'reviews-reviews-delete' ) |
| 201 | + ) ); |
| 202 | + } |
174 | 203 | } |
175 | 204 | |
176 | 205 | } |
Index: trunk/extensions/Reviews/Reviews.i18n.php |
— | — | @@ -75,6 +75,11 @@ |
76 | 76 | 'reviews-reviews-header' => 'This page lists all reviews posted on this wiki', |
77 | 77 | 'reviews-reviews-nosuchreview' => 'You do not have a review with the provided ID, it might have been deleted. All reviews are listed below.', |
78 | 78 | 'reviews-reviews-editheader' => 'On this page you can manage this review. You can also view a list of [[Special:Reviews|all reviews]].', |
| 79 | + 'reviews-reviews-deleted' => 'The review was deleted successfully', |
| 80 | + 'reviews-reviews-reviewtext' => 'Review text', |
| 81 | + 'reviews-reviews-controls' => 'Administration controls', |
| 82 | + 'reviews-reviews-delete' => 'Remove this review', |
| 83 | + 'reviews-reviews-delete-confirm' => 'Are you sure you want to delete this review?', |
79 | 84 | |
80 | 85 | 'reviews-reviews-header-title' => 'Review title', |
81 | 86 | 'reviews-reviews-header-page' => 'For page', |
— | — | @@ -144,6 +149,11 @@ |
145 | 150 | 'reviews-reviews-header' => "Line on top of a page explaining it's function", |
146 | 151 | 'reviews-reviews-nosuchreview' => "Line on top of a page explaining it's function", |
147 | 152 | 'reviews-reviews-editheader' => "Line on top of a page explaining it's function", |
| 153 | + 'reviews-reviews-deleted' => 'Message indicating that a review was succesfully deleted.', |
| 154 | + 'reviews-reviews-reviewtext' => 'Level 3 header', |
| 155 | + 'reviews-reviews-controls' => 'Level 3 header', |
| 156 | + 'reviews-reviews-delete' => 'Delete button text', |
| 157 | + 'reviews-reviews-delete-confirm' => 'Message asking for confirmation of deletion shown in a confirmation dialog', |
148 | 158 | |
149 | 159 | 'reviews-pager-no-results' => 'Informs the user that there are no results', |
150 | 160 | 'reviews-pager-post-time' => 'Tabele column header', |
Index: trunk/extensions/Reviews/api/ApiDeleteReviews.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | $this->dieUsage( 'Review deletion is disabled', 'reviewdeletiondisabled' ); |
21 | 21 | } |
22 | 22 | |
23 | | - if ( !$this->getUser()->isAllowed( 'reviewadmin' ) || $this->getUser()->isBlocked() ) { |
| 23 | + if ( !$this->getUser()->isAllowed( 'reviewsadmin' ) || $this->getUser()->isBlocked() ) { |
24 | 24 | $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
25 | 25 | } |
26 | 26 | |
— | — | @@ -43,11 +43,6 @@ |
44 | 44 | return true; |
45 | 45 | } |
46 | 46 | |
47 | | - public function getTokenSalt() { |
48 | | - $params = $this->extractRequestParams(); |
49 | | - return 'deletereview' . implode( '|', $params['ids'] ); |
50 | | - } |
51 | | - |
52 | 47 | public function mustBePosted() { |
53 | 48 | return true; |
54 | 49 | } |
— | — | @@ -66,7 +61,7 @@ |
67 | 62 | public function getParamDescription() { |
68 | 63 | return array( |
69 | 64 | 'ids' => 'The IDs of the reviews to delete', |
70 | | - 'token' => 'Edit token, salted with the review ids', |
| 65 | + 'token' => 'Edit token. You can get one of these through prop=info.', |
71 | 66 | ); |
72 | 67 | } |
73 | 68 | |
Index: trunk/extensions/Reviews/Reviews.php |
— | — | @@ -227,8 +227,11 @@ |
228 | 228 | 'reviews.special.js', |
229 | 229 | ), |
230 | 230 | 'dependencies' => array( |
231 | | - 'jquery.reviewState' |
| 231 | + 'jquery.reviewState', 'jquery.ui.button', 'ext.reviews' |
232 | 232 | ), |
| 233 | + 'messages' => array( |
| 234 | + 'reviews-reviews-delete-confirm' |
| 235 | + ), |
233 | 236 | ); |
234 | 237 | |
235 | 238 | unset( $moduleTemplate ); |
Index: trunk/extensions/Reviews/resources/reviews.review.js |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | }; |
20 | 20 | |
21 | 21 | this.save = function( callback ) { |
22 | | - requestArgs = { |
| 22 | + var requestArgs = { |
23 | 23 | 'action': 'submitreview', |
24 | 24 | 'format': 'json', |
25 | 25 | 'token': mw.user.tokens.get( 'editToken' ), |
— | — | @@ -47,6 +47,23 @@ |
48 | 48 | |
49 | 49 | reviews.Review.prototype = { |
50 | 50 | |
| 51 | + remove: function( callback ) { |
| 52 | + var requestArgs = { |
| 53 | + 'action': 'deletereviews', |
| 54 | + 'format': 'json', |
| 55 | + 'token': mw.user.tokens.get( 'editToken' ), |
| 56 | + 'ids': this.fields.id |
| 57 | + }; |
| 58 | + |
| 59 | + $.post( |
| 60 | + wgScriptPath + '/api.php', |
| 61 | + requestArgs, |
| 62 | + function( data ) { |
| 63 | + callback( data.hasOwnProperty( 'success' ) && data.success ); |
| 64 | + } |
| 65 | + ); |
| 66 | + } |
| 67 | + |
51 | 68 | }; |
52 | 69 | |
53 | 70 | })( window.jQuery, window.mediaWiki, window.reviews ); |
\ No newline at end of file |
Index: trunk/extensions/Reviews/resources/reviews.special.js |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
8 | 8 | */ |
9 | 9 | |
10 | | -(function( $, mw ) { |
| 10 | +(function( $, mw, reviews ) { |
11 | 11 | |
12 | 12 | $( document ).ready( function() { |
13 | 13 | |
— | — | @@ -14,6 +14,25 @@ |
15 | 15 | $( e ).reviewState(); |
16 | 16 | } ); |
17 | 17 | |
| 18 | + $( '.reviews-delete-button' ).button().click( function() { |
| 19 | + if ( confirm( mw.msg( 'reviews-reviews-delete-confirm' ) ) ) { |
| 20 | + var $this = $( this ); |
| 21 | + var review = new reviews.Review( { 'id': $this.attr( 'data-review-id' ) } ); |
| 22 | + $this.button( 'disable' ); |
| 23 | + |
| 24 | + review.remove( function( success ) { |
| 25 | + if ( success ) { |
| 26 | + window.location = $this.attr( 'data-completion-url' ); |
| 27 | + } |
| 28 | + else { |
| 29 | + // TODO |
| 30 | + alert( 'The review could not be removed.' ); |
| 31 | + $this.button( 'enable' ); |
| 32 | + } |
| 33 | + } ); |
| 34 | + } |
| 35 | + } ); |
| 36 | + |
18 | 37 | } ); |
19 | 38 | |
20 | | -})( window.jQuery, window.mediaWiki ); |
| 39 | +})( window.jQuery, window.mediaWiki, window.reviews ); |