MediaWiki REL1_30
Gadgets_body.php
Go to the documentation of this file.
1<?php
17class Gadget {
22
23 const CACHE_TTL = 86400;
24
25 private $scripts = [],
26 $styles = [],
28 $peers = [],
35 $targets = [ 'desktop' ],
36 $onByDefault = false,
37 $hidden = false,
38 $type = '',
40
41 public function __construct( array $options ) {
42 foreach ( $options as $member => $option ) {
43 switch ( $member ) {
44 case 'scripts':
45 case 'styles':
46 case 'dependencies':
47 case 'peers':
48 case 'messages':
49 case 'name':
50 case 'definition':
51 case 'resourceLoaded':
52 case 'requiredRights':
53 case 'requiredSkins':
54 case 'targets':
55 case 'onByDefault':
56 case 'type':
57 case 'hidden':
58 case 'category':
59 $this->{$member} = $option;
60 break;
61 default:
62 throw new InvalidArgumentException( "Unrecognized '$member' parameter" );
63 }
64 }
65 }
66
74 public static function newFromDefinitionContent( $id, GadgetDefinitionContent $content ) {
75 $data = $content->getAssocArray();
76 $prefixGadgetNs = function ( $page ) {
77 return 'Gadget:' . $page;
78 };
79 $info = [
80 'name' => $id,
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'],
93 ];
94
95 return new self( $info );
96 }
97
104 public static function newEmptyGadget( $id ) {
105 return new self( [ 'name' => $id ] );
106 }
107
114 public static function isValidGadgetID( $id ) {
115 return strlen( $id ) > 0 && ResourceLoader::isValidModuleName( self::getModuleName( $id ) );
116 }
117
121 public function getName() {
122 return $this->name;
123 }
124
128 public function getDescription() {
129 return wfMessage( "gadget-{$this->getName()}" )->parse();
130 }
131
135 public function getRawDescription() {
136 return wfMessage( "gadget-{$this->getName()}" )->plain();
137 }
138
142 public function getCategory() {
143 return $this->category;
144 }
145
150 public static function getModuleName( $id ) {
151 return "ext.gadget.{$id}";
152 }
153
160 public function isEnabled( $user ) {
161 return (bool)$user->getOption( "gadget-{$this->name}", $this->onByDefault );
162 }
163
170 public function isAllowed( $user ) {
171 return count( array_intersect( $this->requiredRights, $user->getRights() ) ) ==
172 count( $this->requiredRights )
173 && ( $this->requiredSkins === true
174 || !count( $this->requiredSkins )
175 || in_array( $user->getOption( 'skin' ), $this->requiredSkins )
176 );
177 }
178
183 public function isOnByDefault() {
184 return $this->onByDefault;
185 }
186
190 public function isHidden() {
191 return $this->hidden;
192 }
193
197 public function supportsResourceLoader() {
199 }
200
204 public function hasModule() {
205 return count( $this->styles )
206 + ( $this->supportsResourceLoader() ? count( $this->scripts ) : 0 )
207 > 0;
208 }
209
213 public function getDefinition() {
214 return $this->definition;
215 }
216
220 public function getScripts() {
221 return $this->scripts;
222 }
223
227 public function getStyles() {
228 return $this->styles;
229 }
230
234 public function getScriptsAndStyles() {
235 return array_merge( $this->scripts, $this->styles );
236 }
237
241 public function getTargets() {
242 return $this->targets;
243 }
244
249 public function getLegacyScripts() {
250 if ( $this->supportsResourceLoader() ) {
251 return [];
252 }
253 return $this->scripts;
254 }
255
260 public function getDependencies() {
261 return $this->dependencies;
262 }
263
273 public function getPeers() {
274 return $this->peers;
275 }
276
280 public function getMessages() {
281 return $this->messages;
282 }
283
288 public function getRequiredRights() {
290 }
291
296 public function getRequiredSkins() {
298 }
299
304 public function getType() {
305 if ( $this->type === 'styles' || $this->type === 'general' ) {
306 return $this->type;
307 }
308 // Similar to ResourceLoaderWikiModule default
309 if ( $this->styles && !$this->scripts && !$this->dependencies ) {
310 return 'styles';
311 } else {
312 return 'general';
313 }
314 }
315}
The package scripts
Definition README.txt:1
getAssocArray()
Get the JSON content as an associative array with all fields filled out, populating defaults as neces...
Wrapper for one gadget.
const GADGET_CLASS_VERSION
Increment this when changing class structure.
getType()
Returns the load type of this Gadget's ResourceLoader module.
supportsResourceLoader()
__construct(array $options)
const CACHE_TTL
isAllowed( $user)
Checks whether given user has permissions to use this gadget.
static isValidGadgetID( $id)
Whether the provided gadget id is valid.
getRawDescription()
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.
getDependencies()
Returns names of resources this gadget depends on.
isEnabled( $user)
Checks whether this gadget is enabled for given user.
getScriptsAndStyles()
getRequiredRights()
Returns array of permissions required by this gadget.
static isValidModuleName( $moduleName)
Check a module name for validity.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:1971
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition postgres.txt:36