Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulUtil.php |
— | — | @@ -5,6 +5,15 @@ |
6 | 6 | */ |
7 | 7 | class MarkAsHelpfulUtil { |
8 | 8 | |
| 9 | + /** |
| 10 | + * Generate 'mark as helpful' template for current user |
| 11 | + * @param $user Object - The current user |
| 12 | + * @param $isAbleToMark bool - flag to check if the user is able to mark the item as helpful |
| 13 | + * @param $helpfulUserList array - list of users who have marked this item as helpful |
| 14 | + * @param $type string - the object type |
| 15 | + * @param $item int - the object id |
| 16 | + * @return html | empty text |
| 17 | + */ |
9 | 18 | public static function getMarkAsHelpfulTemplate( $user, $isAbleToMark, $helpfulUserList, $type, $item ) { |
10 | 19 | |
11 | 20 | if ( $user->isAnon() ) { |
— | — | @@ -29,23 +38,31 @@ |
30 | 39 | |
31 | 40 | } |
32 | 41 | |
| 42 | + /** |
| 43 | + * The template to display in this format: {{user name or ip}} thinks this is helpful |
| 44 | + * @param $helpfulUserList array - List of users that mark the item as helpful |
| 45 | + * @return string html | empty text |
| 46 | + */ |
33 | 47 | private static function otherMarkedTemplate( $helpfulUserList ) { |
| 48 | + |
34 | 49 | if ( count( $helpfulUserList ) == 0 ) { |
35 | 50 | return ''; |
36 | 51 | } |
37 | 52 | |
38 | | - $userList = ''; |
39 | | - |
40 | | - foreach ( $helpfulUserList as $val ) { |
41 | | - $userList .= $val['user_name'] . ' '; |
| 53 | + reset( $helpfulUserList ); |
| 54 | + |
| 55 | + $user = current( $helpfulUserList ); |
| 56 | + |
| 57 | + // show the first user 'in mark as helpful' template |
| 58 | + if ( $user['user_name'] ) { |
| 59 | + $data = wfMessage( 'mah-someone-marked-text' )->params( $user['user_name'] )->escaped(); |
42 | 60 | } |
43 | | - |
44 | | - $data = ''; |
45 | | - |
46 | | - if ( $userList ) { |
47 | | - $data = wfMessage( 'mah-someone-marked-text' )->params( $userList )->escaped(); |
| 61 | + else { |
| 62 | + $data = wfMessage( 'mah-someone-marked-text' )->params( $user['user_ip'] )->escaped(); |
48 | 63 | } |
49 | | - |
| 64 | + |
| 65 | + // Add other user in user list to a hidden div, this is for future enhancement |
| 66 | + |
50 | 67 | return <<<HTML |
51 | 68 | <div class='mw-mah-wrapper'> |
52 | 69 | <span class='mah-helpful-marked-state'> |
— | — | @@ -55,6 +72,12 @@ |
56 | 73 | HTML; |
57 | 74 | } |
58 | 75 | |
| 76 | + /** |
| 77 | + * The template to display in this format: You think this is helpful |
| 78 | + * @Todo future enhancement: We may pass the list of other users as well |
| 79 | + * so we can put them in hidden div |
| 80 | + * @return string html |
| 81 | + */ |
59 | 82 | private static function ownerMarkedTemplate() { |
60 | 83 | $mahMarkedText = wfMessage( 'mah-you-marked-text' )->escaped(); |
61 | 84 | $undoLinkText = wfMessage( 'mah-undo-mark-text' )->escaped(); |
— | — | @@ -69,6 +92,10 @@ |
70 | 93 | HTML; |
71 | 94 | } |
72 | 95 | |
| 96 | + /** |
| 97 | + * The template to request a user to mark an item as helpful |
| 98 | + * @return string html |
| 99 | + */ |
73 | 100 | private static function requestToMarkTemplate() { |
74 | 101 | $mahLinkText = wfMessage( 'mah-mark-text' )->escaped(); |
75 | 102 | return <<<HTML |