X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTemplateParser.php;h=8ce342020f1c714b2cd5a34671971219c2094fe8;hb=f43fa6f4f0e2cb60b8543daad661b48a3e0653a9;hp=3c62c14002843040dfc85528a225b1263ca778d5;hpb=9fce4b73ff2bb7d9377d6a85e8d4188e0de46433;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/TemplateParser.php b/includes/TemplateParser.php index 3c62c14002..a1e6d5b5a7 100644 --- a/includes/TemplateParser.php +++ b/includes/TemplateParser.php @@ -38,10 +38,10 @@ class TemplateParser { /** * @param string $templateDir - * @param boolean $forceRecompile + * @param bool $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 @@ -103,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( 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 ) { @@ -172,13 +170,13 @@ class TemplateParser { } return LightnCandy::compile( $code, - 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, 'basedir' => $this->templateDir, 'fileext' => '.mustache', - ) + ] ); } @@ -188,10 +186,10 @@ class TemplateParser { * @code * echo $templateParser->processTemplate( * 'ExampleTemplate', - * array( + * [ * 'username' => $user->getName(), * 'message' => 'Hello!' - * ) + * ] * ); * @endcode * @param string $templateName The name of the template @@ -199,7 +197,7 @@ class TemplateParser { * @param array $scopes * @return string */ - public function processTemplate( $templateName, $args, array $scopes = array() ) { + public function processTemplate( $templateName, $args, array $scopes = [] ) { $template = $this->getTemplate( $templateName ); return call_user_func( $template, $args, $scopes ); }