[aur-dev] Added license search (fixed)
Hi, Thanks for the feedback. The rationale is to make it easier to find packages to adopt, or to find packages that can be moved. Best regards, Alexander Rødseth
Signed-off-by: Alexander Rødseth <rodseth@gmail.com> --- web/lib/pkgfuncs.inc.php | 49 ++++++++++++++++++++++++++++++++++++++ web/template/pkg_search_form.php | 21 ++++++++++++++++ 2 files changed, 70 insertions(+), 0 deletions(-) diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 3e89fa3..9a2074e 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -92,6 +92,40 @@ function pkgCategories($dbh=NULL) { return $cats; } +# grab the current list of distinct licenses +# +# "fromdb" is boolean and decides if the list of licenses +# should be fetched from the available licenses in the database +# or from a predefined list. Set to true or false here to make +# either one the default. Set to false if the database load is too high. +# +function package_licenses($dbh=NULL, $fromdb=true) { + $lics = array(); + if ($fromdb != false) { + if(!$dbh) { + $dbh = db_connect(); + } + $q = "SELECT DISTINCT License FROM Packages WHERE License != '' "; + $q.= "ORDER BY License ASC"; + $result = db_query($q, $dbh); + if ($result) { + while ($row = mysql_fetch_row($result)) { + $lics[] = $row[0]; + } + } + } else { + // All possible licenses from + // https://wiki.archlinux.org/index.php/PKGBUILD#license + $lics = array("AGPL", "AGPL3", "APACHE", "Apache", "Artistic2.0", + "BSD", "CCPL", "CDDL", "CPL", "custom", "EPL", "FDL", + "FDL1.2", "FDL1.3", "GPL", "GPL2", "GPL3", "LGPL", + "LGPL2.1", "LGPL3", "LPPL", "MIT", "MPL", "PHP", "PSF", + "PerlArtistic", "Python", "RUBY", "ZLIB", "ZPL"); + // sort($lics); + } + return $lics; +} + # check to see if the package name exists # function pkgid_from_name($name="", $dbh=NULL) { @@ -370,6 +404,9 @@ function package_details($id=0, $SID="", $dbh=NULL) { * s - package submitter's username * do_Orphans - boolean. whether to search packages * without a maintainer + * outdated - if the package is flagged: "on" or "off" + * license - the license ID, where 0 is "Any" + * license ID may change at any time * * * These two are actually handled in packages.php. @@ -396,6 +433,8 @@ function pkg_search_page($SID="", $dbh=NULL) { $myuid = uid_from_sid($SID, $dbh); // get a list of package categories $cats = pkgCategories($dbh); //meow + // get a list of licenses + $lics = package_licenses($dbh); // :-a // sanitize paging variables // @@ -494,6 +533,16 @@ function pkg_search_page($SID="", $dbh=NULL) { $q_where .= "AND OutOfDateTS IS NULL "; } } + + if (isset($_GET['license'])) { + // List ID ($lid) starts with 0 for "Any" and then enumerates the + // licenses from 1, which explains the "-1" below + $lid = intval($_GET["license"]); + if ($lid != 0) { + // Make the query select on licenses too + $q_where .= "AND Packages.License = '".$lics[$lid-1]."' "; + } + } $order = (isset($_GET["SO"]) && $_GET["SO"] == 'd') ? 'DESC' : 'ASC'; diff --git a/web/template/pkg_search_form.php b/web/template/pkg_search_form.php index 53d34fe..8c82859 100644 --- a/web/template/pkg_search_form.php +++ b/web/template/pkg_search_form.php @@ -119,6 +119,27 @@ ?> </select> </li> + <li> + <label><?php print __("License"); ?></label> + <select name='license'> + <option value='0'><?php print __("Any"); ?></option> + <?php + $lics = package_licenses(); + for($id = 0; $id < sizeof($lics); ++$id): + $lic = $lics[$id]; + // "Any" occupies slot 0 + $lid = $id+1; + if (isset($_REQUEST['license']) && $_REQUEST['license'] == $lid): + ?> + <option value="<?php print $lid ?>" selected="selected"><?php print $lic; ?></option> + <?php else: ?> + <option value="<?php print $lid ?>"><?php print $lic; ?></option> + <?php + endif; + endfor; + ?> + </select> + </li> </ul> </div> <?php endif; ?> -- 1.7.7
--- web/lib/pkgfuncs.inc.php | 36 ++++++++++-------------------------- web/template/pkg_search_form.php | 10 +++++----- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 9a2074e..83252d7 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -94,34 +94,18 @@ function pkgCategories($dbh=NULL) { # grab the current list of distinct licenses # -# "fromdb" is boolean and decides if the list of licenses -# should be fetched from the available licenses in the database -# or from a predefined list. Set to true or false here to make -# either one the default. Set to false if the database load is too high. -# -function package_licenses($dbh=NULL, $fromdb=true) { +function package_licenses($dbh=NULL) { $lics = array(); - if ($fromdb != false) { - if(!$dbh) { - $dbh = db_connect(); - } - $q = "SELECT DISTINCT License FROM Packages WHERE License != '' "; - $q.= "ORDER BY License ASC"; - $result = db_query($q, $dbh); - if ($result) { - while ($row = mysql_fetch_row($result)) { - $lics[] = $row[0]; - } + if(!$dbh) { + $dbh = db_connect(); + } + $q = "SELECT DISTINCT License FROM Packages WHERE License != '' "; + $q.= "ORDER BY License ASC"; + $result = db_query($q, $dbh); + if ($result) { + while ($row = mysql_fetch_row($result)) { + $lics[] = $row[0]; } - } else { - // All possible licenses from - // https://wiki.archlinux.org/index.php/PKGBUILD#license - $lics = array("AGPL", "AGPL3", "APACHE", "Apache", "Artistic2.0", - "BSD", "CCPL", "CDDL", "CPL", "custom", "EPL", "FDL", - "FDL1.2", "FDL1.3", "GPL", "GPL2", "GPL3", "LGPL", - "LGPL2.1", "LGPL3", "LPPL", "MIT", "MPL", "PHP", "PSF", - "PerlArtistic", "Python", "RUBY", "ZLIB", "ZPL"); - // sort($lics); } return $lics; } diff --git a/web/template/pkg_search_form.php b/web/template/pkg_search_form.php index 8c82859..c197fc3 100644 --- a/web/template/pkg_search_form.php +++ b/web/template/pkg_search_form.php @@ -125,18 +125,18 @@ <option value='0'><?php print __("Any"); ?></option> <?php $lics = package_licenses(); - for($id = 0; $id < sizeof($lics); ++$id): - $lic = $lics[$id]; + foreach (array_values($lics) as $id => $lic): // "Any" occupies slot 0 $lid = $id+1; + $license_description = htmlspecialchars($lic); if (isset($_REQUEST['license']) && $_REQUEST['license'] == $lid): ?> - <option value="<?php print $lid ?>" selected="selected"><?php print $lic; ?></option> + <option value="<?php print $lid ?>" selected="selected"><?php print $license_description; ?></option> <?php else: ?> - <option value="<?php print $lid ?>"><?php print $lic; ?></option> + <option value="<?php print $lid ?>"><?php print $license_description; ?></option> <?php endif; - endfor; + endforeach; ?> </select> </li> -- 1.7.7
On Mon, Oct 24, 2011 at 06:43:33PM +0200, Alexander Rødseth wrote:
Hi,
Thanks for the feedback. The rationale is to make it easier to find packages to adopt, or to find packages that can be moved.
Your patches look better now :) Thanks! A small tip for the future: You can submit an amended patch instead of sending a patch to your patch next time (in case of a single patch, just use `git commit --amend` when committing the fix). And it might be worthwhile to add a short comment to the patch (like the rationale in this case). I'll do this for you before pushing these patches. Anyway, since I never felt like I needed to search for a specific license, still a +/-0 from me. Anyone else?
Hi, Thanks for the review and tips for the future. I will try to create an amended patch next time the situation should arise. I will also remember to include a rationale. When it comes to the rationale itself, I can add that when finding packages that could be eligible for moving to [community], the license is an important factor. Lacking a license search function, the only available tool I know of would be "aurphan". While I like aurphan, it would be nice to be able to do a similar search through the web interface. In any case, if the feature is not needed, it's understandable. Stability and resistance to introduce new code or features is also a valuable feature for a piece of software. -- Cordially, Alexander Rødseth Arch Linux Trusted User (xyproto on IRC, trontonic on AUR)
participants (2)
-
Alexander Rødseth
-
Lukas Fleischer