r78529 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78528‎ | r78529 | r78530 >
Date:07:59, 17 December 2010
Author:questpc
Status:deferred
Tags:
Comment:
Fixed questions of mixed type with just one category defined. Fixed two PHP warnings in strict mode
Modified paths:
  • /trunk/extensions/QPoll/qp_question.php (modified) (history)
  • /trunk/extensions/QPoll/qp_user.php (modified) (history)

Diff [purge]

Index: trunk/extensions/QPoll/qp_user.php
@@ -92,11 +92,11 @@
9393 public static $cache_control = false;
9494 /* end of default configuration settings */
9595
96 - static function entities( &$s ) {
 96+ static function entities( $s ) {
9797 return htmlentities( $s, ENT_COMPAT, 'UTF-8' );
9898 }
9999
100 - static function specialchars( &$s ) {
 100+ static function specialchars( $s ) {
101101 return htmlspecialchars( $s, ENT_COMPAT, 'UTF-8' );
102102 }
103103
@@ -1197,7 +1197,8 @@
11981198 }
11991199
12001200 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 );
12021203 }
12031204
12041205 // use newRow() or addColumn() to add resulting row/column to the table
Index: trunk/extensions/QPoll/qp_question.php
@@ -88,7 +88,7 @@
8989 # @param $state - sets new question state (note that the 'error' state cannot be changed)
9090 function bodyErrorMessage( $msg, $state ) {
9191 $prev_state = $this->getState();
92 - $this->setState( $state );
 92+ $this->setState( $state, $msg );
9393 # return the message only for the first error occured
9494 # (this one has to be short, that's why title attribute is being used)
9595 return ( $prev_state == '' ) ? '<span class="proposalerror" title="' . $msg . '">???</span> ' : '';
@@ -827,24 +827,36 @@
828828 $row[ $catId ][ 0 ] = $inp;
829829 }
830830 }
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' );
836837 }
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' ) {
843854 foreach( $row as &$cell ) {
844855 $cell[ 'style' ] = QP_CSS_ERROR_STYLE;
845856 }
 857+ $rawClass = 'proposalerror';
 858+ } else {
 859+ throw new MWException( $e->getMessage() );
846860 }
847 - $text = $this->bodyErrorMessage( wfMsg( 'qp_error_no_answer' ), 'NA' ) . $text;
848 - $rawClass = 'proposalerror';
849861 }
850862 $text = array( '__tag'=>'td', '__end'=>"\n", 'class'=>'proposaltext', 'style'=>$this->proposalTextStyle, 0=>$this->parser->recursiveTagParse( $text ) );
851863 if ( $this->proposalsFirst ) {
@@ -910,16 +922,16 @@
911923 if ( $curr_elem != '' ) {
912924 $categories[] = $curr_elem;
913925 }
 926+ $categories = array_map( 'trim', $categories );
914927 # analyze previousely build "raw" categories array
915928 # 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' );
918931 }
919932 foreach( $categories as $catkey => $category ) {
920 - $category = trim( $category );
921933 # 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' );
924936 }
925937 $this->mCategories[ $catkey ]["name"] = $category;
926938 $row[] = $this->parser->recursiveTagParse( $category );

Status & tagging log