r99188 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99187‎ | r99188 | r99189 >
Date:04:01, 7 October 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on contestant pager - added challenge name and option to filter on it
Modified paths:
  • /trunk/extensions/Contest/Contest.i18n.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestantPager.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContest.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/Contest.i18n.php
@@ -101,7 +101,7 @@
102102 'contest-welcome-signup' => 'Signup now',
103103 'contest-welcome-js-off' => 'Contest uses JavaScript for an improved interface. Your browser either does not support JavaScript or has JavaScript turned off.',
104104
105 - 'contest-welcome-select-header' => 'Select your challange:',
 105+ 'contest-welcome-select-header' => 'Select your challenge:',
106106
107107 // Special:ContestSignup & Special:ContestSubmission
108108 'contest-signup-unknown' => 'There is no contest with the provided name.',
@@ -141,6 +141,7 @@
142142
143143 // Contestant pager
144144 'contest-contestant-id' => 'ID',
 145+ 'contest-contestant-challenge-name' => 'Challenge name',
145146 'contest-contestant-volunteer' => 'Volunteer',
146147 'contest-contestant-wmf' => 'WMF',
147148 'contest-contestant-no' => 'No',
Index: trunk/extensions/Contest/specials/SpecialContestPage.php
@@ -14,7 +14,7 @@
1515 */
1616 abstract class SpecialContestPage extends SpecialPage {
1717
18 - protected $subPage;
 18+ public $subPage;
1919
2020 /**
2121 * @see SpecialPage::getDescription
Index: trunk/extensions/Contest/specials/SpecialContest.php
@@ -32,6 +32,11 @@
3333 public function execute( $subPage ) {
3434 $subPage = str_replace( '_', ' ', $subPage );
3535
 36+ $subPage = explode( '/', $subPage, 2 );
 37+ $challengeTitle = count( $subPage ) > 1 ? $subPage[1] : false;
 38+
 39+ $subPage = $subPage[0];
 40+
3641 if ( !parent::execute( $subPage ) ) {
3742 return;
3843 }
@@ -47,7 +52,7 @@
4853 $out->setPageTitle( wfMsgExt( 'contest-contest-title', 'parseinline', $contest->getField( 'name' ) ) );
4954 $this->displayNavigation();
5055 $this->showGeneralInfo( $contest );
51 - $this->showContestants( $contest );
 56+ $this->showContestants( $contest, $challengeTitle );
5257 }
5358 }
5459
@@ -109,10 +114,9 @@
110115 * @since 0.1
111116 *
112117 * @param Contest $contest
113 - *
114 - * TODO: list scores and comment counts as well
 118+ * @param string|false $challengeTitle
115119 */
116 - protected function showContestants( Contest $contest ) {
 120+ protected function showContestants( Contest $contest, $challengeTitle ) {
117121 $out = $this->getOutput();
118122
119123 $out->addHTML( Html::element( 'h3', array(), wfMsg( 'contest-contest-contestants' ) ) );
@@ -121,6 +125,14 @@
122126 'contestant_contest_id' => $contest->getId()
123127 );
124128
 129+ if ( $challengeTitle !== false ) {
 130+ $challenge = ContestChallenge::s()->selectRow( 'id', array( 'title' => $challengeTitle ) );
 131+
 132+ if ( $challenge !== false ) {
 133+ $conds['contestant_challenge_id'] = $challenge->getField( 'id' );
 134+ }
 135+ }
 136+
125137 $pager = new ContestantPager( $this, $conds );
126138
127139 if ( $pager->getNumRows() ) {
Index: trunk/extensions/Contest/includes/ContestantPager.php
@@ -14,18 +14,52 @@
1515 class ContestantPager extends TablePager {
1616
1717 protected $conds;
 18+
 19+ /**
 20+ * @var SpecialContestPage
 21+ */
1822 protected $page;
 23+
 24+ protected $challengeTitles = array();
1925
2026 public function __construct( $page, $conds ) {
2127 $this->page = $page;
2228 $this->conds = $conds;
2329 $this->mDefaultDirection = true;
2430
 31+ $this->queryChallengeTitles( $conds );
 32+
 33+ // when MW 1.19 becomes min, we want to pass an IContextSource $context here.
2534 parent::__construct();
2635
2736 $this->getOutput()->addModules( 'contest.contestant.pager' );
2837 }
2938
 39+ protected function queryChallengeTitles( $allConds ) {
 40+ $conds = array();
 41+
 42+ if ( array_key_exists( 'contestant_contest_id', $allConds ) ) {
 43+ $conds['contest_id'] = $allConds['contestant_contest_id'];
 44+ }
 45+
 46+ if ( array_key_exists( 'contestant_challenge_id', $allConds ) ) {
 47+ $conds['id'] = $allConds['contestant_challenge_id'];
 48+ }
 49+
 50+ foreach ( ContestChallenge::s()->select( array( 'id', 'title' ), $conds ) as /* ContestChallenge */ $challenge ) {
 51+ $this->challengeTitles[$challenge->getId()] = $challenge->getField( 'title' );
 52+ }
 53+ }
 54+
 55+ protected function getChallengeTitle( $challengeId ) {
 56+ if ( array_key_exists( $challengeId, $this->challengeTitles ) ) {
 57+ return $this->challengeTitles[$challengeId];
 58+ }
 59+ else {
 60+ throw new MWException( 'Attempt to get non-set challenge title' );
 61+ }
 62+ }
 63+
3064 /**
3165 * Get the OutputPage being used for this instance.
3266 * IndexPager extends ContextSource as of 1.19.
@@ -56,6 +90,7 @@
5791 if ( is_null( $headers ) ) {
5892 $headers = array(
5993 'contestant_id' => 'contest-contestant-id',
 94+ 'contestant_challenge_id' => 'contest-contestant-challenge-name',
6095 'contestant_volunteer' => 'contest-contestant-volunteer',
6196 'contestant_wmf' => 'contest-contestant-wmf',
6297 'contestant_comments' => 'contest-contestant-commentcount',
@@ -108,6 +143,19 @@
109144 $value
110145 );
111146 break;
 147+ case 'contestant_challenge_id':
 148+ $value = Html::element(
 149+ 'a',
 150+ array(
 151+ 'href' =>
 152+ SpecialPage::getTitleFor(
 153+ 'Contest',
 154+ $this->page->subPage . '/' . $this->getChallengeTitle( $value )
 155+ )->getLocalURL()
 156+ ),
 157+ $this->getChallengeTitle( $value )
 158+ );
 159+ break;
112160 case 'contestant_volunteer': case 'contestant_wmf':
113161 $value = wfMsg( 'contest-contestant-' . ( $value === '1' ? 'yes' : 'no' ) );
114162 break;
@@ -132,6 +180,7 @@
133181 'tables' => array( 'contest_contestants' ),
134182 'fields' => array(
135183 'contestant_id',
 184+ 'contestant_challenge_id',
136185 'contestant_volunteer',
137186 'contestant_wmf',
138187 'contestant_comments',
@@ -161,6 +210,7 @@
162211 $name,
163212 array(
164213 'contestant_id',
 214+ 'contestant_challenge_id',
165215 'contestant_volunteer',
166216 'contestant_wmf',
167217 'contestant_comments',

Follow-up revisions

RevisionCommit summaryAuthorDate
r99190follow up to r99188jeroendedauw04:16, 7 October 2011

Status & tagging log