42 foreach ( $options as $member => $option ) {
51 case 'resourceLoaded':
52 case 'requiredRights':
59 $this->{$member} = $option;
62 throw new InvalidArgumentException(
"Unrecognized '$member' parameter" );
76 $prefixGadgetNs =
function ( $page ) {
77 return 'Gadget:' . $page;
81 'resourceLoaded' =>
true,
82 'requiredRights' => $data[
'settings'][
'rights'],
83 'onByDefault' => $data[
'settings'][
'default'],
84 'hidden' => $data[
'settings'][
'hidden'],
85 'requiredSkins' => $data[
'settings'][
'skins'],
86 'category' => $data[
'settings'][
'category'],
87 'scripts' => array_map( $prefixGadgetNs, $data[
'module'][
'scripts'] ),
88 'styles' => array_map( $prefixGadgetNs, $data[
'module'][
'styles'] ),
89 'dependencies' => $data[
'module'][
'dependencies'],
90 'peers' => $data[
'module'][
'peers'],
91 'messages' => $data[
'module'][
'messages'],
92 'type' => $data[
'module'][
'type'],
95 return new self( $info );
105 return new self( [
'name' => $id ] );
115 return strlen( $id ) > 0 && ResourceLoader::isValidModuleName( self::getModuleName( $id ) );
129 return wfMessage(
"gadget-{$this->getName()}" )->parse();
136 return wfMessage(
"gadget-{$this->getName()}" )->plain();
151 return "ext.gadget.{$id}";
161 return (
bool)$user->getOption(
"gadget-{$this->name}", $this->onByDefault );
196 return ( count( $this->requiredSkins ) === 0
197 || in_array( $skin->
getSkinName(), $this->requiredSkins )
212 return count( $this->styles )
242 return array_merge( $this->scripts, $this->styles );
312 if ( $this->type ===
'styles' || $this->type ===
'general' ) {
316 if ( $this->styles && !$this->scripts && !$this->dependencies ) {
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
const GADGET_CLASS_VERSION
Increment this when changing class structure.
getType()
Returns the load type of this Gadget's ResourceLoader module.
__construct(array $options)
static isValidGadgetID( $id)
Whether the provided gadget id is valid.
static getModuleName( $id)
static newFromDefinitionContent( $id, GadgetDefinitionContent $content)
Create a object based on the metadata in a GadgetDefinitionContent object.
static newEmptyGadget( $id)
Get a placeholder object to use if a gadget doesn't exist.
getPeers()
Get list of extra modules that should be loaded when this gadget is enabled.
getLegacyScripts()
Returns list of scripts that don't support ResourceLoader.
getRequiredSkins()
Returns array of skins where this gadget works.
isAllowed(User $user)
Checks whether given user has permissions to use this gadget.
isSkinSupported(Skin $skin)
Check if this gadget is compatible with a skin.
getDependencies()
Returns names of resources this gadget depends on.
isEnabled( $user)
Checks whether this gadget is enabled for given user.
getRequiredRights()
Returns array of permissions required by this gadget.
The main skin class which provides methods and properties for all other skins.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
isAllowedAll(... $permissions)