Index: trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWInfo.php |
— | — | @@ -0,0 +1,105 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to obtain info about the SMW install, |
| 6 | + * primerily targeted at usage by the SMW registry. |
| 7 | + * |
| 8 | + * @since 1.6 |
| 9 | + * |
| 10 | + * @file ApiSMWInfo.php |
| 11 | + * @ingroup SMW |
| 12 | + * @ingroup API |
| 13 | + * |
| 14 | + * @licence GNU GPL v3+ |
| 15 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 16 | + */ |
| 17 | +class ApiSMWInfo extends ApiBase { |
| 18 | + |
| 19 | + public function __construct( $main, $action ) { |
| 20 | + parent::__construct( $main, $action ); |
| 21 | + } |
| 22 | + |
| 23 | + public function execute() { |
| 24 | + $params = $this->extractRequestParams(); |
| 25 | + $requestedInfo = $params['info']; |
| 26 | + $resultInfo = array(); |
| 27 | + |
| 28 | + if ( in_array( 'proppagecount', $requestedInfo ) ) { |
| 29 | + $resultInfo['proppagecount'] = wfGetDB( DB_SLAVE )->estimateRowCount( |
| 30 | + 'page', |
| 31 | + '*', |
| 32 | + array( |
| 33 | + 'page_namespace' => SMW_NS_PROPERTY |
| 34 | + ) |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | + if ( in_array( 'propcount', $requestedInfo ) |
| 39 | + || in_array( 'usedpropcount', $requestedInfo ) |
| 40 | + || in_array( 'declaredpropcount', $requestedInfo ) ) { |
| 41 | + |
| 42 | + $semanticStats = smwfGetStore()->getStatistics(); |
| 43 | + |
| 44 | + $map = array( |
| 45 | + 'propcount' => 'PROPUSES', |
| 46 | + 'usedpropcount' => 'USEDPROPS', |
| 47 | + 'declaredpropcount' => 'DECLPROPS', |
| 48 | + ); |
| 49 | + |
| 50 | + foreach ( $map as $apiName => $smwName ) { |
| 51 | + if ( in_array( $apiName, $requestedInfo ) ) { |
| 52 | + $resultInfo[$apiName] = $semanticStats[$smwName]; |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + $this->getResult()->addValue( |
| 58 | + null, |
| 59 | + 'info', |
| 60 | + $resultInfo |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + public function getAllowedParams() { |
| 65 | + return array( |
| 66 | + 'info' => array( |
| 67 | + ApiBase::PARAM_DFLT => 'propcount|usedpropcount|declaredpropcount', |
| 68 | + ApiBase::PARAM_ISMULTI => true, |
| 69 | + ApiBase::PARAM_TYPE => array( |
| 70 | + 'propcount', |
| 71 | + 'usedpropcount', |
| 72 | + 'declaredpropcount', |
| 73 | + 'proppagecount', |
| 74 | + ) |
| 75 | + ), |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + public function getParamDescription() { |
| 80 | + return array( |
| 81 | + 'info' => 'The info to provide.' |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + public function getDescription() { |
| 86 | + return array( |
| 87 | + 'API module get info about this SMW install.' |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + public function getPossibleErrors() { |
| 92 | + return array_merge( parent::getPossibleErrors(), array( |
| 93 | + ) ); |
| 94 | + } |
| 95 | + |
| 96 | + protected function getExamples() { |
| 97 | + return array( |
| 98 | + 'api.php?action=smwinfo&info=proppagecount|propcount', |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + public function getVersion() { |
| 103 | + return __CLASS__ . ': $Id$'; |
| 104 | + } |
| 105 | + |
| 106 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWInfo.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 107 | + Id |
Added: svn:eol-style |
2 | 108 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | global $wgVersion, $wgFooterIcons, $wgExtensionFunctions, $wgAutoloadClasses, $wgSpecialPages; |
36 | 36 | global $wgSpecialPageGroups, $wgHooks, $wgExtensionMessagesFiles; |
37 | 37 | global $smwgIP, $smwgNamespace, $wgJobClasses, $wgExtensionAliasesFiles, $wgServer; |
38 | | - global $wgResourceModules, $smwgScriptPath; |
| 38 | + global $wgResourceModules, $smwgScriptPath, $wgAPIModules; |
39 | 39 | |
40 | 40 | $wgFooterIcons['poweredby']['semanticmediawiki'] = array( |
41 | 41 | 'src' => null, |
— | — | @@ -299,6 +299,9 @@ |
300 | 300 | //$wgAutoloadClasses['ApiSMWQuery'] = $smwgIP . 'includes/api/ApiSMWQuery.php'; |
301 | 301 | //$wgAPIModules['smwquery'] = 'ApiSMWQuery'; |
302 | 302 | |
| 303 | + $wgAutoloadClasses['ApiSMWInfo'] = $smwgIP . 'includes/api/ApiSMWInfo.php'; |
| 304 | + $wgAPIModules['smwinfo'] = 'ApiSMWInfo'; |
| 305 | + |
303 | 306 | return true; |
304 | 307 | } |
305 | 308 | |