Changed paths to package dependency file
authorPerside Rosalie <rosalieperside@gmail.com>
Sun, 25 Oct 2015 23:55:47 +0000 (00:55 +0100)
committerBryanDavis <bdavis@wikimedia.org>
Mon, 26 Oct 2015 15:58:03 +0000 (15:58 +0000)
Paths to ./composer.lock is changed to ./vendor/composer/installed.json
and dependency information now is read from the installed.json file.
A new ComposerInstalled class has been declared and uses the class now
to access the getInstalledDependencies() method to read data

Bug: T106247
Change-Id: Ic216577bb19b4fc5832ba003fcbbe9195d707b41

autoload.php
includes/api/ApiQuerySiteinfo.php
includes/libs/composer/ComposerInstalled.php [new file with mode: 0644]
includes/specials/SpecialVersion.php

index 9b5e10f..731bdaa 100644 (file)
@@ -242,6 +242,7 @@ $wgAutoloadLocalClasses = array(
        'CompareParserCache' => __DIR__ . '/maintenance/compareParserCache.php',
        'CompareParsers' => __DIR__ . '/maintenance/compareParsers.php',
        'ComposerHookHandler' => __DIR__ . '/includes/composer/ComposerHookHandler.php',
+       'ComposerInstalled' => __DIR__ . '/includes/libs/composer/ComposerInstalled.php',
        'ComposerJson' => __DIR__ . '/includes/libs/composer/ComposerJson.php',
        'ComposerLock' => __DIR__ . '/includes/libs/composer/ComposerLock.php',
        'ComposerPackageModifier' => __DIR__ . '/includes/composer/ComposerPackageModifier.php',
index 1265155..c13b30b 100644 (file)
@@ -540,18 +540,14 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
        protected function appendInstalledLibraries( $property ) {
                global $IP;
-               $path = "$IP/composer.lock";
+               $path = "$IP/vendor/composer/installed.json";
                if ( !file_exists( $path ) ) {
-                       // Maybe they're using mediawiki/vendor?
-                       $path = "$IP/vendor/composer.lock";
-                       if ( !file_exists( $path ) ) {
-                               return true;
-                       }
+                       return true;
                }
 
                $data = array();
-               $lock = new ComposerLock( $path );
-               foreach ( $lock->getInstalledDependencies() as $name => $info ) {
+               $installed = new ComposerInstalled( $path );
+               foreach ( $installed->getInstalledDependencies() as $name => $info ) {
                        if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
                                // Skip any extensions or skins since they'll be listed
                                // in their proper section
diff --git a/includes/libs/composer/ComposerInstalled.php b/includes/libs/composer/ComposerInstalled.php
new file mode 100644 (file)
index 0000000..5f87b54
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * Reads an installed.json file and provides accessors to get what is
+ * installed
+ *
+ * @since 1.27
+ */
+class ComposerInstalled {
+
+       /**
+        * @param string $location
+        */
+       public function __construct( $location ) {
+               $this->contents = json_decode( file_get_contents( $location ), true );
+       }
+
+       /**
+        * Dependencies currently installed according to installed.json
+        *
+        * @return array
+        */
+       public function getInstalledDependencies() {
+               $deps = array();
+               foreach ( $this->contents as $installed ) {
+                       $deps[$installed['name']] = array(
+                               'version' => ComposerJson::normalizeVersion( $installed['version'] ),
+                               'type' => $installed['type'],
+                               'licenses' => isset( $installed['license'] ) ? $installed['license'] : array(),
+                               'authors' => isset( $installed['authors'] ) ? $installed['authors'] : array(),
+                               'description' => isset( $installed['description'] ) ? $installed['description']: '',
+                       );
+               }
+
+               ksort( $deps );
+               return $deps;
+       }
+}
index 38baf5b..7e0f0b2 100644 (file)
@@ -518,16 +518,12 @@ class SpecialVersion extends SpecialPage {
         */
        protected function getExternalLibraries() {
                global $IP;
-               $path = "$IP/composer.lock";
+               $path = "$IP/vendor/composer/installed.json";
                if ( !file_exists( $path ) ) {
-                       // Maybe they're using mediawiki/vendor?
-                       $path = "$IP/vendor/composer.lock";
-                       if ( !file_exists( $path ) ) {
-                               return '';
-                       }
+                       return '';
                }
 
-               $lock = new ComposerLock( $path );
+               $installed = new ComposerInstalled( $path );
                $out = Html::element(
                        'h2',
                        array( 'id' => 'mw-version-libraries' ),
@@ -545,7 +541,7 @@ class SpecialVersion extends SpecialPage {
                        . Html::element( 'th', array(), $this->msg( 'version-libraries-authors' )->text() )
                        . Html::closeElement( 'tr' );
 
-               foreach ( $lock->getInstalledDependencies() as $name => $info ) {
+               foreach ( $installed->getInstalledDependencies() as $name => $info ) {
                        if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
                                // Skip any extensions or skins since they'll be listed
                                // in their proper section