r108309 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108308‎ | r108309 | r108310 >
Date:09:08, 7 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed issue occuring when validation failed for a new item. got to love htmlform
Modified paths:
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTerm.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEditInstitution.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialEditInstitution.php
@@ -72,7 +72,7 @@
7373 * @return string|true
7474 */
7575 public function countryIsValid( $value, array $alldata = null ) {
76 - $countries = array_keys( CountryNames::getNames( $this->getLang()->getCode() ) );
 76+ $countries = array_keys( CountryNames::getNames( $this->getLanguage()->getCode() ) );
7777
7878 if ( $this->isNew() ) {
7979 array_unshift( $countries, '' );
Index: trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php
@@ -149,7 +149,8 @@
150150 static $isNew = null;
151151
152152 if ( is_null( $isNew ) ) {
153 - $isNew = $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'newEditToken' ) );
 153+ $isNew = $this->getRequest()->wasPosted() &&
 154+ ( $this->getRequest()->getCheck( 'isnew' ) || $this->getRequest()->getCheck( 'wpisnew' ) );
154155 }
155156
156157 return $isNew;
@@ -163,7 +164,7 @@
164165 protected function showForm() {
165166 $form = $this->getForm();
166167
167 - if ( $this->isNew() ) {
 168+ if ( $this->getRequest()->wasPosted() && $this->getRequest()->getCheck( 'isnew' ) ) {
168169 $form->prepareForm();
169170 $form->displayForm( Status::newGood() );
170171 }
@@ -204,8 +205,17 @@
205206 * @return HTMLForm|null
206207 */
207208 protected function getForm() {
208 - $form = new HTMLForm( $this->getFormFields(), $this->getContext() );
 209+ $fields = $this->getFormFields();
209210
 211+ if ( $this->isNew() ) {
 212+ $fields['isnew'] = array(
 213+ 'type' => 'hidden',
 214+ 'default' => 1
 215+ );
 216+ }
 217+
 218+ $form = new HTMLForm( $fields, $this->getContext() );
 219+
210220 $form->setSubmitCallback( array( $this, 'handleSubmission' ) );
211221 $form->setSubmitText( wfMsg( 'educationprogram-org-submit' ) );
212222
@@ -239,12 +249,14 @@
240250 $fields = array();
241251
242252 $fields['id'] = array( 'type' => 'hidden' );
243 -
 253+
 254+ $req = $this->getRequest();
 255+
244256 // This sort of sucks as well. Meh, HTMLForm is odd.
245 - if ( $this->getRequest()->wasPosted()
246 - && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) )
247 - && $this->getRequest()->getCheck( 'wpitem-id' ) ) {
248 - $fields['id']['default'] = $this->getRequest()->getInt( 'wpitem-id' );
 257+ if ( $req->wasPosted()
 258+ && $this->getUser()->matchEditToken( $req->getVal( 'wpEditToken' ) )
 259+ && $req->getCheck( 'wpitem-id' ) ) {
 260+ $fields['id']['default'] = $req->getInt( 'wpitem-id' );
249261 }
250262
251263 return $fields;
@@ -272,7 +284,7 @@
273285 $mappedFields = array();
274286
275287 foreach ( $fields as $name => $field ) {
276 - if ( $this->isNew() ) {
 288+ if ( $this->getRequest()->getCheck( 'isnew' ) ) {
277289 // HTML form is being a huge pain in running the validation on post,
278290 // so just remove it if when not appropriate.
279291 unset( $field['validation-callback'] );
@@ -326,7 +338,7 @@
327339 $matches = array();
328340
329341 if ( preg_match( '/item-(.+)/', $name, $matches ) ) {
330 - if ( $matches[1] === 'id' && $value === '' ) {
 342+ if ( $matches[1] === 'id' && ( $value === '' || $value === '0' ) ) {
331343 $value = null;
332344 }
333345
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -233,7 +233,7 @@
234234 'submit'
235235 ) );
236236
237 - $out->addHTML( Html::hidden( 'newEditToken', $context->getUser()->editToken() ) );
 237+ $out->addHTML( Html::hidden( 'isnew', 1 ) );
238238
239239 $out->addHTML( '</fieldset></form>' );
240240
Index: trunk/extensions/EducationProgram/includes/EPTerm.php
@@ -229,7 +229,7 @@
230230 'submit'
231231 ) );
232232
233 - $out->addHTML( Html::hidden( 'newEditToken', $context->getUser()->editToken() ) );
 233+ $out->addHTML( Html::hidden( 'isnew', 1 ) );
234234
235235 $out->addHTML( '</fieldset></form>' );
236236
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -213,7 +213,7 @@
214214 'submit'
215215 ) );
216216
217 - $out->addHTML( Html::hidden( 'newEditToken', $context->getUser()->editToken() ) );
 217+ $out->addHTML( Html::hidden( 'isnew', 1 ) );
218218
219219 $out->addHTML( '</fieldset></form>' );
220220

Status & tagging log