r93011 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93010‎ | r93011 | r93012 >
Date:20:11, 24 July 2011
Author:jeroendedauw
Status:ok (Comments)
Tags:lamecommitsummary 
Comment:
fu r92969 r92970 - work on campaign config
Modified paths:
  • /trunk/extensions/UploadWizard/includes/UploadWizardConfig.php (modified) (history)
  • /trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/includes/UploadWizardConfig.php
@@ -14,6 +14,15 @@
1515 class UploadWizardConfig {
1616
1717 /**
 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+ /**
1827 * Returns the globally configuration, optionaly combined with campaign sepcific
1928 * configuration.
2029 *
@@ -29,16 +38,45 @@
3039
3140 if ( !$mergedConfig ) {
3241 $wgUploadWizardConfig = array_merge( self::getDefaultConfig(), $wgUploadWizardConfig );
 42+ $mergedConfig = true;
3343 }
3444
3545 if ( !is_null( $campaignName ) ) {
3646 $wgUploadWizardConfig = array_merge( $wgUploadWizardConfig, self::getCampaignConfig( $campaignName ) );
3747 }
3848
39 - return $wgUploadWizardConfig;
 49+ return array_merge( $wgUploadWizardConfig, self::$urlConfig );
4050 }
4151
4252 /**
 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+ /**
4381 * Returns the default global config, from UploadWizard.config.php.
4482 *
4583 * @since 1.2
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php
@@ -12,6 +12,14 @@
1313 class SpecialUploadWizard extends SpecialPage {
1414 // the HTML form without javascript
1515 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;
1624
1725 // $request is the request (usually wgRequest)
1826 // $par is everything in the URL after Special:UploadWizard. Not sure what we can use it for
@@ -38,7 +46,7 @@
3947 */
4048 public function execute( $subPage ) {
4149 global $wgRequest, $wgLang, $wgUser, $wgOut, $wgExtensionAssetsPath,
42 - $wgUploadWizardDisableResourceLoader, $wgUploadWizardConfig;
 50+ $wgUploadWizardDisableResourceLoader;
4351
4452 // side effects: if we can't upload, will print error page to wgOut
4553 // and return false
@@ -49,9 +57,12 @@
5058 $this->setHeaders();
5159 $this->outputHeader();
5260
 61+ $this->campaign = $wgRequest->getVal( 'campaign' );
 62+
5363 // 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 );
5667 }
5768
5869 // fallback for non-JS
@@ -70,7 +81,7 @@
7182 } else {
7283 $basepath = "$wgExtensionAssetsPath/UploadWizard";
7384 $dependencyLoader = new UploadWizardDependencyLoader( $wgLang->getCode() );
74 - if ( $wgUploadWizardConfig['debug'] ) {
 85+ if ( UploadWizardConfig::getSetting( 'debug', $this->campaign ) ) {
7586 // each file as an individual script or style
7687 $dependencyLoader->outputHtmlDebug( $wgOut, $basepath );
7788 } else {
@@ -94,12 +105,12 @@
95106 * @param subpage, e.g. the "foo" in Special:UploadWizard/foo
96107 */
97108 public function addJsVars( $subPage ) {
98 - global $wgOut, $wgSitename, $wgRequest;
99 -
 109+ global $wgOut, $wgSitename;
 110+
100111 $wgOut->addScript(
101112 Skin::makeVariablesScript(
102113 array(
103 - 'UploadWizardConfig' => UploadWizardConfig::getConfig( $wgRequest->getVal( 'campaign' ) )
 114+ 'UploadWizardConfig' => UploadWizardConfig::getConfig( $this->campaign )
104115 ) +
105116 // Site name is a true global not specific to Upload Wizard
106117 array(
@@ -172,19 +183,21 @@
173184 * @return {String} html
174185 */
175186 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' ] ) {
177195
178 - if ( array_key_exists( 'fallbackToAltUploadForm', $wgUploadWizardConfig )
179 - && array_key_exists( 'altUploadForm', $wgUploadWizardConfig )
180 - && $wgUploadWizardConfig['altUploadForm'] != ''
181 - && $wgUploadWizardConfig[ 'fallbackToAltUploadForm' ] ) {
182 -
183196 $linkHtml = '';
184 - $altUploadForm = Title::newFromText( $wgUploadWizardConfig[ 'altUploadForm' ] );
 197+ $altUploadForm = Title::newFromText( $globalConf[ 'altUploadForm' ] );
185198 if ( $altUploadForm instanceof Title ) {
186199 $linkHtml = Html::rawElement( 'p', array( 'style' => 'text-align: center;' ),
187200 Html::rawElement( 'a', array( 'href' => $altUploadForm->getLocalURL() ),
188 - $wgUploadWizardConfig['altUploadForm']
 201+ $globalConf['altUploadForm']
189202 )
190203 );
191204 }
@@ -197,12 +210,13 @@
198211
199212 }
200213
201 - $tutorialHtml = '';
 214+ $tutorialHtml = '';
202215 // only load the tutorial HTML if we aren't skipping the first step
203216 // 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'] ) {
205218 $tutorialHtml = UploadWizardTutorial::getHtml();
206219 }
 220+
207221 // TODO move this into UploadWizard.js or some other javascript resource so the upload wizard
208222 // can be dynamically included ( for example the add media wizard )
209223 return

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92969merge the campaign uptions in with the other configjeroendedauw22:11, 23 July 2011
r92970work on campaign config handlingjeroendedauw22:38, 23 July 2011

Comments

#Comment by NeilK (talk | contribs)   13:07, 22 August 2011

nice that we are relying a little bit less on globals as a side effect here.

Status & tagging log