2014-11-11 19:50:44 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Resource loader module for generated and embedded images.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @author Trevor Parscal
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resource loader module for generated and embedded images.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.25
|
|
|
|
|
*/
|
|
|
|
|
class ResourceLoaderImageModule extends ResourceLoaderModule {
|
|
|
|
|
|
2015-05-24 16:56:44 +00:00
|
|
|
protected $definition = null;
|
2015-04-07 16:02:46 +00:00
|
|
|
|
2014-11-11 19:50:44 +00:00
|
|
|
/**
|
|
|
|
|
* Local base path, see __construct()
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $localBasePath = '';
|
|
|
|
|
|
|
|
|
|
protected $origin = self::ORIGIN_CORE_SITEWIDE;
|
|
|
|
|
|
|
|
|
|
protected $images = array();
|
|
|
|
|
protected $variants = array();
|
2015-03-23 21:04:54 +00:00
|
|
|
protected $prefix = null;
|
2015-03-27 17:27:47 +00:00
|
|
|
protected $selectorWithoutVariant = '.{prefix}-{name}';
|
|
|
|
|
protected $selectorWithVariant = '.{prefix}-{name}-{variant}';
|
2014-12-10 23:31:48 +00:00
|
|
|
protected $targets = array( 'desktop', 'mobile' );
|
2014-11-11 19:50:44 +00:00
|
|
|
|
2015-05-25 14:04:57 +00:00
|
|
|
/** @var string Position on the page to load this module at */
|
|
|
|
|
protected $position = 'bottom';
|
|
|
|
|
|
2014-11-11 19:50:44 +00:00
|
|
|
/**
|
|
|
|
|
* Constructs a new module from an options array.
|
|
|
|
|
*
|
|
|
|
|
* @param array $options List of options; if not given or empty, an empty module will be
|
|
|
|
|
* constructed
|
|
|
|
|
* @param string $localBasePath Base path to prepend to all local paths in $options. Defaults
|
|
|
|
|
* to $IP
|
|
|
|
|
*
|
|
|
|
|
* Below is a description for the $options array:
|
|
|
|
|
* @par Construction options:
|
|
|
|
|
* @code
|
|
|
|
|
* array(
|
|
|
|
|
* // Base path to prepend to all local paths in $options. Defaults to $IP
|
|
|
|
|
* 'localBasePath' => [base path],
|
2015-04-07 16:02:46 +00:00
|
|
|
* // Path to JSON file that contains any of the settings below
|
|
|
|
|
* 'data' => [file path string]
|
2014-11-11 19:50:44 +00:00
|
|
|
* // CSS class prefix to use in all style rules
|
|
|
|
|
* 'prefix' => [CSS class prefix],
|
2015-03-23 21:04:54 +00:00
|
|
|
* // Alternatively: Format of CSS selector to use in all style rules
|
2015-03-27 17:27:47 +00:00
|
|
|
* 'selector' => [CSS selector template, variables: {prefix} {name} {variant}],
|
2015-03-23 21:04:54 +00:00
|
|
|
* // Alternatively: When using variants
|
2015-03-27 17:27:47 +00:00
|
|
|
* 'selectorWithoutVariant' => [CSS selector template, variables: {prefix} {name}],
|
|
|
|
|
* 'selectorWithVariant' => [CSS selector template, variables: {prefix} {name} {variant}],
|
2014-11-11 19:50:44 +00:00
|
|
|
* // List of variants that may be used for the image files
|
|
|
|
|
* 'variants' => array(
|
2015-05-24 16:56:44 +00:00
|
|
|
* [theme name] => array(
|
2014-11-11 19:50:44 +00:00
|
|
|
* [variant name] => array(
|
|
|
|
|
* 'color' => [color string, e.g. '#ffff00'],
|
2015-03-15 01:52:45 +00:00
|
|
|
* 'global' => [boolean, if true, this variant is available
|
|
|
|
|
* for all images of this type],
|
2014-11-11 19:50:44 +00:00
|
|
|
* ),
|
2015-05-24 16:56:44 +00:00
|
|
|
* ...
|
|
|
|
|
* ),
|
2015-03-27 17:27:47 +00:00
|
|
|
* ...
|
2014-11-11 19:50:44 +00:00
|
|
|
* ),
|
|
|
|
|
* // List of image files and their options
|
|
|
|
|
* 'images' => array(
|
2015-05-24 16:56:44 +00:00
|
|
|
* [theme name] => array(
|
2014-11-11 19:50:44 +00:00
|
|
|
* [file path string],
|
|
|
|
|
* [file path string] => array(
|
|
|
|
|
* 'name' => [image name string, defaults to file name],
|
2015-03-15 01:52:45 +00:00
|
|
|
* 'variants' => [array of variant name strings, variants
|
|
|
|
|
* available for this image],
|
2014-11-11 19:50:44 +00:00
|
|
|
* ),
|
2015-05-24 16:56:44 +00:00
|
|
|
* ...
|
|
|
|
|
* ),
|
2015-03-27 17:27:47 +00:00
|
|
|
* ...
|
2014-11-11 19:50:44 +00:00
|
|
|
* ),
|
|
|
|
|
* )
|
|
|
|
|
* @endcode
|
2015-03-30 16:51:10 +00:00
|
|
|
* @throws InvalidArgumentException
|
2014-11-11 19:50:44 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct( $options = array(), $localBasePath = null ) {
|
|
|
|
|
$this->localBasePath = self::extractLocalBasePath( $options, $localBasePath );
|
|
|
|
|
|
2015-04-07 16:02:46 +00:00
|
|
|
$this->definition = $options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse definition and external JSON data, if referenced.
|
|
|
|
|
*/
|
2015-05-24 16:56:44 +00:00
|
|
|
protected function loadFromDefinition() {
|
2015-04-07 16:02:46 +00:00
|
|
|
if ( $this->definition === null ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$options = $this->definition;
|
|
|
|
|
$this->definition = null;
|
|
|
|
|
|
|
|
|
|
if ( isset( $options['data'] ) ) {
|
|
|
|
|
$dataPath = $this->localBasePath . '/' . $options['data'];
|
|
|
|
|
$data = json_decode( file_get_contents( $dataPath ), true );
|
|
|
|
|
$options = array_merge( $data, $options );
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 21:04:54 +00:00
|
|
|
// Accepted combinations:
|
|
|
|
|
// * prefix
|
|
|
|
|
// * selector
|
|
|
|
|
// * selectorWithoutVariant + selectorWithVariant
|
|
|
|
|
// * prefix + selector
|
|
|
|
|
// * prefix + selectorWithoutVariant + selectorWithVariant
|
|
|
|
|
|
|
|
|
|
$prefix = isset( $options['prefix'] ) && $options['prefix'];
|
|
|
|
|
$selector = isset( $options['selector'] ) && $options['selector'];
|
|
|
|
|
$selectorWithoutVariant = isset( $options['selectorWithoutVariant'] ) && $options['selectorWithoutVariant'];
|
|
|
|
|
$selectorWithVariant = isset( $options['selectorWithVariant'] ) && $options['selectorWithVariant'];
|
|
|
|
|
|
|
|
|
|
if ( $selectorWithoutVariant && !$selectorWithVariant ) {
|
2015-03-30 16:51:10 +00:00
|
|
|
throw new InvalidArgumentException( "Given 'selectorWithoutVariant' but no 'selectorWithVariant'." );
|
2015-03-23 21:04:54 +00:00
|
|
|
}
|
|
|
|
|
if ( $selectorWithVariant && !$selectorWithoutVariant ) {
|
2015-03-30 16:51:10 +00:00
|
|
|
throw new InvalidArgumentException( "Given 'selectorWithVariant' but no 'selectorWithoutVariant'." );
|
2015-03-23 21:04:54 +00:00
|
|
|
}
|
|
|
|
|
if ( $selector && $selectorWithVariant ) {
|
2015-03-30 16:51:10 +00:00
|
|
|
throw new InvalidArgumentException( "Incompatible 'selector' and 'selectorWithVariant'+'selectorWithoutVariant' given." );
|
2015-03-23 21:04:54 +00:00
|
|
|
}
|
|
|
|
|
if ( !$prefix && !$selector && !$selectorWithVariant ) {
|
2015-03-30 16:51:10 +00:00
|
|
|
throw new InvalidArgumentException( "None of 'prefix', 'selector' or 'selectorWithVariant'+'selectorWithoutVariant' given." );
|
2014-11-11 19:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $options as $member => $option ) {
|
|
|
|
|
switch ( $member ) {
|
|
|
|
|
case 'images':
|
|
|
|
|
case 'variants':
|
|
|
|
|
if ( !is_array( $option ) ) {
|
2015-03-30 16:51:10 +00:00
|
|
|
throw new InvalidArgumentException(
|
2015-03-27 17:27:47 +00:00
|
|
|
"Invalid list error. '$option' given, array expected."
|
2014-11-11 19:50:44 +00:00
|
|
|
);
|
|
|
|
|
}
|
2015-05-24 16:56:44 +00:00
|
|
|
if ( !isset( $option['default'] ) ) {
|
|
|
|
|
// Backwards compatibility
|
|
|
|
|
$option = array( 'default' => $option );
|
|
|
|
|
}
|
|
|
|
|
foreach ( $option as $skin => $data ) {
|
|
|
|
|
if ( !is_array( $option ) ) {
|
|
|
|
|
throw new InvalidArgumentException(
|
|
|
|
|
"Invalid list error. '$option' given, array expected."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-11 19:50:44 +00:00
|
|
|
$this->{$member} = $option;
|
|
|
|
|
break;
|
|
|
|
|
|
2015-05-25 14:04:57 +00:00
|
|
|
case 'position':
|
|
|
|
|
$this->isPositionDefined = true;
|
2014-11-11 19:50:44 +00:00
|
|
|
case 'prefix':
|
2015-03-23 21:04:54 +00:00
|
|
|
case 'selectorWithoutVariant':
|
|
|
|
|
case 'selectorWithVariant':
|
2014-11-11 19:50:44 +00:00
|
|
|
$this->{$member} = (string)$option;
|
|
|
|
|
break;
|
2015-03-23 21:04:54 +00:00
|
|
|
|
|
|
|
|
case 'selector':
|
|
|
|
|
$this->selectorWithoutVariant = $this->selectorWithVariant = (string)$option;
|
2014-11-11 19:50:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get CSS class prefix used by this module.
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getPrefix() {
|
2015-05-23 17:06:06 +00:00
|
|
|
$this->loadFromDefinition();
|
2014-11-11 19:50:44 +00:00
|
|
|
return $this->prefix;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 21:04:54 +00:00
|
|
|
/**
|
|
|
|
|
* Get CSS selector templates used by this module.
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getSelectors() {
|
2015-05-23 17:06:06 +00:00
|
|
|
$this->loadFromDefinition();
|
2015-03-23 21:04:54 +00:00
|
|
|
return array(
|
|
|
|
|
'selectorWithoutVariant' => $this->selectorWithoutVariant,
|
|
|
|
|
'selectorWithVariant' => $this->selectorWithVariant,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 19:50:44 +00:00
|
|
|
/**
|
|
|
|
|
* Get a ResourceLoaderImage object for given image.
|
|
|
|
|
* @param string $name Image name
|
2015-06-05 22:38:06 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2014-11-11 19:50:44 +00:00
|
|
|
* @return ResourceLoaderImage|null
|
|
|
|
|
*/
|
2015-05-24 16:56:44 +00:00
|
|
|
public function getImage( $name, ResourceLoaderContext $context ) {
|
2015-05-23 17:06:06 +00:00
|
|
|
$this->loadFromDefinition();
|
2015-05-24 16:56:44 +00:00
|
|
|
$images = $this->getImages( $context );
|
2014-11-11 19:50:44 +00:00
|
|
|
return isset( $images[$name] ) ? $images[$name] : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get ResourceLoaderImage objects for all images.
|
2015-06-05 22:38:06 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2014-11-11 19:50:44 +00:00
|
|
|
* @return ResourceLoaderImage[] Array keyed by image name
|
|
|
|
|
*/
|
2015-05-24 16:56:44 +00:00
|
|
|
public function getImages( ResourceLoaderContext $context ) {
|
|
|
|
|
$skin = $context->getSkin();
|
2014-11-11 19:50:44 +00:00
|
|
|
if ( !isset( $this->imageObjects ) ) {
|
2015-05-23 17:06:06 +00:00
|
|
|
$this->loadFromDefinition();
|
2014-11-11 19:50:44 +00:00
|
|
|
$this->imageObjects = array();
|
2015-05-24 16:56:44 +00:00
|
|
|
}
|
|
|
|
|
if ( !isset( $this->imageObjects[ $skin ] ) ) {
|
|
|
|
|
$this->imageObjects[ $skin ] = array();
|
|
|
|
|
if ( !isset( $this->images[ $skin ] ) ) {
|
|
|
|
|
$this->images[ $skin ] = isset( $this->images[ 'default' ] ) ?
|
|
|
|
|
$this->images[ 'default' ] :
|
|
|
|
|
array();
|
|
|
|
|
}
|
|
|
|
|
foreach ( $this->images[ $skin ] as $name => $options ) {
|
2015-03-28 00:44:47 +00:00
|
|
|
$fileDescriptor = is_string( $options ) ? $options : $options['file'];
|
2014-11-11 19:50:44 +00:00
|
|
|
|
2015-03-27 17:27:47 +00:00
|
|
|
$allowedVariants = array_merge(
|
|
|
|
|
is_array( $options ) && isset( $options['variants'] ) ? $options['variants'] : array(),
|
2015-05-24 16:56:44 +00:00
|
|
|
$this->getGlobalVariants( $context )
|
2015-03-27 17:27:47 +00:00
|
|
|
);
|
2015-05-24 16:56:44 +00:00
|
|
|
if ( isset( $this->variants[ $skin ] ) ) {
|
2015-03-27 17:27:47 +00:00
|
|
|
$variantConfig = array_intersect_key(
|
2015-05-24 16:56:44 +00:00
|
|
|
$this->variants[ $skin ],
|
2015-03-27 17:27:47 +00:00
|
|
|
array_fill_keys( $allowedVariants, true )
|
2015-03-15 01:52:45 +00:00
|
|
|
);
|
2015-03-27 17:27:47 +00:00
|
|
|
} else {
|
|
|
|
|
$variantConfig = array();
|
2014-11-11 19:50:44 +00:00
|
|
|
}
|
2015-03-27 17:27:47 +00:00
|
|
|
|
|
|
|
|
$image = new ResourceLoaderImage(
|
|
|
|
|
$name,
|
|
|
|
|
$this->getName(),
|
2015-03-28 00:44:47 +00:00
|
|
|
$fileDescriptor,
|
2015-03-27 17:27:47 +00:00
|
|
|
$this->localBasePath,
|
|
|
|
|
$variantConfig
|
|
|
|
|
);
|
2015-05-24 16:56:44 +00:00
|
|
|
$this->imageObjects[ $skin ][ $image->getName() ] = $image;
|
2014-11-11 19:50:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-24 16:56:44 +00:00
|
|
|
return $this->imageObjects[ $skin ];
|
2014-11-11 19:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-03-27 17:27:47 +00:00
|
|
|
* Get list of variants in this module that are 'global', i.e., available
|
|
|
|
|
* for every image regardless of image options.
|
2015-06-05 22:38:06 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2014-11-11 19:50:44 +00:00
|
|
|
* @return string[]
|
|
|
|
|
*/
|
2015-05-24 16:56:44 +00:00
|
|
|
public function getGlobalVariants( ResourceLoaderContext $context ) {
|
|
|
|
|
$skin = $context->getSkin();
|
2015-03-27 17:27:47 +00:00
|
|
|
if ( !isset( $this->globalVariants ) ) {
|
2015-05-23 17:06:06 +00:00
|
|
|
$this->loadFromDefinition();
|
2015-03-27 17:27:47 +00:00
|
|
|
$this->globalVariants = array();
|
2015-05-24 16:56:44 +00:00
|
|
|
}
|
|
|
|
|
if ( !isset( $this->globalVariants[ $skin ] ) ) {
|
|
|
|
|
$this->globalVariants[ $skin ] = array();
|
|
|
|
|
if ( !isset( $this->variants[ $skin ] ) ) {
|
|
|
|
|
$this->variants[ $skin ] = isset( $this->variants[ 'default' ] ) ?
|
|
|
|
|
$this->variants[ 'default' ] :
|
|
|
|
|
array();
|
|
|
|
|
}
|
|
|
|
|
foreach ( $this->variants[ $skin ] as $name => $config ) {
|
|
|
|
|
if ( isset( $config['global'] ) && $config['global'] ) {
|
|
|
|
|
$this->globalVariants[ $skin ][] = $name;
|
2014-11-11 19:50:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-24 16:56:44 +00:00
|
|
|
return $this->globalVariants[ $skin ];
|
2014-11-11 19:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getStyles( ResourceLoaderContext $context ) {
|
2015-05-23 17:06:06 +00:00
|
|
|
$this->loadFromDefinition();
|
2015-04-07 16:02:46 +00:00
|
|
|
|
2014-11-11 19:50:44 +00:00
|
|
|
// Build CSS rules
|
|
|
|
|
$rules = array();
|
|
|
|
|
$script = $context->getResourceLoader()->getLoadScript( $this->getSource() );
|
2015-03-23 21:04:54 +00:00
|
|
|
$selectors = $this->getSelectors();
|
|
|
|
|
|
2015-05-24 16:56:44 +00:00
|
|
|
foreach ( $this->getImages( $context ) as $name => $image ) {
|
2014-11-11 19:50:44 +00:00
|
|
|
$declarations = $this->getCssDeclarations(
|
|
|
|
|
$image->getDataUri( $context, null, 'original' ),
|
|
|
|
|
$image->getUrl( $context, $script, null, 'rasterized' )
|
|
|
|
|
);
|
|
|
|
|
$declarations = implode( "\n\t", $declarations );
|
2015-03-23 21:04:54 +00:00
|
|
|
$selector = strtr(
|
|
|
|
|
$selectors['selectorWithoutVariant'],
|
|
|
|
|
array(
|
|
|
|
|
'{prefix}' => $this->getPrefix(),
|
|
|
|
|
'{name}' => $name,
|
|
|
|
|
'{variant}' => '',
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$rules[] = "$selector {\n\t$declarations\n}";
|
2014-11-11 19:50:44 +00:00
|
|
|
|
|
|
|
|
foreach ( $image->getVariants() as $variant ) {
|
|
|
|
|
$declarations = $this->getCssDeclarations(
|
|
|
|
|
$image->getDataUri( $context, $variant, 'original' ),
|
|
|
|
|
$image->getUrl( $context, $script, $variant, 'rasterized' )
|
|
|
|
|
);
|
|
|
|
|
$declarations = implode( "\n\t", $declarations );
|
2015-03-23 21:04:54 +00:00
|
|
|
$selector = strtr(
|
|
|
|
|
$selectors['selectorWithVariant'],
|
|
|
|
|
array(
|
|
|
|
|
'{prefix}' => $this->getPrefix(),
|
|
|
|
|
'{name}' => $name,
|
|
|
|
|
'{variant}' => $variant,
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$rules[] = "$selector {\n\t$declarations\n}";
|
2014-11-11 19:50:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$style = implode( "\n", $rules );
|
|
|
|
|
return array( 'all' => $style );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-03-23 20:55:12 +00:00
|
|
|
* SVG support using a transparent gradient to guarantee cross-browser
|
|
|
|
|
* compatibility (browsers able to understand gradient syntax support also SVG).
|
|
|
|
|
* http://pauginer.tumblr.com/post/36614680636/invisible-gradient-technique
|
|
|
|
|
*
|
|
|
|
|
* Keep synchronized with the .background-image-svg LESS mixin in
|
|
|
|
|
* /resources/src/mediawiki.less/mediawiki.mixins.less.
|
|
|
|
|
*
|
2014-11-11 19:50:44 +00:00
|
|
|
* @param string $primary Primary URI
|
|
|
|
|
* @param string $fallback Fallback URI
|
|
|
|
|
* @return string[] CSS declarations to use given URIs as background-image
|
|
|
|
|
*/
|
|
|
|
|
protected function getCssDeclarations( $primary, $fallback ) {
|
|
|
|
|
return array(
|
|
|
|
|
"background-image: url($fallback);",
|
|
|
|
|
"background-image: -webkit-linear-gradient(transparent, transparent), url($primary);",
|
|
|
|
|
"background-image: linear-gradient(transparent, transparent), url($primary);",
|
2015-03-23 20:55:12 +00:00
|
|
|
"background-image: -o-linear-gradient(transparent, transparent), url($fallback);",
|
2014-11-11 19:50:44 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function supportsURLLoading() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 19:31:19 +00:00
|
|
|
/**
|
|
|
|
|
* Get the definition summary for this module.
|
|
|
|
|
*
|
|
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getDefinitionSummary( ResourceLoaderContext $context ) {
|
2015-05-23 17:06:06 +00:00
|
|
|
$this->loadFromDefinition();
|
2015-04-14 19:31:19 +00:00
|
|
|
$summary = parent::getDefinitionSummary( $context );
|
|
|
|
|
foreach ( array(
|
|
|
|
|
'localBasePath',
|
|
|
|
|
'images',
|
|
|
|
|
'variants',
|
|
|
|
|
'prefix',
|
|
|
|
|
'selectorWithoutVariant',
|
|
|
|
|
'selectorWithVariant',
|
|
|
|
|
) as $member ) {
|
|
|
|
|
$summary[$member] = $this->{$member};
|
|
|
|
|
};
|
|
|
|
|
return $summary;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the last modified timestamp of this module.
|
|
|
|
|
*
|
|
|
|
|
* @param ResourceLoaderContext $context Context in which to calculate
|
|
|
|
|
* the modified time
|
|
|
|
|
* @return int UNIX timestamp
|
|
|
|
|
*/
|
|
|
|
|
public function getModifiedTime( ResourceLoaderContext $context ) {
|
2015-05-23 17:06:06 +00:00
|
|
|
$this->loadFromDefinition();
|
2015-04-14 19:31:19 +00:00
|
|
|
$files = array();
|
2015-05-24 16:56:44 +00:00
|
|
|
foreach ( $this->getImages( $context ) as $name => $image ) {
|
2015-04-14 19:31:19 +00:00
|
|
|
$files[] = $image->getPath( $context );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$files = array_values( array_unique( $files ) );
|
|
|
|
|
$filesMtime = max( array_map( array( __CLASS__, 'safeFilemtime' ), $files ) );
|
|
|
|
|
|
2015-06-02 18:40:55 +00:00
|
|
|
return $filesMtime;
|
2015-04-14 19:31:19 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 19:50:44 +00:00
|
|
|
/**
|
|
|
|
|
* Extract a local base path from module definition information.
|
|
|
|
|
*
|
|
|
|
|
* @param array $options Module definition
|
|
|
|
|
* @param string $localBasePath Path to use if not provided in module definition. Defaults
|
|
|
|
|
* to $IP
|
|
|
|
|
* @return string Local base path
|
|
|
|
|
*/
|
|
|
|
|
public static function extractLocalBasePath( $options, $localBasePath = null ) {
|
|
|
|
|
global $IP;
|
|
|
|
|
|
|
|
|
|
if ( $localBasePath === null ) {
|
|
|
|
|
$localBasePath = $IP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( array_key_exists( 'localBasePath', $options ) ) {
|
|
|
|
|
$localBasePath = (string)$options['localBasePath'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $localBasePath;
|
|
|
|
|
}
|
2015-05-25 14:04:57 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getPosition() {
|
|
|
|
|
$this->loadFromDefinition();
|
|
|
|
|
return $this->position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isPositionDefault() {
|
|
|
|
|
$this->loadFromDefinition();
|
|
|
|
|
return parent::isPositionDefault();
|
|
|
|
|
}
|
2014-11-11 19:50:44 +00:00
|
|
|
}
|