mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-11-13 17:53:22 +00:00
Bug 13742 - Allow for gadgets to be turned on by default.
Because I'm lazy to do everything twice, README now points to on-wiki docs for definition format.
This commit is contained in:
parent
86b548c7bc
commit
dbc8ef531f
|
@ -34,6 +34,7 @@ Local administrators can edit the [[MediaWiki:Gadgets-definition|definitions]] a
|
|||
This overview provides easy access to the system message pages that define each gadget's description and code.",
|
||||
'gadgets-uses' => 'Uses',
|
||||
'gadgets-required-rights' => 'Requires the {{PLURAL:$2|$1 right|following rights: $1}}.',
|
||||
'gadgets-default' => 'Enabled for everyone by default.',
|
||||
'gadgets-export' => 'Export',
|
||||
'gadgets-export-title' => 'Gadget export',
|
||||
'gadgets-not-found' => 'Gadget "$1" not found.',
|
||||
|
|
|
@ -40,12 +40,16 @@
|
|||
if (!$gadgets) return true;
|
||||
|
||||
$options = array();
|
||||
$default = array();
|
||||
foreach( $gadgets as $section => $thisSection ) {
|
||||
$available = array();
|
||||
foreach( $thisSection as $gadget ) {
|
||||
if ( $gadget->isAllowed( $user ) ) {
|
||||
$gname = $gadget->getName();
|
||||
$available[wfMsgExt( "gadget-$gname", 'parseinline' )] = $gname;
|
||||
if ( $gadget->isEnabled( $user ) ) {
|
||||
$default[] = $gname;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $section !== '' ) {
|
||||
|
@ -77,6 +81,7 @@
|
|||
'section' => 'gadgets',
|
||||
'label' => ' ',
|
||||
'prefix' => 'gadget-',
|
||||
'default' => $default,
|
||||
);
|
||||
|
||||
return true;
|
||||
|
@ -107,8 +112,6 @@
|
|||
public static function beforePageDisplay( $out ) {
|
||||
global $wgUser;
|
||||
|
||||
if ( !$wgUser->isLoggedIn() ) return true;
|
||||
|
||||
wfProfileIn( __METHOD__ );
|
||||
|
||||
$gadgets = Gadget::loadList();
|
||||
|
@ -187,7 +190,7 @@ class Gadget {
|
|||
/**
|
||||
* Increment this when changing class structure
|
||||
*/
|
||||
const GADGET_CLASS_VERSION = 3;
|
||||
const GADGET_CLASS_VERSION = 4;
|
||||
|
||||
private $version = self::GADGET_CLASS_VERSION,
|
||||
$scripts = array(),
|
||||
|
@ -196,7 +199,8 @@ class Gadget {
|
|||
$name,
|
||||
$definition,
|
||||
$resourceLoaded = false,
|
||||
$requiredRights = array();
|
||||
$requiredRights = array(),
|
||||
$onByDefault = false;
|
||||
|
||||
/**
|
||||
* Creates an instance of this class from definition in MediaWiki:Gadgets-definition
|
||||
|
@ -234,6 +238,9 @@ class Gadget {
|
|||
case 'rights':
|
||||
$gadget->requiredRights = $params;
|
||||
break;
|
||||
case 'default':
|
||||
$gadget->onByDefault = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach ( preg_split( '/\s*\|\s*/', $m[3], -1, PREG_SPLIT_NO_EMPTY ) as $page ) {
|
||||
|
@ -276,7 +283,7 @@ class Gadget {
|
|||
* @return Boolean
|
||||
*/
|
||||
public function isEnabled( $user ) {
|
||||
return (bool)$user->getOption( "gadget-{$this->name}" );
|
||||
return (bool)$user->getOption( "gadget-{$this->name}", $this->onByDefault );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -289,6 +296,13 @@ class Gadget {
|
|||
return count( array_intersect( $this->requiredRights, $user->getRights() ) ) == count( $this->requiredRights );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Boolean: Whether this gadget is on by default for everyone (but can be disabled in preferences)
|
||||
*/
|
||||
public function isOnByDefault() {
|
||||
return $this->onByDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Boolean: Whether all of this gadget's JS components support ResourceLoader
|
||||
*/
|
||||
|
|
63
README
63
README
|
@ -28,68 +28,7 @@ LocalSettings.php file (near the end):
|
|||
require_once( "$IP/extensions/Gadgets/Gadgets.php" );
|
||||
|
||||
== Usage ==
|
||||
The list of available gadgets is defined on MediaWiki:Gadgets-definition.
|
||||
Gadgets defined there show up in the "Gadgets" section of
|
||||
Special:Preferences, so users can pick the gadgets they would like to use.
|
||||
An overview of the gadgets defined by MediaWiki:Gadgets-definition is also
|
||||
shown on Special:Gadgets, along with links to the respective system
|
||||
messages, for easy editing.
|
||||
|
||||
Each line in MediaWiki:Gadgets-definition that start with one or more "*"
|
||||
(asterisk) characters defines a gadget; it must have the following form:
|
||||
|
||||
* mygadget|mygadget.js|mygadget.css
|
||||
|
||||
or
|
||||
|
||||
* mygadget[ResourceLoader]|mygadget.js|mygadget.css
|
||||
|
||||
That is, each line consists of fields separated by a "|" (pipe) character.
|
||||
The first field ("mygadget" in the example) is the gadgets internal name,
|
||||
and references a system message (MediaWiki:Gadget-mygadget in the example)
|
||||
that contains a short description of the gadget, using wiki syntax.
|
||||
Note that the internal name must start with an ASCII letter, must not be
|
||||
longer than 25 bytes, and must contain only ASCII letters and numbers,
|
||||
hyphens ("-"), underscores ("_"), colons (":"), and periods (".")
|
||||
(spaces are also allowed but converted to underscores ("_"), like for
|
||||
page titles).
|
||||
|
||||
If the gadget name is followed by [ResourceLoader], its JavaScript will
|
||||
be loaded concatenated, minified and gzipped by ResourceLoader, thus
|
||||
improving load times. However, older gadgets may be incompatible with
|
||||
ResourceLoader, so all JS is by default loaded the old way, using separate
|
||||
<script> tags.
|
||||
|
||||
The remaining fields on the line refer to the JavaScript or CSS code that
|
||||
makes up the gadget, contained in system messages
|
||||
(MediaWiki:Gadget-mygadget.js and MediaWiki:Gadget-mygadget.css in the
|
||||
example); the names of those messages must end with ".js" or ".css",
|
||||
respectively. A gadget can use any number of code messages, specifically,
|
||||
common code can be put into a code message used by several gadgets, in
|
||||
addition to their own specific code, e.g:
|
||||
|
||||
* frobinator|commonStuff.js|frob.js|frob.css|pretty.css
|
||||
* l33t|commonStuff.js|tools.js|l33t.js
|
||||
|
||||
Gadget definitions can contain whitespace between its elements, e.g.
|
||||
the following definitions are equivalent:
|
||||
|
||||
*mygadget[ResourceLoader]|mygadget.js|mygadget.css
|
||||
|
||||
and
|
||||
|
||||
* mygadget [ ResourceLoader ] | mygadget.js | mygadget.css
|
||||
|
||||
The list of gadgets in MediaWiki:Gadgets-definition can be broken into
|
||||
sections using lines that start and end with two or more "=" (equals)
|
||||
characters, enclosing the name of a system message that defines the
|
||||
section's name - for example:
|
||||
|
||||
== editing-gadgets ==
|
||||
|
||||
This would define a new section, with the title defined on the page
|
||||
MediaWiki:Gadget-section-editing-gadgets
|
||||
|
||||
See http://www.mediawiki.org/wiki/Extension:Gadgets#Usage
|
||||
|
||||
== Caveats ==
|
||||
|
||||
|
|
|
@ -116,8 +116,12 @@ class SpecialGadgets extends SpecialPage {
|
|||
$wgOut->addHTML( $wgLang->commaList( $lnk ) );
|
||||
$rights = $gadget->getRequiredRights();
|
||||
if ( count( $rights ) ) {
|
||||
$wgOut->addHTML( '<br />' );
|
||||
$wgOut->addWikiMsg( 'gadgets-required-rights', $wgLang->commaList( $rights ), count( $rights ) );
|
||||
$wgOut->addHTML( '<br />' .
|
||||
wfMessage( 'gadgets-required-rights', $wgLang->commaList( $rights ), count( $rights ) )->parse()
|
||||
);
|
||||
}
|
||||
if ( $gadget->isOnByDefault() ) {
|
||||
$wgOut->addHTML( '<br />' . wfMessage( 'gadgets-default' )->parse() );
|
||||
}
|
||||
|
||||
$wgOut->addHTML( Xml::closeElement( 'li' ) . "\n" );
|
||||
|
|
Loading…
Reference in a new issue