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 @@ |
49 | 49 | // Contest statuses |
50 | 50 | 'contest-status-draft' => 'Draft (disabled)', |
51 | 51 | 'contest-status-active' => 'Active (enabled)', |
| 52 | + 'contest-status-expired' => 'Expired (enabled, past end date)', |
52 | 53 | 'contest-status-finished' => 'Finished (disabled)', |
53 | 54 | |
54 | 55 | // Special page names |
Index: trunk/extensions/Contest/Contest.hooks.php |
— | — | @@ -56,7 +56,6 @@ |
57 | 57 | $testDir = dirname( __FILE__ ) . '/test/'; |
58 | 58 | |
59 | 59 | $files[] = $testDir . 'ContestValidationTests.php'; |
60 | | - $files[] = $testDir . 'ContestParseTests.php'; |
61 | 60 | |
62 | 61 | return true; |
63 | 62 | } |
Index: trunk/extensions/Contest/specials/SpecialContest.php |
— | — | @@ -102,7 +102,7 @@ |
103 | 103 | $stats = array(); |
104 | 104 | |
105 | 105 | $stats['name'] = $contest->getField( 'name' ); |
106 | | - $stats['status'] = Contest::getStatusMessage( $contest->getField( 'status' ) ); |
| 106 | + $stats['status'] = Contest::getStatusMessage( $contest->getStatus() ); |
107 | 107 | $stats['submissioncount'] = $this->getLang()->formatNum( $contest->getField( 'submission_count' ) ); |
108 | 108 | |
109 | 109 | return $stats; |
Index: trunk/extensions/Contest/specials/SpecialContests.php |
— | — | @@ -77,7 +77,7 @@ |
78 | 78 | * @since 0.1 |
79 | 79 | */ |
80 | 80 | 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' ) ); |
82 | 82 | |
83 | 83 | if ( count( $contests ) > 0 ) { |
84 | 84 | $this->displayContestsTable( $contests ); |
— | — | @@ -173,7 +173,7 @@ |
174 | 174 | else { |
175 | 175 | $contest->getField( 'name' ); |
176 | 176 | } |
177 | | - |
| 177 | + |
178 | 178 | $fields[] = Html::rawElement( |
179 | 179 | 'td', |
180 | 180 | array( 'data-sort-value' => $contest->getField( 'name' ) ), |
— | — | @@ -182,8 +182,8 @@ |
183 | 183 | |
184 | 184 | $fields[] = Html::element( |
185 | 185 | '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() ) |
188 | 188 | ); |
189 | 189 | |
190 | 190 | $fields[] = Html::element( |
Index: trunk/extensions/Contest/specials/SpecialContestSignup.php |
— | — | @@ -107,7 +107,7 @@ |
108 | 108 | $out->returnToMain(); |
109 | 109 | } |
110 | 110 | else { |
111 | | - switch ( $contest->getField( 'status' ) ) { |
| 111 | + switch ( $contest->getStatus() ) { |
112 | 112 | case Contest::STATUS_ACTIVE: |
113 | 113 | $this->showEnabledPage( $contest, $challengeId ); |
114 | 114 | break; |
— | — | @@ -117,6 +117,7 @@ |
118 | 118 | $out->returnToMain(); |
119 | 119 | break; |
120 | 120 | case Contest::STATUS_FINISHED: |
| 121 | + case Contest::STATUS_EXPIRED: |
121 | 122 | $this->showWarning( 'contest-signup-finished' ); |
122 | 123 | $out->addHTML( '<br /><br /><br /><br />' ); |
123 | 124 | $out->returnToMain(); |
Index: trunk/extensions/Contest/specials/SpecialEditContest.php |
— | — | @@ -172,7 +172,7 @@ |
173 | 173 | $fields['status'] = array ( |
174 | 174 | 'type' => 'radio', |
175 | 175 | 'label-message' => 'contest-edit-status', |
176 | | - 'options' => Contest::getStatusMessages() |
| 176 | + 'options' => Contest::getStatusMessages( $onlySettable = true ) |
177 | 177 | ); |
178 | 178 | |
179 | 179 | $fields['intro'] = array ( |
— | — | @@ -397,4 +397,4 @@ |
398 | 398 | ); |
399 | 399 | } |
400 | 400 | |
401 | | -} |
\ No newline at end of file |
| 401 | +} |
Index: trunk/extensions/Contest/specials/SpecialMyContests.php |
— | — | @@ -213,11 +213,12 @@ |
214 | 214 | $out->returnToMain(); |
215 | 215 | } |
216 | 216 | else { |
217 | | - switch ( $contest->getField( 'status' ) ) { |
| 217 | + switch ( $contest->getStatus() ) { |
218 | 218 | case Contest::STATUS_ACTIVE: |
219 | | - $this->handleEnabledPage( $contest ); |
| 219 | + $this->handleEnabledPage( $contest ); |
220 | 220 | break; |
221 | 221 | case Contest::STATUS_FINISHED: |
| 222 | + case Contest::STATUS_EXPIRED: |
222 | 223 | $this->showWarning( 'contest-submission-finished' ); |
223 | 224 | $out->addHTML( '<br /><br /><br /><br />' ); |
224 | 225 | $out->returnToMain(); |
— | — | @@ -527,4 +528,4 @@ |
528 | 529 | ); |
529 | 530 | } |
530 | 531 | |
531 | | -} |
\ No newline at end of file |
| 532 | +} |
Index: trunk/extensions/Contest/specials/SpecialContestWelcome.php |
— | — | @@ -45,10 +45,15 @@ |
46 | 46 | $out->addHTML( '<br /><br /><br /><br />' ); |
47 | 47 | $out->returnToMain(); |
48 | 48 | } |
49 | | - else if ( $contest->getField( 'status' ) !== Contest::STATUS_ACTIVE ) { |
| 49 | + else if ( ( $contest->getStatus() == Contest::STATUS_FINISHED ) || |
| 50 | + ( $contest->getStatus() == Contest::STATUS_EXPIRED ) ) { |
50 | 51 | $this->showWarning( 'contest-signup-finished' ); |
51 | 52 | $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(); |
53 | 58 | } |
54 | 59 | else { |
55 | 60 | $this->showEnabledPage( $contest ); |
Index: trunk/extensions/Contest/includes/Contest.class.php |
— | — | @@ -16,7 +16,8 @@ |
17 | 17 | // Constants representing the states a contest can have. |
18 | 18 | const STATUS_DRAFT = 0; |
19 | 19 | 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 |
21 | 22 | |
22 | 23 | /** |
23 | 24 | * List of challenges for this contest. |
— | — | @@ -172,21 +173,23 @@ |
173 | 174 | /** |
174 | 175 | * Returns a list of status messages and their corresponding constants. |
175 | 176 | * |
| 177 | + * @param boolean $onlySettable Whether to return only messages for modifiable status. |
| 178 | + * |
176 | 179 | * @since 0.1 |
177 | 180 | * |
178 | 181 | * @return array |
179 | 182 | */ |
180 | | - public static function getStatusMessages() { |
| 183 | + public static function getStatusMessages( $onlySettable = false ) { |
181 | 184 | static $map = false; |
182 | 185 | |
183 | 186 | if ( $map === false ) { |
184 | 187 | $map = array( |
185 | 188 | wfMsg( 'contest-status-draft' ) => self::STATUS_DRAFT, |
186 | 189 | wfMsg( 'contest-status-active' ) => self::STATUS_ACTIVE, |
187 | | - wfMsg( 'contest-status-finished' ) => self::STATUS_FINISHED, |
| 190 | + wfMsg( 'contest-status-finished' ) => self::STATUS_FINISHED, |
188 | 191 | ); |
189 | 192 | } |
190 | | - |
| 193 | + if (!$onlySettable) $map[wfMsg( 'contest-status-expired')] = self::STATUS_EXPIRED; |
191 | 194 | return $map; |
192 | 195 | } |
193 | 196 | |
— | — | @@ -455,4 +458,22 @@ |
456 | 459 | return (int)ceil( $this->getTimeLeft() / ( 60 * 60 * 24 ) ); |
457 | 460 | } |
458 | 461 | |
| 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 | + } |
459 | 480 | } |