MediaWiki
1.34.0
ResourceLoaderLessVarFileModule.php
Go to the documentation of this file.
1
<?php
27
class
ResourceLoaderLessVarFileModule
extends
ResourceLoaderFileModule
{
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
71
protected
function
getMessageBlob
(
ResourceLoaderContext
$context
) {
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
95
protected
function
getLessVars
(
ResourceLoaderContext
$context
) {
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
}
ResourceLoaderLessVarFileModule
Module augmented with context-specific LESS variables.
Definition:
ResourceLoaderLessVarFileModule.php:27
ResourceLoaderContext
Context object that contains information about the state of a specific ResourceLoader web request.
Definition:
ResourceLoaderContext.php:33
ResourceLoaderLessVarFileModule\$lessVariables
$lessVariables
Definition:
ResourceLoaderLessVarFileModule.php:28
ResourceLoaderLessVarFileModule\getLessVars
getLessVars(ResourceLoaderContext $context)
Get language-specific LESS variables for this module.
Definition:
ResourceLoaderLessVarFileModule.php:95
ResourceLoaderFileModule
Module based on local JavaScript/CSS files.
Definition:
ResourceLoaderFileModule.php:35
$blob
$blob
Definition:
testCompression.php:65
ResourceLoaderLessVarFileModule\__construct
__construct( $options=[], $localBasePath=null, $remoteBasePath=null)
Constructs a new module from an options array.List of options; if not given or empty,...
Definition:
ResourceLoaderLessVarFileModule.php:33
ResourceLoaderLessVarFileModule\excludeMessagesFromBlob
excludeMessagesFromBlob( $blob, $exclusions)
Exclude a set of messages from a JSON string representation.
Definition:
ResourceLoaderLessVarFileModule.php:59
ResourceLoaderFileModule\$localBasePath
string $localBasePath
Local base path, see __construct()
Definition:
ResourceLoaderFileModule.php:38
$context
$context
Definition:
load.php:45
ResourceLoaderLessVarFileModule\getMessageBlob
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.1.27 string|null JSON blob or null if module has no messages
Definition:
ResourceLoaderLessVarFileModule.php:71
ResourceLoaderFileModule\$remoteBasePath
string $remoteBasePath
Remote base path, see __construct()
Definition:
ResourceLoaderFileModule.php:41
ResourceLoaderLessVarFileModule\getMessages
getMessages()
Gets list of message keys used by this module.array List of message keys
Definition:
ResourceLoaderLessVarFileModule.php:47
ResourceLoaderLessVarFileModule\wrapAndEscapeMessage
static wrapAndEscapeMessage( $msg)
Takes a message and wraps it in quotes for compatibility with LESS parser (ModifyVars) method so that...
Definition:
ResourceLoaderLessVarFileModule.php:85
includes
resourceloader
ResourceLoaderLessVarFileModule.php
Generated on Thu Dec 19 2019 14:54:45 for MediaWiki by
1.8.16