Fix missing LightnCandy in MW 1.34

This commit is contained in:
lkucharczyk 2020-09-27 13:51:59 +02:00
parent b82ea2d518
commit 05e55672a6

View file

@ -2,17 +2,16 @@
namespace PortableInfobox\Helpers;
use LightnCandy\LightnCandy;
use MediaWiki\MediaWikiServices;
use MediaWiki\Logger\LoggerFactory;
class PortableInfoboxTemplateEngine {
const CACHE_TTL = 86400;
const TYPE_NOT_SUPPORTED_MESSAGE = 'portable-infobox-render-not-supported-type';
const COMPILE_FLAGS = LightnCandy::FLAG_BESTPERFORMANCE | LightnCandy::FLAG_PARENT;
private static $cache = [];
private static $compileFlags;
private static $lightncandy;
private static $memcache;
protected static $templates = [
@ -31,6 +30,11 @@ class PortableInfoboxTemplateEngine {
];
public function __construct() {
if ( !isset( self::$lightncandy ) ) {
self::$lightncandy = class_exists( '\LightnCandy\LightnCandy' ) ? \LightnCandy\LightnCandy::class : \LightnCandy::class;
self::$compileFlags = self::$lightncandy::FLAG_BESTPERFORMANCE | self::$lightncandy::FLAG_PARENT;
}
if ( !isset( self::$memcache ) ) {
self::$memcache = MediaWikiServices::getInstance()->getMainWANObjectCache();
}
@ -71,18 +75,18 @@ class PortableInfoboxTemplateEngine {
$template = self::$memcache->getWithSetCallback(
$cachekey, self::CACHE_TTL, function () use ( $path ) {
// @see https://github.com/wikimedia/mediawiki-vendor/tree/master/zordius/lightncandy
return LightnCandy::compile( file_get_contents( $path ), [
'flags' => self::COMPILE_FLAGS
return self::$lightncandy::compile( file_get_contents( $path ), [
'flags' => self::$compileFlags
] );
}
);
} else {
$template = LightnCandy::compile( file_get_contents( $path ), [
'flags' => self::COMPILE_FLAGS
$template = self::$lightncandy::compile( file_get_contents( $path ), [
'flags' => self::$compileFlags
] );
}
self::$cache[$type] = LightnCandy::prepare( $template );
self::$cache[$type] = self::$lightncandy::prepare( $template );
}
return self::$cache[$type];