http://www.mediawiki.org/wiki/Special:Code/MediaWiki/85902
Revision: 85902
Author: maxsem
Date: 2011-04-12 18:09:50 +0000 (Tue, 12 Apr 2011)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/extensions/Gadgets/Gadgets.i18n.php
trunk/extensions/Gadgets/Gadgets_body.php
trunk/extensions/Gadgets/README
trunk/extensions/Gadgets/SpecialGadgets.php
Modified: trunk/extensions/Gadgets/Gadgets.i18n.php
===================================================================
--- trunk/extensions/Gadgets/Gadgets.i18n.php 2011-04-12 18:03:29 UTC (rev
85901)
+++ trunk/extensions/Gadgets/Gadgets.i18n.php 2011-04-12 18:09:50 UTC (rev
85902)
@@ -34,6 +34,7 @@
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.',
Modified: trunk/extensions/Gadgets/Gadgets_body.php
===================================================================
--- trunk/extensions/Gadgets/Gadgets_body.php 2011-04-12 18:03:29 UTC (rev
85901)
+++ trunk/extensions/Gadgets/Gadgets_body.php 2011-04-12 18:09:50 UTC (rev
85902)
@@ -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 @@
/**
* 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 @@
$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 @@
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 @@
* @return Boolean
*/
public function isEnabled( $user ) {
- return (bool)$user->getOption( "gadget-{$this->name}" );
+ return (bool)$user->getOption( "gadget-{$this->name}",
$this->onByDefault );
}
/**
@@ -290,6 +297,13 @@
}
/**
+ * @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
*/
public function supportsResourceLoader() {
Modified: trunk/extensions/Gadgets/README
===================================================================
--- trunk/extensions/Gadgets/README 2011-04-12 18:03:29 UTC (rev 85901)
+++ trunk/extensions/Gadgets/README 2011-04-12 18:09:50 UTC (rev 85902)
@@ -28,69 +28,8 @@
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.
+See http://www.mediawiki.org/wiki/Extension:Gadgets#Usage
-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
-
-
== Caveats ==
* Gadgets do not apply to Special:Preferences, Special:UserLogin and
Modified: trunk/extensions/Gadgets/SpecialGadgets.php
===================================================================
--- trunk/extensions/Gadgets/SpecialGadgets.php 2011-04-12 18:03:29 UTC (rev
85901)
+++ trunk/extensions/Gadgets/SpecialGadgets.php 2011-04-12 18:09:50 UTC (rev
85902)
@@ -116,9 +116,13 @@
$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" );
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs