===== 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


Filter view:

Records (857): 1-10 | 11-20
(Sorted by:signuptime, desc)
  User Name Email Signup Time Signup IP O E C Actions
HypeXR scott@xxxx.xx 2005-08-01 09:01:54 XX.XX.XX.XX 1 2 1 delete :: feedback
WiebTest wiebren.w@xxxx.xx 2005-07-31 19:35:26 XX.XX.XX.XX 0 0 0 delete :: feedback
DennyShimkoski denny@xxxx.xx 2005-07-31 00:22:58 XX.XX.XX.XX 6 38 1 delete :: feedback
RobinW wikka@xxxx.xx 2005-07-30 02:06:20 XX.XX.XX.XX 0 0 1 delete :: feedback
VictorManuelVarela vmvarela@xxxx.xx 2005-07-30 00:01:13 XX.XX.XX.XX 1 6 0 delete :: feedback
EniBevoli enibevoli@xxxx.xx 2005-07-29 12:13:44 XX.XX.XX.XX 0 4 1 delete :: feedback
MyPrivateWiki serayamaouche@xxxx.xx 2005-07-28 20:30:36 XX.XX.XX.XX 0 0 0 delete :: feedback
DaSt dstolars@xxxx.xx 2005-07-27 17:32:06 XX.XX.XX.XX 0 0 0 delete :: feedback
WikiSop mail-to-sophie@xxxx.xx 2005-07-27 14:59:07 XX.XX.XX.XX 0 0 0 delete :: feedback
Aragorn2005 mail.matthias.schulz@xxxx.xx 2005-07-27 08:48:46 XX.XX.XX.XX 0 0 0 delete :: feedback
Mass-action[Check all | Uncheck all]
"" ---- ===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 .= '
'.FORM_LEGEND.''."\n"; $form .= '
'."\n"; // ranged drop-down $users_opts = optionRanges($user_limits,$numusers,DEFAULT_MIN_RECORDS_DISPLAY); $form .= ' '."\n"; $form .= '
'."\n"; // build pager links if ($s > 0) $prev = ''.($s-$l+1).'-'.$s.' | '."\n"; if ($numusers > ($s + $l)) $next = ' | '.($s+$l+1).'-'.($s+2*$l).''."\n"; $form .= FORM_RESULT_INFO.' ('.$numusers.'): '.$prev.($s+1).'-'.($s+$l).$next.'
'."\n"; $form .= '('.FORM_RESULT_SORTED_BY.''.$sort.', '.$d.')'."\n"; $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". " \n". " \n". " \n". /* " \n". # installed as beta feature at wikka.jsnx.com */ " \n". " \n". " \n". " \n". " \n\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)? ''.$numowned.'' : '0'; $changeslink = ($numchanges > 0)? ''.$numchanges.'' : '0'; $commentslink = ($numcomments > 0)? ''.$numcomments.'' : '0'; // build handler links $deleteuser = ''.ACTION_DELETE_LINK.''; $feedbackuser = ''.ACTION_FEEDBACK_LINK.''; // build table body $htmlout .= "\n"; if ($r_color == 1) { $htmlout .= "\n"; #enable alternate row color } else { $htmlout .= "\n"; #disable alternate row color } $htmlout .= " \n". " \n". #check if userpage exists " \n". " \n". /* " \n". # installed as beta feature at wikka.jsnx.com */ " \n". #set column color " \n". #set column color " \n". #set column color " \n"; $htmlout .= " \n\n"; //increase row counter ----- alternate row colors if ($r_color == 1) $r++; } $htmlout .= "
 ".$nameheader."".$emailheader."".$timeheader."".$ipheader.";\"O\"/\"E\"/\"C\"/Actions
".(($this->ExistsPage($user['name']))? $this->Link($user['name']) : $user['name'])."".$user['email']."".$user['signuptime']."".$user['ipaddress']."".$ownedlink."".$changeslink."".$commentslink."".$deleteuser." :: ".$feedbackuser."
\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 '
'.FORM_MASSACTION_LEGEND.''; echo '['.CHECK_ALL.' | '.UNCHECK_ALL.']
'; echo ' '; 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"}}""## ""
  User Name Email Signup Time Signup IP O E C Actions
HypeXR scott@xxxx.xx 2005-08-01 09:01:54 XX.XX.XX.XX 1 2 1 delete :: feedback
WiebTest wiebren.w@xxxx.xx 2005-07-31 19:35:26 XX.XX.XX.XX 0 0 0 delete :: feedback
DennyShimkoski denny@xxxx.xx 2005-07-31 00:22:58 XX.XX.XX.XX 6 38 1 delete :: feedback
"" **Alternate rows only:** ##""{{useradmin colcolor="0"}}""## ""
  User Name Email Signup Time Signup IP O E C Actions
HypeXR scott@xxxx.xx 2005-08-01 09:01:54 XX.XX.XX.XX 1 2 1 delete :: feedback
WiebTest wiebren.w@xxxx.xx 2005-07-31 19:35:26 XX.XX.XX.XX 0 0 0 delete :: feedback
DennyShimkoski denny@xxxx.xx 2005-07-31 00:22:58 XX.XX.XX.XX 6 38 1 delete :: feedback
"" **Colored columns only:** ##""{{useradmin rowcolor="0"}}""## ""
  User Name Email Signup Time Signup IP O E C Actions
HypeXR scott@xxxx.xx 2005-08-01 09:01:54 XX.XX.XX.XX 1 2 1 delete :: feedback
WiebTest wiebren.w@xxxx.xx 2005-07-31 19:35:26 XX.XX.XX.XX 0 0 0 delete :: feedback
DennyShimkoski denny@xxxx.xx 2005-07-31 00:22:58 XX.XX.XX.XX 6 38 1 delete :: feedback
"" **Alternate rows and colored columns:** ##""{{useradmin}}""## ""
  User Name Email Signup Time Signup IP O E C Actions
HypeXR scott@xxxx.xx 2005-08-01 09:01:54 XX.XX.XX.XX 1 2 1 delete :: feedback
WiebTest wiebren.w@xxxx.xx 2005-07-31 19:35:26 XX.XX.XX.XX 0 0 0 delete :: feedback
DennyShimkoski denny@xxxx.xx 2005-07-31 00:22:58 XX.XX.XX.XX 6 38 1 delete :: feedback
"" ---- CategoryDevelopmentActions CategoryDevelopmentAdmin