r105856 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105855‎ | r105856 | r105857 >
Date:06:59, 12 December 2011
Author:questpc
Status:deferred
Tags:
Comment:
Fix multi-line proposal/category definition parsing regexps. Prettify some old comments.
Modified paths:
  • /trunk/extensions/QPoll/ctrl/question/qp_stubquestion.php (modified) (history)
  • /trunk/extensions/QPoll/view/poll/qp_pollview.php (modified) (history)

Diff [purge]

Index: trunk/extensions/QPoll/ctrl/question/qp_stubquestion.php
@@ -75,10 +75,15 @@
7676 return array_search( $proposalName, $this->mProposalNames, true );
7777 }
7878
 79+ /**
 80+ * Replace lines of alone '\' character to empty lines.
 81+ * Trims first and last empty line, left from raws split regexp,
 82+ * when available.
 83+ */
7984 private function substBackslashNL( &$s ) {
8085 # warning: in single quoted regexp replace '\\\' translates into '\';
81 - # without trim(), regexp match in qp_PropAttrs::getFromSource() will fail.
82 - $s = preg_replace( '/^(\s*\\\??\s*)$/mu', '', trim( $s ) );
 86+ # wikitext always uses '\n' as line separator (unix style)
 87+ $s = preg_replace( '/^(\s*\\\??\s*)$|(\A\n)|(\n\Z)/mu', '', $s );
8388 }
8489
8590 /**
@@ -87,13 +92,12 @@
8893 */
8994 function splitRawProposals( $input ) {
9095 # detect type of raw proposals
91 - # originally was: preg_match( '/(?:^|\n)\s*\\??\s*(?:$|\n)/', $input )
9296 # multiline raw proposals have empty lines and also optionally have lines
9397 # containing only '\' character.
9498 if ( preg_match( '/^\s*\\??\s*$/mu', $input ) ) {
9599 # multiline raw proposals
96100 # warning: in single quoted regexp split '\\' translates into '\'
97 - $this->raws = preg_split( '/^(\s*\\??\s*)$/mu', $input, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
 101+ $this->raws = preg_split( '/((?:^\s*$)+)/mu', $input, -1, PREG_SPLIT_NO_EMPTY );
98102 array_walk( $this->raws, array( __CLASS__, 'substBackslashNL' ) );
99103 } else {
100104 # single line raw proposals
@@ -101,9 +105,10 @@
102106 }
103107 }
104108
105 - # load some question fields from qp_QuestionData given
106 - # (usually qp_QuestionData is an array property of qp_PollStore instance)
107 - # @param $qdata - an instance of qp_QuestionData
 109+ /**
 110+ * Load answer-related question fields from qp_QuestionData instance given.
 111+ * @param $qdata instance of qp_QuestionData
 112+ */
108113 function loadAnswer( qp_QuestionData $qdata ) {
109114 $this->alreadyVoted = $qdata->alreadyVoted;
110115 $this->mPrevProposalCategoryId = $qdata->ProposalCategoryId;
@@ -116,8 +121,10 @@
117122 }
118123 }
119124
120 - # populates an instance of qp_Question with data from qp_QuestionData
121 - # @param the object of type qp_Question
 125+ /**
 126+ * Populates current instance of question with data from pollstore.
 127+ * @param $pollStore instance of qp_PollStore
 128+ */
122129 function getQuestionAnswer( qp_PollStore $pollStore ) {
123130 if ( $pollStore->pid !== null ) {
124131 if ( $pollStore->questionExists( $this->mQuestionId ) ) {
@@ -131,9 +138,13 @@
132139 return false;
133140 }
134141
135 - # checks, whether user had previousely selected the category of the proposal of this question
136 - # returns true/false for 'checkbox' and 'radio' inputTypes
137 - # text string/false for 'text' inputType
 142+ /**
 143+ * Check, whether current user previousely selected the particular category of
 144+ * the proposal of this question.
 145+ * @return mixed
 146+ * boolean true / boolean false for 'checkbox' and 'radio' inputTypes
 147+ * string / boolean false for 'text' inputType
 148+ */
138149 function answerExists( $inputType, $proposalId, $catId ) {
139150 if ( $this->alreadyVoted ) {
140151 if ( array_key_exists( $proposalId, $this->mPrevProposalCategoryId ) ) {
Index: trunk/extensions/QPoll/view/poll/qp_pollview.php
@@ -63,7 +63,7 @@
6464 $write_col[] = array( '__tag' => 'td', 'valign' => 'top', 0 => $question->view->renderQuestion(), '__end' => "\n" );
6565 if ( $this->currCol == 1 ) {
6666 $write_row[] = array( '__tag' => 'tr', 0 => $write_col, '__end' => "\n" );
67 - $write_col = Array();
 67+ $write_col = array();
6868 }
6969 if ( --$this->currCol < 1 ) {
7070 $this->currCol = $this->perRow;
@@ -131,22 +131,22 @@
132132 }
133133 } else {
134134 if ( $pollStore->getState() == "error" ) {
135 - $submitBtn[ 'disabled' ] = 'disabled';
 135+ $submitBtn['disabled'] = 'disabled';
136136 }
137137 }
138138 $atLeft = $this->ctrl->attemptsLeft();
139139 if ( $atLeft === false ) {
140 - $submitBtn[ 'disabled' ] = 'disabled';
 140+ $submitBtn['disabled'] = 'disabled';
141141 }
142142 # disable submit button in preview mode & printable version
143143 if ( qp_Setup::$request->getVal( 'action' ) == 'parse' ||
144144 qp_Setup::$output->isPrintable() ) {
145 - $submitBtn[ 'disabled' ] = 'disabled';
 145+ $submitBtn['disabled'] = 'disabled';
146146 }
147 - $submitBtn[ 'value' ] = wfMsgHtml( $submitMsg );
 147+ $submitBtn['value'] = wfMsgHtml( $submitMsg );
148148 $p = array( '__tag' => 'p' );
149149 $p[] = $submitBtn;
150 - # output no more attempts message, when applicable
 150+ # output "no more attempts" message, when applicable
151151 if ( $atLeft === false ) {
152152 $p[] = array( '__tag' => 'span', 'class' => 'attempts_counter', qp_Setup::specialchars( wfMsg( 'qp_error_no_more_attempts' ) ) );
153153 } elseif ( $atLeft !== true ) {

Status & tagging log