r111326 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111325‎ | r111326 | r111327 >
Date:21:20, 12 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added disenrollment page
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/api/ApiEnlist.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialDisenroll.php (added) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -113,6 +113,7 @@
114114 $wgAutoloadClasses['SpecialStudent'] = dirname( __FILE__ ) . '/specials/SpecialStudent.php';
115115 $wgAutoloadClasses['SpecialStudents'] = dirname( __FILE__ ) . '/specials/SpecialStudents.php';
116116 $wgAutoloadClasses['SpecialEnroll'] = dirname( __FILE__ ) . '/specials/SpecialEnroll.php';
 117+$wgAutoloadClasses['SpecialDisenroll'] = dirname( __FILE__ ) . '/specials/SpecialDisenroll.php';
117118 $wgAutoloadClasses['SpecialCAs'] = dirname( __FILE__ ) . '/specials/SpecialCAs.php';
118119 $wgAutoloadClasses['SpecialOAs'] = dirname( __FILE__ ) . '/specials/SpecialOAs.php';
119120 //$wgAutoloadClasses['SpecialCA'] = dirname( __FILE__ ) . '/specials/SpecialCA.php';
@@ -129,6 +130,7 @@
130131 $wgSpecialPages['Courses'] = 'SpecialCourses';
131132 $wgSpecialPages['EducationProgram'] = 'SpecialEducationProgram';
132133 $wgSpecialPages['Enroll'] = 'SpecialEnroll';
 134+$wgSpecialPages['Disenroll'] = 'SpecialDisenroll';
133135 $wgSpecialPages['CampusAmbassadors'] = 'SpecialCAs';
134136 $wgSpecialPages['OnlineAmbassadors'] = 'SpecialOAs';
135137 //$wgSpecialPages['CampusAmbassador'] = 'SpecialCA';
@@ -148,6 +150,8 @@
149151 //$wgSpecialPageGroups['OnlineAmbassador'] = 'education';
150152 $wgSpecialPageGroups['CampusAmbassadorProfile'] = 'education';
151153 $wgSpecialPageGroups['OnlineAmbassadorProfile'] = 'education';
 154+$wgSpecialPageGroups['Enroll'] = 'education';
 155+$wgSpecialPageGroups['Disenroll'] = 'education';
152156
153157 define( 'EP_STUDENT', 0 );
154158 define( 'EP_INSTRUCTOR', 1 );
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php
@@ -23,6 +23,7 @@
2424 'Courses' => array( 'Courses' ),
2525 'EducationProgram' => array( 'EducationProgram' ),
2626 'Enroll' => array( 'Enroll' ),
 27+ 'Disenroll' => array( 'Disenroll' ),
2728 'CampusAmbassadors' => array( 'CampusAmbassadors' ),
2829 'OnlineAmbassadors' => array( 'OnlineAmbassadors' ),
2930 // 'CampusAmbassador' => array( 'CampusAmbassador' ),
Index: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php
@@ -0,0 +1,105 @@
 2+<?php
 3+
 4+/**
 5+ * Disenrollment page for students.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file SpecialDisenroll.php
 10+ * @ingroup EducationProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class SpecialDisenroll extends SpecialEPPage {
 16+
 17+ /**
 18+ * @since 0.1
 19+ * @var EPCourse
 20+ */
 21+ protected $course;
 22+
 23+ /**
 24+ * @since 0.1
 25+ * @var string|false
 26+ */
 27+ protected $token = false;
 28+
 29+ /**
 30+ * Constructor.
 31+ *
 32+ * @since 0.1
 33+ */
 34+ public function __construct() {
 35+ parent::__construct( 'Disenroll', '', false );
 36+ }
 37+
 38+ /**
 39+ * Main method.
 40+ *
 41+ * @since 0.1
 42+ *
 43+ * @param string $subPage
 44+ */
 45+ public function execute( $subPage ) {
 46+ parent::execute( $subPage );
 47+
 48+ $args = explode( '/', $this->subPage, 2 );
 49+
 50+ if ( $args[0] === '' ) {
 51+ $this->showWarning( wfMessage( 'ep-disenroll-no-name' ) );
 52+ }
 53+ else {
 54+ $course = EPCourse::get( $args[0] );
 55+
 56+ if ( $course === false ) {
 57+ $this->showWarning( wfMessage( 'ep-disenroll-invalid-name' ) );
 58+ }
 59+ else {
 60+ if ( EPStudent::newFromUser( $this->getUser() )->hasCourse( array( 'id' => $course->getId() ) ) ) {
 61+ if ( $course->getStatus() === 'current' ) {
 62+ if ( $this->getUser()->isLoggedIn() ) {
 63+ $req = $this->getRequest();
 64+
 65+ if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'disenrollEditToken' ) ) ) {
 66+ $this->doDisenroll( $course );
 67+ }
 68+ else {
 69+ $this->showDisenrollForm( $course );
 70+ }
 71+ }
 72+ else {
 73+ $this->showLoginLink();
 74+ }
 75+ }
 76+ else {
 77+ $this->showWarning( wfMessage( 'ep-disenroll-course-passed' ) );
 78+ }
 79+ }
 80+ else {
 81+ $this->showWarning( wfMessage( 'ep-disenroll-not-enrolled' ) );
 82+ }
 83+ }
 84+ }
 85+ }
 86+
 87+ protected function showLoginLink() {
 88+ $this->getOutput()->addHTML( Linker::linkKnown(
 89+ SpecialPage::getTitleFor( 'Userlogin' ),
 90+ wfMsgHtml( 'ep-enroll-login-and-enroll' ),
 91+ array(),
 92+ array(
 93+ 'returnto' => $this->getTitle( $this->subPage )->getFullText()
 94+ )
 95+ ) );
 96+ }
 97+
 98+ protected function showDisenrollForm( EPCourse $course ) {
 99+ // TODO
 100+ }
 101+
 102+ protected function doDisenroll( EPCourse $course ) {
 103+ // TODO
 104+ }
 105+
 106+}
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -34,6 +34,7 @@
3535 'ep-tab-create' => 'Create',
3636 'ep-tab-history' => 'View history',
3737 'ep-tab-enroll' => 'Enroll',
 38+ 'ep-tab-disenroll' => 'Disenroll',
