summaryrefslogtreecommitdiff
path: root/web/lib/pkgfuncs.inc.php
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2015-09-13 17:54:36 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2015-09-16 22:00:04 +0200
commitf9476c10930029ca7a44a14b5e1749d36512880c (patch)
tree72ef3ef678e75396ac7be164047bb0b4524e3900 /web/lib/pkgfuncs.inc.php
parent209b0b6edad0c18a2ea14eac83c6c4787264aa63 (diff)
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>
Diffstat (limited to 'web/lib/pkgfuncs.inc.php')
-rw-r--r--web/lib/pkgfuncs.inc.php65
1 files changed, 59 insertions, 6 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index d760429..d83a01f 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -155,6 +155,33 @@ function pkg_groups($pkgid) {
}
/**
+ * 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
*
* @param int $pkgid The package to get dependencies for
@@ -232,15 +259,41 @@ function pkg_depend_link($name, $type, $cond, $arch, $pkg_id, $show_desc=true) {
$desc = '(unknown)';
}
- $link = '<a href="';
+ $providers = array();
if (is_null($pkg_id)) {
- $link .= 'https://www.archlinux.org/packages/?q=' . urlencode($name);
+ /*
+ * 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 .= htmlspecialchars(get_pkg_uri($name), ENT_QUOTES);
+ $link = '<a href="';
+ if (is_null($pkg_id)) {
+ $link .= 'https://www.archlinux.org/packages/?q=' . urlencode($name);
+ } else {
+ $link .= htmlspecialchars(get_pkg_uri($name), ENT_QUOTES);
+ }
+ $link .= '" title="' . __('View packages details for') .' ' . htmlspecialchars($name) . '">';
+ $link .= htmlspecialchars($name) . '</a>';
+ $link .= htmlspecialchars($cond);
}
- $link .= '" title="' . __('View packages details for') .' ' . htmlspecialchars($name) . '">';
- $link .= htmlspecialchars($name) . '</a>';
- $link .= htmlspecialchars($cond);
if ($type != 'depends' || $arch) {
$link .= ' <em>(';