Skip to content

Commit

Permalink
Homepage|Build Repository: Format hyperlinks in commit titles
Browse files Browse the repository at this point in the history
When producing the commit log HTML doc also process hyperlinks in
commit titles (as well as the message body).

Also improved HTML processing so that "internal" links (i.e., other
URIs on the dengine.net host) are not marked with the "link-external"
CSS class.
  • Loading branch information
danij-deng committed Jun 15, 2012
1 parent 6fd0cee commit b43b470
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions web/plugins/buildrepository/commitutils.php
Expand Up @@ -22,6 +22,7 @@
includeGuard('commitutils.php');

require_once(DIR_INCLUDES.'/utilities.inc.php');
require_once(DIR_CLASSES.'/url.class.php');
require_once('buildevent.class.php');

function addCommitToGroup(&$groups, $groupName, &$commit)
Expand Down Expand Up @@ -67,18 +68,36 @@ function groupBuildCommits(&$build, &$groups)

function make_pretty_hyperlink($matches)
{
$uri = implode('', array_slice($matches, 1));
return generateHyperlinkHTML($uri, 40, 'link-external');
global $FrontController;

$uri = new Url(implode('', array_slice($matches, 1)));
$homeUri = new Url($FrontController->homeURL());

$isExternal = ($uri->host() !== $homeUri->host());
if(!$isExternal)
{
$uri->setScheme()->setHost();
}

return generateHyperlinkHTML($uri, 40, $isExternal? 'link-external' : NULL);
}

function formatCommitMessageHTML($msg)
function formatCommitHTML($msg)
{
if(strcasecmp(gettype($msg), 'string')) return $msg;

// Process the commit message, replacing web URIs with clickable links.
htmlspecialchars($msg);
$msg = preg_replace_callback("/([^A-z0-9])(http|ftp|https)([\:\/\/])([^\\s]+)/",
$msg = preg_replace_callback("/([^A-z0-9_])(http|ftp|https)([\:\/\/])([^\\s]+)/",
"make_pretty_hyperlink", $msg);
return $msg;
}

function formatCommitMessageHTML($msg)
{
if(strcasecmp(gettype($msg), 'string')) return $msg;

$msg = formatCommitHTML($msg);
$msg = nl2br($msg);
return $msg;
}
Expand All @@ -89,6 +108,7 @@ function outputCommitHTML(&$commit)
throw new Exception('Invalid commit argument, array expected');

// Format the commit message for HTML output.
$title = formatCommitHTML($commit['title']);
$message = formatCommitMessageHTML($commit['message']);
$haveMessage = (bool)(strlen($message) > 0);

Expand Down Expand Up @@ -116,7 +136,7 @@ function outputCommitHTML(&$commit)
// Ouput HTML for the commit.
?><span class="metadata"><a href="<?php echo $commit['repositoryUri']; ?>" class="link-external" title="<?php echo htmlspecialchars($repoLinkTitle); ?>"><?php echo htmlspecialchars(date('Y-m-d', $commit['submitDate'])); ?></a></span><?php

?><p class="heading <?php if($haveMessage) echo 'collapsible'; ?>" <?php if($haveMessage) echo 'title="Toggle commit message display"'; ?>><strong><span class="title"><?php echo htmlspecialchars($commit['title']); ?></span></strong> by <em><?php echo htmlspecialchars($commit['author']); ?></em></p><?php echo $tagList;
?><p class="heading <?php if($haveMessage) echo 'collapsible'; ?>" <?php if($haveMessage) echo 'title="Toggle commit message display"'; ?>><strong><span class="title"><?php echo $title; ?></span></strong> by <em><?php echo htmlspecialchars($commit['author']); ?></em></p><?php echo $tagList;

if($haveMessage)
{
Expand Down

0 comments on commit b43b470

Please sign in to comment.