MediaWiki REL1_32
ResourceLoaderLessVarFileModule.php
Go to the documentation of this file.
1<?php
2
7 protected $lessVariables = [];
8
12 public function __construct(
13 $options = [],
14 $localBasePath = null,
15 $remoteBasePath = null
16 ) {
17 if ( isset( $options['lessMessages'] ) ) {
18 $this->lessVariables = $options['lessMessages'];
19 }
20 parent::__construct( $options, $localBasePath, $remoteBasePath );
21 }
22
26 public function getMessages() {
27 // Overload so MessageBlobStore can detect updates to messages and purge as needed.
28 return array_merge( $this->messages, $this->lessVariables );
29 }
30
38 protected function excludeMessagesFromBlob( $blob, $exclusions ) {
39 $data = json_decode( $blob, true );
40 // unset the LESS variables so that they are not forwarded to JavaScript
41 foreach ( $exclusions as $key ) {
42 unset( $data[$key] );
43 }
44 return (object)$data;
45 }
46
51 $blob = parent::getMessageBlob( $context );
52 return json_encode( $this->excludeMessagesFromBlob( $blob, $this->lessVariables ) );
53 }
54
64 private static function wrapAndEscapeMessage( $msg ) {
65 return str_replace( "'", "\'", CSSMin::serializeStringValue( $msg ) );
66 }
67
75 $blob = parent::getMessageBlob( $context );
76 $lessMessages = $this->excludeMessagesFromBlob( $blob, $this->messages );
77
78 $vars = parent::getLessVars( $context );
79 foreach ( $lessMessages as $msgKey => $value ) {
80 $vars['msg-' . $msgKey] = self::wrapAndEscapeMessage( $value );
81 }
82 return $vars;
83 }
84}
Object passed around to modules which contains information about the state of a specific loader reque...
ResourceLoader module based on local JavaScript/CSS files.
string $localBasePath
Local base path, see __construct()
string $remoteBasePath
Remote base path, see __construct()
Subclass with context specific LESS variables.
getMessageBlob(ResourceLoaderContext $context)
@inheritDoc
__construct( $options=[], $localBasePath=null, $remoteBasePath=null)
@inheritDoc
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.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:2278
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:2050
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2885