r111666 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111665‎ | r111666 | r111667 >
Date:19:44, 16 February 2012
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
tweaks to logging
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/api/ApiEnlist.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialDisenroll.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php
@@ -163,10 +163,15 @@
164164 * @param EPCourse $course
165165 */
166166 protected function doDisenroll( EPCourse $course ) {
 167+ $revAction = new EPRevisionAction();
 168+ $revAction->setUser( $this->getUser() );
 169+ $revAction->setComment( $this->getRequest()->getText( 'summary' ) );
 170+
167171 $success = $course->unenlistUsers(
168172 $this->getUser()->getId(),
169173 'student',
170 - $this->getRequest()->getText( 'summary' )
 174+ true,
 175+ $revAction
171176 );
172177
173178 if ( $success ) {
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -548,13 +548,12 @@
549549 *
550550 * @param array|integer $newUsers
551551 * @param string $role
552 - * @param string $message
553552 * @param boolean $save
554 - * @param boolean $log
 553+ * @param EPRevisionAction|null $revAction
555554 *
556555 * @return boolean Success indicator
557556 */
558 - public function enlistUsers( $newUsers, $role, $message = '', $save = true, $log = true ) {
 557+ public function enlistUsers( $newUsers, $role, $save = true, EPRevisionAction $revAction = null ) {
559558 $roleMap = array(
560559 'student' => 'students',
561560 'campus' => 'campus_ambs',
@@ -588,8 +587,9 @@
589588 $this->enableLogging();
590589 }
591590
592 - if ( $success && $log ) {
593 - $this->logRoleChange( 'add', $role, $addedUsers, $message );
 591+ if ( $success && !is_null( $revAction ) ) {
 592+ $action = count( $addedUsers ) == 1 && $revAction->getUser()->getId() === $addedUsers[0] ? 'selfadd' : 'add';
 593+ $this->logRoleChange( $action, $role, $addedUsers, $revAction->getComment() );
594594 }
595595
596596 return $success;
@@ -608,14 +608,13 @@
609609 *
610610 * @param array|integer $sadUsers
611611 * @param string $role
612 - * @param string $message
613612 * @param boolean $save
614 - * @param boolean $log
 613+ * @param EPRevisionAction|null $revAction
615614 *
616615 * @return boolean Success indicator
617616 */
618 - public function unenlistUsers( $sadUsers, $role, $message = '', $save = true, $log = true ) {
619 - $removedUser = array();
 617+ public function unenlistUsers( $sadUsers, $role, $save = true, EPRevisionAction $revAction = null ) {
 618+ $removedUsers = array();
620619 $remaimingUsers = array();
621620 $sadUsers = (array)$sadUsers;
622621
@@ -630,14 +629,14 @@
631630
632631 foreach ( $this->getField( $field ) as $userId ) {
633632 if ( in_array( $userId, $sadUsers ) ) {
634 - $removedUser[] = $userId;
 633+ $removedUsers[] = $userId;
635634 }
636635 else {
637636 $remaimingUsers[] = $userId;
638637 }
639638 }
640639
641 - if ( count( $removedUser ) > 0 ) {
 640+ if ( count( $removedUsers ) > 0 ) {
642641 $this->setField( $field, $remaimingUsers );
643642
644643 $success = true;
@@ -648,8 +647,9 @@
649648 $this->enableLogging();
650649 }
651650
652 - if ( $success && $log ) {
653 - $this->logRoleChange( 'remove', $role, $removedUser, $message );
 651+ if ( $success && !is_null( $revAction ) ) {
 652+ $action = count( $removedUsers ) == 1 && $revAction->getUser()->getId() === $removedUsers[0] ? 'selfremove' : 'remove';
 653+ $this->logRoleChange( $action, $role, $removedUsers, $revAction->getComment() );
654654 }
655655
656656 return $success;
@@ -690,8 +690,8 @@
691691 'subtype' => $action,
692692 'title' => $this->getTitle(),
693693 'parameters' => array(
694 - '4::instructorcount' => count( $names ),
695 - '5::instructors' => $GLOBALS['wgLang']->listToText( $names )
 694+ '4::usercount' => count( $names ),
 695+ '5::users' => $GLOBALS['wgLang']->listToText( $names )
696696 ),
697697 );
698698
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -94,7 +94,7 @@
9595 'logentry-instructor-add' => '$1 {{GENDER:$2|added}} {{PLURAL:$4|instructor|instructors}} $5 to course $3',
9696 'logentry-instructor-remove' => '$1 {{GENDER:$2|removed}} {{PLURAL:$4|instructor|instructors}} $5 from course $3',
9797 'logentry-instructor-selfadd' => '$1 added {{GENDER:$2|added himself|herself}} as {{GENDER:$2|instructor}} to course $3',
98 - 'logentry-instructor-selfremove' => '$1 removed {{GENDER:$2|removed himself|herself}} as {{GENDER:$2|instructor}} from course $3',
 98+ 'logentry-instructor-selfremove' => '$1 removed {{GENDER:$2|himself|herself}} as {{GENDER:$2|instructor}} from course $3',
9999
100100 'logentry-online-add' => '$1 added {{PLURAL:$4|Online Ambassador|Online Ambassadors}} $5 to course $3',
101101 'logentry-online-remove' => '$1 removed {{PLURAL:$4|Online Ambassador|Online Ambassadors}} $5 from course $3',
@@ -107,7 +107,7 @@
108108 'logentry-campus-selfremove' => '$1 removed {{GENDER:$2|himself|herself}} as {{GENDER:$2|Campus Ambassador}} from course $3',
109109
110110 'logentry-student-add' => '$1 enrolled in course $3',
111 - 'logentry-student-remove' => '$1 removed $4 as student from course $3',
 111+ 'logentry-student-remove' => '$1 removed $5 as student from course $3',
112112 'logentry-student-selfremove' => '$1 removed {{GENDER:$2|his|her}} enrollment from course $3',
113113
114114 // Preferences
Index: trunk/extensions/EducationProgram/api/ApiEnlist.php
@@ -53,13 +53,17 @@
5454 }
5555
5656 $success = false;
57 -
 57+
 58+ $revAction = new EPRevisionAction();
 59+ $revAction->setUser( $this->getUser() );
 60+ $revAction->setComment( $params['reason'] );
 61+
5862 switch ( $params['subaction'] ) {
5963 case 'add':
60 - $success = $course->enlistUsers( array( $userId ), $params['role'], $params['reason'] );
 64+ $success = $course->enlistUsers( array( $userId ), $params['role'], true, $revAction );
6165 break;
6266 case 'remove':
63 - $success = $course->unenlistUsers( array( $userId ), $params['role'], $params['reason'] );
 67+ $success = $course->unenlistUsers( array( $userId ), $params['role'], true, $revAction );
6468 break;
6569 }
6670

Follow-up revisions

RevisionCommit summaryAuthorDate
r111793follow up to r111666jeroendedauw21:27, 17 February 2012

Comments

#Comment by Nikerabbit (talk | contribs)   06:39, 17 February 2012
'5::users' => $GLOBALS['wgLang']->listToText( $names )

You probably don't want to add preformatted data to logging table depending on the current user's language.

#Comment by Dantman (talk | contribs)   06:49, 17 February 2012

Not to mention that the request context should be used.

Status & tagging log