Use virtual paths for package details

Extend the routing front/back ends to allow for using
"/package/$pkgname/" for individual packages.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2012-07-14 01:57:19 +02:00
parent 2425f963f8
commit 03486c3b6f
10 changed files with 40 additions and 15 deletions

View file

@ -5,8 +5,16 @@ include_once("config.inc.php");
include_once("routing.inc.php"); include_once("routing.inc.php");
$path = rtrim($_SERVER['PATH_INFO'], '/'); $path = rtrim($_SERVER['PATH_INFO'], '/');
$tokens = explode('/', $path);
if (get_route($path) !== NULL) { if (isset($tokens[1]) &&'/' . $tokens[1] == get_pkg_route()) {
if (isset($tokens[2])) {
unset($_GET['ID']);
$_GET['N'] = $tokens[2];
}
include get_route('/' . $tokens[1]);
} elseif (get_route($path) !== NULL) {
include get_route($path); include get_route($path);
} else { } else {
switch ($path) { switch ($path) {

View file

@ -400,7 +400,7 @@ if ($uid):
# Entire package creation process is atomic # Entire package creation process is atomic
end_atomic_commit($dbh); end_atomic_commit($dbh);
header('Location: ' . get_uri('/packages/') . '?ID=' . $packageID); header('Location: ' . get_pkg_uri($pkg_name));
} }
chdir($cwd); chdir($cwd);

View file

@ -15,7 +15,7 @@ if ($atype == 'Trusted User' || $atype== 'Developer'):
?> ?>
<div class="box"> <div class="box">
<h2>Votes for <a href="<?php echo get_uri('/packages/'); ?>?ID=<?php echo $pkgid ?>"><?php echo pkgname_from_id($pkgid) ?></a></h2> <h2>Votes for <a href="<?php echo get_pkg_uri(pkgname_from_id($pkgid)); ?>"><?php echo pkgname_from_id($pkgid) ?></a></h2>
<div class="boxbody"> <div class="boxbody">
<?php <?php

View file

@ -238,8 +238,7 @@ function add_package_comment($pkgid, $uid, $comment, $dbh=NULL) {
# Simply making these strings translatable won't work, users would be # Simply making these strings translatable won't work, users would be
# getting emails in the language that the user who posted the comment was in # getting emails in the language that the user who posted the comment was in
$body = $body =
'from ' . $AUR_LOCATION . '/' . get_uri('/packages/') . '?ID=' 'from ' . $AUR_LOCATION . '/' . get_pkg_uri($row['Name']) . "\n"
. $pkgid . "\n"
. username_from_sid($_COOKIE['AURSID'], $dbh) . " wrote:\n\n" . username_from_sid($_COOKIE['AURSID'], $dbh) . " wrote:\n\n"
. $comment . $comment
. "\n\n---\nIf you no longer wish to receive notifications about this package, please go the the above package page and click the UnNotify button."; . "\n\n---\nIf you no longer wish to receive notifications about this package, please go the the above package page and click the UnNotify button.";
@ -744,7 +743,7 @@ function pkg_flag ($atype, $ids, $action=true, $dbh=NULL) {
if (mysql_num_rows($result)) { if (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) { while ($row = mysql_fetch_assoc($result)) {
# construct email # construct email
$body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . " [1]. You may view your package at:\n" . $AUR_LOCATION . "/" . get_uri('/packages/') . "?ID=" . $row['ID'] . "\n\n[1] - " . $AUR_LOCATION . "/" . get_uri('/accounts/') . "?Action=AccountInfo&ID=" . $f_uid; $body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . " [1]. You may view your package at:\n" . $AUR_LOCATION . "/" . get_pkg_uri($row['Name']) . "\n\n[1] - " . $AUR_LOCATION . "/" . get_uri('/accounts/') . "?Action=AccountInfo&ID=" . $f_uid;
$body = wordwrap($body, 70); $body = wordwrap($body, 70);
$headers = "Reply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n"; $headers = "Reply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n";
@mail($row['Email'], "AUR Out-of-date Notification for ".$row['Name'], $body, $headers); @mail($row['Email'], "AUR Out-of-date Notification for ".$row['Name'], $body, $headers);
@ -813,7 +812,7 @@ function pkg_delete ($atype, $ids, $mergepkgid, $dbh=NULL) {
$body = ""; $body = "";
if ($mergepkgid) { if ($mergepkgid) {
$body .= username_from_sid($_COOKIE['AURSID']) . " merged \"".$pkgname."\" into \"$mergepkgname\".\n\n"; $body .= username_from_sid($_COOKIE['AURSID']) . " merged \"".$pkgname."\" into \"$mergepkgname\".\n\n";
$body .= "You will no longer receive notifications about this package, please go to https://aur.archlinux.org/" . get_uri('/packages/') . "?ID=".$mergepkgid." and click the Notify button if you wish to recieve them again."; $body .= "You will no longer receive notifications about this package, please go to https://aur.archlinux.org/" . get_pkg_uri($mergepkgname) . " and click the Notify button if you wish to recieve them again.";
} else { } else {
$body .= username_from_sid($_COOKIE['AURSID']) . " deleted \"".$pkgname."\".\n\n"; $body .= username_from_sid($_COOKIE['AURSID']) . " deleted \"".$pkgname."\".\n\n";
$body .= "You will no longer receive notifications about this package."; $body .= "You will no longer receive notifications about this package.";

View file

@ -17,6 +17,8 @@ $ROUTES = array(
'/addvote' => 'addvote.php', '/addvote' => 'addvote.php',
); );
$PKG_PATH = '/packages';
function get_route($path) { function get_route($path) {
global $ROUTES; global $ROUTES;
@ -37,3 +39,19 @@ function get_uri($path) {
return get_route($path); return get_route($path);
} }
} }
function get_pkg_route() {
global $PKG_PATH;
return $PKG_PATH;
}
function get_pkg_uri($pkgname) {
global $USE_VIRTUAL_URLS;
global $PKG_PATH;
if ($USE_VIRTUAL_URLS) {
return $PKG_PATH . '/' . urlencode($pkgname) . '/';
} else {
return get_route($PKG_PATH) . '?N=' . urlencode($pkgname);
}
}

View file

@ -1,5 +1,5 @@
<div class="box"> <div class="box">
<form action="<?php echo get_uri('/packages/'); ?>?ID=<?php echo $row['ID'] ?>" method="post"> <form action="<?php echo htmlspecialchars(get_pkg_uri($row['Name']), ENT_QUOTES); ?>" method="post">
<fieldset> <fieldset>
<input type="hidden" name="IDs[<?php echo $row['ID'] ?>]" value="1" /> <input type="hidden" name="IDs[<?php echo $row['ID'] ?>]" value="1" />
<input type="hidden" name="ID" value="<?php echo $row['ID'] ?>" /> <input type="hidden" name="ID" value="<?php echo $row['ID'] ?>" />

View file

@ -4,7 +4,7 @@ $count = package_comments_count($_GET['ID']);
?> ?>
<div id="news"> <div id="news">
<h3> <h3>
<a href="<?php echo htmlentities($_SERVER['REQUEST_URI'], ENT_QUOTES) ?>&amp;comments=all" title="<?php echo __('View all %s comments' , $count) ?>"><?php echo __('Latest Comments') ?></a> <a href="<?php echo htmlentities($_SERVER['REQUEST_URI'], ENT_QUOTES) ?>?comments=all" title="<?php echo __('View all %s comments' , $count) ?>"><?php echo __('Latest Comments') ?></a>
<span class="arrow"></span> <span class="arrow"></span>
</h3> </h3>
@ -14,7 +14,7 @@ $count = package_comments_count($_GET['ID']);
endif; ?> endif; ?>
<h4> <h4>
<?php if (canDeleteCommentArray($row, $atype, $uid)): ?> <?php if (canDeleteCommentArray($row, $atype, $uid)): ?>
<form method="post" action="<?php echo get_uri('/packages/'); ?>?ID=<?php echo $row['ID'] ?>"> <form method="post" action="<?php echo htmlspecialchars(get_pkg_uri($row['Name']), ENT_QUOTES); ?>">
<fieldset style="display:inline;"> <fieldset style="display:inline;">
<input type="hidden" name="action" value="do_DeleteComment" /> <input type="hidden" name="action" value="do_DeleteComment" />
<input type="hidden" name="comment_id" value="<?php echo $row['ID'] ?>" /> <input type="hidden" name="comment_id" value="<?php echo $row['ID'] ?>" />

View file

@ -57,7 +57,7 @@ if ($SID && ($uid == $row["MaintainerUID"] ||
($atype == "Developer" || $atype == "Trusted User"))): ($atype == "Developer" || $atype == "Trusted User"))):
?> ?>
<td> <td>
<form method="post" action="<?php echo get_uri('/packages/'); ?>?ID=<?php echo $pkgid ?>"> <form method="post" action="<?php echo htmlspecialchars(get_pkg_uri($row['Name']), ENT_QUOTES); ?>">
<div> <div>
<input type="hidden" name="action" value="do_ChangeCategory" /> <input type="hidden" name="action" value="do_ChangeCategory" />
<?php if ($SID): ?> <?php if ($SID): ?>
@ -139,7 +139,7 @@ if ($atype == "Developer" || $atype == "Trusted User"):
# darr: (DepName, DepCondition, PackageID), where ID is NULL if it didn't exist # darr: (DepName, DepCondition, PackageID), where ID is NULL if it didn't exist
if (!is_null($darr[2])): if (!is_null($darr[2])):
?> ?>
<li><a href="<?php echo get_uri('/packages/'); ?>?ID=<?php echo $darr[2]?>" title="<?php echo __('View packages details for').' '.$darr[0].$darr[1]?>"><?php echo $darr[0].$darr[1]?></a></li> <li><a href="<?php echo htmlspecialchars(get_pkg_uri($darr[0]), ENT_QUOTES); ?>" title="<?php echo __('View packages details for').' '.$darr[0].$darr[1]?>"><?php echo $darr[0].$darr[1]?></a></li>
<?php else: ?> <?php else: ?>
<li><a href="http://www.archlinux.org/packages/?q=<?php echo urlencode($darr[0])?>" title="<?php echo __('View packages details for').' '.$darr[0].$darr[1] ?>"><?php echo $darr[0].$darr[1] ?></a></li> <li><a href="http://www.archlinux.org/packages/?q=<?php echo urlencode($darr[0])?>" title="<?php echo __('View packages details for').' '.$darr[0].$darr[1] ?>"><?php echo $darr[0].$darr[1] ?></a></li>
<?php endif; ?> <?php endif; ?>
@ -155,7 +155,7 @@ if ($atype == "Developer" || $atype == "Trusted User"):
# darr: (PackageName, PackageID) # darr: (PackageName, PackageID)
while (list($k, $darr) = each($requiredby)): while (list($k, $darr) = each($requiredby)):
?> ?>
<li><a href="<?php echo get_uri('/packages/'); ?>?ID=<?php echo $darr[1] ?>" title="<?php echo __('View packages details for').' '.$darr[0]?>"><?php echo $darr[0] ?></a></li> <li><a href="<?php echo htmlspecialchars(get_pkg_uri($darr[0]), ENT_QUOTES); ?>" title="<?php echo __('View packages details for').' '.$darr[0]?>"><?php echo $darr[0] ?></a></li>
<?php endwhile; ?> <?php endwhile; ?>
</ul> </ul>
<?php endif; ?> <?php endif; ?>

View file

@ -52,7 +52,7 @@ if (!$result): ?>
<td><input type="checkbox" name="IDs[<?php echo $row["ID"] ?>]" value="1" /></td> <td><input type="checkbox" name="IDs[<?php echo $row["ID"] ?>]" value="1" /></td>
<?php endif; ?> <?php endif; ?>
<td><?php echo htmlspecialchars($row["Category"]) ?></td> <td><?php echo htmlspecialchars($row["Category"]) ?></td>
<td><a href="<?php echo get_uri('/packages/'); ?>?ID=<?php echo $row["ID"] ?>"><?php echo htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]) ?></a></td> <td><a href="<?php echo htmlspecialchars(get_pkg_uri($row["Name"]), ENT_QUOTES); ?>"><?php echo htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]) ?></a></td>
<td><?php echo $row["NumVotes"] ?></td> <td><?php echo $row["NumVotes"] ?></td>
<?php if ($SID): ?> <?php if ($SID): ?>
<td> <td>

View file

@ -6,7 +6,7 @@
<?php foreach ($newest_packages->getIterator() as $row): ?> <?php foreach ($newest_packages->getIterator() as $row): ?>
<tr> <tr>
<td> <td>
<a href="<?php echo get_uri('/packages/'); ?>?ID=<?php print intval($row["ID"]); ?>"><?php print htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?></a> <a href="<?php echo get_pkg_uri($row["Name"]); ?>"><?php print htmlspecialchars($row["Name"]) . ' ' . htmlspecialchars($row["Version"]); ?></a>
</td> </td>
<td> <td>
<span><?php print gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span> <span><?php print gmdate("Y-m-d H:i", intval($row["ModifiedTS"])); ?></span>