http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99491

Revision: 99491
Author:   jeroendedauw
Date:     2011-10-11 16:38:22 +0000 (Tue, 11 Oct 2011)
Log Message:
-----------
initial work on special:mycontests

Modified Paths:
--------------
    trunk/extensions/Contest/Contest.alias.php
    trunk/extensions/Contest/Contest.i18n.php
    trunk/extensions/Contest/Contest.php
    trunk/extensions/Contest/includes/ContestContestant.php
    trunk/extensions/Contest/includes/ContestDBObject.php

Added Paths:
-----------
    trunk/extensions/Contest/specials/SpecialMyContests.php

Modified: trunk/extensions/Contest/Contest.alias.php
===================================================================
--- trunk/extensions/Contest/Contest.alias.php  2011-10-11 16:17:20 UTC (rev 
99490)
+++ trunk/extensions/Contest/Contest.alias.php  2011-10-11 16:38:22 UTC (rev 
99491)
@@ -23,4 +23,5 @@
        'ContestSubmission' => array( 'ContestSubmission' ),
        'ContestWelcome' => array( 'ContestWelcome' ),
        'EditContest' => array( 'EditContest' ),
+       'MyContests' => array( 'MyContests' ),
 );

Modified: trunk/extensions/Contest/Contest.i18n.php
===================================================================
--- trunk/extensions/Contest/Contest.i18n.php   2011-10-11 16:17:20 UTC (rev 
99490)
+++ trunk/extensions/Contest/Contest.i18n.php   2011-10-11 16:38:22 UTC (rev 
99491)
@@ -180,6 +180,11 @@
        // Emails
        'contest-email-signup-title' => 'Thanks for joining the challenge!',
        'contest-email-reminder-title' => 'Only $1 {{PLURAL:$1|day|days}} until 
the end of the challenge!',
+
+       // Special:MyContests
+       'contest-mycontests-no-contests' => 'You are not participating in any 
contest.',
+       'contest-mycontests-active-header' => 'Running contests',
+       'contest-mycontests-finished-header' => 'Passed contests',
 );
 
 /** Message documentation (Message documentation)

Modified: trunk/extensions/Contest/Contest.php
===================================================================
--- trunk/extensions/Contest/Contest.php        2011-10-11 16:17:20 UTC (rev 
99490)
+++ trunk/extensions/Contest/Contest.php        2011-10-11 16:38:22 UTC (rev 
99491)
@@ -73,6 +73,7 @@
 $wgAutoloadClasses['SpecialContestSubmission']         = dirname( __FILE__ ) . 
'/specials/SpecialContestSubmission.php';
 $wgAutoloadClasses['SpecialContestWelcome']    = dirname( __FILE__ ) . 
'/specials/SpecialContestWelcome.php';
 $wgAutoloadClasses['SpecialEditContest']               = dirname( __FILE__ ) . 
'/specials/SpecialEditContest.php';
+$wgAutoloadClasses['SpecialMyContests']                = dirname( __FILE__ ) . 
'/specials/SpecialMyContests.php';
 
 // Special pages
 $wgSpecialPages['Contest']                                             = 
'SpecialContest';
@@ -82,6 +83,7 @@
 $wgSpecialPages['ContestSubmission']                   = 
'SpecialContestSubmission';
 $wgSpecialPages['ContestWelcome']                              = 
'SpecialContestWelcome';
 $wgSpecialPages['EditContest']                                         = 
'SpecialEditContest';
+$wgSpecialPages['MyContests']                                  = 
'SpecialMyContests';
 
 $wgSpecialPageGroups['Contest']                                = 'other';
 $wgSpecialPageGroups['Contestant']                             = 'other';
@@ -90,6 +92,7 @@
 $wgSpecialPageGroups['ContestSubmission']              = 'other';
 $wgSpecialPageGroups['ContestWelcome']                         = 'other';
 $wgSpecialPageGroups['EditContest']                    = 'other';
+$wgSpecialPageGroups['MyContests']                             = 'other';
 
 // API
 $wgAPIModules['deletecontest']                                         = 
'ApiDeleteContest';

Modified: trunk/extensions/Contest/includes/ContestContestant.php
===================================================================
--- trunk/extensions/Contest/includes/ContestContestant.php     2011-10-11 
16:17:20 UTC (rev 99490)
+++ trunk/extensions/Contest/includes/ContestContestant.php     2011-10-11 
16:38:22 UTC (rev 99491)
@@ -144,11 +144,11 @@
         * 
         * @since 0.1
         * 
-        * @param array|null $fields The fields to load, null for all fields.
+        * @param array|string|null $fields The fields to load, null for all 
fields.
         * 
         * @return Contest
         */
