r111540 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111539‎ | r111540 | r111541 >
Date:14:47, 15 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed more issues caused by recent refactor, hope I got em all now :)
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPEditAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/api/ApiEnlist.php (modified) (history)
  • /trunk/extensions/EducationProgram/api/ApiRefreshEducation.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPageTable.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevision.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionedObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisions.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRoleObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialDisenroll.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEnroll.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialMyCourses.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/actions/EPEditAction.php
@@ -100,8 +100,7 @@
101101 }
102102 else {
103103 if ( $object === false ) {
104 - $c = $this->table->getDataObjectClass();
105 - $c::displayDeletionLog(
 104+ $this->table->displayDeletionLog(
106105 $this->getContext(),
107106 'ep-' . strtolower( $this->getName() ) . '-deleted'
108107 );
@@ -355,18 +354,16 @@
356355 return Title::newFromText( $this->getRequest()->getText( 'wpreturnto' ) );
357356 }
358357 elseif ( !$addedItem && $this->isNew() ) {
359 - $c = $this->table->getDataObjectClass(); // Yeah, this is needed in PHP 5.3 >_>
360 - return SpecialPage::getTitleFor( $c::getListPage() );
 358+ return SpecialPage::getTitleFor( $this->table->getListPage() );
361359 }
362360 elseif ( $this->item !== false ) {
363361 return $this->item->getTitle();
364362 }
365363 else {
366 - $c = $this->table->getDataObjectClass(); // Yeah, this is needed in PHP 5.3 >_>
367 - $fieldName = 'wpitem-' . $c::getIdentifierField();
 364+ $fieldName = 'wpitem-' . $this->table->getIdentifierField();
368365
369366 if ( $this->getRequest()->getCheck( $fieldName ) ) {
370 - return $c::getTitleFor( $this->getRequest()->getText( $fieldName ) );
 367+ return $this->table->getTitleFor( $this->getRequest()->getText( $fieldName ) );
371368 }
372369 else {
373370 return $this->getTitle();
Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php
@@ -44,7 +44,7 @@
4545 $this->displayCourses();
4646 }
4747 else {
48 - $course = EPCourse::selectRow( null, array( 'name' => $this->subPage ) );
 48+ $course = EPCourses::singleton()->selectRow( null, array( 'name' => $this->subPage ) );
4949
5050 if ( $course === false ) {
5151 // TODO
@@ -108,7 +108,7 @@
109109 */
110110 protected function displayEnrollment() {
111111 if ( $this->getRequest()->getCheck( 'enrolled' ) ) {
112 - EPStudent::setReadDb( DB_MASTER );
 112+ EPStudents::singleton()->setReadDb( DB_MASTER );
113113 }
114114
115115 $student = EPStudent::newFromUser( $this->getUser() );
@@ -123,7 +123,10 @@
124124 );
125125
126126 if ( $this->getRequest()->getCheck( 'enrolled' ) && in_array( $this->getRequest()->getInt( 'enrolled' ), $courseIds ) ) {
127 - $course = EPCourse::selectRow( array( 'name', 'org_id' ), array( 'id' => $this->getRequest()->getInt( 'enrolled' ) ) );
 127+ $course = EPCourses::singleton()->selectRow(
 128+ array( 'name', 'org_id' ),
 129+ array( 'id' => $this->getRequest()->getInt( 'enrolled' ) )
 130+ );
128131
129132 $this->showSuccess( wfMessage(
130133 'ep-mycourses-enrolled',
Index: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php
@@ -38,7 +38,7 @@
3939 $this->showWarning( wfMessage( 'ep-disenroll-no-name' ) );
4040 }
4141 else {
42 - $course = EPCourse::get( $args[0] );
 42+ $course = EPCourses::singleton()->get( $args[0] );
4343
4444 if ( $course === false ) {
4545 $this->showWarning( wfMessage( 'ep-disenroll-invalid-name', $subPage ) );
Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php
@@ -51,7 +51,7 @@
5252 $this->showWarning( wfMessage( 'ep-enroll-no-id' ) );
5353 }
5454 else {
55 - $course = EPCourse::get( $args[0] );
 55+ $course = EPCourses::singleton()->get( $args[0] );
5656
5757 if ( $course === false ) {
5858 $this->showWarning( wfMessage( 'ep-enroll-invalid-id' ) );
Index: trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php
@@ -75,12 +75,12 @@
7676
7777 $lang = $this->getLanguage();
7878
79 - $data['org-count'] = $lang->formatNum( EPOrg::count() );
80 - $data['course-count'] = $lang->formatNum( EPCourse::count() );
81 - $data['student-count'] = $lang->formatNum( EPStudent::count() );
82 - $data['instructor-count'] = $lang->formatNum( EPInstructor::count() );
83 - $data['oa-count'] = $lang->formatNum( EPOA::count() );
84 - $data['ca-count'] = $lang->formatNum( EPCA::count() );
 79+ $data['org-count'] = $lang->formatNum( EPOrgs::singleton()->count() );
 80+ $data['course-count'] = $lang->formatNum( EPCourses::singleton()->count() );
 81+ $data['student-count'] = $lang->formatNum( EPStudents::singleton()->count() );
 82+ $data['instructor-count'] = $lang->formatNum( EPInstructors::singleton()->count() );
 83+ $data['oa-count'] = $lang->formatNum( EPOAs::singleton()->count() );
 84+ $data['ca-count'] = $lang->formatNum( EPCAs::singleton()->count() );
8585
8686 return $data;
8787 }
Index: trunk/extensions/EducationProgram/includes/EPPageTable.php
@@ -114,7 +114,7 @@
115115 * (non-PHPdoc)
116116 * @see EPRevisionedObject::getLogInfo()
117117 */
118 - protected function getLogInfoForTitle( Title $title ) {
 118+ public function getLogInfoForTitle( Title $title ) {
119119 return array(
120120 'type' => self::$info[get_called_class()]['log-type'],
121121 'title' => $title,
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php
@@ -153,8 +153,8 @@
154154 $field = $fieldMap[$this->getRoleName()];
155155
156156 if ( count( $courseIds ) > 0 ) {
157 - EPOrg::updateSummaryFields( $field, array( 'id' => array_unique( $courseIds ) ) );
158 - EPCourse::updateSummaryFields( $field, array( 'id' => $courseIds ) );
 157+ EPOrgs::singleton()->updateSummaryFields( $field, array( 'id' => array_unique( $courseIds ) ) );
 158+ EPCourses::singleton()->updateSummaryFields( $field, array( 'id' => $courseIds ) );
159159 }
160160
161161 return $success;
Index: trunk/extensions/EducationProgram/includes/EPRevisions.php
@@ -66,4 +66,37 @@
6767 );
6868 }
6969
 70+ /**
 71+ * Create a new revision object for the provided EPRevisionedObject.
 72+ * The EPRevisionedObject should have all it's fields loaded.
 73+ *
 74+ * @since 0.1
 75+ *
 76+ * @param DBDataObject $object
 77+ * @param EPRevisionAction $revAction
 78+ *
 79+ * @return EPRevision
 80+ */
 81+ public function newFromObject( EPRevisionedObject $object, EPRevisionAction $revAction ) {
 82+ $fields = array(
 83+ 'object_id' => $object->getId(),
 84+ 'user_id' => $revAction->getUser()->getID(),
 85+ 'user_text' => $revAction->getUser()->getName(),
 86+ 'type' => get_class( $object ),
 87+ 'comment' => $revAction->getComment(),
 88+ 'minor_edit' => $revAction->isMinor(),
 89+ 'time' => $revAction->getTime(),
 90+ 'deleted' => $revAction->isDelete(),
 91+ 'data' => serialize( $object->toArray() )
 92+ );
 93+
 94+ $identifier = $object->getIdentifier();
 95+
 96+ if ( !is_null( $identifier ) ) {
 97+ $fields['object_identifier'] = $identifier;
 98+ }
 99+
 100+ return new EPRevision( $this, $fields );
 101+ }
 102+
70103 }
Index: trunk/extensions/EducationProgram/includes/EPCourses.php
@@ -121,4 +121,14 @@
122122 );
123123 }
124124
 125+ public function hasActiveName( $courseName ) {
 126+ $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
 127+
 128+ return $this->has( array(
 129+ 'name' => $courseName,
 130+ 'end >= ' . $now,
 131+ 'start <= ' . $now,
 132+ ) );
 133+ }
 134+
125135 }
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -36,7 +36,7 @@
3737 $fields = array();
3838
3939 if ( in_array( 'course_count', $summaryFields ) ) {
40 - $fields['course_count'] = EPCourse::count( array( 'org_id' => $this->getId() ) );
 40+ $fields['course_count'] = EPCourses::singleton()->count( array( 'org_id' => $this->getId() ) );
4141 }
4242
4343 $dbr = wfGetDB( DB_SLAVE );
@@ -44,7 +44,7 @@
4545 if ( in_array( 'active', $summaryFields ) ) {
4646 $now = $dbr->addQuotes( wfTimestampNow() );
4747
48 - $fields['active'] = EPCourse::has( array(
 48+ $fields['active'] = EPCourses::singleton()->has( array(
4949 'org_id' => $this->getId(),
5050 'end >= ' . $now,
5151 'start <= ' . $now,
@@ -52,9 +52,9 @@
5353 }
5454
5555 foreach ( array( 'student_count', 'instructor_count', 'oa_count', 'ca_count' ) as $field ) {
56 - $fields[$field] = EPCourse::rawSelectRow(
57 - array( 'SUM(' . EPCourse::getPrefixedField( $field ). ') AS sum' ),
58 - EPCourse::getPrefixedValues( array(
 56+ $fields[$field] = EPCourses::singleton()->rawSelectRow(
 57+ array( 'SUM(' . EPCourses::singleton()->getPrefixedField( $field ). ') AS sum' ),
 58+ EPCourses::singleton()->getPrefixedValues( array(
5959 'org_id' => $this->getId()
6060 ) )
6161 )->sum;
@@ -68,7 +68,7 @@
6969 * @see EPRevisionedObject::onRemoved()
7070 */
7171 protected function onRemoved() {
72 - foreach ( EPCourse::select( null, array( 'org_id' => $this->getId() ) ) as /* EPCourse */ $course ) {
 72+ foreach ( EPCourses::singleton()->select( null, array( 'org_id' => $this->getId() ) ) as /* EPCourse */ $course ) {
7373 $revAction = clone $this->revAction;
7474
7575 if ( trim( $revAction->getComment() ) === '' ) {
@@ -201,7 +201,7 @@
202202 */
203203 public function getCourses( array $fields = null ) {
204204 if ( $this->courses === false ) {
205 - $this->courses = EPCourse::select( $fields, array( 'org_id' => $this->getId() ) );
 205+ $this->courses = EPCourses::singleton()->select( $fields, array( 'org_id' => $this->getId() ) );
206206 }
207207
208208 return $this->courses;
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
@@ -101,7 +101,7 @@
102102 */
103103 protected function storeRevision( EPRevisionedObject $object ) {
104104 if ( $this->storeRevisions && $this->revAction !== false ) {
105 - return EPRevision::newFromObject( $object, $this->revAction )->save();
 105+ return EPRevisions::singleton()->newFromObject( $object, $this->revAction )->save();
106106 }
107107
108108 return true;
@@ -136,9 +136,9 @@
137137 */
138138 protected function saveExisting() {
139139 if ( !$this->inSummaryMode ) {
140 - static::setReadDb( DB_MASTER );
141 - $originalObject = static::selectRow( null, array( 'id' => $this->getId() ) );
142 - static::setReadDb( DB_SLAVE );
 140+ $this->table->setReadDb( DB_MASTER );
 141+ $originalObject = $this->table->selectRow( null, array( 'id' => $this->getId() ) );
 142+ $this->table->setReadDb( DB_SLAVE );
143143
144144 if ( $originalObject === false ) {
145145 return false;
Index: trunk/extensions/EducationProgram/includes/EPRevision.php
@@ -22,51 +22,6 @@
2323 protected $user = false;
2424
2525 /**
26 - * @see parent::__construct
27 - *
28 - * @since 0.1
29 - *
30 - * @param array|null $fields
31 - * @param bool $loadDefaults
32 - */
33 - public function __construct( $fields = null, $loadDefaults = false ) {
34 - parent::__construct( $fields, $loadDefaults );
35 - }
36 -
37 - /**
38 - * Create a new revision object for the provided EPRevisionedObject.
39 - * The EPRevisionedObject should have all it's fields loaded.
40 - *
41 - * @since 0.1
42 - *
43 - * @param DBDataObject $object
44 - * @param EPRevisionAction $revAction
45 - *
46 - * @return EPRevision
47 - */
48 - public static function newFromObject( EPRevisionedObject $object, EPRevisionAction $revAction ) {
49 - $fields = array(
50 - 'object_id' => $object->getId(),
51 - 'user_id' => $revAction->getUser()->getID(),
52 - 'user_text' => $revAction->getUser()->getName(),
53 - 'type' => get_class( $object ),
54 - 'comment' => $revAction->getComment(),
55 - 'minor_edit' => $revAction->isMinor(),
56 - 'time' => $revAction->getTime(),
57 - 'deleted' => $revAction->isDelete(),
58 - 'data' => serialize( $object->toArray() )
59 - );
60 -
61 - $identifier = $object->getIdentifier();
62 -
63 - if ( !is_null( $identifier ) ) {
64 - $fields['object_identifier'] = $identifier;
65 - }
66 -
67 - return new static( $fields );
68 - }
69 -
70 - /**
7126 * Return the object as it was at this revision.
7227 *
7328 * @since 0,1
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -124,7 +124,7 @@
125125 $success = parent::insert();
126126
127127 if ( $success && $this->updateSummaries ) {
128 - EPOrg::updateSummaryFields( array( 'course_count', 'active' ), array( 'id' => $this->getField( 'org_id' ) ) );
 128+ EPOrgs::singleton()->updateSummaryFields( array( 'course_count', 'active' ), array( 'id' => $this->getField( 'org_id' ) ) );
129129 }
130130
131131 return $success;
@@ -136,7 +136,7 @@
137137 */
138138 protected function onRemoved() {
139139 if ( $this->updateSummaries ) {
140 - EPOrg::updateSummaryFields( null, array( 'id' => $this->getField( 'org_id' ) ) );
 140+ EPOrgs::singleton()->updateSummaryFields( null, array( 'id' => $this->getField( 'org_id' ) ) );
141141 }
142142
143143 wfGetDB( DB_MASTER )->delete( 'ep_users_per_course', array( 'upc_course_id' => $this->getId() ) );
@@ -203,10 +203,10 @@
204204 if ( $this->updateSummaries ) {
205205 if ( $this->hasField( 'org_id' ) && $originalCourse->getField( 'org_id' ) !== $this->getField( 'org_id' ) ) {
206206 $conds = array( 'id' => array( $originalCourse->getField( 'org_id' ), $this->getField( 'org_id' ) ) );
207 - EPOrg::updateSummaryFields( null, $conds );
 207+ EPOrgs::singleton()->updateSummaryFields( null, $conds );
208208 }
209209 else if ( !empty( $changedSummaries ) ) {
210 - EPOrg::updateSummaryFields( $changedSummaries, array( 'id' => $originalCourse->getField( 'org_id' ) ) );
 210+ EPOrgs::singleton()->updateSummaryFields( $changedSummaries, array( 'id' => $originalCourse->getField( 'org_id' ) ) );
211211 }
212212 }
213213
@@ -243,7 +243,7 @@
244244 */
245245 public function getOrg( $fields = null ) {
246246 if ( $this->org === false ) {
247 - $this->org = EPOrg::selectRow( $fields, array( 'id' => $this->loadAndGetField( 'org_id' ) ) );
 247+ $this->org = EPOrgs::singleton()->selectRow( $fields, array( 'id' => $this->loadAndGetField( 'org_id' ) ) );
248248 }
249249
250250 return $this->org;
@@ -701,15 +701,5 @@
702702
703703 EPUtils::log( $info );
704704 }
705 -
706 - public static function hasActiveName( $courseName ) {
707 - $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
708 -
709 - return EPCourses::singleton()->has( array(
710 - 'name' => $courseName,
711 - 'end >= ' . $now,
712 - 'start <= ' . $now,
713 - ) );
714 - }
715705
716706 }
Index: trunk/extensions/EducationProgram/api/ApiRefreshEducation.php
@@ -22,8 +22,8 @@
2323 * @var array
2424 */
2525 protected static $typeMap = array(
26 - 'org' => 'EPOrg',
27 - 'course' => 'EPCourse',
 26+ 'org' => 'EPOrsg',
 27+ 'course' => 'EPCourses',
2828 );
2929
3030 public function execute() {
@@ -34,7 +34,7 @@
3535 }
3636
3737 $c = self::$typeMap[$params['type']];
38 - $c::updateSummaryFields( null, array( 'id' => $params['ids'] ) );
 38+ $c::singleton()->updateSummaryFields( null, array( 'id' => $params['ids'] ) );
3939
4040 $this->getResult()->addValue(
4141 null,
Index: trunk/extensions/EducationProgram/api/ApiEnlist.php
@@ -46,7 +46,7 @@
4747
4848 $field = $roleMap[$params['role']];
4949
50 - $course = EPCourse::selectRow( array( 'id', 'name', $field ), array( 'id' => $params['courseid'] ) );
 50+ $course = EPCourses::singleton()->selectRow( array( 'id', 'name', $field ), array( 'id' => $params['courseid'] ) );
5151
5252 if ( $course === false ) {
5353 $this->dieUsage( wfMsg( 'ep-enlist-invalid-course' ), 'invalid-course' );
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -207,7 +207,7 @@
208208 $textParts[1] = implode( '/', $textParts[1] );
209209 }
210210
211 - $title = EPCourse::getTitleFor( $textParts[1] );
 211+ $title = EPCourses::singleton()->getTitleFor( $textParts[1] );
212212
213213 if ( !is_null( $title ) ) {
214214 self::displayTabs( $sktemplate, $links, $title );
@@ -272,7 +272,7 @@
273273 $hasCourse = $student !== false && $student->hasCourse( array( 'name' => $title->getText() ) );
274274
275275 if ( $user->isAllowed( 'ep-enroll' ) ) {
276 - if ( !$hasCourse && EPCourse::hasActiveName( $title->getText() ) ) {
 276+ if ( !$hasCourse && EPCourses::singleton()->hasActiveName( $title->getText() ) ) {
277277 $links['views']['enroll'] = array(
278278 'class' => $isSpecial ? 'selected' : false,
279279 'text' => wfMsg( 'ep-tab-enroll' ),
@@ -281,7 +281,7 @@
282282 }
283283 }
284284
285 - if ( $hasCourse && EPCourse::hasActiveName( $title->getText() ) ) {
 285+ if ( $hasCourse && EPCourses::singleton()->hasActiveName( $title->getText() ) ) {
286286 $links[$isSpecial ? 'views' : 'actions']['disenroll'] = array(
287287 'class' => $isSpecial ? 'selected' : false,
288288 'text' => wfMsg( 'ep-tab-disenroll' ),

Status & tagging log