Show providers in dependencies

For all "virtual provisions" in package dependencies, show links to the
actual packages providing the dependency.

This partly implements FS#14125.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2015-09-13 17:54:36 +02:00
parent 209b0b6eda
commit f9476c1093

View file

@ -154,6 +154,33 @@ function pkg_groups($pkgid) {
return $grps;
}
/**
* Get providers for a specific package
*
* @param string $name The name of the "package" to get providers for
*
* @return array The IDs and names of all providers of the package
*/
function pkg_providers($name) {
$dbh = DB::connect();
$q = "SELECT p.ID, p.Name FROM Packages p ";
$q.= "INNER JOIN PackageRelations pr ON pr.PackageID = p.ID ";
$q.= "INNER JOIN RelationTypes rt ON rt.ID = pr.RelTypeID ";
$q.= "WHERE rt.Name = 'provides' ";
$q.= "AND pr.RelName = " . $dbh->quote($name);
$result = $dbh->query($q);
if (!$result) {
return array();
}
$providers = array();
while ($row = $result->fetch(PDO::FETCH_NUM)) {
$providers[] = $row;
}
return $providers;
}
/**
* Get package dependencies for a specific package
*
@ -232,6 +259,31 @@ function pkg_depend_link($name, $type, $cond, $arch, $pkg_id, $show_desc=true) {
$desc = '(unknown)';
}
$providers = array();
if (is_null($pkg_id)) {
/*
* TODO: We currently perform one SQL query per nonexistent
* package dependency. It would be much better if we could
* annotate dependency data with providers so that we already
* know whether a dependency is a "provision name" or a package
* from the official repositories at this point.
*/
$providers = pkg_providers($name);
}
if (count($providers) > 0) {
$link = htmlspecialchars($name) . ' ';
$link .= '<span class="virtual-dep">(';
foreach ($providers as $provider) {
$name = $provider[1];
$link .= '<a href="';
$link .= htmlspecialchars(get_pkg_uri($name), ENT_QUOTES);
$link .= '" title="' . __('View packages details for') .' ' . htmlspecialchars($name) . '">';
$link .= htmlspecialchars($name) . '</a>, ';
}
$link = substr($link, 0, -2);
$link .= ')</span>';
} else {
$link = '<a href="';
if (is_null($pkg_id)) {
$link .= 'https://www.archlinux.org/packages/?q=' . urlencode($name);
@ -241,6 +293,7 @@ function pkg_depend_link($name, $type, $cond, $arch, $pkg_id, $show_desc=true) {
$link .= '" title="' . __('View packages details for') .' ' . htmlspecialchars($name) . '">';
$link .= htmlspecialchars($name) . '</a>';
$link .= htmlspecialchars($cond);
}
if ($type != 'depends' || $arch) {
$link .= ' <em>(';