r96464 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96463‎ | r96464 | r96465 >
Date:18:09, 7 September 2011
Author:ashley
Status:deferred
Tags:
Comment:
Survey: } else { should not take up more than one line; also fixed a few spacing/capitalization issues and swapped some else ifs to elseifs in PHP
Modified paths:
  • /trunk/extensions/Survey/api/ApiAddSurvey.php (modified) (history)
  • /trunk/extensions/Survey/api/ApiQuerySurveys.php (modified) (history)
  • /trunk/extensions/Survey/api/ApiSubmitSurvey.php (modified) (history)
  • /trunk/extensions/Survey/includes/Survey.class.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyDBClass.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyTag.php (modified) (history)
  • /trunk/extensions/Survey/resources/ext.survey.js (modified) (history)
  • /trunk/extensions/Survey/resources/ext.survey.special.surveys.js (modified) (history)
  • /trunk/extensions/Survey/resources/jquery.survey.js (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurvey.php (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurveys.php (modified) (history)
  • /trunk/extensions/Survey/test/SurveyQuestionTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/test/SurveyQuestionTest.php
@@ -2,26 +2,26 @@
33
44 /**
55 * SurveyQuestion test case.
6 - *
 6+ *
77 * @ingroup Survey
88 * @since 0.1
9 - *
 9+ *
1010 * @licence GNU GPL v3
1111 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1212 */
1313 class SurveyQuestionTest extends MediaWikiTestCase {
14 -
 14+
1515 /**
1616 * Tests SurveyQuestion::newFromUrlData and SurveyQuestion::toUrlData
1717 */
1818 public function testQuestionUrlSerialization() {
1919 $question = new SurveyQuestion( 9001, 42, 'ohai there!', 0, true );
20 -
21 - $this->assertEquals(
22 - $question,
23 - SurveyQuestion::newFromUrlData( $question->toUrlData() ),
24 - "Serializaion test failed at " . __METHOD__
25 - );
 20+
 21+ $this->assertEquals(
 22+ $question,
 23+ SurveyQuestion::newFromUrlData( $question->toUrlData() ),
 24+ "Serializaion test failed at " . __METHOD__
 25+ );
2626 }
2727
2828 }
Index: trunk/extensions/Survey/specials/SpecialSurvey.php
@@ -36,13 +36,11 @@
3737
3838 if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
3939 $this->handleSubmission();
40 - }
41 - else {
 40+ } else {
4241 if ( is_null( $subPage ) ) {
4342 $survey = new Survey( null, true );
4443 $survey->loadDefaults();
45 - }
46 - else {
 44+ } else {
4745 $survey = Survey::newFromName( $subPage, null, true );
4846 }
4947
@@ -70,8 +68,7 @@
7169
7270 if ( $wgRequest->getInt( 'survey-id' ) == 0 ) {
7371 $survey = new Survey( null );
74 - }
75 - else {
 72+ } else {
7673 $survey = Survey::newFromId( $wgRequest->getInt( 'survey-id' ), null, false );
7774 }
7875
@@ -102,8 +99,7 @@
103100
104101 if ( preg_match( '/survey-question-text-(\d)+/', $name, $matches ) ) {
105102 $questions[] = $this->getSubmittedQuestion( $matches[1] );
106 - }
107 - else if ( preg_match( '/survey-question-text-new-(\d)+/', $name, $matches ) ) {
 103+ } elseif ( preg_match( '/survey-question-text-new-(\d)+/', $name, $matches ) ) {
108104 $questions[] = $this->getSubmittedQuestion( $matches[1], true );
109105 }
110106 }
@@ -126,8 +122,7 @@
127123 if ( $isNewQuestion ) {
128124 $questionDbId = null;
129125 $questionId = "new-$questionId";
130 - }
131 - else {
 126+ } else {
132127 $questionDbId = $questionId;
133128 }
134129
@@ -241,8 +236,7 @@
242237 // the second argument for the HTMLForm constructor.
243238 if ( is_callable( array( $this, 'getContext' ) ) ) {
244239 $form = new HTMLForm( $fields, $this->getContext() );
245 - }
246 - else {
 240+ } else {
247241 $form = new HTMLForm( $fields );
248242 }
249243
@@ -270,8 +264,7 @@
271265 foreach ( $this->mParams['options'] as $name => $value ) {
272266 if ( is_bool( $value ) ) {
273267 $value = $value ? '1' : '0';
274 - }
275 - elseif( is_object( $value ) || is_array( $value ) ) {
 268+ } elseif( is_object( $value ) || is_array( $value ) ) {
276269 $value = FormatJson::encode( $value );
277270 }
278271
Index: trunk/extensions/Survey/specials/SpecialSurveys.php
@@ -38,8 +38,7 @@
3939 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) )
4040 && $wgRequest->getCheck( 'newsurvey' ) ) {
4141 $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Survey', $wgRequest->getVal( 'newsurvey' ) )->getLocalURL() );
42 - }
43 - else {
 42+ } else {
4443 $this->displaySurveys();
4544 }
4645 }
Index: trunk/extensions/Survey/includes/SurveyDBClass.php
@@ -195,7 +195,7 @@
196196 $fields = array_keys( static::getFieldTypes() );
197197 }
198198
199 - $dbr = wfgetDB( DB_SLAVE );
 199+ $dbr = wfGetDB( DB_SLAVE );
