Index: trunk/extensions/SecurePoll/includes/ballots/RadioRangeCommentBallot.php |
— | — | @@ -7,44 +7,44 @@ |
8 | 8 | class SecurePoll_RadioRangeCommentBallot extends SecurePoll_RadioRangeBallot { |
9 | 9 | public function getForm( $prevStatus = false ) { |
10 | 10 | $form = parent::getForm( $prevStatus ); |
11 | | - |
12 | | - $form .= Html::element('hr'); |
| 11 | + |
| 12 | + $form .= Html::element( 'hr' ); |
13 | 13 | // Add the comment call |
14 | 14 | $callForComments = $this->election->parseMessage( 'comments' ); |
15 | 15 | $form .= Html::rawElement( 'p', null, $callForComments ); |
16 | | - |
| 16 | + |
17 | 17 | // Add the comments boxes. |
18 | 18 | $form .= Html::textarea( 'securepoll_comments_native', '', |
19 | 19 | array( 'rows' => 10, 'cols' => 20 ) ); |
20 | 20 | $form .= Html::textarea( 'securepoll_comments_en', '', |
21 | 21 | array( 'rows' => 10, 'cols' => 20 ) ); |
22 | | - |
| 22 | + |
23 | 23 | return $form; |
24 | 24 | } |
25 | | - |
| 25 | + |
26 | 26 | public function submitForm() { |
27 | 27 | $status = parent::submitForm(); |
28 | | - |
| 28 | + |
29 | 29 | if ( ! $status->isGood() ) { |
30 | 30 | return $status; |
31 | 31 | } |
32 | | - |
| 32 | + |
33 | 33 | // Load comments |
34 | 34 | global $wgRequest; |
35 | | - |
| 35 | + |
36 | 36 | $commentNative = $wgRequest->getText( 'securepoll_comments_native' ); |
37 | 37 | $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 | + |
44 | 44 | $status->value = $record; |
45 | | - |
| 45 | + |
46 | 46 | return $status; |
47 | 47 | } |
48 | | - |
| 48 | + |
49 | 49 | /** |
50 | 50 | * Copy and modify from parent function, complex to refactor. |
51 | 51 | */ |
— | — | @@ -56,57 +56,57 @@ |
57 | 57 | $questions[$question->getId()] = $question; |
58 | 58 | } |
59 | 59 | 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 ) ) |
62 | 62 | { |
63 | 63 | // Allow comments |
64 | 64 | if ( $record[$offset] == '/' ) { |
65 | 65 | break; |
66 | 66 | } |
67 | | - |
68 | | - wfDebug( __METHOD__.": regex doesn't match\n" ); |
| 67 | + |
| 68 | + wfDebug( __METHOD__ . ": regex doesn't match\n" ); |
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | $qid = intval( base_convert( $m[1], 16, 10 ) ); |
72 | 72 | $oid = intval( base_convert( $m[2], 16, 10 ) ); |
73 | 73 | $score = intval( $m[3] ); |
74 | 74 | if ( !isset( $questions[$qid] ) ) { |
75 | | - wfDebug( __METHOD__.": invalid question ID\n" ); |
| 75 | + wfDebug( __METHOD__ . ": invalid question ID\n" ); |
76 | 76 | return false; |
77 | 77 | } |
78 | 78 | list( $min, $max ) = $this->getMinMax( $questions[$qid] ); |
79 | 79 | if ( $score < $min || $score > $max ) { |
80 | | - wfDebug( __METHOD__.": score out of range\n" ); |
| 80 | + wfDebug( __METHOD__ . ": score out of range\n" ); |
81 | 81 | return false; |
82 | 82 | } |
83 | 83 | $scores[$qid][$oid] = $score; |
84 | 84 | } |
85 | | - |
| 85 | + |
86 | 86 | // Read comments |
87 | 87 | $scores['comment'] = array(); |
88 | | - |
| 88 | + |
89 | 89 | $scores['comment']['native'] = $this->readComment( $record, $offset ); |
90 | 90 | |
91 | 91 | if ( substr( $record, $offset, 2 ) !== '--' ) { |
92 | | - wfDebug( __METHOD__.": Invalid format\n" ); |
| 92 | + wfDebug( __METHOD__ . ": Invalid format\n" ); |
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | $offset += 2; |
96 | 96 | |
97 | 97 | $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" ); |
101 | 101 | return false; |
102 | 102 | } |
103 | | - |
| 103 | + |
104 | 104 | return $scores; |
105 | 105 | } |
106 | | - |
| 106 | + |
107 | 107 | 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 ) ); |
111 | 111 | $result = substr( $record, $commentOffset + 1, $commentLength ); |
112 | 112 | $offset = $commentOffset + $commentLength + 1; // Fast-forward |
113 | 113 | return $result; |