r106906 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106905‎ | r106906 | r106907 >
Date:00:35, 21 December 2011
Author:bsitu
Status:deferred
Tags:markashelpful 
Comment:
updated the template and moved template generation for different cases to individual functions
Modified paths:
  • /trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulUtil.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulUtil.php
@@ -1,58 +1,73 @@
22 <?php
33
 4+/**
 5+ * Utility class for Mark As Helpful
 6+ */
47 class MarkAsHelpfulUtil {
58
69 public static function getMarkAsHelpfulTemplate( $user, $isAbleToMark, $helpfulUserList, $type, $item ) {
 10+
711 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 );
2613 } else {
27 - $userList = '';
2814 $userId = $user->getId();
2915
3016 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 - &nbsp;(<a class='markashelpful-undo'>$undoLinkText</a>)
40 - </div>
41 -HTML;
 17+ $html = self::ownerMarkedTemplate();
4218 } else {
4319 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();
5221 }
 22+ else {
 23+ $html = self::otherMarkedTemplate( $helpfulUserList );
 24+ }
5325
5426 }
5527 }
5628
 29+ return '<div class="mw-mah-wrapper">' . $html . '</div>';
 30+
5731 }
 32+
 33+ private static function otherMarkedTemplate( $helpfulUserList ) {
 34+ $userList = '';
5835
 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+ &nbsp;(<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+
5974 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r106908trim unneeded html returns from MarkAsHelpfulUtil.php follow up to r106906rmoen00:48, 21 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r106843Mark As Helpful APIs and backendbsitu19:30, 20 December 2011

Status & tagging log