r72126 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72125‎ | r72126 | r72127 >
Date:17:50, 1 September 2010
Author:reedy
Status:deferred
Tags:
Comment:
Deal with an anon token for anonymous users (let multiple anon users rate the same article. Joy)

To just add the col:
ALTER TABLE mw_article_assessment ADD COLUMN aa_user_anon_token binary(32) DEFAULT NULL AFTER aa_user_text;
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.sql (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.sql
@@ -14,6 +14,7 @@
1515 aa_user_id integer NOT NULL,
1616 -- unique user identifier
1717 aa_user_text varchar(255) binary NOT NULL,
 18+ aa_user_anon_token binary(32) DEFAULT NULL,
1819 -- Foreign key to revision.rev_id
1920 aa_revision integer unsigned NOT NULL,
2021 -- MW Timestamp
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php
@@ -33,6 +33,16 @@
3434 if ( $params['userrating'] ) {
3535 global $wgUser;
3636
 37+ if ( $wgUser->isAnon() ) {
 38+ if ( !isset( $params['anontoken'] ) ) {
 39+ $this->dieUsageMsg( array( 'missingparam', 'anontoken' ) );
 40+ } elseif ( strlen( $params['anontoken'] ) != 32 ) {
 41+ $this->dieUsage( 'The anontoken is not 32 characters', 'invalidtoken' );
 42+ }
 43+
 44+ $this->addWhereFld( 'aa_user_anon_token', $params['anontoken'] );
 45+ }
 46+
3747 $this->addWhereFld( 'aa_user_id', $wgUser->getId() );
3848 $this->addTables( 'article_assessment' );
3949 $this->addJoinConds( array(
@@ -135,6 +145,7 @@
136146 ),
137147 'revid' => null,
138148 'userrating' => false,
 149+ 'anontoken' => null,
139150 'limit' => array(
140151 ApiBase::PARAM_DFLT => 1,
141152 ApiBase::PARAM_TYPE => 'limit',
@@ -150,6 +161,7 @@
151162 'pageid' => 'Page ID to get assessments for',
152163 'revid' => 'Specific revision to get (used in conjunction with userrating param, otherwise ignored. Needed for stale calculation)',
153164 'userrating' => 'Whether to get the current users ratings for the specific rev/article',
 165+ 'anontoken' => 'Token for anonymous users',
154166 'limit' => 'Amount of pages to get the ratings for',
155167 );
156168 }
@@ -162,7 +174,10 @@
163175
164176 public function getPossibleErrors() {
165177 return array_merge( parent::getPossibleErrors(), array(
166 - ) );
 178+ array( 'missingparam', 'anontoken' ),
 179+ array( 'code' => 'invalidtoken', 'info' => 'The anontoken is not 32 characters' ),
 180+ )
 181+ );
167182 }
168183
169184 protected function getExamples() {
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php
@@ -8,17 +8,31 @@
99 global $wgUser, $wgArticleAssessmentRatingCount;
1010 $params = $this->extractRequestParams();
1111
 12+ $token = array();
 13+ if ( $wgUser->isAnon() ) {
 14+ if ( !isset( $params['anontoken'] ) ) {
 15+ $this->dieUsageMsg( array( 'missingparam', 'anontoken' ) );
 16+ } elseif ( strlen( $params['anontoken'] ) != 32 ) {
 17+ $this->dieUsage( 'The anontoken is not 32 characters', 'invalidtoken' );
 18+ }
 19+
 20+ $token['aa_user_anon_token'] = $params['anontoken'];
 21+ }
 22+
1223 $dbr = wfGetDB( DB_SLAVE );
1324
1425 // TODO:Refactor out...?
1526 $res = $dbr->select(
1627 'article_assessment',
1728 array( 'aa_rating_id', 'aa_rating_value', 'aa_revision' ),
18 - array(
19 - 'aa_user_id' => $wgUser->getId(),
20 - 'aa_user_text' => $wgUser->getName(),
21 - 'aa_page_id' => $params['pageid'],
 29+ array_merge(
 30+ array(
 31+ 'aa_user_id' => $wgUser->getId(),
 32+ 'aa_user_text' => $wgUser->getName(),
 33+ 'aa_page_id' => $params['pageid'],
2234 ),
 35+ $token
 36+ ),
2337 __METHOD__,
2438 array(
2539 'ORDER BY' => 'aa_revision DESC',
@@ -51,7 +65,7 @@
5266 ( $lastRating == 0 && $thisRating != 0 )
5367 );
5468
55 - $this->insertUserRatings( $pageId, $revisionId, $wgUser, $i, $thisRating );
 69+ $this->insertUserRatings( $pageId, $revisionId, $wgUser, $token, $i, $thisRating );
5670 }
5771
5872 $r = array();
@@ -99,22 +113,26 @@
100114 * @param $pageId Integer:
101115 * @param $revisionId Integer:
102116 * @param $user User:
 117+ * @param $token Array:
103118 * @param $ratingId Integer:
104119 * @param $ratingValue Integer:
105120 */
106 - private function insertUserRatings( $pageId, $revisionId, $user, $ratingId, $ratingValue ) {
 121+ private function insertUserRatings( $pageId, $revisionId, $user, $token, $ratingId, $ratingValue ) {
107122 $dbw = wfGetDB( DB_MASTER );
108123
109124 $res = $dbw->insert(
110125 'article_assessment',
111 - array(
112 - 'aa_page_id' => $pageId,
113 - 'aa_user_id' => $user->getId(),
114 - 'aa_user_text' => $user->getName(),
115 - 'aa_revision' => $revisionId,
116 - 'aa_timestamp' => wfTimestampNow(),
117 - 'aa_rating_id' => $ratingId,
118 - 'aa_rating_value' => $ratingValue,
 126+ array_merge(
 127+ array(
 128+ 'aa_page_id' => $pageId,
 129+ 'aa_user_id' => $user->getId(),
 130+ 'aa_user_text' => $user->getName(),
 131+ 'aa_revision' => $revisionId,
 132+ 'aa_timestamp' => wfTimestampNow(),
 133+ 'aa_rating_id' => $ratingId,
 134+ 'aa_rating_value' => $ratingValue,
 135+ ),
 136+ $token
119137 ),
120138 __METHOD__,
121139 array( 'IGNORE' )
@@ -127,11 +145,14 @@
128146 'aa_timestamp' => wfTimestampNow(),
129147 'aa_rating_value' => $ratingValue,
130148 ),
131 - array(
132 - 'aa_page_id' => $pageId,
133 - 'aa_user_text' => $user->getName(),
134 - 'aa_revision' => $revisionId,
135 - 'aa_rating_id' => $ratingId,
 149+ array_merge(
 150+ array(
 151+ 'aa_page_id' => $pageId,
 152+ 'aa_user_text' => $user->getName(),
 153+ 'aa_revision' => $revisionId,
 154+ 'aa_rating_id' => $ratingId,
 155+ ),
 156+ $token
136157 ),
137158 __METHOD__
138159 );
@@ -149,7 +170,8 @@
150171 ApiBase::PARAM_TYPE => 'integer',
151172 ApiBase::PARAM_REQUIRED => true,
152173 ApiBase::PARAM_ISMULTI => false,
153 - )
 174+ ),
 175+ 'anontoken' => null,
154176 );
155177
156178 for ( $i = 1; $i <= $wgArticleAssessmentRatingCount; $i++ ) {
@@ -167,7 +189,8 @@
168190 global $wgArticleAssessmentRatingCount;
169191 $ret = array(
170192 'pageid' => 'Page ID to submit assessment for',
171 - 'revid' => 'Revision ID to submit assessment for'
 193+ 'revid' => 'Revision ID to submit assessment for',
 194+ 'anontoken' => 'Token for anonymous users',
172195 );
173196 for ( $i = 1; $i <= $wgArticleAssessmentRatingCount; $i++ ) {
174197 $ret["r{$i}"] = "Rating {$i}";
@@ -187,6 +210,8 @@
188211
189212 public function getPossibleErrors() {
190213 return array_merge( parent::getPossibleErrors(), array(
 214+ array( 'missingparam', 'anontoken' ),
 215+ array( 'code' => 'invalidtoken', 'info' => 'The anontoken is not 32 characters' ),
191216 ) );
192217 }
193218

Status & tagging log