X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTemplateParser.php;h=8ce342020f1c714b2cd5a34671971219c2094fe8;hb=9d9467c3a8ef2aff3c0bdfc916603232b6a2e200;hp=3de70fa2a21b34c197a9d0a7e03a04bb18b5cd64;hpb=a9ae91c3621d2e081a664bcb97bd853cfb2995fb;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/TemplateParser.php b/includes/TemplateParser.php index 3de70fa2a2..8ce342020f 100644 --- a/includes/TemplateParser.php +++ b/includes/TemplateParser.php @@ -41,7 +41,7 @@ class TemplateParser { * @param boolean $forceRecompile */ public function __construct( $templateDir = null, $forceRecompile = false ) { - $this->templateDir = $templateDir ? $templateDir : __DIR__ . '/templates'; + $this->templateDir = $templateDir ?: __DIR__ . '/templates'; $this->forceRecompile = $forceRecompile; } @@ -49,7 +49,7 @@ class TemplateParser { * Constructs the location of the the source Mustache template * @param string $templateName The name of the template * @return string - * @throws UnexpectedValueException Disallows upwards directory traversal via $templateName + * @throws UnexpectedValueException If $templateName attempts upwards directory traversal */ protected function getTemplateFilename( $templateName ) { // Prevent upwards directory traversal using same methods as Title::secureAndSplit @@ -79,7 +79,9 @@ class TemplateParser { */ protected function getTemplate( $templateName ) { // If a renderer has already been defined for this template, reuse it - if ( isset( $this->renderers[$templateName] ) && is_callable( $this->renderers[$templateName] ) ) { + if ( isset( $this->renderers[$templateName] ) && + is_callable( $this->renderers[$templateName] ) + ) { return $this->renderers[$templateName]; } @@ -101,10 +103,8 @@ class TemplateParser { if ( $secretKey ) { // See if the compiled PHP code is stored in cache. - // CACHE_ACCEL throws an exception if no suitable object cache is present, so fall - // back to CACHE_ANYTHING. - $cache = ObjectCache::newAccelerator( array(), CACHE_ANYTHING ); - $key = wfMemcKey( 'template', $templateName, $fastHash ); + $cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING ); + $key = $cache->makeKey( 'template', $templateName, $fastHash ); $code = $this->forceRecompile ? null : $cache->get( $key ); if ( !$code ) { @@ -130,7 +130,8 @@ class TemplateParser { if ( !is_callable( $renderer ) ) { throw new RuntimeException( "Requested template, {$templateName}, is not callable" ); } - return $this->renderers[$templateName] = $renderer; + $this->renderers[$templateName] = $renderer; + return $renderer; } /** @@ -172,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', ) ); }