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 '<div class="quizText">' .
$buffer . '<br /></div>' . "\n";
+ return '<div class="quizText">' .
$questionText . '<br /></div>' . "\n";
break;
}
}
- $output = '<div class="question">' . "\n";
- $output .= '<div class="header">' . "\n";
- $output .= '<span class="questionId">' . ++$this->mQuestionId .
'. </span>' . $buffer;
- $output .= '</div>' . "\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 .= '<table class="object" ';
- $lState = $question->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(),
+ wfMessage('quiz_colorRight'
)->text(),
$this->mAddedPoints *
$question->mCoef
- )->escaped() . '"';
+ )->escaped();
break;
+
case 'wrong':
$this->mTotal += $this->mAddedPoints *
$question->mCoef;
$this->mScore -= $this->mCutoffPoints *
$question->mCoef;
- $output .= 'title="' . wfMessage(
+
+ $tableTitle= wfMessage(
'quiz_points',
- wfMessage( 'quiz_colorWrong'
)->text(),
+
wfMessage('quiz_colorWrong')->text(),
-$this->mCutoffPoints *
$question->mCoef
- )->escaped() . '"';
+ )->escaped();
break;
+
case 'NA':
$this->mTotal += $this->mAddedPoints *
$question->mCoef;
- $output .= 'title="' . wfMessage(
+
+ $tableTitle = wfMessage(
'quiz_points',
- wfMessage( 'quiz_colorNA'
)->text(), 0
- )->escaped() . '"';
+
wfMessage('quiz_colorNA')->text(),
+ 0
+ )->escaped();
break;
+
case 'error':
$this->mState = 'error';
break;
}
+
+ $stateObject = array(
+ 'tableStyle' => $tableStyle,
+ 'tableTitle' => $tableTitle
+ );
}
- $output .= '><tbody>' . "\n";
- $output .= $buffer;
- $output .= '</tbody></table>' . "\n";
- $output .= '<br /></div>' . "\n";
- return $output;
+
+ return $templateParser->processTemplate(
+ 'Question',
+ array(
+ 'question' => array(
+ 'id' => $this->mQuestionId,
+ 'text' => $questionText,
+ 'answers' => $answers
+ ),
+ 'state' => $stateObject
+ )
+ );
}
}
diff --git a/templates/Question.mustache b/templates/Question.mustache
new file mode 100644
index 0000000..790f13a
--- /dev/null
+++ b/templates/Question.mustache
@@ -0,0 +1,11 @@
+<div class="question">
+ <div class="header">
+ <span class="questionId">{{ question.id }}</span>
+ <span class="questionText">{{{ question.text }}}</span>
+ </div>
+ <table class="object" style="{{ state.tableStyle }}" title="{{
state.tableTitle }}">
+ <tbody>
+ {{{ question.answers }}}
+ </tbody>
+ </table>
+</div>
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/339941
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I557803731645f925db43166ae0d90eb1db8bdea8
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/Quiz
Gerrit-Branch: master
Gerrit-Owner: Crisbal <[email protected]>
Gerrit-Reviewer: Crisbal <[email protected]>
Gerrit-Reviewer: Mvolz <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Zppix <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits