Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js |
— | — | @@ -247,6 +247,7 @@ |
248 | 248 | } |
249 | 249 | } |
250 | 250 | } |
| 251 | + // Report |
251 | 252 | if ( typeof ratingData === 'undefined' || ratingData.total == 0 ) { |
252 | 253 | // Setup in "no ratings" mode |
253 | 254 | $(this) |
— | — | @@ -258,9 +259,7 @@ |
259 | 260 | .end() |
260 | 261 | .find( '.articleFeedback-rating-count' ) |
261 | 262 | .text( mw.msg( 'articlefeedback-report-empty' ) ) |
262 | | - .end() |
263 | | - .find( 'input' ) |
264 | | - .attr( 'checked', false ); |
| 263 | + .end(); |
265 | 264 | } else { |
266 | 265 | // Setup using ratingData |
267 | 266 | var average = ratingData.total / ratingData.count; |
— | — | @@ -276,11 +275,24 @@ |
277 | 276 | .text( mw.msg( |
278 | 277 | 'articlefeedback-report-ratings', ratingData.count |
279 | 278 | ) ) |
280 | | - .end() |
281 | | - .find( 'input[value="' + ratingData.userrating + '"]' ) |
| 279 | + .end(); |
| 280 | + } |
| 281 | + // Form |
| 282 | + if ( typeof ratingData.userrating !== 'undefined' ) { |
| 283 | + if ( ratingData.userrating === 0 ) { |
| 284 | + $(this) |
| 285 | + .find( 'input' ) |
| 286 | + .attr( 'checked', false ); |
| 287 | + } else { |
| 288 | + $(this) |
| 289 | + .find( 'input[value="' + ratingData.userrating + '"]' ) |
282 | 290 | .attr( 'checked', true ); |
283 | | - // If any ratings exist, make sure expertise is enabled so users can suppliment their ratings. |
284 | | - $.articleFeedback.fn.enableExpertise( context.$ui.find( '.articleFeedback-expertise' ) ); |
| 291 | + } |
| 292 | + // If any ratings exist, make sure expertise is enabled so users can |
| 293 | + // suppliment their ratings. |
| 294 | + $.articleFeedback.fn.enableExpertise( |
| 295 | + context.$ui.find( '.articleFeedback-expertise' ) |
| 296 | + ); |
285 | 297 | } |
286 | 298 | $.articleFeedback.fn.updateRating.call( $(this) ); |
287 | 299 | } ); |
Index: trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php |
— | — | @@ -13,7 +13,6 @@ |
14 | 14 | |
15 | 15 | $this->addTables( array( 'article_feedback_pages', 'article_feedback_ratings' ) ); |
16 | 16 | $this->addFields( array( |
17 | | - 'aap_page_id', |
18 | 17 | 'MAX(aap_revision) as aap_revision', |
19 | 18 | 'SUM(aap_total) as aap_total', |
20 | 19 | 'SUM(aap_count) as aap_count', |
— | — | @@ -32,59 +31,74 @@ |
33 | 32 | $this->addOption( 'GROUP BY', 'aap_rating_id' ); |
34 | 33 | $this->addOption( 'LIMIT', count( $wgArticleFeedbackRatings ) ); |
35 | 34 | |
| 35 | + // Rating counts and totals |
36 | 36 | $res = $this->select( __METHOD__ ); |
37 | | - |
38 | | - if ( $params['userrating'] ) { |
39 | | - $userRatings = $this->getUserRatings( $params ); |
40 | | - } |
41 | | - |
42 | | - $ratings = array(); |
43 | | - |
44 | | - $userRatedArticle = false; |
45 | | - |
46 | | - $rev = null; |
| 37 | + $ratings = array( $params['pageid'] => array( 'pageid' => $params['pageid'] ) ); |
47 | 38 | foreach ( $res as $i => $row ) { |
48 | | - // All the revs and pageIds will be the same for all rows, these are shortcuts |
49 | | - $pageId = $row->aap_page_id; |
50 | | - // This is special however, because we need this data later for expired calculation |
51 | | - $rev = $row->aap_revision; |
52 | | - |
53 | | - if ( !isset( $ratings[$pageId] ) ) { |
54 | | - $page = array( |
55 | | - 'pageid' => $pageId, |
56 | | - 'revid' => $rev, |
57 | | - ); |
58 | | - |
59 | | - if ( $params['userrating'] ) { |
60 | | - if ( isset( $userRatings[$i]['expertise'] ) ) { |
61 | | - $page['expertise'] = $userRatings[$i]['expertise']; |
62 | | - } |
63 | | - } |
64 | | - |
65 | | - $ratings[$pageId] = $page; |
| 39 | + if ( !isset( $ratings[$params['pageid']] ) ) { |
| 40 | + $ratings[$params['pageid']]['revid'] = $row->aap_revision; |
66 | 41 | } |
67 | | - |
68 | | - $thisRow = array( |
| 42 | + if ( !isset( $ratings[$params['pageid']]['ratings'] ) ) { |
| 43 | + $ratings[$params['pageid']]['ratings'] = array(); |
| 44 | + } |
| 45 | + $ratings[$params['pageid']]['ratings'][] = array( |
69 | 46 | 'ratingid' => $row->aap_rating_id, |
70 | 47 | 'ratingdesc' => $row->aar_rating, |
71 | 48 | 'total' => $row->aap_total, |
72 | 49 | 'count' => $row->aap_count, |
73 | 50 | ); |
74 | | - |
75 | | - if ( $params['userrating'] && isset( $userRatings[$i]['value'] ) ) { |
76 | | - $thisRow['userrating'] = $userRatings[$i]['value']; |
77 | | - |
78 | | - $userRatedArticle = true; |
| 51 | + } |
| 52 | + |
| 53 | + // User ratings |
| 54 | + $ratings[$params['pageid']]['status'] = 'current'; |
| 55 | + if ( $params['userrating'] ) { |
| 56 | + $userRatings = $this->getUserRatings( $params ); |
| 57 | + if ( isset( $ratings[$params['pageid']]['ratings'] ) ) { |
| 58 | + // Valid ratings already exist |
| 59 | + foreach ( $ratings[$params['pageid']]['ratings'] as $i => $rating ) { |
| 60 | + // Rating value |
| 61 | + $ratings[$params['pageid']]['ratings'][$i]['userrating'] = |
| 62 | + $userRatings[$rating['ratingid']]['value']; |
| 63 | + // Expertise |
| 64 | + if ( !isset( $ratings[$params['pageid']]['expertise'] ) ) { |
| 65 | + $ratings[$params['pageid']]['expertise'] = |
| 66 | + $userRatings[$rating['ratingid']]['expertise']; |
| 67 | + } |
| 68 | + // Expiration |
| 69 | + if ( $userRatings[$rating['ratingid']]['revision'] < $revisionLimit ) { |
| 70 | + $ratings[$params['pageid']]['status'] = 'expired'; |
| 71 | + } |
| 72 | + } |
| 73 | + } else { |
| 74 | + // No valid ratings exist |
| 75 | + if ( count( $userRatings ) ) { |
| 76 | + $ratings[$params['pageid']]['status'] = 'expired'; |
| 77 | + } |
| 78 | + foreach ( $userRatings as $ratingId => $userRating ) { |
| 79 | + // Revision |
| 80 | + if ( !isset( $ratings[$params['pageid']]['revid'] ) ) { |
| 81 | + $ratings[$params['pageid']]['revid'] = $userRating['revision']; |
| 82 | + } |
| 83 | + // Ratings |
| 84 | + if ( !isset( $ratings[$params['pageid']]['ratings'] ) ) { |
| 85 | + $ratings[$params['pageid']]['ratings'] = array(); |
| 86 | + } |
| 87 | + // Rating value |
| 88 | + $ratings[$params['pageid']]['ratings'][] = array( |
| 89 | + 'ratingid' => $ratingId, |
| 90 | + 'ratingdesc' => $userRating['text'], |
| 91 | + 'total' => 0, |
| 92 | + 'count' => 0, |
| 93 | + 'userrating' => $userRating['value'], |
| 94 | + ); |
| 95 | + // Expertise |
| 96 | + if ( !isset( $ratings[$params['pageid']]['expertise'] ) ) { |
| 97 | + $ratings[$params['pageid']]['expertise'] = $userRating['expertise']; |
| 98 | + } |
| 99 | + } |
79 | 100 | } |
80 | | - |
81 | | - $ratings[$pageId]['ratings'][] = $thisRow; |
82 | 101 | } |
83 | 102 | |
84 | | - // Ratings can only be expired if the user has rated before |
85 | | - if ( $params['userrating'] && $userRatedArticle ) { |
86 | | - $ratings[$params['pageid']]['status'] = $rev >= $revisionLimit ? 'current' : 'expired'; |
87 | | - } |
88 | | - |
89 | 103 | foreach ( $ratings as $rat ) { |
90 | 104 | $result->setIndexedTagName( $rat['ratings'], 'r' ); |
91 | 105 | $result->addValue( array( 'query', $this->getModuleName() ), null, $rat ); |
— | — | @@ -107,11 +121,16 @@ |
108 | 122 | $token = $params['anontoken']; |
109 | 123 | } |
110 | 124 | |
111 | | - $dbr = wfGetDb( DB_SLAVE ); |
112 | | - $res = $dbr->select( |
113 | | - array( 'article_feedback', 'article_feedback_properties' ), |
114 | | - array( 'aa_rating_id', 'aa_rating_value', 'afp_value_text' ), |
| 125 | + $res = $this->getDB()->select( |
| 126 | + array( 'article_feedback', 'article_feedback_properties', 'article_feedback_ratings' ), |
115 | 127 | array( |
| 128 | + 'aa_rating_id', |
| 129 | + 'aar_rating', |
| 130 | + 'aa_revision', |
| 131 | + 'aa_rating_value', |
| 132 | + 'afp_value_text' |
| 133 | + ), |
| 134 | + array( |
116 | 135 | 'aa_page_id' => $pageId, |
117 | 136 | 'aa_rating_id' => $wgArticleFeedbackRatings, |
118 | 137 | 'aa_user_id' => $wgUser->getId(), |
— | — | @@ -121,21 +140,26 @@ |
122 | 141 | 'ORDER BY' => 'aa_revision DESC', |
123 | 142 | 'LIMIT' => count( $wgArticleFeedbackRatings ) |
124 | 143 | ), |
125 | | - array( 'article_feedback_properties' => array( |
126 | | - 'LEFT JOIN', array( |
127 | | - 'afp_revision=aa_revision', |
128 | | - 'afp_user_text=aa_user_text', |
129 | | - 'afp_user_anon_token=aa_user_anon_token', |
130 | | - 'aa_user_anon_token' => $token, |
131 | | - 'afp_key' => 'expertise', |
132 | | - ) |
133 | | - ) ) |
| 144 | + array( |
| 145 | + 'article_feedback_properties' => array( |
| 146 | + 'LEFT JOIN', array( |
| 147 | + 'afp_revision=aa_revision', |
| 148 | + 'afp_user_text=aa_user_text', |
| 149 | + 'afp_user_anon_token=aa_user_anon_token', |
| 150 | + 'aa_user_anon_token' => $token, |
| 151 | + 'afp_key' => 'expertise', |
| 152 | + ) |
| 153 | + ), |
| 154 | + 'article_feedback_ratings' => array( 'LEFT JOIN', array( 'aar_id=aa_rating_id' ) ) |
| 155 | + ) |
134 | 156 | ); |
135 | 157 | $ratings = array(); |
136 | 158 | foreach ( $res as $row ) { |
137 | 159 | $ratings[$row->aa_rating_id] = array( |
138 | 160 | 'value' => $row->aa_rating_value, |
139 | | - 'expertise' => $row->afp_value_text |
| 161 | + 'expertise' => $row->afp_value_text, |
| 162 | + 'revision' => $row->aa_revision, |
| 163 | + 'text' => $row->aar_rating, |
140 | 164 | ); |
141 | 165 | } |
142 | 166 | return $ratings; |
— | — | @@ -150,8 +174,7 @@ |
151 | 175 | protected function getRevisionLimit( $pageId ) { |
152 | 176 | global $wgArticleFeedbackRatingLifetime; |
153 | 177 | |
154 | | - $dbr = wfGetDb( DB_SLAVE ); |
155 | | - $revision = $dbr->selectField( |
| 178 | + $revision = $this->getDB()->selectField( |
156 | 179 | 'revision', |
157 | 180 | 'rev_id', |
158 | 181 | array( 'rev_page' => $pageId ), |