jenkins-bot has submitted this change and it was merged.

Change subject: Add git HEAD date to Special:Version for core and extensions
......................................................................


Add git HEAD date to Special:Version for core and extensions

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 <[email protected]> and updated and fixed
by Wikinaut<[email protected]>.

Bug: 38783
Change-Id: I0931400ecacf91ed2ab4fc7aa46dceac17661768
---
M includes/DefaultSettings.php
M includes/GitInfo.php
M includes/installer/Installer.i18n.php
M includes/installer/Installer.php
M includes/specials/SpecialVersion.php
5 files changed, 82 insertions(+), 6 deletions(-)

Approvals:
  Parent5446: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index d74a074..ff299fc 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -5010,6 +5010,11 @@
 $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
  *
  * Key is a pattern passed to preg_match() and preg_replace(),
diff --git a/includes/GitInfo.php b/includes/GitInfo.php
index 6f7f802..bf3bff7 100644
--- a/includes/GitInfo.php
+++ b/includes/GitInfo.php
@@ -121,6 +121,32 @@
        }
 
        /**
+        * 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
         */
diff --git a/includes/installer/Installer.i18n.php 
b/includes/installer/Installer.i18n.php
index 9119312..bbb41fe 100644
--- a/includes/installer/Installer.i18n.php
+++ b/includes/installer/Installer.i18n.php
@@ -142,6 +142,8 @@
        '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 @@
        '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.',
diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php
index 0dca23d..6a7970b 100644
--- a/includes/installer/Installer.php
+++ b/includes/installer/Installer.php
@@ -114,6 +114,7 @@
                'envCheckModSecurity',
                'envCheckDiff3',
                'envCheckGraphics',
+               'envCheckGit',
                'envCheckServer',
                'envCheckPath',
                'envCheckExtension',
@@ -147,6 +148,7 @@
                'wgDBtype',
                'wgDiff3',
                'wgImageMagickConvertCommand',
+               'wgGitBin',
                'IP',
                'wgServer',
                'wgScriptPath',
@@ -898,7 +900,8 @@
         */
        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 ) {
@@ -915,6 +918,28 @@
        }
 
        /**
+        * 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.
         */
        protected function envCheckServer() {
diff --git a/includes/specials/SpecialVersion.php 
b/includes/specials/SpecialVersion.php
index 581727d..d375316 100644
--- a/includes/specials/SpecialVersion.php
+++ b/includes/specials/SpecialVersion.php
@@ -274,10 +274,11 @@
        }
 
        /**
-        * @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 @@
                }
 
                $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 @@
         * @return string
         */
        function getCreditsForExtension( array $extension ) {
+               global $wgLang;
+
                $name = isset( $extension['name'] ) ? $extension['name'] : '[no 
name]';
 
                $vcsText = false;
@@ -474,6 +484,10 @@
                                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.

-- 
To view, visit https://gerrit.wikimedia.org/r/54986
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0931400ecacf91ed2ab4fc7aa46dceac17661768
Gerrit-PatchSet: 62
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Wikinaut <[email protected]>
Gerrit-Reviewer: Aklapper <[email protected]>
Gerrit-Reviewer: DaSch <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: PleaseStand <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Wikinaut <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to