200200
201201 return $dbr->select(
202202 static::getDBTable(),
@@ -227,8 +227,7 @@
228228 public function writeToDB() {
229229 if ( $this->hasIdField() ) {
230230 return $this->updateInDB();
231 - }
232 - else {
 231+ } else {
233232 return $this->insertIntoDB();
234233 }
235234 }
@@ -348,8 +347,7 @@
349348 case 'bool':
350349 if ( is_string( $value ) ) {
351350 $value = $value !== '0';
352 - }
353 - else if ( is_int( $value ) ) {
 351+ } elseif ( is_int( $value ) ) {
354352 $value = $value !== 0;
355353 }
356354 break;
@@ -366,8 +364,7 @@
367365 }
368366
369367 $this->fields[$name] = $value;
370 - }
371 - else {
 368+ } else {
372369 throw new MWException( 'Attempted to set unknonw field ' . $name );
373370 }
374371 }
@@ -385,8 +382,7 @@
386383 public function getField( $name ) {
387384 if ( $this->hasField( $name ) ) {
388385 return $this->fields[$name];
389 - }
390 - else {
 386+ } else {
391387 throw new MWException( 'Attempted to get not-set field ' . $name );
392388 }
393389 }
@@ -561,8 +557,7 @@
562558
563559 if ( !is_array( $fields ) ) {
564560 $setFields = $this->getSetFieldNames();
565 - }
566 - else {
 561+ } else {
567562 foreach ( $fields as $field ) {
568563 if ( $this->hasField( $field ) ) {
569564 $setFields[] = $field;
Index: trunk/extensions/Survey/includes/SurveyTag.php
@@ -48,8 +48,7 @@
4949
5050 $this->parameters['class'] = 'surveytag';
5151 $this->parameters['survey-data-token'] = $GLOBALS['wgUser']->editToken();
52 - }
53 - else {
 52+ } else {
5453 throw new MWException( 'Invalid parameters for survey tag.' );
5554 }
5655 }
Index: trunk/extensions/Survey/includes/Survey.class.php
@@ -269,7 +269,7 @@
270270 array( 'submission_survey_id' => $this->getId() )
271271 );
272272
273 - $dbw = wfgetDB( DB_MASTER );
 273+ $dbw = wfGetDB( DB_MASTER );
