r99958 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99957‎ | r99958 | r99959 >
Date:17:47, 16 October 2011
Author:erik
Status:resolved (Comments)
Tags:
Comment:
* Actually implement contest expiry. When a contest is active
but expired, it will return the new expired status.
* Remove failing test for function which was removed.
Modified paths:
  • /trunk/extensions/Contest/Contest.hooks.php (modified) (history)
  • /trunk/extensions/Contest/Contest.i18n.php (modified) (history)
  • /trunk/extensions/Contest/includes/Contest.class.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContest.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestSignup.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestWelcome.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContests.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialEditContest.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialMyContests.php (modified) (history)
  • /trunk/extensions/Contest/test/ContestParseTests.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/Contest/test/ContestParseTests.php
@@ -1,41 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Contest parse tests cases.
6 - *
7 - * @ingroup Contest
8 - * @since 0.1
9 - *
10 - * @licence GNU GPL v3
11 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
12 - */
13 -class ContestParseTests extends MediaWikiTestCase {
14 -
15 - /**
16 - * Tests @see ContestUtils::replaceRelativeLinks
17 - */
18 - public function testLinkReplacing() {
19 - $tests = array(
20 - '[[Foo|Bar]]' => '[' . Title::newFromText( 'Foo' )->getFullUrl() . ' Bar]',
21 - '[[Foo|Foo]]' => '[' . Title::newFromText( 'Foo' )->getFullUrl() . ' Foo]',
22 - '[[MediaWiki:Foo|Foo]]' => '[' . Title::newFromText( 'MediaWiki:Foo' )->getFullUrl() . ' Foo]',
23 - '[[Foo bar|ohai there]]' => '[' . Title::newFromText( 'Foo bar' )->getFullUrl() . ' ohai there]',
24 -
25 - '[[Foo]]' => '[' . Title::newFromText( 'Foo' )->getFullUrl() . ' Foo]',
26 - '[[MediaWiki:Foo]]' => '[' . Title::newFromText( 'MediaWiki:Foo' )->getFullUrl() . ' MediaWiki:Foo]',
27 - '[[Foo bar]]' => '[' . Title::newFromText( 'Foo bar' )->getFullUrl() . ' Foo bar]',
28 -
29 - 'This should [not be altered!' => 'This should [not be altered!',
30 - "This''' should [not be alt/\\|ered!'''" => "This''' should [not be alt/\\|ered!'''",
31 - '[http://foo.bar/wiki/Baz O_o]' => '[http://foo.bar/wiki/Baz O_o]',
32 - );
33 -
34 - foreach ( $tests as $source => $target ) {
35 - $this->assertEquals(
36 - $target,
37 - ContestUtils::replaceRelativeLinks( $source )
38 - );
39 - }
40 - }
41 -
42 -}
Index: trunk/extensions/Contest/Contest.i18n.php
@@ -48,6 +48,7 @@
4949 // Contest statuses
5050 'contest-status-draft' => 'Draft (disabled)',
5151 'contest-status-active' => 'Active (enabled)',
 52+ 'contest-status-expired' => 'Expired (enabled, past end date)',
5253 'contest-status-finished' => 'Finished (disabled)',
5354
5455 // Special page names
Index: trunk/extensions/Contest/Contest.hooks.php
@@ -56,7 +56,6 @@
5757 $testDir = dirname( __FILE__ ) . '/test/';
5858
5959 $files[] = $testDir . 'ContestValidationTests.php';
60 - $files[] = $testDir . 'ContestParseTests.php';
6160
6261 return true;
6362 }
Index: trunk/extensions/Contest/specials/SpecialContest.php
@@ -102,7 +102,7 @@
103103 $stats = array();
104104
105105 $stats['name'] = $contest->getField( 'name' );
106 - $stats['status'] = Contest::getStatusMessage( $contest->getField( 'status' ) );
 106+ $stats['status'] = Contest::getStatusMessage( $contest->getStatus() );
