Merge "mediawiki.searchSuggest: Show full article title as a tooltip for each suggestion"
[lhc/web/wiklou.git] / includes / specials / SpecialVersion.php
index c8add01..41847dc 100644 (file)
 class SpecialVersion extends SpecialPage {
        protected $firstExtOpened = false;
 
+       /**
+        * Stores the current rev id/SHA hash of MediaWiki core
+        */
+       protected $coreId = '';
+
        protected static $extensionTypes = false;
 
        protected static $viewvcUrls = array(
@@ -160,7 +165,7 @@ class SpecialVersion extends SpecialPage {
        /**
         * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
         *
-        * @return String
+        * @return string
         */
        public static function getCopyrightAndAuthorList() {
                global $wgLang;
@@ -235,7 +240,7 @@ class SpecialVersion extends SpecialPage {
        /**
         * Return a string of the MediaWiki version with SVN revision if available.
         *
-        * @param $flags String
+        * @param string $flags
         * @return mixed
         */
        public static function getVersion( $flags = '' ) {
@@ -404,7 +409,7 @@ class SpecialVersion extends SpecialPage {
         *
         * @since 1.17
         *
-        * @param $type String
+        * @param string $type
         *
         * @return string
         */
@@ -417,7 +422,7 @@ class SpecialVersion extends SpecialPage {
        /**
         * Generate wikitext showing extensions name, URL, author and description.
         *
-        * @return String: Wikitext
+        * @return string Wikitext
         */
        function getExtensionCredits() {
                global $wgExtensionCredits;
@@ -428,10 +433,7 @@ class SpecialVersion extends SpecialPage {
 
                $extensionTypes = self::getExtensionTypes();
 
-               /**
-                * @deprecated as of 1.17, use hook ExtensionTypes instead.
-                */
-               wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
+               wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ), '1.17' );
 
                $out = Xml::element(
                                'h2',
@@ -528,8 +530,8 @@ class SpecialVersion extends SpecialPage {
         *
         * @since 1.17
         *
-        * @param $type String
-        * @param $message String
+        * @param string $type
+        * @param string $message
         *
         * @return string
         */
@@ -553,8 +555,8 @@ class SpecialVersion extends SpecialPage {
 
        /**
         * Callback to sort extensions by type.
-        * @param $a array
-        * @param $b array
+        * @param array $a
+        * @param array $b
         * @return int
         */
        function compare( $a, $b ) {
@@ -580,9 +582,9 @@ class SpecialVersion extends SpecialPage {
         *  - Description of extension (descriptionmsg or description)
         *  - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
         *
-        * @param $extension Array
+        * @param array $extension
         *
-        * @return string raw HTML
+        * @return string Raw HTML
         */
        function getCreditsForExtension( array $extension ) {
                $out = $this->getOutput();
@@ -616,20 +618,43 @@ class SpecialVersion extends SpecialPage {
                }
 
                if ( isset( $extension['path'] ) ) {
-                       $extensionPath = dirname( $extension['path'] );
-                       $gitInfo = new GitInfo( $extensionPath );
-                       $vcsVersion = $gitInfo->getHeadSHA1();
-                       if ( $vcsVersion !== false ) {
-                               $vcsVersion = substr( $vcsVersion, 0, 7 );
-                               $vcsLink = $gitInfo->getHeadViewUrl();
-                               $vcsDate = $gitInfo->getHeadCommitDate();
-                       } else {
-                               $svnInfo = self::getSvnInfo( $extensionPath );
-                               if ( $svnInfo !== false ) {
-                                       $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
-                                       $vcsLink = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : '';
+                       global $IP;
+                       if ( $this->coreId == '' ) {
+                               wfDebug( 'Looking up core head id' );
+                               $coreHeadSHA1 = self::getGitHeadSha1( $IP );
+                               if ( $coreHeadSHA1 ) {
+                                       $this->coreId = $coreHeadSHA1;
+                               } else {
+                                       $svnInfo = self::getSvnInfo( $IP );
+                                       if ( $svnInfo !== false ) {
+                                               $this->coreId = $svnInfo['checkout-rev'];
+                                       }
                                }
                        }
+                       $cache = wfGetCache( CACHE_ANYTHING );
+                       $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId );
+                       list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
+
+                       if ( !$vcsVersion ) {
+                               wfDebug( "Getting VCS info for extension $extensionName" );
+                               $extensionPath = dirname( $extension['path'] );
+                               $gitInfo = new GitInfo( $extensionPath );
+                               $vcsVersion = $gitInfo->getHeadSHA1();
+                               if ( $vcsVersion !== false ) {
+                                       $vcsVersion = substr( $vcsVersion, 0, 7 );
+                                       $vcsLink = $gitInfo->getHeadViewUrl();
+                                       $vcsDate = $gitInfo->getHeadCommitDate();
+                               } else {
+                                       $svnInfo = self::getSvnInfo( $extensionPath );
+                                       if ( $svnInfo !== false ) {
+                                               $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
+                                               $vcsLink = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : '';
+                                       }
+                               }
+                               $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
+                       } else {
+                               wfDebug( "Pulled VCS info for extension $extensionName from cache" );
+                       }
                }
 
                $versionString = Html::rawElement(
@@ -733,7 +758,7 @@ class SpecialVersion extends SpecialPage {
        /**
         * Generate wikitext showing hooks in $wgHooks.
         *
-        * @return String: wikitext
+        * @return string Wikitext
         */
        private function getWgHooks() {
                global $wgSpecialVersionShowHooks, $wgHooks;
@@ -804,7 +829,7 @@ class SpecialVersion extends SpecialPage {
        /**
         * Get information about client's IP address.
         *
-        * @return String: HTML fragment
+        * @return string HTML fragment
         */
        private function IPInfo() {
                $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
@@ -826,11 +851,11 @@ class SpecialVersion extends SpecialPage {
         *   If no '...' string variant is found, but an authors file is found an
         *   'and others' will be added to the end of the credits.
         *
-        * @param $authors mixed: string or array of strings
-        * @param $extName string: name of the extension for link creation
-        * @param $extDir  string: path to the extension root directory
+        * @param string|array $authors
+        * @param string $extName Name of the extension for link creation
+        * @param string $extDir Path to the extension root directory
         *
-        * @return String: HTML fragment
+        * @return string HTML fragment
         */
        function listAuthors( $authors, $extName, $extDir ) {
                $hasOthers = false;
@@ -930,36 +955,30 @@ class SpecialVersion extends SpecialPage {
        /**
         * Convert an array of items into a list for display.
         *
-        * @param array $list of elements to display
-        * @param $sort Boolean: whether to sort the items in $list
+        * @param array $list List of elements to display
+        * @param bool $sort Whether to sort the items in $list
         *
-        * @return String
+        * @return string
         */
        function listToText( $list, $sort = true ) {
-               $cnt = count( $list );
-
-               if ( $cnt == 1 ) {
-                       // Enforce always returning a string
-                       return (string)self::arrayToString( $list[0] );
-               } elseif ( $cnt == 0 ) {
+               if ( !count( $list ) ) {
                        return '';
-               } else {
-                       if ( $sort ) {
-                               sort( $list );
-                       }
-
-                       return $this->getLanguage()
-                               ->listToText( array_map( array( __CLASS__, 'arrayToString' ), $list ) );
                }
+               if ( $sort ) {
+                       sort( $list );
+               }
+
+               return $this->getLanguage()
+                       ->listToText( array_map( array( __CLASS__, 'arrayToString' ), $list ) );
        }
 
        /**
         * Convert an array or object to a string for display.
         *
-        * @param $list Mixed: will convert an array to string if given and return
-        *              the paramater unaltered otherwise
+        * @param mixed $list Will convert an array to string if given and return
+        *   the paramater unaltered otherwise
         *
-        * @return Mixed
+        * @return mixed
         */
        public static function arrayToString( $list ) {
                if ( is_array( $list ) && count( $list ) == 1 ) {
@@ -995,7 +1014,7 @@ class SpecialVersion extends SpecialPage {
         *        url                   The subversion URL of the directory
         *        repo-url              The base URL of the repository
         *        viewvc-url            A ViewVC URL pointing to the checked-out revision
-        * @param $dir string
+        * @param string $dir
         * @return array|bool
         */
        public static function getSvnInfo( $dir ) {
@@ -1068,9 +1087,9 @@ class SpecialVersion extends SpecialPage {
        /**
         * Retrieve the revision number of a Subversion working directory.
         *
-        * @param string $dir directory of the svn checkout
+        * @param string $dir Directory of the svn checkout
         *
-        * @return Integer: revision number as int
+        * @return int Revision number
         */
        public static function getSvnRevision( $dir ) {
                $info = self::getSvnInfo( $dir );
@@ -1085,8 +1104,8 @@ class SpecialVersion extends SpecialPage {
        }
 
        /**
-        * @param string $dir directory of the git checkout
-        * @return bool|String sha1 of commit HEAD points to
+        * @param string $dir Directory of the git checkout
+        * @return bool|string Sha1 of commit HEAD points to
         */
        public static function getGitHeadSha1( $dir ) {
                $repo = new GitInfo( $dir );
@@ -1094,6 +1113,15 @@ class SpecialVersion extends SpecialPage {
                return $repo->getHeadSHA1();
        }
 
+       /**
+        * @param string $dir Directory of the git checkout
+        * @return bool|string Branch currently checked out
+        */
+       public static function getGitCurrentBranch( $dir ) {
+               $repo = new GitInfo( $dir );
+               return $repo->getCurrentBranch();
+       }
+
        /**
         * Get the list of entry points and their URLs
         * @return string Wikitext