mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-11-15 03:23:51 +00:00
(bug 31414) Skin specific gadgets
This commit is contained in:
parent
fb4ad3cac6
commit
b9aa1fea37
|
@ -119,6 +119,7 @@ class ApiQueryGadgets extends ApiQueryBase {
|
|||
return array(
|
||||
'settings' => array(
|
||||
'rights' => $g->getRequiredRights(),
|
||||
'skins' => $g->getRequiredSkins(),
|
||||
'default' => $g->isOnByDefault(),
|
||||
'hidden' => false, // Only exists in RL2 branch
|
||||
'shared' => false, // Only exists in RL2 branch
|
||||
|
@ -136,6 +137,7 @@ class ApiQueryGadgets extends ApiQueryBase {
|
|||
private function setIndexedTagNameForMetadata( &$metadata ) {
|
||||
static $tagNames = array(
|
||||
'rights' => 'right',
|
||||
'skins' => 'skin',
|
||||
'scripts' => 'script',
|
||||
'styles' => 'style',
|
||||
'dependencies' => 'dependency',
|
||||
|
|
|
@ -36,6 +36,7 @@ This overview provides easy access to the system message pages that define each
|
|||
'gadgets-required-rights' => 'Requires the following {{PLURAL:$2|right|rights}}:
|
||||
|
||||
$1',
|
||||
'gadgets-required-skins' => 'Available on the {{PLURAL:$2|$1 skin|following skins: $1}}.',
|
||||
'gadgets-default' => 'Enabled for everyone by default.',
|
||||
'gadgets-export' => 'Export',
|
||||
'gadgets-export-title' => 'Gadget export',
|
||||
|
@ -71,6 +72,9 @@ $messages['qqq'] = array(
|
|||
See [http://meta.wikimedia.org/wiki/Special:Gadgets Gadgets page in meta.wikimedia.org]",
|
||||
'gadgets-required-rights' => 'Parameters:
|
||||
* $1 - a list in wikitext.
|
||||
* $2 - the number of items in list $1 for PLURAL use.',
|
||||
'gadgets-required-skins' => 'Parameters:
|
||||
* $1 - a comma list.
|
||||
* $2 - the number of items in list $1 for PLURAL use.',
|
||||
'gadgets-export' => 'Used on [[Special:Gadgets]]. This is a verb, not noun.
|
||||
{{Identical|Export}}',
|
||||
|
|
|
@ -239,6 +239,7 @@ class Gadget {
|
|||
$definition,
|
||||
$resourceLoaded = false,
|
||||
$requiredRights = array(),
|
||||
$requiredSkins = array(),
|
||||
$onByDefault = false,
|
||||
$category;
|
||||
|
||||
|
@ -280,6 +281,9 @@ class Gadget {
|
|||
case 'rights':
|
||||
$gadget->requiredRights = $params;
|
||||
break;
|
||||
case 'skins':
|
||||
$gadget->requiredSkins = array_intersect( array_keys( Skin::getSkinNames() ), $params );
|
||||
break;
|
||||
case 'default':
|
||||
$gadget->onByDefault = true;
|
||||
break;
|
||||
|
@ -359,7 +363,8 @@ class Gadget {
|
|||
* @return Boolean
|
||||
*/
|
||||
public function isAllowed( $user ) {
|
||||
return count( array_intersect( $this->requiredRights, $user->getRights() ) ) == count( $this->requiredRights );
|
||||
return count( array_intersect( $this->requiredRights, $user->getRights() ) ) == count( $this->requiredRights )
|
||||
&& ( !count( $this->requiredSkins ) || in_array( $user->getOption( 'skin' ), $this->requiredSkins ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -465,6 +470,14 @@ class Gadget {
|
|||
return $this->requiredRights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of skins where this gadget works
|
||||
* @return Array
|
||||
*/
|
||||
public function getRequiredSkins() {
|
||||
return $this->requiredSkins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and returns a list of all gadgets
|
||||
* @return Mixed: Array of gadgets or false
|
||||
|
|
|
@ -117,17 +117,27 @@ class SpecialGadgets extends SpecialPage {
|
|||
$lnk[] = $skin->link( $t, htmlspecialchars( $t->getText() ) );
|
||||
}
|
||||
$wgOut->addHTML( $wgLang->commaList( $lnk ) );
|
||||
|
||||
$rights = array();
|
||||
foreach ( $gadget->getRequiredRights() as $right ) {
|
||||
$rights[] = '* ' . wfMessage( "right-$right" )->plain();
|
||||
}
|
||||
|
||||
if ( count( $rights ) ) {
|
||||
$wgOut->addHTML( '<br />' .
|
||||
wfMessage( 'gadgets-required-rights', implode( "\n", $rights ), count( $rights ) )->parse()
|
||||
);
|
||||
}
|
||||
|
||||
$skins = array();
|
||||
foreach ( $gadget->getRequiredSkins() as $skinid ) {
|
||||
$skins[] = wfMessage( "skinname-$skinid" )->plain();
|
||||
}
|
||||
if ( count( $skins ) ) {
|
||||
$wgOut->addHTML( '<br />' .
|
||||
wfMessage( 'gadgets-required-skins', $wgLang->commaList( $skins ), count( $skins ) )->parse()
|
||||
);
|
||||
}
|
||||
|
||||
if ( $gadget->isOnByDefault() ) {
|
||||
$wgOut->addHTML( '<br />' . wfMessage( 'gadgets-default' )->parse() );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue