jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/339827 )

Change subject: Start implementing Quiz generation using TemplateParser
......................................................................


Start implementing Quiz generation using TemplateParser

As noted in T152293 TemplateParser should be used instead of raw HTML.
This first commit will start using TemplateParser for a part of the Quiz
element. It is still needed to transform into templates the Questions and
the Setting element. As a result of this initial conversion I was able to drop
the use of an addittional CSS class (hideCorrection).

Bug: T152293
Change-Id: I7d1ae881d6d2c5b583509d5fa2e7f758715b13d5
---
M Quiz.class.php
M modules/ext.quiz.css
A templates/Quiz.mustache
3 files changed, 46 insertions(+), 33 deletions(-)

Approvals:
  jenkins-bot: Verified
  Mvolz: Looks good to me, approved



diff --git a/Quiz.class.php b/Quiz.class.php
index a04e8a0..ff2fa0a 100755
--- a/Quiz.class.php
+++ b/Quiz.class.php
@@ -112,6 +112,7 @@
         * @return string
         */
        function parseQuiz( $input ) {
+
                // Ouput the style and the script to the header once for all.
                if ( $this->mQuizId == 0 ) {
                        global $wgOut;
@@ -122,10 +123,8 @@
                $input = $this->parseQuestions( $this->parseIncludes( $input ) 
);
 
                // Generates the output.
-               // TODO: Use TemplateParser instead of HTML tags in code to 
improve code readability in the future
-               $classHide = ( $this->mBeingCorrected ) ? '' : ' 
class="hideCorrection"';
-               $output  = '<div class="quiz">' . "\n";
-               $output .= '<form id="quiz' . $this->mQuizId . '" ' . 
$classHide . ' method="post" action="#quiz' . $this->mQuizId . '">' . "\n";
+
+               $templateParser = new TemplateParser(  __DIR__ . '/templates' );
 
                // Determine the content of the settings table.
                $settings = array_fill( 0, 4, '' );
@@ -173,33 +172,27 @@
                        }
                }
 
-               if ( !empty( $settingsTable ) ) {
-                       $output .= '<table class="settings">' . "\n";
-                       $output .= $settingsTable . "\n";
-                       $output .= '</table>' . "\n";
-               }
-               $output .= '<input type="hidden" name="quizId" value="' . 
$this->mQuizId . '" />' . "\n";
-
-               $output .= '<div class="quizQuestions">' . "\n";
-               $output .= $input . "\n";
-               $output .= '</div>' . "\n";
-
-               $output .= '<p><input type="submit" value="' . wfMessage( 
'quiz_correction' )->escaped() . '"/>';
-               if ( $this->mBeingCorrected ) {
-                       $output .= '<input class="reset" type="submit" value="' 
.
-                               wfMessage( 'quiz_reset' )->escaped() . '" 
style="display: none;" />';
-               }
-               $output .= '</p>' . "\n";
-
-               $output .= '<span class="correction">';
-               $output .= wfMessage( 'quiz_score' )->rawParams(
+               $quiz_score = wfMessage( 'quiz_score' )->rawParams(
                        '<span class="score">' . $this->mScore . '</span>',
-                       '<span class="total">' . $this->mTotal . '</span>'
-               )->escaped();
-               $output .= '</span>' . "\n";
+                       '<span class="total">' . $this->mTotal . 
'</span>')->escaped();
 
-               $output .= '</form>' . "\n";
-               $output .= '</div>' . "\n";
+               return $templateParser->processTemplate(
+                       'Quiz',
+                       array(
+                               'quiz' => array(
+                                       'id' => $this->mQuizId,
+                                       'beingCorrected' => 
$this->mBeingCorrected,
+                                       'questions' => $input
+                               ),
+                               'settingsTable' => $settingsTable,
+                               'wfMessage' => array(
+                                       'quiz_correction' => wfMessage( 
'quiz_correction' )->escaped(),
+                                       'quiz_reset' => wfMessage( 'quiz_reset' 
)->escaped(),
+                                       'quiz_score' => $quiz_score
+                               )
+                       )
+               );
+
                return $output;
        }
 
diff --git a/modules/ext.quiz.css b/modules/ext.quiz.css
index c03834c..2060bcb 100644
--- a/modules/ext.quiz.css
+++ b/modules/ext.quiz.css
@@ -10,10 +10,6 @@
        background-color: transparent;
 }
 
-.quiz .hideCorrection .correction {
-       display: none;
-}
-
 .quiz .settings td {
        padding: 0.1em 0.4em 0.1em 0.4em;
 }
diff --git a/templates/Quiz.mustache b/templates/Quiz.mustache
new file mode 100644
index 0000000..3ad1d03
--- /dev/null
+++ b/templates/Quiz.mustache
@@ -0,0 +1,24 @@
+<div class="quiz">
+       <form id="quiz{{ quiz.id }}" method="post" action="#quiz{{ quiz.id }}">
+               {{#settingsTable}}
+                       <table class="settings">
+                               {{{ . }}}
+                       </table>
+               {{/settingsTable}}
+               <input type="hidden" name="quizId" value="{{ quiz.id }}" />
+               <div class="quizQuestions">
+                       {{{ quiz.questions }}}
+               </div>
+               <p>
+                       <input type="submit" value="{{ 
wfMessage.quiz_correction }}"/>
+                       {{#if quiz.beingCorrected }}
+                               <input class="reset" type="submit" value="{{ 
wfMessage.quiz_reset }}" style="display: none;">
+                       {{/if}}
+               </p>
+               {{#if quiz.beingCorrected }}
+                       <span class="correction">
+                               {{{ wfMessage.quiz_score }}}
+                       </span>
+               {{/if}}
+       </form>
+</div>
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/339827
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7d1ae881d6d2c5b583509d5fa2e7f758715b13d5
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Quiz
Gerrit-Branch: master
Gerrit-Owner: Crisbal <bld.cris...@gmail.com>
Gerrit-Reviewer: Crisbal <bld.cris...@gmail.com>
Gerrit-Reviewer: Mvolz <mv...@wikimedia.org>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to