MediaWiki  1.29.1
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. More...
 
 getDescription ()
 
 getLegacyScripts ()
 Returns list of scripts that don't support ResourceLoader. More...
 
 getMessages ()
 
 getName ()
 
 getPeers ()
 Get list of extra modules that should be loaded when this gadget is enabled. More...
 
 getRawDescription ()
 
 getRequiredRights ()
 Returns array of permissions required by this gadget. More...
 
 getRequiredSkins ()
 Returns array of skins where this gadget works. More...
 
 getScripts ()
 
 getScriptsAndStyles ()
 
 getStyles ()
 
 getTargets ()
 
 getType ()
 Returns the load type of this Gadget's ResourceLoader module. More...
 
 hasModule ()
 
 isAllowed ( $user)
 Checks whether given user has permissions to use this gadget. More...
 
 isEnabled ( $user)
 Checks whether this gadget is enabled for given user. More...
 
 isHidden ()
 
 isOnByDefault ()
 
 supportsResourceLoader ()
 

Static Public Member Functions

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

Public Attributes

 $category
 
 $definition
 
 $dependencies = []
 
 $hidden = false
 
 $messages = []
 
 $name
 
 $onByDefault = false
 
 $peers = []
 
 $requiredRights = []
 
 $requiredSkins = []
 
 $resourceLoaded = false
 
 $styles = []
 
 $targets = [ 'desktop' ]
 
 $type = ''
 
const CACHE_TTL = 86400
 
const GADGET_CLASS_VERSION = 9
 Increment this when changing class structure. More...
 

Private Attributes

 $scripts = []
 

Detailed Description

Wrapper for one gadget.

Definition at line 18 of file Gadgets_body.php.

Constructor & Destructor Documentation

◆ __construct()

Gadget::__construct ( array  $options)

Definition at line 42 of file Gadgets_body.php.

References $options, and as.

Member Function Documentation

◆ getCategory()

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

Definition at line 145 of file Gadgets_body.php.

References $category.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getDefinition()

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

Definition at line 211 of file Gadgets_body.php.

References $definition.

◆ getDependencies()

Gadget::getDependencies ( )

Returns names of resources this gadget depends on.

Returns
Array

Definition at line 258 of file Gadgets_body.php.

References $dependencies.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getDescription()

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

Definition at line 131 of file Gadgets_body.php.

References wfMessage().

◆ getLegacyScripts()

Gadget::getLegacyScripts ( )

Returns list of scripts that don't support ResourceLoader.

Returns
Array

Definition at line 247 of file Gadgets_body.php.

References $scripts, and supportsResourceLoader().

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getMessages()

Gadget::getMessages ( )
Returns
array

Definition at line 278 of file Gadgets_body.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 153 of file Gadgets_body.php.

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

◆ getName()

Gadget::getName ( )
Returns
String: Gadget name

Definition at line 124 of file Gadgets_body.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
Array

Definition at line 271 of file Gadgets_body.php.

References $peers.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getRawDescription()

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

Definition at line 138 of file Gadgets_body.php.

References wfMessage().

◆ getRequiredRights()

Gadget::getRequiredRights ( )

Returns array of permissions required by this gadget.

Returns
Array

Definition at line 286 of file Gadgets_body.php.

References $requiredRights.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getRequiredSkins()

Gadget::getRequiredSkins ( )

Returns array of skins where this gadget works.

Returns
Array

Definition at line 294 of file Gadgets_body.php.

References $requiredSkins.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ getScripts()

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

Definition at line 218 of file Gadgets_body.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 232 of file Gadgets_body.php.

References scripts.

◆ getStyles()

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

Definition at line 225 of file Gadgets_body.php.

References $styles.

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

◆ getTargets()

Gadget::getTargets ( )
Returns
array

Definition at line 239 of file Gadgets_body.php.

References $targets.

◆ getType()

Gadget::getType ( )

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

Returns
string 'styles', 'general' or ''

Definition at line 302 of file Gadgets_body.php.

References $type, scripts, supportsResourceLoader(), and type.

◆ hasModule()

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

