Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php |
— | — | @@ -25,6 +25,7 @@ |
26 | 26 | * @since 0.1 |
27 | 27 | */ |
28 | 28 | public function __construct() { |
| 29 | + // We can not demand ep-enroll here already, since the user might first need to login. |
29 | 30 | parent::__construct( 'Enroll', '', false ); |
30 | 31 | } |
31 | 32 | |
— | — | @@ -43,48 +44,109 @@ |
44 | 45 | if ( !ctype_digit( $args[0] ) ) { |
45 | 46 | $this->showWarning( wfMessage( $args[0] === '' ? 'ep-enroll-no-id' : 'ep-enroll-invalid-id' ) ); |
46 | 47 | } |
47 | | - elseif ( count( $args ) === 1 ) { |
48 | | - // TODO: might want to have an input here |
49 | | - $this->showWarning( wfMessage( 'ep-enroll-no-token' ) ); |
50 | | - } |
51 | | - elseif ( count( $args ) === 2 ) { |
52 | | - $term = EPTerm::selectRow( null, array( |
53 | | - 'id' => $args[0], |
54 | | - 'token' => $args[1] |
55 | | - ) ); |
56 | | - |
| 48 | + else { |
| 49 | + $term = EPTerm::selectRow( null, array( 'id' => $args[0] ) ); |
| 50 | + |
57 | 51 | if ( $term === false ) { |
58 | | - $this->showWarning( wfMessage( 'ep-enroll-invalid-token' ) ); |
| 52 | + $this->showWarning( wfMessage( 'ep-enroll-nosuchterm' ) ); |
59 | 53 | } |
| 54 | + elseif ( $term->getStatus() === 'current' ) { |
| 55 | + $token = ''; |
| 56 | + |
| 57 | + if ( count( $args ) === 2 ) { |
| 58 | + $token = $args[1]; |
| 59 | + } |
| 60 | + elseif ( $this->getRequest()->wasPosted() && $this->getRequest()->getCheck( 'wptoken' ) ) { |
| 61 | + $token = $this->getRequest()->getText( 'wptoken' ); |
| 62 | + } |
| 63 | + |
| 64 | + if ( $term->getField( 'token' ) === $token ) { |
| 65 | + $this->showEnrollmentView( $term ); |
| 66 | + } |
| 67 | + else { |
| 68 | + if ( $token !== '' ) { |
| 69 | + $this->showWarning( wfMessage( 'ep-enroll-invalid-token' ) ); |
| 70 | + } |
| 71 | + |
| 72 | + $this->showTokenInput(); |
| 73 | + } |
| 74 | + } |
60 | 75 | else { |
61 | | - $this->term = $term; |
| 76 | + $this->showWarning( wfMessage( 'ep-enroll-term-' . $term->getStatus() ) ); |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Shows the actuall enrollment view. |
| 83 | + * Should only be called after everything checks out, ie the user can enroll in the term. |
| 84 | + * |
| 85 | + * @since 0.1 |
| 86 | + * |
| 87 | + * @param EPTerm $term |
| 88 | + */ |
| 89 | + protected function showEnrollmentView( EPTerm $term ) { |
| 90 | + $this->term = $term; |
62 | 91 | |
63 | | - $this->setPageTitle( $term ); |
| 92 | + $this->setPageTitle( $term ); |
64 | 93 | |
65 | | - if ( $this->getUser()->isLoggedIn() ) { |
66 | | - if ( $this->getUser()->isAllowed( 'ep-enroll' ) ) { |
67 | | - $user = $this->getUser(); |
68 | | - $hasFields = trim( $user->getRealName() ) !== '' && $user->getOption( 'gender' ) !== 'unknown'; |
| 94 | + if ( $this->getUser()->isLoggedIn() ) { |
| 95 | + if ( $this->getUser()->isAllowed( 'ep-enroll' ) ) { |
| 96 | + $user = $this->getUser(); |
| 97 | + $hasFields = trim( $user->getRealName() ) !== '' && $user->getOption( 'gender' ) !== 'unknown'; |
69 | 98 | |
70 | | - if ( $hasFields ) { |
71 | | - $this->doEnroll( $term ); |
72 | | - $this->onSuccess(); |
73 | | - } |
74 | | - else { |
75 | | - $this->showEnrollmentForm( $term ); |
76 | | - } |
77 | | - } |
78 | | - else { |
79 | | - $this->showWarning( wfMessage( 'ep-enroll-not-allowed' ) ); |
80 | | - } |
| 99 | + if ( $hasFields ) { |
| 100 | + $this->doEnroll( $term ); |
| 101 | + $this->onSuccess(); |
81 | 102 | } |
82 | 103 | else { |
83 | | - $this->showSignupLink(); |
| 104 | + $this->showEnrollmentForm( $term ); |
84 | 105 | } |
85 | 106 | } |
| 107 | + else { |
| 108 | + $this->showWarning( wfMessage( 'ep-enroll-not-allowed' ) ); |
| 109 | + } |
86 | 110 | } |
| 111 | + else { |
| 112 | + $this->showSignupLink(); |
| 113 | + } |
87 | 114 | } |
| 115 | + |
| 116 | + /** |
| 117 | + * Show an input for a token. |
| 118 | + * |
| 119 | + * @since 0.1 |
| 120 | + */ |
| 121 | + protected function showTokenInput() { |
| 122 | + $out = $this->getOutput(); |
| 123 | + |
| 124 | + // $out->addWikiMsg( 'ep-enroll-no-token' ); |
| 125 | + |
| 126 | + $out->addHTML( Html::openElement( |
| 127 | + 'form', |
| 128 | + array( |
| 129 | + 'method' => 'post', |
| 130 | + 'action' => $this->getTitle( $this->subPage )->getLocalURL(), |
| 131 | + ) |
| 132 | + ) ); |
88 | 133 | |
| 134 | + $out->addHTML( '<fieldset>' ); |
| 135 | + |
| 136 | + $out->addHTML( '<legend>' . wfMsgHtml( 'ep-enroll-add-token' ) . '</legend>' ); |
| 137 | + |
| 138 | + $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-enroll-add-token-doc' ) ) ); |
| 139 | + |
| 140 | + $out->addHTML( ' ' . Xml::inputLabel( wfMsg( 'ep-enroll-token' ), 'wptoken', 'wptoken' ) ); |
| 141 | + |
| 142 | + $out->addHTML( ' ' . Html::input( |
| 143 | + 'submittoken', |
| 144 | + wfMsg( 'ep-enroll-submit-token' ), |
| 145 | + 'submit' |
| 146 | + ) ); |
| 147 | + |
| 148 | + $out->addHTML( '</fieldset></form>' ); |
| 149 | + } |
| 150 | + |
89 | 151 | /** |
90 | 152 | * Set the page title. |
91 | 153 | * |
— | — | @@ -240,6 +302,13 @@ |
241 | 303 | ) |
242 | 304 | ); |
243 | 305 | } |
| 306 | + |
| 307 | + if ( $this->getRequest()->getCheck( 'wptoken' ) ) { |
| 308 | + $fields['token'] = array( |
| 309 | + 'type' => 'hidden', |
| 310 | + 'default' => $this->getRequest()->getText( 'wptoken' ) |
| 311 | + ); |
| 312 | + } |
244 | 313 | |
245 | 314 | return $fields; |
246 | 315 | } |
Index: trunk/extensions/EducationProgram/specials/SpecialTerm.php |
— | — | @@ -69,16 +69,20 @@ |
70 | 70 | |
71 | 71 | $out->addHTML( $this->getOutput()->parse( $term->getField( 'description' ) ) ); |
72 | 72 | |
73 | | - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-term-students' ) ) ); |
74 | | - |
75 | 73 | $studentIds = array_map( |
76 | 74 | function( EPStudent $student ) { |
77 | 75 | return $student->getId(); |
78 | 76 | }, |
79 | 77 | $term->getStudents( 'id' ) |
80 | 78 | ); |
81 | | - |
82 | | - EPStudent::displayPager( $this->getContext(), array( 'id' => $studentIds ) ); |
| 79 | + |
| 80 | + if ( count( $studentIds ) > 0 ) { |
| 81 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-term-students' ) ) ); |
| 82 | + EPStudent::displayPager( $this->getContext(), array( 'id' => $studentIds ) ); |
| 83 | + } |
| 84 | + else { |
| 85 | + // TODO |
| 86 | + } |
83 | 87 | } |
84 | 88 | } |
85 | 89 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -322,7 +322,6 @@ |
323 | 323 | 'ep-enroll-not-allowed' => 'Your account is not allowed to enroll', |
324 | 324 | 'ep-enroll-invalid-id' => 'The term you tried to enroll for does not exist. A list of existing terms can be found [[Special:Terms|here]].', |
325 | 325 | 'ep-enroll-no-id' => 'You need to specify a term to enroll for. A list of existing terms can be found [[Special:Terms|here]].', |
326 | | - 'ep-enroll-no-token' => 'You need to provide the token needed to enroll for this term.', |
327 | 326 | 'ep-enroll-invalid-token' => 'The token you provided is invalid.', |
328 | 327 | 'ep-enroll-legend' => 'Enroll', |
329 | 328 | 'ep-enroll-header' => 'In order to enroll for this course, all you need to do is fill out this form and click the submission button. After that you will be enrolled.', |
— | — | @@ -330,6 +329,10 @@ |
331 | 330 | 'ep-enroll-realname' => 'Real name (required)', |
332 | 331 | 'ep-enroll-invalid-name' => 'The name needs to be at least contain $1 {{PLURAL:$1|character|characters}}.', |
333 | 332 | 'ep-enroll-invalid-gender' => 'Please select one of these genders', |
| 333 | + 'ep-enroll-add-token' => 'Enter your enrollment token', |
| 334 | + 'ep-enroll-add-token-doc' => 'In order to enroll for this term, you need a token provided by your instructor or one of the ambassadors for your term.', |
| 335 | + 'ep-enroll-token' => 'Enrollment token', |
| 336 | + 'ep-enroll-submit-token' => 'Enroll with this token', |
334 | 337 | |
335 | 338 | // Special:MyCourses |
336 | 339 | 'ep-mycourses-enrolled' => 'You have successfully enrolled for $1 at $2.', |