r98033 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98032‎ | r98033 | r98034 >
Date:21:27, 24 September 2011
Author:catrope
Status:ok
Tags:
Comment:
MoodBar: Expose formatted HTML for each row in list=moodbarcomments
Modified paths:
  • /trunk/extensions/MoodBar/ApiQueryMoodBarComments.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/ApiQueryMoodBarComments.php
@@ -6,7 +6,9 @@
77 }
88
99 public function execute() {
 10+ global $wgLang;
1011 $params = $this->extractRequestParams();
 12+ $prop = array_flip( $params['prop'] );
1113
1214 // Build the query
1315 $this->addTables( array( 'moodbar_feedback', 'user' ) );
@@ -46,7 +48,7 @@
4749 break;
4850 }
4951
50 - $vals = $this->extractRowInfo( $row );
 52+ $vals = $this->extractRowInfo( $row, $prop );
5153 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
5254 if ( !$fit ) {
5355 $this->setContinueEnumParameter( 'continue', $this->getContinue( $row ) );
@@ -79,15 +81,21 @@
8082 );
8183 }
8284
83 - protected function extractRowInfo( $row ) {
84 - $r = array(
85 - 'id' => intval( $row->mbf_id ),
86 - 'type' => $row->mbf_type,
87 - 'timestamp' => wfTimestamp( TS_ISO_8601, $row->mbf_timestamp ),
88 - 'userid' => intval( $row->mbf_user_id ),
89 - 'username' => $row->mbf_user_ip === null ? $row->user_name : $row->mbf_user_ip,
90 - );
91 - ApiResult::setContent( $r, $row->mbf_comment );
 85+ protected function extractRowInfo( $row, $prop ) {
 86+ $r = array();
 87+ if ( isset( $prop['metadata'] ) ) {
 88+ $r += array(
 89+ 'id' => intval( $row->mbf_id ),
 90+ 'type' => $row->mbf_type,
 91+ 'timestamp' => wfTimestamp( TS_ISO_8601, $row->mbf_timestamp ),
 92+ 'userid' => intval( $row->mbf_user_id ),
 93+ 'username' => $row->mbf_user_ip === null ? $row->user_name : $row->mbf_user_ip,
 94+ );
 95+ ApiResult::setContent( $r, $row->mbf_comment );
 96+ }
 97+ if ( isset( $prop['formatted'] ) ) {
 98+ $r['formatted'] = SpecialMoodBarFeedback::formatListItem( $row );
 99+ }
92100 return $r;
93101 }
94102
@@ -116,6 +124,11 @@
117125 'user' => array(
118126 ApiBase::PARAM_TYPE => 'user',
119127 ),
 128+ 'prop' => array(
 129+ ApiBase::PARAM_TYPE => array( 'metadata', 'formatted' ),
 130+ ApiBase::PARAM_DFLT => 'metadata',
 131+ ApiBase::PARAM_ISMULTI => true,
 132+ ),
120133 );
121134 }
122135
@@ -128,7 +141,11 @@
129142 'limit' => 'How many comments to return',
130143 'continue' => 'When more results are available, use this to continue',
131144 'type' => 'Only return comments of the given type(s). If not set or empty, return all comments',
132 - 'user' =>' Only return comments submitted by the given user',
 145+ 'user' => 'Only return comments submitted by the given user',
 146+ 'prop' => array( 'Which properties to get:',
 147+ ' metadata - Comment ID, type, timestamp, user',
 148+ ' formatted - HTML that would be displayed for this comment on Special:MoodBarFeedback',
 149+ ),
133150 );
134151 }
135152

Status & tagging log