Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | |
15 | 15 | // Auto-load files |
16 | 16 | $dir = dirname( __FILE__ ) . '/'; |
17 | | -$wgAutoloadClasses['ApiListArticleAssessment'] = $dir . 'api/ApiListArticleAssessment.php'; |
| 17 | +$wgAutoloadClasses['ApiQueryArticleAssessment'] = $dir . 'api/ApiQueryArticleAssessment.php'; |
18 | 18 | $wgAutoloadClasses['ApiArticleAssessment'] = $dir . 'api/ApiArticleAssessment.php'; |
19 | 19 | $wgAutoloadClasses['ArticleAssessmentPilotHooks'] = $dir . 'ArticleAssessmentPilot.hooks.php'; |
20 | 20 | |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | $wgHooks['BeforePageDisplay'][] = 'ArticleAssessmentPilotHooks::addResources'; |
27 | 27 | |
28 | 28 | // API modules |
29 | | -$wgAPIListModules['articleassessment'] = 'ApiListArticleAssessment'; |
| 29 | +$wgAPIListModules['articleassessment'] = 'ApiQueryArticleAssessment'; |
30 | 30 | $wgAPIModules['articleassessment'] = 'ApiArticleAssessment'; |
31 | 31 | |
32 | 32 | // i18n and aliases |
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php |
— | — | @@ -1,196 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * |
5 | | - * |
6 | | - * @file |
7 | | - * @ingroup API |
8 | | - */ |
9 | | -class ApiListArticleAssessment extends ApiQueryBase { |
10 | | - public function __construct( $query, $moduleName ) { |
11 | | - parent::__construct( $query, $moduleName, 'aa' ); |
12 | | - } |
13 | | - |
14 | | - public function execute() { |
15 | | - $params = $this->extractRequestParams(); |
16 | | - |
17 | | - $result = $this->getResult(); |
18 | | - |
19 | | - $this->addTables( array( 'article_assessment_pages', 'article_assessment_ratings' ) ); |
20 | | - |
21 | | - $this->addFields( array( 'aap_page_id', 'aap_total', 'aap_count', 'aap_rating_id', 'aar_rating' ) ); |
22 | | - |
23 | | - $this->addJoinConds( array( |
24 | | - 'article_assessment_ratings' => array( 'LEFT JOIN', array( |
25 | | - 'aar_id=aap_rating_id', |
26 | | - ) |
27 | | - ), |
28 | | - ) ); |
29 | | - |
30 | | - if ( isset( $params['pageid'] ) ) { |
31 | | - $this->addWhereFld( 'aap_page_id', $params['pageid'] ); |
32 | | - } |
33 | | - |
34 | | - if ( $params['userrating'] ) { |
35 | | - global $wgUser; |
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 | | - |
47 | | - $this->addWhereFld( 'aa_user_id', $wgUser->getId() ); |
48 | | - $this->addTables( 'article_assessment' ); |
49 | | - $this->addJoinConds( array( |
50 | | - 'article_assessment' => array( 'LEFT JOIN', array( |
51 | | - 'aa_page_id=aap_page_id', |
52 | | - 'aa_rating_id=aap_rating_id' ) ), |
53 | | - ) |
54 | | - ); |
55 | | - |
56 | | - $this->addFields( array( 'aa_rating_value', 'aa_revision' ) ); |
57 | | - |
58 | | - if ( isset( $params['revid'] ) ) { |
59 | | - $this->addWhereFld( 'aa_revision', $params['revid'] ); |
60 | | - } |
61 | | - |
62 | | - $this->addOption( 'ORDER BY', 'aa_revision DESC' ); |
63 | | - } |
64 | | - |
65 | | - $limit = $params['limit']; |
66 | | - $this->addOption( 'LIMIT', $limit * 4 ); //4 "Ratings" |
67 | | - |
68 | | - $res = $this->select( __METHOD__ ); |
69 | | - |
70 | | - $ratings = array(); |
71 | | - |
72 | | - $userRatedArticle = false; |
73 | | - |
74 | | - foreach ( $res as $row ) { |
75 | | - $pageId = $row->aap_page_id; |
76 | | - |
77 | | - if ( !isset( $ratings[$pageId] ) ) { |
78 | | - $page = array( |
79 | | - 'pageid' => $pageId, |
80 | | - ); |
81 | | - |
82 | | - if ( isset( $params['revid'] ) || $params['userrating'] ) { |
83 | | - $page['revid'] = $row->aa_revision; |
84 | | - } |
85 | | - |
86 | | - $ratings[$pageId] = $page; |
87 | | - } |
88 | | - |
89 | | - $thisRow = array( |
90 | | - 'ratingid' => $row->aap_rating_id, |
91 | | - 'ratingdesc' => $row->aar_rating, |
92 | | - 'total' => $row->aap_total, |
93 | | - 'count' => $row->aap_count, |
94 | | - ); |
95 | | - |
96 | | - if ( $params['userrating'] && !is_null( $row->aa_rating_value ) ) { |
97 | | - $thisRow['userrating'] = $row->aa_rating_value; |
98 | | - |
99 | | - $userRatedArticle = true; |
100 | | - } |
101 | | - |
102 | | - $ratings[$pageId]['ratings'][] = $thisRow; |
103 | | - } |
104 | | - |
105 | | - //Only can actually be "stale" if the user has rated the article before |
106 | | - if ( $params['userrating'] && $userRatedArticle ) { |
107 | | - $revid = isset( $params['revid'] ) ? $params['revid'] : $ratings[$pageId]['revid']; |
108 | | - |
109 | | - $dbr = wfGetDb( DB_SLAVE ); |
110 | | - |
111 | | - $res = $dbr->selectField( |
112 | | - 'revision', |
113 | | - 'COUNT(*) AS norevs', |
114 | | - array( |
115 | | - 'rev_page' => $params['pageid'], |
116 | | - 'rev_id > ' . $revid |
117 | | - ), |
118 | | - __METHOD__ |
119 | | - ); |
120 | | - |
121 | | - global $wgArticleAssessmentStaleCount; |
122 | | - |
123 | | - if ( $res && (int)$res > $wgArticleAssessmentStaleCount ) { |
124 | | - //it's stale! |
125 | | - $ratings[$params['pageid']]['stale'] = intval( $res ); |
126 | | - } |
127 | | - } |
128 | | - |
129 | | - $count = 0; |
130 | | - foreach ( $ratings as $rat ) { |
131 | | - if ( ++ $count > $limit ) { |
132 | | - //$this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->page_title ) ); |
133 | | - break; |
134 | | - } |
135 | | - |
136 | | - $result->setIndexedTagName( $rat['ratings'], 'r' ); |
137 | | - $result->addValue( array( 'query', $this->getModuleName() ), null, $rat ); |
138 | | - } |
139 | | - |
140 | | - $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'aa' ); |
141 | | - } |
142 | | - |
143 | | - public function getAllowedParams() { |
144 | | - return array( |
145 | | - 'pageid' => array( |
146 | | - ApiBase::PARAM_ISMULTI => false, |
147 | | - ApiBase::PARAM_TYPE => 'integer', |
148 | | - ), |
149 | | - 'revid' => null, |
150 | | - 'userrating' => false, |
151 | | - 'anontoken' => null, |
152 | | - 'limit' => array( |
153 | | - ApiBase::PARAM_DFLT => 1, |
154 | | - ApiBase::PARAM_TYPE => 'limit', |
155 | | - ApiBase::PARAM_MIN => 1, |
156 | | - ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
157 | | - ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG1, |
158 | | - ), |
159 | | - ); |
160 | | - } |
161 | | - |
162 | | - public function getParamDescription() { |
163 | | - return array( |
164 | | - 'pageid' => 'Page ID to get assessments for', |
165 | | - 'revid' => 'Specific revision to get (used in conjunction with userrating param, otherwise ignored)', |
166 | | - 'userrating' => "Whether to get the current user's ratings for the specific rev/article", |
167 | | - 'anontoken' => 'Token for anonymous users', |
168 | | - 'limit' => 'Amount of pages to get the ratings for', |
169 | | - ); |
170 | | - } |
171 | | - |
172 | | - public function getDescription() { |
173 | | - return array( |
174 | | - 'List all article assessments' |
175 | | - ); |
176 | | - } |
177 | | - |
178 | | - public function getPossibleErrors() { |
179 | | - return array_merge( parent::getPossibleErrors(), array( |
180 | | - array( 'missingparam', 'anontoken' ), |
181 | | - array( 'code' => 'invalidtoken', 'info' => 'The anontoken is not 32 characters' ), |
182 | | - ) |
183 | | - ); |
184 | | - } |
185 | | - |
186 | | - protected function getExamples() { |
187 | | - return array( |
188 | | - 'api.php?action=query&list=articleassessment', |
189 | | - 'api.php?action=query&list=articleassessment&aapageid=1', |
190 | | - 'api.php?action=query&list=articleassessment&aapageid=1&aauserrating', |
191 | | - ); |
192 | | - } |
193 | | - |
194 | | - public function getVersion() { |
195 | | - return __CLASS__ . ': $Id$'; |
196 | | - } |
197 | | -} |
\ No newline at end of file |
Index: trunk/extensions/ArticleAssessmentPilot/api/ApiQueryArticleAssessment.php |
— | — | @@ -0,0 +1,196 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup API |
| 8 | + */ |
| 9 | +class ApiListArticleAssessment extends ApiQueryBase { |
| 10 | + public function __construct( $query, $moduleName ) { |
| 11 | + parent::__construct( $query, $moduleName, 'aa' ); |
| 12 | + } |
| 13 | + |
| 14 | + public function execute() { |
| 15 | + $params = $this->extractRequestParams(); |
| 16 | + |
| 17 | + $result = $this->getResult(); |
| 18 | + |
| 19 | + $this->addTables( array( 'article_assessment_pages', 'article_assessment_ratings' ) ); |
| 20 | + |
| 21 | + $this->addFields( array( 'aap_page_id', 'aap_total', 'aap_count', 'aap_rating_id', 'aar_rating' ) ); |
| 22 | + |
| 23 | + $this->addJoinConds( array( |
| 24 | + 'article_assessment_ratings' => array( 'LEFT JOIN', array( |
| 25 | + 'aar_id=aap_rating_id', |
| 26 | + ) |
| 27 | + ), |
| 28 | + ) ); |
| 29 | + |
| 30 | + if ( isset( $params['pageid'] ) ) { |
| 31 | + $this->addWhereFld( 'aap_page_id', $params['pageid'] ); |
| 32 | + } |
| 33 | + |
| 34 | + if ( $params['userrating'] ) { |
| 35 | + global $wgUser; |
| 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 | + |
| 47 | + $this->addWhereFld( 'aa_user_id', $wgUser->getId() ); |
| 48 | + $this->addTables( 'article_assessment' ); |
| 49 | + $this->addJoinConds( array( |
| 50 | + 'article_assessment' => array( 'LEFT JOIN', array( |
| 51 | + 'aa_page_id=aap_page_id', |
| 52 | + 'aa_rating_id=aap_rating_id' ) ), |
| 53 | + ) |
| 54 | + ); |
| 55 | + |
| 56 | + $this->addFields( array( 'aa_rating_value', 'aa_revision' ) ); |
| 57 | + |
| 58 | + if ( isset( $params['revid'] ) ) { |
| 59 | + $this->addWhereFld( 'aa_revision', $params['revid'] ); |
| 60 | + } |
| 61 | + |
| 62 | + $this->addOption( 'ORDER BY', 'aa_revision DESC' ); |
| 63 | + } |
| 64 | + |
| 65 | + $limit = $params['limit']; |
| 66 | + $this->addOption( 'LIMIT', $limit * 4 ); //4 "Ratings" |
| 67 | + |
| 68 | + $res = $this->select( __METHOD__ ); |
| 69 | + |
| 70 | + $ratings = array(); |
| 71 | + |
| 72 | + $userRatedArticle = false; |
| 73 | + |
| 74 | + foreach ( $res as $row ) { |
| 75 | + $pageId = $row->aap_page_id; |
| 76 | + |
| 77 | + if ( !isset( $ratings[$pageId] ) ) { |
| 78 | + $page = array( |
| 79 | + 'pageid' => $pageId, |
| 80 | + ); |
| 81 | + |
| 82 | + if ( isset( $params['revid'] ) || $params['userrating'] ) { |
| 83 | + $page['revid'] = $row->aa_revision; |
| 84 | + } |
| 85 | + |
| 86 | + $ratings[$pageId] = $page; |
| 87 | + } |
| 88 | + |
| 89 | + $thisRow = array( |
| 90 | + 'ratingid' => $row->aap_rating_id, |
| 91 | + 'ratingdesc' => $row->aar_rating, |
| 92 | + 'total' => $row->aap_total, |
| 93 | + 'count' => $row->aap_count, |
| 94 | + ); |
| 95 | + |
| 96 | + if ( $params['userrating'] && !is_null( $row->aa_rating_value ) ) { |
| 97 | + $thisRow['userrating'] = $row->aa_rating_value; |
| 98 | + |
| 99 | + $userRatedArticle = true; |
| 100 | + } |
| 101 | + |
| 102 | + $ratings[$pageId]['ratings'][] = $thisRow; |
| 103 | + } |
| 104 | + |
| 105 | + //Only can actually be "stale" if the user has rated the article before |
| 106 | + if ( $params['userrating'] && $userRatedArticle ) { |
| 107 | + $revid = isset( $params['revid'] ) ? $params['revid'] : $ratings[$pageId]['revid']; |
| 108 | + |
| 109 | + $dbr = wfGetDb( DB_SLAVE ); |
| 110 | + |
| 111 | + $res = $dbr->selectField( |
| 112 | + 'revision', |
| 113 | + 'COUNT(*) AS norevs', |
| 114 | + array( |
| 115 | + 'rev_page' => $params['pageid'], |
| 116 | + 'rev_id > ' . $revid |
| 117 | + ), |
| 118 | + __METHOD__ |
| 119 | + ); |
| 120 | + |
| 121 | + global $wgArticleAssessmentStaleCount; |
| 122 | + |
| 123 | + if ( $res && (int)$res > $wgArticleAssessmentStaleCount ) { |
| 124 | + //it's stale! |
| 125 | + $ratings[$params['pageid']]['stale'] = intval( $res ); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + $count = 0; |
| 130 | + foreach ( $ratings as $rat ) { |
| 131 | + if ( ++ $count > $limit ) { |
| 132 | + //$this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->page_title ) ); |
| 133 | + break; |
| 134 | + } |
| 135 | + |
| 136 | + $result->setIndexedTagName( $rat['ratings'], 'r' ); |
| 137 | + $result->addValue( array( 'query', $this->getModuleName() ), null, $rat ); |
| 138 | + } |
| 139 | + |
| 140 | + $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'aa' ); |
| 141 | + } |
| 142 | + |
| 143 | + public function getAllowedParams() { |
| 144 | + return array( |
| 145 | + 'pageid' => array( |
| 146 | + ApiBase::PARAM_ISMULTI => false, |
| 147 | + ApiBase::PARAM_TYPE => 'integer', |
| 148 | + ), |
| 149 | + 'revid' => null, |
| 150 | + 'userrating' => false, |
| 151 | + 'anontoken' => null, |
| 152 | + 'limit' => array( |
| 153 | + ApiBase::PARAM_DFLT => 1, |
| 154 | + ApiBase::PARAM_TYPE => 'limit', |
| 155 | + ApiBase::PARAM_MIN => 1, |
| 156 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 157 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG1, |
| 158 | + ), |
| 159 | + ); |
| 160 | + } |
| 161 | + |
| 162 | + public function getParamDescription() { |
| 163 | + return array( |
| 164 | + 'pageid' => 'Page ID to get assessments for', |
| 165 | + 'revid' => 'Specific revision to get (used in conjunction with userrating param, otherwise ignored)', |
| 166 | + 'userrating' => "Whether to get the current user's ratings for the specific rev/article", |
| 167 | + 'anontoken' => 'Token for anonymous users', |
| 168 | + 'limit' => 'Amount of pages to get the ratings for', |
| 169 | + ); |
| 170 | + } |
| 171 | + |
| 172 | + public function getDescription() { |
| 173 | + return array( |
| 174 | + 'List all article assessments' |
| 175 | + ); |
| 176 | + } |
| 177 | + |
| 178 | + public function getPossibleErrors() { |
| 179 | + return array_merge( parent::getPossibleErrors(), array( |
| 180 | + array( 'missingparam', 'anontoken' ), |
| 181 | + array( 'code' => 'invalidtoken', 'info' => 'The anontoken is not 32 characters' ), |
| 182 | + ) |
| 183 | + ); |
| 184 | + } |
| 185 | + |
| 186 | + protected function getExamples() { |
| 187 | + return array( |
| 188 | + 'api.php?action=query&list=articleassessment', |
| 189 | + 'api.php?action=query&list=articleassessment&aapageid=1', |
| 190 | + 'api.php?action=query&list=articleassessment&aapageid=1&aauserrating', |
| 191 | + ); |
| 192 | + } |
| 193 | + |
| 194 | + public function getVersion() { |
| 195 | + return __CLASS__ . ': $Id$'; |
| 196 | + } |
| 197 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/ArticleAssessmentPilot/api/ApiQueryArticleAssessment.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 198 | + native |
Added: svn:keywords |
2 | 199 | + Id |