MediaWiki REL1_34
Gadget Class Reference

Wrapper for one gadget. More...

Public Member Functions

 __construct (array $options)
 
 getCategory ()
 
 getDefinition ()
 
 getDependencies ()
 Returns names of resources this gadget depends on.
 
 getDescription ()
 
 getLegacyScripts ()
 Returns list of scripts that don't support ResourceLoader.
 
 getMessages ()
 
 getName ()
 
 getPeers ()
 Get list of extra modules that should be loaded when this gadget is enabled.
 
 getRawDescription ()
 
 getRequiredRights ()
 Returns array of permissions required by this gadget.
 
 getRequiredSkins ()
 Returns array of skins where this gadget works.
 
 getScripts ()
 
 getScriptsAndStyles ()
 
 getStyles ()
 
 getTargets ()
 
 getType ()
 Returns the load type of this Gadget's ResourceLoader module.
 
 hasModule ()
 
 isAllowed (User $user)
 Checks whether given user has permissions to use this gadget.
 
 isEnabled ( $user)
 Checks whether this gadget is enabled for given user.
 
 isHidden ()
 
 isOnByDefault ()
 
 isSkinSupported (Skin $skin)
 Check if this gadget is compatible with a skin.
 
 supportsResourceLoader ()
 

Static Public Member Functions

static getModuleName ( $id)
 
static isValidGadgetID ( $id)
 Whether the provided gadget id is valid.
 
static newEmptyGadget ( $id)
 Get a placeholder object to use if a gadget doesn't exist.
 
static newFromDefinitionContent ( $id, GadgetDefinitionContent $content)
 Create a object based on the metadata in a GadgetDefinitionContent object.
 

Public Attributes

const CACHE_TTL = 86400
 
const GADGET_CLASS_VERSION = 9
 Increment this when changing class structure.
 

Private Attributes

 $category
 
 $definition
 
 $dependencies = []
 
 $hidden = false
 
 $messages = []
 
 $name
 
 $onByDefault = false
 
 $peers = []
 
 $requiredRights = []
 
 $requiredSkins = []
 
 $resourceLoaded = false
 
 $scripts = []
 
 $styles = []
 
 $targets = [ 'desktop' ]
 
 $type = ''
 

Detailed Description

Wrapper for one gadget.

Definition at line 17 of file Gadget.php.

Constructor & Destructor Documentation

◆ __construct()

Gadget::__construct ( array $options)

Definition at line 41 of file Gadget.php.

Member Function Documentation

◆ getCategory()

Gadget::getCategory ( )
Returns
string Name of category (aka section) our gadget belongs to. Empty string if none.

Definition at line 142 of file Gadget.php.

References $category.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getDefinition()

Gadget::getDefinition ( )
Returns
string Definition for this gadget from MediaWiki:gadgets-definition

Definition at line 220 of file Gadget.php.

References $definition.

◆ getDependencies()

Gadget::getDependencies ( )

Returns names of resources this gadget depends on.

Returns
string[]

Definition at line 267 of file Gadget.php.

References $dependencies.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getDescription()

Gadget::getDescription ( )
Returns
string Gadget description parsed into HTML

Definition at line 128 of file Gadget.php.

References wfMessage().

◆ getLegacyScripts()

Gadget::getLegacyScripts ( )

Returns list of scripts that don't support ResourceLoader.

Returns
string[]

Definition at line 256 of file Gadget.php.

References $scripts, and supportsResourceLoader().

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getMessages()

Gadget::getMessages ( )
Returns
array

Definition at line 287 of file Gadget.php.

References $messages.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getModuleName()

static Gadget::getModuleName ( $id)
static
Parameters
string$idName of gadget
Returns
string Name of ResourceLoader module for the gadget

Definition at line 150 of file Gadget.php.

Referenced by GadgetHooks\beforePageDisplay(), GadgetHooks\registerModules(), and GadgetTest\testSimpleCases().

◆ getName()

Gadget::getName ( )
Returns
string Gadget name

Definition at line 121 of file Gadget.php.

References $name.

Referenced by ApiQueryGadgets\isNeeded().

◆ getPeers()

Gadget::getPeers ( )

Get list of extra modules that should be loaded when this gadget is enabled.

Primary use case is to allow a Gadget that includes JavaScript to also load a (usually, hidden) styles-type module to be applied to the page. Dependencies don't work for this use case as those would not be part of page rendering.

Returns
string[]

Definition at line 280 of file Gadget.php.

References $peers.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getRawDescription()

Gadget::getRawDescription ( )
Returns
string Wikitext of gadget description

Definition at line 135 of file Gadget.php.

References wfMessage().

◆ getRequiredRights()

Gadget::getRequiredRights ( )

Returns array of permissions required by this gadget.

Returns
string[]

Definition at line 295 of file Gadget.php.

References $requiredRights.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getRequiredSkins()

Gadget::getRequiredSkins ( )

Returns array of skins where this gadget works.

Returns
string[]

Definition at line 303 of file Gadget.php.

References $requiredSkins.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getScripts()

Gadget::getScripts ( )
Returns
array Array of pages with JS (including namespace)

Definition at line 227 of file Gadget.php.

References $scripts.

Referenced by ApiQueryGadgets\fakeMetadata(), and GadgetResourceLoaderModule\getPages().

◆ getScriptsAndStyles()

Gadget::getScriptsAndStyles ( )
Returns
array Array of all of this gadget's resources

Definition at line 241 of file Gadget.php.

◆ getStyles()

Gadget::getStyles ( )
Returns
array Array of pages with CSS (including namespace)

Definition at line 234 of file Gadget.php.

References $styles.

Referenced by ApiQueryGadgets\fakeMetadata(), and GadgetResourceLoaderModule\getPages().

