Index: trunk/extensions/Distribution/maintenance/getSvnMetadata.php |
— | — | @@ -176,7 +176,7 @@ |
177 | 177 | |
178 | 178 | // Map the version values to the db schema. |
179 | 179 | $versionValues = array( |
180 | | - 'version_status' => 0, // TODO |
| 180 | + 'version_status' => DistributionRelease::mapState( DistributionRelease::getDefaultState() ), // TODO |
181 | 181 | 'version_desc' => $metaData['description'], |
182 | 182 | 'version_authors' => $metaData['authors'], |
183 | 183 | 'version_url' => $metaData['url'], |
Index: trunk/extensions/Distribution/Distribution.php |
— | — | @@ -22,6 +22,9 @@ |
23 | 23 | // Register the internationalization file. |
24 | 24 | $wgExtensionMessagesFiles['Distribution'] = dirname( __FILE__ ) . '/Distribution.i18n.php'; |
25 | 25 | |
| 26 | +// Load classes. |
| 27 | +$wgAutoloadClasses['DistributionRelease'] = dirname( __FILE__ ) . '/includes/DistributionRelease.php'; |
| 28 | + |
26 | 29 | // Hook registration. |
27 | 30 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'efDistributionSchemaUpdate'; |
28 | 31 | |
Index: trunk/extensions/Distribution/includes/DistributionRelease.php |
— | — | @@ -0,0 +1,63 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Static class for handling release data. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @author Jeroen De Dauw |
| 10 | + */ |
| 11 | +class DistributionRelease { |
| 12 | + |
| 13 | + /** |
| 14 | + * Mapping between the state names and internal representation. |
| 15 | + * |
| 16 | + * @since 0.1 |
| 17 | + * |
| 18 | + * @var array |
| 19 | + */ |
| 20 | + private static $states = array( |
| 21 | + 'dev' => 0, |
| 22 | + 'alpha' => 1, |
| 23 | + 'beta' => 2, |
| 24 | + 'rc' => 3, |
| 25 | + 'stable' => 4, |
| 26 | + 'deprecated' => 5 |
| 27 | + ); |
| 28 | + |
| 29 | + /** |
| 30 | + * Returns a list of supported states. |
| 31 | + * |
| 32 | + * @since 0.1 |
| 33 | + * |
| 34 | + * @return array |
| 35 | + */ |
| 36 | + public static function getStates() { |
| 37 | + return array_keys( self::$states ); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Returns the name of the default state. |
| 42 | + */ |
| 43 | + public static function getDefaultState() { |
| 44 | + return 'stable'; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Returns the internal state representation of the provided state name. |
| 49 | + * |
| 50 | + * @since 0.1 |
| 51 | + * |
| 52 | + * @param $stateName Integer |
| 53 | + */ |
| 54 | + public static function mapState( $stateName ) { |
| 55 | + if ( !array_key_exists( $stateName, self::$states ) ) { |
| 56 | + $oldName = $stateName; |
| 57 | + $stateName = self::getDefaultState(); |
| 58 | + wfWarn( "State '$oldName' was not recognized, defaulted to '$stateName'" ); |
| 59 | + } |
| 60 | + |
| 61 | + return self::$states[$stateName]; |
| 62 | + } |
| 63 | + |
| 64 | +} |
Property changes on: trunk/extensions/Distribution/includes/DistributionRelease.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 65 | + native |
Index: trunk/extensions/Distribution/api/ApiQueryExtensions.php |
— | — | @@ -144,8 +144,8 @@ |
145 | 145 | ), |
146 | 146 | 'state' => array( |
147 | 147 | ApiBase::PARAM_ISMULTI => true, |
148 | | - ApiBase::PARAM_TYPE => array( 'dev', 'alpha', 'beta', 'rc', 'stable', 'deprecated' ), |
149 | | - ApiBase::PARAM_DFLT => 'stable', |
| 148 | + ApiBase::PARAM_TYPE => DistributionRelease::getStates(), |
| 149 | + ApiBase::PARAM_DFLT => DistributionRelease::getDefaultState(), |
150 | 150 | ), |
151 | 151 | ); |
152 | 152 | } |