Jeroen De Dauw has submitted this change and it was merged.

Change subject: (Bug 46458) ApiSMWInfo add count information of individual 
query formats
......................................................................


(Bug 46458) ApiSMWInfo add count information of individual query formats

Add "formatcount" parameter to ApiSMWInfo which will ouput
an array of used formats together with the count information

## JSON example

{
    "info": {
        "formatcount": {
            "datatables": 44,
            "list": 27,
            "jqplotchart": 15,
            "eventcalendar": 15,
            "gallery": 15,
            "jqplotseries": 13,
            "count": 2,
            "sum": 2,
            "rdf": 1
        }
    }
}

Change-Id: Ifb34d9b17a0b34082ee62245ecf5f49dc0b2eec1
---
M includes/api/ApiSMWInfo.php
M includes/storage/SQLStore/SMW_SQLStore3_SpecialPageHandlers.php
M tests/phpunit/includes/api/ApiSMWInfoTest.php
3 files changed, 43 insertions(+), 2 deletions(-)

Approvals:
  Mwjames: Looks good to me, but someone else must approve
  Jeroen De Dauw: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/api/ApiSMWInfo.php b/includes/api/ApiSMWInfo.php
index dc92f42..d6a8481 100644
--- a/includes/api/ApiSMWInfo.php
+++ b/includes/api/ApiSMWInfo.php
@@ -34,6 +34,7 @@
                        || in_array( 'proppagecount', $requestedInfo )
                        || in_array( 'querycount', $requestedInfo )
                        || in_array( 'querysize', $requestedInfo )
+                       || in_array( 'formatcount', $requestedInfo )
                        || in_array( 'conceptcount', $requestedInfo )
                        || in_array( 'subobjectcount', $requestedInfo )
                        || in_array( 'declaredpropcount', $requestedInfo ) ) {
@@ -54,6 +55,14 @@
                        foreach ( $map as $apiName => $smwName ) {
                                if ( in_array( $apiName, $requestedInfo ) ) {
                                        $resultInfo[$apiName] = 
$semanticStats[$smwName];
+                               }
+                       }
+
+                       // Output follows ['formatcount'][formatName] = count
+                       if ( in_array( 'formatcount', $requestedInfo ) ) {
+                               $resultInfo['formatcount'] = array();
+                               foreach ( $semanticStats['QUERYFORMATS'] as 
$name => $count ) {
+                                       $resultInfo['formatcount'][$name] = 
$count;
                                }
                        }
                }
@@ -77,6 +86,7 @@
                                        'proppagecount',
                                        'querycount',
                                        'querysize',
+                                       'formatcount',
                                        'conceptcount',
                                        'subobjectcount'
                                )
diff --git a/includes/storage/SQLStore/SMW_SQLStore3_SpecialPageHandlers.php 
b/includes/storage/SQLStore/SMW_SQLStore3_SpecialPageHandlers.php
index 5b5b112..52b596e 100644
--- a/includes/storage/SQLStore/SMW_SQLStore3_SpecialPageHandlers.php
+++ b/includes/storage/SQLStore/SMW_SQLStore3_SpecialPageHandlers.php
@@ -224,6 +224,26 @@
                $result['QUERYSIZE'] = $row->count;
                $dbr->freeResult( $res );
 
+               // Count used formats
+               $result['QUERYFORMATS'] = array();
+               $typeProp = new SMWDIProperty( '_ASKFO' );
+               $typeTable = $propertyTables[SMWSQLStore3::findPropertyTableID( 
$typeProp )];
+               $res = $dbr->select(
+                       $typeTable->getName(),
+                       'o_hash, COUNT(s_id) AS count',
+                       array(),
+                       'SMW::getStatistics',
+                       array(
+                               'ORDER BY' => 'count DESC',
+                               'GROUP BY' => 'o_hash'
+                       )
+               );
+
+               foreach ( $res as $row ) {
+                       $result['QUERYFORMATS'][$row->o_hash] = 
(int)$row->count;
+               }
+               $dbr->freeResult( $res );
+
                // Count existing concepts
                $result['CONCEPTS'] = 0;
                $typeProp = new SMWDIProperty( '_CONC' );
diff --git a/tests/phpunit/includes/api/ApiSMWInfoTest.php 
b/tests/phpunit/includes/api/ApiSMWInfoTest.php
index c214f9b..24d3507 100644
--- a/tests/phpunit/includes/api/ApiSMWInfoTest.php
+++ b/tests/phpunit/includes/api/ApiSMWInfoTest.php
@@ -80,11 +80,22 @@
         * @since 1.9
         */
        public function testQueryParameters( $queryParameters ) {
-
                $data = $this->getAPIResults( $queryParameters );
 
                // Info array should return with either 0 or > 0
                $this->assertGreaterThanOrEqual( 0, 
$data['info'][$queryParameters] );
+       }
+
+       /**
+        * Test 'formatcount' query parameter
+        *
+        * @since 1.9
+        */
+       public function testFormatCountQueryParameter() {
+               $data = $this->getAPIResults( 'formatcount' );
+
+               // An array is expected as return value
+               $this->assertInternalType( 'array', 
$data['info']['formatcount'] );
        }
 
        /**
@@ -96,8 +107,8 @@
         * @since 1.9
         */
        public function testUnknownQueryParameter() {
-
                $data = $this->getAPIResults( 'Foo' );
+
                $this->assertInternalType( 'array', $data['warnings'] );
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/59990
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifb34d9b17a0b34082ee62245ecf5f49dc0b2eec1
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Mwjames <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to