3839
3940 // Tooltips
4041 'tooltip-ep-form-save' => 'Save',
@@ -167,6 +168,7 @@
168169 'special-campusambassadors' => 'Campus ambassadors',
169170 'special-onlineambassador' => 'Online ambassador',
170171 'special-campusambassador' => 'Campus ambassador',
 172+ 'special-disenroll' => 'Disenroll',
171173
172174 // Course statuses
173175 'ep-course-status-passed' => 'Passed',
Index: trunk/extensions/EducationProgram/api/ApiEnlist.php
@@ -33,7 +33,7 @@
3434 $this->dieUsage( wfMsg( 'ep-enlist-invalid-user' ), 'invalid-user' );
3535 }
3636
37 - if ( !$this->userIsAllowed( $userId, $params['role'] ) ) {
 37+ if ( !$this->userIsAllowed( $userId, $params['role'], $params['subaction'] ) ) {
3838 $this->dieUsageMsg( array( 'badaccess-groups' ) );
3939 }
4040
@@ -77,13 +77,19 @@
7878 *
7979 * @param integer $userId User id of the mentor affected
8080 * @param string $role
 81+ * @param string $subAction
8182 *
8283 * @return boolean
8384 */
84 - protected function userIsAllowed( $userId, $role ) {
 85+ protected function userIsAllowed( $userId, $role, $subAction ) {
8586 $user = $this->getUser();
8687 $isSelf = $user->getId() === $userId;
 88+ $isRemove = $subAction === 'remove';
8789
 90+ if ( $isSelf && $isRemove ) {
 91+ return true;
 92+ }
 93+
8894 switch ( $role ) {
8995 case 'student':
9096 return $user->isAllowed( 'ep-enroll' ) && $isSelf;
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -193,7 +193,9 @@
194194 public static function onSpecialPageTabs( SkinTemplate &$sktemplate, array &$links ) {
195195 $textParts = SpecialPageFactory::resolveAlias( $sktemplate->getTitle()->getText() );
196196
197 - if ( $textParts[0] === 'Enroll' && !is_null( $textParts[1] ) && trim( $textParts[1] ) !== '' ) {
 197+ if ( in_array( $textParts[0], array( 'Enroll', 'Disenroll' ) )
 198+ && !is_null( $textParts[1] ) && trim( $textParts[1] ) !== '' ) {
 199+
198200 // Remove the token from the title if needed.
199201 if ( !$sktemplate->getRequest()->getCheck( 'wptoken' ) ) {
200202 $textParts[1] = explode( '/', $textParts[1] );
@@ -264,12 +266,13 @@
265267 'text' => wfMsg( 'ep-tab-history' ),
266268 'href' => $title->getLocalUrl( array( 'action' => 'history' ) )
267269 );
268 -
 270+
269271 if ( $title->getNamespace() === EP_NS_COURSE ) {
 272+ $student = EPStudent::newFromUser( $user );
 273+ $hasCourse = $student !== false && $student->hasCourse( array( 'name' => $title->getText() ) );
 274+
270275 if ( $user->isAllowed( 'ep-enroll' ) ) {
271 - $student = EPStudent::newFromUser( $user );
272 -
273 - if ( $student === false || !$student->hasCourse( array( 'name' => $title->getText() ) ) ) {
 276+ if ( !$hasCourse ) {
274277 $links['views']['enroll'] = array(
275278 'class' => $isSpecial ? 'selected' : false,
276279 'text' => wfMsg( 'ep-tab-enroll' ),
@@ -277,6 +280,14 @@
278281 );
279282 }
280283 }
 284+
 285+ if ( $hasCourse ) {
 286+ $links[$isSpecial ? 'views' : 'actions']['disenroll'] = array(
 287+ 'class' => $isSpecial ? 'selected' : false,
 288+ 'text' => wfMsg( 'ep-tab-disenroll' ),
 289+ 'href' => SpecialPage::getTitleFor( 'Disenroll', $title->getText() )->getLocalURL()
 290+ );
 291+ }
281292 }
282293 }
283294 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r111328follow up to r111326, kill dead code, added messages and added docsjeroendedauw21:27, 12 February 2012

Status & tagging log