Index: trunk/extensions/UploadWizard/UploadWizardConfig.php |
— | — | @@ -0,0 +1,51 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Static class with methods for interacting with the Upload Wizards configuration. |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Upload |
| 9 | + * |
| 10 | + * @since 1.2 |
| 11 | + * |
| 12 | + * @licence GNU GPL v3+ |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class UploadWizardConfig { |
| 16 | + |
| 17 | + public static function getConfig( $campaignName = null ) { |
| 18 | + global $wgUploadWizardConfig; |
| 19 | + static $mergedConfig = false; |
| 20 | + |
| 21 | + if ( !$mergedConfig ) { |
| 22 | + $wgUploadWizardConfig = array_merge( self::getDefaultConfig(), $wgUploadWizardConfig ); |
| 23 | + } |
| 24 | + |
| 25 | + if ( !is_null( $campaignName ) ) { |
| 26 | + $wgUploadWizardConfig = array_merge( $wgUploadWizardConfig, self::getCampaignConfig( $campaignName ) ); |
| 27 | + } |
| 28 | + |
| 29 | + return $wgUploadWizardConfig; |
| 30 | + } |
| 31 | + |
| 32 | + protected static function getDefaultConfig() { |
| 33 | + global $wgUpwizDir; |
| 34 | + $configPath = $wgUpwizDir . '/UploadWizard.config.php'; |
| 35 | + return is_file( $configPath ) ? include( $configPath ) : array(); |
| 36 | + } |
| 37 | + |
| 38 | + protected static function getCampaignConfig( $campaignName ) { |
| 39 | + $capmaignSettings = array(); |
| 40 | + |
| 41 | + if ( !is_null( $capaignName ) ) { |
| 42 | + $capaign = UploadWizardCampaign::newFromName( $capaignName ); |
| 43 | + |
| 44 | + if ( $capaign !== false ) { |
| 45 | + return $capaign->getConfig(); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + return array(); |
| 50 | + } |
| 51 | + |
| 52 | +} |
Property changes on: trunk/extensions/UploadWizard/UploadWizardConfig.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 53 | + native |
Index: trunk/extensions/UploadWizard/UploadWizard.php |
— | — | @@ -37,6 +37,7 @@ |
38 | 38 | |
39 | 39 | # Require modules, including the special page |
40 | 40 | foreach ( array( |
| 41 | + 'UploadWizardConfig', |
41 | 42 | 'SpecialUploadWizard', |
42 | 43 | 'SpecialUploadCampaigns', |
43 | 44 | 'SpecialUploadCampaign', |
Index: trunk/extensions/UploadWizard/UploadWizardCampaign.php |
— | — | @@ -142,6 +142,49 @@ |
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
| 146 | + * Returns the list of configuration settings that can be modified by campaigns, |
| 147 | + * and the HTMLForm input type that can be used to represent their value. |
| 148 | + * Property name => HTMLForm input type |
| 149 | + * |
| 150 | + * @since 1.2 |
| 151 | + * |
| 152 | + * @return array |
| 153 | + */ |
| 154 | + public static function getConfigTypes() { |
| 155 | + return array( |
| 156 | + 'skipTutorial' => 'check' |
| 157 | + ); |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * Returns the default configuration values. |
| 162 | + * Property name => array( 'default' => $value, 'type' => HTMLForm input type ) |
| 163 | + * |
| 164 | + * @since 1.2 |
| 165 | + * |
| 166 | + * @return array |
| 167 | + */ |
| 168 | + public static function getDefaultConfig() { |
| 169 | + static $config = false; |
| 170 | + |
| 171 | + if ( $config === false ) { |
| 172 | + $config = array(); |
| 173 | + $globalConf = UploadWizardConfig::getConfig(); |
| 174 | + |
| 175 | + foreach ( self::getConfigTypes() as $setting => $type ) { |
| 176 | + if ( array_key_exists( $setting, $globalConf ) ) { |
| 177 | + $config[$setting] = array( 'type' => $type, 'default' => $globalConf[$setting] ); |
| 178 | + } |
| 179 | + else { |
| 180 | + wfWarn( "Nonexiting Upload Wizard configuration setting '$setting' will be ignored." ); |
| 181 | + } |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + return $config; |
| 186 | + } |
| 187 | + |
| 188 | + /** |
146 | 189 | * Returns the id of the campaign. |
147 | 190 | * |
148 | 191 | * @since 1.2 |
— | — | @@ -230,19 +273,6 @@ |
231 | 274 | } |
232 | 275 | |
233 | 276 | /** |
234 | | - * Returns the default configuration values. |
235 | | - * |
236 | | - * @since 1.2 |
237 | | - * |
238 | | - * @return array |
239 | | - */ |
240 | | - public static function getDefaultConfig() { |
241 | | - return array ( // TODO |
242 | | - 'skipTutorial' => array ( 'type' => 'check', 'default' => true ) |
243 | | - ); |
244 | | - } |
245 | | - |
246 | | - /** |
247 | 277 | * Returns the value of the specified config property. |
248 | 278 | * |
249 | 279 | * @since 1.2 |
Index: trunk/extensions/UploadWizard/SpecialUploadWizard.php |
— | — | @@ -82,7 +82,6 @@ |
83 | 83 | // where the uploadwizard will go |
84 | 84 | // TODO import more from UploadWizard's createInterface call. |
85 | 85 | $wgOut->addHTML( self::getWizardHtml() ); |
86 | | - |
87 | 86 | } |
88 | 87 | |
89 | 88 | /** |
— | — | @@ -95,29 +94,12 @@ |
96 | 95 | * @param subpage, e.g. the "foo" in Special:UploadWizard/foo |
97 | 96 | */ |
98 | 97 | public function addJsVars( $subPage ) { |
99 | | - global $wgOut, $wgUpwizDir, $wgUploadWizardConfig, $wgSitename, $wgRequest; |
100 | | - |
101 | | - $capmaignSettings = array(); |
102 | | - $capaignName = $wgRequest->getVal( 'campaign' ); |
103 | | - |
104 | | - if ( !is_null( $capaignName ) ) { |
105 | | - $capaign = UploadWizardCampaign::newFromName( $capaignName ); |
106 | | - |
107 | | - if ( $capaign !== false ) { |
108 | | - $capmaignSettings = $capaign->getConfig(); |
109 | | - } |
110 | | - } |
111 | | - |
112 | | - // Merge the default configuration with the local settings $wgUploadWizardConfig configuration |
113 | | - $configPath = $wgUpwizDir . '/UploadWizard.config.php'; |
114 | | - if( is_file( $configPath ) ){ |
115 | | - $wgUploadWizardConfig = array_merge( include( $configPath ), $wgUploadWizardConfig, $capmaignSettings ); |
116 | | - } |
| 98 | + global $wgOut, $wgSitename, $wgRequest; |
117 | 99 | |
118 | 100 | $wgOut->addScript( |
119 | 101 | Skin::makeVariablesScript( |
120 | 102 | array( |
121 | | - 'UploadWizardConfig' => $wgUploadWizardConfig |
| 103 | + 'UploadWizardConfig' => UploadWizardConfig::getConfig( $wgRequest->getVal( 'campaign' ) ) |
122 | 104 | ) + |
123 | 105 | // Site name is a true global not specific to Upload Wizard |
124 | 106 | array( |