22use Wikimedia\Minify\CSSMin;
45 if ( isset( $options[
'lessMessages'] ) ) {
46 $this->lessVariables = $options[
'lessMessages'];
56 return array_merge( $this->messages, $this->lessVariables );
66 private function pluckFromMessageBlob( $blob, array $allowed ): array {
67 $data = $blob ? json_decode( $blob, true ) : [];
70 return array_intersect_key( $data, array_fill_keys( $allowed,
true ) );
77 $blob = parent::getMessageBlob( $context );
83 return json_encode( (
object)$this->pluckFromMessageBlob( $blob, $this->messages ) );
107 private static function wrapAndEscapeMessage( $msg ) {
108 return str_replace(
"'",
"\'", CSSMin::serializeStringValue( $msg ) );
120 $vars = parent::getLessVars( $context );
122 $blob = parent::getMessageBlob( $context );
123 $messages = $this->pluckFromMessageBlob( $blob, $this->lessVariables );
130 foreach ( $this->lessVariables as $msgKey ) {
131 $vars[
'msg-' . $msgKey] = self::wrapAndEscapeMessage( $messages[$msgKey] ??
"⧼{$msgKey}⧽" );
Context object that contains information about the state of a specific ResourceLoader web request.