r107523 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107522‎ | r107523 | r107524 >
Date:20:39, 28 December 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Fix mixed tabs/spaces. Fix trailing whitespace
Modified paths:
  • /trunk/extensions/MoodBar/ApiFeedbackDashboardResponse.php (modified) (history)
  • /trunk/extensions/MoodBar/ApiMoodBarSetUserEmail.php (modified) (history)
  • /trunk/extensions/MoodBar/ApiQueryMoodBarComments.php (modified) (history)
  • /trunk/extensions/MoodBar/FeedbackResponseItem.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/ApiMoodBarSetUserEmail.php
@@ -2,69 +2,65 @@
33
44
55 class ApiMoodBarSetUserEmail extends ApiBase {
6 -
 6+
77 public function execute() {
88 global $wgUser, $wgAuth, $wgEnableEmail, $wgEmailAuthentication;
9 -
 9+
1010 if ( $wgUser->isAnon() ) {
1111 $this->dieUsage( "You don't have permission to do that", 'permission-denied' );
1212 }
13 -
 13+
1414 $params = $this->extractRequestParams();
1515
1616 $error = false;
17 -
 17+
1818 switch ( $params['mbaction']) {
19 -
 19+
2020 case 'setemail':
2121 if ( !$wgAuth->allowPropChange( 'emailaddress' ) ) {
22 - $error = wfMsgExt( 'cannotchangeemail', 'parseinline' );
23 - }
24 - else {
 22+ $error = wfMsgExt( 'cannotchangeemail', 'parseinline' );
 23+ } else {
2524 //only set email if user does not have email on profile yet
2625 if ( !$wgUser->getEmail() ) {
27 -
 26+
2827 if ( !isset( $params['email'] ) || !Sanitizer::validateEmail( $params['email'] ) ) {
2928 $error = wfMsgExt( 'invalidemailaddress', 'parseinline' ) ;
3029 }
3130 else {
3231 list( $status, $info ) = self::trySetUserEmail( $wgUser, $params['email'] );
33 -
 32+
3433 // Status Object
3534 if ( $status !== true ) {
3635 $error = $status->getWikiText( $info );
 36+ } else {
 37+ $wgUser->saveSettings();
3738 }
38 - else {
39 - $wgUser->saveSettings();
40 - }
4139 }
42 -
 40+
4341 }
4442 }
45 - break;
46 -
 43+ break;
 44+
4745 case 'resendverification':
4846 //only sends the email if the email has not been verified
4947 if ( $wgEnableEmail && $wgEmailAuthentication && $wgUser->getEmail() && !$wgUser->isEmailConfirmed() ) {
5048 $status = $wgUser->sendConfirmationMail( 'set' );
5149 if ( !$status->isGood() ) {
5250 $error = $status->getWikiText( 'mailerror' );
53 - }
 51+ }
5452 }
55 - break;
56 -
 53+ break;
 54+
5755 default:
5856 throw new MWApiMoodBarSetUserEmailInvalidActionException( "Action {$params['mbaction']} not implemented" );
59 - break;
60 -
6157 }
62 -
 58+
6359 if ( $error === false ) {
6460 $result = array( 'result' => 'success' );
6561 } else {
6662 $result = array( 'result' => 'error', 'error' => $error );
6763 }
68 -
 64+
6965 $this->getResult()->addValue( null, $this->getModuleName(), $result );
7066 }
7167
@@ -95,8 +91,6 @@
9692 return array( true, $info );
9793 }
9894
99 -
100 -
10195 public function needsToken() {
10296 return true;
10397 }
@@ -114,11 +108,11 @@
115109 'resendverification',
116110 ),
117111 ),
118 -
 112+
119113 'email' => array(
120114 ApiBase::PARAM_TYPE => 'string'
121115 ),
122 -
 116+
