r105449 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105448‎ | r105449 | r105450 >
Date:19:04, 7 December 2011
Author:gregchiasson
Status:ok
Tags:
Comment:
AFTv5 - Re-enable isFeedbackEnabled check, move getAnonToken to the right place, and pass __METHOD__ into select in a couple of places where it was missing.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -32,12 +32,12 @@
3333 $params = $this->extractRequestParams();
3434
3535 // Anon token check
36 - $token = ApiArticleFeedbackv5Utils::getAnonToken( $params );
 36+ $token = $this->getAnonToken( $params );
3737
3838 // Is feedback enabled on this page check?
39 -# if ( !ApiArticleFeedbackv5Utils::isFeedbackEnabled( $params ) ) {
40 -# $this->dieUsage( 'ArticleFeedback is not enabled on this page', 'invalidpage' );
41 -# }
 39+ if ( !ApiArticleFeedbackv5Utils::isFeedbackEnabled( $params ) ) {
 40+ $this->dieUsage( 'ArticleFeedback is not enabled on this page', 'invalidpage' );
 41+ }
4242
4343 $feedbackId = $this->newFeedback( $params );
4444 $dbr = wfGetDB( DB_SLAVE );
@@ -313,7 +313,7 @@
314314 $revId = $params['revid'];
315315 $bucket = $params['bucket'];
316316 $link = $params['link'];
317 - $token = ApiArticleFeedbackv5Utils::getAnonToken( $params );
 317+ $token = $this->getAnonToken( $params );
318318 $timestamp = $dbw->timestamp();
319319 $ip = wfGetIP();
320320
@@ -379,6 +379,28 @@
380380 }
381381
382382 /**
 383+ * Gets the anonymous token from the params
 384+ *
 385+ * @param $params array the params
 386+ * @return string the token, or null if the user is not anonymous
 387+ */
 388+ public function getAnonToken( $params ) {
 389+ global $wgUser;
 390+ $token = null;
 391+ if ( $wgUser->isAnon() ) {
 392+ if ( !isset( $params['anontoken'] ) ) {
 393+ $this->dieUsageMsg( array( 'missingparam', 'anontoken' ) );
 394+ } elseif ( strlen( $params['anontoken'] ) != 32 ) {
 395+ $this->dieUsage( 'The anontoken is not 32 characters', 'invalidtoken' );
 396+ }
 397+ $token = $params['anontoken'];
 398+ } else {
 399+ $token = '';
 400+ }
 401+ return $token;
 402+ }
 403+
 404+ /**
383405 * Gets the allowed parameters
384406 *
385407 * @return array the params info, indexed by allowed key
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php
@@ -20,31 +20,7 @@
2121 * @subpackage Api
2222 */
2323 class ApiArticleFeedbackv5Utils {
24 -
2524 /**
26 - * Gets the anonymous token from the params
27 - *
28 - * @param $params array the params
29 - * @return string the token, or null if the user is not anonymous
30 - */
31 - public static function getAnonToken( $params ) {
32 - global $wgUser;
33 - $token = null;
34 - if ( $wgUser->isAnon() ) {
35 -# TODO: error handling
36 - if ( !isset( $params['anontoken'] ) ) {
37 -# $this->dieUsageMsg( array( 'missingparam', 'anontoken' ) );
38 - } elseif ( strlen( $params['anontoken'] ) != 32 ) {
39 -# $this->dieUsage( 'The anontoken is not 32 characters', 'invalidtoken' );
40 - }
41 - $token = $params['anontoken'];
42 - } else {
43 - $token = '';
44 - }
45 - return $token;
46 - }
47 -
48 - /**
4925 * Returns whether feedback is enabled for this page
5026 *
5127 * @param $params array the params
@@ -100,7 +76,9 @@
10177 $dbr = wfGetDB( DB_SLAVE );
10278 $rv = $dbr->select(
10379 'aft_article_field',
104 - array( 'afi_name', 'afi_id', 'afi_data_type', 'afi_bucket_id' )
 80+ array( 'afi_name', 'afi_id', 'afi_data_type', 'afi_bucket_id' ),
 81+ null,
 82+ __METHOD__
10583 );
10684 return $rv;
10785 }
@@ -122,7 +100,9 @@
123101 $dbr = wfGetDB( DB_SLAVE );
124102 $rows = $dbr->select(
125103 'aft_article_field_option',
126 - array( 'afo_option_id', 'afo_field_id', 'afo_name' )
 104+ array( 'afo_option_id', 'afo_field_id', 'afo_name' ),
 105+ null,
 106+ __METHOD__
127107 );
128108 $rv = array();
129109 foreach ( $rows as $row ) {
@@ -130,6 +110,5 @@
131111 }
132112 return $rv;
133113 }
134 -
135114 }
136115

Status & tagging log