274274
275275 $dbw->begin();
276276
Index: trunk/extensions/Survey/api/ApiSubmitSurvey.php
@@ -37,8 +37,7 @@
3838 if ( $survey === false ) {
3939 $this->dieUsage( wfMsgExt( 'survey-err-survey-name-unknown', 'parsemag', $params['name'] ), 'survey-name-unknown' );
4040 }
41 - }
42 - else {
 41+ } else {
4342 $survey = Survey::newFromId( $params['id'], null, false );
4443
4544 if ( $survey === false ) {
Index: trunk/extensions/Survey/api/ApiAddSurvey.php
@@ -38,8 +38,7 @@
3939 catch ( DBQueryError $ex ) {
4040 if ( $ex->errno == 1062 ) {
4141 $this->dieUsage( wfMsgExt( 'survey-err-duplicate-name', 'parsemag', $params['name'] ), 'duplicate-survey-name' );
42 - }
43 - else {
 42+ } else {
4443 throw $ex;
4544 }
4645 }
Index: trunk/extensions/Survey/api/ApiQuerySurveys.php
@@ -15,11 +15,11 @@
1616 class ApiQuerySurveys extends ApiQueryBase {
1717
1818 public function __construct( $main, $action ) {
19 - parent :: __construct( $main, $action, 'su' );
 19+ parent::__construct( $main, $action, 'su' );
2020 }
2121
2222 /**
23 - * Retrieve the specil words from the database.
 23+ * Retrieve the special words from the database.
2424 */
2525 public function execute() {
2626 global $wgUser;
@@ -52,8 +52,7 @@
5353
5454 if ( isset( $params['ids'] ) ) {
5555 $this->addWhere( array( 'survey_id' => $params['ids'] ) );
56 - }
57 - else {
 56+ } else {
5857 $this->addWhere( array( 'survey_name' => $params['names'] ) );
5958 }
6059
@@ -144,11 +143,11 @@
145144 ApiBase::PARAM_TYPE => 'integer',
146145 ),
147146 'limit' => array(
148 - ApiBase :: PARAM_DFLT => 20,
149 - ApiBase :: PARAM_TYPE => 'limit',
150 - ApiBase :: PARAM_MIN => 1,
151 - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
152 - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
 147+ ApiBase::PARAM_DFLT => 20,
 148+ ApiBase::PARAM_TYPE => 'limit',
 149+ ApiBase::PARAM_MIN => 1,
 150+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
 151+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
153152 ),
154153 'continue' => null,
155154 'token' => null,
@@ -168,7 +167,7 @@
169168 'enabled' => 'Enabled state to filter on',
170169 'props' => 'Survey data to query',
171170 'continue' => 'Offset number from where to continue the query',
172 - 'limit' => 'Max amount of words to return',
 171+ 'limit' => 'Max amount of words to return',
173172 'token' => 'Edit token. You can get one of these through prop=info.',
174173 );
175174 }
Index: trunk/extensions/Survey/resources/ext.survey.special.surveys.js
@@ -20,8 +20,7 @@
2121 function( data ) {
2222 if ( data.success ) {
2323 successCallback();
24 - }
25 - else {
 24+ } else {
2625 failCallback( survey.msg( 'surveys-special-delete-failed' ) );
2726 }
2827 }
Index: trunk/extensions/Survey/resources/jquery.survey.js
@@ -32,12 +32,10 @@
3333 function( data ) {
3434 if ( data.surveys ) {
3535 callback( data.surveys );
36 - }
37 - else if ( data.error ) {
 36+ } else if ( data.error ) {
3837 debugger;
3938 // TODO
40 - }
41 - else {
 39+ } else {
4240 debugger;
4341 // TODO
4442 }
@@ -187,14 +185,12 @@
188186 function() {
189187 if ( surveyData.thanks == '' ) {
190188 _this.doCompletion();
191 - }
192 - else {
 189+ } else {
193190 _this.showCompletion( surveyData );
194191 }
195192 }
196193 );
197 - }
198 - else {
 194+ } else {
199195 // TODO
200196
201197 $this.button( 'enable' );
@@ -239,8 +235,7 @@
240236 if ( $this.attr( 'survey-data-id' ) ) {
241237 this.identifier = $this.attr( 'survey-data-id' );
242238 this.identifierType = 'id';
243 - }
244 - else if ( $this.attr( 'survey-data-name' ) ) {
 239+ } else if ( $this.attr( 'survey-data-name' ) ) {
245240 this.identifier = $this.attr( 'survey-data-name' );
246241 this.identifierType = 'name';
247242 }
Index: trunk/extensions/Survey/resources/ext.survey.js
@@ -14,8 +14,7 @@
1515 if ( typeof console !== 'undefined' ) {
1616 console.log( 'Survey: ' + message );
1717 }
18 - }
19 - else {
 18+ } else {
2019 return mediaWiki.log.call( mediaWiki.log, 'Survey: ' + message );
2120 }
2221 }
@@ -30,8 +29,7 @@
3130 }
3231
3332 return message;
34 - }
35 - else {
 33+ } else {
3634 return mediaWiki.msg.apply( mediaWiki.msg, arguments );
3735 }
3836 };

Status & tagging log