r108917 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108916‎ | r108917 | r108918 >
Date:16:50, 14 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on special:enroll
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEnroll.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialTerm.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php
@@ -25,6 +25,7 @@
2626 * @since 0.1
2727 */
2828 public function __construct() {
 29+ // We can not demand ep-enroll here already, since the user might first need to login.
2930 parent::__construct( 'Enroll', '', false );
3031 }
3132
@@ -43,48 +44,109 @@
4445 if ( !ctype_digit( $args[0] ) ) {
4546 $this->showWarning( wfMessage( $args[0] === '' ? 'ep-enroll-no-id' : 'ep-enroll-invalid-id' ) );
4647 }
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+
5751 if ( $term === false ) {
58 - $this->showWarning( wfMessage( 'ep-enroll-invalid-token' ) );
 52+ $this->showWarning( wfMessage( 'ep-enroll-nosuchterm' ) );
5953 }
 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+ }
6075 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;
6291
63 - $this->setPageTitle( $term );
 92+ $this->setPageTitle( $term );
6493
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';
6998
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();
81102 }
82103 else {
83 - $this->showSignupLink();
 104+ $this->showEnrollmentForm( $term );
84105 }
85106 }
 107+ else {
 108+ $this->showWarning( wfMessage( 'ep-enroll-not-allowed' ) );
 109+ }
86110 }
 111+ else {
 112+ $this->showSignupLink();
 113+ }
87114 }
 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+ ) );
88133
 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( '&#160;' . Xml::inputLabel( wfMsg( 'ep-enroll-token' ), 'wptoken', 'wptoken' ) );
 141+
 142+ $out->addHTML( '&#160;' . Html::input(
 143+ 'submittoken',
 144+ wfMsg( 'ep-enroll-submit-token' ),
 145+ 'submit'
 146+ ) );
 147+
 148+ $out->addHTML( '</fieldset></form>' );
 149+ }
 150+
89151 /**
90152 * Set the page title.
91153 *
@@ -240,6 +302,13 @@
241303 )
242304 );
243305 }
 306+
 307+ if ( $this->getRequest()->getCheck( 'wptoken' ) ) {
 308+ $fields['token'] = array(
 309+ 'type' => 'hidden',
 310+ 'default' => $this->getRequest()->getText( 'wptoken' )
 311+ );
 312+ }
244313
245314 return $fields;
246315 }
Index: trunk/extensions/EducationProgram/specials/SpecialTerm.php
@@ -69,16 +69,20 @@
7070
7171 $out->addHTML( $this->getOutput()->parse( $term->getField( 'description' ) ) );
7272
73 - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-term-students' ) ) );
74 -
7573 $studentIds = array_map(
7674 function( EPStudent $student ) {
7775 return $student->getId();
7876 },
7977 $term->getStudents( 'id' )
8078 );
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+ }
8387 }
8488 }
8589 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -322,7 +322,6 @@
323323 'ep-enroll-not-allowed' => 'Your account is not allowed to enroll',
324324 '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]].',
325325 '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.',
327326 'ep-enroll-invalid-token' => 'The token you provided is invalid.',
328327 'ep-enroll-legend' => 'Enroll',
329328 '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 @@
331330 'ep-enroll-realname' => 'Real name (required)',
332331 'ep-enroll-invalid-name' => 'The name needs to be at least contain $1 {{PLURAL:$1|character|characters}}.',
333332 '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',
334337
335338 // Special:MyCourses
336339 'ep-mycourses-enrolled' => 'You have successfully enrolled for $1 at $2.',

Follow-up revisions

RevisionCommit summaryAuthorDate
r108918follow up to r108917, allow for not having a tokenjeroendedauw16:54, 14 January 2012
r108928follow up to r108917, added missing messagesjeroendedauw17:52, 14 January 2012

Status & tagging log