From 06bfb654ab68bfe547403460c1656a95d9fded58 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Thu, 12 Feb 2015 13:09:23 -0800 Subject: [PATCH] Expose installed libraries in action=query&meta=siteinfo Bug: T89385 Change-Id: I4256f4d9858c09c042f649b7e701189acf85aedd --- RELEASE-NOTES-1.25 | 5 ++++- includes/api/ApiQuerySiteinfo.php | 34 +++++++++++++++++++++++++++++++ includes/api/i18n/en.json | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 3f24db013a..eb9fe3879f 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -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. diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 4e5c42b68a..5ac10366e5 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -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', diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index 0e766bf573..677957100b 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -871,7 +871,7 @@ "apihelp-query+search-example-generator": "Ger page info about the pages returned for a search for meaning.", "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 $1inlanguagecode).\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 $1inlanguagecode).\n;skins:Returns a list of all enabled skins (optionally localised by using $1inlanguagecode, 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 [[mw:Manual:$wgHooks|$wgHooks]]).\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 $1inlanguagecode).\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 $1inlanguagecode).\n;skins:Returns a list of all enabled skins (optionally localised by using $1inlanguagecode, 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 [[mw:Manual:$wgHooks|$wgHooks]]).\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.", -- 2.20.1