Merge "SpecialTrackingCategories: Read from the extension registry"
[lhc/web/wiklou.git] / includes / specials / SpecialVersion.php
index ee9e2ad..2aa629e 100644 (file)
@@ -132,6 +132,7 @@ class SpecialVersion extends SpecialPage {
                                $out->addHtml(
                                        $this->getSkinCredits() .
                                        $this->getExtensionCredits() .
+                                       $this->getExternalLibraries() .
                                        $this->getParserTags() .
                                        $this->getParserFunctionHooks()
                                );
@@ -251,7 +252,6 @@ class SpecialVersion extends SpecialPage {
         */
        public static function getVersion( $flags = '' ) {
                global $wgVersion, $IP;
-               wfProfileIn( __METHOD__ );
 
                $gitInfo = self::getGitHeadSha1( $IP );
                $svnInfo = self::getSvnInfo( $IP );
@@ -275,8 +275,6 @@ class SpecialVersion extends SpecialPage {
                                )->text();
                }
 
-               wfProfileOut( __METHOD__ );
-
                return $version;
        }
 
@@ -290,7 +288,6 @@ class SpecialVersion extends SpecialPage {
         */
        public static function getVersionLinked() {
                global $wgVersion;
-               wfProfileIn( __METHOD__ );
 
                $gitVersion = self::getVersionLinkedGit();
                if ( $gitVersion ) {
@@ -304,8 +301,6 @@ class SpecialVersion extends SpecialPage {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
-
                return $v;
        }
 
@@ -503,6 +498,50 @@ class SpecialVersion extends SpecialPage {
                return $out;
        }
 
+       /**
+        * Generate an HTML table for external libraries that are installed
+        *
+        * @return string
+        */
+       protected function getExternalLibraries() {
+               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 '';
+                       }
+               }
+
+               $lock = new ComposerLock( $path );
+               $out = Html::element(
+                       'h2',
+                       array( 'id' => 'mw-version-libraries' ),
+                       $this->msg( 'version-libraries' )->text()
+               );
+               $out .= Html::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-libraries' ) );
+               $out .= Html::openElement( 'tr' )
+                       . Html::element( 'th', array(), $this->msg( 'version-libraries-library' )->text() )
+                       . Html::element( 'th', array(), $this->msg( 'version-libraries-version' )->text() )
+                       . Html::closeElement( 'tr' );
+
+               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;
+                       }
+                       $out .= Html::openElement( 'tr' )
+                               . Html::rawElement( 'td', array(), Linker::makeExternalLink( "https://packagist.org/packages/$name", $name ) )
+                               . Html::element( 'td', array(), $info['version'] )
+                               . Html::closeElement( 'tr' );
+               }
+               $out .= Html::closeElement( 'table' );
+
+               return $out;
+       }
+
        /**
         * Obtains a list of installed parser tags and the associated H2 header
         *
@@ -689,7 +728,7 @@ class SpecialVersion extends SpecialPage {
                        list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
 
                        if ( !$vcsVersion ) {
-                               wfDebug( "Getting VCS info for extension $extensionName" );
+                               wfDebug( "Getting VCS info for extension {$extension['name']}" );
                                $gitInfo = new GitInfo( $extensionPath );
                                $vcsVersion = $gitInfo->getHeadSHA1();
                                if ( $vcsVersion !== false ) {
@@ -705,7 +744,7 @@ class SpecialVersion extends SpecialPage {
                                }
                                $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
                        } else {
-                               wfDebug( "Pulled VCS info for extension $extensionName from cache" );
+                               wfDebug( "Pulled VCS info for extension {$extension['name']} from cache" );
                        }
                }
 
@@ -748,24 +787,23 @@ class SpecialVersion extends SpecialPage {
                // ... and license information; if a license file exists we
                // will link to it
                $licenseLink = '';
-               if ( isset( $extension['license-name'] ) ) {
-                       $licenseLink = Linker::link(
-                               $this->getPageTitle( 'License/' . $extensionName ),
-                               $out->parseInline( $extension['license-name'] ),
-                               array(
-                                       'class' => 'mw-version-ext-license',
-                                       'dir' => 'auto',
-                               )
-                       );
-               } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
-                       $licenseLink = Linker::link(
-                               $this->getPageTitle( 'License/' . $extensionName ),
-                               $this->msg( 'version-ext-license' ),
-                               array(
-                                       'class' => 'mw-version-ext-license',
-                                       'dir' => 'auto',
-                               )
-                       );
+               if ( isset( $extension['name'] ) ) {
+                       $licenseName = null;
+                       if ( isset( $extension['license-name'] ) ) {
+                               $licenseName = $out->parseInline( $extension['license-name'] );
+                       } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
+                               $licenseName = $this->msg( 'version-ext-license' );
+                       }
+                       if ( $licenseName !== null ) {
+                               $licenseLink = Linker::link(
+                                       $this->getPageTitle( 'License/' . $extension['name'] ),
+                                       $licenseName,
+                                       array(
+                                               'class' => 'mw-version-ext-license',
+                                               'dir' => 'auto',
+                                       )
+                               );
+                       }
                }
 
                // ... and generate the description; which can be a parameterized l10n message
@@ -793,12 +831,12 @@ class SpecialVersion extends SpecialPage {
 
                // ... now get the authors for this extension
                $authors = isset( $extension['author'] ) ? $extension['author'] : array();
-               $authors = $this->listAuthors( $authors, $extensionName, $extensionPath );
+               $authors = $this->listAuthors( $authors, $extension['name'], $extensionPath );
 
                // Finally! Create the table
                $html = Html::openElement( 'tr', array(
                                'class' => 'mw-version-ext',
-                               'id' => "mw-version-ext-{$extensionName}"
+                               'id' => "mw-version-ext-{$extension['name']}"
                        )
                );
 
@@ -1039,7 +1077,7 @@ class SpecialVersion extends SpecialPage {
         * Convert an array or object to a string for display.
         *
         * @param mixed $list Will convert an array to string if given and return
-        *   the paramater unaltered otherwise
+        *   the parameter unaltered otherwise
         *
         * @return mixed
         */