Index: branches/wmf/1.19wmf1/extensions/ArticleFeedbackv5/ArticleFeedbackv5.flagging.php |
— | — | @@ -0,0 +1,627 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * ArticleFeedbackv5Flagging class |
| 5 | + * |
| 6 | + * @package ArticleFeedback |
| 7 | + * @author Elizabeth M Smith <elizabeth@omniti.com> |
| 8 | + * @author Reha Sterbin <reha@omniti.com> |
| 9 | + * @version $Id$ |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * Handles flagging of feedback |
| 14 | + * |
| 15 | + * Known flags are: 'delete', 'hide', 'resetoversight', 'abuse', 'oversight', |
| 16 | + * 'unhelpful', and 'helpful' |
| 17 | + * |
| 18 | + * @package ArticleFeedback |
| 19 | + */ |
| 20 | +class ArticleFeedbackv5Flagging { |
| 21 | + |
| 22 | + /** |
| 23 | + * The user performing the action |
| 24 | + * |
| 25 | + * Either zero for a system call, or $wgUser for a user-directed one |
| 26 | + * |
| 27 | + * @var mixed |
| 28 | + */ |
| 29 | + private $user; |
| 30 | + |
| 31 | + /** |
| 32 | + * The page ID |
| 33 | + * |
| 34 | + * @var int |
| 35 | + */ |
| 36 | + private $pageId; |
| 37 | + |
| 38 | + /** |
| 39 | + * The feedback ID |
| 40 | + * |
| 41 | + * @var int |
| 42 | + */ |
| 43 | + private $feedbackId; |
| 44 | + |
| 45 | + /** |
| 46 | + * Constructor |
| 47 | + * |
| 48 | + * @param mixed $user the user performing the action ($wgUser), or |
| 49 | + * zero if it's a system call |
| 50 | + * @param int $pageId the page ID |
| 51 | + * @param int $feedbackId the feedback ID |
| 52 | + */ |
| 53 | + public function __construct( $user, $pageId, $feedbackId ) { |
| 54 | + $this->user = $user; |
| 55 | + $this->pageId = $pageId; |
| 56 | + $this->feedbackId = $feedbackId; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Run a flagging action |
| 61 | + * |
| 62 | + * @param $flag string the flag |
| 63 | + * @param $notes string [optional] any notes to send to the activity log |
| 64 | + * @param $direction string [optional] the direction of the request ('increase' / 'decrease') |
| 65 | + * @param $toggle bool [optional] whether to toggle the flag |
| 66 | + * @return array information about the run, containing at least the |
| 67 | + * keys 'result' ('Error' / 'Success') and 'reason' (a |
| 68 | + * message key) |
| 69 | + */ |
| 70 | + public function run( $flag, $notes = '', $direction = 'increase', $toggle = false ) { |
| 71 | + $flag = $flag; |
| 72 | + $notes = $notes; |
| 73 | + $direction = $direction == 'increase' ? 'increase' : 'decrease'; |
| 74 | + $toggle = $toggle ? true : false; |
| 75 | + |
| 76 | + // default values for information to be filled in |
| 77 | + $filters = array(); |
| 78 | + $update = array(); |
| 79 | + $results = array(); |
| 80 | + |
| 81 | + // start |
| 82 | + $where = array( 'af_id' => $this->feedbackId ); |
| 83 | + |
| 84 | + // we may not actually use this, but don't want to repeat this a million times |
| 85 | + $default_user = wfMessage( 'articlefeedbackv5-default-user' )->text(); |
| 86 | + |
| 87 | + // we use ONE db connection that talks to master |
| 88 | + $dbw = wfGetDB( DB_MASTER ); |
| 89 | + $dbw->begin(); |
| 90 | + $timestamp = $dbw->timestamp(); |
| 91 | + |
| 92 | + // load feedback record, bail if we don't have one |
| 93 | + $record = $this->fetchRecord( $dbw, $this->feedbackId ); |
| 94 | + |
| 95 | + if ( $record === false || !$record->af_id ) { |
| 96 | + // no-op, because this is already broken |
| 97 | + $error = 'articlefeedbackv5-invalid-feedback-id'; |
| 98 | + |
| 99 | + } elseif ( 'delete' == $flag && $this->isAllowed( 'aftv5-delete-feedback' ) ) { |
| 100 | + |
| 101 | + // deleting means to "mark as oversighted" and "delete" it |
| 102 | + // oversighting also auto-hides the item |
| 103 | + |
| 104 | + // increase means "oversight this" |
| 105 | + if ( $direction == 'increase' ) { |
| 106 | + $activity = 'oversight'; |
| 107 | + |
| 108 | + // delete |
| 109 | + $update['af_is_deleted'] = true; |
| 110 | + $update['af_is_undeleted'] = false; |
| 111 | + // only store the oversighter on delete/oversight |
| 112 | + $update['af_oversight_user_id'] = $this->getUserId(); |
| 113 | + $update['af_oversight_timestamp'] = $timestamp; |
| 114 | + // delete specific filters |
| 115 | + $filters['deleted'] = 1; |
| 116 | + $filters['notdeleted'] = -1; |
| 117 | + if ( true == $record->af_is_undeleted ) { |
| 118 | + $filters['undeleted'] = -1; |
| 119 | + } |
| 120 | + |
| 121 | + // This is data for the "hidden by, oversighted by" red line |
| 122 | + $results['oversight-user'] = $this->getUserLink(); |
| 123 | + $results['oversight-timestamp'] = wfTimestamp( TS_RFC2822, $timestamp ); |
| 124 | + |
| 125 | + // autohide if not hidden |
| 126 | + if ( false == $record->af_is_hidden ) { |
| 127 | + $update['af_is_hidden'] = true; |
| 128 | + $update['af_is_unhidden'] = false; |
| 129 | + $filters = $this->changeFilterCounts( $record, $filters, 'hide' ); |
| 130 | + // 0 is used for "autohidden" purposes, we'll explicitly set it to overwrite last hider |
| 131 | + $update['af_hide_user_id'] = 0; |
| 132 | + $update['af_hide_timestamp'] = $timestamp; |
| 133 | + $implicit_hide = true; // for logging |
| 134 | + // tell front-end autohiding was done |
| 135 | + $results['autohidden'] = 1; |
| 136 | + // This is data for the "hidden by, oversighted by" red line |
| 137 | + $results['hide-user'] = ApiArticleFeedbackv5Utils::getUserLink( null, $default_user ); |
| 138 | + $results['hide-timestamp'] = wfTimestamp( TS_RFC2822, $timestamp ); |
| 139 | + } |
| 140 | + |
| 141 | + } else { |
| 142 | + // decrease means "unoversight this" but does NOT auto-unhide |
| 143 | + $activity = 'unoversight'; |
| 144 | + $update['af_is_deleted'] = false; |
| 145 | + $update['af_is_undeleted'] = true; |
| 146 | + // increment "undeleted", decrement "deleted" |
| 147 | + // NOTE: we do not touch visible, since hidden controls visiblity |
| 148 | + $filters['deleted'] = -1; |
| 149 | + $filters['undeleted'] = 1; |
| 150 | + // increment "notdeleted" for count of everything but oversighted |
| 151 | + $filters['notdeleted'] = 1; |
| 152 | + } |
| 153 | + |
| 154 | + } elseif ( 'hide' == $flag && $this->isAllowed( 'aftv5-hide-feedback' ) ) { |
| 155 | + |
| 156 | + // increase means "hide this" |
| 157 | + if ( $direction == 'increase' ) { |
| 158 | + $activity = 'hidden'; |
| 159 | + |
| 160 | + // hide |
| 161 | + $update['af_is_hidden'] = true; |
| 162 | + $update['af_is_unhidden'] = false; |
| 163 | + // only store the hider on hide not show |
| 164 | + $update['af_hide_user_id'] = $this->getUserId(); |
| 165 | + $update['af_hide_timestamp'] = $timestamp; |
| 166 | + $filters = $this->changeFilterCounts( $record, $filters, 'hide' ); |
| 167 | + |
| 168 | + // This is data for the "hidden by, oversighted by" red line |
| 169 | + $results['hide-user'] = $this->getUserLink(); |
| 170 | + $results['hide-timestamp'] = wfTimestamp( TS_RFC2822, $timestamp ); |
| 171 | + |
| 172 | + } else { |
| 173 | + // decrease means "unhide this" |
| 174 | + $activity = 'unhidden'; |
| 175 | + |
| 176 | + $update['af_is_hidden'] = false; |
| 177 | + $update['af_is_unhidden'] = true; |
| 178 | + |
| 179 | + $filters = $this->changeFilterCounts( $record, $filters, 'show' ); |
| 180 | + } |
| 181 | + |
| 182 | + } elseif ( 'resetoversight' === $flag && $this->isAllowed( 'aftv5-delete-feedback' ) ) { |
| 183 | + |
| 184 | + $activity = 'decline'; |
| 185 | + // oversight request count becomes 0 |
| 186 | + $update['af_oversight_count'] = 0; |
| 187 | + // declined oversight is flagged |
| 188 | + $update['af_is_declined'] = true; |
| 189 | + $filters['declined'] = 1; |
| 190 | + // if the oversight count was greater then 1 |
| 191 | + if ( 0 < $record->af_oversight_count ) { |
| 192 | + $filters['needsoversight'] = -1; |
| 193 | + } |
| 194 | + |
| 195 | + } elseif ( 'abuse' === $flag ) { |
| 196 | + |
| 197 | + // Conditional formatting for abuse flag |
| 198 | + global $wgArticleFeedbackv5AbusiveThreshold, |
| 199 | + $wgArticleFeedbackv5HideAbuseThreshold; |
| 200 | + |
| 201 | + $results['abuse_count'] = $record->af_abuse_count; |
| 202 | + |
| 203 | + // Make the abuse count in the result reflect this vote. |
| 204 | + if ( $direction == 'increase' ) { |
| 205 | + $results['abuse_count']++; |
| 206 | + } else { |
| 207 | + $results['abuse_count']--; |
| 208 | + } |
| 209 | + // no negative numbers |
| 210 | + $results['abuse_count'] = max( 0, $results['abuse_count'] ); |
| 211 | + |
| 212 | + // Return a flag in the JSON, that turns the link red. |
| 213 | + if ( $results['abuse_count'] >= $wgArticleFeedbackv5AbusiveThreshold ) { |
| 214 | + $results['abusive'] = 1; |
| 215 | + } |
| 216 | + |
| 217 | + // Adding a new abuse flag: abusive++ |
| 218 | + if ( $direction == 'increase' ) { |
| 219 | + $activity = 'flag'; |
| 220 | + $filters['abusive'] = 1; |
| 221 | + // NOTE: we are bypassing traditional sql escaping here |
| 222 | + $update[] = "af_abuse_count = af_abuse_count + 1"; |
| 223 | + |
| 224 | + // Auto-hide after threshold flags |
| 225 | + if ( $record->af_abuse_count > $wgArticleFeedbackv5HideAbuseThreshold |
| 226 | + && false == $record->af_is_hidden ) { |
| 227 | + // hide |
| 228 | + $update['af_is_hidden'] = true; |
| 229 | + $update['af_is_unhidden'] = false; |
| 230 | + // 0 is used for "autohidden" purposes, we'll explicitly set it to overwrite last hider |
| 231 | + $update['af_hide_user_id'] = 0; |
| 232 | + $update['af_hide_timestamp'] = $timestamp; |
| 233 | + |
| 234 | + $filters = $this->changeFilterCounts( $record, $filters, 'hide' ); |
| 235 | + $results['abuse-hidden'] = 1; |
| 236 | + $implicit_hide = true; |
| 237 | + |
| 238 | + // tell front-end autohiding was done |
| 239 | + $results['autohidden'] = 1; |
| 240 | + // This is data for the "hidden by, oversighted by" red line |
| 241 | + $results['hide-user'] = ApiArticleFeedbackv5Utils::getUserLink( null, $default_user ); |
| 242 | + $results['hide-timestamp'] = wfTimestamp( TS_RFC2822, $timestamp ); |
| 243 | + } |
| 244 | + } |
| 245 | + |
| 246 | + // Removing the last abuse flag: abusive-- |
| 247 | + elseif ( $direction == 'decrease' ) { |
| 248 | + $activity = 'unflag'; |
| 249 | + $filters['abusive'] = -1; |
| 250 | + // NOTE: we are bypassing traditional sql escaping here |
| 251 | + $update[] = "af_abuse_count = GREATEST(CONVERT(af_abuse_count, SIGNED) -1, 0)"; |
| 252 | + |
| 253 | + // Un-hide if we don't have 5 flags anymore |
| 254 | + if ( $record->af_abuse_count == 5 && true == $record->af_is_hidden ) { |
| 255 | + $update['af_is_hidden'] = false; |
| 256 | + $update['af_is_unhidden'] = true; |
| 257 | + |
| 258 | + $filters = $this->changeFilterCounts( $record, $filters, 'show' ); |
| 259 | + |
| 260 | + $implicit_unhide = true; |
| 261 | + } |
| 262 | + } else { |
| 263 | + // TODO: real error here? |
| 264 | + $error = 'articlefeedbackv5-invalid-feedback-flag'; |
| 265 | + } |
| 266 | + |
| 267 | + // NOTE: this is actually request/unrequest oversight and works similar to abuse |
| 268 | + } elseif ( 'oversight' === $flag && $this->isAllowed( 'aftv5-hide-feedback' ) ) { |
| 269 | + |
| 270 | + if ( $direction == 'increase' ) { |
| 271 | + $activity = 'request'; |
| 272 | + $filters['needsoversight'] = 1; |
| 273 | + // NOTE: we are bypassing traditional sql escaping here |
| 274 | + $update[] = "af_oversight_count = af_oversight_count + 1"; |
| 275 | + |
| 276 | + // autohide if not hidden |
| 277 | + if ( false == $record->af_is_hidden ) { |
| 278 | + $update['af_is_hidden'] = true; |
| 279 | + $update['af_is_unhidden'] = false; |
| 280 | + // 0 is used for "autohidden" purposes, we'll explicitly set it to overwrite last hider |
| 281 | + $update['af_hide_user_id'] = 0; |
| 282 | + $update['af_hide_timestamp'] = $timestamp; |
| 283 | + |
| 284 | + $filters = $this->changeFilterCounts( $record, $filters, 'hide' ); |
| 285 | + $implicit_hide = true; // for logging |
| 286 | + // tell front-end autohiding was done |
| 287 | + $results['autohidden'] = 1; |
| 288 | + // This is data for the "hidden by, oversighted by" red line |
| 289 | + $results['hide-user'] = ApiArticleFeedbackv5Utils::getUserLink( null, $default_user ); |
| 290 | + $results['hide-timestamp'] = wfTimestamp( TS_RFC2822, $timestamp ); |
| 291 | + } |
| 292 | + |
| 293 | + // IF the previous setting was 0, send an email |
| 294 | + if ( $record->af_oversight_count < 1 ) { |
| 295 | + $this->sendOversightEmail(); |
| 296 | + } |
| 297 | + |
| 298 | + } elseif ( $direction == 'decrease' ) { |
| 299 | + $activity = 'unrequest'; |
| 300 | + $filters['needsoversight'] = -1; |
| 301 | + // NOTE: we are bypassing traditional sql escaping here |
| 302 | + $update[] = "af_oversight_count = GREATEST(CONVERT(af_oversight_count, SIGNED) - 1, 0)"; |
| 303 | + } else { |
| 304 | + // TODO: real error here? |
| 305 | + $error = 'articlefeedbackv5-invalid-feedback-flag'; |
| 306 | + } |
| 307 | + |
| 308 | + // helpful and unhelpful flagging |
| 309 | + } elseif ( 'unhelpful' === $flag || 'helpful' === $flag ) { |
| 310 | + |
| 311 | + $results['toggle'] = $toggle; |
| 312 | + $helpful = $record->af_helpful_count; |
| 313 | + $unhelpful = $record->af_unhelpful_count; |
| 314 | + |
| 315 | + // if toggle is on, we are decreasing one and increasing the other atomically |
| 316 | + // means one less http request and the counts don't mess up |
| 317 | + if ( true == $toggle ) { |
| 318 | + |
| 319 | + if ( ( ( $flag == 'helpful' && $direction == 'increase' ) |
| 320 | + || ( $flag == 'unhelpful' && $direction == 'decrease' ) ) |
| 321 | + ) { |
| 322 | + // NOTE: we are bypassing traditional sql escaping here |
| 323 | + $update[] = "af_helpful_count = af_helpful_count + 1"; |
| 324 | + $update[] = "af_unhelpful_count = GREATEST(0, CONVERT(af_unhelpful_count, SIGNED) - 1)"; |
| 325 | + $helpful++; |
| 326 | + $unhelpful--; |
| 327 | + |
| 328 | + } elseif ( ( ( $flag == 'unhelpful' && $direction == 'increase' ) |
| 329 | + || ( $flag == 'helpful' && $direction == 'decrease' ) ) |
| 330 | + ) { |
| 331 | + // NOTE: we are bypassing traditional sql escaping here |
| 332 | + $update[] = "af_unhelpful_count = af_unhelpful_count + 1"; |
| 333 | + $update[] = "af_helpful_count = GREATEST(0, CONVERT(af_helpful_count, SIGNED) - 1)"; |
| 334 | + $helpful--; |
| 335 | + $unhelpful++; |
| 336 | + } |
| 337 | + |
| 338 | + } else { |
| 339 | + |
| 340 | + if ( 'unhelpful' === $flag && $direction == 'increase' ) { |
| 341 | + // NOTE: we are bypassing traditional sql escaping here |
| 342 | + $update[] = "af_unhelpful_count = af_unhelpful_count + 1"; |
| 343 | + $unhelpful++; |
| 344 | + } elseif ( 'unhelpful' === $flag && $direction == 'decrease' ) { |
| 345 | + // NOTE: we are bypassing traditional sql escaping here |
| 346 | + $update[] = "af_unhelpful_count = GREATEST(0, CONVERT(af_unhelpful_count, SIGNED) - 1)"; |
| 347 | + $unhelpful--; |
| 348 | + } elseif ( $flag == 'helpful' && $direction == 'increase' ) { |
| 349 | + // NOTE: we are bypassing traditional sql escaping here |
| 350 | + $update[] = "af_helpful_count = af_helpful_count + 1"; |
| 351 | + $helpful++; |
| 352 | + } elseif ( $flag == 'helpful' && $direction == 'decrease' ) { |
| 353 | + // NOTE: we are bypassing traditional sql escaping here |
| 354 | + $update[] = "af_helpful_count = GREATEST(0, CONVERT(af_helpful_count, SIGNED) - 1)"; |
| 355 | + $helpful--; |
| 356 | + } |
| 357 | + |
| 358 | + } |
| 359 | + |
| 360 | + $netHelpfulness = $helpful - $unhelpful; |
| 361 | + |
| 362 | + // increase helpful OR decrease unhelpful |
| 363 | + if ( ( ( $flag == 'helpful' && $direction == 'increase' ) |
| 364 | + || ( $flag == 'unhelpful' && $direction == 'decrease' ) ) |
| 365 | + ) { |
| 366 | + // net was -1: no longer unhelpful |
| 367 | + if ( $netHelpfulness == -1 ) { |
| 368 | + $filters['unhelpful'] = -1; |
| 369 | + } |
| 370 | + |
| 371 | + // net was 0: now helpful |
| 372 | + if ( $netHelpfulness == 0 ) { |
| 373 | + $filters['helpful'] = 1; |
| 374 | + } |
| 375 | + } |
| 376 | + |
| 377 | + // increase unhelpful OR decrease unhelpful |
| 378 | + if ( ( ( $flag == 'unhelpful' && $direction == 'increase' ) |
| 379 | + || ( $flag == 'helpful' && $direction == 'decrease' ) ) |
| 380 | + ) { |
| 381 | + // net was 1: no longer helpful |
| 382 | + if ( $netHelpfulness == 1 ) { |
| 383 | + $filters['helpful'] = -1; |
| 384 | + } |
| 385 | + |
| 386 | + // net was 0: now unhelpful |
| 387 | + if ( $netHelpfulness == 0 ) { |
| 388 | + $filters['unhelpful'] = 1; |
| 389 | + } |
| 390 | + } |
| 391 | + |
| 392 | + } else { |
| 393 | + $error = 'articlefeedbackv5-invalid-feedback-flag'; |
| 394 | + } |
| 395 | + |
| 396 | + // we were valid |
| 397 | + if ( !isset( $error ) ) { |
| 398 | + |
| 399 | + $success = $dbw->update( |
| 400 | + 'aft_article_feedback', |
| 401 | + $update, |
| 402 | + $where, |
| 403 | + __METHOD__ |
| 404 | + ); |
| 405 | + |
| 406 | + // Update the filter count rollups. |
| 407 | + ApiArticleFeedbackv5Utils::updateFilterCounts( $dbw, $this->pageId, $filters ); |
| 408 | + |
| 409 | + $dbw->commit(); // everything went well, so we commit our db changes |
| 410 | + |
| 411 | + // helpfulness counts are NOT logged, no activity is set |
| 412 | + if ( isset( $activity ) ) { |
| 413 | + ApiArticleFeedbackv5Utils::logActivity( $activity, $this->pageId, $this->feedbackId, $notes, $this->isSystemCall() ); |
| 414 | + } |
| 415 | + |
| 416 | + // handle implicit hide/show logging |
| 417 | + if ( isset( $implicit_hide ) && $implicit_hide ) { |
| 418 | + ApiArticleFeedbackv5Utils::logActivity( 'hidden' , $this->pageId, $this->feedbackId, '', true ); |
| 419 | + } |
| 420 | + |
| 421 | + // Update helpful/unhelpful display count after submission. |
| 422 | + if ( $flag == 'helpful' || $flag == 'unhelpful' ) { |
| 423 | + |
| 424 | + // no negative numbers please |
| 425 | + $helpful = max( 0, $helpful ); |
| 426 | + $unhelpful = max( 0, $unhelpful ); |
| 427 | + |
| 428 | + $results['helpful'] = wfMessage( |
| 429 | + 'articlefeedbackv5-form-helpful-votes', |
| 430 | + $helpful, $unhelpful |
| 431 | + )->escaped(); |
| 432 | + |
| 433 | + // Update net_helpfulness after flagging as helpful/unhelpful. |
| 434 | + $dbw->update( |
| 435 | + 'aft_article_feedback', |
| 436 | + array( 'af_net_helpfulness = CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED)' ), |
| 437 | + array( |
| 438 | + 'af_id' => $params['feedbackid'], |
| 439 | + ), |
| 440 | + __METHOD__ |
| 441 | + ); |
| 442 | + } |
| 443 | + } |
| 444 | + |
| 445 | + if ( isset( $error ) ) { |
| 446 | + $results['result'] = 'Error'; |
| 447 | + $results['reason'] = $error; |
| 448 | + } else { |
| 449 | + $results['result'] = 'Success'; |
| 450 | + $results['reason'] = null; |
| 451 | + } |
| 452 | + |
| 453 | + return $results; |
| 454 | + } |
| 455 | + |
| 456 | + /** |
| 457 | + * Returns whether this is a system call rather than a user-directed one |
| 458 | + * |
| 459 | + * @return bool |
| 460 | + */ |
| 461 | + public function isSystemCall() { |
| 462 | + return $this->user === 0; |
| 463 | + } |
| 464 | + |
| 465 | + /** |
| 466 | + * Returns whether an action is allowed |
| 467 | + * |
| 468 | + * @param $action string the name of the action |
| 469 | + * @return bool whether it's allowed |
| 470 | + */ |
| 471 | + public function isAllowed( $action ) { |
| 472 | + if ( $this->isSystemCall() ) { |
| 473 | + return true; |
| 474 | + } |
| 475 | + return $this->user->isAllowed( $action ); |
| 476 | + } |
| 477 | + |
| 478 | + /** |
| 479 | + * Gets the user id |
| 480 | + * |
| 481 | + * @return mixed the user's ID, or zero if it's a system call |
| 482 | + */ |
| 483 | + public function getUserId() { |
| 484 | + if ( $this->isSystemCall() ) { |
| 485 | + return 0; |
| 486 | + } |
| 487 | + return $this->user->getId(); |
| 488 | + } |
| 489 | + |
| 490 | + /** |
| 491 | + * Gets the user link, for use in displays |
| 492 | + * |
| 493 | + * @return string the link |
| 494 | + */ |
| 495 | + public function getUserLink() { |
| 496 | + if ( $this->isSystemCall() ) { |
| 497 | + return ApiArticleFeedbackv5Utils::getUserLink( null, $default_user ); |
| 498 | + } |
| 499 | + return ApiArticleFeedbackv5Utils::getUserLink( $this->user ); |
| 500 | + } |
| 501 | + |
| 502 | + /** |
| 503 | + * Helper function to grab a record from the database with information |
| 504 | + * about the current feedback row |
| 505 | + * |
| 506 | + * @param object $dbw connection to database |
| 507 | + * @param int $id id of the feedback to fetch |
| 508 | + * @return object database record |
| 509 | + */ |
| 510 | + private function fetchRecord( $dbw, $id ) { |
| 511 | + $record = $dbw->selectRow( |
| 512 | + 'aft_article_feedback', |
| 513 | + array( |
| 514 | + 'af_id', |
| 515 | + 'af_page_id', |
| 516 | + 'af_abuse_count', |
| 517 | + 'af_is_hidden', |
| 518 | + 'af_helpful_count', |
| 519 | + 'af_unhelpful_count', |
| 520 | + 'af_is_deleted', |
| 521 | + 'af_net_helpfulness', |
| 522 | + 'af_is_unhidden', |
| 523 | + 'af_is_undeleted', |
| 524 | + 'af_is_declined', |
| 525 | + 'af_has_comment', |
| 526 | + 'af_oversight_count' ), |
| 527 | + array( 'af_id' => $id ) |
| 528 | + ); |
| 529 | + return $record; |
| 530 | + } |
| 531 | + |
| 532 | + /** |
| 533 | + * Helper function to manipulate all flags when hiding/showing a piece of feedback |
| 534 | + * |
| 535 | + * @param object $record existing feedback database record |
| 536 | + * @param array $filters existing filters |
| 537 | + * @param string $action 'hide' or 'show' |
| 538 | + * @return array the filter array with new filter choices added |
| 539 | + */ |
| 540 | + protected function changeFilterCounts( $record, $filters, $action ) { |
| 541 | + // only filters that hide shouldn't manipulate are |
| 542 | + // all, deleted, undeleted, and notdeleted |
| 543 | + |
| 544 | + // use -1 (decrement) for hide, 1 for increment (show) - default is hide |
| 545 | + switch( $action ) { |
| 546 | + case 'show': |
| 547 | + $int = 1; |
| 548 | + // if we're showing, this will increment |
| 549 | + $filters['unhidden'] = 1; |
| 550 | + break; |
| 551 | + default: |
| 552 | + // if we're hiding, and was unhidden, decrement |
| 553 | + if ( true == $record->af_is_unhidden ) { |
| 554 | + $filters['unhidden'] = -1; |
| 555 | + } |
| 556 | + $int = -1; |
| 557 | + break; |
| 558 | + } |
| 559 | + |
| 560 | + // visible, invisible, unhidden |
| 561 | + $filters['visible'] = $int; |
| 562 | + $filters['invisible'] = -$int; // opposite of int |
| 563 | + |
| 564 | + // comment |
| 565 | + if ( true == $record->af_has_comment ) { |
| 566 | + $filters['comment'] = $int; |
| 567 | + } |
| 568 | + |
| 569 | + // abusive |
| 570 | + if ( $record->af_abuse_count > 1 ) { |
| 571 | + $filters['abusive'] = $int; |
| 572 | + } |
| 573 | + // helpful and unhelpful |
| 574 | + if ( $record->af_net_helpfulness > 1 ) { |
| 575 | + $filters['helpful'] = $int; |
| 576 | + } elseif ( $record->af_net_helpfulness < 1 ) { |
| 577 | + $filters['unhelpful'] = $int; |
| 578 | + } |
| 579 | + |
| 580 | + return $filters; |
| 581 | + } |
| 582 | + |
| 583 | + /** |
| 584 | + * Helper function to dig out page url and title, feedback permalink, and |
| 585 | + * requestor page url and name - if all this data can be retrieved properly |
| 586 | + * it shoves an email job into the queue for sending to the oversighters' |
| 587 | + * mailing list - only called for NEW oversight requests |
| 588 | + */ |
| 589 | + protected function sendOversightEmail() { |
| 590 | + global $wgUser; |
| 591 | + |
| 592 | + // jobs need a title object |
| 593 | + $title_object = Title::newFromID( $this->pageId ); |
| 594 | + |
| 595 | + if ( !$title_object ) { |
| 596 | + return; // no title object, no mail |
| 597 | + } |
| 598 | + |
| 599 | + // get the string name of the page |
| 600 | + $page_name = $title_object->getDBKey(); |
| 601 | + |
| 602 | + // make a title out of our user (sigh) |
| 603 | + $user_page = $wgUser->getPage(); |
| 604 | + |
| 605 | + if ( !$user_page ) { |
| 606 | + return; // no user title object, no mail |
| 607 | + } |
| 608 | + |
| 609 | + // to build our permalink, use the feedback entry key + the page name (isn't page name a title? but title is an object? confusing) |
| 610 | + $permalink = SpecialPage::getTitleFor( 'ArticleFeedbackv5', "$page_name/" . $this->feedbackId ); |
| 611 | + |
| 612 | + if ( !$permalink ) { |
| 613 | + return; // no proper permalink? no mail |
| 614 | + } |
| 615 | + |
| 616 | + // build our params |
| 617 | + $params = array( 'user_name' => $wgUser->getName(), |
| 618 | + 'user_url' => $user_page->getCanonicalUrl(), |
| 619 | + 'page_name' => $title_object->getPrefixedText(), |
| 620 | + 'page_url' => $title_object->getCanonicalUrl(), |
| 621 | + 'permalink' => $permalink->getCanonicalUrl() ); |
| 622 | + |
| 623 | + $job = new ArticleFeedbackv5MailerJob( $title_object, $params ); |
| 624 | + $job->insert(); |
| 625 | + } |
| 626 | + |
| 627 | +} |
| 628 | + |
Property changes on: branches/wmf/1.19wmf1/extensions/ArticleFeedbackv5/ArticleFeedbackv5.flagging.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 629 | + native |