public function testMissingJsonData() { $dir = $GLOBALS['IP'] . '/testMissingJsonData'; $fixture = new GitInfo($dir); $this->assertFalse($fixture->cacheIsComplete()); $this->assertEquals(false, $fixture->getHead()); $this->assertEquals(false, $fixture->getHeadSHA1()); $this->assertEquals(false, $fixture->getHeadCommitDate()); $this->assertEquals(false, $fixture->getCurrentBranch()); $this->assertEquals(false, $fixture->getHeadViewUrl()); // After calling all the outputs, the cache should be complete $this->assertTrue($fixture->cacheIsComplete()); }
/** * @param string $dir directory of the git checkout * @return bool|String sha1 of commit HEAD points to */ public static function getGitHeadSha1($dir) { $repo = new GitInfo($dir); return $repo->getHeadSHA1(); }
public function setSourceInfoGithub($owner, $repo, $repoDir = null) { $section = new kfLogSection(__METHOD__); $this->sourceInfo = array('issueTrackerUrl' => "https://github.com/{$owner}/{$repo}/issues", 'repoViewUrl' => "https://github.com/{$owner}/{$repo}"); if (is_dir($repoDir)) { $gitInfo = new GitInfo($repoDir); $repoCommitID = $gitInfo->getHeadSHA1(); if ($repoCommitID) { $this->sourceInfo['repoDir'] = $repoDir; $this->sourceInfo['repoCommitID'] = substr($repoCommitID, 0, 8); $this->sourceInfo['repoCommitUrl'] = "https://github.com/{$owner}/{$repo}/commit/{$repoCommitID}"; } else { kfLog("GitInfo for '{$repoDir}' failed."); } } }
/** * Gets the list of repository viewers * @return array */ protected static function getViewers() { global $wgGitRepositoryViewers; if (self::$viewers === false) { self::$viewers = $wgGitRepositoryViewers; Hooks::run('GitViewers', [&self::$viewers]); } return self::$viewers; }
/** * Returns the HTML to add to the page for the toolbar * * @param $context IContextSource * @return array */ public static function getDebugInfo(IContextSource $context) { if (!self::$enabled) { return array(); } global $wgVersion, $wgRequestTime; $request = $context->getRequest(); return array('mwVersion' => $wgVersion, 'phpVersion' => PHP_VERSION, 'gitRevision' => GitInfo::headSHA1(), 'gitBranch' => GitInfo::currentBranch(), 'gitViewUrl' => GitInfo::headViewUrl(), 'time' => microtime(true) - $wgRequestTime, 'log' => self::$log, 'debugLog' => self::$debug, 'queries' => self::$query, 'request' => array('method' => $request->getMethod(), 'url' => $request->getRequestURL(), 'headers' => $request->getAllHeaders(), 'params' => $request->getValues()), 'memory' => $context->getLanguage()->formatSize(memory_get_usage()), 'memoryPeak' => $context->getLanguage()->formatSize(memory_get_peak_usage()), 'includes' => self::getFilesIncluded($context)); }
/** * Returns the HTML to add to the page for the toolbar * * @param IContextSource $context * @return array */ public static function getDebugInfo(IContextSource $context) { if (!self::$enabled) { return array(); } global $wgVersion, $wgRequestTime; $request = $context->getRequest(); // HHVM's reported memory usage from memory_get_peak_usage() // is not useful when passing false, but we continue passing // false for consistency of historical data in zend. // see: https://github.com/facebook/hhvm/issues/2257#issuecomment-39362246 $realMemoryUsage = wfIsHHVM(); return array('mwVersion' => $wgVersion, 'phpEngine' => wfIsHHVM() ? 'HHVM' : 'PHP', 'phpVersion' => wfIsHHVM() ? HHVM_VERSION : PHP_VERSION, 'gitRevision' => GitInfo::headSHA1(), 'gitBranch' => GitInfo::currentBranch(), 'gitViewUrl' => GitInfo::headViewUrl(), 'time' => microtime(true) - $wgRequestTime, 'log' => self::$log, 'debugLog' => self::$debug, 'queries' => self::$query, 'request' => array('method' => $request->getMethod(), 'url' => $request->getRequestURL(), 'headers' => $request->getAllHeaders(), 'params' => $request->getValues()), 'memory' => $context->getLanguage()->formatSize(memory_get_usage($realMemoryUsage)), 'memoryPeak' => $context->getLanguage()->formatSize(memory_get_peak_usage($realMemoryUsage)), 'includes' => self::getFilesIncluded($context)); }
protected function appendExtensions($property) { global $wgExtensionCredits; $data = array(); foreach ($wgExtensionCredits as $type => $extensions) { foreach ($extensions as $ext) { $ret = array(); $ret['type'] = $type; if (isset($ext['name'])) { $ret['name'] = $ext['name']; } if (isset($ext['description'])) { $ret['description'] = $ext['description']; } if (isset($ext['descriptionmsg'])) { // Can be a string or array( key, param1, param2, ... ) if (is_array($ext['descriptionmsg'])) { $ret['descriptionmsg'] = $ext['descriptionmsg'][0]; $ret['descriptionmsgparams'] = array_slice($ext['descriptionmsg'], 1); $this->getResult()->setIndexedTagName($ret['descriptionmsgparams'], 'param'); } else { $ret['descriptionmsg'] = $ext['descriptionmsg']; } } if (isset($ext['author'])) { $ret['author'] = is_array($ext['author']) ? implode(', ', $ext['author']) : $ext['author']; } if (isset($ext['url'])) { $ret['url'] = $ext['url']; } if (isset($ext['version'])) { $ret['version'] = $ext['version']; } elseif (isset($ext['svn-revision']) && preg_match('/\\$(?:Rev|LastChangedRevision|Revision): *(\\d+)/', $ext['svn-revision'], $m)) { $ret['version'] = 'r' . $m[1]; } if (isset($ext['path'])) { $extensionPath = dirname($ext['path']); $gitInfo = new GitInfo($extensionPath); $vcsVersion = $gitInfo->getHeadSHA1(); if ($vcsVersion !== false) { $ret['vcs-system'] = 'git'; $ret['vcs-version'] = $vcsVersion; $ret['vcs-url'] = $gitInfo->getHeadViewUrl(); $vcsDate = $gitInfo->getHeadCommitDate(); if ($vcsDate !== false) { $ret['vcs-date'] = wfTimestamp(TS_ISO_8601, $vcsDate); } } else { $svnInfo = SpecialVersion::getSvnInfo($extensionPath); if ($svnInfo !== false) { $ret['vcs-system'] = 'svn'; $ret['vcs-version'] = $svnInfo['checkout-rev']; $ret['vcs-url'] = isset($svnInfo['viewvc-url']) ? $svnInfo['viewvc-url'] : ''; } } if (SpecialVersion::getExtLicenseFileName($extensionPath)) { $ret['license-name'] = isset($ext['license-name']) ? $ext['license-name'] : ''; $ret['license'] = SpecialPage::getTitleFor('Version', "License/{$ext['name']}")->getLinkURL(); } if (SpecialVersion::getExtAuthorsFileName($extensionPath)) { $ret['credits'] = SpecialPage::getTitleFor('Version', "Credits/{$ext['name']}")->getLinkURL(); } } $data[] = $ret; } } $this->getResult()->setIndexedTagName($data, 'ext'); return $this->getResult()->addValue('query', $property, $data); }
/** * @param string $dir Directory of the git checkout * @return bool|string Branch currently checked out */ public static function getGitCurrentBranch($dir) { $repo = new GitInfo($dir); return $repo->getCurrentBranch(); }
/** * Gets the list of repository viewers * @return array */ protected static function getViewers() { global $wgGitRepositoryViewers; if (self::$viewers === false) { self::$viewers = $wgGitRepositoryViewers; wfRunHooks('GitViewers', array(&self::$viewers)); } return self::$viewers; }
protected function appendExtensions($property) { $data = []; foreach ($this->getConfig()->get('ExtensionCredits') as $type => $extensions) { foreach ($extensions as $ext) { $ret = []; $ret['type'] = $type; if (isset($ext['name'])) { $ret['name'] = $ext['name']; } if (isset($ext['namemsg'])) { $ret['namemsg'] = $ext['namemsg']; } if (isset($ext['description'])) { $ret['description'] = $ext['description']; } if (isset($ext['descriptionmsg'])) { // Can be a string or array( key, param1, param2, ... ) if (is_array($ext['descriptionmsg'])) { $ret['descriptionmsg'] = $ext['descriptionmsg'][0]; $ret['descriptionmsgparams'] = array_slice($ext['descriptionmsg'], 1); ApiResult::setIndexedTagName($ret['descriptionmsgparams'], 'param'); } else { $ret['descriptionmsg'] = $ext['descriptionmsg']; } } if (isset($ext['author'])) { $ret['author'] = is_array($ext['author']) ? implode(', ', $ext['author']) : $ext['author']; } if (isset($ext['url'])) { $ret['url'] = $ext['url']; } if (isset($ext['version'])) { $ret['version'] = $ext['version']; } if (isset($ext['path'])) { $extensionPath = dirname($ext['path']); $gitInfo = new GitInfo($extensionPath); $vcsVersion = $gitInfo->getHeadSHA1(); if ($vcsVersion !== false) { $ret['vcs-system'] = 'git'; $ret['vcs-version'] = $vcsVersion; $ret['vcs-url'] = $gitInfo->getHeadViewUrl(); $vcsDate = $gitInfo->getHeadCommitDate(); if ($vcsDate !== false) { $ret['vcs-date'] = wfTimestamp(TS_ISO_8601, $vcsDate); } } if (SpecialVersion::getExtLicenseFileName($extensionPath)) { $ret['license-name'] = isset($ext['license-name']) ? $ext['license-name'] : ''; $ret['license'] = SpecialPage::getTitleFor('Version', "License/{$ext['name']}")->getLinkURL(); } if (SpecialVersion::getExtAuthorsFileName($extensionPath)) { $ret['credits'] = SpecialPage::getTitleFor('Version', "Credits/{$ext['name']}")->getLinkURL(); } } $data[] = $ret; } } ApiResult::setIndexedTagName($data, 'ext'); return $this->getResult()->addValue('query', $property, $data); }
// When checking out a whole bunch of remote branches, creating // archives, moving stuff around. The working copy will leave build artificants // behind. It will also contain lots of files that will be considered "untracked" // according to a different branch pointer. // Beware that if you run this locally, don't use your main wiki as this also // removes things like "LocalSettings.php". print "Clean workspace and checkout {$remoteBranchName}...\n"; $execOut = kfGitCleanReset(array('checkout' => $remoteBranchName)); // Get revision of this branch. Used so we can check that the checkout worked // (in the past the script failed once due to a .git/index.lock error, in which case // the checkout command was aborted, and all the archives were for the same revision). // This will not happen again because we're now verifying that the remote branch head // matches the HEAD of the working copy after the checkout. print "Verifiying checkout succeeded...\n"; $currHead = trim(kfShellExec("git rev-parse --verify HEAD")); if (!GitInfo::isSHA1($currHead)) { print "> rev-parse failed for HEAD: {$currHead}\n"; print "> Skipping {$remoteBranchName}...\n"; continue; } if ($branchHead !== $currHead) { // Checkout likely failed print "> ERROR: Current HEAD does not match remote branch pointer. Skipping...\n"; continue; } // Get AuthorDate of latest commit this branch (Author instead of Commit) $headTimestamp = kfShellExec("git show HEAD --format='%at' -s"); print "Generating new archive...\n"; $archiveFilePathEscaped = kfEscapeShellArg($archiveFilePath); // Toolserver's git doesn't support --format='tar.gz', using 'tar' and piping to gzip instead $execOut = kfShellExec("git archive HEAD --format='tar' | gzip > {$archiveFilePathEscaped}");