jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/344726 )
Change subject: Put Html code of Answer in Question.php into mustache template
......................................................................
Put Html code of Answer in Question.php into mustache template
Question.php consisted of raw HTML code to generate HTML form code
of a quiz.TemplateParser class using mustache template is considered
better.This change uses mustache for answers HTML code.
Bug:T161318
Change-Id: Ie9641d58db4c0380ce928b930fbb3725d830e6bb
---
M Question.php
A templates/Answer.mustache
2 files changed, 58 insertions(+), 24 deletions(-)
Approvals:
jenkins-bot: Verified
Mvolz: Looks good to me, approved
diff --git a/Question.php b/Question.php
index 5410f87..952e853 100644
--- a/Question.php
+++ b/Question.php
@@ -354,31 +354,35 @@
function parseTextField( $input ) {
global $wqInputId;
$wqInputId++;
- $title = $state = $size = $maxlength = $class = $style = $value
= $disabled = $a_inputBeg = $a_inputEnd = $big = '';
+ $title = $state = $size = $maxlength = $class = $style = $value
= $disabled = $big = '';
// determine size and maxlength of the input.
if ( array_key_exists( 3, $input ) ) {
$size = $input[3];
if ( $size < 3 ) {
- $size = 'size="1"';
+ $size = 1;
} elseif ( $size < 12 ) {
- $size = 'size="' . ( $size - 2 ) . '"';
+ $size = $size - 2;
} else {
- $size = 'size="' . ( $size - 1 ) . '"';
+ $size = $size - 1;
}
- $maxlength = 'maxlength="' . $input[3] . '"';
+ $maxlength = $input[3];
}
// Syntax error if there is no input text.
if ( empty( $input[1] ) ) {
$value = 'value="???"';
$state = 'error';
} else {
+ $templateParser = new TemplateParser( __DIR__ .
'/templates' );
+ // For hiding down arrow
+ $bigDisplay = 'display: none';
if ( $this->mBeingCorrected ) {
$value = trim( $this->mRequest->getVal(
$wqInputId ) );
- $a_inputBeg = '<a class="input"
href="#nogo"><span class="correction">';
$state = 'NA';
- $title = 'title="' . wfMessage( 'quiz_colorNA'
)->escaped() . '"';
+ $title = wfMessage( 'quiz_colorNA' )->escaped();
+
}
- $class = 'class="numbers"';
+ $class = 'numbers';
+ $poss = ' ';
foreach ( preg_split( '` *\| *`', trim( $input[1] ),
-1, PREG_SPLIT_NO_EMPTY ) as $possibility ) {
if ( $state == '' || $state == 'NA' || $state
== 'wrong' ) {
if ( preg_match(
'`^(-?\d+\.?\d*)(-(-?\d+\.?\d*)| (\d+\.?\d*)(%))?$`', str_replace( ',', '.',
$possibility ), $matches ) ) {
@@ -399,25 +403,25 @@
) ||
$value == $possibility )
) {
$state =
'right';
- $title =
'title="' . wfMessage( 'quiz_colorRight' )->escaped() . '"';
+ $title =
wfMessage( 'quiz_colorRight' )->escaped();
} else {
$state =
'wrong';
- $title =
'title="' . wfMessage( 'quiz_colorWrong' )->escaped() . '"';
+ $title =
wfMessage( 'quiz_colorWrong' )->escaped();
}
}
} else {
$strlen = preg_match( '`
\(i\)$`', $possibility ) ? mb_strlen( $possibility ) - 4 : mb_strlen(
$possibility );
- $class = 'class="words"';
+ $class = 'words';
if ( $this->mBeingCorrected &&
!empty( $value ) ) {
if ( $value ==
$possibility ||
( preg_match(
'`^' . preg_quote( $value, '`' ) . ' \(i\)$`i', $possibility ) ) ||
(
!$this->mCaseSensitive && preg_match( '`^' . preg_quote( $value, '`' ) . '$`i',
$possibility ) )
) {
$state =
'right';
- $title =
'title="' . wfMessage( 'quiz_colorRight' )->escaped() . '"';
+ $title =
wfMessage( 'quiz_colorRight' )->escaped();
} else {
$state =
'wrong';
- $title =
'title="' . wfMessage( 'quiz_colorWrong' )->escaped() . '"';
+ $title =
wfMessage( 'quiz_colorWrong' )->escaped();
}
}
}
@@ -428,30 +432,46 @@
}
}
if ( $this->mBeingCorrected ) {
- $a_inputBeg .= $possibility . '<br />';
+ $poss .= $possibility . '<br />';
}
}
- $value = empty( $value ) ? '' : 'value="' .
str_replace( '"', '"', $value ) . '"';
+ $value = empty( $value ) ? '' : str_replace( '"',
'"', $value );
if ( $this->mBeingCorrected ) {
- $a_inputBeg.= '</span>';
- $a_inputEnd = '</a>';
- $big = '<em>▼</em>';
+ $big = '▼';
+ $bigDisplay = ' ';
}
}
if ( $state == 'error' || $this->mBeingCorrected ) {
global $wgContLang;
$border = $wgContLang->isRTL() ? 'border-right' :
'border-left';
- $style = 'style="' . $border . ':3px solid ' .
Quiz::getColor( $state ) . ';"';
+ $style = $border . ':3px solid ' . Quiz::getColor(
$state ) . ';';
$this->setState( empty( $value ) ? 'new_NA' : $state );
if ( $state == 'error' ) {
$size = '';
$maxlength = '';
- $disabled = 'disabled="disabled"';
- $title = 'title="' . wfMessage(
'quiz_colorError' )->escaped() . '"';
+ $disabled = 'disabled';
+ $title = wfMessage( 'quiz_colorError'
)->escaped();
}
}
- return $output = $a_inputBeg . '<span ' . $style . '>' .
- '<input $class type="text" name="' . $wqInputId
. '" ' . $title . ' ' . $size . ' ' . $maxlength . ' ' . $value . ' ' .
$disabled . ' autocomplete="off" />' .
- $big . '</span>' . $a_inputEnd;
+ $name = $wqInputId;
+
+ $temp = $templateParser->processTemplate(
+ 'Answer',
+ array(
+ 'style' => $style,
+ 'title' => $title,
+ 'class' => $class,
+ 'value' => $value,
+ 'correction' => $this->mBeingCorrected,
+ 'possibility' => $poss,
+ 'disabled' => $disabled,
+ 'size' => $size,
+ 'big' => $big,
+ 'maxlength' => $maxlength,
+ 'name' => $name,
+ 'bigDisplay' => $bigDisplay,
+ )
+ );
+ return $temp;
}
}
diff --git a/templates/Answer.mustache b/templates/Answer.mustache
new file mode 100644
index 0000000..9f1082e
--- /dev/null
+++ b/templates/Answer.mustache
@@ -0,0 +1,14 @@
+<div style="display:inline-block">
+ {{#if correction}}
+ <a class="input" href="#nogo">
+ <span class="correction">{{{ possibility }}}
+ </span>
+ {{/if}} <span style="{{ style }}">
+ <input type="text" name="{{ name }}" title="{{
title }}" {{ disabled }} size="{{ size }}" maxlength="{{ maxlength }}"
autocomplete="off" value="{{ value }}" />
+ <em style="{{ bigDisplay }}">{{ big }}
+ </em>
+ </span>
+ {{#if answer.corrected}}
+ </a>
+ {{/if}}
+</div>
--
To view, visit https://gerrit.wikimedia.org/r/344726
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie9641d58db4c0380ce928b930fbb3725d830e6bb
Gerrit-PatchSet: 19
Gerrit-Project: mediawiki/extensions/Quiz
Gerrit-Branch: master
Gerrit-Owner: Harjotsingh <[email protected]>
Gerrit-Reviewer: Fomafix <[email protected]>
Gerrit-Reviewer: Harjotsingh <[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