Index: trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php |
— | — | @@ -34,21 +34,24 @@ |
35 | 35 | // Rating counts and totals |
36 | 36 | $res = $this->select( __METHOD__ ); |
37 | 37 | $ratings = array( $params['pageid'] => array( 'pageid' => $params['pageid'] ) ); |
| 38 | + $historicCounts = $this->getHistoricCounts( $params ); |
38 | 39 | foreach ( $res as $i => $row ) { |
39 | 40 | if ( !isset( $ratings[$params['pageid']]['revid'] ) ) { |
40 | | - $ratings[$params['pageid']]['revid'] = $row->aap_revision; |
| 41 | + $ratings[$params['pageid']]['revid'] = (int) $row->aap_revision; |
41 | 42 | } |
42 | 43 | if ( !isset( $ratings[$params['pageid']]['ratings'] ) ) { |
43 | 44 | $ratings[$params['pageid']]['ratings'] = array(); |
44 | 45 | } |
45 | 46 | $ratings[$params['pageid']]['ratings'][] = array( |
46 | | - 'ratingid' => $row->aap_rating_id, |
| 47 | + 'ratingid' => (int) $row->aap_rating_id, |
47 | 48 | 'ratingdesc' => $row->aar_rating, |
48 | | - 'total' => $row->aap_total, |
49 | | - 'count' => $row->aap_count, |
| 49 | + 'total' => (int) $row->aap_total, |
| 50 | + 'count' => (int) $row->aap_count, |
| 51 | + 'countall' => isset( $historicCounts[$row->aap_rating_id] ) |
| 52 | + ? $historicCounts[$row->aap_rating_id] + 100 : 0 |
50 | 53 | ); |
51 | 54 | } |
52 | | - |
| 55 | + |
53 | 56 | // User-specific data |
54 | 57 | $ratings[$params['pageid']]['status'] = 'current'; |
55 | 58 | if ( $params['userrating'] ) { |
— | — | @@ -102,10 +105,33 @@ |
103 | 106 | $result->setIndexedTagName( $rat['ratings'], 'r' ); |
104 | 107 | $result->addValue( array( 'query', $this->getModuleName() ), null, $rat ); |
105 | 108 | } |
106 | | - |
| 109 | + |
107 | 110 | $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'aa' ); |
108 | 111 | } |
109 | | - |
| 112 | + |
| 113 | + protected function getHistoricCounts( $params ) { |
| 114 | + global $wgArticleFeedbackRatings; |
| 115 | + |
| 116 | + $res = $this->getDB()->select( |
| 117 | + 'article_feedback_pages', |
| 118 | + array( |
| 119 | + 'aap_rating_id', |
| 120 | + 'SUM(aap_count) as count', |
| 121 | + ), |
| 122 | + array( |
| 123 | + 'aap_page_id' => $params['pageid'], |
| 124 | + 'aap_rating_id' => $wgArticleFeedbackRatings, |
| 125 | + ), |
| 126 | + __METHOD__, |
| 127 | + array( 'GROUP BY' => 'aap_rating_id') |
| 128 | + ); |
| 129 | + $counts = array(); |
| 130 | + foreach ( $res as $row ) { |
| 131 | + $counts[$row->aap_rating_id] = $row->count; |
| 132 | + } |
| 133 | + return $counts; |
| 134 | + } |
| 135 | + |
110 | 136 | protected function getAnonToken( $params ) { |
111 | 137 | global $wgUser; |
112 | 138 | |