From e9e24cbfe7849c7e2387a0953cce3e059b452a1a Mon Sep 17 00:00:00 2001 From: DaSch Date: Wed, 1 Aug 2012 22:49:17 +0200 Subject: [PATCH] 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 and updated and fixed by Wikinaut. Bug: 38783 Change-Id: I0931400ecacf91ed2ab4fc7aa46dceac17661768 --- includes/DefaultSettings.php | 5 +++++ includes/GitInfo.php | 26 ++++++++++++++++++++++++++ includes/installer/Installer.i18n.php | 6 ++++++ includes/installer/Installer.php | 27 ++++++++++++++++++++++++++- includes/specials/SpecialVersion.php | 24 +++++++++++++++++++----- 5 files changed, 82 insertions(+), 6 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index d74a074ed5..ff299fc71b 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 * diff --git a/includes/GitInfo.php b/includes/GitInfo.php index 6f7f80200b..bf3bff78b6 100644 --- a/includes/GitInfo.php +++ b/includes/GitInfo.php @@ -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 diff --git a/includes/installer/Installer.i18n.php b/includes/installer/Installer.i18n.php index 91193122d3..bbb41fe6a2 100644 --- a/includes/installer/Installer.i18n.php +++ b/includes/installer/Installer.i18n.php @@ -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: $1.', + 'config-git-bad' => 'Git version control software not found.', 'config-imagemagick' => 'Found ImageMagick: $1. 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 Git executable file name.', + 'config-git-bad' => 'Message if Git version control software is not found.', 'config-imagemagick' => '$1 is ImageMagick\'s convert executable file name. Add dir="ltr" to the for right-to-left languages.', diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 0dca23d766..6a7970b031 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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. */ diff --git a/includes/specials/SpecialVersion.php b/includes/specials/SpecialVersion.php index 581727de77..d375316bb2 100644 --- a/includes/specials/SpecialVersion.php +++ b/includes/specials/SpecialVersion.php @@ -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 .= "
" . $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 .= "
" . $wgLang->timeanddate( $gitHeadCommitDate, true ); + } } else { $svnInfo = self::getSvnInfo( dirname( $extension['path'] ) ); # Make subversion text/link. -- 2.20.1