Index: trunk/extensions/Gadgets/Gadgets_body.php |
— | — | @@ -40,12 +40,16 @@ |
41 | 41 | if (!$gadgets) return true; |
42 | 42 | |
43 | 43 | $options = array(); |
| 44 | + $default = array(); |
44 | 45 | foreach( $gadgets as $section => $thisSection ) { |
45 | 46 | $available = array(); |
46 | 47 | foreach( $thisSection as $gadget ) { |
47 | 48 | if ( $gadget->isAllowed( $user ) ) { |
48 | 49 | $gname = $gadget->getName(); |
49 | 50 | $available[wfMsgExt( "gadget-$gname", 'parseinline' )] = $gname; |
| 51 | + if ( $gadget->isEnabled( $user ) ) { |
| 52 | + $default[] = $gname; |
| 53 | + } |
50 | 54 | } |
51 | 55 | } |
52 | 56 | if ( $section !== '' ) { |
— | — | @@ -77,6 +81,7 @@ |
78 | 82 | 'section' => 'gadgets', |
79 | 83 | 'label' => ' ', |
80 | 84 | 'prefix' => 'gadget-', |
| 85 | + 'default' => $default, |
81 | 86 | ); |
82 | 87 | |
83 | 88 | return true; |
— | — | @@ -107,8 +112,6 @@ |
108 | 113 | public static function beforePageDisplay( $out ) { |
109 | 114 | global $wgUser; |
110 | 115 | |
111 | | - if ( !$wgUser->isLoggedIn() ) return true; |
112 | | - |
113 | 116 | wfProfileIn( __METHOD__ ); |
114 | 117 | |
115 | 118 | $gadgets = Gadget::loadList(); |
— | — | @@ -187,7 +190,7 @@ |
188 | 191 | /** |
189 | 192 | * Increment this when changing class structure |
190 | 193 | */ |
191 | | - const GADGET_CLASS_VERSION = 3; |
| 194 | + const GADGET_CLASS_VERSION = 4; |
192 | 195 | |
193 | 196 | private $version = self::GADGET_CLASS_VERSION, |
194 | 197 | $scripts = array(), |
— | — | @@ -196,7 +199,8 @@ |
197 | 200 | $name, |
198 | 201 | $definition, |
199 | 202 | $resourceLoaded = false, |
200 | | - $requiredRights = array(); |
| 203 | + $requiredRights = array(), |
| 204 | + $onByDefault = false; |
201 | 205 | |
202 | 206 | /** |
203 | 207 | * Creates an instance of this class from definition in MediaWiki:Gadgets-definition |
— | — | @@ -234,6 +238,9 @@ |
235 | 239 | case 'rights': |
236 | 240 | $gadget->requiredRights = $params; |
237 | 241 | break; |
| 242 | + case 'default': |
| 243 | + $gadget->onByDefault = true; |
| 244 | + break; |
238 | 245 | } |
239 | 246 | } |
240 | 247 | foreach ( preg_split( '/\s*\|\s*/', $m[3], -1, PREG_SPLIT_NO_EMPTY ) as $page ) { |
— | — | @@ -276,7 +283,7 @@ |
277 | 284 | * @return Boolean |
278 | 285 | */ |
279 | 286 | public function isEnabled( $user ) { |
280 | | - return (bool)$user->getOption( "gadget-{$this->name}" ); |
| 287 | + return (bool)$user->getOption( "gadget-{$this->name}", $this->onByDefault ); |
281 | 288 | } |
282 | 289 | |
283 | 290 | /** |
— | — | @@ -290,6 +297,13 @@ |
291 | 298 | } |
292 | 299 | |
293 | 300 | /** |
| 301 | + * @return Boolean: Whether this gadget is on by default for everyone (but can be disabled in preferences) |
| 302 | + */ |
| 303 | + public function isOnByDefault() { |
| 304 | + return $this->onByDefault; |
| 305 | + } |
| 306 | + |
| 307 | + /** |
294 | 308 | * @return Boolean: Whether all of this gadget's JS components support ResourceLoader |
295 | 309 | */ |
296 | 310 | public function supportsResourceLoader() { |
Index: trunk/extensions/Gadgets/Gadgets.i18n.php |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | This overview provides easy access to the system message pages that define each gadget's description and code.", |
36 | 36 | 'gadgets-uses' => 'Uses', |
37 | 37 | 'gadgets-required-rights' => 'Requires the {{PLURAL:$2|$1 right|following rights: $1}}.', |
| 38 | + 'gadgets-default' => 'Enabled for everyone by default.', |
38 | 39 | 'gadgets-export' => 'Export', |
39 | 40 | 'gadgets-export-title' => 'Gadget export', |
40 | 41 | 'gadgets-not-found' => 'Gadget "$1" not found.', |
Index: trunk/extensions/Gadgets/SpecialGadgets.php |
— | — | @@ -116,9 +116,13 @@ |
117 | 117 | $wgOut->addHTML( $wgLang->commaList( $lnk ) ); |
118 | 118 | $rights = $gadget->getRequiredRights(); |
119 | 119 | if ( count( $rights ) ) { |
120 | | - $wgOut->addHTML( '<br />' ); |
121 | | - $wgOut->addWikiMsg( 'gadgets-required-rights', $wgLang->commaList( $rights ), count( $rights ) ); |
| 120 | + $wgOut->addHTML( '<br />' . |
| 121 | + wfMessage( 'gadgets-required-rights', $wgLang->commaList( $rights ), count( $rights ) )->parse() |
| 122 | + ); |
122 | 123 | } |
| 124 | + if ( $gadget->isOnByDefault() ) { |
| 125 | + $wgOut->addHTML( '<br />' . wfMessage( 'gadgets-default' )->parse() ); |
| 126 | + } |
123 | 127 | |
124 | 128 | $wgOut->addHTML( Xml::closeElement( 'li' ) . "\n" ); |
125 | 129 | } |
Index: trunk/extensions/Gadgets/README |
— | — | @@ -28,69 +28,8 @@ |
29 | 29 | require_once( "$IP/extensions/Gadgets/Gadgets.php" ); |
30 | 30 | |
31 | 31 | == Usage == |
32 | | -The list of available gadgets is defined on MediaWiki:Gadgets-definition. |
33 | | -Gadgets defined there show up in the "Gadgets" section of |
34 | | -Special:Preferences, so users can pick the gadgets they would like to use. |
35 | | -An overview of the gadgets defined by MediaWiki:Gadgets-definition is also |
36 | | -shown on Special:Gadgets, along with links to the respective system |
37 | | -messages, for easy editing. |
| 32 | +See http://www.mediawiki.org/wiki/Extension:Gadgets#Usage |
38 | 33 | |
39 | | -Each line in MediaWiki:Gadgets-definition that start with one or more "*" |
40 | | -(asterisk) characters defines a gadget; it must have the following form: |
41 | | - |
42 | | - * mygadget|mygadget.js|mygadget.css |
43 | | - |
44 | | -or |
45 | | - |
46 | | - * mygadget[ResourceLoader]|mygadget.js|mygadget.css |
47 | | - |
48 | | -That is, each line consists of fields separated by a "|" (pipe) character. |
49 | | -The first field ("mygadget" in the example) is the gadgets internal name, |
50 | | -and references a system message (MediaWiki:Gadget-mygadget in the example) |
51 | | -that contains a short description of the gadget, using wiki syntax. |
52 | | -Note that the internal name must start with an ASCII letter, must not be |
53 | | -longer than 25 bytes, and must contain only ASCII letters and numbers, |
54 | | -hyphens ("-"), underscores ("_"), colons (":"), and periods (".") |
55 | | -(spaces are also allowed but converted to underscores ("_"), like for |
56 | | -page titles). |
57 | | - |
58 | | -If the gadget name is followed by [ResourceLoader], its JavaScript will |
59 | | -be loaded concatenated, minified and gzipped by ResourceLoader, thus |
60 | | -improving load times. However, older gadgets may be incompatible with |
61 | | -ResourceLoader, so all JS is by default loaded the old way, using separate |
62 | | -<script> tags. |
63 | | - |
64 | | -The remaining fields on the line refer to the JavaScript or CSS code that |
65 | | -makes up the gadget, contained in system messages |
66 | | -(MediaWiki:Gadget-mygadget.js and MediaWiki:Gadget-mygadget.css in the |
67 | | -example); the names of those messages must end with ".js" or ".css", |
68 | | -respectively. A gadget can use any number of code messages, specifically, |
69 | | -common code can be put into a code message used by several gadgets, in |
70 | | -addition to their own specific code, e.g: |
71 | | - |
72 | | - * frobinator|commonStuff.js|frob.js|frob.css|pretty.css |
73 | | - * l33t|commonStuff.js|tools.js|l33t.js |
74 | | - |
75 | | -Gadget definitions can contain whitespace between its elements, e.g. |
76 | | -the following definitions are equivalent: |
77 | | - |
78 | | - *mygadget[ResourceLoader]|mygadget.js|mygadget.css |
79 | | - |
80 | | -and |
81 | | - |
82 | | - * mygadget [ ResourceLoader ] | mygadget.js | mygadget.css |
83 | | - |
84 | | -The list of gadgets in MediaWiki:Gadgets-definition can be broken into |
85 | | -sections using lines that start and end with two or more "=" (equals) |
86 | | -characters, enclosing the name of a system message that defines the |
87 | | -section's name - for example: |
88 | | - |
89 | | - == editing-gadgets == |
90 | | - |
91 | | -This would define a new section, with the title defined on the page |
92 | | -MediaWiki:Gadget-section-editing-gadgets |
93 | | - |
94 | | - |
95 | 34 | == Caveats == |
96 | 35 | |
97 | 36 | * Gadgets do not apply to Special:Preferences, Special:UserLogin and |