Index: trunk/extensions/MoodBar/MoodBar.hooks.php |
— | — | @@ -15,7 +15,53 @@ |
16 | 16 | |
17 | 17 | return true; |
18 | 18 | } |
| 19 | + |
| 20 | + /** |
| 21 | + * Determines if this user has right to mark an feedback response as helpful |
| 22 | + * @param $mahaction string - mark/unmark |
| 23 | + * @param $type string - the object type to be marked |
| 24 | + * @param $item int - an item of $type to be marked |
| 25 | + * @param $User User Object - the User in current session |
| 26 | + * @return bool |
| 27 | + */ |
| 28 | + public static function onMarkItemAsHelpful( $mahaction, $type, $item, $User ) { |
| 29 | + |
| 30 | + $isAbleToMark = true; |
| 31 | + |
| 32 | + switch ( $mahaction ) { |
| 33 | + |
| 34 | + case 'mark': |
| 35 | + $dbr = wfGetDB( DB_SLAVE ); |
| 36 | + |
| 37 | + $conds = array( 'mbf_id = mbfr_mbf_id', 'mbfr_id' => intval( $item ) ); |
| 38 | + |
| 39 | + if ( !$User->isAnon() ) { |
| 40 | + $conds['mbf_user_id'] = $User->getId(); |
| 41 | + } |
| 42 | + else { |
| 43 | + $conds['mbf_user_ip'] = $User->getName(); |
| 44 | + } |
| 45 | + |
| 46 | + $res = $dbr->selectRow( array( 'moodbar_feedback', 'moodbar_feedback_response' ), |
| 47 | + array( 'mbf_id' ), |
| 48 | + $conds, |
| 49 | + __METHOD__ ); |
| 50 | + |
| 51 | + if ( $res === false ) { |
| 52 | + $isAbleToMark = false; |
| 53 | + } |
| 54 | + break; |
| 55 | + |
| 56 | + case 'unmark': |
| 57 | + default: |
| 58 | + //We will leve the MarkAsHelpFul extension to check if the user has unmark right |
| 59 | + break; |
| 60 | + } |
19 | 61 | |
| 62 | + return $isAbleToMark; |
| 63 | + |
| 64 | + } |
| 65 | + |
20 | 66 | /** |
21 | 67 | * Determines whether or not we should show the MoodBar. |
22 | 68 | * |
Index: trunk/extensions/MoodBar/MoodBar.php |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | $wgHooks['ResourceLoaderGetConfigVars'][] = 'MoodBarHooks::resourceLoaderGetConfigVars'; |
40 | 40 | $wgHooks['MakeGlobalVariablesScript'][] = 'MoodBarHooks::makeGlobalVariablesScript'; |
41 | 41 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'MoodBarHooks::onLoadExtensionSchemaUpdates'; |
| 42 | +$wgHooks['onMarkItemAsHelpful'][] = 'MoodBarHooks::onMarkItemAsHelpful'; |
42 | 43 | |
43 | 44 | // Special pages |
44 | 45 | $wgAutoloadClasses['SpecialMoodBar'] = dirname(__FILE__).'/SpecialMoodBar.php'; |