Index: trunk/extensions/MoodBar/MoodBar.hooks.php |
— | — | @@ -18,40 +18,40 @@ |
19 | 19 | /** |
20 | 20 | * Determines if this user has right to mark an feedback response as helpful, only the user who wrote the |
21 | 21 | * feedback can mark the response as helpful |
22 | | - * @param $mahaction string - mark/unmark |
23 | 22 | * @param $type string - the object type to be marked |
24 | 23 | * @param $item int - an item of $type to be marked |
25 | | - * @param $User User Object - the User in current session |
26 | | - * @param $isAbleToMark bool - determine whether the user is able to mark the item |
| 24 | + * @param $user User Object - the User in current session |
| 25 | + * @param $isAbleToMark bool - determine if the user has permission to mark the item |
| 26 | + * @param $page Title Object - the page requesting the item |
| 27 | + * @param $isAbleToShow bool - determin if the page has permission to request the item |
27 | 28 | * @return bool |
28 | 29 | */ |
29 | | - public static function onMarkItemAsHelpful( $mahaction, $type, $item, $User, &$isAbleToMark ) { |
30 | | - if ( $User->isAnon() ) { |
31 | | - $isAbleToMark = false; |
32 | | - return true; |
33 | | - } |
34 | | - |
| 30 | + public static function onMarkItemAsHelpful( $type, $item, $user, &$isAbleToMark, $page, &$isAbleToShow ) { |
35 | 31 | if ( $type == 'mbresponse' ) { |
36 | | - switch ( $mahaction ) { |
37 | | - case 'mark': |
38 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 32 | + $dbr = wfGetDB( DB_SLAVE ); |
39 | 33 | |
40 | | - $res = $dbr->selectRow( |
41 | | - array( 'moodbar_feedback', 'moodbar_feedback_response' ), |
42 | | - array( 'mbf_id' ), |
43 | | - array( 'mbf_id = mbfr_mbf_id', |
44 | | - 'mbfr_id' => intval( $item ), |
45 | | - 'mbf_user_id' => $User->getId() |
46 | | - ), __METHOD__ ); |
| 34 | + $res = $dbr->selectRow( |
| 35 | + array( 'moodbar_feedback', 'moodbar_feedback_response' ), |
| 36 | + array( 'mbf_id', 'mbf_user_id' ), |
| 37 | + array( 'mbf_id = mbfr_mbf_id', |
| 38 | + 'mbfr_id' => intval( $item ) |
| 39 | + ),__METHOD__ ); |
47 | 40 | |
48 | | - if ( $res === false ) { |
49 | | - $isAbleToMark = false; |
| 41 | + if ( $res !== false ) { |
| 42 | + |
| 43 | + $commenter = User::newFromId( $res->mbf_user_id ); |
| 44 | + |
| 45 | + // Make sure that the page requesting 'mark as helpful' item is the |
| 46 | + // talk page of the user who wrote the feedback |
| 47 | + if ( $commenter && $page->isTalkPage() && |
| 48 | + $commenter->getTalkPage()->getPrefixedText() == $page->getPrefixedText() ) { |
| 49 | + |
| 50 | + $isAbleToShow = true; |
| 51 | + |
| 52 | + if ( !$user->isAnon() && $res->mbf_user_id == $user->getId() ) { |
| 53 | + $isAbleToMark = true; |
50 | 54 | } |
51 | | - break; |
52 | | - case 'unmark': |
53 | | - default: |
54 | | - //We will leve the MarkAsHelpFul extension to check if the user has unmark right |
55 | | - break; |
| 55 | + } |
56 | 56 | } |
57 | 57 | } |
58 | 58 | |