r100079 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100078‎ | r100079 | r100080 >
Date:20:16, 17 October 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fix refresh issue; votes will now show up directly after making them. This is done by loading the non-id fields of the contestant only after the submission is made
Modified paths:
  • /trunk/extensions/Contest/includes/Contest.class.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestDBObject.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestant.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/specials/SpecialContestant.php
@@ -34,7 +34,7 @@
3535 return;
3636 }
3737
38 - $contestant = ContestContestant::s()->selectRow( null, array( 'id' => (int)$subPage ) );
 38+ $contestant = ContestContestant::s()->selectRow( 'id', array( 'id' => (int)$subPage ) );
3939
4040 if ( $contestant === false ) {
4141 $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() );
@@ -43,9 +43,10 @@
4444 if ( $this->getRequest()->wasPosted()
4545 && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) )
4646 {
47 - $this->handleSubmission( $contestant );
 47+ $this->handleSubmission( $contestant->getId() );
4848 }
4949
 50+ $contestant->loadFields();
5051 $this->showPage( $contestant );
5152 }
5253 }
@@ -56,17 +57,17 @@
5758 *
5859 * @since 0.1
5960 *
60 - * @param ContestContestant $contestant
 61+ * @param integer $contestantId
6162 *
6263 * @return boolean Success indicator
6364 */
64 - protected function handleSubmission( ContestContestant $contestant ) {
 65+ protected function handleSubmission( $contestantId ) {
6566 $success = true;
6667
6768 if ( trim( $this->getRequest()->getText( 'new-comment-text' ) ) !== '' ) {
6869 $comment = new ContestComment( array(
6970 'user_id' => $this->getUser()->getId(),
70 - 'contestant_id' => $contestant->getId(),
 71+ 'contestant_id' => $contestantId,
7172
7273 'text' => $this->getRequest()->getText( 'new-comment-text' ),
7374 'time' => wfTimestampNow()
@@ -82,7 +83,7 @@
8384 if ( $success && !is_null( $this->getRequest()->getVal( 'contestant-rating' ) ) ) {
8485 $attribs = array(
8586 'value' => $this->getRequest()->getInt( 'contestant-rating' ),
86 - 'contestant_id' => $contestant->getId(),
 87+ 'contestant_id' => $contestantId,
8788 'user_id' => $this->getUser()->getId()
8889 );
8990
Index: trunk/extensions/Contest/includes/ContestDBObject.php
@@ -43,6 +43,39 @@
4444
4545 $this->setFields( $fields );
4646 }
 47+
 48+ /**
 49+ * Load the specified fields from the database.
 50+ *
 51+ * @since 0.1
 52+ *
 53+ * @param array|null $fields
 54+ * @param boolean $override
 55+ *
 56+ * @return Success indicator
 57+ */
 58+ public function loadFields( $fields = null, $override = true ) {
 59+ if ( is_null( $this->getId() ) ) {
 60+ return false;
 61+ }
 62+
 63+ if ( is_null( $fields ) ) {
 64+ $fields = array_keys( $this->getFieldTypes() );
 65+ }
 66+
 67+ $results = $this->rawSelect(
 68+ $this->getPrefixedFields( $fields ),
 69+ array( $this->getPrefixedField( 'id' ) => $this->getId() ),
 70+ array( 'LIMIT' => 1 )
 71+ );
 72+
 73+ foreach ( $results as $result ) {
 74+ $this->setFields( $this->getFieldsFromDBResult( $result ), $override );
 75+ return true;
 76+ }
 77+
 78+ return false;
 79+ }
4780
4881 /**
4982 * Returns the name of the database table objects of this type are stored in.
@@ -472,15 +505,17 @@
473506 }
474507
475508 /**
476 - * Get a new instance of the class from a database result.
 509+ * Get an array with fields from a database result,
 510+ * that can be fed directly to the constructor or
 511+ * to setFields.
477512 *
478513 * @since 0.1
479514 *
480515 * @param object $result
481516 *
482 - * @return ContestDBObject
 517+ * @return array
483518 */
484 - public function newFromDBResult( $result ) {
 519+ protected function getFieldsFromDBResult( $result ) {
485520 $result = (array)$result;
486521 $data = array();
487522 $idFieldLength = strlen( $this->getFieldPrefix() );
@@ -488,9 +523,22 @@
489524 foreach ( $result as $name => $value ) {
490525 $data[substr( $name, $idFieldLength )] = $value;
491526 }
492 -
493 - return $this->newFromArray( $data );
 527+
 528+ return $data;
494529 }
 530+
 531+ /**
 532+ * Get a new instance of the class from a database result.
 533+ *
 534+ * @since 0.1
 535+ *
 536+ * @param object $result
 537+ *
 538+ * @return ContestDBObject
 539+ */
 540+ public function newFromDBResult( $result ) {
 541+ return $this->newFromArray( $this->getFieldsFromDBResult( $result ) );
 542+ }
495543
496544 /**
497545 * Removes the object from the database.
Index: trunk/extensions/Contest/includes/Contest.class.php
@@ -472,10 +472,9 @@
473473 *
474474 **/
475475 public function getStatus() {
 476+ $dbStatus = $this->getField( 'status' );
476477
477 - $dbStatus = $this->getField('status');
478 -
479 - if ( $dbStatus === self::STATUS_ACTIVE && $this->getTimeLeft() <= 0 ) {
 478+ if ( $dbStatus === self::STATUS_ACTIVE && $this->getTimeLeft() <= 0 ) {
480479 return self::STATUS_EXPIRED;
481480 } else {
482481 return $dbStatus;

Status & tagging log