https://www.mediawiki.org/wiki/Special:Code/MediaWiki/101940
Revision: 101940
Author: jeroendedauw
Date: 2011-11-04 01:25:46 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
added filter options for the contestant list
Modified Paths:
--------------
trunk/extensions/Contest/Contest.i18n.php
trunk/extensions/Contest/RELEASE-NOTES
trunk/extensions/Contest/includes/ContestantPager.php
trunk/extensions/Contest/specials/SpecialContest.php
Modified: trunk/extensions/Contest/Contest.i18n.php
===================================================================
--- trunk/extensions/Contest/Contest.i18n.php 2011-11-04 01:12:48 UTC (rev
101939)
+++ trunk/extensions/Contest/Contest.i18n.php 2011-11-04 01:25:46 UTC (rev
101940)
@@ -153,6 +153,18 @@
'contest-contest-reminder-mail' => 'Reminder e-mail',
'contest-contest-reminder-page' => 'The content for the reminder e-mail
comes from [[$1|this page]].',
'contest-contest-send-reminder' => 'Send reminder',
+ 'contest-contest-go' => 'Go',
+ 'contest-contest-showonly' => 'Filter contestants by',
+ 'contest-contest-yes' => 'Yes',
+ 'contest-contest-no' => 'No',
+ 'contest-contest-none' => 'None',
+ 'contest-contest-some' => 'Some',
+ 'contest-contest-filter-challenge' => 'Challenge',
+ 'contest-contest-filter-volunteer' => 'Volunteer',
+ 'contest-contest-filter-wmf' => 'WMF',
+ 'contest-contest-filter-comments' => 'Comments',
+ 'contest-contest-filter-rating_count' => 'Votes',
+ 'contest-contest-filter-submission' => 'Submission',
// Special:Contest, reminder email JS
'contest-contest-reminder-preview' => 'Preview of the reminder e-mail:',
@@ -276,6 +288,8 @@
'contest-contest-reminder-mail' => 'Reminder e-mail',
'contest-contest-reminder-page' => 'Text explaining the e-mail content
is pulled from a page, $1 is the page name.',
'contest-contest-send-reminder' => 'Send reminder button text',
+ 'contest-contest-go' => 'Submission button text for filter form',
+ 'contest-contest-showonly' => 'Header text for filter form',
'contest-contest-reminder-preview' => 'Text indicating that the
following content is the preview for the reminder e-mail.',
'contest-contest-reminder-title' => 'Dialog title',
'contest-contest-reminder-send' => 'Send button text',
Modified: trunk/extensions/Contest/RELEASE-NOTES
===================================================================
--- trunk/extensions/Contest/RELEASE-NOTES 2011-11-04 01:12:48 UTC (rev
101939)
+++ trunk/extensions/Contest/RELEASE-NOTES 2011-11-04 01:25:46 UTC (rev
101940)
@@ -4,6 +4,10 @@
Latest version of the release notes:
http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Contest/RELEASE-NOTES?view=co
+=== Version 0.2 ===
+
+* Added filter options for the contestant pager on Special:Contest.
+
=== Version 0.1 ===
2011-10-20
Modified: trunk/extensions/Contest/includes/ContestantPager.php
===================================================================
--- trunk/extensions/Contest/includes/ContestantPager.php 2011-11-04
01:12:48 UTC (rev 101939)
+++ trunk/extensions/Contest/includes/ContestantPager.php 2011-11-04
01:25:46 UTC (rev 101940)
@@ -198,7 +198,7 @@
);
break;
case 'contestant_challenge_id':
- $value = Html::element(
+ $value = /*Html::element(
'a',
array(
'href' =>
@@ -207,8 +207,8 @@
$this->page->subPage . '/' . $this->getChallengeTitle( $value )
)->getLocalURL()
),
- $this->getChallengeTitle( $value )
- );
+ */$this->getChallengeTitle( $value );
+ //);
break;
case 'contestant_volunteer': case 'contestant_wmf':
// contest-contestant-yes, contest-contestant-no
Modified: trunk/extensions/Contest/specials/SpecialContest.php
===================================================================
--- trunk/extensions/Contest/specials/SpecialContest.php 2011-11-04
01:12:48 UTC (rev 101939)
+++ trunk/extensions/Contest/specials/SpecialContest.php 2011-11-04
01:25:46 UTC (rev 101940)
@@ -61,6 +61,10 @@
$this->showMailFunctionality( $contest );
}
+ $out->addHTML( Html::element( 'h3', array(), wfMsg(
'contest-contest-contestants' ) ) );
+
+ $this->addFilterOptionsToSession();
+ $this->showFilterControl( $contest, $challengeTitle );
$this->showContestants( $contest, $challengeTitle );
$out->addModules( 'contest.special.contest' );
@@ -175,23 +179,14 @@
protected function showContestants( Contest $contest, $challengeTitle )
{
$out = $this->getOutput();
- $out->addHTML( Html::element( 'h3', array(), wfMsg(
'contest-contest-contestants' ) ) );
+ $out->addWikiMsg( 'contest-contest-contestants-text' );
$conds = array(
'contestant_contest_id' => $contest->getId()
);
-
- if ( $challengeTitle !== false ) {
- $challenge = ContestChallenge::s()->selectRow( 'id',
array( 'title' => $challengeTitle ) );
-
- if ( $challenge !== false ) {
- $conds['contestant_challenge_id'] =
$challenge->getField( 'id' );
- unset( $conds['contestant_contest_id'] ); //
Not needed because the challenge implies the context
- }
- }
-
- $out->addWikiMsg( 'contest-contest-contestants-text' );
-
+
+ $this->addRequestConditions( $conds );
+
$pager = new ContestantPager( $this, $conds );
if ( $pager->getNumRows() ) {
@@ -205,5 +200,178 @@
$out->addWikiMsg( 'contest-contest-no-results' );
}
}
+
+ /**
+ * Add the filter options to the session, so they get retained
+ * when the user does navigation such as going to the next
+ * set of results using the pager.
+ *
+ * @since 0.2
+ */
+ protected function addFilterOptionsToSession() {
+ $fields = array(
+ 'volunteer',
+ 'wmf',
+ 'comments',
+ 'rating_count',
+ 'challenge',
+ 'submission'
+ );
+
+ $req = $this->getRequest();
+
+ foreach ( $fields as $field ) {
+ if ( $req->getCheck( $field ) ) {
+ $req->setSessionData( 'contestant-' . $field,
$req->getVal( $field ) );
+ }
+ }
+ }
+
+ /**
+ * Add the needed conditions to the provided array depending
+ * on the filter options set.
+ *
+ * @since 0.2
+ *
+ * @param array $conds
+ */
+ protected function addRequestConditions( &$conds ) {
+ $req = $this->getRequest();
+
+ foreach ( array( 'volunteer', 'wmf' ) as $field ) {
+ if ( in_array( $req->getSessionData( 'contestant-' .
$field ), array( 'yes', 'no' ) ) ) {
+ $conds['contestant_' . $field] =
$req->getSessionData( 'contestant-' . $field ) == 'yes' ? 1 : 0;
+ }
+ }
+ foreach ( array( 'comments', 'rating_count' ) as $field ) {
+ if ( in_array( $req->getSessionData( 'contestant-' .
$field ), array( 'some', 'none' ) ) ) {
+ if ( $req->getSessionData( 'contestant-' .
$field ) == 'none' ) {
+ $conds['contestant_' . $field] = 0;
+ }
+ else {
+ $conds[] = 'contestant_' . $field . ' >
0';
+ }
+ }
+ }
+
+ if ( $req->getSessionData( 'contestant-challenge' ) ) {
+ $challenge = ContestChallenge::s()->selectRow( 'id',
array( 'title' => $req->getSessionData( 'contestant-' . $field ) ) );
+
+ if ( $challenge !== false ) {
+ $conds['contestant_challenge_id'] =
$challenge->getField( 'id' );
+ unset( $conds['contestant_contest_id'] ); //
Not needed because the challenge implies the context
+ }
+ }
+
+ if ( in_array( $req->getSessionData( 'contestant-submission' ),
array( 'some', 'none' ) ) ) {
+ if ( $req->getSessionData( 'contestant-submission' ) ==
'none' ) {
+ $conds['contestant_submission'] = '';
+ }
+ else {
+ $conds[] = 'contestant_submission <> ""';
+ }
+ }
+ }
+
+ /**
+ * Create the filter control and add it to the output.
+ *
+ * @since 0.2
+ *
+ * @param Contest $contest
+ */
+ protected function showFilterControl( Contest $contest ) {
+ $req = $this->getRequest();
+ $challenges = array();
+
+ foreach ( $contest->getChallenges() as /* ContestChallenge */
$challenge ) {
+ $challenges[$challenge->getField( 'title' )] =
$challenge->getField( 'title' );
+ }
+
+ $yesNo = array(
+ 'yes' => wfMsg( 'contest-contest-yes' ),
+ 'no' => wfMsg( 'contest-contest-no' )
+ );
+
+ $noneSome = array(
+ 'none' => wfMsg( 'contest-contest-none' ),
+ 'some' => wfMsg( 'contest-contest-some' ),
+ );
+
+ $title = $this->getTitle( $this->subPage )->getFullText();
+
+ $this->getOutput()->addHTML(
+ '<fieldset>' .
+ '<legend>' . wfMsgHtml(
'contest-contest-showonly' ) . '</legend>' .
+ '<form method="post" action="' .
$GLOBALS['wgScript'] . '?title=' . $title . '">' .
+ Html::hidden( 'title', $title ) .
+ $this->getDropdownHTML(
+ 'challenge',
+ $challenges
+ ) .
+ $this->getDropdownHTML(
+ 'volunteer',
+ $yesNo
+ ) .
+ $this->getDropdownHTML(
+ 'wmf',
+ $yesNo
+ ) .
+ $this->getDropdownHTML(
+ 'comments',
+ $noneSome
+ ) .
+ $this->getDropdownHTML(
+ 'rating_count',
+ $noneSome
+ ) .
+ $this->getDropdownHTML(
+ 'submission',
+ $noneSome
+ ) .
+ '<input type="submit" value="' .
wfMsgHtml( 'contest-contest-go' ) . '">' .
+ '</form>' .
+ '</fieldset>'
+ );
+ }
+
+ /**
+ * Get the HTML for a filter option dropdown menu.
+ *
+ * @since 0.2
+ *
+ * @param string $name
+ * @param array $options
+ * @param string|null $message
+ * @param mixed $value
+ *
+ * @return string
+ */
+ protected function getDropdownHTML( $name, array $options, $message =
null, $value = null ) {
+ $opts = array();
+ $options = array_merge( array( '' => ' ' ), $options );
+
+ if ( is_null( $value ) ) {
+ $value = $this->getRequest()->getSessionData(
'contestant-' . $name );
+ }
+
+ if ( is_null( $message ) ) {
+ $message = 'contest-contest-filter-' . $name;
+ }
+
+ foreach ( $options as $val => $label ) {
+ $attribs = array( 'value' => $val );
+
+ if ( $val == $value || ( $val === ' ' &&
!array_key_exists( $val, $options ) ) ) {
+ $attribs['selected'] = 'selected';
+ }
+
+ $opts[] = Html::element( 'option', $attribs, $label );
+ }
+
+ return Html::element( 'label', array( 'for' => $name ), wfMsg(
$message ) ) . ' ' .
+ Html::rawElement( 'select', array( 'name' => $name,
'id' => $name ), implode( "\n", $opts ) ) . ' ';
+ }
+
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs