dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge "Fix localization of time in Turkish"
[lhc/web/wiklou.git]
/
includes
/
TemplateParser.php
diff --git
a/includes/TemplateParser.php
b/includes/TemplateParser.php
index
2759ff9
..
2293dab
100644
(file)
--- a/
includes/TemplateParser.php
+++ b/
includes/TemplateParser.php
@@
-38,6
+38,13
@@
class TemplateParser {
*/
protected $forceRecompile = false;
*/
protected $forceRecompile = false;
+ /**
+ * @var int Compilation flags passed to LightnCandy
+ */
+ // Do not add more flags here without discussion.
+ // If you do add more flags, be sure to update unit tests as well.
+ protected $compileFlags = LightnCandy::FLAG_ERROR_EXCEPTION;
+
/**
* @param string $templateDir
* @param bool $forceRecompile
/**
* @param string $templateDir
* @param bool $forceRecompile
@@
-47,6
+54,18
@@
class TemplateParser {
$this->forceRecompile = $forceRecompile;
}
$this->forceRecompile = $forceRecompile;
}
+ /**
+ * Enable/disable the use of recursive partials.
+ * @param bool $enable
+ */
+ public function enableRecursivePartials( $enable ) {
+ if ( $enable ) {
+ $this->compileFlags = $this->compileFlags | LightnCandy::FLAG_RUNTIMEPARTIAL;
+ } else {
+ $this->compileFlags = $this->compileFlags & ~LightnCandy::FLAG_RUNTIMEPARTIAL;
+ }
+ }
+
/**
* Constructs the location of the the source Mustache template
* @param string $templateName The name of the template
/**
* Constructs the location of the the source Mustache template
* @param string $templateName The name of the template
@@
-73,11
+92,13
@@
class TemplateParser {
* @throws RuntimeException
*/
protected function getTemplate( $templateName ) {
* @throws RuntimeException
*/
protected function getTemplate( $templateName ) {
+ $templateKey = $templateName . '|' . $this->compileFlags;
+
// If a renderer has already been defined for this template, reuse it
// If a renderer has already been defined for this template, reuse it
- if ( isset( $this->renderers[$template
Name
] ) &&
- is_callable( $this->renderers[$template
Name
] )
+ if ( isset( $this->renderers[$template
Key
] ) &&
+ is_callable( $this->renderers[$template
Key
] )
) {
) {
- return $this->renderers[$template
Name
];
+ return $this->renderers[$template
Key
];
}
$filename = $this->getTemplateFilename( $templateName );
}
$filename = $this->getTemplateFilename( $templateName );
@@
-90,7
+111,7
@@
class TemplateParser {
$fileContents = file_get_contents( $filename );
// Generate a quick hash for cache invalidation
$fileContents = file_get_contents( $filename );
// Generate a quick hash for cache invalidation
- $fastHash = md5( $fileContents );
+ $fastHash = md5( $
this->compileFlags . '|' . $
fileContents );
// Fetch a secret key for building a keyed hash of the PHP code
$config = MediaWikiServices::getInstance()->getMainConfig();
// Fetch a secret key for building a keyed hash of the PHP code
$config = MediaWikiServices::getInstance()->getMainConfig();
@@
-127,7
+148,7
@@
class TemplateParser {
if ( !is_callable( $renderer ) ) {
throw new RuntimeException( "Requested template, {$templateName}, is not callable" );
}
if ( !is_callable( $renderer ) ) {
throw new RuntimeException( "Requested template, {$templateName}, is not callable" );
}
- $this->renderers[$template
Name
] = $renderer;
+ $this->renderers[$template
Key
] = $renderer;
return $renderer;
}
return $renderer;
}
@@
-168,9
+189,7
@@
class TemplateParser {
return LightnCandy::compile(
$code,
[
return LightnCandy::compile(
$code,
[
- // 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' => $this->compileFlags,
'basedir' => $this->templateDir,
'fileext' => '.mustache',
]
'basedir' => $this->templateDir,
'fileext' => '.mustache',
]