r113702 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113701‎ | r113702 | r113703 >
Date:01:36, 13 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
use proper array empty check and prioritized todos
Modified paths:
  • /trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPViewAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/api/ApiDeleteEducation.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/DBDataObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPageTable.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionedObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRoleObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.articletable.js (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialMyCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialStudent.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
@@ -54,7 +54,7 @@
5555 $course->getStudents( 'id' )
5656 );
5757
58 - if ( count( $studentIds ) > 0 ) {
 58+ if ( !empty( $studentIds ) ) {
5959 $out->addElement( 'h2', array(), wfMsg( 'ep-course-students' ) );
6060
6161 $pager = new EPArticleTable(
@@ -131,7 +131,10 @@
132132 protected function getRoleList( EPCourse $course, $roleName ) {
133133 $users = $course->getUserWithRole( $roleName );
134134
135 - if ( count( $users ) > 0 ) {
 135+ if ( empty( $users ) ) {
 136+ $html = wfMsgHtml( 'ep-course-no-' . $roleName );
 137+ }
 138+ else {
136139 $instList = array();
137140
138141 foreach ( $users as /* EPIRole */ $user ) {
@@ -145,9 +148,6 @@
146149 $html = '<ul><li>' . implode( '</li><li>', $instList ) . '</li></ul>';
147150 }
148151 }
149 - else {
150 - $html = wfMsgHtml( 'ep-course-no-' . $roleName );
151 - }
152152
153153 return Html::rawElement(
154154 'div',
@@ -204,13 +204,13 @@
205205 );
206206 }
207207
208 - if ( count( $links ) > 0 ) {
 208+ if ( empty( $links ) ) {
 209+ return '';
 210+ }
 211+ else {
209212 $this->getOutput()->addModules( 'ep.enlist' );
210213 return '<br />' . $this->getLanguage()->pipeList( $links );
211214 }
212 - else {
213 - return '';
214 - }
215215 }
216216
217217 }
Index: trunk/extensions/EducationProgram/actions/EPViewAction.php
@@ -55,7 +55,7 @@
5656 ) );
5757
5858 if ( $rev === false ) {
59 - // TODO
 59+ // TODO high
6060 }
6161 else {
6262 $object = $rev->getObject();
Index: trunk/extensions/EducationProgram/actions/EPRemoveStudentAction.php
@@ -33,7 +33,7 @@
3434 'format' => 'json',
3535 'courseid' => $this->getRequest()->getInt( 'course-id' ),
3636 'userid' => $this->getRequest()->getInt( 'user-id' ),
37 - 'reason' => '', // TODO
 37+ 'reason' => '', // TODO high
3838 'role' => 'student'
3939 ), true ), true );
4040
Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php
@@ -47,7 +47,7 @@
4848 $course = EPCourses::singleton()->selectRow( null, array( 'name' => $this->subPage ) );
4949
5050 if ( $course === false ) {
51 - // TODO
 51+ // TODO high
5252 }
5353 else {
5454 $this->displayCourse( $course );
@@ -155,7 +155,7 @@
156156 break;
157157 }
158158
159 - if ( count( $courses ) > 0 ) {
 159+ if ( !empty( $courses ) ) {
160160 $message = wfMsgExt( 'ep-mycourses-courses-' . strtolower( $class ), 'parsemag', count( $courses ), $this->getUser()->getName() );
161161 $this->getOutput()->addElement( 'h2', array(), $message );
162162
Index: trunk/extensions/EducationProgram/specials/SpecialStudent.php
@@ -57,13 +57,13 @@
5858 $student->getCourses( 'id' )
5959 );
6060
61 - if ( count( $courseIds ) > 0 ) {
 61+ if ( empty( $courseIds ) ) {
 62+ // TODO: high
 63+ }
 64+ else {
6265 $out->addElement( 'h2', array(), wfMsg( 'ep-student-courses' ) );
6366 EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ) );
6467 }
65 - else {
66 - // TODO
67 - }
6868 }
6969 }
7070 }
Index: trunk/extensions/EducationProgram/includes/DBDataObject.php
@@ -127,7 +127,7 @@
128128 $fields = array_diff( $fields, array_keys( $this->fields ) );
129129 }
130130
131 - if ( count( $fields ) > 0 ) {
 131+ if ( !empty( $fields ) ) {
132132 $result = $this->table->rawSelectRow(
133133 $this->table->getPrefixedFields( $fields ),
134134 array( $this->table->getPrefixedField( 'id' ) => $this->getId() ),
Index: trunk/extensions/EducationProgram/includes/EPPageTable.php
@@ -76,7 +76,7 @@
7777
7878 $success = true;
7979
80 - if ( count( $objects ) > 0 ) {
 80+ if ( !empty( $objects ) ) {
8181 $revAction->setDelete( true );
8282
8383 foreach ( $objects as /* EPPageObject */ $object ) {
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php
@@ -163,7 +163,7 @@
164164
165165 $field = $fieldMap[$this->getRoleName()];
166166
167 - if ( count( $courseIds ) > 0 ) {
 167+ if ( !empty( $courseIds ) ) {
168168 EPOrgs::singleton()->updateSummaryFields( $field, array( 'id' => array_unique( $courseIds ) ) );
169169 EPCourses::singleton()->updateSummaryFields( $field, array( 'id' => $courseIds ) );
170170 }
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -117,7 +117,7 @@
118118 $courseRevAction = new EPRevisionAction();
119119
120120 $courseRevAction->setUser( $revAction->getUser() );
121 - $courseRevAction->setComment( '' ); // TODO
 121+ $courseRevAction->setComment( $revAction->getComment() );
122122
123123 foreach ( $this->getField( 'courses' ) as $courseId ) {
124124 $courseRevision = EPRevisions::singleton()->getLatestRevision( array(
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
@@ -260,7 +260,7 @@
261261 array( 'LIMIT' => 1 )
262262 );
263263
264 - return count( $objects ) > 0 ? $objects[0] : false;
 264+ return empty( $objects ) ? false : $objects[0];
265265 }
266266
267267 /**
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -180,7 +180,7 @@
181181 $changedSummaries[] = $countMap[$usersField];
182182 }
183183
184 - if ( count( $removedIds ) > 0 ) {
 184+ if ( !empty( $removedIds ) ) {
185185 $dbw->delete( 'ep_users_per_course', array(
186186 'upc_course_id' => $this->getId(),
187187 'upc_user_id' => $removedIds,
@@ -579,7 +579,10 @@
580580 $users = $this->getField( $field );
581581 $addedUsers = array_diff( (array)$newUsers, $users );
582582
583 - if ( count( $addedUsers ) > 0 ) {
 583+ if ( empty( $addedUsers ) ) {
 584+ return 0;
 585+ }
 586+ else {
584587 $this->setField( $field, array_merge( $users, $addedUsers ) );
585588
586589 $success = true;
@@ -597,9 +600,6 @@
598601
599602 return $success ? count( $addedUsers ) : false;
600603 }
601 - else {
602 - return 0;
603 - }
604604 }
605605
606606 /**
@@ -630,7 +630,10 @@
631631
632632 $removedUsers = array_intersect( $sadUsers, $this->getField( $field ) );
633633
634 - if ( count( $removedUsers ) > 0 ) {
 634+ if ( empty( $removedUsers ) ) {
 635+ return 0;
 636+ }
 637+ else {
635638 $this->setField( $field, array_diff( $this->getField( $field ), $sadUsers ) );
636639
637640 if ( $role === 'student' ) {
@@ -658,9 +661,6 @@
659662
660663 return $success ? count( $removedUsers ) : false;
661664 }
662 - else {
663 - return 0;
664 - }
665665 }
666666
667667 /**
Index: trunk/extensions/EducationProgram/api/ApiDeleteEducation.php
@@ -56,7 +56,7 @@
5757
5858 $class = self::$typeMap[$params['type']];
5959
60 - if ( count( $params['ids'] ) > 0 ) {
 60+ if ( !empty( $params['ids'] ) ) {
6161 $revAction = new EPRevisionAction();
6262
6363 $revAction->setUser( $this->getUser() );
Index: trunk/extensions/EducationProgram/resources/ep.articletable.js
@@ -262,7 +262,7 @@
263263
264264 $( '.ep-rem-article' ).click( removeArticle );
265265
266 - $( '#addarticlename' ).autocomplete( { // TODO
 266+ $( '#addarticlename' ).autocomplete( {
267267 source: function( request, response ) {
268268 $.getJSON(
269269 wgScriptPath + '/api.php',

Status & tagging log