https://www.mediawiki.org/wiki/Special:Code/MediaWiki/102992
Revision: 102992 Author: reedy Date: 2011-11-14 17:16:17 +0000 (Mon, 14 Nov 2011) Log Message: ----------- MFT r101940 Modified Paths: -------------- branches/wmf/1.18wmf1/extensions/Contest/Contest.i18n.php branches/wmf/1.18wmf1/extensions/Contest/RELEASE-NOTES branches/wmf/1.18wmf1/extensions/Contest/includes/ContestantPager.php branches/wmf/1.18wmf1/extensions/Contest/specials/SpecialContest.php Property Changed: ---------------- branches/wmf/1.18wmf1/extensions/Contest/ Property changes on: branches/wmf/1.18wmf1/extensions/Contest ___________________________________________________________________ Modified: svn:mergeinfo - /branches/REL1_15/phase3/extensions/Contest:51646 /branches/REL1_17/phase3/extensions/Contest:81445,81448 /branches/new-installer/phase3/extensions/Contest:43664-66004 /branches/sqlite/extensions/Contest:58211-58321 /trunk/extensions/Contest:99592,99653,100324,100399,100402,100405,100419,100427,100432-100433,100435-100439 /trunk/phase3/extensions/Contest:92580,92634,92713,92762,92765,92791,92854,92884,92886-92887,92894,92898,92907,92932,92958,93141,93149,93151,93233-93234,93258,93266,93303,93516-93518,93520,93818-93822,93847,93858,93891,93935-93936,94058,94062,94068,94107,94155,94235,94277,94346,94372,94422,94425,94444,94448,94456,94498,94517,94601,94630,94728,94738,94825,94862,94995-94997,95023,95042,95072-95073,95155,95327,95332,95410,95422,95426,95442,95468,95601,95812,98578,98598,98656 + /branches/REL1_15/phase3/extensions/Contest:51646 /branches/REL1_17/phase3/extensions/Contest:81445,81448 /branches/new-installer/phase3/extensions/Contest:43664-66004 /branches/sqlite/extensions/Contest:58211-58321 /trunk/extensions/Contest:99592,99653,100324,100399,100402,100405,100419,100427,100432-100433,100435-100439,101940 /trunk/phase3/extensions/Contest:92580,92634,92713,92762,92765,92791,92854,92884,92886-92887,92894,92898,92907,92932,92958,93141,93149,93151,93233-93234,93258,93266,93303,93516-93518,93520,93818-93822,93847,93858,93891,93935-93936,94058,94062,94068,94107,94155,94235,94277,94346,94372,94422,94425,94444,94448,94456,94498,94517,94601,94630,94728,94738,94825,94862,94995-94997,95023,95042,95072-95073,95155,95327,95332,95410,95422,95426,95442,95468,95601,95812,98578,98598,98656 Modified: branches/wmf/1.18wmf1/extensions/Contest/Contest.i18n.php =================================================================== --- branches/wmf/1.18wmf1/extensions/Contest/Contest.i18n.php 2011-11-14 16:53:50 UTC (rev 102991) +++ branches/wmf/1.18wmf1/extensions/Contest/Contest.i18n.php 2011-11-14 17:16:17 UTC (rev 102992) @@ -152,6 +152,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:', @@ -274,7 +286,9 @@ '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-reminder-preview' => 'Text indicating that the following content is the preview for the reminder email.', + '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', 'contest-contest-reminder-cancel' => 'Cancel button text', Modified: branches/wmf/1.18wmf1/extensions/Contest/RELEASE-NOTES =================================================================== --- branches/wmf/1.18wmf1/extensions/Contest/RELEASE-NOTES 2011-11-14 16:53:50 UTC (rev 102991) +++ branches/wmf/1.18wmf1/extensions/Contest/RELEASE-NOTES 2011-11-14 17:16:17 UTC (rev 102992) @@ -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: branches/wmf/1.18wmf1/extensions/Contest/includes/ContestantPager.php =================================================================== --- branches/wmf/1.18wmf1/extensions/Contest/includes/ContestantPager.php 2011-11-14 16:53:50 UTC (rev 102991) +++ branches/wmf/1.18wmf1/extensions/Contest/includes/ContestantPager.php 2011-11-14 17:16:17 UTC (rev 102992) @@ -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: branches/wmf/1.18wmf1/extensions/Contest/specials/SpecialContest.php =================================================================== --- branches/wmf/1.18wmf1/extensions/Contest/specials/SpecialContest.php 2011-11-14 16:53:50 UTC (rev 102991) +++ branches/wmf/1.18wmf1/extensions/Contest/specials/SpecialContest.php 2011-11-14 17:16:17 UTC (rev 102992) @@ -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 MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs