Index: trunk/extensions/QPoll/qp_user.php |
— | — | @@ -92,11 +92,11 @@ |
93 | 93 | public static $cache_control = false; |
94 | 94 | /* end of default configuration settings */ |
95 | 95 | |
96 | | - static function entities( &$s ) { |
| 96 | + static function entities( $s ) { |
97 | 97 | return htmlentities( $s, ENT_COMPAT, 'UTF-8' ); |
98 | 98 | } |
99 | 99 | |
100 | | - static function specialchars( &$s ) { |
| 100 | + static function specialchars( $s ) { |
101 | 101 | return htmlspecialchars( $s, ENT_COMPAT, 'UTF-8' ); |
102 | 102 | } |
103 | 103 | |
— | — | @@ -1197,7 +1197,8 @@ |
1198 | 1198 | } |
1199 | 1199 | |
1200 | 1200 | static function displayRow( $row, $rowattrs = "", $celltag = "td", $attribute_maps = null ) { |
1201 | | - return self::renderHTMLobject( self::newRow( $row, $rowattrs, $celltag, $attribute_maps ) ); |
| 1201 | + $tagsrow = self::newRow( $row, $rowattrs, $celltag, $attribute_maps ); |
| 1202 | + return self::renderHTMLobject( $tagsrow ); |
1202 | 1203 | } |
1203 | 1204 | |
1204 | 1205 | // use newRow() or addColumn() to add resulting row/column to the table |
Index: trunk/extensions/QPoll/qp_question.php |
— | — | @@ -88,7 +88,7 @@ |
89 | 89 | # @param $state - sets new question state (note that the 'error' state cannot be changed) |
90 | 90 | function bodyErrorMessage( $msg, $state ) { |
91 | 91 | $prev_state = $this->getState(); |
92 | | - $this->setState( $state ); |
| 92 | + $this->setState( $state, $msg ); |
93 | 93 | # return the message only for the first error occured |
94 | 94 | # (this one has to be short, that's why title attribute is being used) |
95 | 95 | return ( $prev_state == '' ) ? '<span class="proposalerror" title="' . $msg . '">???</span> ' : ''; |
— | — | @@ -827,24 +827,36 @@ |
828 | 828 | $row[ $catId ][ 0 ] = $inp; |
829 | 829 | } |
830 | 830 | } |
831 | | - # If the proposal text is empty, the question has a syntax error. |
832 | | - if( trim( $text ) == '' ) { |
833 | | - $text = $this->bodyErrorMessage( wfMsg( "qp_error_proposal_text_empty" ), "error" ); |
834 | | - foreach( $row as &$cell ) { |
835 | | - $cell[ 'style' ] = QP_CSS_ERROR_STYLE; |
| 831 | + try { |
| 832 | + # if there is only one category defined and it is not a textfield, |
| 833 | + # the question has a syntax error |
| 834 | + if ( count( $matches ) < 2 && $matches[0] != '<>' ) { |
| 835 | + $text = $this->bodyErrorMessage( wfMsg( 'qp_error_too_few_categories' ), 'error' ); |
| 836 | + throw new Exception( 'qp_error' ); |
836 | 837 | } |
837 | | - $rawClass = 'proposalerror'; |
838 | | - } |
839 | | - # If the proposal was submitted but unanswered |
840 | | - if ( $this->mBeingCorrected && !array_key_exists( $proposalId, $this->mProposalCategoryId ) ) { |
841 | | - # if there was no previous errors, hightlight the whole row |
842 | | - if ( $this->getState() == '' ) { |
| 838 | + # If the proposal text is empty, the question has a syntax error. |
| 839 | + if( trim( $text ) == '' ) { |
| 840 | + $text = $this->bodyErrorMessage( wfMsg( "qp_error_proposal_text_empty" ), "error" ); |
| 841 | + throw new Exception( 'qp_error' ); |
| 842 | + } |
| 843 | + # If the proposal was submitted but unanswered |
| 844 | + if ( $this->mBeingCorrected && !array_key_exists( $proposalId, $this->mProposalCategoryId ) ) { |
| 845 | + $prev_state = $this->getState(); |
| 846 | + $text = $this->bodyErrorMessage( wfMsg( 'qp_error_no_answer' ), 'NA' ) . $text; |
| 847 | + # if there was no previous errors, hightlight the whole row |
| 848 | + if ( $prev_state == '' ) { |
| 849 | + throw new Exception( 'qp_error' ); |
| 850 | + } |
| 851 | + } |
| 852 | + } catch( Exception $e ) { |
| 853 | + if ( $e->getMessage() == 'qp_error' ) { |
843 | 854 | foreach( $row as &$cell ) { |
844 | 855 | $cell[ 'style' ] = QP_CSS_ERROR_STYLE; |
845 | 856 | } |
| 857 | + $rawClass = 'proposalerror'; |
| 858 | + } else { |
| 859 | + throw new MWException( $e->getMessage() ); |
846 | 860 | } |
847 | | - $text = $this->bodyErrorMessage( wfMsg( 'qp_error_no_answer' ), 'NA' ) . $text; |
848 | | - $rawClass = 'proposalerror'; |
849 | 861 | } |
850 | 862 | $text = array( '__tag'=>'td', '__end'=>"\n", 'class'=>'proposaltext', 'style'=>$this->proposalTextStyle, 0=>$this->parser->recursiveTagParse( $text ) ); |
851 | 863 | if ( $this->proposalsFirst ) { |
— | — | @@ -910,16 +922,16 @@ |
911 | 923 | if ( $curr_elem != '' ) { |
912 | 924 | $categories[] = $curr_elem; |
913 | 925 | } |
| 926 | + $categories = array_map( 'trim', $categories ); |
914 | 927 | # analyze previousely build "raw" categories array |
915 | 928 | # Less than two categories is a syntax error. |
916 | | - if ( !array_key_exists( 1, $categories ) ) { |
917 | | - $categories[0] .= $this->bodyErrorMessage( wfMsg( "qp_error_too_few_categories" ), "error" ); |
| 929 | + if ( $this->mType != 'mixedChoice' && count( $categories ) < 2 ) { |
| 930 | + $categories[0] .= $this->bodyErrorMessage( wfMsg( 'qp_error_too_few_categories' ), 'error' ); |
918 | 931 | } |
919 | 932 | foreach( $categories as $catkey => $category ) { |
920 | | - $category = trim( $category ); |
921 | 933 | # If a category name is empty, the question has a syntax error. |
922 | | - if( $category == "") { |
923 | | - $category = $this->bodyErrorMessage( wfMsg( "qp_error_category_name_empty" ), "error" ); |
| 934 | + if( $category == '' ) { |
| 935 | + $category = $this->bodyErrorMessage( wfMsg( 'qp_error_category_name_empty' ), 'error' ); |
924 | 936 | } |
925 | 937 | $this->mCategories[ $catkey ]["name"] = $category; |
926 | 938 | $row[] = $this->parser->recursiveTagParse( $category ); |