r92970 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92969‎ | r92970 | r92971 >
Date:22:38, 23 July 2011
Author:jeroendedauw
Status:ok
Tags:
Comment:
work on campaign config handling
Modified paths:
  • /trunk/extensions/UploadWizard/SpecialUploadWizard.php (modified) (history)
  • /trunk/extensions/UploadWizard/UploadWizard.php (modified) (history)
  • /trunk/extensions/UploadWizard/UploadWizardCampaign.php (modified) (history)
  • /trunk/extensions/UploadWizard/UploadWizardConfig.php (added) (history)

Diff [purge]

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
153 + native
Index: trunk/extensions/UploadWizard/UploadWizard.php
@@ -37,6 +37,7 @@
3838
3939 # Require modules, including the special page
4040 foreach ( array(
 41+ 'UploadWizardConfig',
4142 'SpecialUploadWizard',
4243 'SpecialUploadCampaigns',
4344 'SpecialUploadCampaign',
Index: trunk/extensions/UploadWizard/UploadWizardCampaign.php
@@ -142,6 +142,49 @@
143143 }
144144
145145 /**
 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+ /**
146189 * Returns the id of the campaign.
147190 *
148191 * @since 1.2
@@ -230,19 +273,6 @@
231274 }
232275
233276 /**
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 - /**
247277 * Returns the value of the specified config property.
248278 *
249279 * @since 1.2
Index: trunk/extensions/UploadWizard/SpecialUploadWizard.php
@@ -82,7 +82,6 @@
8383 // where the uploadwizard will go
8484 // TODO import more from UploadWizard's createInterface call.
8585 $wgOut->addHTML( self::getWizardHtml() );
86 -
8786 }
8887
8988 /**
@@ -95,29 +94,12 @@
9695 * @param subpage, e.g. the "foo" in Special:UploadWizard/foo
9796 */
9897 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;
11799
118100 $wgOut->addScript(
119101 Skin::makeVariablesScript(
120102 array(
121 - 'UploadWizardConfig' => $wgUploadWizardConfig
 103+ 'UploadWizardConfig' => UploadWizardConfig::getConfig( $wgRequest->getVal( 'campaign' ) )
122104 ) +
123105 // Site name is a true global not specific to Upload Wizard
124106 array(

Follow-up revisions

RevisionCommit summaryAuthorDate
r92971fu r92970 - added docs, fixed var name typo and added check to only hold into...jeroendedauw22:45, 23 July 2011
r93011fu r92969 r92970 - work on campaign configjeroendedauw20:11, 24 July 2011

Status & tagging log