123117 'token' => array(
124118 ApiBase::PARAM_REQUIRED => true,
125119 ),
Index: trunk/extensions/MoodBar/ApiFeedbackDashboardResponse.php
@@ -1,22 +1,22 @@
22 <?php
33
44 class ApiFeedbackDashboardResponse extends ApiBase {
5 -
 5+
66 private $EnotifUserTalk;
77 private $EnotifWatchlist;
8 -
 8+
99 public function execute() {
1010 global $wgRequest, $wgUser;
11 -
 11+
1212 if ( $wgUser->isAnon() ) {
1313 $this->dieUsage( "You don't have permission to do that", 'permission-denied' );
1414 }
1515 if ( $wgUser->isBlocked( false ) ) {
1616 $this->dieUsageMsg( array( 'blockedtext' ) );
1717 }
18 -
 18+
1919 $params = $this->extractRequestParams();
20 -
 20+
2121 //Response Object
2222 $item = MBFeedbackResponseItem::create( array() );
2323
@@ -27,73 +27,73 @@
2828 }
2929 }
3030
31 - $item->setProperties( $setParams );
 31+ $item->setProperties( $setParams );
3232 $item->save();
33 -
 33+
3434 $commenter = $item->getProperty('feedbackitem')->getProperty('user');
35 -
 35+
3636 if ( $commenter !== null && $commenter->isAnon() == false ) {
3737 $talkPage = $commenter->getTalkPage();
38 -
 38+
3939 $response = Parser::cleanSigInSig($params['response']);
40 -
 40+
4141 $feedback_link = wfMessage('moodbar-feedback-response-title')->inContentLanguage()->
42 - params( SpecialPage::getTitleFor( 'FeedbackDashboard', $item->getProperty('feedback') )->
43 - getPrefixedText() )->escaped();
44 -
 42+ params( SpecialPage::getTitleFor( 'FeedbackDashboard', $item->getProperty('feedback') )->
 43+ getPrefixedText() )->escaped();
 44+
4545 $summary = wfMessage('moodbar-feedback-edit-summary')->inContentLanguage()->
46 - rawParams( $item->getProperty('feedback'), $response)->escaped();
47 -
48 - $this->disableUserTalkEmailNotification();
49 -
 46+ rawParams( $item->getProperty('feedback'), $response)->escaped();
 47+
 48+ $this->disableUserTalkEmailNotification();
 49+
5050 $id = intval( $item->getProperty( 'id' ) );
5151 $api = new ApiMain( new FauxRequest( array(
5252 'action' => 'edit',
5353 'title' => $talkPage->getFullText(),
54 - 'appendtext' => ( $talkPage->exists() ? "\n\n" : '' ) .
55 - $feedback_link . "\n" .
56 - '<span id="feedback-dashboard-response-' . $id . '"></span>' . "\n\n" .
 54+ 'appendtext' => ( $talkPage->exists() ? "\n\n" : '' ) .
 55+ $feedback_link . "\n" .
 56+ '<span id="feedback-dashboard-response-' . $id . '"></span>' . "\n\n" .
5757 $response . "\n\n~~~~\n\n" .
5858 '<span class="markashelpful-item" data-markashelpful-item="' . $id . '" data-markashelpful-type="mbresponse"></span>',
5959 'token' => $params['token'],
6060 'summary' => $summary,
6161 'notminor' => true,
6262 ), true, array( 'wsEditToken' => $wgRequest->getSessionData( 'wsEditToken' ) ) ), true );
63 -
 63+
6464 $api->execute();
65 -
 65+
6666 $this->restoreUserTalkEmailNotification();
67 -
68 - global $wgLang;
69 -
 67+
 68+ global $wgLang;
 69+
7070 $EMailNotif = new MoodBarHTMLEmailNotification();
7171 $EMailNotif->notifyOnRespond( $wgUser, $talkPage, wfTimestampNow(), $item->getProperty('feedback'), $wgLang->truncate( $response, 250 ) );
72 -
 72+
7373 }
74 -
 74+
7575 $result = array( 'result' => 'success' );
76 - $this->getResult()->addValue( null, $this->getModuleName(), $result );
 76+ $this->getResult()->addValue( null, $this->getModuleName(), $result );
7777 }
78 -
 78+
