r91096 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91095‎ | r91096 | r91097 >
Date:18:48, 29 June 2011
Author:reedy
Status:deferred
Tags:
Comment:
Add ApiAnalyticsBase class (may/probably will be switched to being an ApiQueryBase abstract subclass)

Add some more display text stuffs
Modified paths:
  • /trunk/extensions/MetricsReporting/ApiAnalytics.php (modified) (history)
  • /trunk/extensions/MetricsReporting/ApiAnalyticsBase.php (added) (history)
  • /trunk/extensions/MetricsReporting/MetricsReporting.php (modified) (history)

Diff [purge]

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
140 + native
Added: svn:keywords
241 + Id
Index: trunk/extensions/MetricsReporting/MetricsReporting.php
@@ -12,7 +12,16 @@
1313 'description' => 'Api for Wikimedia Metrics Reporting output',
1414 );
1515
 16+$wgMetricsDBserver = '';
 17+//$wgMetricsDBport = 5432;
 18+$wgMetricsDBname = '';
 19+$wgMetricsDBuser = '';
 20+$wgMetricsDBpassword = '';
 21+//$wgMetricsDBtype = 'mysql';
 22+
1623 $dir = dirname( __FILE__ ) . '/';
1724
1825 $wgAutoloadClasses['ApiAnalytics'] = $dir . 'ApiAnalytics.php';
1926 $wgAPIModules['analytics'] = 'ApiAnalytics';
 27+
 28+$wgAutoloadClasses['ApiAnalyticsBase'] = $dir . 'ApiAnalyticsBase.php';
Index: trunk/extensions/MetricsReporting/ApiAnalytics.php
@@ -2,7 +2,7 @@
33
44 class ApiAnalytics extends ApiBase {
55
6 - private $metricModuleNames;
 6+ private $metricModuleNames, $params;
77
88 private $metricModules = array(
99 );
@@ -13,12 +13,38 @@
1414 }
1515
1616 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+ }
1729 }
1830
 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+
1945 public function getAllowedParams() {
2046 return array(
2147 'metric' => array(
22 - ApiBase::PARAM_ISMULTI => true,
 48+ ApiBase::PARAM_ISMULTI => false,
2349 ApiBase::PARAM_TYPE => $this->metricModuleNames
2450 ),
2551 );
@@ -26,13 +52,16 @@
2753
2854 public function getParamDescription() {
2955 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+ ),
3160 );
3261 }
3362
3463 public function getDescription() {
3564 return array(
36 - ''
 65+ 'Collect data from the analytics database'
3766 );
3867 }
3968

Status & tagging log