===== User Administration Module =====
{{lastedit}}
This is the development page for the User Administration module. The User Administration module has been committed to the [[http://wush.net/websvn/wikka/listing.php?repname=wikka&path=%2Fbranches%2F1.1.6.4%2F 1.1.6.4 branch]] and will be available with the [[http://blog.wikkawiki.org/2007/11/23/pre-release-announcement-for-securityantispam-release-1164/ 1.1.6.4 release]]. **Documentation** http://docs.wikkawiki.org/UserAdministration
This action is meant to allow Wikka Administrators to manage users and perform several maintenance operations.
It displays the standard LastUsers list to non-admins.
>>**See also:**
~-AdminModules
~-WikkaBetaFeatures
~-UnderDevelopment
~-Are you an administrator of this site ? --- Give it a [[UserAdminTest try]]
>><<**Table of Contents:**
~-""Why?""
~-""Current version""
~-""To do""
~-""The code""
~-""Styling options""<<
::c::
=== Why? ===
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]]) ''-- done as of 1.1.6.4; however, other core changes must be made to recognize users as being deleted''
~~-**add users** - in case the registration of a page is turned off, but you want to add a user
~~~& noted, good idea -- DarTar
~~~~& See DanWestUserReg. Worked for me as intended. I'd say, this function's done --MasinAlDujaili, 2007-05-21
~~-**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 can be used by adding ##""{{useradmin}}""## in the body of a page.
Here's a preview of the interface (the email and IP fields are masked for privacy reasons)
----
==sample output==
""
User Administration
""
----
===Current version=== (//2005-08-31//):
##0.5##
~-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 Signup IP ( installed on this server as a beta feature).
~~-TrackIPaddressMod for (possible) install on 'your' server
~-added constants, UI strings and a bunch of configurable options including styling options (see below).
==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''
===To do ===
~-mass-operations;
~-deleting/banning users;
~-integrate with other admin modules.
----
====The code====
<<##actions/useradmin.php##<<
**Note:** this action uses the ##ipaddress## field that has been added as a beta antispam feature to this server. Lines relative to this field have been commented out in the code to allow installation on a native wikka package
The code has also been adapted to take advantage of the ##[[WikkaCountingRecords getCount()]]## method, which is required for the action to work.
%%(php;1)
= $max)
{
// add $max to the list; then break out of the loop
$opts[] = $max;
break;
}
// when $limit is reached, it becomes the new start and increment for the next 'range'
$inc = $limit;
}
return $opts;
}
// restrict access to admins
if ($this->IsAdmin($this->GetUser())) {
// -------------------------------------
// set default values as constants
define('DEFAULT_RECORDS_LIMIT', '10'); # number of records per page
define('DEFAULT_MIN_RECORDS_DISPLAY', '5'); # min number of records
define('DEFAULT_RECORDS_RANGE',serialize(array('10','50','100','500','1000'))); #range array for records pager
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 search
define('ALTERNATE_ROW_COLOR', '1'); # switch alternate row color
define('STAT_COLUMN_COLOR', '1'); # switch color for statistics columns
// -------------------------------------
// User-interface: icons
define('OWNED_ICON', 'images/icons/16x16/stock_keyring.png');
define('EDITS_ICON', 'images/icons/16x16/text-editor.png');
define('COMMENTS_ICON', 'images/icons/16x16/stock_help-agent.png');
// -------------------------------------
// User-interface: strings
define('PAGE_TITLE','User Administration');
define('FORM_LEGEND','Filter view:');
define('FORM_SEARCH_STRING_LABEL','Search user:');
define('FORM_SEARCH_STRING_TITLE','Enter a search string');
define('FORM_SEARCH_SUBMIT','Submit');
define('FORM_PAGER_LABEL_BEFORE','Show');
define('FORM_PAGER_TITLE','Select records-per-page limit');
define('FORM_PAGER_LABEL_AFTER','records per page');
define('FORM_PAGER_SUBMIT','Apply');
define('FORM_PAGER_LINK','Show records from %d to %d');
define('FORM_RESULT_INFO','Records');
define('FORM_RESULT_SORTED_BY','Sorted by:');
define('TABLE_HEADING_USERNAME','User Name');
define('TABLE_HEADING_USERNAME_TITLE','Sort by user name');
define('TABLE_HEADING_EMAIL','Email');
define('TABLE_HEADING_EMAIL_TITLE','Sort by email');
define('TABLE_HEADING_SIGNUPTIME','Signup Time');
define('TABLE_HEADING_SIGNUPTIME_TITLE','Sort by signup time');
define('TABLE_HEADING_SIGNUPIP','Signup IP');
define('TABLE_HEADING_SIGNUPIP_TITLE','Sort by signup IP');
define('TABLE_SUMMARY','List of users registered on this server');
define('TABLE_HEADING_OWNED_TITLE','Owned Pages');
define('TABLE_HEADING_EDITS_TITLE','Page Edits');
define('TABLE_HEADING_COMMENTS_TITLE','Comments');
define('ACTION_DELETE_LINK_TITLE','Remove user %s');
define('ACTION_FEEDBACK_LINK_TITLE','Send feedback to user %s');
define('ACTION_DELETE_LINK','delete');
define('ACTION_FEEDBACK_LINK','feedback');
define('TABLE_CELL_OWNED_TITLE','Display pages owned by %s (%d)');
define('TABLE_CELL_EDITS_TITLE','Display page edits by %s (%d)');
define('TABLE_CELL_COMMENTS_TITLE','Display comments by %s (%d)');
define('SELECT_RECORD_TITLE','Select %s');
define('CHECK_ALL_TITLE','Check all records');
define('CHECK_ALL','Check all');
define('UNCHECK_ALL_TITLE','Uncheck all records');
define('UNCHECK_ALL','Uncheck all');
define('FORM_MASSACTION_LEGEND','Mass-action');
define('FORM_MASSACTION_LABEL','With selected');
define('FORM_MASSACTION_SELECT_TITLE','Choose action to apply to selected records');
define('FORM_MASSACTION_OPT_DELETE','Remove all');
define('FORM_MASSACTION_OPT_FEEDBACK','Send feedback to all');
define('FORM_MASSACTION_SUBMIT','Submit');
define('ERROR_NO_MATCHES','Sorry, there are no users matching "%s"');
//initialize row & column colors variables
$r = 1; #initialize row counter
$r_color = ALTERNATE_ROW_COLOR; #get alternate row color option
$c_color = STAT_COLUMN_COLOR; #get column color option
// record dropdown
$user_limits = unserialize(DEFAULT_RECORDS_RANGE);
// pager
$prev = '';
$next = '';
//override defaults with action parameters
if (is_array($vars))
{
foreach ($vars as $param => $value)
{
switch ($param)
{
case 'colcolor':
$c_color = (preg_match('/[01]/',$value))? $value : STAT_COLUMN_COLOR;
break;
case 'rowcolor':
$r_color = (preg_match('/[01]/',$value))? $value : ALTERNATE_ROW_COLOR;
break;
}
}
}
//perform actions if required
if ($_GET['action'] == 'feedback' || $_REQUEST['mail'])
{
echo $this->Action('userfeedback');
}
elseif ($_GET['action'] == 'owned')
{
echo $this->Action('userpages');
}
elseif ($_GET['action'] == 'changes')
{
echo $this->Action('userchanges');
}
elseif ($_GET['action'] == 'comments')
{
echo $this->Action('usercomments');
}
else
{
// process URL variables
# JW 2005-07-19 some modifications to avoid notices but these are still not actually secure
// number of 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 string
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"' : '';
}
// restrict MySQL query by search string
$where = ('' == $q) ? "1" : "`name` LIKE '%".$q."%'";
// get total number of users
$numusers = $this->getCount('users', $where);
// print page header
echo $this->Format('==== '.PAGE_TITLE.' ==== --- ');
// build pager form
$form = $this->FormOpen('','','post','user_admin_panel');
$form .= ''.$this->FormClose()."\n";
// print form
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 header links
$nameheader = ''.TABLE_HEADING_USERNAME.'';
$emailheader = ''.TABLE_HEADING_EMAIL.'';
$timeheader = ''.TABLE_HEADING_SIGNUPTIME.'';
/*$ipheader = ''.TABLE_HEADING_SIGNUPIP.''; # installed as beta feature at wikka.jsnx.com */
// build table headers
$htmlout = "
\n\n".
"
\n".
"
\n".
"
".$nameheader."
\n".
"
".$emailheader."
\n".
"
".$timeheader."
\n".
/* "
".$ipheader."
\n". # installed as beta feature at wikka.jsnx.com */
"
\n";
// print the table
echo $this->FormOpen('','','get');
echo $htmlout;
// multiple-user operations (forthcoming) JW 2005-07-19 accesskey removed (causes more problems than it solves)
echo '';
echo $this->FormClose();
}
else
{
// no records matching the search string: print error message
echo '
'.sprintf(ERROR_NO_MATCHES, $q).'
';
}
}
} else {
// user is not admin
echo $this->Action('lastusers');
}
?>
%%
===New CSS classes===
The styling of the tables requires a bunch of [[TableStyling new CSS classes]].
----
==== Styling options ====
The ##useradmin## action accepts two optional styling parameters:
##colcolor##
Enables color for statistics columns
1: enables colored columns (default);
0: disables colored columns;
##rowcolor##
Enables alternate row colors
1: enables colored rows (default);
0: disables colored rows;
The following examples show how the table is rendered using these two parameters:
**No styling:** ##""{{useradmin colcolor="0" rowcolor="0"}}""##
""