Add git HEAD date to Special:Version for core and extensions
authorDaSch <dasch@daschmedia.de>
Wed, 1 Aug 2012 20:49:17 +0000 (22:49 +0200)
committerParent5446 <tylerromeo@gmail.com>
Mon, 15 Apr 2013 20:47:15 +0000 (20:47 +0000)
The patch adds the localised commit date of i) core and ii) extensions
in the Special:Version page tables. It requires the Git version control
system being installed, which is checked during the installation.

Introduces a new parameter for the git binary in DefaultSettings.php:
$wgGitBin = '/usr/bin/git';

Patch authored by DaSch <dasch@daschmedia.de> and updated and fixed
by Wikinaut<mail@tgries.de>.

Bug: 38783
Change-Id: I0931400ecacf91ed2ab4fc7aa46dceac17661768

includes/DefaultSettings.php
includes/GitInfo.php
includes/installer/Installer.i18n.php
includes/installer/Installer.php
includes/specials/SpecialVersion.php

index d74a074..ff299fc 100644 (file)
@@ -5009,6 +5009,11 @@ $wgReadOnlyFile = false;
  */
 $wgUpgradeKey = false;
 
+/**
+ * Fully specified path to git binary
+ */
+$wgGitBin = '/usr/bin/git';
+
 /**
  * Map GIT repository URLs to viewer URLs to provide links in Special:Version
  *
index 6f7f802..bf3bff7 100644 (file)
@@ -120,6 +120,32 @@ class GitInfo {
                return $sha1;
        }
 
+       /**
+        * Return the commit date of HEAD entry of the git code repository
+        *
+        * @since 1.22
+        * @return int|bool Commit date (UNIX timestamp) or false
+        */
+       public function getHeadCommitDate() {
+               global $wgGitBin;
+
+               if ( !is_file( $wgGitBin ) || !is_executable( $wgGitBin ) ) {
+                       return false;
+               }
+
+               $environment = array( "GIT_DIR" => $this->basedir );
+               $cmd = wfEscapeShellArg( $wgGitBin ) . " show -s --format=format:%ct HEAD";
+               $retc = false;
+               $commitDate = wfShellExec( $cmd, $retc, $environment );
+
+               if ( $retc !== 0 ) {
+                       return false;
+               } else {
+                       return (int)$commitDate;
+               }
+
+        }
+
        /**
         * Return the name of the current branch, or HEAD if not found
         * @return string The branch name, HEAD, or false
index 9119312..bbb41fe 100644 (file)
@@ -142,6 +142,8 @@ Object caching is not enabled.",
        'config-mod-security'             => "'''Warning:''' Your web server has [http://modsecurity.org/ mod_security] enabled. If misconfigured, it can cause problems for MediaWiki or other software that allows users to post arbitrary content.
 Refer to [http://modsecurity.org/documentation/ mod_security documentation] or contact your host's support if you encounter random errors.",
        'config-diff3-bad'                => 'GNU diff3 not found.',
+       'config-git'                      => 'Found the Git version control software: <code>$1</code>.',
+       'config-git-bad'                  => 'Git version control software not found.',
        'config-imagemagick'              => 'Found ImageMagick: <code>$1</code>.
 Image thumbnailing will be enabled if you enable uploads.',
        'config-gd'                       => 'Found GD graphics library built-in.
@@ -647,6 +649,10 @@ Parameters:
        'config-xcache' => 'Message indicates if this program is available',
        'config-apc' => 'Message indicates if this program is available',
        'config-wincache' => 'Message indicates if this program is available',
+       'config-git' => 'Message if Git version control software is available.
+Parameter:
+* $1 is the <code>Git</code> executable file name.',
+       'config-git-bad' => 'Message if Git version control software is not found.',
        'config-imagemagick' => '$1 is ImageMagick\'s <code>convert</code> executable file name.
 
 Add dir="ltr" to the <nowiki><code></nowiki> for right-to-left languages.',
index 0dca23d..6a7970b 100644 (file)
@@ -114,6 +114,7 @@ abstract class Installer {
                'envCheckModSecurity',
                'envCheckDiff3',
                'envCheckGraphics',
+               'envCheckGit',
                'envCheckServer',
                'envCheckPath',
                'envCheckExtension',
@@ -147,6 +148,7 @@ abstract class Installer {
                'wgDBtype',
                'wgDiff3',
                'wgImageMagickConvertCommand',
+               'wgGitBin',
                'IP',
                'wgServer',
                'wgScriptPath',
@@ -898,7 +900,8 @@ abstract class Installer {
         */
        protected function envCheckGraphics() {
                $names = array( wfIsWindows() ? 'convert.exe' : 'convert' );
-               $convert = self::locateExecutableInDefaultPaths( $names, array( '$1 -version', 'ImageMagick' ) );
+               $versionInfo = array( '$1 -version', 'ImageMagick' );
+               $convert = self::locateExecutableInDefaultPaths( $names, $versionInfo );
 
                $this->setVar( 'wgImageMagickConvertCommand', '' );
                if ( $convert ) {
@@ -914,6 +917,28 @@ abstract class Installer {
                return true;
        }
 
+       /**
+        * Search for git.
+        *
+        * @since 1.22
+        * @return bool
+        */
+       protected function envCheckGit() {
+               $names = array( wfIsWindows() ? 'git.exe' : 'git' );
+               $versionInfo = array( '$1 --version', 'git version' );
+
+               $git = self::locateExecutableInDefaultPaths( $names, $versionInfo );
+
+               if ( $git ) {
+                       $this->setVar( 'wgGitBin', $git );
+                       $this->showMessage( 'config-git', $git );
+               } else {
+                       $this->setVar( 'wgGitBin', false );
+                       $this->showMessage( 'config-git-bad' );
+               }
+               return true;
+       }
+
        /**
         * Environment check for the server hostname.
         */
index 581727d..d375316 100644 (file)
@@ -274,10 +274,11 @@ class SpecialVersion extends SpecialPage {
        }
 
        /**
-        * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 chars. False on failure
+        * @since 1.22 Returns the HEAD date in addition to the sha1 and link
+        * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 chars with link and date, or false on failure
         */
        private static function getVersionLinkedGit() {
-               global $IP;
+               global $IP, $wgLang;
 
                $gitInfo = new GitInfo( $IP );
                $headSHA1 = $gitInfo->getHeadSHA1();
@@ -286,10 +287,17 @@ class SpecialVersion extends SpecialPage {
                }
 
                $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
-               $viewerUrl = $gitInfo->getHeadViewUrl();
-               if ( $viewerUrl !== false ) {
-                       $shortSHA1 = "[$viewerUrl $shortSHA1]";
+
+               $gitHeadUrl = $gitInfo->getHeadViewUrl();
+               if ( $gitHeadUrl !== false ) {
+                       $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
+               }
+
+               $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
+               if ( $gitHeadCommitDate ) {
+                       $shortSHA1 .= "<br/>" . $wgLang->timeanddate( $gitHeadCommitDate, true );
                }
+
                return self::getwgVersionLinked() . " $shortSHA1";
        }
 
@@ -461,6 +469,8 @@ class SpecialVersion extends SpecialPage {
         * @return string
         */
        function getCreditsForExtension( array $extension ) {
+               global $wgLang;
+
                $name = isset( $extension['name'] ) ? $extension['name'] : '[no name]';
 
                $vcsText = false;
@@ -474,6 +484,10 @@ class SpecialVersion extends SpecialPage {
                                if ( $gitViewerUrl !== false ) {
                                        $vcsText = "[$gitViewerUrl $vcsText]";
                                }
+                               $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
+                               if ( $gitHeadCommitDate ) {
+                                       $vcsText .= "<br/>" .  $wgLang->timeanddate( $gitHeadCommitDate, true );
+                               }
                        } else {
                                $svnInfo = self::getSvnInfo( dirname( $extension['path'] ) );
                                # Make subversion text/link.