http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99561
Revision: 99561
Author: jeroendedauw
Date: 2011-10-11 20:37:04 +0000 (Tue, 11 Oct 2011)
Log Message:
-----------
Follow up to r99560; comitted only /specials/
Modified Paths:
--------------
trunk/extensions/Contest/Contest.alias.php
trunk/extensions/Contest/Contest.hooks.php
trunk/extensions/Contest/Contest.i18n.php
trunk/extensions/Contest/Contest.php
trunk/extensions/Contest/Contest.settings.php
trunk/extensions/Contest/includes/ContestContestant.php
trunk/extensions/Contest/includes/ContestDBObject.php
Modified: trunk/extensions/Contest/Contest.alias.php
===================================================================
--- trunk/extensions/Contest/Contest.alias.php 2011-10-11 20:35:23 UTC (rev
99560)
+++ trunk/extensions/Contest/Contest.alias.php 2011-10-11 20:37:04 UTC (rev
99561)
@@ -20,8 +20,7 @@
'Contestant' => array( 'Contestant' ),
'Contests' => array( 'Contests' ),
'ContestSignup' => array( 'ContestSignup' ),
- 'ContestSubmission' => array( 'ContestSubmission' ),
'ContestWelcome' => array( 'ContestWelcome' ),
'EditContest' => array( 'EditContest' ),
- 'MyContests' => array( 'MyContests' ),
+ 'MyContests' => array( 'MyContests', 'ContestSubmission', 'My contests'
),
);
Modified: trunk/extensions/Contest/Contest.hooks.php
===================================================================
--- trunk/extensions/Contest/Contest.hooks.php 2011-10-11 20:35:23 UTC (rev
99560)
+++ trunk/extensions/Contest/Contest.hooks.php 2011-10-11 20:37:04 UTC (rev
99561)
@@ -81,8 +81,8 @@
$contestants = $dbr->select(
array( 'contest_contestants', 'contests' ),
array( 'contestant_id' ),
- array( 'contest_status' => Contest::STATUS_ACTIVE ),
- '',
+ array( 'contest_status' => Contest::STATUS_ACTIVE,
'contestant_user_id' => $user->getId() ),
+ __METHOD__,
array(),
array( 'contests' => array( 'INNER JOIN', array(
'contest_id=contestant_contest_id' ) ) )
);
@@ -103,4 +103,62 @@
return true;
}
+ /**
+ * Called after the personal URLs have been set up, before they are
shown.
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls
+ *
+ * @since 0.1
+ *
+ * @param array $personal_urls
+ * @param Title $title
+ *
+ * @return true
+ */
+ public static function onPersonalUrls( array &$personal_urls, Title
&$title ) {
+ if ( ContestSettings::get( 'enableTopLink' ) ) {
+ global $wgUser;
+
+ // Find the watchlist item and replace it by the my
contests link and itself.
+ if ( $wgUser->isLoggedIn() && $wgUser->getOption(
'contest_showtoplink' ) ) {
+ $keys = array_keys( $personal_urls );
+ $watchListLocation = array_search( 'watchlist',
$keys );
+ $watchListItem =
$personal_urls[$keys[$watchListLocation]];
+
+ $url = SpecialPage::getTitleFor( 'MyContests'
)->getLinkUrl();
+ $myContests = array(
+ 'text' => wfMsg( 'contest-toplink' ),
+ 'href' => $url,
+ 'active' => ( $url ==
$title->getLinkUrl() )
+ );
+
+ array_splice( $personal_urls,
$watchListLocation, 1, array( $myContests, $watchListItem ) );
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Adds the preferences of Contest to the list of available ones.
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
+ *
+ * @since 0.1
+ *
+ * @param User $user
+ * @param array $preferences
+ *
+ * @return true
+ */
+ public static function onGetPreferences( User $user, array
&$preferences ) {
+ if ( ContestSettings::get( 'enableTopLink' ) ) {
+ $preferences['contest_showtoplink'] = array(
+ 'type' => 'toggle',
+ 'label-message' => 'contest-prefs-showtoplink',
+ 'section' => 'contest',
+ );
+ }
+
+ return true;
+ }
+
}
Modified: trunk/extensions/Contest/Contest.i18n.php
===================================================================
--- trunk/extensions/Contest/Contest.i18n.php 2011-10-11 20:35:23 UTC (rev
99560)
+++ trunk/extensions/Contest/Contest.i18n.php 2011-10-11 20:37:04 UTC (rev
99561)
@@ -20,6 +20,9 @@
$messages['en'] = array(
'contest-desc' => 'Contest extension that allows users to participate
in admin defined contest challenges. Via a judging interface, judges can
discuss and vote on submissions.',
+ // Misc
+ 'contest-toplink' => 'My contests',
+
// Rights
'right-contestadmin' => 'Manage contests',
'right-contestparticipant' => 'Participate in contests',
@@ -38,6 +41,10 @@
'group-contestjudge-member' => 'contest judge',
'grouppage-contestjudge' => 'Project:Contest_judges',
+ // Preferences
+ 'prefs-contest' => 'Contests',
+ 'contest-prefs-showtoplink' => 'Show a link to [[Special:MyContests|My
Contests]] in the top menue.',
+
// Contest statuses
'contest-status-draft' => 'Draft (disabled)',
'contest-status-active' => 'Active (enabled)',
@@ -50,6 +57,7 @@
'special-contestsubmission' => 'Contest submission',
'special-contestwelcome' => 'Contest',
'special-editcontest' => 'Edit contest',
+ 'special-mycontests' => 'Contests',
// Navigation links
'contest-nav-contests' => 'Contests list',
@@ -182,9 +190,14 @@
'contest-email-reminder-title' => 'Only $1 {{PLURAL:$1|day|days}} until
the end of the challenge!',
// Special:MyContests
+ 'contest-mycontests-toplink' => 'My contests',
'contest-mycontests-no-contests' => 'You are not participating in any
contest.',
'contest-mycontests-active-header' => 'Running contests',
'contest-mycontests-finished-header' => 'Passed contests',
+ 'contest-mycontests-active-text' => 'These are the contests you are
currently participating in.',
+ 'contest-mycontests-finished-text' => 'These are the passed contests
you have participated in.',
+ 'contest-mycontests-header-contest' => 'Contest',
+ 'contest-mycontests-header-challenge' => 'Challenge',
);
/** Message documentation (Message documentation)
@@ -240,4 +253,10 @@
// Emails
'contest-email-signup-title' => 'Title for signup emails',
'contest-email-reminder-title' => 'Title for reminder emails',
+
+ // Special:MyContests
+ 'contest-mycontests-toplink' => 'Text for link in the top menue (ie
where watchlist and preferences are linked)',
+ 'contest-mycontests-no-contests' => 'Message indicating there are no
contests for the user, displayed instead of a list.',
+ 'contest-mycontests-active-header' => 'Page header (h2)',
+ 'contest-mycontests-finished-header' => 'Page header (h2)',
);
Modified: trunk/extensions/Contest/Contest.php
===================================================================
--- trunk/extensions/Contest/Contest.php 2011-10-11 20:35:23 UTC (rev
99560)
+++ trunk/extensions/Contest/Contest.php 2011-10-11 20:37:04 UTC (rev
99561)
@@ -70,7 +70,6 @@
$wgAutoloadClasses['SpecialContestPage'] = dirname( __FILE__ ) .
'/specials/SpecialContestPage.php';
$wgAutoloadClasses['SpecialContests'] = dirname( __FILE__ ) .
'/specials/SpecialContests.php';
$wgAutoloadClasses['SpecialContestSignup'] = dirname( __FILE__ ) .
'/specials/SpecialContestSignup.php';
-$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';
@@ -80,7 +79,6 @@
$wgSpecialPages['Contestant'] =
'SpecialContestant';
$wgSpecialPages['Contests'] =
'SpecialContests';
$wgSpecialPages['ContestSignup'] =
'SpecialContestSignup';
-$wgSpecialPages['ContestSubmission'] =
'SpecialContestSubmission';
$wgSpecialPages['ContestWelcome'] =
'SpecialContestWelcome';
$wgSpecialPages['EditContest'] =
'SpecialEditContest';
$wgSpecialPages['MyContests'] =
'SpecialMyContests';
@@ -89,7 +87,6 @@
$wgSpecialPageGroups['Contestant'] = 'other';
$wgSpecialPageGroups['Contests'] = 'other';
$wgSpecialPageGroups['ContestSignup'] = 'other';
-$wgSpecialPageGroups['ContestSubmission'] = 'other';
$wgSpecialPageGroups['ContestWelcome'] = 'other';
$wgSpecialPageGroups['EditContest'] = 'other';
$wgSpecialPageGroups['MyContests'] = 'other';
@@ -105,6 +102,8 @@
$wgHooks['LoadExtensionSchemaUpdates'][] =
'ContestHooks::onSchemaUpdate';
$wgHooks['UnitTestsList'][] =
'ContestHooks::registerUnitTests';
$wgHooks['UserSetEmail'][] =
'ContestHooks::onUserSetEmail';
+$wgHooks['PersonalUrls'][] =
'ContestHooks::onPersonalUrls';
+$wgHooks['GetPreferences'][] =
'ContestHooks::onGetPreferences';
// Rights
Modified: trunk/extensions/Contest/Contest.settings.php
===================================================================
--- trunk/extensions/Contest/Contest.settings.php 2011-10-11 20:35:23 UTC
(rev 99560)
+++ trunk/extensions/Contest/Contest.settings.php 2011-10-11 20:37:04 UTC
(rev 99561)
@@ -28,7 +28,8 @@
*/
protected static function getDefaultSettings() {
return array(
- 'votevalues' => range( 0, 5 )
+ 'votevalues' => range( 0, 5 ),
+ 'enableTopLink' => true,
);
}
Modified: trunk/extensions/Contest/includes/ContestContestant.php
===================================================================
--- trunk/extensions/Contest/includes/ContestContestant.php 2011-10-11
20:35:23 UTC (rev 99560)
+++ trunk/extensions/Contest/includes/ContestContestant.php 2011-10-11
20:37:04 UTC (rev 99561)
@@ -458,16 +458,29 @@
$success = parent::insertIntoDB();
if ( $success ) {
- $this->getContest( array( 'id' )
)->addToSubmissionCount( 1 );
- $this->sendSignupEmail();
-
- wfRunHooks( 'ContestAfterContestantInsert', array(
&$this ) );
+ $this->onUserSignup();
}
return $success;
}
/**
+ * Handles successfull user signup for a contest.
+ *
+ * @since 0.1
+ */
+ protected function onUserSignup() {
+ $this->getContest( array( 'id' ) )->addToSubmissionCount( 1 );
+
+ $this->getUser()->setOption( 'contest_showtoplink', true );
+ $this->getUser()->saveSettings(); // TODO: can't we just save
this single option instead of everything?
+
+ $this->sendSignupEmail();
+
+ wfRunHooks( 'ContestAfterContestantInsert', array( &$this ) );
+ }
+
+ /**
* Send the signup email.
*
* @since 0.1
Modified: trunk/extensions/Contest/includes/ContestDBObject.php
===================================================================
--- trunk/extensions/Contest/includes/ContestDBObject.php 2011-10-11
20:35:23 UTC (rev 99560)
+++ trunk/extensions/Contest/includes/ContestDBObject.php 2011-10-11
20:37:04 UTC (rev 99561)
@@ -643,7 +643,7 @@
$this->getDBTable(),
$fields,
count( $conditions ) == 0 ? '' : $conditions,
- '',
+ __METHOD__,
$options
);
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs