X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTemplateParser.php;h=470a75c4b9820878bf81b31b05de325960c2b1a6;hb=1a04abebcbb37e6ac5415c4692522f35147f1fff;hp=d6b101b26d0b1216432496d1df12affd81d99460;hpb=6c4601cfbde285ece65aecddcdad2585be418521;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/TemplateParser.php b/includes/TemplateParser.php index d6b101b26d..470a75c4b9 100644 --- a/includes/TemplateParser.php +++ b/includes/TemplateParser.php @@ -1,4 +1,6 @@ templateDir = $templateDir ? $templateDir : __DIR__ . '/templates'; + $this->templateDir = $templateDir ?: __DIR__ . '/templates'; $this->forceRecompile = $forceRecompile; } @@ -49,7 +51,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 +81,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]; } @@ -96,15 +100,13 @@ class TemplateParser { $fastHash = md5( $fileContents ); // Fetch a secret key for building a keyed hash of the PHP code - $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); + $config = MediaWikiServices::getInstance()->getMainConfig(); $secretKey = $config->get( 'SecretKey' ); 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 ) { @@ -170,13 +172,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', - ) + ] ); } @@ -186,10 +188,10 @@ class TemplateParser { * @code * echo $templateParser->processTemplate( * 'ExampleTemplate', - * array( + * [ * 'username' => $user->getName(), * 'message' => 'Hello!' - * ) + * ] * ); * @endcode * @param string $templateName The name of the template @@ -197,7 +199,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 ); }