Revision [10213]
This is an old revision of UserAdmin made by DarTar on 2005-07-25 15:48:10.
User Administration Module
I've started writing some code for a user administration module. I think this might be interesting for wikka-based projects with a large number of registered users.
This action will enable Wikka administrators (or, in the future, users belonging to an Admin group) to have access to several user management functions from a single page:
- Display a pageable, sortable and searchable list of registered users -- done;
- Perform specific actions on single users, like:
- delete users (forthcoming: see this RemovingUsers discussion);
- add users - in case the registration of a page is turned off, but you want to add a user
- noted, good idea -- DarTar
- send user feedback -- done;
- rename users
- If anyone is interested, running through the seven tables and updating every instance of your old wiki name to your new wiki name will effectively change your name throughout the wiki. copied from comment on the homepage. --NilsLindenberg
- manage user privileges (forthcoming);
- Display user's owned pages -- done;
- Display user's comments -- done.
- Display user's changes -- done;
- other...
The code below must be saved as actions/useradmin.php and used as {{useradmin}}.
Here's a preview of the interface (email addresses are masked for privacy reasons)
User Administration
Name | Signup Time | Signup IP | O | E | C | Actions | ||
---|---|---|---|---|---|---|---|---|
BaW | badasswright@xxxx.xx | 2005-07-24 19:17:39 | XXX.XXX.XXX.XXX | |||||
Cride5 | evil@xxxx.xx | 2005-07-24 16:51:32 | XXX.XXX.XXX.XXX | |||||
SimonSchlachter | wikka.*.simschla@xxxx.xx | 2005-07-24 14:05:12 | XXX.XXX.XXX.XXX | |||||
AndreasDether | tomparis@xxxx.xx | 2005-07-23 15:53:34 | XXX.XXX.XXX.XXX | |||||
AlexHazlewood | alex@xxxx.xx | 2005-07-23 15:38:09 | XXX.XXX.XXX.XXX | |||||
ZielGruppe | pajoma@xxxx.xx | 2005-07-23 14:43:53 | XXX.XXX.XXX.XXX | |||||
DorTor | dartar@xxxx.xx | 2005-07-22 21:32:13 | XXX.XXX.XXX.XXX | |||||
TechnoSight | ken@xxxx.xx | 2005-07-22 16:10:02 | XXX.XXX.XXX.XXX | |||||
SaBreyn | sabbyart@xxxx.xx | 2005-07-21 22:20:08 | XXX.XXX.XXX.XXX | |||||
KaihuaWang | KaihuaWang@xxxx.xx | 2005-07-21 02:36:18 | XXX.XXX.XXX.XXX |
Current features (2005-07-25):
- users can be sorted by different fields (click on table header to reverse sort order), searched and paged;
- if the current user is not an administrator, then the lastuser.php action is displayed
- feedback can be sent to single users.
- displays pages owned by each user.
- displays pages changed by each user.
- displays pages commented by each user.
- added extra column for beta feature (Signup IP) installed on this server.
- Note - if you want to test the code below with the standard Wikka tables, you'll have to remove the lines marked with the [remove this line] comment.
Files needed (2004-09-16):
- actions/useradmin.php: see code on this page;
- FeedbackActionUpgrade actions/userfeedback.php (enhanced version of FeedbackAction); 2005-04-18 - action parameter support added
- UserPagesAction actions/userpages.php (enhanced version of mypages.php);2005-04-18 - action parameter support added
- UserChangesAction actions/userchanges.php (enhanced version of mychanges.php); 2005-04-18 - action parameter support added
- UserCommentsAction actions/usercomments.php (new action); 2004-11-23 - RewriteRules bug fixed
actions/useradmin.php
<?php
/**
* Display a module for user management.
*
* This action allows admins to display information on registered users.
* Users can be searched, paged, filtered. User-related statistics are given,
* showing the number of commented, created and modified pages. A feedback
* handler allows admins to send an email to single users. If the current user
* is not an administrator, then the lastuser action is displayed instead.
*
* @package Actions
* @name Useradmin
*
* @author {@link http://wikka.jsnx.com/DarTar Dario Taraborelli}
* @version 1.1
* @since Wikka 1.1.X.X
* @output user data table
*
* @todo
* - mass-operations;
* - deleting/banning users;
* - sanitize code;
* - integrate with other admin modules.
*/
// admin only code
if ($this->IsAdmin($this->GetUser())) {
// set default values as constants
define('DEFAULT_RECORDS_LIMIT', '20'); # number of records per page
define('DEFAULT_REC_LIMIT_STEP', '10'); # step for selectable records limit
define('DEFAULT_SORT_FIELD', 'signuptime'); # sort field
define('DEFAULT_SORT_ORDER', 'desc'); # sort order, ascendant or descendant
define('DEFAULT_START', '0'); # start record
define('DEFAULT_SEARCH', ''); # keyword to restrict page search
if ($_GET['action'] == 'feedback' || $_REQUEST['mail']) {
echo $this->Action('userfeedback');
} else if ($_GET['action'] == 'owned') {
echo $this->Action('userpages');
} else if ($_GET['action'] == 'changes') {
echo $this->Action('userchanges');
} else if ($_GET['action'] == 'comments') {
echo $this->Action('usercomments');
} else {
// pager defaults
// limit records per page
if (isset($_POST['l']))
$l = $_POST['l'];
elseif (isset($_GET['l']))
$l = $_GET['l'];
else
$l = DEFAULT_RECORDS_LIMIT;
// sort field
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : DEFAULT_SORT_FIELD;
// sort order
$d = (isset($_GET['d'])) ? $_GET['d'] : DEFAULT_SORT_ORDER;
// start record
$s = (isset($_GET['s'])) ? $_GET['s'] : DEFAULT_START;
// search field
if (isset($_POST['q']))
$q = $_POST['q'];
elseif (isset($_GET['q']))
$q = $_GET['q'];
else
$q = DEFAULT_SEARCH;
// select all
$checked = '';
if (isset($_GET['selectall']))
{
$checked = (1 == $_GET['selectall']) ? ' checked="checked"' : '';
}
// search results
$where = ('' == $q) ? "1" : "`name` LIKE '%".$q."%'";
echo $this->Format('==== User Administration ==== --- ---');
// 1. Get total number of users
$numusers = $this->getCount('users', $where);
// 2. Display pager form
$form = $this->FormOpen('','','post');
$form .= '<div style="float:left; margin-top:10px; margin-bottom:10px; padding:10px; border:1px dotted #AAA; background-color:#EEE; line-height:.9em">';
$form .='<p>Search user: <input type ="text" title="Enter a search string" name="q" size="20" maxlength="50" value="'.$q.'"/><input type="submit" value="Submit" /></p>';
$form .= '<p>Show <select name="l" title="Select records-per-page limit">';
for ($rec=DEFAULT_REC_LIMIT_STEP; $rec < ($numusers+DEFAULT_REC_LIMIT_STEP); $rec+=DEFAULT_REC_LIMIT_STEP) {
$selected = ($l == $rec)? 'selected' : '';
$form .= '<option value="'.$rec.'" '.$selected.'>'.$rec.'</option>';
}
$form .= '</select> records per page <input type="submit" value="Apply" /></p';
// build pager links
$prev = '';
$next = '';
if ($s > 0)
$prev = '<a href="' .$this->Href('','','l='.$l.'&sort='.$sort.'&d='.$d.'&s='.($s-$l)).'&q='.$q.'" title="Show records from '.($s-$l+1).' to '.$s.'">'.($s-$l+1).'-'.$s.'</a> | ';
if ($numusers > ($s + $l))
$next = ' | <a href="'.$this->Href('','','l='.$l.'&sort='.$sort.'&d='.$d.'&s='.($s+$l)).'&q='.$q.'" title="Show records from '.($s+$l+1).' to '.($s+2*$l).'">'.($s+$l+1).'-'.($s+2*$l).'</a>';
$form .= '<p>[Records ('.$numusers.'): '.$prev.'<strong>'.($s+1).'-'.($s+$l).'</strong>'.$next.' (sorted by: <em>'.$sort.', '.$d.'</em> )]</p>';
$form .= '</div>'.$this->FormClose();
echo $form;
// get user list
$userdata = $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."users WHERE ".
$where." ORDER BY ".$sort." ".$d." limit ".$s.", ".$l);
if ($userdata) {
// build table headers
$nameheader = '<a href="'.$this->Href('','', (($sort == 'name' && $d == 'asc')? 'l='.$l.'&sort=name&d=desc' : 'l='.$l.'&sort=name&d=asc')).'" title="Sort by user name">Name</a>';
$emailheader = '<a href="'.$this->Href('','', (($sort == 'email' && $d == 'asc')? 'l='.$l.'&sort=email&d=desc' : 'l='.$l.'&sort=email&d=asc')).'" title="Sort by email">Email</a>';
$timeheader = '<a href="'.$this->Href('','', (($sort == 'signuptime' && $d == 'desc')? 'l='.$l.'&sort=signuptime&d=asc' : 'l='.$l.'')).'" title="Sort by signup time">Signup Time</a>';
$ipheader = '<a href="'.$this->Href('','', (($sort == 'ipaddress' && $d == 'desc')? 'l='.$l.'&sort=ipaddress&d=asc' : 'l='.$l.'&sort=ipaddress&d=desc')).'" title="Sort by signup IP">Signup IP</a>';
// print table headers
$htmlout = "<div class=\"pagedata\" style=\"clear:both\">\n<table id=\"compare\" width=\"100%\" border=\"1px\">\n<thead>\n".
" <tr>\n".
" <th> </th>\n".
" <th>".$nameheader."</th>\n".
" <th>".$emailheader."</th>\n".
" <th>".$timeheader."</th>\n".
" <th>".$ipheader."</th>\n". #[remove this line if you are using standard Wikka tables]
" <th title=\"Owned pages\" abbr=\"Owned pages\">O</th>\n".
" <th title=\"Page edits\" abbr=\"Page edits\">E</th>\n".
" <th title=\"Comments\" abbr=\"Comments\">C</th>\n".
" <th>Actions</th>\n".
" </tr>\n</thead>\n";
// print user table
foreach($userdata as $user) {
// get counts
$where_owned = "`owner` = '".$user['name']."' AND latest = 'Y'";
$where_changes = "`user` = '".$user['name']."'";
$where_comments = "`user` = '".$user['name']."'";
$numowned = $this->getCount('pages', $where_owned);
$numchanges = $this->getCount('pages', $where_changes);
$numcomments = $this->getCount('comments', $where_comments);
// build statistics links if needed
$ownedlink = ($numowned > 0)? '<a title="Display pages owned by '.$user['name'].'" href="'.$this->Href('','','user='.$user['name'].'&action=owned').'">'.$numowned.'</a>' : '0';
$changeslink = ($numchanges > 0)? '<a title="Display page edits by '.$user['name'].'" href="'.$this->Href('','','user='.$user['name'].'&action=changes').'">'.$numchanges.'</a>' : '0';
$commentslink = ($numcomments > 0)? '<a title="Display comments by '.$user['name'].'" href="'.$this->Href('','','user='.$user['name'].'&action=comments').'">'.$numcomments.'</a>' : '0';
$htmlout .= "<tbody>\n <tr>\n".
" <td><input type=\"checkbox\" id=\"".$user['id']."\"".$checked." title=\"Select ".$user['name']."\"/></td>\n".
" <td>".$this->Link($user['name'])."</td>\n".
" <td>".$user['email']."</td>\n".
" <td class=\"time\">".$user['signuptime']."</td>\n".
" <td>".$user['ipaddress']."</td>\n". #[remove this line if you are using standard Wikka tables]
" <td><center />".$ownedlink."</td>\n".
" <td><center />".$changeslink."</td>\n".
" <td><center />".$commentslink."</td>\n".
" <td><center />delete :: <a title=\"Send feedback to ".$user['name']."\" href=\"".$this->Href('','','user='.$user['name'].'&action=feedback')."\">feedback</a></td>\n";
$htmlout .= " </tr>\n</tbody>\n";
}
$htmlout .= "</table>\n</div>\n";
echo $htmlout;
} else {
echo "<p><span class=\"error\">Sorry, there are no users matching</span> <strong>\"".$_POST["search"]."\"</strong></p>";
}
}
} else {
// user is not admin
echo $this->Action("lastusers");
}
?>
/**
* Display a module for user management.
*
* This action allows admins to display information on registered users.
* Users can be searched, paged, filtered. User-related statistics are given,
* showing the number of commented, created and modified pages. A feedback
* handler allows admins to send an email to single users. If the current user
* is not an administrator, then the lastuser action is displayed instead.
*
* @package Actions
* @name Useradmin
*
* @author {@link http://wikka.jsnx.com/DarTar Dario Taraborelli}
* @version 1.1
* @since Wikka 1.1.X.X
* @output user data table
*
* @todo
* - mass-operations;
* - deleting/banning users;
* - sanitize code;
* - integrate with other admin modules.
*/
// admin only code
if ($this->IsAdmin($this->GetUser())) {
// set default values as constants
define('DEFAULT_RECORDS_LIMIT', '20'); # number of records per page
define('DEFAULT_REC_LIMIT_STEP', '10'); # step for selectable records limit
define('DEFAULT_SORT_FIELD', 'signuptime'); # sort field
define('DEFAULT_SORT_ORDER', 'desc'); # sort order, ascendant or descendant
define('DEFAULT_START', '0'); # start record
define('DEFAULT_SEARCH', ''); # keyword to restrict page search
if ($_GET['action'] == 'feedback' || $_REQUEST['mail']) {
echo $this->Action('userfeedback');
} else if ($_GET['action'] == 'owned') {
echo $this->Action('userpages');
} else if ($_GET['action'] == 'changes') {
echo $this->Action('userchanges');
} else if ($_GET['action'] == 'comments') {
echo $this->Action('usercomments');
} else {
// pager defaults
// limit records per page
if (isset($_POST['l']))
$l = $_POST['l'];
elseif (isset($_GET['l']))
$l = $_GET['l'];
else
$l = DEFAULT_RECORDS_LIMIT;
// sort field
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : DEFAULT_SORT_FIELD;
// sort order
$d = (isset($_GET['d'])) ? $_GET['d'] : DEFAULT_SORT_ORDER;
// start record
$s = (isset($_GET['s'])) ? $_GET['s'] : DEFAULT_START;
// search field
if (isset($_POST['q']))
$q = $_POST['q'];
elseif (isset($_GET['q']))
$q = $_GET['q'];
else
$q = DEFAULT_SEARCH;
// select all
$checked = '';
if (isset($_GET['selectall']))
{
$checked = (1 == $_GET['selectall']) ? ' checked="checked"' : '';
}
// search results
$where = ('' == $q) ? "1" : "`name` LIKE '%".$q."%'";
echo $this->Format('==== User Administration ==== --- ---');
// 1. Get total number of users
$numusers = $this->getCount('users', $where);
// 2. Display pager form
$form = $this->FormOpen('','','post');
$form .= '<div style="float:left; margin-top:10px; margin-bottom:10px; padding:10px; border:1px dotted #AAA; background-color:#EEE; line-height:.9em">';
$form .='<p>Search user: <input type ="text" title="Enter a search string" name="q" size="20" maxlength="50" value="'.$q.'"/><input type="submit" value="Submit" /></p>';
$form .= '<p>Show <select name="l" title="Select records-per-page limit">';
for ($rec=DEFAULT_REC_LIMIT_STEP; $rec < ($numusers+DEFAULT_REC_LIMIT_STEP); $rec+=DEFAULT_REC_LIMIT_STEP) {
$selected = ($l == $rec)? 'selected' : '';
$form .= '<option value="'.$rec.'" '.$selected.'>'.$rec.'</option>';
}
$form .= '</select> records per page <input type="submit" value="Apply" /></p';
// build pager links
$prev = '';
$next = '';
if ($s > 0)
$prev = '<a href="' .$this->Href('','','l='.$l.'&sort='.$sort.'&d='.$d.'&s='.($s-$l)).'&q='.$q.'" title="Show records from '.($s-$l+1).' to '.$s.'">'.($s-$l+1).'-'.$s.'</a> | ';
if ($numusers > ($s + $l))
$next = ' | <a href="'.$this->Href('','','l='.$l.'&sort='.$sort.'&d='.$d.'&s='.($s+$l)).'&q='.$q.'" title="Show records from '.($s+$l+1).' to '.($s+2*$l).'">'.($s+$l+1).'-'.($s+2*$l).'</a>';
$form .= '<p>[Records ('.$numusers.'): '.$prev.'<strong>'.($s+1).'-'.($s+$l).'</strong>'.$next.' (sorted by: <em>'.$sort.', '.$d.'</em> )]</p>';
$form .= '</div>'.$this->FormClose();
echo $form;
// get user list
$userdata = $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."users WHERE ".
$where." ORDER BY ".$sort." ".$d." limit ".$s.", ".$l);
if ($userdata) {
// build table headers
$nameheader = '<a href="'.$this->Href('','', (($sort == 'name' && $d == 'asc')? 'l='.$l.'&sort=name&d=desc' : 'l='.$l.'&sort=name&d=asc')).'" title="Sort by user name">Name</a>';
$emailheader = '<a href="'.$this->Href('','', (($sort == 'email' && $d == 'asc')? 'l='.$l.'&sort=email&d=desc' : 'l='.$l.'&sort=email&d=asc')).'" title="Sort by email">Email</a>';
$timeheader = '<a href="'.$this->Href('','', (($sort == 'signuptime' && $d == 'desc')? 'l='.$l.'&sort=signuptime&d=asc' : 'l='.$l.'')).'" title="Sort by signup time">Signup Time</a>';
$ipheader = '<a href="'.$this->Href('','', (($sort == 'ipaddress' && $d == 'desc')? 'l='.$l.'&sort=ipaddress&d=asc' : 'l='.$l.'&sort=ipaddress&d=desc')).'" title="Sort by signup IP">Signup IP</a>';
// print table headers
$htmlout = "<div class=\"pagedata\" style=\"clear:both\">\n<table id=\"compare\" width=\"100%\" border=\"1px\">\n<thead>\n".
" <tr>\n".
" <th> </th>\n".
" <th>".$nameheader."</th>\n".
" <th>".$emailheader."</th>\n".
" <th>".$timeheader."</th>\n".
" <th>".$ipheader."</th>\n". #[remove this line if you are using standard Wikka tables]
" <th title=\"Owned pages\" abbr=\"Owned pages\">O</th>\n".
" <th title=\"Page edits\" abbr=\"Page edits\">E</th>\n".
" <th title=\"Comments\" abbr=\"Comments\">C</th>\n".
" <th>Actions</th>\n".
" </tr>\n</thead>\n";
// print user table
foreach($userdata as $user) {
// get counts
$where_owned = "`owner` = '".$user['name']."' AND latest = 'Y'";
$where_changes = "`user` = '".$user['name']."'";
$where_comments = "`user` = '".$user['name']."'";
$numowned = $this->getCount('pages', $where_owned);
$numchanges = $this->getCount('pages', $where_changes);
$numcomments = $this->getCount('comments', $where_comments);
// build statistics links if needed
$ownedlink = ($numowned > 0)? '<a title="Display pages owned by '.$user['name'].'" href="'.$this->Href('','','user='.$user['name'].'&action=owned').'">'.$numowned.'</a>' : '0';
$changeslink = ($numchanges > 0)? '<a title="Display page edits by '.$user['name'].'" href="'.$this->Href('','','user='.$user['name'].'&action=changes').'">'.$numchanges.'</a>' : '0';
$commentslink = ($numcomments > 0)? '<a title="Display comments by '.$user['name'].'" href="'.$this->Href('','','user='.$user['name'].'&action=comments').'">'.$numcomments.'</a>' : '0';
$htmlout .= "<tbody>\n <tr>\n".
" <td><input type=\"checkbox\" id=\"".$user['id']."\"".$checked." title=\"Select ".$user['name']."\"/></td>\n".
" <td>".$this->Link($user['name'])."</td>\n".
" <td>".$user['email']."</td>\n".
" <td class=\"time\">".$user['signuptime']."</td>\n".
" <td>".$user['ipaddress']."</td>\n". #[remove this line if you are using standard Wikka tables]
" <td><center />".$ownedlink."</td>\n".
" <td><center />".$changeslink."</td>\n".
" <td><center />".$commentslink."</td>\n".
" <td><center />delete :: <a title=\"Send feedback to ".$user['name']."\" href=\"".$this->Href('','','user='.$user['name'].'&action=feedback')."\">feedback</a></td>\n";
$htmlout .= " </tr>\n</tbody>\n";
}
$htmlout .= "</table>\n</div>\n";
echo $htmlout;
} else {
echo "<p><span class=\"error\">Sorry, there are no users matching</span> <strong>\"".$_POST["search"]."\"</strong></p>";
}
}
} else {
// user is not admin
echo $this->Action("lastusers");
}
?>
CategoryDevelopmentActions CategoryDevelopmentAdmin