7979 /**
80 - * temporarily disable the talk page email notification
 80+ * temporarily disable the talk page email notification
8181 * for user and watchers
8282 */
8383 private function disableUserTalkEmailNotification() {
8484 global $wgEnotifUserTalk, $wgEnotifWatchlist;
8585
8686 $this->EnotifUserTalk = $wgEnotifUserTalk;
87 - $this->EnotifWatchlist = $wgEnotifWatchlist;
88 -
89 - $wgEnotifUserTalk = $wgEnotifWatchlist = false;
 87+ $this->EnotifWatchlist = $wgEnotifWatchlist;
 88+
 89+ $wgEnotifUserTalk = $wgEnotifWatchlist = false;
9090 }
91 -
 91+
9292 /**
9393 * restore the default state of talk page email notification
9494 */
9595 private function restoreUserTalkEmailNotification() {
9696 global $wgEnotifUserTalk, $wgEnotifWatchlist;
97 -
 97+
9898 if ( !is_null( $this->EnotifUserTalk ) ) {
9999 $wgEnotifUserTalk = $this->EnotifUserTalk;
100100 }
@@ -101,7 +101,7 @@
102102 $wgEnotifWatchlist = $this->EnotifWatchlist;
103103 }
104104 }
105 -
 105+
106106 public function needsToken() {
107107 return true;
108108 }
@@ -160,5 +160,5 @@
161161 public function getDescription() {
162162 return 'Allows users to submit response to a feedback about their experiences on the site';
163163 }
164 -
 164+
165165 }
Index: trunk/extensions/MoodBar/ApiQueryMoodBarComments.php
@@ -4,12 +4,12 @@
55 public function __construct( $query, $moduleName ) {
66 parent::__construct( $query, $moduleName, 'mbc' );
77 }
8 -
 8+
99 public function execute() {
10 - global $wgLang, $wgUser;
 10+ global $wgUser;
1111 $params = $this->extractRequestParams();
1212 $prop = array_flip( $params['prop'] );
13 -
 13+
1414 // Build the query
1515 $this->addTables( array( 'moodbar_feedback', 'user' ) );
1616 $this->addJoinConds( array( 'user' => array( 'LEFT JOIN', 'user_id=mbf_user_id' ) ) );
@@ -28,40 +28,40 @@
2929 $this->addWhere( 'mbf_user_ip IS NULL' );
3030 }
3131 }
32 -
 32+
3333 if ( $params['continue'] !== null ) {
3434 $this->applyContinue( $params['continue'], $params['dir'] == 'older' );
3535 }
36 -
 36+
3737 // Add ORDER BY mbf_timestamp {ASC|DESC}, mbf_id {ASC|DESC}
3838 $this->addWhereRange( 'mbf_timestamp', $params['dir'], null, null );
3939 $this->addWhereRange( 'mbf_id', $params['dir'], null, null );
4040 $this->addOption( 'LIMIT', $params['limit'] + 1 );
41 -
 41+
4242 if ( $params['myresponse'] == '1' && !$wgUser->isAnon() ) {
4343 $this->addTables( array( 'moodbar_feedback_response' ) );
4444 $this->addJoinConds( array( 'moodbar_feedback_response' => array( 'INNER JOIN', 'mbf_id=mbfr_mbf_id' ) ) );
4545 $this->addWhereFld( 'mbfr_user_id', $wgUser->getId() );
4646 $this->addOption( 'GROUP BY', 'mbf_id' );
4747 }
48 -
 48+
4949 if ( ! $wgUser->isAllowed( 'moodbar-admin' ) ) {
5050 $this->addWhereFld( 'mbf_hidden_state', 0 );
5151 }
52 -
 52+
5353 $res = $this->select( __METHOD__ );
5454 $result = $this->getResult();
5555 $count = 0;
56 -
 56+
5757 $response = SpecialFeedbackDashboard::getResponseSummary( $res );
58 -
 58+
5959 foreach ( $res as $row ) {
6060 if ( ++$count > $params['limit'] ) {
6161 // We've reached the one extra which shows that there are additional rows. Stop here
6262 $this->setContinueEnumParameter( 'continue', $this->getContinue( $row ) );
6363 break;
6464 }
65 -
 65+
6666 $vals = $this->extractRowInfo( $row, $prop, $response );
6767 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
6868 if ( !$fit ) {
@@ -71,19 +71,19 @@
7272 }
7373 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'comment' );
7474 }
75 -
 75+
