X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FGitInfo.php;h=de7e8c28e2d8373af10bbe253b696f1daaf11573;hb=eb46307b001ad116426b866b506ef49fb21f1e3d;hp=acf1bf64a374d5f1457906bd2572c136c041cf1e;hpb=9bb1b0f62601801dfacdc396778af094e7c2dc63;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GitInfo.php b/includes/GitInfo.php index acf1bf64a3..de7e8c28e2 100644 --- a/includes/GitInfo.php +++ b/includes/GitInfo.php @@ -43,7 +43,7 @@ class GitInfo { /** * Cached git information. */ - protected $cache = array(); + protected $cache = []; /** * Map of repo URLs to viewer URLs. Access via static method getViewers(). @@ -96,7 +96,7 @@ class GitInfo { * * @param string $repoDir The root directory of the repo where .git can be found * @return string Path to GitInfo cache file in $wgGitInfoCacheDirectory or - * null if $wgGitInfoCacheDirectory is false (cache disabled). + * fallback in the extension directory itself * @since 1.24 */ protected static function getCacheFilePath( $repoDir ) { @@ -119,9 +119,13 @@ class GitInfo { // a filename $repoName = strtr( $repoName, DIRECTORY_SEPARATOR, '-' ); $fileName = 'info' . $repoName . '.json'; - return "{$wgGitInfoCacheDirectory}/{$fileName}"; + $cachePath = "{$wgGitInfoCacheDirectory}/{$fileName}"; + if ( is_readable( $cachePath ) ) { + return $cachePath; + } } - return null; + + return "$repoDir/gitinfo.json"; } /** @@ -211,7 +215,7 @@ class GitInfo { is_executable( $wgGitBin ) && $this->getHead() !== false ) { - $environment = array( "GIT_DIR" => $this->basedir ); + $environment = [ "GIT_DIR" => $this->basedir ]; $cmd = wfEscapeShellArg( $wgGitBin ) . " show -s --format=format:%ct HEAD"; $retc = false; @@ -253,19 +257,17 @@ class GitInfo { if ( $url === false ) { return false; } - if ( substr( $url, -4 ) !== '.git' ) { - $url .= '.git'; - } foreach ( self::getViewers() as $repo => $viewer ) { $pattern = '#^' . $repo . '$#'; if ( preg_match( $pattern, $url, $matches ) ) { $viewerUrl = preg_replace( $pattern, $viewer, $url ); $headSHA1 = $this->getHeadSHA1(); - $replacements = array( + $replacements = [ '%h' => substr( $headSHA1, 0, 7 ), '%H' => $headSHA1, '%r' => urlencode( $matches[1] ), - ); + '%R' => $matches[1], + ]; return strtr( $viewerUrl, $replacements ); } } @@ -274,16 +276,16 @@ class GitInfo { /** * Get the URL of the remote origin. - * @return string|bool string if a URL is available or false otherwise. + * @return string|bool String if a URL is available or false otherwise. */ protected function getRemoteUrl() { if ( !isset( $this->cache['remoteURL'] ) ) { $config = "{$this->basedir}/config"; $url = false; if ( is_readable( $config ) ) { - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $configArray = parse_ini_file( $config, true ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); $remote = false; // Use the "origin" remote repo if available or any other repo if not. @@ -392,7 +394,7 @@ class GitInfo { if ( self::$viewers === false ) { self::$viewers = $wgGitRepositoryViewers; - wfRunHooks( 'GitViewers', array( &self::$viewers ) ); + Hooks::run( 'GitViewers', [ &self::$viewers ] ); } return self::$viewers;