-       public function getContest( array $fields = null ) {
+       public function getContest( $fields = null ) {
                if ( !is_null( $this->contest ) ) {
                        return $this->contest;
                }

Modified: trunk/extensions/Contest/includes/ContestDBObject.php
===================================================================
--- trunk/extensions/Contest/includes/ContestDBObject.php       2011-10-11 
16:17:20 UTC (rev 99490)
+++ trunk/extensions/Contest/includes/ContestDBObject.php       2011-10-11 
16:38:22 UTC (rev 99491)
@@ -543,7 +543,7 @@
         * 
         * @since 0.1
         * 
-        * @param array|null $fields
+        * @param array|string|null $fields
         * @param array $conditions
         * @param array $options
         * 
@@ -575,7 +575,7 @@
         * 
         * @since 0.1
         * 
-        * @param array|null $fields
+        * @param array|string|null $fields
         * @param array $conditions
         * @param array $options
         * 

Added: trunk/extensions/Contest/specials/SpecialMyContests.php
===================================================================
--- trunk/extensions/Contest/specials/SpecialMyContests.php                     
        (rev 0)
+++ trunk/extensions/Contest/specials/SpecialMyContests.php     2011-10-11 
16:38:22 UTC (rev 99491)
@@ -0,0 +1,85 @@
+<?php
+
+/**
+ * List of contests for a user. 
+ * 
+ * @since 0.1
+ * 
+ * @file SpecialMyContests.php
+ * @ingroup Contest
+ * 
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class SpecialMyContests extends SpecialContestPage {
+       
+       /**
+        * Constructor.
+        * 
+        * @since 0.1
+        */
+       public function __construct() {
+               parent::__construct( 'MyContests', 'contestparticipant' );
+       }
+       
+       /**
+        * Main method.
+        * 
+        * @since 0.1
+        * 
+        * @param string $arg
+        */
+       public function execute( $subPage ) {
+               $subPage = str_replace( '_', ' ', $subPage );
+               
+               if ( !parent::execute( $subPage ) ) {
+                       return;
+               }
+               
+               $contestants = ContestContestant::s()->select( 
+                       array( 'id', 'contest_id', 'challenge_id' ),
+                       array( 'user_id' => $this->getUser()->getId() )
+               );
+               
+               $contestantCount = count( $contestants );
+               
+               if ( $contestantCount == 0 ) {
+                       $this->getOutput()->addWikiMsg( 
'contest-mycontests-no-contests' );
+               }
+               else if ( $contestantCount == 1 ) {
+                       $contest =  $contestants[0]->getContest( array( 
'status', 'name' ) );
+                       
+                       if ( $contest->getField( 'status' ) == 
Contest::STATUS_ACTIVE ) {
+                               $this->getOutput()->redirect( 
SpecialPage::getTitleFor( 'ContestSubmission', $contest->getField( 'name' ) 
)->getLocalURL() );
+                       }
+                       else {
+                               $this->displayContestsTable( $contestants );
+                       }
+               }
+               else {
+                       $this->displayContestsTable( $contestants );
+               }
+       }
+       
+       /**
+        * Displays a list of contests the user participates or participated in,
+        * together with their user specific choices such as the contest 
challenge.
+        * 
+        * @since 0.1
+        * 
+        * @param array $contestants
+        */
+       protected function displayContestsTable( array /* of ContestContestant 
*/ $contestants ) {
+               $user = $this->getUser();
+               $out = $this->getOutput();
+               
+               $out->addHTML( Html::element( 'h2', array(), wfMsg( 
'contest-mycontests-active-header' ) ) );
+               
+               // TODO
+               
+               $out->addHTML( Html::element( 'h2', array(), wfMsg( 
'contest-mycontests-finished-header' ) ) );
+               
+               // TODO
+       }       
+       
+}


Property changes on: trunk/extensions/Contest/specials/SpecialMyContests.php
___________________________________________________________________
Added: svn:eol-style
   + native


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to