r98031 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98030‎ | r98031 | r98032 >
Date:21:14, 24 September 2011
Author:catrope
Status:ok
Tags:
Comment:
SpecialMoodBarFeedback: factor out row formatting into a static function
Modified paths:
  • /trunk/extensions/MoodBar/SpecialMoodBarFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/SpecialMoodBarFeedback.php
@@ -94,40 +94,44 @@
9595 HTML;
9696 }
9797
 98+ public static function formatListItem( $row ) {
 99+ global $wgLang;
 100+ $type = $row->mbf_type;
 101+ $typeMsg = wfMessage( "moodbar-type-$type" )->escaped();
 102+ $time = $wgLang->formatTimePeriod( wfTimestamp( TS_UNIX ) - wfTimestamp( TS_UNIX, $row->mbf_timestamp ),
 103+ array( 'avoid' => 'avoidminutes', 'noabbrevs' => true )
 104+ );
 105+ $timeMsg = wfMessage( 'ago' )->params( $time )->escaped();
 106+ $username = htmlspecialchars( $row->user_name === null ? $row->mbf_user_ip : $row->user_name );
 107+ $links = Linker::userToolLinks( $row->mbf_user_id, $username );
 108+ $comment = htmlspecialchars( $row->mbf_comment );
 109+ $permalinkURL = htmlspecialchars( SpecialPage::getTitleFor( 'MoodBarFeedback', $row->mbf_id )->getLinkURL() );
 110+ $permalinkText = wfMessage( 'moodbar-feedback-permalink' )->escaped();
 111+
 112+ return <<<HTML
 113+ <li class="fbd-item">
 114+ <div class="fbd-item-emoticon fbd-item-emoticon-$type">
 115+ <span class="fbd-item-emoticon-label">$typeMsg</span>
 116+ </div>
 117+ <div class="fbd-item-time">$timeMsg</div>
 118+ <h3 class="fbd-item-userName">
 119+ <a href="#">$username</a>
 120+ <sup class="fbd-item-userLinks">
 121+ $links
 122+ </sup>
 123+ </h3>
 124+ <div class="fbd-item-message">$comment</div>
 125+ <div class="fbd-item-permalink">(<a href="$permalinkURL">$permalinkText</a>)</div>
 126+ <div style="clear:both"></div>
 127+ </li>
 128+HTML;
 129+ }
 130+
98131 public function buildList( $res ) {
99 - global $wgLang, $wgRequest;
100 - $now = wfTimestamp( TS_UNIX );
 132+ global $wgRequest;
101133 $list = '';
102134 foreach ( $res['rows'] as $row ) {
103 - $type = $row->mbf_type;
104 - $typeMsg = wfMessage( "moodbar-type-$type" )->escaped();
105 - $time = $wgLang->formatTimePeriod( $now - wfTimestamp( TS_UNIX, $row->mbf_timestamp ),
106 - array( 'avoid' => 'avoidminutes', 'noabbrevs' => true )
107 - );
108 - $timeMsg = wfMessage( 'ago' )->params( $time )->escaped();
109 - $username = htmlspecialchars( $row->user_name === null ? $row->mbf_user_ip : $row->user_name );
110 - $links = Linker::userToolLinks( $row->mbf_user_id, $username );
111 - $comment = htmlspecialchars( $row->mbf_comment );
112 - $permalinkURL = htmlspecialchars( $this->getTitle( $row->mbf_id )->getLinkURL() );
113 - $permalinkText = wfMessage( 'moodbar-feedback-permalink' )->escaped();
114 -
115 - $list .= <<<HTML
116 - <li class="fbd-item">
117 - <div class="fbd-item-emoticon fbd-item-emoticon-$type">
118 - <span class="fbd-item-emoticon-label">$typeMsg</span>
119 - </div>
120 - <div class="fbd-item-time">$timeMsg</div>
121 - <h3 class="fbd-item-userName">
122 - <a href="#">$username</a>
123 - <sup class="fbd-item-userLinks">
124 - $links
125 - </sup>
126 - </h3>
127 - <div class="fbd-item-message">$comment</div>
128 - <div class="fbd-item-permalink">(<a href="$permalinkURL">$permalinkText</a>)</div>
129 - <div style="clear:both"></div>
130 - </li>
131 -HTML;
 135+ $list .= self::formatListItem( $row );
132136 }
133137
134138 if ( $list === '' ) {

Status & tagging log