Index: trunk/extensions/ArticleAssessmentPilot/api/ApiListArticleAssessment.php |
— | — | @@ -19,12 +19,36 @@ |
20 | 20 | |
21 | 21 | $this->addFields( array( 'aap_page_id', 'aap_total', 'aap_count', 'aap_rating_id', 'aar_rating' ) ); |
22 | 22 | |
23 | | - $this->addWhere( 'aap_rating_id = aar_id' ); |
| 23 | + $this->addJoinConds( array( |
| 24 | + 'article_assessment_ratings' => array( 'LEFT JOIN', array( |
| 25 | + 'aar_id=aap_rating_id', |
| 26 | + ) ), |
| 27 | + ) |
| 28 | + ); |
24 | 29 | |
25 | 30 | if ( isset( $params['pageid'] ) ) { |
26 | 31 | $this->addWhereFld( 'aap_page_id', $params['pageid'] ); |
27 | 32 | } |
28 | 33 | |
| 34 | + if ( $params['userrating'] ) { |
| 35 | + global $wgUser; |
| 36 | + |
| 37 | + $this->addWhereFld( 'aa_user_id', $wgUser->getId() ); |
| 38 | + $this->addTables( 'article_assessment' ); |
| 39 | + $this->addJoinConds( array( |
| 40 | + 'article_assessment' => array( 'LEFT JOIN', array( |
| 41 | + 'aa_page_id=aap_page_id', |
| 42 | + 'aa_rating_id=aap_rating_id' ) ), |
| 43 | + ) |
| 44 | + ); |
| 45 | + |
| 46 | + $this->addFields( 'aa_rating_value' ); |
| 47 | + |
| 48 | + if ( isset( $params['revid'] ) ){ |
| 49 | + $this->addWhereFld( 'aa_revision', $params['revid'] ); |
| 50 | + } |
| 51 | + } |
| 52 | + |
29 | 53 | $res = $this->select( __METHOD__ ); |
30 | 54 | |
31 | 55 | $ratings = array(); |
— | — | @@ -33,17 +57,29 @@ |
34 | 58 | $pageId = $row->aap_page_id; |
35 | 59 | |
36 | 60 | if ( !isset( $ratings[$pageId] ) ) { |
37 | | - $ratings[$pageId] = array( |
| 61 | + $page = array( |
38 | 62 | 'pageid' => $pageId, |
39 | 63 | ); |
| 64 | + |
| 65 | + if ( isset( $params['revid'] ) ){ |
| 66 | + $page['revid'] = $row->aa_revision ; |
| 67 | + } |
| 68 | + |
| 69 | + $ratings[$pageId] = $page; |
40 | 70 | } |
41 | 71 | |
42 | | - $ratings[$pageId]['ratings'][] = array( |
| 72 | + $thisRow = array( |
43 | 73 | 'ratingid' => $row->aap_rating_id, |
44 | 74 | 'ratingdesc' => $row->aar_rating, |
45 | 75 | 'total' => $row->aap_total, |
46 | | - 'count' => $row->aap_count |
| 76 | + 'count' => $row->aap_count, |
47 | 77 | ); |
| 78 | + |
| 79 | + if ( $params['userrating'] && !is_null( $row->aa_rating_value ) ) { |
| 80 | + $thisRow['userrating'] = $row->aa_rating_value; |
| 81 | + } |
| 82 | + |
| 83 | + $ratings[$pageId]['ratings'][] = $thisRow; |
48 | 84 | } |
49 | 85 | |
50 | 86 | foreach ( $ratings as $rat ) { |
— | — | @@ -57,12 +93,16 @@ |
58 | 94 | public function getAllowedParams() { |
59 | 95 | return array( |
60 | 96 | 'pageid' => null, |
| 97 | + 'revid' => null, |
| 98 | + 'userrating' => false, |
61 | 99 | ); |
62 | 100 | } |
63 | 101 | |
64 | 102 | public function getParamDescription() { |
65 | 103 | return array( |
66 | | - 'pageid' => '', |
| 104 | + 'pageid' => 'Page ID to get assessments for', |
| 105 | + 'revid' => 'Specific revision to get (used in conjunction with user param, otherwise ignored)', |
| 106 | + 'userrating' => 'Whether to get the current users ratings for the specific rev/article', |
67 | 107 | ); |
68 | 108 | } |
69 | 109 | |
— | — | @@ -80,7 +120,8 @@ |
81 | 121 | protected function getExamples() { |
82 | 122 | return array( |
83 | 123 | 'api.php?action=query&list=articleassessment', |
84 | | - 'api.php?action=query&list=articleassessment&aapageid=1' |
| 124 | + 'api.php?action=query&list=articleassessment&aapageid=1', |
| 125 | + 'api.php?action=query&list=articleassessment&aapageid=1&userrating', |
85 | 126 | ); |
86 | 127 | } |
87 | 128 | |