Index: trunk/extensions/MetricsReporting/MetricsReporting.php |
— | — | @@ -0,0 +1,18 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 5 | + die(); |
| 6 | +} |
| 7 | + |
| 8 | +$wgExtensionCredits['other'][] = array( |
| 9 | + 'path' => __FILE__, |
| 10 | + 'name' => 'MetricsReporting', |
| 11 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:MetricsReporting', |
| 12 | + 'author' => 'Sam Reed', |
| 13 | + 'description' => 'Api for Wikimedia Metrics Reporting output', |
| 14 | +); |
| 15 | + |
| 16 | +$dir = dirname( __FILE__ ) . '/'; |
| 17 | + |
| 18 | +$wgAutoloadClasses['ApiAnalytics'] = $dir . 'ApiAnalytics.php'; |
| 19 | +$wgAPIModules['analytics'] = 'ApiAnalytics'; |
Property changes on: trunk/extensions/MetricsReporting/MetricsReporting.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 20 | + Id |
Added: svn:eol-style |
2 | 21 | + native |
Index: trunk/extensions/MetricsReporting/ApiAnalytics.php |
— | — | @@ -0,0 +1,96 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class ApiMetrics extends ApiBase { |
| 5 | + |
| 6 | + private $metricModuleNames; |
| 7 | + |
| 8 | + private $metricModules = array( |
| 9 | + ); |
| 10 | + |
| 11 | + public function __construct( $main, $action ) { |
| 12 | + parent::__construct( $main, $action ); |
| 13 | + $this->metricModuleNames = array_keys( $this->metricModules ); |
| 14 | + } |
| 15 | + |
| 16 | + public function execute() { |
| 17 | + } |
| 18 | + |
| 19 | + public function getAllowedParams() { |
| 20 | + return array( |
| 21 | + 'metric' => array( |
| 22 | + ApiBase::PARAM_ISMULTI => true, |
| 23 | + ApiBase::PARAM_TYPE => $this->metricModuleNames |
| 24 | + ), |
| 25 | + ); |
| 26 | + } |
| 27 | + |
| 28 | + public function getParamDescription() { |
| 29 | + return array( |
| 30 | + 'metric' => '', |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + public function getDescription() { |
| 35 | + return array( |
| 36 | + '' |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + /*public function getPossibleErrors() { |
| 41 | + return array_merge( parent::getPossibleErrors(), array( |
| 42 | + ) ); |
| 43 | + }*/ |
| 44 | + |
| 45 | + protected function getExamples() { |
| 46 | + return array( |
| 47 | + 'api.php?action=analytics&metric=', |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @return string |
| 53 | + */ |
| 54 | + public function makeHelpMsg() { |
| 55 | + $msg = ''; |
| 56 | + |
| 57 | + $querySeparator = str_repeat( '--- ', 12 ); |
| 58 | + $moduleSeparator = str_repeat( '*** ', 14 ); |
| 59 | + $msg .= "\n$querySeparator Analytics: Metric $querySeparator\n\n"; |
| 60 | + $msg .= $this->makeHelpMsgHelper( $this->metricModules, 'metric' ); |
| 61 | + $msg .= "\n\n$moduleSeparator Modules: continuation $moduleSeparator\n\n"; |
| 62 | + |
| 63 | + // Perform the base call last because the $this->mAllowedGenerators |
| 64 | + // will be updated inside makeHelpMsgHelper() |
| 65 | + // Use parent to make default message for the query module |
| 66 | + $msg = parent::makeHelpMsg() . $msg; |
| 67 | + |
| 68 | + return $msg; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * For all modules in $moduleList, generate help messages and join them together |
| 73 | + * @param $moduleList Array array(modulename => classname) |
| 74 | + * @param $paramName string Parameter name |
| 75 | + * @return string |
| 76 | + */ |
| 77 | + private function makeHelpMsgHelper( $moduleList, $paramName ) { |
| 78 | + $moduleDescriptions = array(); |
| 79 | + |
| 80 | + foreach ( $moduleList as $moduleName => $moduleClass ) { |
| 81 | + $module = new $moduleClass( $this, $moduleName, null ); |
| 82 | + |
| 83 | + $msg = ApiMain::makeHelpMsgHeader( $module, $paramName ); |
| 84 | + $msg2 = $module->makeHelpMsg(); |
| 85 | + if ( $msg2 !== false ) { |
| 86 | + $msg .= $msg2; |
| 87 | + } |
| 88 | + $moduleDescriptions[] = $msg; |
| 89 | + } |
| 90 | + |
| 91 | + return implode( "\n", $moduleDescriptions ); |
| 92 | + } |
| 93 | + |
| 94 | + public function getVersion() { |
| 95 | + return __CLASS__ . ': $Id: $'; |
| 96 | + } |
| 97 | +} |
Property changes on: trunk/extensions/MetricsReporting/ApiAnalytics.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 98 | + native |