Index: trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php |
— | — | @@ -49,9 +49,15 @@ |
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
53 | | - // User ratings |
| 53 | + // User-specific data |
54 | 54 | $ratings[$params['pageid']]['status'] = 'current'; |
55 | 55 | if ( $params['userrating'] ) { |
| 56 | + // Expertise |
| 57 | + $expertise = $this->getExpertise( $params ); |
| 58 | + if ( $expertise !== false ) { |
| 59 | + $ratings[$params['pageid']]['expertise'] = $expertise; |
| 60 | + } |
| 61 | + // User ratings |
56 | 62 | $userRatings = $this->getUserRatings( $params ); |
57 | 63 | if ( isset( $ratings[$params['pageid']]['ratings'] ) ) { |
58 | 64 | // Valid ratings already exist |
— | — | @@ -60,11 +66,6 @@ |
61 | 67 | // Rating value |
62 | 68 | $ratings[$params['pageid']]['ratings'][$i]['userrating'] = |
63 | 69 | $userRatings[$rating['ratingid']]['value']; |
64 | | - // Expertise |
65 | | - if ( !isset( $ratings[$params['pageid']]['expertise'] ) ) { |
66 | | - $ratings[$params['pageid']]['expertise'] = |
67 | | - $userRatings[$rating['ratingid']]['expertise']; |
68 | | - } |
69 | 70 | // Expiration |
70 | 71 | if ( $userRatings[$rating['ratingid']]['revision'] < $revisionLimit ) { |
71 | 72 | $ratings[$params['pageid']]['status'] = 'expired'; |
— | — | @@ -93,10 +94,6 @@ |
94 | 95 | 'count' => 0, |
95 | 96 | 'userrating' => $userRating['value'], |
96 | 97 | ); |
97 | | - // Expertise |
98 | | - if ( !isset( $ratings[$params['pageid']]['expertise'] ) ) { |
99 | | - $ratings[$params['pageid']]['expertise'] = $userRating['expertise']; |
100 | | - } |
101 | 98 | } |
102 | 99 | } |
103 | 100 | } |
— | — | @@ -108,11 +105,10 @@ |
109 | 106 | |
110 | 107 | $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'aa' ); |
111 | 108 | } |
112 | | - |
113 | | - protected function getUserRatings( $params ) { |
114 | | - global $wgUser, $wgArticleFeedbackRatings; |
115 | | - |
116 | | - $pageId = $params['pageid']; |
| 109 | + |
| 110 | + protected function getAnonToken( $params ) { |
| 111 | + global $wgUser; |
| 112 | + |
117 | 113 | $token = ''; |
118 | 114 | if ( $wgUser->isAnon() ) { |
119 | 115 | if ( !isset( $params['anontoken'] ) ) { |
— | — | @@ -122,36 +118,49 @@ |
123 | 119 | } |
124 | 120 | $token = $params['anontoken']; |
125 | 121 | } |
| 122 | + return $token; |
| 123 | + } |
| 124 | + |
| 125 | + protected function getExpertise( $params ) { |
| 126 | + global $wgUser; |
| 127 | + |
| 128 | + return $this->getDB()->selectField( |
| 129 | + 'article_feedback_properties', |
| 130 | + 'afp_value_text', |
| 131 | + array( |
| 132 | + 'afp_key' => 'expertise', |
| 133 | + 'afp_user_text' => $wgUser->getName(), |
| 134 | + 'afp_user_anon_token' => $this->getAnonToken( $params ), |
| 135 | + ), |
| 136 | + __METHOD__, |
| 137 | + array( 'ORDER BY', 'afp_revision DESC' ) |
| 138 | + ); |
| 139 | + } |
| 140 | + |
| 141 | + protected function getUserRatings( $params ) { |
| 142 | + global $wgUser, $wgArticleFeedbackRatings; |
126 | 143 | |
127 | 144 | $res = $this->getDB()->select( |
128 | | - array( 'article_feedback', 'article_feedback_properties', 'article_feedback_ratings' ), |
| 145 | + array( 'article_feedback', 'article_feedback_ratings' ), |
129 | 146 | array( |
130 | 147 | 'aa_rating_id', |
131 | 148 | 'aar_rating', |
132 | 149 | 'aa_revision', |
133 | 150 | 'aa_rating_value', |
134 | | - 'afp_value_text' |
135 | 151 | ), |
136 | 152 | array( |
137 | | - 'aa_page_id' => $pageId, |
| 153 | + 'aa_page_id' => $params['pageid'], |
138 | 154 | 'aa_rating_id' => $wgArticleFeedbackRatings, |
139 | 155 | 'aa_user_id' => $wgUser->getId(), |
| 156 | + 'aa_user_text' => $wgUser->getName(), |
| 157 | + 'aa_user_anon_token' => $this->getAnonToken( $params ), |
140 | 158 | ), |
141 | 159 | __METHOD__, |
142 | 160 | array( |
143 | | - 'ORDER BY' => 'aa_revision DESC', |
144 | | - 'LIMIT' => count( $wgArticleFeedbackRatings ) |
| 161 | + 'LIMIT' => count( $wgArticleFeedbackRatings ), |
| 162 | + 'ORDER BY' => array( 'aa_rating_id', 'aa_revision DESC' ), |
145 | 163 | ), |
146 | 164 | array( |
147 | | - 'article_feedback_properties' => array( |
148 | | - 'LEFT JOIN', array( |
149 | | - 'afp_revision=aa_revision', |
150 | | - 'afp_user_text=aa_user_text', |
151 | | - 'afp_user_anon_token=aa_user_anon_token', |
152 | | - 'aa_user_anon_token' => $token, |
153 | | - 'afp_key' => 'expertise', |
154 | | - ) |
155 | | - ), |
156 | 165 | 'article_feedback_ratings' => array( 'LEFT JOIN', array( 'aar_id=aa_rating_id' ) ) |
157 | 166 | ) |
158 | 167 | ); |
— | — | @@ -165,7 +174,6 @@ |
166 | 175 | if ( $revId === $row->aa_revision ) { |
167 | 176 | $ratings[$row->aa_rating_id] = array( |
168 | 177 | 'value' => $row->aa_rating_value, |
169 | | - 'expertise' => $row->afp_value_text, |
170 | 178 | 'revision' => $row->aa_revision, |
171 | 179 | 'text' => $row->aar_rating, |
172 | 180 | ); |