r110244 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110243‎ | r110244 | r110245 >
Date:15:05, 29 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixes and htmlform love
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPEditAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EditCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPFailForm.php (added) (history)
  • /trunk/extensions/EducationProgram/resources/ep.addcourse.js (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -93,6 +93,7 @@
9494 $wgAutoloadClasses['EPRevision'] = dirname( __FILE__ ) . '/includes/EPRevision.php';
9595 $wgAutoloadClasses['EPRevisionPager'] = dirname( __FILE__ ) . '/includes/EPRevisionPager.php';
9696 $wgAutoloadClasses['EPPageObject'] = dirname( __FILE__ ) . '/includes/EPPageObject.php';
 97+$wgAutoloadClasses['EPFailForm'] = dirname( __FILE__ ) . '/includes/EPFailForm.php';
9798
9899 $wgAutoloadClasses['CoursePage'] = dirname( __FILE__ ) . '/pages/CoursePage.php';
99100 $wgAutoloadClasses['EPPage'] = dirname( __FILE__ ) . '/pages/EPPage.php';
Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
@@ -26,28 +26,7 @@
2727 $this->displayNavigation();
2828
2929 if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
30 - $out->addWikiMsg( 'ep-course-create', $name );
31 -
32 - $bracketPos = strpos( $name, '(' );
33 -
34 - if ( $bracketPos !== false ) {
35 - if ( $bracketPos > 0 && in_array( $name{$bracketPos - 1}, array( ' ', '_' ) ) ) {
36 - $bracketPos -= 1;
37 - }
38 -
39 - $newName = substr( $name, 0, $bracketPos );
40 - }
41 -
42 - EPCourse::displayAddNewRegion(
43 - $this->getContext(),
44 - array(
45 - 'name' => $this->getRequest()->getText(
46 - 'newname',
47 - $newName
48 - ),
49 - 'term' => $this->getRequest()->getText( 'newterm', '' ),
50 - )
51 - );
 30+ $out->redirect( $this->getTitle()->getLocalURL( array( 'action' => 'edit' ) ) );
5231 }
5332 else {
5433 $out->addWikiMsg( 'ep-course-none', $name );
Index: trunk/extensions/EducationProgram/actions/EditCourseAction.php
@@ -14,7 +14,36 @@
1515 public function onView() {
1616 $this->getOutput()->addModules( array( 'ep.datepicker', 'ep.combobox' ) );
1717
18 - return parent::onView();
 18+ $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_>
 19+
 20+ if ( !$this->isNewPost() && !$c::hasIdentifier( $this->getTitle()->getText() ) ) {
 21+ $name = $this->getTitle()->getText();
 22+ $bracketPos = strpos( $name, '(' );
 23+
 24+ if ( $bracketPos !== false ) {
 25+ if ( $bracketPos > 0 && in_array( $name{$bracketPos - 1}, array( ' ', '_' ) ) ) {
 26+ $bracketPos -= 1;
 27+ }
 28+
 29+ $name = substr( $name, 0, $bracketPos );
 30+ }
 31+
 32+ EPCourse::displayAddNewRegion(
 33+ $this->getContext(),
 34+ array(
 35+ 'name' => $this->getRequest()->getText(
 36+ 'newname',
 37+ $name
 38+ ),
 39+ 'term' => $this->getRequest()->getText( 'newterm', '' ),
 40+ )
 41+ );
 42+
 43+ return '';
 44+ }
 45+ else {
 46+ return parent::onView();
 47+ }
1948 }
2049
2150 protected function getItemClass() {
@@ -142,17 +171,19 @@
143172 * @see SpecialEPFormPage::getNewData()
144173 */
145174 protected function getNewData() {
146 - return array(
147 - 'org_id' => $this->getRequest()->getVal( 'neworg' ),
148 - 'name' => wfMsgExt(
149 - 'ep-course-edit-name-format',
150 - 'parsemag',
151 - $this->getRequest()->getVal( 'newname' ),
152 - $this->getRequest()->getVal( 'newterm' )
153 - ),
154 - 'term' => $this->getRequest()->getVal( 'newterm' ),
155 - 'mc' => $this->getRequest()->getVal( 'newname' ),
 175+ $data = parent::getNewData();
 176+
 177+ $data['org_id'] = $this->getRequest()->getVal( 'neworg' );
 178+ $data['name'] = wfMsgExt(
 179+ 'ep-course-edit-name-format',
 180+ 'parsemag',
 181+ $data['name'],
 182+ $this->getRequest()->getVal( 'newterm' )
156183 );
 184+ $data['term'] = $this->getRequest()->getVal( 'newterm' );
 185+ $data['mc'] = $data['name'];
 186+
 187+ return $data;
157188 }
158189
159190 /**
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php
@@ -16,6 +16,7 @@
1717 $this->getOutput()->addModules( 'ep.formpage' );
1818
1919 if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) {
 20+
2021 $this->showForm();
2122 }
2223 else {
@@ -155,8 +156,10 @@
156157 );
157158 }
158159
159 - $form = new HTMLForm( $fields, $this->getContext() );
 160+ $form = new EPFailForm( $fields, $this->getContext() );
160161
 162+ $form->setQuery( array( 'action' => 'edit' ) );
 163+
161164 $form->setSubmitCallback( array( $this, 'handleSubmission' ) );
162165 $form->setSubmitText( wfMsg( 'educationprogram-org-submit' ) );
163166 $form->setSubmitTooltip( 'ep-form-save' );
Index: trunk/extensions/EducationProgram/includes/EPFailForm.php
@@ -0,0 +1,51 @@
 2+<?php
 3+
 4+/**
 5+ * I so love HTMLForm.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPFailForm.php
 10+ * @ingroup EducationProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPFailForm extends HTMLForm {
 16+
 17+ /**
 18+ * Wrap the form innards in an actual <form> element
 19+ * @param $html String HTML contents to wrap.
 20+ * @return String wrapped HTML.
 21+ */
 22+ function wrapForm( $html ) {
 23+
 24+ # Include a <fieldset> wrapper for style, if requested.
 25+ if ( $this->mWrapperLegend !== false ) {
 26+ $html = Xml::fieldset( $this->mWrapperLegend, $html );
 27+ }
 28+ # Use multipart/form-data
 29+ $encType = $this->mUseMultipart
 30+ ? 'multipart/form-data'
 31+ : 'application/x-www-form-urlencoded';
 32+ # Attributes
 33+ $attribs = array(
 34+ 'action' => $this->getTitle()->getFullURL( $this->query ),
 35+ 'method' => $this->mMethod,
 36+ 'class' => 'visualClear',
 37+ 'enctype' => $encType,
 38+ );
 39+ if ( !empty( $this->mId ) ) {
 40+ $attribs['id'] = $this->mId;
 41+ }
 42+
 43+ return Html::rawElement( 'form', $attribs, $html );
 44+ }
 45+
 46+ protected $query = array();
 47+
 48+ public function setQuery( array $query ) {
 49+ $this->query = $query;
 50+ }
 51+
 52+}
\ No newline at end of file
Property changes on: trunk/extensions/EducationProgram/includes/EPFailForm.php
___________________________________________________________________
Added: svn:eol-style
153 + native
Index: trunk/extensions/EducationProgram/resources/ep.addcourse.js
@@ -20,6 +20,18 @@
2121 );
2222 } );
2323
 24+ var list = [ 'neworg', 'newname', 'newterm' ];
 25+
 26+ for ( i in list ) {
 27+ if ( list.hasOwnProperty( i ) ) {
 28+ var $element = $( '#' + list[i] ),
 29+ val = $element.val();
 30+
 31+ $element.removeAttr( 'value' );
 32+ $element.val( val );
 33+ }
 34+ }
 35+
2436 $( '.ep-course-add' ).removeAttr( 'disabled' );
2537
2638 } );

Status & tagging log