Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.sql |
— | — | @@ -14,6 +14,7 @@ |
15 | 15 | aa_user_id integer NOT NULL, |
16 | 16 | -- unique user identifier |
17 | 17 | aa_user_text varchar(255) binary NOT NULL, |
| 18 | + aa_user_anon_token binary(32) DEFAULT NULL, |
18 | 19 | -- Foreign key to revision.rev_id |
19 | 20 | aa_revision integer unsigned NOT NULL, |
20 | 21 | -- MW Timestamp |
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php |
— | — | @@ -33,6 +33,16 @@ |
34 | 34 | if ( $params['userrating'] ) { |
35 | 35 | global $wgUser; |
36 | 36 | |
| 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 | + |
37 | 47 | $this->addWhereFld( 'aa_user_id', $wgUser->getId() ); |
38 | 48 | $this->addTables( 'article_assessment' ); |
39 | 49 | $this->addJoinConds( array( |
— | — | @@ -135,6 +145,7 @@ |
136 | 146 | ), |
137 | 147 | 'revid' => null, |
138 | 148 | 'userrating' => false, |
| 149 | + 'anontoken' => null, |
139 | 150 | 'limit' => array( |
140 | 151 | ApiBase::PARAM_DFLT => 1, |
141 | 152 | ApiBase::PARAM_TYPE => 'limit', |
— | — | @@ -150,6 +161,7 @@ |
151 | 162 | 'pageid' => 'Page ID to get assessments for', |
152 | 163 | 'revid' => 'Specific revision to get (used in conjunction with userrating param, otherwise ignored. Needed for stale calculation)', |
153 | 164 | 'userrating' => 'Whether to get the current users ratings for the specific rev/article', |
| 165 | + 'anontoken' => 'Token for anonymous users', |
154 | 166 | 'limit' => 'Amount of pages to get the ratings for', |
155 | 167 | ); |
156 | 168 | } |
— | — | @@ -162,7 +174,10 @@ |
163 | 175 | |
164 | 176 | public function getPossibleErrors() { |
165 | 177 | return array_merge( parent::getPossibleErrors(), array( |
166 | | - ) ); |
| 178 | + array( 'missingparam', 'anontoken' ), |
| 179 | + array( 'code' => 'invalidtoken', 'info' => 'The anontoken is not 32 characters' ), |
| 180 | + ) |
| 181 | + ); |
167 | 182 | } |
168 | 183 | |
169 | 184 | protected function getExamples() { |
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiArticleAssessment.php |
— | — | @@ -8,17 +8,31 @@ |
9 | 9 | global $wgUser, $wgArticleAssessmentRatingCount; |
10 | 10 | $params = $this->extractRequestParams(); |
11 | 11 | |
| 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 | + |
12 | 23 | $dbr = wfGetDB( DB_SLAVE ); |
13 | 24 | |
14 | 25 | // TODO:Refactor out...? |
15 | 26 | $res = $dbr->select( |
16 | 27 | 'article_assessment', |
17 | 28 | 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'], |
22 | 34 | ), |
| 35 | + $token |
| 36 | + ), |
23 | 37 | __METHOD__, |
24 | 38 | array( |
25 | 39 | 'ORDER BY' => 'aa_revision DESC', |
— | — | @@ -51,7 +65,7 @@ |
52 | 66 | ( $lastRating == 0 && $thisRating != 0 ) |
53 | 67 | ); |
54 | 68 | |
55 | | - $this->insertUserRatings( $pageId, $revisionId, $wgUser, $i, $thisRating ); |
| 69 | + $this->insertUserRatings( $pageId, $revisionId, $wgUser, $token, $i, $thisRating ); |
56 | 70 | } |
57 | 71 | |
58 | 72 | $r = array(); |
— | — | @@ -99,22 +113,26 @@ |
100 | 114 | * @param $pageId Integer: |
101 | 115 | * @param $revisionId Integer: |
102 | 116 | * @param $user User: |
| 117 | + * @param $token Array: |
103 | 118 | * @param $ratingId Integer: |
104 | 119 | * @param $ratingValue Integer: |
105 | 120 | */ |
106 | | - private function insertUserRatings( $pageId, $revisionId, $user, $ratingId, $ratingValue ) { |
| 121 | + private function insertUserRatings( $pageId, $revisionId, $user, $token, $ratingId, $ratingValue ) { |
107 | 122 | $dbw = wfGetDB( DB_MASTER ); |
108 | 123 | |
109 | 124 | $res = $dbw->insert( |
110 | 125 | '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 |
119 | 137 | ), |
120 | 138 | __METHOD__, |
121 | 139 | array( 'IGNORE' ) |
— | — | @@ -127,11 +145,14 @@ |
128 | 146 | 'aa_timestamp' => wfTimestampNow(), |
129 | 147 | 'aa_rating_value' => $ratingValue, |
130 | 148 | ), |
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 |
136 | 157 | ), |
137 | 158 | __METHOD__ |
138 | 159 | ); |
— | — | @@ -149,7 +170,8 @@ |
150 | 171 | ApiBase::PARAM_TYPE => 'integer', |
151 | 172 | ApiBase::PARAM_REQUIRED => true, |
152 | 173 | ApiBase::PARAM_ISMULTI => false, |
153 | | - ) |
| 174 | + ), |
| 175 | + 'anontoken' => null, |
154 | 176 | ); |
155 | 177 | |
156 | 178 | for ( $i = 1; $i <= $wgArticleAssessmentRatingCount; $i++ ) { |
— | — | @@ -167,7 +189,8 @@ |
168 | 190 | global $wgArticleAssessmentRatingCount; |
169 | 191 | $ret = array( |
170 | 192 | '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', |
172 | 195 | ); |
173 | 196 | for ( $i = 1; $i <= $wgArticleAssessmentRatingCount; $i++ ) { |
174 | 197 | $ret["r{$i}"] = "Rating {$i}"; |
— | — | @@ -187,6 +210,8 @@ |
188 | 211 | |
189 | 212 | public function getPossibleErrors() { |
190 | 213 | return array_merge( parent::getPossibleErrors(), array( |
| 214 | + array( 'missingparam', 'anontoken' ), |
| 215 | + array( 'code' => 'invalidtoken', 'info' => 'The anontoken is not 32 characters' ), |
191 | 216 | ) ); |
192 | 217 | } |
193 | 218 | |