MediaWiki REL1_34
ResourceLoaderLessVarFileModule.php
Go to the documentation of this file.
1<?php
28 protected $lessVariables = [];
29
33 public function __construct(
34 $options = [],
35 $localBasePath = null,
36 $remoteBasePath = null
37 ) {
38 if ( isset( $options['lessMessages'] ) ) {
39 $this->lessVariables = $options['lessMessages'];
40 }
41 parent::__construct( $options, $localBasePath, $remoteBasePath );
42 }
43
47 public function getMessages() {
48 // Overload so MessageBlobStore can detect updates to messages and purge as needed.
49 return array_merge( $this->messages, $this->lessVariables );
50 }
51
59 protected function excludeMessagesFromBlob( $blob, $exclusions ) {
60 $data = json_decode( $blob, true );
61 // unset the LESS variables so that they are not forwarded to JavaScript
62 foreach ( $exclusions as $key ) {
63 unset( $data[$key] );
64 }
65 return (object)$data;
66 }
67
72 $blob = parent::getMessageBlob( $context );
73 return json_encode( $this->excludeMessagesFromBlob( $blob, $this->lessVariables ) );
74 }
75
85 private static function wrapAndEscapeMessage( $msg ) {
86 return str_replace( "'", "\'", CSSMin::serializeStringValue( $msg ) );
87 }
88
96 $blob = parent::getMessageBlob( $context );
97 $lessMessages = $this->excludeMessagesFromBlob( $blob, $this->messages );
98
99 $vars = parent::getLessVars( $context );
100 foreach ( $lessMessages as $msgKey => $value ) {
101 $vars['msg-' . $msgKey] = self::wrapAndEscapeMessage( $value );
102 }
103 return $vars;
104 }
105}
static serializeStringValue( $value)
Serialize a string (escape and quote) for use as a CSS string value.
Definition CSSMin.php:190
Context object that contains information about the state of a specific ResourceLoader web request.
Module based on local JavaScript/CSS files.
string $localBasePath
Local base path, see __construct()
string $remoteBasePath
Remote base path, see __construct()
Module augmented with context-specific LESS variables.
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.1.27 string|null JSON blob or null if module has no messages
__construct( $options=[], $localBasePath=null, $remoteBasePath=null)
Constructs a new module from an options array.Below is a description for the $options array: [ //...
getMessages()
Gets list of message keys used by this module.array List of message keys
static wrapAndEscapeMessage( $msg)
Takes a message and wraps it in quotes for compatibility with LESS parser (ModifyVars) method so that...
excludeMessagesFromBlob( $blob, $exclusions)
Exclude a set of messages from a JSON string representation.
getLessVars(ResourceLoaderContext $context)
Get language-specific LESS variables for this module.
$context
Definition load.php:45