<?php
/**
- * Abstraction for ResourceLoader modules.
- *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
/**
* Abstraction for ResourceLoader modules, with name registration and maxage functionality.
+ *
+ * @ingroup ResourceLoader
+ * @since 1.17
*/
abstract class ResourceLoaderModule implements LoggerAwareInterface {
/** @var Config */
* @param ResourceLoaderContext $context
* @return bool
*/
- public function getFlip( $context ) {
+ public function getFlip( ResourceLoaderContext $context ) {
return MediaWikiServices::getInstance()->getContentLanguage()->getDir() !==
$context->getDirection();
}
/**
* Get JS representing deprecation information for the current module if available
*
+ * @param ResourceLoaderContext|null $context Missing $context is deprecated in 1.34
* @return string JavaScript code
*/
- public function getDeprecationInformation() {
+ public function getDeprecationInformation( ResourceLoaderContext $context = null ) {
+ if ( $context === null ) {
+ wfDeprecated( __METHOD__ . ' without a ResourceLoader context', '1.34' );
+ }
$deprecationInfo = $this->deprecated;
if ( $deprecationInfo ) {
$name = $this->getName();
if ( is_string( $deprecationInfo ) ) {
$warning .= "\n" . $deprecationInfo;
}
- return 'mw.log.warn(' . ResourceLoader::encodeJsonForScript( $warning ) . ');';
+ if ( $context === null ) {
+ return 'mw.log.warn(' . ResourceLoader::encodeJsonForScript( $warning ) . ');';
+ }
+ return 'mw.log.warn(' . $context->encodeJson( $warning ) . ');';
} else {
return '';
}
* @return array
*/
final protected function buildContent( ResourceLoaderContext $context ) {
- $rl = $context->getResourceLoader();
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
$statStart = microtime( true );
}
// Wrap styles into @media groups as needed and flatten into a numerical array
$styles = [
- 'css' => $rl->makeCombinedStyles( $stylePairs )
+ 'css' => ResourceLoader::makeCombinedStyles( $stylePairs )
];
}
}