Index: trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql |
— | — | @@ -56,11 +56,14 @@ |
57 | 57 | af_has_comment boolean NOT NULL DEFAULT FALSE, |
58 | 58 | -- Keep track of number of activities (hide/show/flag/unflag) |
59 | 59 | -- should be equivalent to counting rows in logging table |
60 | | - af_activity_count integer unsigned NOT NULL DEFAULT 0 |
61 | | - -- for some of the filtering, we need to know "unhidden" |
62 | | - -- to do this we have to keep track of "has ever been hidden |
63 | | - -- same with "has ever been oversighted, has ever had oversight requested" |
64 | | - -- these go on and never go back off, really |
| 60 | + af_activity_count integer unsigned NOT NULL DEFAULT 0, |
| 61 | + -- keep the user id of the last hider and/or oversighter of the feedback |
| 62 | + -- only registered users can do this, which is why no ips |
| 63 | + -- data used on the overlay of hidden/oversighted items |
| 64 | + af_hide_user_id integer unsigned NOT NULL DEFAULT 0, |
| 65 | + af_hide_timestamp binary(14) NOT NULL DEFAULT '', |
| 66 | + af_oversight_user_id integer unsigned NOT NULL DEFAULT 0, |
| 67 | + af_oversight_timestamp binary(14) NOT NULL DEFAULT '', |
65 | 68 | ) /*$wgDBTableOptions*/; |
66 | 69 | CREATE INDEX /*i*/af_page_user_token_id ON /*_*/aft_article_feedback (af_page_id, af_user_id, af_user_anon_token, af_id); |
67 | 70 | CREATE INDEX /*i*/af_revision_id ON /*_*/aft_article_feedback (af_revision_id); |
Index: trunk/extensions/ArticleFeedbackv5/sql/alter.sql |
— | — | @@ -133,6 +133,10 @@ |
134 | 134 | ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_is_undeleted BOOLEAN NOT NULL DEFAULT FALSE; |
135 | 135 | ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_is_declined BOOLEAN NOT NULL DEFAULT FALSE; |
136 | 136 | ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_activity_count integer unsigned NOT NULL DEFAULT 0; |
| 137 | +ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_hide_user_id integer unsigned NOT NULL DEFAULT 0; |
| 138 | +ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_oversight_user_id integer unsigned NOT NULL DEFAULT 0; |
| 139 | +ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_hide_timestamp binary(14) NOT NULL DEFAULT ''; |
| 140 | +ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_oversight_timestamp binary(14) NOT NULL DEFAULT ''; |
137 | 141 | |
| 142 | +-- set has_comment appropriately from current values |
138 | 143 | UPDATE aft_article_feedback, aft_article_answer SET af_has_comment = TRUE WHERE af_bucket_id = 1 AND af_id = aa_feedback_id AND aa_response_text IS NOT NULL; |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php |
— | — | @@ -51,6 +51,7 @@ |
52 | 52 | // we use ONE db connection that talks to master |
53 | 53 | $dbw = wfGetDB( DB_MASTER ); |
54 | 54 | $dbw->begin(); |
| 55 | + $timestamp = $dbw->timestamp(); |
55 | 56 | |
56 | 57 | // load feedback record, bail if we don't have one |
57 | 58 | $record = $this->fetchRecord( $dbw, $feedbackId ); |
— | — | @@ -69,8 +70,11 @@ |
70 | 71 | $activity = 'oversight'; |
71 | 72 | |
72 | 73 | // delete |
73 | | - $update[] = "af_is_deleted = TRUE"; |
74 | | - $update[] = "af_is_undeleted = FALSE"; |
| 74 | + $update['af_is_deleted'] = true; |
| 75 | + $update['af_is_undeleted'] = false; |
| 76 | + // only store the oversighter on delete/oversight |
| 77 | + $update['af_oversight_user_id'] = $wgUser->getId(); |
| 78 | + $update['af_oversight_timestamp'] = $timestamp; |
75 | 79 | // delete specific filters |
76 | 80 | $filters['deleted'] = 1; |
77 | 81 | $filters['notdeleted'] = -1; |
— | — | @@ -80,17 +84,20 @@ |
81 | 85 | |
82 | 86 | // autohide if not hidden |
83 | 87 | if (false == $record->af_is_hidden ) { |
84 | | - $update[] = "af_is_hidden = TRUE"; |
85 | | - $update[] = "af_is_unhidden = FALSE"; |
| 88 | + $update['af_is_hidden'] = true; |
| 89 | + $update['af_is_unhidden'] = false; |
86 | 90 | $filters = $this->changeFilterCounts( $record, $filters, 'hide' ); |
| 91 | + // 0 is used for "autohidden" purposes, we'll explicitly set it to overwrite last hider |
| 92 | + $update['af_hide_user_id'] = 0; |
| 93 | + $update['af_hide_timestamp'] = $timestamp; |
87 | 94 | $implicit_hide = true; // for logging |
88 | 95 | } |
89 | 96 | |
90 | 97 | } else { |
91 | 98 | // decrease means "unoversight this" but does NOT auto-unhide |
92 | 99 | $activity = 'unoversight'; |
93 | | - $update[] = "af_is_deleted = FALSE"; |
94 | | - $update[] = "af_is_undeleted = TRUE"; |
| 100 | + $update['af_is_deleted'] = false; |
| 101 | + $update['af_is_undeleted'] = true; |
95 | 102 | // increment "undeleted", decrement "deleted" |
96 | 103 | // NOTE: we do not touch visible, since hidden controls visiblity |
97 | 104 | $filters['deleted'] = -1; |
— | — | @@ -106,17 +113,19 @@ |
107 | 114 | $activity = 'hidden'; |
108 | 115 | |
109 | 116 | // hide |
110 | | - $update[] = "af_is_hidden = TRUE"; |
111 | | - $update[] = "af_is_unhidden = FALSE"; |
112 | | - |
| 117 | + $update['af_is_hidden'] = true; |
| 118 | + $update['af_is_unhidden'] = false; |
| 119 | + // only store the hider on hide not show |
| 120 | + $update['af_hide_user_id'] = $wgUser->getId(); |
| 121 | + $update['af_hide_timestamp'] = $timestamp; |
113 | 122 | $filters = $this->changeFilterCounts( $record, $filters, 'hide' ); |
114 | 123 | |
115 | 124 | } else { |
116 | 125 | // decrease means "unhide this" |
117 | 126 | $activity = 'unhidden'; |
118 | 127 | |
119 | | - $update[] = "af_is_hidden = FALSE"; |
120 | | - $update[] = "af_is_unhidden = TRUE"; |
| 128 | + $update['af_is_hidden'] = false; |
| 129 | + $update['af_is_unhidden'] = true; |
121 | 130 | |
122 | 131 | $filters = $this->changeFilterCounts( $record, $filters, 'show' ); |
123 | 132 | } |
— | — | @@ -125,9 +134,9 @@ |
126 | 135 | |
127 | 136 | $activity = 'decline'; |
128 | 137 | // oversight request count becomes 0 |
129 | | - $update[] = "af_oversight_count = 0"; |
| 138 | + $update['af_oversight_count'] = 0; |
130 | 139 | // declined oversight is flagged |
131 | | - $update[] = "af_is_declined = TRUE"; |
| 140 | + $update['af_is_declined'] = true; |
132 | 141 | $filters['declined'] = 1; |
133 | 142 | // if the oversight count was greater then 1 |
134 | 143 | if(0 < $record->af_oversight_count) { |
— | — | @@ -160,14 +169,18 @@ |
161 | 170 | if($direction == 'increase') { |
162 | 171 | $activity = 'flag'; |
163 | 172 | $filters['abusive'] = 1; |
| 173 | + // NOTE: we are bypassing traditional sql escaping here |
164 | 174 | $update[] = "af_abuse_count = af_abuse_count + 1"; |
165 | 175 | |
166 | 176 | // Auto-hide after threshold flags |
167 | 177 | if( $record->af_abuse_count > $wgArticleFeedbackv5HideAbuseThreshold |
168 | 178 | && false == $record->af_is_hidden ) { |
169 | 179 | // hide |
170 | | - $update[] = "af_is_hidden = TRUE"; |
171 | | - $update[] = "af_is_unhidden = FALSE"; |
| 180 | + $update['af_is_hidden'] = true; |
| 181 | + $update['af_is_unhidden'] = false; |
| 182 | + // 0 is used for "autohidden" purposes, we'll explicitly set it to overwrite last hider |
| 183 | + $update['af_hide_user_id'] = 0; |
| 184 | + $update['af_hide_timestamp'] = $timestamp; |
172 | 185 | |
173 | 186 | $filters = $this->changeFilterCounts( $record, $filters, 'hide' ); |
174 | 187 | $results['abuse-hidden'] = 1; |
— | — | @@ -179,12 +192,13 @@ |
180 | 193 | elseif($direction == 'decrease') { |
181 | 194 | $activity = 'unflag'; |
182 | 195 | $filters['abusive'] = -1; |
| 196 | + // NOTE: we are bypassing traditional sql escaping here |
183 | 197 | $update[] = "af_abuse_count = GREATEST(CONVERT(af_abuse_count, SIGNED) -1, 0)"; |
184 | 198 | |
185 | 199 | // Un-hide if we don't have 5 flags anymore |
186 | 200 | if( $record->af_abuse_count == 5 && true == $record->af_is_hidden ) { |
187 | | - $update[] = "af_is_hidden = FALSE"; |
188 | | - $update[] = "af_is_unhidden = TRUE"; |
| 201 | + $update['af_is_hidden'] = false; |
| 202 | + $update['af_is_unhidden'] = true; |
189 | 203 | |
190 | 204 | $filters = $this->changeFilterCounts( $record, $filters, 'show' ); |
191 | 205 | |
— | — | @@ -201,24 +215,28 @@ |
202 | 216 | if($direction == 'increase') { |
203 | 217 | $activity = 'request'; |
204 | 218 | $filters['needsoversight'] = 1; |
| 219 | + // NOTE: we are bypassing traditional sql escaping here |
205 | 220 | $update[] = "af_oversight_count = af_oversight_count + 1"; |
206 | 221 | |
207 | 222 | // autohide if not hidden |
208 | 223 | if (false == $record->af_is_hidden ) { |
209 | | - $update[] = "af_is_hidden = TRUE"; |
210 | | - $update[] = "af_is_unhidden = FALSE"; |
| 224 | + $update['af_is_hidden'] = true; |
| 225 | + $update['af_is_unhidden'] = false; |
| 226 | + // 0 is used for "autohidden" purposes, we'll explicitly set it to overwrite last hider |
| 227 | + $update['af_hide_user_id'] = 0; |
211 | 228 | $filters = $this->changeFilterCounts( $record, $filters, 'hide' ); |
212 | 229 | $implicit_hide = true; // for logging |
213 | 230 | } |
214 | 231 | } elseif($direction == 'decrease') { |
215 | 232 | $activity = 'unrequest'; |
216 | 233 | $filters['needsoversight'] = -1; |
| 234 | + // NOTE: we are bypassing traditional sql escaping here |
217 | 235 | $update[] = "af_oversight_count = GREATEST(CONVERT(af_oversight_count, SIGNED) - 1, 0)"; |
218 | 236 | |
219 | 237 | // Un-hide if we don't have oversight flags anymore |
220 | 238 | if( $record->af_oversight_count == 1 && true == $record->af_is_hidden ) { |
221 | | - $update[] = "af_is_hidden = FALSE"; |
222 | | - $update[] = "af_is_unhidden = TRUE"; |
| 239 | + $update['af_is_hidden'] = false; |
| 240 | + $update['af_is_unhidden'] = true; |
223 | 241 | |
224 | 242 | $filters = $this->changeFilterCounts( $record, $filters, 'show' ); |
225 | 243 | |
— | — | @@ -243,6 +261,7 @@ |
244 | 262 | if( ( ($flag == 'helpful' && $direction == 'increase' ) |
245 | 263 | || ($flag == 'unhelpful' && $direction == 'decrease' ) ) |
246 | 264 | ) { |
| 265 | + // NOTE: we are bypassing traditional sql escaping here |
247 | 266 | $update[] = "af_helpful_count = af_helpful_count + 1"; |
248 | 267 | $update[] = "af_unhelpful_count = GREATEST(0, CONVERT(af_unhelpful_count, SIGNED) - 1)"; |
249 | 268 | $helpful++; |
— | — | @@ -251,6 +270,7 @@ |
252 | 271 | } elseif ( ( ($flag == 'unhelpful' && $direction == 'increase' ) |
253 | 272 | || ($flag == 'helpful' && $direction == 'decrease' ) ) |
254 | 273 | ) { |
| 274 | + // NOTE: we are bypassing traditional sql escaping here |
255 | 275 | $update[] = "af_unhelpful_count = af_unhelpful_count + 1"; |
256 | 276 | $update[] = "af_helpful_count = GREATEST(0, CONVERT(af_helpful_count, SIGNED) - 1)"; |
257 | 277 | $helpful--; |
— | — | @@ -260,15 +280,19 @@ |
261 | 281 | } else { |
262 | 282 | |
263 | 283 | if ( 'unhelpful' === $flag && $direction == 'increase') { |
| 284 | + // NOTE: we are bypassing traditional sql escaping here |
264 | 285 | $update[] = "af_unhelpful_count = af_unhelpful_count + 1"; |
265 | 286 | $unhelpful++; |
266 | 287 | } elseif ( 'unhelpful' === $flag && $direction == 'decrease') { |
| 288 | + // NOTE: we are bypassing traditional sql escaping here |
267 | 289 | $update[] = "af_unhelpful_count = GREATEST(0, CONVERT(af_unhelpful_count, SIGNED) - 1)"; |
268 | 290 | $unhelpful--; |
269 | 291 | } elseif ( $flag == 'helpful' && $direction == 'increase' ) { |
| 292 | + // NOTE: we are bypassing traditional sql escaping here |
270 | 293 | $update[] = "af_helpful_count = af_helpful_count + 1"; |
271 | 294 | $helpful++; |
272 | 295 | } elseif ( $flag == 'helpful' && $direction == 'decrease' ) { |
| 296 | + // NOTE: we are bypassing traditional sql escaping here |
273 | 297 | $update[] = "af_helpful_count = GREATEST(0, CONVERT(af_helpful_count, SIGNED) - 1)"; |
274 | 298 | $helpful--; |
275 | 299 | } |