r108624 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108623‎ | r108624 | r108625 >
Date:15:26, 11 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on enrollment form
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTermPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEnroll.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php
@@ -33,7 +33,7 @@
3434 *
3535 * @since 0.1
3636 *
37 - * @param string $arg
 37+ * @param string $subPage
3838 */
3939 public function execute( $subPage ) {
4040 parent::execute( $subPage );
@@ -63,22 +63,30 @@
6464
6565 if ( $this->getUser()->isLoggedIn() ) {
6666 if ( $this->getUser()->isAllowed( 'epstudent' ) ) {
67 - $this->showEnrollmentForm( $term );
 67+ $user = $this->getUser();
 68+ $hasFields = trim( $user->getRealName() ) !== '' || $user->getOption( 'gender' ) !== 'unknown';
 69+
 70+ if ( $hasFields ) {
 71+ $this->showEnrollmentForm( $term );
 72+ }
 73+ else {
 74+
 75+ }
6876 }
6977 else {
7078 $this->showWarning( wfMessage( 'ep-enroll-not-allowed' ) );
7179 }
7280 }
7381 else {
74 - $this->showSignupLink( $term );
 82+ $this->showSignupLink();
7583 }
7684 }
7785 }
7886 }
7987
8088 /**
 89+ * Set the page title.
8190 *
82 - *
8391 * @since 0.1
8492 *
8593 * @param EPTerm $term
@@ -93,13 +101,11 @@
94102 }
95103
96104 /**
 105+ * Show links to signup.
97106 *
98 - *
99 - * @param EPTerm $term
100 - *
101107 * @since 0.1
102108 */
103 - protected function showSignupLink( EPTerm $term ) {
 109+ protected function showSignupLink() {
104110 $out = $this->getOutput();
105111
106112 $out->addWikiMsg( 'ep-enroll-login-first' );
@@ -129,15 +135,30 @@
130136
131137 $out->addHTML( '</li></ul>' );
132138 }
 139+
 140+ /**
 141+ * Just enroll the user in the term. This is useful when
 142+ * there are no things for the user to fill out in the
 143+ * enrollment form, making that step not needed.
 144+ *
 145+ * @since 0.1
 146+ *
 147+ * @param EPTerm $term
 148+ */
 149+ protected function autoEnroll( EPTerm $term ) {
 150+ // TODO
 151+ }
133152
134153 /**
 154+ * Create and display the enrollment form.
135155 *
136 - *
137156 * @since 0.1
138157 *
139158 * @param EPTerm $term
140159 */
141160 protected function showEnrollmentForm( EPTerm $term ) {
 161+ $this->getOutput()->addWikiMsg( 'ep-enroll-header' );
 162+
142163 $form = new HTMLForm( $this->getFormFields(), $this->getContext() );
143164
144165 $form->setSubmitCallback( array( $this, 'handleSubmission' ) );
@@ -150,8 +171,8 @@
151172 }
152173
153174 /**
 175+ * Returns the definitions for the fields of the signup form.
154176 *
155 - *
156177 * @since 0.1
157178 *
158179 * @return array
@@ -159,11 +180,41 @@
160181 protected function getFormFields() {
161182 $fields = array();
162183
 184+ $user = $this->getUser();
 185+
163186 $fields['enroll'] = array(
164187 'type' => 'hidden',
165188 'default' => 1
166189 );
167190
 191+ if ( trim( $user->getRealName() ) === '' ) {
 192+ $fields['realname'] = array(
 193+ 'type' => 'text',
 194+ 'default' => '',
 195+ 'label-message' => 'ep-enroll-realname',
 196+ 'required' => true,
 197+ 'validation-callback' => function( $value, array $alldata = null ) {
 198+ return strlen( $value ) < 2 ? wfMsgExt( 'ep-enroll-invalid-name', 'parsemag', 2 ) : true;
 199+ }
 200+ );
 201+ }
 202+
 203+ if ( $user->getOption( 'gender' ) === 'unknown' ) {
 204+ $fields['gender'] = array(
 205+ 'type' => 'select',
 206+ 'default' => 'unknown',
 207+ 'label-message' => 'ep-enroll-gender',
 208+ 'validation-callback' => function( $value, array $alldata = null ) {
 209+ return strlen( $value ) < 2 ? wfMsg( 'ep-enroll-invalid-gender' ) : true;
 210+ },
 211+ 'options' => array(
 212+ wfMsg( 'gender-male' ) => 'male',
 213+ wfMsg( 'gender-female' ) => 'female',
 214+ wfMsg( 'gender-unknown' ) => 'unknown',
 215+ )
 216+ );
 217+ }
 218+
168219 return $fields;
169220 }
170221
Index: trunk/extensions/EducationProgram/includes/EPTermPager.php
@@ -74,7 +74,7 @@
7575 );
7676 break;
7777 case 'year':
78 - $value = htmlspecialchars( $value );
 78+ $value = htmlspecialchars( $this->getLanguage()->formatNum( $value, true ) );
7979 break;
8080 case 'start': case 'end':
8181 $value = htmlspecialchars( $this->getLanguage()->date( $value ) );
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -265,6 +265,7 @@
266266 'ep-enroll-no-token' => 'You need to provide the token needed to enroll for this term.',
267267 'ep-enroll-invalid-token' => 'The token you provided is invalid.',
268268 'ep-enroll-legend' => 'Enroll',
 269+ '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.',
269270
270271 // Special:MyCourses
271272 'ep-mycourses-enrolled' => 'You have successfully enrolled for $1 at $2.',

Status & tagging log