r107588 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107587‎ | r107588 | r107589 >
Date:19:16, 29 December 2011
Author:bsitu
Status:ok (Comments)
Tags:
Comment:
only show markashelpful for feedback response on the talk page of feedback owner
Modified paths:
  • /trunk/extensions/MoodBar/MoodBar.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/MoodBar.hooks.php
@@ -18,40 +18,40 @@
1919 /**
2020 * Determines if this user has right to mark an feedback response as helpful, only the user who wrote the
2121 * feedback can mark the response as helpful
22 - * @param $mahaction string - mark/unmark
2322 * @param $type string - the object type to be marked
2423 * @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
2728 * @return bool
2829 */
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 ) {
3531 if ( $type == 'mbresponse' ) {
36 - switch ( $mahaction ) {
37 - case 'mark':
38 - $dbr = wfGetDB( DB_SLAVE );
 32+ $dbr = wfGetDB( DB_SLAVE );
3933
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__ );
4740
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;
5054 }
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+ }
5656 }
5757 }
5858

Follow-up revisions

RevisionCommit summaryAuthorDate
r107909followup -r107588 - remove unnecessary trailing spacesbsitu17:42, 3 January 2012

Comments

#Comment by Robmoen (talk | contribs)   19:38, 30 December 2011

Trailing space on this line:

+					'mbfr_id' => intval( $item ) 
#Comment by Catrope (talk | contribs)   12:15, 4 January 2012
+					$commenter->getTalkPage()->getPrefixedText() == $page->getPrefixedText() ) {

To compare two titles, you can also use $commenter->getTalkPage()->equals( $page ) .

Status & tagging log