◆ getTargets()

Gadget::getTargets ( )
Returns
array

Definition at line 248 of file Gadget.php.

References $targets.

◆ getType()

Gadget::getType ( )

Returns the load type of this Gadget's ResourceLoader module.

Returns
string 'styles' or 'general'

Definition at line 311 of file Gadget.php.

References $type.

◆ hasModule()

Gadget::hasModule ( )
Returns
bool Whether this gadget has resources that can be loaded via ResourceLoader

Definition at line 211 of file Gadget.php.

References supportsResourceLoader().

◆ isAllowed()

Gadget::isAllowed ( User $user)

Checks whether given user has permissions to use this gadget.

Parameters
User$userThe user to check against
Returns
bool

Definition at line 170 of file Gadget.php.

References User\isAllowedAll().

Referenced by ApiQueryGadgets\isNeeded().

◆ isEnabled()

Gadget::isEnabled ( $user)

Checks whether this gadget is enabled for given user.

Parameters
User$useruser to check against
Returns
bool

Definition at line 160 of file Gadget.php.

Referenced by ApiQueryGadgets\isNeeded().

◆ isHidden()

Gadget::isHidden ( )
Returns
bool

Definition at line 185 of file Gadget.php.

References $hidden.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ isOnByDefault()

Gadget::isOnByDefault ( )
Returns
bool Whether this gadget is on by default for everyone (but can be disabled in preferences)

Definition at line 178 of file Gadget.php.

References $onByDefault.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ isSkinSupported()

Gadget::isSkinSupported ( Skin $skin)

Check if this gadget is compatible with a skin.

Parameters
Skin$skinThe skin to check against
Returns
bool

Definition at line 195 of file Gadget.php.

References Skin\getSkinName().

◆ isValidGadgetID()

static Gadget::isValidGadgetID ( $id)
static

Whether the provided gadget id is valid.

Parameters
string$id
Returns
bool

Definition at line 114 of file Gadget.php.

Referenced by MediaWikiGadgetsDefinitionRepo\newFromDefinition().

◆ newEmptyGadget()

static Gadget::newEmptyGadget ( $id)
static

Get a placeholder object to use if a gadget doesn't exist.

Parameters
string$idname
Returns
Gadget

Definition at line 104 of file Gadget.php.

Referenced by GadgetResourceLoaderModule\getGadget().

◆ newFromDefinitionContent()

static Gadget::newFromDefinitionContent ( $id,
GadgetDefinitionContent $content )
static

Create a object based on the metadata in a GadgetDefinitionContent object.

Parameters
string$id
GadgetDefinitionContent$content
Returns
Gadget

Definition at line 74 of file Gadget.php.

References $content.

Referenced by GadgetDefinitionNamespaceRepo\getGadget().

◆ supportsResourceLoader()

Gadget::supportsResourceLoader ( )
Returns
bool Whether all of this gadget's JS components support ResourceLoader

Definition at line 204 of file Gadget.php.

References $resourceLoaded.

Referenced by getLegacyScripts(), GadgetResourceLoaderModule\getPages(), and hasModule().

Member Data Documentation

◆ $category

Gadget::$category
private

Definition at line 39 of file Gadget.php.

Referenced by getCategory().

◆ $definition

Gadget::$definition
private

Definition at line 31 of file Gadget.php.

Referenced by getDefinition().

◆ $dependencies

Gadget::$dependencies = []
private

Definition at line 27 of file Gadget.php.

Referenced by getDependencies().

◆ $hidden

Gadget::$hidden = false
private

Definition at line 37 of file Gadget.php.

Referenced by isHidden().

◆ $messages

Gadget::$messages = []
private

Definition at line 29 of file Gadget.php.

Referenced by getMessages().

◆ $name

Gadget::$name
private

Definition at line 30 of file Gadget.php.

Referenced by getName().

◆ $onByDefault

Gadget::$onByDefault = false
private

Definition at line 36 of file Gadget.php.

Referenced by isOnByDefault().

◆ $peers

Gadget::$peers = []
private

Definition at line 28 of file Gadget.php.

Referenced by getPeers().

◆ $requiredRights

Gadget::$requiredRights = []
private

Definition at line 33 of file Gadget.php.

Referenced by getRequiredRights().

◆ $requiredSkins

Gadget::$requiredSkins = []
private

Definition at line 34 of file Gadget.php.

Referenced by getRequiredSkins().

◆ $resourceLoaded

Gadget::$resourceLoaded = false
private

Definition at line 32 of file Gadget.php.

Referenced by supportsResourceLoader().

◆ $scripts

Gadget::$scripts = []
private

Definition at line 25 of file Gadget.php.

Referenced by getLegacyScripts(), and getScripts().

◆ $styles

Gadget::$styles = []
private

Definition at line 26 of file Gadget.php.

Referenced by getStyles().

◆ $targets

Gadget::$targets = [ 'desktop' ]
private

Definition at line 35 of file Gadget.php.

Referenced by getTargets().

◆ $type

Gadget::$type = ''
private

Definition at line 38 of file Gadget.php.

Referenced by getType().

◆ CACHE_TTL

const Gadget::CACHE_TTL = 86400

Definition at line 23 of file Gadget.php.

Referenced by MediaWikiGadgetsDefinitionRepo\loadGadgets().

◆ GADGET_CLASS_VERSION

const Gadget::GADGET_CLASS_VERSION = 9

Increment this when changing class structure.

Definition at line 21 of file Gadget.php.

Referenced by MediaWikiGadgetsDefinitionRepo\getDefinitionCacheKey(), and GadgetDefinitionNamespaceRepo\getGadgetCacheKey().


The documentation for this class was generated from the following file: