r88521 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88520‎ | r88521 | r88522 >
Date:16:15, 21 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added very simple API module via which the info also displayed on special:semanticstatistics can also be obtained
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/api (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWInfo.php (added) (history)

Diff [purge]

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
1107 + Id
Added: svn:eol-style
2108 + native
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
@@ -34,7 +34,7 @@
3535 global $wgVersion, $wgFooterIcons, $wgExtensionFunctions, $wgAutoloadClasses, $wgSpecialPages;
3636 global $wgSpecialPageGroups, $wgHooks, $wgExtensionMessagesFiles;
3737 global $smwgIP, $smwgNamespace, $wgJobClasses, $wgExtensionAliasesFiles, $wgServer;
38 - global $wgResourceModules, $smwgScriptPath;
 38+ global $wgResourceModules, $smwgScriptPath, $wgAPIModules;
3939
4040 $wgFooterIcons['poweredby']['semanticmediawiki'] = array(
4141 'src' => null,
@@ -299,6 +299,9 @@
300300 //$wgAutoloadClasses['ApiSMWQuery'] = $smwgIP . 'includes/api/ApiSMWQuery.php';
301301 //$wgAPIModules['smwquery'] = 'ApiSMWQuery';
302302
 303+ $wgAutoloadClasses['ApiSMWInfo'] = $smwgIP . 'includes/api/ApiSMWInfo.php';
 304+ $wgAPIModules['smwinfo'] = 'ApiSMWInfo';
 305+
303306 return true;
304307 }
305308

Status & tagging log