http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88521

Revision: 88521
Author:   jeroendedauw
Date:     2011-05-21 16:15:12 +0000 (Sat, 21 May 2011)
Log Message:
-----------
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

Added Paths:
-----------
    trunk/extensions/SemanticMediaWiki/includes/api/
    trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWInfo.php

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php   2011-05-21 
15:03:06 UTC (rev 88520)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php   2011-05-21 
16:15:12 UTC (rev 88521)
@@ -34,7 +34,7 @@
        global $wgVersion, $wgFooterIcons, $wgExtensionFunctions, 
$wgAutoloadClasses, $wgSpecialPages;
        global $wgSpecialPageGroups, $wgHooks, $wgExtensionMessagesFiles;
        global $smwgIP, $smwgNamespace, $wgJobClasses, 
$wgExtensionAliasesFiles, $wgServer;
-       global $wgResourceModules, $smwgScriptPath;
+       global $wgResourceModules, $smwgScriptPath, $wgAPIModules;
        
        $wgFooterIcons['poweredby']['semanticmediawiki'] = array(
                'src' => null,
@@ -299,6 +299,9 @@
        //$wgAutoloadClasses['ApiSMWQuery']                     = $smwgIP . 
'includes/api/ApiSMWQuery.php';
        //$wgAPIModules['smwquery'] = 'ApiSMWQuery';
        
+       $wgAutoloadClasses['ApiSMWInfo']             = $smwgIP . 
'includes/api/ApiSMWInfo.php';
+       $wgAPIModules['smwinfo'] = 'ApiSMWInfo';
+       
        return true;
 }
 

Added: trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWInfo.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWInfo.php              
                (rev 0)
+++ trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWInfo.php      
2011-05-21 16:15:12 UTC (rev 88521)
@@ -0,0 +1,105 @@
+<?php
+
+/**
+ * API module to obtain info about the SMW install,
+ * primerily targeted at usage by the SMW registry.
+ *
+ * @since 1.6
+ *
+ * @file ApiSMWInfo.php
+ * @ingroup SMW
+ * @ingroup API
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class ApiSMWInfo extends ApiBase {
+       
+       public function __construct( $main, $action ) {
+               parent::__construct( $main, $action );
+       }
+       
+       public function execute() {
+               $params = $this->extractRequestParams();
+               $requestedInfo = $params['info'];
+               $resultInfo = array();
+               
+               if ( in_array( 'proppagecount', $requestedInfo ) ) {
+                       $resultInfo['proppagecount'] = wfGetDB( DB_SLAVE 
)->estimateRowCount(
+                               'page',
+                               '*',
+                               array(
+                                       'page_namespace' => SMW_NS_PROPERTY
+                               )
+                       );      
+               }
+               
+               if ( in_array( 'propcount', $requestedInfo )
+                       || in_array( 'usedpropcount', $requestedInfo ) 
+                       || in_array( 'declaredpropcount', $requestedInfo ) ) {
+
+                       $semanticStats = smwfGetStore()->getStatistics();
+                       
+                       $map = array(
+                               'propcount' => 'PROPUSES',
+                               'usedpropcount' => 'USEDPROPS',
+                               'declaredpropcount' => 'DECLPROPS',
+                       );
+                       
+                       foreach ( $map as $apiName => $smwName ) {
+                               if ( in_array( $apiName, $requestedInfo ) ) {
+                                       $resultInfo[$apiName] = 
$semanticStats[$smwName];
+                               }
+                       }
+               }
+               
+               $this->getResult()->addValue(
+                       null,
+                       'info',
+                       $resultInfo
+               );
+       }
+
+       public function getAllowedParams() {
+               return array(
+                       'info' => array(
+                               ApiBase::PARAM_DFLT => 
'propcount|usedpropcount|declaredpropcount',
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_TYPE => array(
+                                       'propcount',
+                                       'usedpropcount',
+                                       'declaredpropcount',
+                                       'proppagecount',
+                               )
+                       ),
+               );
+       }
+       
+       public function getParamDescription() {
+               return array(
+                       'info' => 'The info to provide.'
+               );
+       }
+       
+       public function getDescription() {
+               return array(
+                       'API module get info about this SMW install.'
+               );
+       }
+       
+       public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array(
+               ) );
+       }
+
+       protected function getExamples() {
+               return array(
+                       'api.php?action=smwinfo&info=proppagecount|propcount',
+               );
+       }       
+       
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }               
+       
+}


Property changes on: 
trunk/extensions/SemanticMediaWiki/includes/api/ApiSMWInfo.php
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to