7676 protected function getContinue( $row ) {
7777 $ts = wfTimestamp( TS_MW, $row->mbf_timestamp );
7878 return "$ts|{$row->mbf_id}";
7979 }
80 -
 80+
8181 protected function applyContinue( $continue, $sortDesc ) {
8282 $vals = explode( '|', $continue, 3 );
8383 if ( count( $vals ) !== 2 ) {
8484 // TODO this should be a standard message in ApiBase
8585 $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', 'badcontinue' );
8686 }
87 -
 87+
8888 $db = $this->getDB();
8989 $ts = $db->addQuotes( $db->timestamp( $vals[0] ) );
9090 $id = intval( $vals[1] );
@@ -94,15 +94,15 @@
9595 "mbf_id $op= $id)"
9696 );
9797 }
98 -
 98+
9999 protected function extractRowInfo( $row, $prop, $response = array() ) {
100100 global $wgUser;
101 -
 101+
102102 $r = array();
103 -
 103+
104104 $showHidden = isset($prop['hidden']) && $wgUser->isAllowed('moodbar-admin');
105105 $isHidden = $row->mbf_hidden_state > 0;
106 -
 106+
107107 if ( isset( $prop['metadata'] ) ) {
108108 $r += array(
109109 'id' => intval( $row->mbf_id ),
@@ -115,18 +115,18 @@
116116 }
117117 if ( isset( $prop['formatted'] ) ) {
118118 $params = array();
119 -
 119+
120120 if ( $wgUser->isAllowed( 'moodbar-admin' ) ) {
121121 $params[] = 'admin';
122122 }
123 -
 123+
124124 if ( $isHidden && $showHidden ) {
125125 $params[] = 'show-anyway';
126126 }
127 -
 127+
128128 $r['formatted'] = SpecialFeedbackDashboard::formatListItem( $row, $params, $response );
129129 }
130 -
 130+
131131 if ( $isHidden && !$showHidden ) {
132132 unset($r['userid']);
133133 unset($r['username']);
@@ -134,7 +134,7 @@
135135 ApiResult::setContent( $r, '' );
136136 $r['hidden'] = true;
137137 }
138 -
 138+
139139 return $r;
140140 }
141141
@@ -164,7 +164,7 @@
165165 ApiBase::PARAM_TYPE => 'user',
166166 ),
167167 'myresponse' => array(
168 - ApiBase::PARAM_TYPE => array( '1' , '0' ),
 168+ ApiBase::PARAM_TYPE => array( '1' , '0' ),
169169 ),
170170 'prop' => array(
171171 ApiBase::PARAM_TYPE => array( 'metadata', 'formatted', 'hidden' ),
@@ -196,7 +196,7 @@
197197 public function getDescription() {
198198 return 'List all feedback comments submitted through the MoodBar extension.';
199199 }
200 -
 200+
201201 public function getCacheMode( $params ) {
202202 return isset($params['prop']['hidden']) ? 'private' : 'public';
203203 }
Index: trunk/extensions/MoodBar/FeedbackResponseItem.php
@@ -13,17 +13,17 @@
1414 // Feedback response essentials
1515 'id', // ID in the database for response
1616 'feedback', // ID in the database for moodbar_feedback
17 - 'feedbackitem', // the feedback that the user responds to
 17+ 'feedbackitem', // the feedback that the user responds to
1818 'user', // user object
1919 'anonymize',
20 - 'commenter-editcount', // Number of edit for the user writes the feedback
21 - 'user-editcount', // Number of edit for the responder
22 - 'response', // The response itself
23 - 'timestamp', // When response was received
24 - 'system', // Operating System
25 - 'useragent' , // User-Agent header
26 - 'locale', // The locale of the user's browser
27 - 'editmode' // Whether or not the user was editing
 20+ 'commenter-editcount', // Number of edit for the user writes the feedback
 21+ 'user-editcount', // Number of edit for the responder
 22+ 'response', // The response itself
 23+ 'timestamp', // When response was received
 24+ 'system', // Operating System
 25+ 'useragent' , // User-Agent header
 26+ 'locale', // The locale of the user's browser
 27+ 'editmode' // Whether or not the user was editing
2828 );
2929 /**
3030 * Default constructor.
@@ -57,7 +57,7 @@
5858 */
5959 protected function initialiseNew( $info ) {
6060 global $wgUser;
61 -
 61+
6262 $template = array(
6363 'user' => $wgUser,
6464 'timestamp' => wfTimestampNow(),
@@ -94,12 +94,12 @@
9595 'system' => 'mbfr_system_type',
9696 'locale' => 'mbfr_locale',
9797 'editmode' => 'mbfr_editing',
98 - 'commenter-editcount',
99 - 'user-editcount'
 98+ 'commenter-editcount',
 99+ 'user-editcount'
100100 );
101 -
 101+
102102 $properties = array();
103 -
 103+
104104 foreach( $propMappings as $property => $field ) {
105105 if ( isset( $row->$field ) ) {
106106 $properties[$property] = $row->$field;
@@ -117,7 +117,7 @@
118118 }
119119
120120 $this->setProperties( $properties );
121 -
 121+
122122 }
123123
124124 /**
@@ -205,21 +205,19 @@
206206 * @return The MBFeedbackItem's new ID.
207207 */
208208 public function save() {
209 -
 209+
210210 $user = $this->getProperty('user');
211 -
 211+
212212 // Add edit count if necessary
213 - if ( $this->getProperty('user-editcount') === null && $user !== null )
214 - {
 213+ if ( $this->getProperty('user-editcount') === null && $user !== null ) {
215214 $this->setProperty( 'user-editcount', $user->isAnon() ? 0 : $user->getEditCount() );
216 -
217 - }
218 -
 215+ }
 216+
219217 if($this->getProperty('commenter-editcount') === null) {
220218 $commenter = $this->getProperty('feedbackitem')->getProperty('user');
221219 $this->setProperty( 'commenter-editcount', $commenter->isAnon() ? 0 : $commenter->getEditCount() );
222220 }
223 -
 221+
224222 $dbw = wfGetDB( DB_MASTER );
225223
226224 $row = array(
@@ -237,8 +235,7 @@
238236 if($user->isAnon()) {
239237 $row['mbfr_user_id'] = 0;
240238 $row['mbfr_user_ip'] = $user->getName();
241 - }
242 - else {
 239+ } else {
243240 $row['mbfr_user_id'] = $user->getId();
244241 }
245242
@@ -260,7 +257,7 @@
261258 public static function getValidTypes() {
262259 return self::$validTypes;
263260 }
264 -
 261+
265262 /**
266263 * Set the Feedback Item this Response is associated to
267264 * @param $mbf_id mbfr_mbf_id in moodbar_feedback_response table
@@ -268,17 +265,17 @@
269266 */
270267 protected function setFeedbackItem($mbf_id) {
271268 $dbr = wfGetDB( DB_SLAVE );
272 -
 269+
273270 $row = $dbr->selectRow( 'moodbar_feedback', '*',
274271 array( 'mbf_id' => $mbf_id ), __METHOD__ );
275 -
 272+
276273 if( $row !== false ) {
277 - $this->setProperties( array ( 'feedbackitem' => MBFeedbackItem::load( $row ) ) );
 274+ $this->setProperties( array ( 'feedbackitem' => MBFeedbackItem::load( $row ) ) );
278275 return true;
279276 }
280277 else {
281 - return false;
282 - }
 278+ return false;
 279+ }
283280 }
284281
285282 }

Sign-offs

UserFlagDate
Nikerabbitinspected06:28, 29 December 2011

Comments

#Comment by Dowjohn (talk | contribs)   22:40, 28 December 2011

Thank you for cleaning this up, I will keep this consistent next time, :)

#Comment by Bsitu (talk | contribs)   22:43, 28 December 2011

Oops, Didn't realize I was logging in with my wiki test account, :)

#Comment by Reedy (talk | contribs)   23:03, 28 December 2011

The more important one is using tabs not spaces :)

Status & tagging log