Definition at line 202 of file Gadgets_body.php.

References captcha-old\count, scripts, and supportsResourceLoader().

◆ isAllowed()

Gadget::isAllowed (   $user)

Checks whether given user has permissions to use this gadget.

Parameters
$userUser: user to check against
Returns
Boolean

Definition at line 173 of file Gadgets_body.php.

References $requiredSkins, $user, and captcha-old\count.

Referenced by ApiQueryGadgets\isNeeded().

◆ isEnabled()

Gadget::isEnabled (   $user)

Checks whether this gadget is enabled for given user.

Parameters
$userUser: user to check against
Returns
Boolean

Definition at line 163 of file Gadgets_body.php.

References $user.

Referenced by ApiQueryGadgets\isNeeded().

◆ isHidden()

Gadget::isHidden ( )
Returns
bool

Definition at line 188 of file Gadgets_body.php.

References $hidden.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ isOnByDefault()

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

Definition at line 181 of file Gadgets_body.php.

References $onByDefault.

Referenced by ApiQueryGadgets\fakeMetadata().

◆ isValidGadgetID()

static Gadget::isValidGadgetID (   $id)
static

Whether the provided gadget id is valid.

Parameters
string$id
Returns
bool

Definition at line 116 of file Gadgets_body.php.

References getModuleName().

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 106 of file Gadgets_body.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 75 of file Gadgets_body.php.

References $content, and $page.

Referenced by GadgetDefinitionNamespaceRepo\getGadget().

◆ supportsResourceLoader()

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

Definition at line 195 of file Gadgets_body.php.

References $resourceLoaded.

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

Member Data Documentation

◆ $category

Gadget::$category

Definition at line 39 of file Gadgets_body.php.

Referenced by getCategory().

◆ $definition

Gadget::$definition

Definition at line 30 of file Gadgets_body.php.

Referenced by getDefinition().

◆ $dependencies

Gadget::$dependencies = []

Definition at line 28 of file Gadgets_body.php.

Referenced by getDependencies().

◆ $hidden

Gadget::$hidden = false

Definition at line 38 of file Gadgets_body.php.

Referenced by isHidden().

◆ $messages

Gadget::$messages = []

Definition at line 30 of file Gadgets_body.php.

Referenced by getMessages().

◆ $name

Gadget::$name

Definition at line 30 of file Gadgets_body.php.

Referenced by getName().

◆ $onByDefault

Gadget::$onByDefault = false

Definition at line 37 of file Gadgets_body.php.

Referenced by isOnByDefault().

◆ $peers

Gadget::$peers = []

Definition at line 29 of file Gadgets_body.php.

Referenced by getPeers().

◆ $requiredRights

Gadget::$requiredRights = []

Definition at line 34 of file Gadgets_body.php.

Referenced by getRequiredRights().

◆ $requiredSkins

Gadget::$requiredSkins = []

Definition at line 35 of file Gadgets_body.php.

Referenced by getRequiredSkins(), and isAllowed().

◆ $resourceLoaded

Gadget::$resourceLoaded = false

Definition at line 33 of file Gadgets_body.php.

Referenced by supportsResourceLoader().

◆ $scripts

Gadget::$scripts = []
private

Definition at line 26 of file Gadgets_body.php.

Referenced by getLegacyScripts(), and getScripts().

◆ $styles

Gadget::$styles = []

Definition at line 27 of file Gadgets_body.php.

Referenced by getStyles().

◆ $targets

Gadget::$targets = [ 'desktop' ]

Definition at line 36 of file Gadgets_body.php.

Referenced by getTargets().

◆ $type

Gadget::$type = ''

Definition at line 39 of file Gadgets_body.php.

Referenced by getType().

◆ CACHE_TTL

const Gadget::CACHE_TTL = 86400

Definition at line 24 of file Gadgets_body.php.

Referenced by MediaWikiGadgetsDefinitionRepo\loadGadgets().

◆ GADGET_CLASS_VERSION

const Gadget::GADGET_CLASS_VERSION = 9

Increment this when changing class structure.

Definition at line 22 of file Gadgets_body.php.

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


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