Index: trunk/extensions/Vector/Vector.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | /* Configuration */ |
18 | 18 | |
19 | 19 | // Each module may be configured individually to be globally on/off or user preference based |
20 | | -$wgVectorModules = array( |
| 20 | +$wgVectorFeatures = array( |
21 | 21 | 'collapsiblenav' => array( 'global' => true, 'user' => true ), |
22 | 22 | 'collapsibletabs' => array( 'global' => true, 'user' => false ), |
23 | 23 | 'editwarning' => array( 'global' => false, 'user' => true ), |
Index: trunk/extensions/Vector/Vector.hooks.php |
— | — | @@ -8,26 +8,65 @@ |
9 | 9 | |
10 | 10 | class VectorHooks { |
11 | 11 | |
12 | | - /* Static Members */ |
| 12 | + /* Protected Static Members */ |
13 | 13 | |
14 | | - static $modules = array( |
15 | | - 'collapsiblenav' => array( |
16 | | - 'name' => 'vector.collapsibleNav', |
17 | | - 'resources' => array( |
18 | | - 'scripts' => 'extensions/Vector/modules/vector.collapsibleNav.js', |
19 | | - 'styles' => 'extensions/Vector/modules/vector.collapsibleNav.css', |
20 | | - 'messages' => array( |
21 | | - 'vector-collapsiblenav-more', |
22 | | - ), |
23 | | - 'dependencies' => array( |
24 | | - 'jquery.client', |
25 | | - 'jquery.cookie', |
26 | | - 'jquery.tabIndex', |
27 | | - ), |
| 14 | + protected static $modules = array( |
| 15 | + 'vector.collapsibleNav' => array( |
| 16 | + 'scripts' => 'extensions/Vector/modules/vector.collapsibleNav.js', |
| 17 | + 'styles' => 'extensions/Vector/modules/vector.collapsibleNav.css', |
| 18 | + 'messages' => array( |
| 19 | + 'vector-collapsiblenav-more', |
28 | 20 | ), |
| 21 | + 'dependencies' => array( |
| 22 | + 'jquery.client', |
| 23 | + 'jquery.cookie', |
| 24 | + 'jquery.tabIndex', |
| 25 | + ), |
| 26 | + ), |
| 27 | + 'vector.collapsibleTabs' => array( |
| 28 | + 'scripts' => 'extensions/Vector/modules/vector.collapsibleTabs.js', |
| 29 | + 'dependencies' => array( |
| 30 | + 'jquery.collapsibleTabs', |
| 31 | + 'jquery.delayedBind', |
| 32 | + ), |
| 33 | + ), |
| 34 | + 'vector.editWarning' => array( |
| 35 | + 'scripts' => 'extensions/Vector/modules/vector.editWarning.js', |
| 36 | + 'messages' => array( |
| 37 | + 'vector-editwarning-warning', |
| 38 | + ), |
| 39 | + ), |
| 40 | + 'vector.expandableSearch' => array( |
| 41 | + 'scripts' => 'extensions/Vector/modules/vector.expandableSearch.js', |
| 42 | + 'styles' => 'extensions/Vector/modules/vector.expandableSearch.css', |
| 43 | + 'dependencies' => array( |
| 44 | + 'jquery.client', |
| 45 | + 'jquery.expandableField', |
| 46 | + 'jquery.delayedBind', |
| 47 | + ), |
| 48 | + ), |
| 49 | + 'vector.footerCleanup' => array( |
| 50 | + 'scripts' => 'extensions/Vector/modules/vector.footerCleanup.js', |
| 51 | + 'styles' => 'extensions/Vector/modules/vector.footerCleanup.css', |
| 52 | + ), |
| 53 | + 'vector.simpleSearch' => array( |
| 54 | + 'scripts' => 'extensions/Vector/modules/vector.simpleSearch.js', |
| 55 | + 'messages' => array( |
| 56 | + 'vector-simplesearch-search', |
| 57 | + 'vector-simplesearch-containing', |
| 58 | + ), |
| 59 | + 'dependencies' => array( |
| 60 | + 'jquery.client', |
| 61 | + 'jquery.suggestions', |
| 62 | + 'jquery.autoEllipsis', |
| 63 | + ), |
| 64 | + ), |
| 65 | + ); |
| 66 | + |
| 67 | + protected static $features = array( |
| 68 | + 'collapsiblenav' => array( |
29 | 69 | 'preferences' => array( |
30 | | - 'key' => 'vector-collapsiblenav', |
31 | | - 'ui' => array( |
| 70 | + 'vector-collapsiblenav' => array( |
32 | 71 | 'type' => 'toggle', |
33 | 72 | 'label-message' => 'vector-collapsiblenav-preference', |
34 | 73 | 'section' => 'rendering/advancedrendering', |
— | — | @@ -37,101 +76,58 @@ |
38 | 77 | 'wgCollapsibleNavBucketTest', |
39 | 78 | 'wgCollapsibleNavForceNewVersion', |
40 | 79 | ), |
| 80 | + 'modules' => array( 'vector.collapsibleNav' ), |
41 | 81 | ), |
42 | 82 | 'collapsibletabs' => array( |
43 | | - 'name' => 'vector.collapsibleTabs', |
44 | | - 'resources' => array( |
45 | | - 'scripts' => 'extensions/Vector/modules/vector.collapsibleTabs.js', |
46 | | - 'dependencies' => array( |
47 | | - 'jquery.collapsibleTabs', |
48 | | - 'jquery.delayedBind', |
49 | | - ), |
50 | | - ), |
| 83 | + 'modules' => array( 'vector.collapsibleTabs' ), |
51 | 84 | ), |
52 | 85 | 'editwarning' => array( |
53 | | - 'name' => 'vector.editWarning', |
54 | | - 'resources' => array( |
55 | | - 'scripts' => 'extensions/Vector/modules/vector.editWarning.js', |
56 | | - 'messages' => array( |
57 | | - 'vector-editwarning-warning', |
58 | | - ), |
59 | | - ), |
60 | 86 | 'preferences' => array( |
61 | 87 | // Ideally this would be 'vector-editwarning' |
62 | | - 'key' => 'useeditwarning', |
63 | | - 'ui' => array( |
| 88 | + 'useeditwarning' => array( |
64 | 89 | 'type' => 'toggle', |
65 | 90 | 'label-message' => 'vector-editwarning-preference', |
66 | 91 | 'section' => 'editing/advancedediting', |
67 | 92 | ), |
68 | 93 | ), |
| 94 | + 'modules' => array( 'vector.editWarning' ), |
69 | 95 | ), |
70 | 96 | 'expandablesearch' => array( |
71 | | - 'name' => 'vector.expandableSearch', |
72 | | - 'resources' => array( |
73 | | - 'scripts' => 'extensions/Vector/modules/vector.expandableSearch.js', |
74 | | - 'styles' => 'extensions/Vector/modules/vector.expandableSearch.css', |
75 | | - 'dependencies' => array( |
76 | | - 'jquery.client', |
77 | | - 'jquery.expandableField', |
78 | | - 'jquery.delayedBind', |
79 | | - ), |
80 | | - ), |
81 | | - 'preferences' => array( |
82 | | - 'requirements' => array( 'vector-simplesearch' => true ), |
83 | | - ), |
| 97 | + 'requirements' => array( 'vector-simplesearch' => true ), |
| 98 | + 'modules' => array( 'vector.expandableSearch' ), |
84 | 99 | ), |
85 | 100 | 'footercleanup' => array( |
86 | | - 'name' => 'vector.footerCleanup', |
87 | | - 'resources' => array( |
88 | | - 'scripts' => 'extensions/Vector/modules/vector.footerCleanup.js', |
89 | | - 'styles' => 'extensions/Vector/modules/vector.footerCleanup.css', |
90 | | - ), |
| 101 | + 'modules' => array( 'vector.footerCleanup' ), |
91 | 102 | ), |
92 | 103 | 'simplesearch' => array( |
93 | | - 'name' => 'vector.simpleSearch', |
94 | | - 'resources' => array( |
95 | | - 'scripts' => 'extensions/Vector/modules/vector.simpleSearch.js', |
96 | | - 'messages' => array( |
97 | | - 'vector-simplesearch-search', |
98 | | - 'vector-simplesearch-containing', |
99 | | - ), |
100 | | - 'dependencies' => array( |
101 | | - 'jquery.client', |
102 | | - 'jquery.suggestions', |
103 | | - 'jquery.autoEllipsis', |
104 | | - ), |
105 | | - ), |
106 | | - 'preferences' => array( |
107 | | - 'requirements' => array( 'vector-simplesearch' => true, 'disablesuggest' => false ), |
108 | | - ), |
| 104 | + 'requirements' => array( 'vector-simplesearch' => true, 'disablesuggest' => false ), |
| 105 | + 'modules' => array( 'vector.simpleSearch' ), |
109 | 106 | ), |
110 | 107 | ); |
111 | 108 | |
112 | 109 | /* Protected Static Methods */ |
113 | 110 | |
114 | | - protected static function isEnabled( $module ) { |
115 | | - global $wgVectorModules, $wgUser; |
| 111 | + protected static function isEnabled( $name ) { |
| 112 | + global $wgVectorFeatures, $wgUser; |
116 | 113 | |
117 | | - $enabled = |
118 | | - $wgVectorModules[$module]['global'] || |
119 | | - ( |
120 | | - $wgVectorModules[$module]['user'] && |
121 | | - isset( self::$modules[$module]['preferences']['key'] ) && |
122 | | - $wgUser->getOption( self::$modules[$module]['preferences']['key'] ) |
123 | | - ); |
124 | | - if ( !$enabled ) { |
125 | | - return false; |
| 114 | + // Features with global set to true are always enabled |
| 115 | + if ( !isset( $wgVectorFeatures[$name] ) || $wgVectorFeatures[$name]['global'] ) { |
| 116 | + return true; |
126 | 117 | } |
127 | | - if ( isset( self::$modules[$module]['preferences']['requirements'] ) ) { |
128 | | - foreach ( self::$modules[$module]['preferences']['requirements'] as $requirement => $value ) { |
129 | | - // Important! We really do want fuzzy evaluation here |
130 | | - if ( $wgUser->getOption( $requirement ) != $value ) { |
131 | | - return false; |
| 118 | + // Features with user preference control can have any number of preferences to be specific values to be enabled |
| 119 | + if ( $wgVectorFeatures[$name]['user'] ) { |
| 120 | + if ( isset( self::$features[$name]['requirements'] ) ) { |
| 121 | + foreach ( self::$features[$name]['requirements'] as $requirement => $value ) { |
| 122 | + // Important! We really do want fuzzy evaluation here |
| 123 | + if ( $wgUser->getOption( $requirement ) != $value ) { |
| 124 | + return false; |
| 125 | + } |
132 | 126 | } |
133 | 127 | } |
| 128 | + return true; |
134 | 129 | } |
135 | | - return true; |
| 130 | + // Features controlled by $wgVectorFeatures with both global and user set to false are awlways disabled |
| 131 | + return false; |
136 | 132 | } |
137 | 133 | |
138 | 134 | /* Static Methods */ |
— | — | @@ -139,23 +135,16 @@ |
140 | 136 | /** |
141 | 137 | * BeforePageDisplay hook |
142 | 138 | * |
143 | | - * Adds the modules to the edit form |
| 139 | + * Adds the modules to the page |
144 | 140 | * |
145 | 141 | * @param $out OutputPage output page |
146 | 142 | * @param $skin Skin current skin |
147 | 143 | */ |
148 | 144 | public static function beforePageDisplay( $out, $skin ) { |
149 | | - global $wgVectorModules; |
150 | | - |
151 | | - // Don't load Vector modules for non-Vector skins |
152 | | - if ( !( $skin instanceof SkinVector ) ) { |
153 | | - return true; |
154 | | - } |
155 | | - |
156 | | - // Add enabled modules |
157 | | - foreach ( $wgVectorModules as $module => $enable ) { |
158 | | - if ( self::isEnabled( $module ) ) { |
159 | | - $out->addModules( self::$modules[$module]['name'] ); |
| 145 | + // Add modules for enabled features |
| 146 | + foreach ( self::$features as $name => $feature ) { |
| 147 | + if ( isset( $feature['modules'] ) && self::isEnabled( $name ) ) { |
| 148 | + $out->addModules( $feature['modules'] ); |
160 | 149 | } |
161 | 150 | } |
162 | 151 | return true; |
— | — | @@ -170,12 +159,15 @@ |
171 | 160 | * @param $skin array list of default user preference controls |
172 | 161 | */ |
173 | 162 | public static function getPreferences( $user, &$defaultPreferences ) { |
174 | | - global $wgVectorModules; |
| 163 | + global $wgVectorFeatures; |
175 | 164 | |
176 | | - foreach ( $wgVectorModules as $module => $enable ) { |
177 | | - if ( $enable['user'] && isset( self::$modules['preferences'][$module]['ui'] ) ) { |
178 | | - $defaultPreferences[self::$modules['preferences'][$module]['key']] = |
179 | | - self::$modules['preferences'][$module]['ui']; |
| 165 | + foreach ( self::$features as $name => $feature ) { |
| 166 | + if ( |
| 167 | + isset( $feature['preferences'] ) && |
| 168 | + ( !isset( $wgVectorFeatures[$name] ) || $wgVectorFeatures[$name]['user'] ) |
| 169 | + ) { |
| 170 | + foreach ( $feature['preferences'] as $key => $options ) |
| 171 | + $defaultPreferences[$key] = $options; |
180 | 172 | } |
181 | 173 | } |
182 | 174 | return true; |
— | — | @@ -187,15 +179,15 @@ |
188 | 180 | * Adds enabled/disabled switches for Vector modules |
189 | 181 | */ |
190 | 182 | public static function makeGlobalVariablesScript( &$vars ) { |
191 | | - global $wgVectorModules; |
| 183 | + global $wgVectorFeatures; |
192 | 184 | |
193 | 185 | $configurations = array(); |
194 | | - foreach ( $wgVectorModules as $module => $enable ) { |
| 186 | + foreach ( self::$features as $name => $feature ) { |
195 | 187 | if ( |
196 | | - isset( self::$modules[$module]['configurations'] ) && |
197 | | - is_array( self::$modules[$module]['configurations'] ) |
| 188 | + isset( $feature['configurations'] ) && |
| 189 | + ( !isset( $wgVectorFeatures[$name] ) || self::isEnabled( $name ) ) |
198 | 190 | ) { |
199 | | - foreach ( self::$modules[$module]['configurations'] as $configuration ) { |
| 191 | + foreach ( $feature['configurations'] as $configuration ) { |
200 | 192 | global $$configuration; |
201 | 193 | $configurations[$configuration] = $$configuration; |
202 | 194 | } |
— | — | @@ -213,8 +205,8 @@ |
214 | 206 | * Adds modules to ResourceLoader |
215 | 207 | */ |
216 | 208 | public static function resourceLoaderRegisterModules() { |
217 | | - foreach ( self::$modules as $module ) { |
218 | | - ResourceLoader::register( $module['name'], new ResourceLoaderFileModule( $module['resources'] ) ); |
| 209 | + foreach ( self::$modules as $name => $resources ) { |
| 210 | + ResourceLoader::register( $name, new ResourceLoaderFileModule( $resources ) ); |
219 | 211 | } |
220 | 212 | return true; |
221 | 213 | } |
Index: trunk/extensions/Vector/README |
— | — | @@ -0,0 +1,22 @@ |
| 2 | +# Enhancements to the Vector skin |
| 3 | +# |
| 4 | +# This is a MediaWiki 1.17+ compatible version of the former UsabilityInitiative/Vector extension. The key differences |
| 5 | +# between these versions is in the usage of ResourceLoader. |
| 6 | +# |
| 7 | +# To get this working on your wiki |
| 8 | + |
| 9 | +require_once( "$IP/extensions/Vector/Vector.php" ); |
| 10 | + |
| 11 | +# Before configuring this extension, see Vector.php and become familiar with the initial state and structure of the |
| 12 | +# $wgVectorFeatures configuration variable. Essentially it's an array or arrays, keyed by feature name, each containing |
| 13 | +# global and user keys with boolean values. "global" indicates that it should be turned on for everyone always, while |
| 14 | +# user indicates that users should be allowed to turn it on or off in their user preferences. |
| 15 | + |
| 16 | +# To enable a preference by default but still allow users to disable it in preferences, use something like... |
| 17 | + |
| 18 | +$wgDefaultUserOptions['vector-collapsiblenav'] = 1; |
| 19 | + |
| 20 | +# By default, the Vector skin does not use the simplified serach box. To take advantage of the simplesearch feature you |
| 21 | +# must add this to your LocalSettings.php file. |
| 22 | + |
| 23 | +$wgVectorUseSimpleSearch = true; |