Fail more gracefully for lower level users

git-svn-id: https://develop.svn.wordpress.org/trunk@1862 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg 2004-11-18 19:51:31 +00:00
parent 0e36c1f615
commit 20c979050f
3 changed files with 25 additions and 17 deletions

View File

@ -106,22 +106,26 @@ function dropdown_categories($default = 0) {
// Dandy new recursive multiple category stuff. // Dandy new recursive multiple category stuff.
function cat_rows($parent = 0, $level = 0, $categories = 0) { function cat_rows($parent = 0, $level = 0, $categories = 0) {
global $wpdb, $bgcolor; global $wpdb, $bgcolor, $user_level;
if (!$categories) { if (!$categories)
$categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name"); $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");
}
if ($categories) { if ($categories) {
foreach ($categories as $category) { foreach ($categories as $category) {
if ($category->category_parent == $parent) { if ($category->category_parent == $parent) {
$category->cat_name = htmlspecialchars($category->cat_name); $category->cat_name = htmlspecialchars($category->cat_name);
$count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID"); $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID");
$pad = str_repeat('— ', $level); $pad = str_repeat('— ', $level);
if ( $user_level > 3 )
$edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>" . __('Edit') . "</a></td><td><a href='categories.php?action=Delete&amp;cat_ID=$category->cat_ID' onclick=\"return confirm('". sprintf(__("You are about to delete the category \'%s\'. All of its posts will go to the default category.\\n \'OK\' to delete, \'Cancel\' to stop."), addslashes($category->cat_name)) . "')\" class='delete'>" . __('Delete') . "</a>";
else
$edit = '';
$class = ('alternate' == $class) ? '' : 'alternate'; $class = ('alternate' == $class) ? '' : 'alternate';
echo "<tr class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td> echo "<tr class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td>
<td>$category->category_description</td> <td>$category->category_description</td>
<td>$count</td> <td>$count</td>
<td><a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>" . __('Edit') . "</a></td><td><a href='categories.php?action=Delete&amp;cat_ID=$category->cat_ID' onclick=\"return confirm('". sprintf(__("You are about to delete the category \'%s\'. All of its posts will go to the default category.\\n \'OK\' to delete, \'Cancel\' to stop."), addslashes($category->cat_name)) . "')\" class='delete'>" . __('Delete') . "</a></td> <td>$edit</td>
</tr>"; </tr>";
cat_rows($category->cat_ID, $level + 1); cat_rows($category->cat_ID, $level + 1);
} }

View File

@ -112,10 +112,8 @@ break;
default: default:
require_once ('admin-header.php'); require_once ('admin-header.php');
if ($user_level < 3) {
die(sprintf(__("You have no right to edit the categories for this blog.<br />Ask for a promotion to your <a href='mailto:%s'>blog admin</a>. :)"), get_settings('admin_email')));
}
$messages[1] = __('Category added.'); $messages[1] = __('Category added.');
$messages[2] = __('Category deleted.'); $messages[2] = __('Category deleted.');
$messages[3] = __('Category updated.'); $messages[3] = __('Category updated.');
@ -126,7 +124,11 @@ $messages[3] = __('Category updated.');
<?php endif; ?> <?php endif; ?>
<div class="wrap"> <div class="wrap">
<h2><?php printf(__('Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2> <?php if ( $user_level > 3 ) : ?>
<h2><?php printf(__('Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2>
<?php else : ?>
<h2><?php _e('Categories') ?> </h2>
<?php endif; ?>
<table width="100%" cellpadding="3" cellspacing="3"> <table width="100%" cellpadding="3" cellspacing="3">
<tr> <tr>
<th scope="col"><?php _e('ID') ?></th> <th scope="col"><?php _e('ID') ?></th>
@ -142,6 +144,7 @@ cat_rows();
</div> </div>
<?php if ( $user_level > 3 ) : ?>
<div class="wrap"> <div class="wrap">
<p><?php printf(__('<strong>Note:</strong><br /> <p><?php printf(__('<strong>Note:</strong><br />
Deleting a category does not delete posts from that category, it will just Deleting a category does not delete posts from that category, it will just
@ -165,8 +168,9 @@ set them back to the default category <strong>%s</strong>.'), get_catname(1)) ?>
<p class="submit"><input type="hidden" name="action" value="addcat" /><input type="submit" name="submit" value="<?php _e('Add Category &raquo;') ?>" /></p> <p class="submit"><input type="hidden" name="action" value="addcat" /><input type="submit" name="submit" value="<?php _e('Add Category &raquo;') ?>" /></p>
</form> </form>
</div> </div>
<?php endif; ?>
<?php <?php
break; break;
} }

View File

@ -74,10 +74,6 @@ default:
require_once('admin-header.php'); require_once('admin-header.php');
if ($user_level <= 3) {
die(__('<p>Your level is not high enough to moderate comments.</p>'));
}
if (isset($deleted) || isset($approved) || isset($ignored)) { if (isset($deleted) || isset($approved) || isset($ignored)) {
echo "<div class='updated'>\n<p>"; echo "<div class='updated'>\n<p>";
if ($approved) { if ($approved) {
@ -107,8 +103,12 @@ if (isset($deleted) || isset($approved) || isset($ignored)) {
?> ?>
<div class="wrap"> <div class="wrap">
<?php <?php
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0'"); if ($user_level > 3)
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0'");
else
$comments = '';
if ($comments) { if ($comments) {
// list all comments that are waiting for approval // list all comments that are waiting for approval
@ -152,7 +152,7 @@ echo " <a href=\"post.php?action=deletecomment&amp;p=".$comment->comment_post_ID
<?php <?php
} else { } else {
// nothing to approve // nothing to approve
echo __("<p>Currently there are no comments to be approved.</p>") . "\n"; echo __("<p>Currently there are no comments for you to moderate.</p>") . "\n";
} }
?> ?>