Add support for 'messages' and 'hidden' gadgets

In the backend, allow:
* Adding dependencies on messages
* Marking gadgets as hidden so they don't show in preferences

These cannot be used by MediaWiki:Gadgets-definition gadgets, but will
be used by Gadgets 2.0 gadgets.

Change-Id: I55e97de9d631ae001ccc0164db172ba9c5689a34
This commit is contained in:
Kunal Mehta 2015-08-02 23:34:16 -07:00 committed by Legoktm
parent 450448a639
commit 152484566d
4 changed files with 38 additions and 8 deletions

View file

@ -89,7 +89,7 @@ class GadgetHooks {
* @var $gadget Gadget
*/
foreach ( $thisSection as $gadget ) {
if ( $gadget->isAllowed( $user ) ) {
if ( !$gadget->isHidden() && $gadget->isAllowed( $user ) ) {
$gname = $gadget->getName();
# bug 30182: dir="auto" because it's often not translated
$desc = '<span dir="auto">' . $gadget->getDescription() . '</span>';

View file

@ -19,13 +19,14 @@ class Gadget {
/**
* Increment this when changing class structure
*/
const GADGET_CLASS_VERSION = 8;
const GADGET_CLASS_VERSION = 9;
const CACHE_TTL = 86400;
private $scripts = array(),
$styles = array(),
$dependencies = array(),
$messages = array(),
$name,
$definition,
$resourceLoaded = false,
@ -33,6 +34,7 @@ class Gadget {
$requiredSkins = array(),
$targets = array( 'desktop' ),
$onByDefault = false,
$hidden = false,
$position = 'bottom',
$category;
@ -45,6 +47,7 @@ class Gadget {
case 'scripts':
case 'styles':
case 'dependencies':
case 'messages':
case 'name':
case 'definition':
case 'resourceLoaded':
@ -53,6 +56,7 @@ class Gadget {
case 'targets':
case 'onByDefault':
case 'position':
case 'hidden':
case 'category':
$this->{$member} = $option;
break;
@ -136,6 +140,13 @@ class Gadget {
return $this->onByDefault;
}
/**
* @return bool
*/
public function isHidden() {
return $this->hidden;
}
/**
* @return Boolean: Whether all of this gadget's JS components support ResourceLoader
*/
@ -202,7 +213,13 @@ class Gadget {
return null;
}
return new GadgetResourceLoaderModule( $pages, $this->dependencies, $this->targets, $this->position );
return new GadgetResourceLoaderModule(
$pages,
$this->dependencies,
$this->targets,
$this->position,
$this->messages
);
}
/**
@ -224,6 +241,13 @@ class Gadget {
return $this->dependencies;
}
/**
* @return array
*/
public function getMessages() {
return $this->messages;
}
/**
* Returns array of permissions required by this gadget
* @return Array

View file

@ -147,8 +147,8 @@ class ApiQueryGadgets extends ApiQueryBase {
'rights' => $g->getRequiredRights(),
'skins' => $g->getRequiredSkins(),
'default' => $g->isOnByDefault(),
'hidden' => false, // Only exists in RL2 branch
'shared' => false, // Only exists in RL2 branch
'hidden' => $g->isHidden(),
'shared' => false,
'category' => $g->getCategory(),
'legacyscripts' => (bool)$g->getLegacyScripts(),
),
@ -156,7 +156,7 @@ class ApiQueryGadgets extends ApiQueryBase {
'scripts' => $g->getScripts(),
'styles' => $g->getStyles(),
'dependencies' => $g->getDependencies(),
'messages' => array(), // Only exists in RL2 branch
'messages' => $g->getMessages(),
)
);
}

View file

@ -4,7 +4,7 @@
* Class representing a list of resources for one gadget
*/
class GadgetResourceLoaderModule extends ResourceLoaderWikiModule {
private $pages, $dependencies;
private $pages, $dependencies, $messages;
/**
* Creates an instance of this class
@ -18,13 +18,15 @@ class GadgetResourceLoaderModule extends ResourceLoaderWikiModule {
* @param $dependencies Array: Names of resources this module depends on
* @param $targets Array: List of targets this module support
* @param $position String: 'bottom' or 'top'
* @param $messages Array
*/
public function __construct( $pages, $dependencies, $targets, $position ) {
public function __construct( $pages, $dependencies, $targets, $position, $messages ) {
$this->pages = $pages;
$this->dependencies = $dependencies;
$this->targets = $targets;
$this->position = $position;
$this->isPositionDefined = true;
$this->messages = $messages;
}
/**
@ -52,4 +54,8 @@ class GadgetResourceLoaderModule extends ResourceLoaderWikiModule {
public function getPosition() {
return $this->position;
}
public function getMessages() {
return $this->messages;
}
}