r99491 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99490‎ | r99491 | r99492 >
Date:16:38, 11 October 2011
Author:jeroendedauw
Status:ok
Tags:
Comment:
initial work on special:mycontests
Modified paths:
  • /trunk/extensions/Contest/Contest.alias.php (modified) (history)
  • /trunk/extensions/Contest/Contest.i18n.php (modified) (history)
  • /trunk/extensions/Contest/Contest.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestContestant.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestDBObject.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialMyContests.php (added) (history)

Diff [purge]

Index: trunk/extensions/Contest/Contest.i18n.php
@@ -180,6 +180,11 @@
181181 // Emails
182182 'contest-email-signup-title' => 'Thanks for joining the challenge!',
183183 'contest-email-reminder-title' => 'Only $1 {{PLURAL:$1|day|days}} until the end of the challenge!',
 184+
 185+ // Special:MyContests
 186+ 'contest-mycontests-no-contests' => 'You are not participating in any contest.',
 187+ 'contest-mycontests-active-header' => 'Running contests',
 188+ 'contest-mycontests-finished-header' => 'Passed contests',
184189 );
185190
186191 /** Message documentation (Message documentation)
Index: trunk/extensions/Contest/Contest.alias.php
@@ -23,4 +23,5 @@
2424 'ContestSubmission' => array( 'ContestSubmission' ),
2525 'ContestWelcome' => array( 'ContestWelcome' ),
2626 'EditContest' => array( 'EditContest' ),
 27+ 'MyContests' => array( 'MyContests' ),
2728 );
Index: trunk/extensions/Contest/specials/SpecialMyContests.php
@@ -0,0 +1,85 @@
 2+<?php
 3+
 4+/**
 5+ * List of contests for a user.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file SpecialMyContests.php
 10+ * @ingroup Contest
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class SpecialMyContests extends SpecialContestPage {
 16+
 17+ /**
 18+ * Constructor.
 19+ *
 20+ * @since 0.1
 21+ */
 22+ public function __construct() {
 23+ parent::__construct( 'MyContests', 'contestparticipant' );
 24+ }
 25+
 26+ /**
 27+ * Main method.
 28+ *
 29+ * @since 0.1
 30+ *
 31+ * @param string $arg
 32+ */
 33+ public function execute( $subPage ) {
 34+ $subPage = str_replace( '_', ' ', $subPage );
 35+
 36+ if ( !parent::execute( $subPage ) ) {
 37+ return;
 38+ }
 39+
 40+ $contestants = ContestContestant::s()->select(
 41+ array( 'id', 'contest_id', 'challenge_id' ),
 42+ array( 'user_id' => $this->getUser()->getId() )
 43+ );
 44+
 45+ $contestantCount = count( $contestants );
 46+
 47+ if ( $contestantCount == 0 ) {
 48+ $this->getOutput()->addWikiMsg( 'contest-mycontests-no-contests' );
 49+ }
 50+ else if ( $contestantCount == 1 ) {
 51+ $contest = $contestants[0]->getContest( array( 'status', 'name' ) );
 52+
 53+ if ( $contest->getField( 'status' ) == Contest::STATUS_ACTIVE ) {
 54+ $this->getOutput()->redirect( SpecialPage::getTitleFor( 'ContestSubmission', $contest->getField( 'name' ) )->getLocalURL() );
 55+ }
 56+ else {
 57+ $this->displayContestsTable( $contestants );
 58+ }
 59+ }
 60+ else {
 61+ $this->displayContestsTable( $contestants );
 62+ }
 63+ }
 64+
 65+ /**
 66+ * Displays a list of contests the user participates or participated in,
 67+ * together with their user specific choices such as the contest challenge.
 68+ *
 69+ * @since 0.1
 70+ *
 71+ * @param array $contestants
 72+ */
 73+ protected function displayContestsTable( array /* of ContestContestant */ $contestants ) {
 74+ $user = $this->getUser();
 75+ $out = $this->getOutput();
 76+
 77+ $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-mycontests-active-header' ) ) );
 78+
 79+ // TODO
 80+
 81+ $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-mycontests-finished-header' ) ) );
 82+
 83+ // TODO
 84+ }
 85+
 86+}
Property changes on: trunk/extensions/Contest/specials/SpecialMyContests.php
___________________________________________________________________
Added: svn:eol-style
187 + native
Index: trunk/extensions/Contest/Contest.php
@@ -73,6 +73,7 @@
7474 $wgAutoloadClasses['SpecialContestSubmission'] = dirname( __FILE__ ) . '/specials/SpecialContestSubmission.php';
7575 $wgAutoloadClasses['SpecialContestWelcome'] = dirname( __FILE__ ) . '/specials/SpecialContestWelcome.php';
7676 $wgAutoloadClasses['SpecialEditContest'] = dirname( __FILE__ ) . '/specials/SpecialEditContest.php';
 77+$wgAutoloadClasses['SpecialMyContests'] = dirname( __FILE__ ) . '/specials/SpecialMyContests.php';
7778
7879 // Special pages
7980 $wgSpecialPages['Contest'] = 'SpecialContest';
@@ -82,6 +83,7 @@
8384 $wgSpecialPages['ContestSubmission'] = 'SpecialContestSubmission';
8485 $wgSpecialPages['ContestWelcome'] = 'SpecialContestWelcome';
8586 $wgSpecialPages['EditContest'] = 'SpecialEditContest';
 87+$wgSpecialPages['MyContests'] = 'SpecialMyContests';
8688
8789 $wgSpecialPageGroups['Contest'] = 'other';
8890 $wgSpecialPageGroups['Contestant'] = 'other';
@@ -90,6 +92,7 @@
9193 $wgSpecialPageGroups['ContestSubmission'] = 'other';
9294 $wgSpecialPageGroups['ContestWelcome'] = 'other';
9395 $wgSpecialPageGroups['EditContest'] = 'other';
 96+$wgSpecialPageGroups['MyContests'] = 'other';
9497
9598 // API
9699 $wgAPIModules['deletecontest'] = 'ApiDeleteContest';
Index: trunk/extensions/Contest/includes/ContestDBObject.php
@@ -543,7 +543,7 @@
544544 *
545545 * @since 0.1
546546 *
547 - * @param array|null $fields
 547+ * @param array|string|null $fields
548548 * @param array $conditions
549549 * @param array $options
550550 *
@@ -575,7 +575,7 @@
576576 *
577577 * @since 0.1
578578 *
579 - * @param array|null $fields
 579+ * @param array|string|null $fields
580580 * @param array $conditions
581581 * @param array $options
582582 *
Index: trunk/extensions/Contest/includes/ContestContestant.php
@@ -144,11 +144,11 @@
145145 *
146146 * @since 0.1
147147 *
148 - * @param array|null $fields The fields to load, null for all fields.
 148+ * @param array|string|null $fields The fields to load, null for all fields.
149149 *
150150 * @return Contest
151151 */
152 - public function getContest( array $fields = null ) {
 152+ public function getContest( $fields = null ) {
153153 if ( !is_null( $this->contest ) ) {
154154 return $this->contest;
155155 }

Status & tagging log