r70862 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70861‎ | r70862 | r70863 >
Date:09:07, 11 August 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added class for the handling of release data
Modified paths:
  • /trunk/extensions/Distribution/Distribution.php (modified) (history)
  • /trunk/extensions/Distribution/api/ApiQueryExtensions.php (modified) (history)
  • /trunk/extensions/Distribution/includes (added) (history)
  • /trunk/extensions/Distribution/includes/DistributionRelease.php (added) (history)
  • /trunk/extensions/Distribution/maintenance/getSvnMetadata.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Distribution/maintenance/getSvnMetadata.php
@@ -176,7 +176,7 @@
177177
178178 // Map the version values to the db schema.
179179 $versionValues = array(
180 - 'version_status' => 0, // TODO
 180+ 'version_status' => DistributionRelease::mapState( DistributionRelease::getDefaultState() ), // TODO
181181 'version_desc' => $metaData['description'],
182182 'version_authors' => $metaData['authors'],
183183 'version_url' => $metaData['url'],
Index: trunk/extensions/Distribution/Distribution.php
@@ -22,6 +22,9 @@
2323 // Register the internationalization file.
2424 $wgExtensionMessagesFiles['Distribution'] = dirname( __FILE__ ) . '/Distribution.i18n.php';
2525
 26+// Load classes.
 27+$wgAutoloadClasses['DistributionRelease'] = dirname( __FILE__ ) . '/includes/DistributionRelease.php';
 28+
2629 // Hook registration.
2730 $wgHooks['LoadExtensionSchemaUpdates'][] = 'efDistributionSchemaUpdate';
2831
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
165 + native
Index: trunk/extensions/Distribution/api/ApiQueryExtensions.php
@@ -144,8 +144,8 @@
145145 ),
146146 'state' => array(
147147 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(),
150150 ),
151151 );
152152 }

Status & tagging log