r107103 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107102‎ | r107103 | r107104 >
Date:19:57, 22 December 2011
Author:bsitu
Status:ok
Tags:
Comment:
Disallow anonymouse user to unmark "Mark As Helpful" item
Modified paths:
  • /trunk/extensions/MarkAsHelpful/api/ApiMarkAsHelpful.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php
@@ -201,11 +201,15 @@
202202 }
203203
204204 /**
205 - * Unmark an item as helpful
 205+ * Unmark an item as helpful, we don't allow anonymous user to unarmk an item
206206 * @param $currentUser Object - the current user who is browsing the site
207207 */
208208 public function unmark( $currentUser ) {
209209
 210+ if ( $currentUser->isAnon() ) {
 211+ return;
 212+ }
 213+
210214 if ( $this->getProperty( 'mah_id' ) ) {
211215
212216 if ( !$this->getProperty( 'mah_type' ) ) {
@@ -218,10 +222,9 @@
219223
220224 if ( $user ) {
221225
222 - if ( $currentUser->isAnon() == $user->isAnon() ) {
 226+ if ( !$user->isAnon() ) {
223227
224 - if ( $currentUser->getId() == $user->getId() ||
225 - $currentUser->getName() == $user->getName() ) {
 228+ if ( $currentUser->getId() == $user->getId() ) {
226229
227230 $dbw = wfGetDB( DB_MASTER );
228231
Index: trunk/extensions/MarkAsHelpful/api/ApiMarkAsHelpful.php
@@ -8,7 +8,12 @@
99 if ( $wgUser->isBlocked( false ) ) {
1010 $this->dieUsageMsg( array( 'blockedtext' ) );
1111 }
12 -
 12+
 13+ // Disallow anonymous user to unmark an 'Mark As Helpful' item
 14+ if ( $wgUser->isAnon() && $params['type'] == 'unmark' ) {
 15+ $this->noPermissionError();
 16+ }
 17+
1318 $params = $this->extractRequestParams();
1419
1520 $isAbleToMark = true;
@@ -17,7 +22,7 @@
1823 wfRunHooks( 'onMarkItemAsHelpful', array( $params['mahaction'], $params['type'], $params['item'], $wgUser, &$isAbleToMark ) );
1924
2025 if ( !$isAbleToMark ) {
21 - $this->dieUsage( "You don't have permission to do that", 'permission-denied' );
 26+ $this->noPermissionError();
2227 }
2328
2429 $error = false;
@@ -66,7 +71,11 @@
6772 }
6873 $this->getResult()->addValue( null, $this->getModuleName(), $result );
6974 }
70 -
 75+
 76+ private function noPermissionError() {
 77+ $this->dieUsage( "You don't have permission to do that", 'permission-denied' );
 78+ }
 79+
7180 public function needsToken() {
7281 return true;
7382 }

Status & tagging log