r94344 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94343‎ | r94344 | r94345 >
Date:13:01, 12 August 2011
Author:werdna
Status:ok
Tags:
Comment:
Stylize
Modified paths:
  • /trunk/extensions/SecurePoll/includes/ballots/RadioRangeCommentBallot.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SecurePoll/includes/ballots/RadioRangeCommentBallot.php
@@ -7,44 +7,44 @@
88 class SecurePoll_RadioRangeCommentBallot extends SecurePoll_RadioRangeBallot {
99 public function getForm( $prevStatus = false ) {
1010 $form = parent::getForm( $prevStatus );
11 -
12 - $form .= Html::element('hr');
 11+
 12+ $form .= Html::element( 'hr' );
1313 // Add the comment call
1414 $callForComments = $this->election->parseMessage( 'comments' );
1515 $form .= Html::rawElement( 'p', null, $callForComments );
16 -
 16+
1717 // Add the comments boxes.
1818 $form .= Html::textarea( 'securepoll_comments_native', '',
1919 array( 'rows' => 10, 'cols' => 20 ) );
2020 $form .= Html::textarea( 'securepoll_comments_en', '',
2121 array( 'rows' => 10, 'cols' => 20 ) );
22 -
 22+
2323 return $form;
2424 }
25 -
 25+
2626 public function submitForm() {
2727 $status = parent::submitForm();
28 -
 28+
2929 if ( ! $status->isGood() ) {
3030 return $status;
3131 }
32 -
 32+
3333 // Load comments
3434 global $wgRequest;
35 -
 35+
3636 $commentNative = $wgRequest->getText( 'securepoll_comments_native' );
3737 $commentEnglish = $wgRequest->getText( 'securepoll_comments_en' );
38 -
39 - $record = rtrim($status->value);
40 -
41 - $record .= '/'.strlen($commentNative).'/'.$commentNative;
42 - $record .= '--/'.strlen($commentEnglish).'/'.$commentEnglish;
43 -
 38+
 39+ $record = rtrim( $status->value );
 40+
 41+ $record .= '/' . strlen( $commentNative ) . '/' . $commentNative;
 42+ $record .= '--/' . strlen( $commentEnglish ) . '/' . $commentEnglish;
 43+
4444 $status->value = $record;
45 -
 45+
4646 return $status;
4747 }
48 -
 48+
4949 /**
5050 * Copy and modify from parent function, complex to refactor.
5151 */
@@ -56,57 +56,57 @@
5757 $questions[$question->getId()] = $question;
5858 }
5959 for ( $offset = 0; $offset < strlen( $record ); $offset += $itemLength ) {
60 - if ( !preg_match( '/Q([0-9A-F]{8})-A([0-9A-F]{8})-S([+-][0-9]{10})--/A',
61 - $record, $m, 0, $offset ) )
 60+ if ( !preg_match( '/Q([0-9A-F]{8})-A([0-9A-F]{8})-S([+-][0-9]{10})--/A',
 61+ $record, $m, 0, $offset ) )
6262 {
6363 // Allow comments
6464 if ( $record[$offset] == '/' ) {
6565 break;
6666 }
67 -
68 - wfDebug( __METHOD__.": regex doesn't match\n" );
 67+
 68+ wfDebug( __METHOD__ . ": regex doesn't match\n" );
6969 return false;
7070 }
7171 $qid = intval( base_convert( $m[1], 16, 10 ) );
7272 $oid = intval( base_convert( $m[2], 16, 10 ) );
7373 $score = intval( $m[3] );
7474 if ( !isset( $questions[$qid] ) ) {
75 - wfDebug( __METHOD__.": invalid question ID\n" );
 75+ wfDebug( __METHOD__ . ": invalid question ID\n" );
7676 return false;
7777 }
7878 list( $min, $max ) = $this->getMinMax( $questions[$qid] );
7979 if ( $score < $min || $score > $max ) {
80 - wfDebug( __METHOD__.": score out of range\n" );
 80+ wfDebug( __METHOD__ . ": score out of range\n" );
8181 return false;
8282 }
8383 $scores[$qid][$oid] = $score;
8484 }
85 -
 85+
8686 // Read comments
8787 $scores['comment'] = array();
88 -
 88+
8989 $scores['comment']['native'] = $this->readComment( $record, $offset );
9090
9191 if ( substr( $record, $offset, 2 ) !== '--' ) {
92 - wfDebug( __METHOD__.": Invalid format\n" );
 92+ wfDebug( __METHOD__ . ": Invalid format\n" );
9393 return false;
9494 }
9595 $offset += 2;
9696
9797 $scores['comment']['en'] = $this->readComment( $record, $offset );
98 -
99 - if ( $offset < strlen($record) ) {
100 - wfDebug( __METHOD__.": Invalid format\n" );
 98+
 99+ if ( $offset < strlen( $record ) ) {
 100+ wfDebug( __METHOD__ . ": Invalid format\n" );
101101 return false;
102102 }
103 -
 103+
104104 return $scores;
105105 }
106 -
 106+
107107 function readComment( $record, &$offset ) {
108 - $commentOffset = strpos( $record, '/', $offset+1 );
109 - $commentLength = intval(substr( $record, $offset+1,
110 - ($commentOffset - $offset) - 1 ) );
 108+ $commentOffset = strpos( $record, '/', $offset + 1 );
 109+ $commentLength = intval( substr( $record, $offset + 1,
 110+ ( $commentOffset - $offset ) - 1 ) );
111111 $result = substr( $record, $commentOffset + 1, $commentLength );
112112 $offset = $commentOffset + $commentLength + 1; // Fast-forward
113113 return $result;

Follow-up revisions

RevisionCommit summaryAuthorDate
r94521MFT r94343 r94344 r94415werdna15:04, 15 August 2011

Status & tagging log