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

Revision: 99488
Author:   jeroendedauw
Date:     2011-10-11 16:14:47 +0000 (Tue, 11 Oct 2011)
Log Message:
-----------
work on handling of email and real/user names

Modified Paths:
--------------
    trunk/extensions/Contest/Contest.hooks.php
    trunk/extensions/Contest/Contest.php
    trunk/extensions/Contest/specials/SpecialContestSignup.php
    trunk/extensions/Contest/specials/SpecialContestSubmission.php

Modified: trunk/extensions/Contest/Contest.hooks.php
===================================================================
--- trunk/extensions/Contest/Contest.hooks.php  2011-10-11 16:08:35 UTC (rev 
99487)
+++ trunk/extensions/Contest/Contest.hooks.php  2011-10-11 16:14:47 UTC (rev 
99488)
@@ -177,4 +177,44 @@
                return true;
        }
        
-}
\ No newline at end of file
+       /**
+        * Called when changing user email address.
+        * @see https://www.mediawiki.org/wiki/Manual:Hooks/UserSetEmail
+        * 
+        * Checks if there are any active contests in which the user is 
participating,
+        * and if so, updates the email there as well.
+        * 
+        * @since 0.1
+        * 
+        * @param User $user
+        * @param string $email
+        * 
+        * @return true
+        */
+       public static function onUserSetEmail( User $user, &$email ) {
+               $dbr = wfGetDB( DB_SLAVE );
+               
+               $contestants = $dbr->select(
+                       array( 'contest_contestants', 'contests' ),
+                       array( 'contestant_id' ),
+                       array( 'contest_status' => Contest::STATUS_ACTIVE ),
+                       '',
+                       array(),
+                       array( 'contest_id=contestant_contest_id' )
+               );
+               
+               $contestantIds = array();
+               
+               foreach ( $contestants as $contestant ) {
+                       $contestantIds[] = $contestant->contestant_id;
+               }
+               
+               ContestContestant::s()->update(
+                       array( 'email' => $email ),
+                       array( 'id' => $contestantIds )
+               );
+               
+               return true;
+       }
+       
+}

Modified: trunk/extensions/Contest/Contest.php
===================================================================
--- trunk/extensions/Contest/Contest.php        2011-10-11 16:08:35 UTC (rev 
99487)
+++ trunk/extensions/Contest/Contest.php        2011-10-11 16:14:47 UTC (rev 
99488)
@@ -101,6 +101,7 @@
 // Hooks
 $wgHooks['LoadExtensionSchemaUpdates'][]               = 
'ContestHooks::onSchemaUpdate';
 $wgHooks['UnitTestsList'][]                                    = 
'ContestHooks::registerUnitTests';
+$wgHooks['UserSetEmail'][]                                             = 
'ContestHooks::onUserSetEmail';
 
 // Rights
 

Modified: trunk/extensions/Contest/specials/SpecialContestSignup.php
===================================================================
--- trunk/extensions/Contest/specials/SpecialContestSignup.php  2011-10-11 
16:08:35 UTC (rev 99487)
+++ trunk/extensions/Contest/specials/SpecialContestSignup.php  2011-10-11 
16:14:47 UTC (rev 99488)
@@ -51,8 +51,8 @@
         * 
         * @return true|array
         */
-       public static function handleSubmission( array $data ) {
-               $user = $GLOBALS['wgUser']; //$this->getUser();
+       public function handleSubmission( array $data ) {
+               $user = $this->getUser();
                
                $user->setEmail( $data['contestant-email'] );
                $user->setRealName( $data['contestant-realname'] );
@@ -63,8 +63,11 @@
                        'user_id' => $user->getId(),
                        'challenge_id' => $data['contestant-challengeid'],
                
+                       'full_name' => $data['contestant-realname'],
+                       'user_name' => $user->getName(),
+                       'email' => $data['contestant-email'],
+               
                        'country' => $data['contestant-country'],
-               
                        'volunteer' => $data['contestant-volunteer'],
                        'wmf' => $data['contestant-wmf'],
                ) );
@@ -156,7 +159,7 @@
        protected function showSignupForm( Contest $contest, $challengeId = 
false ) {
                $form = new HTMLForm( $this->getFormFields( $contest, 
$challengeId ), $this->getContext() );
                
-               $form->setSubmitCallback( array( __CLASS__, 'handleSubmission' 
) );
+               $form->setSubmitCallback( array( $this, 'handleSubmission' ) );
                $form->setSubmitText( wfMsg( 'contest-signup-submit' ) );
                
                if( $form->show() ){

Modified: trunk/extensions/Contest/specials/SpecialContestSubmission.php
===================================================================
--- trunk/extensions/Contest/specials/SpecialContestSubmission.php      
2011-10-11 16:08:35 UTC (rev 99487)
+++ trunk/extensions/Contest/specials/SpecialContestSubmission.php      
2011-10-11 16:14:47 UTC (rev 99488)
@@ -144,8 +144,10 @@
                $contestant = new ContestContestant( array(
                        'id' => $data['contestant-id'],
                
+                       'full_name' => $data['contestant-realname'],
+                       'email' => $data['contestant-email'],
+               
                        'country' => $data['contestant-country'],
-               
                        'volunteer' => $data['contestant-volunteer'],
                        'wmf' => $data['contestant-wmf'],
                        'cv' => $data['contestant-cv'],


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

Reply via email to