Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulUtil.php |
— | — | @@ -1,58 +1,73 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +/** |
| 5 | + * Utility class for Mark As Helpful |
| 6 | + */ |
4 | 7 | class MarkAsHelpfulUtil { |
5 | 8 | |
6 | 9 | public static function getMarkAsHelpfulTemplate( $user, $isAbleToMark, $helpfulUserList, $type, $item ) { |
| 10 | + |
7 | 11 | if ( $user->isAnon() ) { |
8 | | - |
9 | | - $userList = ''; |
10 | | - |
11 | | - foreach ( $helpfulUserList as $val ) { |
12 | | - $userList .= $val['user_name'] . ' '; |
13 | | - } |
14 | | - |
15 | | - $data = ''; |
16 | | - |
17 | | - if ( $userList ) { |
18 | | - $data = wfMessage( 'mah-someone-marked-text' )->params( $userList )->escaped(); |
19 | | - } |
20 | | - |
21 | | - return <<<HTML |
22 | | - <div class="mw-mah-wrapper"> |
23 | | - $data |
24 | | - </div> |
25 | | -HTML; |
| 12 | + $html = self::otherMarkedTemplate( $helpfulUserList ); |
26 | 13 | } else { |
27 | | - $userList = ''; |
28 | 14 | $userId = $user->getId(); |
29 | 15 | |
30 | 16 | if ( isset( $helpfulUserList[$userId] ) ) { |
31 | | - $mahMarkedText = wfMessage( 'mah-you-marked-text' )->escaped(); |
32 | | - $undoLinkText = wfMessage( 'mah-undo-mark-text' )->escaped(); |
33 | | - |
34 | | - return <<<HTML |
35 | | - <div class="mw-mah-wrapper"> |
36 | | - <span class='mah-helpful-marked-state'> |
37 | | - $mahMarkedText |
38 | | - </span> |
39 | | - (<a class='markashelpful-undo'>$undoLinkText</a>) |
40 | | - </div> |
41 | | -HTML; |
| 17 | + $html = self::ownerMarkedTemplate(); |
42 | 18 | } else { |
43 | 19 | if ( $isAbleToMark ) { |
44 | | - $mahLinkText = wfMessage( 'mah-mark-text' )->escaped(); |
45 | | - return <<<HTML |
46 | | - <div class="mw-mah-wrapper"> |
47 | | - <a class='mah-helpful-state markashelpful-mark'> |
48 | | - $mahLinkText |
49 | | - </a> |
50 | | - </div> |
51 | | -HTML; |
| 20 | + $html = self::requestToMarkTemplate(); |
52 | 21 | } |
| 22 | + else { |
| 23 | + $html = self::otherMarkedTemplate( $helpfulUserList ); |
| 24 | + } |
53 | 25 | |
54 | 26 | } |
55 | 27 | } |
56 | 28 | |
| 29 | + return '<div class="mw-mah-wrapper">' . $html . '</div>'; |
| 30 | + |
57 | 31 | } |
| 32 | + |
| 33 | + private static function otherMarkedTemplate( $helpfulUserList ) { |
| 34 | + $userList = ''; |
58 | 35 | |
| 36 | + foreach ( $helpfulUserList as $val ) { |
| 37 | + $userList .= $val['user_name'] . ' '; |
| 38 | + } |
| 39 | + |
| 40 | + $data = ''; |
| 41 | + |
| 42 | + if ( $userList ) { |
| 43 | + $data = wfMessage( 'mah-someone-marked-text' )->params( $userList )->escaped(); |
| 44 | + } |
| 45 | + |
| 46 | + return <<<HTML |
| 47 | + <span class='mah-helpful-marked-state'> |
| 48 | + $data |
| 49 | + </span> |
| 50 | +HTML; |
| 51 | + } |
| 52 | + |
| 53 | + private static function ownerMarkedTemplate() { |
| 54 | + $mahMarkedText = wfMessage( 'mah-you-marked-text' )->escaped(); |
| 55 | + $undoLinkText = wfMessage( 'mah-undo-mark-text' )->escaped(); |
| 56 | + |
| 57 | + return <<<HTML |
| 58 | + <span class='mah-helpful-marked-state'> |
| 59 | + $mahMarkedText |
| 60 | + </span> |
| 61 | + (<a class='markashelpful-undo'>$undoLinkText</a>) |
| 62 | +HTML; |
| 63 | + } |
| 64 | + |
| 65 | + private static function requestToMarkTemplate() { |
| 66 | + $mahLinkText = wfMessage( 'mah-mark-text' )->escaped(); |
| 67 | + return <<<HTML |
| 68 | + <a class='mah-helpful-state markashelpful-mark'> |
| 69 | + $mahLinkText |
| 70 | + </a> |
| 71 | +HTML; |
| 72 | + } |
| 73 | + |
59 | 74 | } |