Index: trunk/extensions/UploadWizard/includes/UploadWizardConfig.php |
— | — | @@ -14,6 +14,15 @@ |
15 | 15 | class UploadWizardConfig { |
16 | 16 | |
17 | 17 | /** |
| 18 | + * Holder for configuration specified via url arguments. |
| 19 | + * This will override other config when returned via getConfig. |
| 20 | + * |
| 21 | + * @since 1.2 |
| 22 | + * @var array |
| 23 | + */ |
| 24 | + protected static $urlConfig = array(); |
| 25 | + |
| 26 | + /** |
18 | 27 | * Returns the globally configuration, optionaly combined with campaign sepcific |
19 | 28 | * configuration. |
20 | 29 | * |
— | — | @@ -29,16 +38,45 @@ |
30 | 39 | |
31 | 40 | if ( !$mergedConfig ) { |
32 | 41 | $wgUploadWizardConfig = array_merge( self::getDefaultConfig(), $wgUploadWizardConfig ); |
| 42 | + $mergedConfig = true; |
33 | 43 | } |
34 | 44 | |
35 | 45 | if ( !is_null( $campaignName ) ) { |
36 | 46 | $wgUploadWizardConfig = array_merge( $wgUploadWizardConfig, self::getCampaignConfig( $campaignName ) ); |
37 | 47 | } |
38 | 48 | |
39 | | - return $wgUploadWizardConfig; |
| 49 | + return array_merge( $wgUploadWizardConfig, self::$urlConfig ); |
40 | 50 | } |
41 | 51 | |
42 | 52 | /** |
| 53 | + * Returns the value of a single configuration setting. |
| 54 | + * |
| 55 | + * @since 1.2 |
| 56 | + * |
| 57 | + * @param string $settingName |
| 58 | + * @param string|null $campaignName |
| 59 | + * |
| 60 | + * @return mixed |
| 61 | + */ |
| 62 | + public static function getSetting( $settingName, $campaignName = null ) { |
| 63 | + $config = self::getConfig(); |
| 64 | + return $config[$settingName]; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Sets a configuration setting provided by URL. |
| 69 | + * This will override other config when returned via getConfig. |
| 70 | + * |
| 71 | + * @param string $name |
| 72 | + * @param mixed $value |
| 73 | + * |
| 74 | + * @since 1.2 |
| 75 | + */ |
| 76 | + public static function setUrlSetting( $name, $value ) { |
| 77 | + self::$urlConfig[$name] = $value; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
43 | 81 | * Returns the default global config, from UploadWizard.config.php. |
44 | 82 | * |
45 | 83 | * @since 1.2 |
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php |
— | — | @@ -12,6 +12,14 @@ |
13 | 13 | class SpecialUploadWizard extends SpecialPage { |
14 | 14 | // the HTML form without javascript |
15 | 15 | private $simpleForm; |
| 16 | + |
| 17 | + /** |
| 18 | + * The name of the upload wizard campaign, or null when none is specified. |
| 19 | + * |
| 20 | + * @since 1.2 |
| 21 | + * @var string|null |
| 22 | + */ |
| 23 | + protected $campaign; |
16 | 24 | |
17 | 25 | // $request is the request (usually wgRequest) |
18 | 26 | // $par is everything in the URL after Special:UploadWizard. Not sure what we can use it for |
— | — | @@ -38,7 +46,7 @@ |
39 | 47 | */ |
40 | 48 | public function execute( $subPage ) { |
41 | 49 | global $wgRequest, $wgLang, $wgUser, $wgOut, $wgExtensionAssetsPath, |
42 | | - $wgUploadWizardDisableResourceLoader, $wgUploadWizardConfig; |
| 50 | + $wgUploadWizardDisableResourceLoader; |
43 | 51 | |
44 | 52 | // side effects: if we can't upload, will print error page to wgOut |
45 | 53 | // and return false |
— | — | @@ -49,9 +57,12 @@ |
50 | 58 | $this->setHeaders(); |
51 | 59 | $this->outputHeader(); |
52 | 60 | |
| 61 | + $this->campaign = $wgRequest->getVal( 'campaign' ); |
| 62 | + |
53 | 63 | // if query string includes 'skiptutorial=true' set config variable to true |
54 | | - if ( $wgRequest->getText( 'skiptutorial' ) ) { |
55 | | - $wgUploadWizardConfig['skipTutorial'] = true; |
| 64 | + if ( $wgRequest->getCheck( 'skiptutorial' ) ) { |
| 65 | + $skip = in_array( $wgRequest->getText( 'skiptutorial' ), array( '1', 'true' ) ); |
| 66 | + UploadWizardConfig::setUrlSetting( 'skipTutorial', $skip ); |
56 | 67 | } |
57 | 68 | |
58 | 69 | // fallback for non-JS |
— | — | @@ -70,7 +81,7 @@ |
71 | 82 | } else { |
72 | 83 | $basepath = "$wgExtensionAssetsPath/UploadWizard"; |
73 | 84 | $dependencyLoader = new UploadWizardDependencyLoader( $wgLang->getCode() ); |
74 | | - if ( $wgUploadWizardConfig['debug'] ) { |
| 85 | + if ( UploadWizardConfig::getSetting( 'debug', $this->campaign ) ) { |
75 | 86 | // each file as an individual script or style |
76 | 87 | $dependencyLoader->outputHtmlDebug( $wgOut, $basepath ); |
77 | 88 | } else { |
— | — | @@ -94,12 +105,12 @@ |
95 | 106 | * @param subpage, e.g. the "foo" in Special:UploadWizard/foo |
96 | 107 | */ |
97 | 108 | public function addJsVars( $subPage ) { |
98 | | - global $wgOut, $wgSitename, $wgRequest; |
99 | | - |
| 109 | + global $wgOut, $wgSitename; |
| 110 | + |
100 | 111 | $wgOut->addScript( |
101 | 112 | Skin::makeVariablesScript( |
102 | 113 | array( |
103 | | - 'UploadWizardConfig' => UploadWizardConfig::getConfig( $wgRequest->getVal( 'campaign' ) ) |
| 114 | + 'UploadWizardConfig' => UploadWizardConfig::getConfig( $this->campaign ) |
104 | 115 | ) + |
105 | 116 | // Site name is a true global not specific to Upload Wizard |
106 | 117 | array( |
— | — | @@ -172,19 +183,21 @@ |
173 | 184 | * @return {String} html |
174 | 185 | */ |
175 | 186 | function getWizardHtml() { |
176 | | - global $wgUploadWizardConfig, $wgExtensionAssetsPath; |
| 187 | + global $wgExtensionAssetsPath; |
| 188 | + |
| 189 | + $globalConf = UploadWizardConfig::getConfig( $this->campaign ); |
| 190 | + |
| 191 | + if ( array_key_exists( 'fallbackToAltUploadForm', $globalConf ) |
| 192 | + && array_key_exists( 'altUploadForm', $globalConf ) |
| 193 | + && $globalConf['altUploadForm'] != '' |
| 194 | + && $globalConf[ 'fallbackToAltUploadForm' ] ) { |
177 | 195 | |
178 | | - if ( array_key_exists( 'fallbackToAltUploadForm', $wgUploadWizardConfig ) |
179 | | - && array_key_exists( 'altUploadForm', $wgUploadWizardConfig ) |
180 | | - && $wgUploadWizardConfig['altUploadForm'] != '' |
181 | | - && $wgUploadWizardConfig[ 'fallbackToAltUploadForm' ] ) { |
182 | | - |
183 | 196 | $linkHtml = ''; |
184 | | - $altUploadForm = Title::newFromText( $wgUploadWizardConfig[ 'altUploadForm' ] ); |
| 197 | + $altUploadForm = Title::newFromText( $globalConf[ 'altUploadForm' ] ); |
185 | 198 | if ( $altUploadForm instanceof Title ) { |
186 | 199 | $linkHtml = Html::rawElement( 'p', array( 'style' => 'text-align: center;' ), |
187 | 200 | Html::rawElement( 'a', array( 'href' => $altUploadForm->getLocalURL() ), |
188 | | - $wgUploadWizardConfig['altUploadForm'] |
| 201 | + $globalConf['altUploadForm'] |
189 | 202 | ) |
190 | 203 | ); |
191 | 204 | } |
— | — | @@ -197,12 +210,13 @@ |
198 | 211 | |
199 | 212 | } |
200 | 213 | |
201 | | - $tutorialHtml = ''; |
| 214 | + $tutorialHtml = ''; |
202 | 215 | // only load the tutorial HTML if we aren't skipping the first step |
203 | 216 | // TODO should use user preference not a cookie ( so the user does not have to skip it for every browser ) |
204 | | - if ( !isset( $_COOKIE['skiptutorial'] ) && !$wgUploadWizardConfig['skipTutorial'] ) { |
| 217 | + if ( !isset( $_COOKIE['skiptutorial'] ) && !$globalConf['skipTutorial'] ) { |
205 | 218 | $tutorialHtml = UploadWizardTutorial::getHtml(); |
206 | 219 | } |
| 220 | + |
207 | 221 | // TODO move this into UploadWizard.js or some other javascript resource so the upload wizard |
208 | 222 | // can be dynamically included ( for example the add media wizard ) |
209 | 223 | return |