From c235e0717e275b7584983577dcf00971d4c40a7c Mon Sep 17 00:00:00 2001 From: S Page Date: Mon, 6 Jul 2015 18:32:21 -0700 Subject: [PATCH] Support mustache partials in server-side templates This is sufficient to make https://gerrit.wikimedia.org/r/#/c/223165/ work. It hardcodes .mustache as the extension, but so does existing getTemplateFilename(). Bug: T97188 Change-Id: Id588ae9b43b13fcf35ebd285c826dd502ac424ec --- includes/TemplateParser.php | 4 +++- tests/phpunit/data/templates/bad_partial.mustache | 1 + tests/phpunit/data/templates/has_partial.mustache | 1 + tests/phpunit/includes/TemplateParserTest.php | 15 ++++++++++++++- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/data/templates/bad_partial.mustache create mode 100644 tests/phpunit/data/templates/has_partial.mustache diff --git a/includes/TemplateParser.php b/includes/TemplateParser.php index d53d593f77..f0a1ebb0c1 100644 --- a/includes/TemplateParser.php +++ b/includes/TemplateParser.php @@ -173,7 +173,9 @@ class TemplateParser { array( // Do not add more flags here without discussion. // If you do add more flags, be sure to update unit tests as well. - 'flags' => LightnCandy::FLAG_ERROR_EXCEPTION + 'flags' => LightnCandy::FLAG_ERROR_EXCEPTION, + 'basedir' => $this->templateDir, + 'fileext' => '.mustache', ) ); } diff --git a/tests/phpunit/data/templates/bad_partial.mustache b/tests/phpunit/data/templates/bad_partial.mustache new file mode 100644 index 0000000000..d2767f0fcc --- /dev/null +++ b/tests/phpunit/data/templates/bad_partial.mustache @@ -0,0 +1 @@ +Partial {{>nonexistenttemplate}} in here diff --git a/tests/phpunit/data/templates/has_partial.mustache b/tests/phpunit/data/templates/has_partial.mustache new file mode 100644 index 0000000000..504387a4a1 --- /dev/null +++ b/tests/phpunit/data/templates/has_partial.mustache @@ -0,0 +1 @@ +Partial {{>foobar_args}} in here diff --git a/tests/phpunit/includes/TemplateParserTest.php b/tests/phpunit/includes/TemplateParserTest.php index 81854ff322..3b37f4a46a 100644 --- a/tests/phpunit/includes/TemplateParserTest.php +++ b/tests/phpunit/includes/TemplateParserTest.php @@ -57,7 +57,20 @@ class TemplateParserTest extends MediaWikiTestCase { array(), false, 'RuntimeException', - ) + ), + array( + 'has_partial', + array( + 'planet' => 'world', + ), + "Partial hello world!\n in here\n", + ), + array( + 'bad_partial', + array(), + false, + 'Exception', + ), ); } } -- 2.20.1