Index: trunk/extensions/MoodBar/ApiQueryMoodBarComments.php |
— | — | @@ -6,7 +6,9 @@ |
7 | 7 | } |
8 | 8 | |
9 | 9 | public function execute() { |
| 10 | + global $wgLang; |
10 | 11 | $params = $this->extractRequestParams(); |
| 12 | + $prop = array_flip( $params['prop'] ); |
11 | 13 | |
12 | 14 | // Build the query |
13 | 15 | $this->addTables( array( 'moodbar_feedback', 'user' ) ); |
— | — | @@ -46,7 +48,7 @@ |
47 | 49 | break; |
48 | 50 | } |
49 | 51 | |
50 | | - $vals = $this->extractRowInfo( $row ); |
| 52 | + $vals = $this->extractRowInfo( $row, $prop ); |
51 | 53 | $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); |
52 | 54 | if ( !$fit ) { |
53 | 55 | $this->setContinueEnumParameter( 'continue', $this->getContinue( $row ) ); |
— | — | @@ -79,15 +81,21 @@ |
80 | 82 | ); |
81 | 83 | } |
82 | 84 | |
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 | + } |
92 | 100 | return $r; |
93 | 101 | } |
94 | 102 | |
— | — | @@ -116,6 +124,11 @@ |
117 | 125 | 'user' => array( |
118 | 126 | ApiBase::PARAM_TYPE => 'user', |
119 | 127 | ), |
| 128 | + 'prop' => array( |
| 129 | + ApiBase::PARAM_TYPE => array( 'metadata', 'formatted' ), |
| 130 | + ApiBase::PARAM_DFLT => 'metadata', |
| 131 | + ApiBase::PARAM_ISMULTI => true, |
| 132 | + ), |
120 | 133 | ); |
121 | 134 | } |
122 | 135 | |
— | — | @@ -128,7 +141,11 @@ |
129 | 142 | 'limit' => 'How many comments to return', |
130 | 143 | 'continue' => 'When more results are available, use this to continue', |
131 | 144 | '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 | + ), |
133 | 150 | ); |
134 | 151 | } |
135 | 152 | |