[MediaWiki-commits] [Gerrit] mediawiki...Quiz[master]: Put Html code of Answer in Question.php into mustache template
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 = ''; $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 ||
[MediaWiki-commits] [Gerrit] mediawiki...Quiz[master]: Put Html code of Answer in Question.php into mustache template
Harjotsingh has uploaded a new change for review. ( 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 Bug:T161318 Change-Id: Ie9641d58db4c0380ce928b930fbb3725d830e6bb --- M Question.php A templates/Answer.mustache 2 files changed, 44 insertions(+), 20 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Quiz refs/changes/26/344726/1 diff --git a/Question.php b/Question.php index 109c563..ebc723d 100755 --- a/Question.php +++ b/Question.php @@ -359,26 +359,31 @@ 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' ); + $bigDisplay = 'display: none'; //For hiding down arrow + if ( $this->mBeingCorrected ) { $value = trim( $this->mRequest->getVal( $wqInputId ) ); - $a_inputBeg = ''; $state = 'NA'; - $title = 'title="' . wfMessage( 'quiz_colorNA' )->escaped() . '"'; + $a_inputBeg = ''; + $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 +404,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="' .