r73181 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73180‎ | r73181 | r73182 >
Date:23:41, 16 September 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Brought code from WikiEditor extension in, reorganized module/feature definitions
Modified paths:
  • /trunk/extensions/Vector/README (added) (history)
  • /trunk/extensions/Vector/Vector.hooks.php (modified) (history)
  • /trunk/extensions/Vector/Vector.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Vector/Vector.php
@@ -16,7 +16,7 @@
1717 /* Configuration */
1818
1919 // Each module may be configured individually to be globally on/off or user preference based
20 -$wgVectorModules = array(
 20+$wgVectorFeatures = array(
2121 'collapsiblenav' => array( 'global' => true, 'user' => true ),
2222 'collapsibletabs' => array( 'global' => true, 'user' => false ),
2323 'editwarning' => array( 'global' => false, 'user' => true ),
Index: trunk/extensions/Vector/Vector.hooks.php
@@ -8,26 +8,65 @@
99
1010 class VectorHooks {
1111
12 - /* Static Members */
 12+ /* Protected Static Members */
1313
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',
2820 ),
 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(
2969 'preferences' => array(
30 - 'key' => 'vector-collapsiblenav',
31 - 'ui' => array(
 70+ 'vector-collapsiblenav' => array(
3271 'type' => 'toggle',
3372 'label-message' => 'vector-collapsiblenav-preference',
3473 'section' => 'rendering/advancedrendering',
@@ -37,101 +76,58 @@
3877 'wgCollapsibleNavBucketTest',
3978 'wgCollapsibleNavForceNewVersion',
4079 ),
 80+ 'modules' => array( 'vector.collapsibleNav' ),
4181 ),
4282 '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' ),
5184 ),
5285 '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 - ),
6086 'preferences' => array(
6187 // Ideally this would be 'vector-editwarning'
62 - 'key' => 'useeditwarning',
63 - 'ui' => array(
 88+ 'useeditwarning' => array(
6489 'type' => 'toggle',
6590 'label-message' => 'vector-editwarning-preference',
6691 'section' => 'editing/advancedediting',
6792 ),
6893 ),
 94+ 'modules' => array( 'vector.editWarning' ),
6995 ),
7096 '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' ),
8499 ),
85100 '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' ),
91102 ),
92103 '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' ),
109106 ),
110107 );
111108
112109 /* Protected Static Methods */
113110
114 - protected static function isEnabled( $module ) {
115 - global $wgVectorModules, $wgUser;
 111+ protected static function isEnabled( $name ) {
 112+ global $wgVectorFeatures, $wgUser;
116113
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;
126117 }
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+ }
132126 }
133127 }
 128+ return true;
134129 }
135 - return true;
 130+ // Features controlled by $wgVectorFeatures with both global and user set to false are awlways disabled
 131+ return false;
136132 }
137133
138134 /* Static Methods */
@@ -139,23 +135,16 @@
140136 /**
141137 * BeforePageDisplay hook
142138 *
143 - * Adds the modules to the edit form
 139+ * Adds the modules to the page
144140 *
145141 * @param $out OutputPage output page
146142 * @param $skin Skin current skin
147143 */
148144 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'] );
160149 }
161150 }
162151 return true;
@@ -170,12 +159,15 @@
171160 * @param $skin array list of default user preference controls
172161 */
173162 public static function getPreferences( $user, &$defaultPreferences ) {
174 - global $wgVectorModules;
 163+ global $wgVectorFeatures;
175164
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;
180172 }
181173 }
182174 return true;
@@ -187,15 +179,15 @@
188180 * Adds enabled/disabled switches for Vector modules
189181 */
190182 public static function makeGlobalVariablesScript( &$vars ) {
191 - global $wgVectorModules;
 183+ global $wgVectorFeatures;
192184
193185 $configurations = array();
194 - foreach ( $wgVectorModules as $module => $enable ) {
 186+ foreach ( self::$features as $name => $feature ) {
195187 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 ) )
198190 ) {
199 - foreach ( self::$modules[$module]['configurations'] as $configuration ) {
 191+ foreach ( $feature['configurations'] as $configuration ) {
200192 global $$configuration;
201193 $configurations[$configuration] = $$configuration;
202194 }
@@ -213,8 +205,8 @@
214206 * Adds modules to ResourceLoader
215207 */
216208 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 ) );
219211 }
220212 return true;
221213 }
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;

Comments

#Comment by Catrope (talk | contribs)   18:15, 1 October 2010
+				foreach ( $feature['preferences'] as $key => $options )
+				$defaultPreferences[$key] = $options;

This is misindented.

+# $wgVectorFeatures configuration variable. Essentially it's an array or arrays, keyed by feature name, each containing

Array of arrays?

#Comment by Trevor Parscal (WMF) (talk | contribs)   19:32, 1 October 2010

The indentation things is resolved in r74086.

The typo is fixed in r74091.

Status & tagging log