107107 $stats['submissioncount'] = $this->getLang()->formatNum( $contest->getField( 'submission_count' ) );
108108
109109 return $stats;
Index: trunk/extensions/Contest/specials/SpecialContests.php
@@ -77,7 +77,7 @@
7878 * @since 0.1
7979 */
8080 protected function displayContests() {
81 - $contests = Contest::s()->select( array( 'id', 'name', 'status', 'submission_count' ) );
 81+ $contests = Contest::s()->select( array( 'id', 'name', 'status', 'end', 'submission_count' ) );
8282
8383 if ( count( $contests ) > 0 ) {
8484 $this->displayContestsTable( $contests );
@@ -173,7 +173,7 @@
174174 else {
175175 $contest->getField( 'name' );
176176 }
177 -
 177+
178178 $fields[] = Html::rawElement(
179179 'td',
180180 array( 'data-sort-value' => $contest->getField( 'name' ) ),
@@ -182,8 +182,8 @@
183183
184184 $fields[] = Html::element(
185185 'td',
186 - array( 'data-sort-value' => $contest->getField( 'status' ) ),
187 - Contest::getStatusMessage( $contest->getField( 'status' ) )
 186+ array( 'data-sort-value' => $contest->getStatus() ),
 187+ Contest::getStatusMessage( $contest->getStatus() )
188188 );
189189
190190 $fields[] = Html::element(
Index: trunk/extensions/Contest/specials/SpecialContestSignup.php
@@ -107,7 +107,7 @@
108108 $out->returnToMain();
109109 }
110110 else {
111 - switch ( $contest->getField( 'status' ) ) {
 111+ switch ( $contest->getStatus() ) {
112112 case Contest::STATUS_ACTIVE:
113113 $this->showEnabledPage( $contest, $challengeId );
114114 break;
@@ -117,6 +117,7 @@
118118 $out->returnToMain();
119119 break;
120120 case Contest::STATUS_FINISHED:
 121+ case Contest::STATUS_EXPIRED:
121122 $this->showWarning( 'contest-signup-finished' );
122123 $out->addHTML( '<br /><br /><br /><br />' );
123124 $out->returnToMain();
Index: trunk/extensions/Contest/specials/SpecialEditContest.php
@@ -172,7 +172,7 @@
173173 $fields['status'] = array (
174174 'type' => 'radio',
175175 'label-message' => 'contest-edit-status',
176 - 'options' => Contest::getStatusMessages()
 176+ 'options' => Contest::getStatusMessages( $onlySettable = true )
177177 );
178178
179179 $fields['intro'] = array (
@@ -397,4 +397,4 @@
398398 );
399399 }
400400
401 -}
\ No newline at end of file
 401+}
Index: trunk/extensions/Contest/specials/SpecialMyContests.php
@@ -213,11 +213,12 @@
214214 $out->returnToMain();
215215 }
216216 else {
217 - switch ( $contest->getField( 'status' ) ) {
 217+ switch ( $contest->getStatus() ) {
218218 case Contest::STATUS_ACTIVE:
219 - $this->handleEnabledPage( $contest );
 219+ $this->handleEnabledPage( $contest );
220220 break;
221221 case Contest::STATUS_FINISHED:
 222+ case Contest::STATUS_EXPIRED:
222223 $this->showWarning( 'contest-submission-finished' );
223224 $out->addHTML( '<br /><br /><br /><br />' );
224225 $out->returnToMain();
@@ -527,4 +528,4 @@
528529 );
529530 }
530531
531 -}
\ No newline at end of file
 532+}
Index: trunk/extensions/Contest/specials/SpecialContestWelcome.php
@@ -45,10 +45,15 @@
4646 $out->addHTML( '<br /><br /><br /><br />' );
4747 $out->returnToMain();
4848 }
49 - else if ( $contest->getField( 'status' ) !== Contest::STATUS_ACTIVE ) {
 49+ else if ( ( $contest->getStatus() == Contest::STATUS_FINISHED ) ||
 50+ ( $contest->getStatus() == Contest::STATUS_EXPIRED ) ) {
5051 $this->showWarning( 'contest-signup-finished' );
5152 $out->addHTML( '<br /><br /><br /><br />' );
52 - $out->returnToMain();
 53+ $out->returnToMain();
 54+ } else if ( $contest->getStatus() == Contest::STATUS_DRAFT ) {
 55+ $this->showWarning( 'contest-signup-draft' );
 56+ $out->addHTML( '<br /><br /><br /><br />' );
 57+ $out->returnToMain();
5358 }
5459 else {
5560 $this->showEnabledPage( $contest );
Index: trunk/extensions/Contest/includes/Contest.class.php
@@ -16,7 +16,8 @@
1717 // Constants representing the states a contest can have.
1818 const STATUS_DRAFT = 0;
1919 const STATUS_ACTIVE = 1;
20 - const STATUS_FINISHED = 2;
 20+ const STATUS_FINISHED = 2; // manually stopped by contest manager
 21+ const STATUS_EXPIRED = 3; // past configured contest end date
2122
2223 /**
2324 * List of challenges for this contest.
@@ -172,21 +173,23 @@
173174 /**
174175 * Returns a list of status messages and their corresponding constants.
175176 *
 177+ * @param boolean $onlySettable Whether to return only messages for modifiable status.
 178+ *
176179 * @since 0.1
177180 *
178181 * @return array
179182 */
180 - public static function getStatusMessages() {
 183+ public static function getStatusMessages( $onlySettable = false ) {
181184 static $map = false;
182185
183186 if ( $map === false ) {
184187 $map = array(
185188 wfMsg( 'contest-status-draft' ) => self::STATUS_DRAFT,
186189 wfMsg( 'contest-status-active' ) => self::STATUS_ACTIVE,
187 - wfMsg( 'contest-status-finished' ) => self::STATUS_FINISHED,
 190+ wfMsg( 'contest-status-finished' ) => self::STATUS_FINISHED,
188191 );
189192 }
190 -
 193+ if (!$onlySettable) $map[wfMsg( 'contest-status-expired')] = self::STATUS_EXPIRED;
191194 return $map;
192195 }
193196
@@ -455,4 +458,22 @@
456459 return (int)ceil( $this->getTimeLeft() / ( 60 * 60 * 24 ) );
457460 }
458461
 462+ /*
 463+ * Gets the contest status, which is either expired, or whatever the
 464+ * contest administrator has manually set it to. Only active contests will
 465+ * be evaluated for expiry.
 466+ *
 467+ * @return integer status constant
 468+ *
 469+ **/
 470+ public function getStatus() {
 471+
 472+ $dbStatus = $this->getField('status');
 473+
 474+ if ( $dbStatus === self::STATUS_ACTIVE && $this->getTimeLeft() <= 0 ) {
 475+ return self::STATUS_EXPIRED;
 476+ } else {
 477+ return $dbStatus;
 478+ }
 479+ }
459480 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r100070Follow up to r99958;jeroendedauw19:31, 17 October 2011

Comments

#Comment by Jeroen De Dauw (talk | contribs)   19:33, 17 October 2011

I was thinking of implementing something that would automatically set the status to finished on deadline, but this also works :)

Status & tagging log