Index: trunk/extensions/MetricsReporting/ApiAnalyticsBase.php |
— | — | @@ -0,0 +1,38 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class ApiAnalyticsBase extends ApiBase/*ApiQueryBase*/ { |
| 5 | + |
| 6 | + protected $mDb; |
| 7 | + |
| 8 | + public function __construct( ApiBase $query, $moduleName, $paramPrefix = '' ) { |
| 9 | + parent::__construct( $query->getMain(), $moduleName, $paramPrefix ); |
| 10 | + } |
| 11 | + |
| 12 | + /** |
| 13 | + * Get the Query database connection (read-only) |
| 14 | + * @return DatabaseBase |
| 15 | + */ |
| 16 | + protected function getDB() { |
| 17 | + if ( is_null( $this->mDb ) ) { |
| 18 | + global $wgMetricsDBserver, $wgMetricsDBname, $wgMetricsDBuser, $wgMetricsDBpassword, $wgMetricsDBtype; |
| 19 | + $this->mDb = DatabaseBase::factory( $wgMetricsDBtype, |
| 20 | + array( |
| 21 | + 'host' => $wgMetricsDBserver, |
| 22 | + 'user' => $wgMetricsDBuser, |
| 23 | + 'password' => $wgMetricsDBpassword, |
| 24 | + 'dbname' => $wgMetricsDBname, |
| 25 | + ) |
| 26 | + ); |
| 27 | + } |
| 28 | + return $this->mDb; |
| 29 | + } |
| 30 | + |
| 31 | + /*public function getPossibleErrors() { |
| 32 | + return array_merge( parent::getPossibleErrors(), array( |
| 33 | + ) ); |
| 34 | + }*/ |
| 35 | + |
| 36 | + public function getVersion() { |
| 37 | + return __CLASS__ . ': $Id$'; |
| 38 | + } |
| 39 | +} |
Property changes on: trunk/extensions/MetricsReporting/ApiAnalyticsBase.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 40 | + native |
Added: svn:keywords |
2 | 41 | + Id |
Index: trunk/extensions/MetricsReporting/MetricsReporting.php |
— | — | @@ -12,7 +12,16 @@ |
13 | 13 | 'description' => 'Api for Wikimedia Metrics Reporting output', |
14 | 14 | ); |
15 | 15 | |
| 16 | +$wgMetricsDBserver = ''; |
| 17 | +//$wgMetricsDBport = 5432; |
| 18 | +$wgMetricsDBname = ''; |
| 19 | +$wgMetricsDBuser = ''; |
| 20 | +$wgMetricsDBpassword = ''; |
| 21 | +//$wgMetricsDBtype = 'mysql'; |
| 22 | + |
16 | 23 | $dir = dirname( __FILE__ ) . '/'; |
17 | 24 | |
18 | 25 | $wgAutoloadClasses['ApiAnalytics'] = $dir . 'ApiAnalytics.php'; |
19 | 26 | $wgAPIModules['analytics'] = 'ApiAnalytics'; |
| 27 | + |
| 28 | +$wgAutoloadClasses['ApiAnalyticsBase'] = $dir . 'ApiAnalyticsBase.php'; |
Index: trunk/extensions/MetricsReporting/ApiAnalytics.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | |
4 | 4 | class ApiAnalytics extends ApiBase { |
5 | 5 | |
6 | | - private $metricModuleNames; |
| 6 | + private $metricModuleNames, $params; |
7 | 7 | |
8 | 8 | private $metricModules = array( |
9 | 9 | ); |
— | — | @@ -13,12 +13,38 @@ |
14 | 14 | } |
15 | 15 | |
16 | 16 | public function execute() { |
| 17 | + $this->params = $this->extractRequestParams(); |
| 18 | + |
| 19 | + // Instantiate requested modules |
| 20 | + $modules = array(); |
| 21 | + $this->instantiateModules( $modules, 'prop', $this->mQueryPropModules ); |
| 22 | + |
| 23 | + // Execute all requested modules. |
| 24 | + foreach ( $modules as $module ) { |
| 25 | + $module->profileIn(); |
| 26 | + $module->execute(); |
| 27 | + $module->profileOut(); |
| 28 | + } |
17 | 29 | } |
18 | 30 | |
| 31 | + /** |
| 32 | + * Create instances of all modules requested by the client |
| 33 | + * @param $modules Array to append instantiated modules to |
| 34 | + * @param $param string Parameter name to read modules from |
| 35 | + * @param $moduleList Array array(modulename => classname) |
| 36 | + */ |
| 37 | + protected function instantiateModules( &$modules, $param, $moduleList ) { |
| 38 | + if ( isset( $this->params[$param] ) ) { |
| 39 | + foreach ( $this->params[$param] as $moduleName ) { |
| 40 | + $modules[] = new $moduleList[$moduleName] ( $this, $moduleName ); |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + |
19 | 45 | public function getAllowedParams() { |
20 | 46 | return array( |
21 | 47 | 'metric' => array( |
22 | | - ApiBase::PARAM_ISMULTI => true, |
| 48 | + ApiBase::PARAM_ISMULTI => false, |
23 | 49 | ApiBase::PARAM_TYPE => $this->metricModuleNames |
24 | 50 | ), |
25 | 51 | ); |
— | — | @@ -26,13 +52,16 @@ |
27 | 53 | |
28 | 54 | public function getParamDescription() { |
29 | 55 | return array( |
30 | | - 'metric' => '', |
| 56 | + 'metric' => array( |
| 57 | + 'Type of data to collect', |
| 58 | + 'About metric names: these include source of data, to allow for alternate sources of similar metrics, which likely are defined differently or have other intrinsic issues (e.g. precision/reliability).' |
| 59 | + ), |
31 | 60 | ); |
32 | 61 | } |
33 | 62 | |
34 | 63 | public function getDescription() { |
35 | 64 | return array( |
36 | | - '' |
| 65 | + 'Collect data from the analytics database' |
37 | 66 | ); |
38 | 67 | } |
39 | 68 | |