r59481 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59480‎ | r59481 | r59482 >
Date:05:53, 27 November 2009
Author:tstarling
Status:deferred
Tags:
Comment:
In RadioRangeBallot: added "column-order" property to allow sorting of columns in descending order. To support the arbcom election.
Modified paths:
  • /trunk/extensions/SecurePoll/includes/ballots/RadioRangeBallot.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SecurePoll/includes/ballots/RadioRangeBallot.php
@@ -11,6 +11,7 @@
1212 * min-score
1313 * max-score
1414 * column-label-msgs
 15+ * column-order
1516 *
1617 * Question messages:
1718 * column-1, column0, column+1, etc.
@@ -31,18 +32,46 @@
3233 return array( $min, $max );
3334 }
3435
 36+ function getColumnDirection( $question ) {
 37+ $order = $question->getProperty( 'column-order' );
 38+ if ( !$order ) {
 39+ return 1;
 40+ } elseif ( preg_match( '/^asc/i', $order ) ) {
 41+ return 1;
 42+ } elseif ( preg_match( '/^desc/i', $order ) ) {
 43+ return -1;
 44+ } else {
 45+ throw new MWException( __METHOD__.': column-order configured incorrectly' );
 46+ }
 47+ }
 48+
 49+
 50+ function getScoresLeftToRight( $question ) {
 51+ $incr = $this->getColumnDirection( $question );
 52+ list( $min, $max ) = $this->getMinMax( $question );
 53+ if ( $incr > 0 ) {
 54+ $left = $min;
 55+ $right = $max;
 56+ } else {
 57+ $left = $max;
 58+ $right = $min;
 59+ }
 60+ return range( $left, $right );
 61+ }
 62+
3563 function getColumnLabels( $question ) {
3664 list( $min, $max ) = $this->getMinMax( $question );
3765 $labels = array();
3866 $useMessageLabels = $question->getProperty( 'column-label-msgs' );
 67+ $scores = $this->getScoresLeftToRight( $question );
3968 if ( $useMessageLabels ) {
40 - for ( $score = $min; $score <= $max; $score++ ) {
 69+ foreach ( $scores as $score ) {
4170 $signedScore = $this->addSign( $question, $score );
4271 $labels[$score] = $question->getMessage( "column$signedScore" );
4372 }
4473 } else {
4574 global $wgLang;
46 - for ( $score = $min; $score <= $max; $score++ ) {
 75+ foreach ( $scores as $score ) {
4776 $labels[$score] = $wgLang->formatNum( $score );
4877 }
4978 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r59482Merged r59481 from trunk to wmf-deployment for arbcom election starting shortly.tstarling05:56, 27 November 2009

Status & tagging log