r106844 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106843‎ | r106844 | r106845 >
Date:19:38, 20 December 2011
Author:bsitu
Status:resolved (Comments)
Tags:
Comment:
Adding Mark as helpful hook to MoodBar
Modified paths:
  • /trunk/extensions/MoodBar/MoodBar.hooks.php (modified) (history)
  • /trunk/extensions/MoodBar/MoodBar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/MoodBar.hooks.php
@@ -15,7 +15,53 @@
1616
1717 return true;
1818 }
 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+ }
1961
 62+ return $isAbleToMark;
 63+
 64+ }
 65+
2066 /**
2167 * Determines whether or not we should show the MoodBar.
2268 *
Index: trunk/extensions/MoodBar/MoodBar.php
@@ -38,6 +38,7 @@
3939 $wgHooks['ResourceLoaderGetConfigVars'][] = 'MoodBarHooks::resourceLoaderGetConfigVars';
4040 $wgHooks['MakeGlobalVariablesScript'][] = 'MoodBarHooks::makeGlobalVariablesScript';
4141 $wgHooks['LoadExtensionSchemaUpdates'][] = 'MoodBarHooks::onLoadExtensionSchemaUpdates';
 42+$wgHooks['onMarkItemAsHelpful'][] = 'MoodBarHooks::onMarkItemAsHelpful';
4243
4344 // Special pages
4445 $wgAutoloadClasses['SpecialMoodBar'] = dirname(__FILE__).'/SpecialMoodBar.php';

Follow-up revisions

RevisionCommit summaryAuthorDate
r107008follow up to -r106844 - alter the logic for Mark As Helpful hook function in ...bsitu23:44, 21 December 2011
r107085follow up to -r106844 - add more comment to the function so the logic is clearbsitu18:40, 22 December 2011

Comments

#Comment by Catrope (talk | contribs)   18:23, 22 December 2011

What logic does this function use? It's not commented at all, and the code is non-obvious, so it's kind of hard to tell what's going on and why you're doing what you're doing. It looks like a user can mark a response as helpful if and only if they authored the feedback that the response is responding to. Is that right?

#Comment by Bsitu (talk | contribs)   18:33, 22 December 2011

Yes, that's right, I will add comment to make it more clear

Status & tagging log