r111582 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111581‎ | r111582 | r111583 >
Date:20:49, 15 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
finished up disenroll form
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPageObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialDisenroll.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php
@@ -49,7 +49,12 @@
5050 if ( $this->getUser()->isLoggedIn() ) {
5151 $req = $this->getRequest();
5252
53 - if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'disenrollEditToken' ) ) ) {
 53+ $editTokenMatches = $this->getUser()->matchEditToken(
 54+ $req->getText( 'disenrollToken' ),
 55+ $this->getTitle( $this->subPage )->getLocalURL()
 56+ );
 57+
 58+ if ( $req->wasPosted() && $editTokenMatches ) {
5459 $this->doDisenroll( $course );
5560 }
5661 else {
@@ -127,24 +132,24 @@
128133
129134 $out->addHTML( '<br />' );
130135
131 - $out->addElement(
132 - 'button',
133 - array(
134 - 'class' => 'ep-disenroll-cancel',
135 - ),
136 - wfMsg( 'ep-disenroll-cancel' )
137 - );
138 -
139136 $out->addHTML( Html::input(
140137 'disenroll',
141138 wfMsg( 'ep-disenroll-button' ),
142139 'submit',
143140 array(
144141 'class' => 'ep-disenroll',
145 - 'target-url' => '', // TODO
146142 )
147143 ) );
148144
 145+ $out->addElement(
 146+ 'button',
 147+ array(
 148+ 'class' => 'ep-disenroll-cancel',
 149+ 'target-url' => $course->getTitle()->getLocalURL(),
 150+ ),
 151+ wfMsg( 'ep-disenroll-cancel' )
 152+ );
 153+
149154 $out->addHTML( Html::hidden( 'disenrollToken', $this->getUser()->getEditToken( $target ) ) );
150155
151156 $out->addHTML( '</form>' );
@@ -158,7 +163,20 @@
159164 * @param EPCourse $course
160165 */
161166 protected function doDisenroll( EPCourse $course ) {
162 - // TODO
 167+ $success = $course->unenlistUsers(
 168+ $this->getUser()->getId(),
 169+ 'student',
 170+ $this->getRequest()->getText( 'summary' )
 171+ );
 172+
 173+ if ( $success ) {
 174+ $this->showSuccess( wfMessage( 'ep-disenroll-success' ) );
 175+ }
 176+ else {
 177+ $this->showError( wfMessage( 'ep-disenroll-fail' ) );
 178+ }
 179+
 180+ $this->getOutput()->addWikiMsg( 'ep-disenroll-returnto', $course->getField( 'name' ) );
163181 }
164182
165183 }
Index: trunk/extensions/EducationProgram/includes/EPPageObject.php
@@ -17,6 +17,13 @@
1818 return $this->getField( $this->table->getIdentifierField() );
1919 }
2020
 21+ /**
 22+ *
 23+ *
 24+ * @since 0.1
 25+ *
 26+ * @return Title
 27+ */
2128 public function getTitle() {
2229 return $this->table->getTitleFor( $this->getIdentifier() );
2330 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -451,6 +451,9 @@
452452 'ep-disenroll-button' => 'Disenroll',
453453 'ep-disenroll-summary' => 'Why are you disenrolling?',
454454 'ep-disenroll-cancel' => 'Cancel',
 455+ 'ep-disenroll-fail' => 'Something went wrong - could not disenroll you from this course.',
 456+ 'ep-disenroll-success' => 'You have been successfully disenrolled from this course!',
 457+ 'ep-disenroll-returnto' => 'Return to [[Course:$1|course $1]].',
455458
456459 // Special:MyCourses
457460 'ep-mycourses-enrolled' => 'You have successfully enrolled for $1 at $2.',

Status & tagging log