Expose installed libraries in action=query&meta=siteinfo
authorKunal Mehta <legoktm@gmail.com>
Thu, 12 Feb 2015 21:09:23 +0000 (13:09 -0800)
committerBryanDavis <bdavis@wikimedia.org>
Thu, 12 Feb 2015 23:25:19 +0000 (23:25 +0000)
Bug: T89385
Change-Id: I4256f4d9858c09c042f649b7e701189acf85aedd

RELEASE-NOTES-1.25
includes/api/ApiQuerySiteinfo.php
includes/api/i18n/en.json

index 3f24db0..eb9fe38 100644 (file)
@@ -86,7 +86,9 @@ production.
 * External libraries installed via composer will now be displayed
   on Special:Version in their own section. Extensions or skins that are
   installed via composer will not be shown in this section as it is assumed
-  they will add the proper credits to the skins or extensions section.
+  they will add the proper credits to the skins or extensions section. They
+  can also be accessed through the API via the new siprop=libraries to
+  ApiQuerySiteInfo.
 * Update QUnit from v1.14.0 to v1.16.0.
 * Update Moment.js from v2.8.3 to v2.8.4.
 * Special:Tags now allows for manipulating the list of user-modifiable change
@@ -208,6 +210,7 @@ production.
   log entry is not implemented yet.
 * list=tags has additional properties to indicate 'active' status and tag
   sources.
+* siprop=libraries was added to ApiQuerySiteInfo to list installed external libraries.
 
 === Action API internal changes in 1.25 ===
 * ApiHelp has been rewritten to support i18n and paginated HTML output.
index 4e5c42b..5ac1036 100644 (file)
@@ -69,6 +69,9 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                case 'usergroups':
                                        $fit = $this->appendUserGroups( $p, $params['numberingroup'] );
                                        break;
+                               case 'libraries':
+                                       $fit = $this->appendInstalledLibraries( $p );
+                                       break;
                                case 'extensions':
                                        $fit = $this->appendExtensions( $p );
                                        break;
@@ -554,6 +557,36 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                return $this->getResult()->addValue( 'query', $property, $data );
        }
 
+       protected function appendInstalledLibraries( $property ) {
+               global $IP;
+               $path = "$IP/composer.lock";
+               if ( !file_exists( $path ) ) {
+                       // Maybe they're using mediawiki/vendor?
+                       $path = "$IP/vendor/composer.lock";
+                       if ( !file_exists( $path ) ) {
+                               return true;
+                       }
+               }
+
+               $data = array();
+               $lock = new ComposerLock( $path );
+               foreach ( $lock->getInstalledDependencies() as $name => $info ) {
+                       if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
+                               // Skip any extensions or skins since they'll be listed
+                               // in their proper section
+                               continue;
+                       }
+                       $data[] = array(
+                               'name' => $name,
+                               'version' => $info['version'],
+                       );
+               }
+               $this->getResult()->setIndexedTagName( $data, 'library' );
+
+               return $this->getResult()->addValue( 'query', $property, $data );
+
+       }
+
        protected function appendExtensions( $property ) {
                $data = array();
                foreach ( $this->getConfig()->get( 'ExtensionCredits' ) as $type => $extensions ) {
@@ -810,6 +843,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        'dbrepllag',
                                        'statistics',
                                        'usergroups',
+                                       'libraries',
                                        'extensions',
                                        'fileextensions',
                                        'rightsinfo',
index 0e766bf..6779571 100644 (file)
        "apihelp-query+search-example-generator": "Ger page info about the pages returned for a search for <kbd>meaning</kbd>.",
 
        "apihelp-query+siteinfo-description": "Return general information about the site.",
-       "apihelp-query+siteinfo-param-prop": "Which information to get:\n;general:Overall system information.\n;namespaces:List of registered namespaces and their canonical names.\n;namespacealiases:List of registered namespace aliases.\n;specialpagealiases:List of special page aliases.\n;magicwords:List of magic words and their aliases.\n;statistics:Returns site statistics.\n;interwikimap:Returns interwiki map (optionally filtered, optionally localised by using <var>$1inlanguagecode</var>).\n;dbrepllag:Returns database server with the highest replication lag.\n;usergroups:Returns user groups and the associated permissions.\n;extensions:Returns extensions installed on the wiki.\n;fileextensions:Returns list of file extensions allowed to be uploaded.\n;rightsinfo:Returns wiki rights (license) information if available.\n;restrictions:Returns information on available restriction (protection) types.\n;languages:Returns a list of languages MediaWiki supports (optionally localised by using <var>$1inlanguagecode</var>).\n;skins:Returns a list of all enabled skins (optionally localised by using <var>$1inlanguagecode</var>, otherwise in the content language).\n;extensiontags:Returns a list of parser extension tags.\n;functionhooks:Returns a list of parser function hooks.\n;showhooks:Returns a list of all subscribed hooks (contents of <var>[[mw:Manual:$wgHooks|$wgHooks]]</var>).\n;variables:Returns a list of variable IDs.\n;protocols:Returns a list of protocols that are allowed in external links.\n;defaultoptions:Returns the default values for user preferences.",
+       "apihelp-query+siteinfo-param-prop": "Which information to get:\n;general:Overall system information.\n;namespaces:List of registered namespaces and their canonical names.\n;namespacealiases:List of registered namespace aliases.\n;specialpagealiases:List of special page aliases.\n;magicwords:List of magic words and their aliases.\n;statistics:Returns site statistics.\n;interwikimap:Returns interwiki map (optionally filtered, optionally localised by using <var>$1inlanguagecode</var>).\n;dbrepllag:Returns database server with the highest replication lag.\n;usergroups:Returns user groups and the associated permissions.\n;libraries:Returns libraries installed on the wiki.\n;extensions:Returns extensions installed on the wiki.\n;fileextensions:Returns list of file extensions allowed to be uploaded.\n;rightsinfo:Returns wiki rights (license) information if available.\n;restrictions:Returns information on available restriction (protection) types.\n;languages:Returns a list of languages MediaWiki supports (optionally localised by using <var>$1inlanguagecode</var>).\n;skins:Returns a list of all enabled skins (optionally localised by using <var>$1inlanguagecode</var>, otherwise in the content language).\n;extensiontags:Returns a list of parser extension tags.\n;functionhooks:Returns a list of parser function hooks.\n;showhooks:Returns a list of all subscribed hooks (contents of <var>[[mw:Manual:$wgHooks|$wgHooks]]</var>).\n;variables:Returns a list of variable IDs.\n;protocols:Returns a list of protocols that are allowed in external links.\n;defaultoptions:Returns the default values for user preferences.",
        "apihelp-query+siteinfo-param-filteriw": "Return only local or only nonlocal entries of the interwiki map.",
        "apihelp-query+siteinfo-param-showalldb": "List all database servers, not just the one lagging the most.",
        "apihelp-query+siteinfo-param-numberingroup": "Lists the number of users in user groups.",