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()); }
/** * Creates and formats a version line for a single extension. * * Information for five columns will be created. Parameters required in the * $extension array for part rendering are indicated in () * - The name of (name), and URL link to (url), the extension * - Official version number (version) and if available version control system * revision (path), link, and date * - If available the short name of the license (license-name) and a linke * to ((LICENSE)|(COPYING))(\.txt)? if it exists. * - Description of extension (descriptionmsg or description) * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists * * @param $extension Array * * @return string raw HTML */ function getCreditsForExtension(array $extension) { $out = $this->getOutput(); // We must obtain the information for all the bits and pieces! // ... such as extension names and links $extensionName = isset($extension['name']) ? $extension['name'] : '[no name]'; if (isset($extension['url'])) { $extensionNameLink = Linker::makeExternalLink($extension['url'], $extensionName, true, '', array('class' => 'mw-version-ext-name')); } else { $extensionNameLink = $extensionName; } // ... and the version information // If the extension path is set we will check that directory for GIT and SVN // metadata in an attempt to extract date and vcs commit metadata. $canonicalVersion = '–'; $extensionPath = null; $vcsVersion = null; $vcsLink = null; $vcsDate = null; if (isset($extension['version'])) { $canonicalVersion = $out->parseInline($extension['version']); } if (isset($extension['path'])) { $extensionPath = dirname($extension['path']); $gitInfo = new GitInfo($extensionPath); $vcsVersion = $gitInfo->getHeadSHA1(); if ($vcsVersion !== false) { $vcsVersion = substr($vcsVersion, 0, 7); $vcsLink = $gitInfo->getHeadViewUrl(); $vcsDate = $gitInfo->getHeadCommitDate(); } else { $svnInfo = self::getSvnInfo($extensionPath); if ($svnInfo !== false) { $vcsVersion = $this->msg('version-svn-revision', $svnInfo['checkout-rev'])->text(); $vcsLink = isset($svnInfo['viewvc-url']) ? $svnInfo['viewvc-url'] : ''; } } } $versionString = Html::rawElement('span', array('class' => 'mw-version-ext-version'), $canonicalVersion); if ($vcsVersion) { if ($vcsLink) { $vcsVerString = Linker::makeExternalLink($vcsLink, $this->msg('version-version', $vcsVersion), true, '', array('class' => 'mw-version-ext-vcs-version')); } else { $vcsVerString = Html::element('span', array('class' => 'mw-version-ext-vcs-version'), "({$vcsVersion})"); } $versionString .= " {$vcsVerString}"; if ($vcsDate) { $vcsTimeString = Html::element('span', array('class' => 'mw-version-ext-vcs-timestamp'), $this->getLanguage()->timeanddate($vcsDate)); $versionString .= " {$vcsTimeString}"; } $versionString = Html::rawElement('span', array('class' => 'mw-version-ext-meta-version'), $versionString); } // ... and license information; if a license file exists we // will link to it $licenseLink = ''; if (isset($extension['license-name'])) { $licenseLink = Linker::link($this->getPageTitle('License/' . $extensionName), $out->parseInline($extension['license-name']), array('class' => 'mw-version-ext-license')); } elseif ($this->getExtLicenseFileName($extensionPath)) { $licenseLink = Linker::link($this->getPageTitle('License/' . $extensionName), $this->msg('version-ext-license'), array('class' => 'mw-version-ext-license')); } // ... and generate the description; which can be a parameterized l10n message // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight // up string if (isset($extension['descriptionmsg'])) { // Localized description of extension $descriptionMsg = $extension['descriptionmsg']; if (is_array($descriptionMsg)) { $descriptionMsgKey = $descriptionMsg[0]; // Get the message key array_shift($descriptionMsg); // Shift out the message key to get the parameters only array_map("htmlspecialchars", $descriptionMsg); // For sanity $description = $this->msg($descriptionMsgKey, $descriptionMsg)->text(); } else { $description = $this->msg($descriptionMsg)->text(); } } elseif (isset($extension['description'])) { // Non localized version $description = $extension['description']; } else { $description = ''; } $description = $out->parseInline($description); // ... now get the authors for this extension $authors = isset($extension['author']) ? $extension['author'] : array(); $authors = $this->listAuthors($authors, $extensionName, $extensionPath); // Finally! Create the table $html = Html::openElement('tr', array('class' => 'mw-version-ext', 'id' => "mw-version-ext-{$extensionName}")); $html .= Html::rawElement('td', array(), $extensionNameLink); $html .= Html::rawElement('td', array(), $versionString); $html .= Html::rawElement('td', array(), $licenseLink); $html .= Html::rawElement('td', array('class' => 'mw-version-ext-description'), $description); $html .= Html::rawElement('td', array('class' => 'mw-version-ext-authors'), $authors); $html .= Html::closeElement('td'); return $html; }
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); }
/** * Creates and formats a version line for a single extension. * * Information for five columns will be created. Parameters required in the * $extension array for part rendering are indicated in () * - The name of (name), and URL link to (url), the extension * - Official version number (version) and if available version control system * revision (path), link, and date * - If available the short name of the license (license-name) and a link * to ((LICENSE)|(COPYING))(\.txt)? if it exists. * - Description of extension (descriptionmsg or description) * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists * * @param string $type Category name of the extension * @param array $extension * * @return string Raw HTML */ public function getCreditsForExtension($type, array $extension) { $out = $this->getOutput(); // We must obtain the information for all the bits and pieces! // ... such as extension names and links if (isset($extension['namemsg'])) { // Localized name of extension $extensionName = $this->msg($extension['namemsg'])->text(); } elseif (isset($extension['name'])) { // Non localized version $extensionName = $extension['name']; } else { $extensionName = $this->msg('version-no-ext-name')->text(); } if (isset($extension['url'])) { $extensionNameLink = Linker::makeExternalLink($extension['url'], $extensionName, true, '', ['class' => 'mw-version-ext-name']); } else { $extensionNameLink = $extensionName; } // ... and the version information // If the extension path is set we will check that directory for GIT // metadata in an attempt to extract date and vcs commit metadata. $canonicalVersion = '–'; $extensionPath = null; $vcsVersion = null; $vcsLink = null; $vcsDate = null; if (isset($extension['version'])) { $canonicalVersion = $out->parseInline($extension['version']); } if (isset($extension['path'])) { global $IP; $extensionPath = dirname($extension['path']); if ($this->coreId == '') { wfDebug('Looking up core head id'); $coreHeadSHA1 = self::getGitHeadSha1($IP); if ($coreHeadSHA1) { $this->coreId = $coreHeadSHA1; } } $cache = wfGetCache(CACHE_ANYTHING); $memcKey = wfMemcKey('specialversion-ext-version-text', $extension['path'], $this->coreId); list($vcsVersion, $vcsLink, $vcsDate) = $cache->get($memcKey); if (!$vcsVersion) { wfDebug("Getting VCS info for extension {$extension['name']}"); $gitInfo = new GitInfo($extensionPath); $vcsVersion = $gitInfo->getHeadSHA1(); if ($vcsVersion !== false) { $vcsVersion = substr($vcsVersion, 0, 7); $vcsLink = $gitInfo->getHeadViewUrl(); $vcsDate = $gitInfo->getHeadCommitDate(); } $cache->set($memcKey, [$vcsVersion, $vcsLink, $vcsDate], 60 * 60 * 24); } else { wfDebug("Pulled VCS info for extension {$extension['name']} from cache"); } } $versionString = Html::rawElement('span', ['class' => 'mw-version-ext-version'], $canonicalVersion); if ($vcsVersion) { if ($vcsLink) { $vcsVerString = Linker::makeExternalLink($vcsLink, $this->msg('version-version', $vcsVersion), true, '', ['class' => 'mw-version-ext-vcs-version']); } else { $vcsVerString = Html::element('span', ['class' => 'mw-version-ext-vcs-version'], "({$vcsVersion})"); } $versionString .= " {$vcsVerString}"; if ($vcsDate) { $vcsTimeString = Html::element('span', ['class' => 'mw-version-ext-vcs-timestamp'], $this->getLanguage()->timeanddate($vcsDate, true)); $versionString .= " {$vcsTimeString}"; } $versionString = Html::rawElement('span', ['class' => 'mw-version-ext-meta-version'], $versionString); } // ... and license information; if a license file exists we // will link to it $licenseLink = ''; if (isset($extension['name'])) { $licenseName = null; if (isset($extension['license-name'])) { $licenseName = $out->parseInline($extension['license-name']); } elseif ($this->getExtLicenseFileName($extensionPath)) { $licenseName = $this->msg('version-ext-license')->escaped(); } if ($licenseName !== null) { $licenseLink = Linker::link($this->getPageTitle('License/' . $extension['name']), $licenseName, ['class' => 'mw-version-ext-license', 'dir' => 'auto']); } } // ... and generate the description; which can be a parameterized l10n message // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight // up string if (isset($extension['descriptionmsg'])) { // Localized description of extension $descriptionMsg = $extension['descriptionmsg']; if (is_array($descriptionMsg)) { $descriptionMsgKey = $descriptionMsg[0]; // Get the message key array_shift($descriptionMsg); // Shift out the message key to get the parameters only array_map("htmlspecialchars", $descriptionMsg); // For sanity $description = $this->msg($descriptionMsgKey, $descriptionMsg)->text(); } else { $description = $this->msg($descriptionMsg)->text(); } } elseif (isset($extension['description'])) { // Non localized version $description = $extension['description']; } else { $description = ''; } $description = $out->parseInline($description); // ... now get the authors for this extension $authors = isset($extension['author']) ? $extension['author'] : []; $authors = $this->listAuthors($authors, $extension['name'], $extensionPath); // Finally! Create the table $html = Html::openElement('tr', ['class' => 'mw-version-ext', 'id' => Sanitizer::escapeId('mw-version-ext-' . $type . '-' . $extension['name'])]); $html .= Html::rawElement('td', [], $extensionNameLink); $html .= Html::rawElement('td', [], $versionString); $html .= Html::rawElement('td', [], $licenseLink); $html .= Html::rawElement('td', ['class' => 'mw-version-ext-description'], $description); $html .= Html::rawElement('td', ['class' => 'mw-version-ext-authors'], $authors); $html .= Html::closeElement('tr'); return $html; }
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); }
/** * Creates and formats the credits for a single extension and returns this. * * @param $extension Array * * @return string */ function getCreditsForExtension(array $extension) { global $wgLang; $name = isset($extension['name']) ? $extension['name'] : '[no name]'; $vcsText = false; if (isset($extension['path'])) { $gitInfo = new GitInfo(dirname($extension['path'])); $gitHeadSHA1 = $gitInfo->getHeadSHA1(); if ($gitHeadSHA1 !== false) { $vcsText = '(' . substr($gitHeadSHA1, 0, 7) . ')'; $gitViewerUrl = $gitInfo->getHeadViewUrl(); 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. if ($svnInfo !== false) { $directoryRev = isset($svnInfo['directory-rev']) ? $svnInfo['directory-rev'] : null; $vcsText = $this->msg('version-svn-revision', $directoryRev, $svnInfo['checkout-rev'])->text(); $vcsText = isset($svnInfo['viewvc-url']) ? '[' . $svnInfo['viewvc-url'] . " {$vcsText}]" : $vcsText; } } } # Make main link (or just the name if there is no URL). if (isset($extension['url'])) { $mainLink = "[{$extension['url']} {$name}]"; } else { $mainLink = $name; } if (isset($extension['version'])) { $versionText = '<span class="mw-version-ext-version">' . $this->msg('version-version', $extension['version'])->text() . '</span>'; } else { $versionText = ''; } # Make description text. $description = isset($extension['description']) ? $extension['description'] : ''; if (isset($extension['descriptionmsg'])) { # Look for a localized description. $descriptionMsg = $extension['descriptionmsg']; if (is_array($descriptionMsg)) { $descriptionMsgKey = $descriptionMsg[0]; // Get the message key array_shift($descriptionMsg); // Shift out the message key to get the parameters only array_map("htmlspecialchars", $descriptionMsg); // For sanity $description = $this->msg($descriptionMsgKey, $descriptionMsg)->text(); } else { $description = $this->msg($descriptionMsg)->text(); } } if ($vcsText !== false) { $extNameVer = "<tr>\n\t\t\t\t<td><em>{$mainLink} {$versionText}</em></td>\n\t\t\t\t<td><em>{$vcsText}</em></td>"; } else { $extNameVer = "<tr>\n\t\t\t\t<td colspan=\"2\"><em>{$mainLink} {$versionText}</em></td>"; } $author = isset($extension['author']) ? $extension['author'] : array(); $extDescAuthor = "<td>{$description}</td>\n\t\t\t<td>" . $this->listAuthors($author, false) . "</td>\n\t\t\t</tr>\n"; return $extNameVer . $extDescAuthor; }