[MediaWiki-commits] [Gerrit] mediawiki...Quiz[master]: Generate questions HTML via TemplateParser
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/339941 ) Change subject: Generate questions HTML via TemplateParser .. Generate questions HTML via TemplateParser This commit will move the generation of the Quiz's questions HTML to TemplateParser. Some work is still needed here, especially it would be good to have CSS classes for the table style instead of inline CSS. I also added some comments here and there especially for an unknown and undocumented feature. Still to port to TemplateParser: Settings table, answers. Bug: T152293 Change-Id: I557803731645f925db43166ae0d90eb1db8bdea8 --- M Quiz.class.php A templates/Question.mustache 2 files changed, 77 insertions(+), 32 deletions(-) Approvals: Zppix: Looks good to me, but someone else must approve jenkins-bot: Verified Mvolz: Looks good to me, approved diff --git a/Quiz.class.php b/Quiz.class.php index ff2fa0a..e97234b 100755 --- a/Quiz.class.php +++ b/Quiz.class.php @@ -247,6 +247,7 @@ -1, PREG_SPLIT_NO_EMPTY ); + $output = ''; $questionPattern = '`(.*?[^|\}])\}[ \t]*(\n(.*)|$)`s'; foreach ( $unparsedQuestions as $unparsedQuestion ) { @@ -288,8 +289,18 @@ $this->mParser ); Hooks::run( 'QuizQuestionCreated', array( $this, &$question ) ); - $buffer = $question->parseHeader( $matches[1] ); - if ( !array_key_exists( 3, $matches ) || trim( $matches[3] ) == '' ) { + + // gets the question text + $questionText = $question->parseHeader( $matches[1] ); + + /* + What is this block of code? + The only place X !X and /X are spoken about is here + https://en.wikiversity.org/wiki/Help:Quiz + "A few exotic features are not yet covered, such as shuffle control using {X} {!X} {/X} tags." + These were added in commit fb53a3b0 back in 2007, without any explanation and/or documentation. The commit message is actually unrelated. + */ + if ( !array_key_exists(3, $matches ) || trim( $matches[3] ) == '' ) { switch ( $matches[1] ) { case 'X': $this->mShuffleDiv++; @@ -309,66 +320,89 @@ } break; default: - return '' . $buffer . '' . "\n"; + return '' . $questionText . '' . "\n"; break; } } - $output = '' . "\n"; - $output .= '' . "\n"; - $output .= '' . ++$this->mQuestionId . '. ' . $buffer; - $output .= '' . "\n"; - // Store the parsed object into a buffer to determine some parameters before outputing it. - $buffer = call_user_func( array( - $question, - $question->mType . 'ParseObject' - ), $matches[3]); - $output .= 'getState(); - // Determine the side border color, title, score and the total of the question. - if ( $lState != '' ) { + $templateParser = new TemplateParser( __DIR__ . '/templates' ); + + $this->mQuestionId++; + + //this will generate the answers HTML code + $answers = call_user_func( + array( $question, $question->mType . 'ParseObject' ), + $matches[3] + ); + + $lState = $question->getState(); // right wrong or unanswered? + + if( $lState != '' ) { + // TODO: convert to CSS classes global $wgContLang; $border = $wgContLang->isRTL() ? 'border-right' : 'border-left'; - $output .= 'style="' . $border . ':3px solid ' . self::getColor( $lState ) . '"'; + $tableStyle = $border . ': 3px solid ' . self::getColor( $lState ) . ';'; + + $tableTitle = ""; + + // if the question is of type=simple if ( $this->mIgnoringCoef ) { $question->mCoef = 1; } - switch ( $lState ) { case 'right': $this->mTotal += $this->mAddedPoints * $question->mCoef; $this->mScore += $this->mAddedPoints * $question->mCoef; -
[MediaWiki-commits] [Gerrit] mediawiki...Quiz[master]: Generate questions HTML via TemplateParser
Crisbal has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/339941 ) Change subject: Generate questions HTML via TemplateParser .. Generate questions HTML via TemplateParser This commit will move the generation of the Quiz's questions HTML to TemplateParser. Some work is still needed here, especially it would be good to have CSS classes for the table style instead of inline CSS. I also added some comments here and there especially for an unknown and undocumented feature. Still to port to TemplateParser: Settings table, answers. Bug: T152293 Change-Id: I557803731645f925db43166ae0d90eb1db8bdea8 --- M Quiz.class.php A templates/Question.mustache 2 files changed, 76 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Quiz refs/changes/41/339941/1 diff --git a/Quiz.class.php b/Quiz.class.php index ff2fa0a..ea3988d 100755 --- a/Quiz.class.php +++ b/Quiz.class.php @@ -247,6 +247,7 @@ -1, PREG_SPLIT_NO_EMPTY ); + $output = ''; $questionPattern = '`(.*?[^|\}])\}[ \t]*(\n(.*)|$)`s'; foreach ( $unparsedQuestions as $unparsedQuestion ) { @@ -288,8 +289,18 @@ $this->mParser ); Hooks::run( 'QuizQuestionCreated', array( $this, &$question ) ); - $buffer = $question->parseHeader( $matches[1] ); - if ( !array_key_exists( 3, $matches ) || trim( $matches[3] ) == '' ) { + + // gets the question text + $questionText = $question->parseHeader( $matches[1] ); + + /* + What is this block of code? + The only place X !X and /X are spoken about is here + https://en.wikiversity.org/wiki/Help:Quiz + "A few exotic features are not yet covered, such as shuffle control using {X} {!X} {/X} tags." + These were added in commit fb53a3b0 back in 2007, without any explanation and/or documentation. The commit message is actually unrelated. + */ + if ( !array_key_exists(3, $matches ) || trim( $matches[3] ) == '' ) { switch ( $matches[1] ) { case 'X': $this->mShuffleDiv++; @@ -313,62 +324,85 @@ break; } } - $output = '' . "\n"; - $output .= '' . "\n"; - $output .= '' . ++$this->mQuestionId . '. ' . $buffer; - $output .= '' . "\n"; - // Store the parsed object into a buffer to determine some parameters before outputing it. - $buffer = call_user_func( array( - $question, - $question->mType . 'ParseObject' - ), $matches[3]); - $output .= 'getState(); - // Determine the side border color, title, score and the total of the question. - if ( $lState != '' ) { + $templateParser = new TemplateParser( __DIR__ . '/templates' ); + + $this->mQuestionId++; + + //this will generate the answers HTML code + $answers = call_user_func( + array($question, $question->mType . 'ParseObject'), + $matches[3] + ); + + $lState = $question->getState(); // right wrong or unanswered? + + if($lState != '') { + // TODO: convert to CSS classes global $wgContLang; $border = $wgContLang->isRTL() ? 'border-right' : 'border-left'; - $output .= 'style="' . $border . ':3px solid ' . self::getColor( $lState ) . '"'; + $tableStyle = $border . ': 3px solid ' . self::getColor( $lState ) . ';'; + + $tableTitle = ""; + + // if the question is of type=simple if ( $this->mIgnoringCoef ) { $question->mCoef = 1; } - switch ( $lState ) { case 'right': $this->mTotal += $this->mAddedPoints * $question->mCoef; $this->mScore += $this->mAddedPoints * $question->mCoef; - $output .= 'title="' . wfMessage( + + $tableTitle = wfMessage( 'quiz_points', - wfMessage( 'quiz_colorRight' )->text(), +