r106700 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106699‎ | r106700 | r106701 >
Date:21:04, 19 December 2011
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
added missing error messages and made some tweaks
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEditCourse.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php
@@ -279,7 +279,10 @@
280280 */
281281 public function handleSubmission( array $data ) {
282282 $fields = array();
 283+ $unknownValues = array();
283284
 285+ $c = $this->itemClass; // Yeah, this is needed in PHP 5.3 >_>
 286+
284287 foreach ( $data as $name => $value ) {
285288 $matches = array();
286289
@@ -288,13 +291,22 @@
289292 $value = null;
290293 }
291294
292 - $fields[$matches[1]] = $value;
 295+ if ( $c::canHasField( $matches[1] ) ) {
 296+ $fields[$matches[1]] = $value;
 297+ }
 298+ else {
 299+ $unknownValues[$matches[1]] = $value;
 300+ }
293301 }
294302 }
295303
296 - $c = $this->itemClass; // Yeah, this is needed in PHP 5.3 >_>
 304+
297305 /* EPDBObject */ $item = new $c( $fields, is_null( $fields['id'] ) );
298306
 307+ foreach ( $unknownValues as $name => $value ) {
 308+
 309+ }
 310+
299311 $success = $item->writeToDB();
300312
301313 if ( $success ) {
@@ -305,4 +317,17 @@
306318 }
307319 }
308320
 321+ /**
 322+ * Gets called for evey unknown submitted value, so they can be dealth with if needed.
 323+ *
 324+ * @since 0.1
 325+ *
 326+ * @param EPDBObject $item
 327+ * @param string $name
 328+ * @param string $value This is a string, since it comes from request data, but might be a number or other type.
 329+ */
 330+ protected function handleUnknownField( EPDBObject $item, $name, $value ) {
 331+ // Override to use.
 332+ }
 333+
309334 }
Index: trunk/extensions/EducationProgram/specials/SpecialEditCourse.php
@@ -35,19 +35,19 @@
3636 'label-message' => 'ep-course-edit-name',
3737 'required' => true,
3838 'validation-callback' => function ( $value, array $alldata = null ) {
39 - return strlen( $value ) < 5 ? wfMsg( 'ep-course-invalid-name' ) : true;
 39+ return strlen( $value ) < 5 ? wfMsgExt( 'ep-course-invalid-name', 'parsemag', 5 ) : true;
4040 },
4141 );
4242
4343 $orgOptions = EPOrg::getOrgOptions( EPOrg::getEditableOrgs( $this->getUser() ) );
4444
45 - $fields['org'] = array (
 45+ $fields['org_id'] = array (
4646 'type' => 'select',
4747 'label-message' => 'ep-course-edit-org',
4848 'required' => true,
4949 'options' => $orgOptions,
50 - 'validation-callback' => function ( $value, array $alldata = null ) {
51 - return strlen( $value ) < 10 ? wfMsg( 'ep-course-invalid-description' ) : true;
 50+ 'validation-callback' => function ( $value, array $alldata = null ) use ( $orgOptions ) {
 51+ return in_array( (int)$value, array_values( $orgOptions ) ) ? true : wfMsg( 'ep-course-invalid-org' );
5252 },
5353 'default' => array_shift( $orgOptions )
5454 );
@@ -57,7 +57,7 @@
5858 'label-message' => 'ep-course-edit-description',
5959 'required' => true,
6060 'validation-callback' => function ( $value, array $alldata = null ) {
61 - return strlen( $value ) < 10 ? wfMsg( 'ep-course-invalid-description' ) : true;
 61+ return strlen( $value ) < 10 ? wfMsgExt( 'ep-course-invalid-description', 'parsemag', 10 ) : true;
6262 },
6363 'default' => '',
6464 'rows' => 5
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -114,6 +114,10 @@
115115 'ep-course-edit-org' => 'Institution',
116116 'ep-course-edit-description' => 'Description',
117117
 118+ 'ep-course-invalid-name' => 'This name is to short. It needs to be at least contain $1 {{PLURAL:$1|character|characters}}.',
 119+ 'ep-course-invalid-description' => 'This description is to short. It needs to be at least contain $1 {{PLURAL:$1|character|characters}}.',
 120+ 'ep-course-invalid-org' => 'This institution does not exist',
 121+
118122 );
119123
120124 /** Message documentation (Message documentation)

Status & tagging log