/**
* Cached git information.
*/
- protected $cache = array();
+ protected $cache = [];
/**
* Map of repo URLs to viewer URLs. Access via static method getViewers().
*
* @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 ) {
// 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";
}
/**
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;
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 );
}
}
if ( self::$viewers === false ) {
self::$viewers = $wgGitRepositoryViewers;
- Hooks::run( 'GitViewers', array( &self::$viewers ) );
+ Hooks::run( 'GitViewers', [ &self::$viewers ] );
}
return self::$viewers;