[aur-dev] [PATCH 1/2] Use a separate function for "Required by" links
Do not use the same function for generating dependency and inverse dependency links. Instead, factor out common code and create two separate functions for those (rather different) functionalities. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/pkgfuncs.inc.php | 92 +++++++++++++++++++++++++++++++------------- web/template/pkg_details.php | 2 +- 2 files changed, 66 insertions(+), 28 deletions(-) diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index d83a01f..2939c25 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -239,6 +239,48 @@ function pkg_relations($pkgid) { } /** + * Get the HTML code to display a package dependency link annotation + * (dependency type, architecture, ...) + * + * @param string $type The name of the dependency type + * @param string $arch The package dependency architecture + * @param string $desc An optdepends description + * + * @return string The HTML code of the label to display + */ +function pkg_deplink_annotation($type, $arch, $desc=false) { + if ($type == 'depends' && !$arch) { + return ''; + } + + $link = ' <em>('; + + if ($type == 'makedepends') { + $link .= 'make'; + } elseif ($type == 'checkdepends') { + $link .= 'check'; + } elseif ($type == 'optdepends') { + $link .= 'optional'; + } + + if ($type != 'depends' && $arch) { + $link .= ', '; + } + + if ($arch) { + $link .= htmlspecialchars($arch); + } + + $link .= ')'; + if ($type == 'optdepends' && $desc) { + $link .= ' – ' . htmlspecialchars($desc) . ' </em>'; + } + $link .= '</em>'; + + return $link; +} + +/** * Get the HTML code to display a package dependency link * * @param string $name The name of the dependency @@ -246,11 +288,10 @@ function pkg_relations($pkgid) { * @param string $cond The package dependency condition string * @param string $arch The package dependency architecture * @param int $pkg_id The package of the package to display the dependency for - * @param bool $show_desc Whether the description of optdepends is shown * * @return string The HTML code of the label to display */ -function pkg_depend_link($name, $type, $cond, $arch, $pkg_id, $show_desc=true) { +function pkg_depend_link($name, $type, $cond, $arch, $pkg_id) { if ($type == 'optdepends' && strpos($name, ':') !== false) { $tokens = explode(':', $name, 2); $name = $tokens[0]; @@ -295,33 +336,30 @@ function pkg_depend_link($name, $type, $cond, $arch, $pkg_id, $show_desc=true) { $link .= htmlspecialchars($cond); } - if ($type != 'depends' || $arch) { - $link .= ' <em>('; - - if ($type == 'makedepends') { - $link .= 'make'; - } elseif ($type == 'checkdepends') { - $link .= 'check'; - } elseif ($type == 'optdepends') { - $link .= 'optional'; - } - - if ($type != 'depends' && $arch) { - $link .= ', '; - } - - if ($arch) { - $link .= htmlspecialchars($arch); - } + return $link . pkg_deplink_annotation($type, $arch, $desc); +} - $link .= ')'; - if ($show_desc && $type == 'optdepends') { - $link .= ' – ' . htmlspecialchars($desc) . ' </em>'; - } - $link .= '</em>'; +/** + * Get the HTML code to display a package requirement link + * + * @param string $name The name of the requirement + * @param string $type The name of the dependency type + * @param string $arch The package dependency architecture + * + * @return string The HTML code of the link to display + */ +function pkg_requiredby_link($name, $type, $arch) { + if ($type == 'optdepends' && strpos($name, ':') !== false) { + $tokens = explode(':', $name, 2); + $name = $tokens[0]; } - return $link; + $link = '<a href="'; + $link .= htmlspecialchars(get_pkg_uri($name), ENT_QUOTES); + $link .= '" title="' . __('View packages details for') .' ' . htmlspecialchars($name) . '">'; + $link .= htmlspecialchars($name) . '</a>'; + + return $link . pkg_deplink_annotation($type, $arch); } /** @@ -379,7 +417,7 @@ function pkg_required($name="") { $deps = array(); if ($name != "") { $dbh = DB::connect(); - $q = "SELECT p.Name, dt.Name, '' AS DepCondition, pd.DepArch, p.ID FROM PackageDepends pd "; + $q = "SELECT p.Name, dt.Name, pd.DepArch FROM PackageDepends pd "; $q.= "LEFT JOIN Packages p ON p.ID = pd.PackageID "; $q.= "LEFT JOIN DependencyTypes dt ON dt.ID = pd.DepTypeID "; $q.= "WHERE pd.DepName = " . $dbh->quote($name) . " "; diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 5ba3607..0a2d90e 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -285,7 +285,7 @@ endif; <?php if (count($requiredby) > 0): ?> <ul id="pkgreqslist"> <?php while (list($k, $darr) = each($requiredby)): ?> - <li><?= pkg_depend_link($darr[0], $darr[1], $darr[2], $darr[3], $darr[4], false); ?></li> + <li><?= pkg_requiredby_link($darr[0], $darr[1], $darr[2]); ?></li> <?php endwhile; ?> </ul> <?php endif; ?> -- 2.5.2
Implements FS#14125. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/pkgfuncs.inc.php | 31 ++++++++++++++++++++++++++----- web/template/pkg_details.php | 8 ++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 2939c25..b00b22d 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -343,12 +343,14 @@ function pkg_depend_link($name, $type, $cond, $arch, $pkg_id) { * Get the HTML code to display a package requirement link * * @param string $name The name of the requirement + * @param string $depends The (literal) name of the dependency of $name * @param string $type The name of the dependency type * @param string $arch The package dependency architecture + * @param string $pkgname The name of dependant package * * @return string The HTML code of the link to display */ -function pkg_requiredby_link($name, $type, $arch) { +function pkg_requiredby_link($name, $depends, $type, $arch, $pkgname) { if ($type == 'optdepends' && strpos($name, ':') !== false) { $tokens = explode(':', $name, 2); $name = $tokens[0]; @@ -359,6 +361,18 @@ function pkg_requiredby_link($name, $type, $arch) { $link .= '" title="' . __('View packages details for') .' ' . htmlspecialchars($name) . '">'; $link .= htmlspecialchars($name) . '</a>'; + if ($depends != $pkgname) { + $depname = $depends; + if (strpos($depends, ':') !== false) { + $tokens = explode(':', $depname, 2); + $depname = $tokens[0]; + } + + $link .= ' <span class="virtual-dep">('; + $link .= __('requires %s', htmlspecialchars($depname)); + $link .= ')</span>'; + } + return $link . pkg_deplink_annotation($type, $arch); } @@ -410,18 +424,25 @@ function pkg_source_link($url, $arch) { * Determine packages that depend on a package * * @param string $name The package name for the dependency search + * @param array $provides A list of virtual provisions of the package * * @return array All packages that depend on the specified package name */ -function pkg_required($name="") { +function pkg_required($name="", $provides) { $deps = array(); if ($name != "") { $dbh = DB::connect(); - $q = "SELECT p.Name, dt.Name, pd.DepArch FROM PackageDepends pd "; + + $name_list = $dbh->quote($name); + foreach ($provides as $p) { + $name_list .= ',' . $dbh->quote($p[0]); + } + + $q = "SELECT p.Name, pd.DepName, dt.Name, pd.DepArch FROM PackageDepends pd "; $q.= "LEFT JOIN Packages p ON p.ID = pd.PackageID "; $q.= "LEFT JOIN DependencyTypes dt ON dt.ID = pd.DepTypeID "; - $q.= "WHERE pd.DepName = " . $dbh->quote($name) . " "; - $q.= "OR SUBSTRING(pd.DepName FROM 1 FOR POSITION(': ' IN pd.DepName) - 1) = " . $dbh->quote($name) . " "; + $q.= "WHERE pd.DepName IN (" . $name_list . ") "; + $q.= "OR SUBSTRING(pd.DepName FROM 1 FOR POSITION(': ' IN pd.DepName) - 1) IN (" . $name_list . ") "; $q.= "ORDER BY p.Name"; $result = $dbh->query($q); if (!$result) {return array();} diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 0a2d90e..b9fd51b 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -40,9 +40,6 @@ $out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($ $lics = pkg_licenses($row["ID"]); $grps = pkg_groups($row["ID"]); -$deps = pkg_dependencies($row["ID"]); -$requiredby = pkg_required($row["Name"]); - usort($deps, function($x, $y) { if ($x[1] != $y[1]) { if ($x[1] == "depends") { @@ -83,6 +80,9 @@ foreach ($rels as $rel) { } } +$deps = pkg_dependencies($row["ID"]); +$requiredby = pkg_required($row["Name"], $rels_p); + # $sources[0] = 'src'; $sources = pkg_sources($row["ID"]); @@ -285,7 +285,7 @@ endif; <?php if (count($requiredby) > 0): ?> <ul id="pkgreqslist"> <?php while (list($k, $darr) = each($requiredby)): ?> - <li><?= pkg_requiredby_link($darr[0], $darr[1], $darr[2]); ?></li> + <li><?= pkg_requiredby_link($darr[0], $darr[1], $darr[2], $darr[3], $row['Name']); ?></li> <?php endwhile; ?> </ul> <?php endif; ?> -- 2.5.2
participants (1)
-
Lukas Fleischer