summaryrefslogtreecommitdiff
path: root/lib/plugins/usermanager/admin.php
diff options
context:
space:
mode:
authorChristopher Smith <chris@jalakai.co.uk>2013-10-06 11:47:53 -0700
committerChristopher Smith <chris@jalakai.co.uk>2013-10-06 11:47:53 -0700
commit7ac75dc1923bc76b6f34831be049a0f02aec9e1f (patch)
tree5c776d2113e5f0c3e9a3f3547c18be228d15c3bb /lib/plugins/usermanager/admin.php
parenta28f4344975a38a4fccbf859720cc7ae2e9a1376 (diff)
parent3712ca9a1625d41832dda690dcf98bd75f955502 (diff)
downloadrpg-7ac75dc1923bc76b6f34831be049a0f02aec9e1f.tar.gz
rpg-7ac75dc1923bc76b6f34831be049a0f02aec9e1f.tar.bz2
Merge pull request #348 from splitbrain/candochecksUsermanager
Cando check and localization improvements of usermanager
Diffstat (limited to 'lib/plugins/usermanager/admin.php')
-rw-r--r--lib/plugins/usermanager/admin.php224
1 files changed, 161 insertions, 63 deletions
diff --git a/lib/plugins/usermanager/admin.php b/lib/plugins/usermanager/admin.php
index 266a7dd64..c4d71cb22 100644
--- a/lib/plugins/usermanager/admin.php
+++ b/lib/plugins/usermanager/admin.php
@@ -21,29 +21,30 @@ if(!defined('DOKU_PLUGIN_IMAGES')) define('DOKU_PLUGIN_IMAGES',DOKU_BASE.'lib/pl
*/
class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
- var $_auth = null; // auth object
- var $_user_total = 0; // number of registered users
- var $_filter = array(); // user selection filter(s)
- var $_start = 0; // index of first user to be displayed
- var $_last = 0; // index of the last user to be displayed
- var $_pagesize = 20; // number of users to list on one page
- var $_edit_user = ''; // set to user selected for editing
- var $_edit_userdata = array();
- var $_disabled = ''; // if disabled set to explanatory string
- var $_import_failures = array();
+ protected $_auth = null; // auth object
+ protected $_user_total = 0; // number of registered users
+ protected $_filter = array(); // user selection filter(s)
+ protected $_start = 0; // index of first user to be displayed
+ protected $_last = 0; // index of the last user to be displayed
+ protected $_pagesize = 20; // number of users to list on one page
+ protected $_edit_user = ''; // set to user selected for editing
+ protected $_edit_userdata = array();
+ protected $_disabled = ''; // if disabled set to explanatory string
+ protected $_import_failures = array();
/**
* Constructor
*/
- function admin_plugin_usermanager(){
+ public function admin_plugin_usermanager(){
+ /** @var DokuWiki_Auth_Plugin $auth */
global $auth;
$this->setupLocale();
if (!isset($auth)) {
- $this->disabled = $this->lang['noauth'];
+ $this->_disabled = $this->lang['noauth'];
} else if (!$auth->canDo('getUsers')) {
- $this->disabled = $this->lang['nosupport'];
+ $this->_disabled = $this->lang['nosupport'];
} else {
// we're good to go
@@ -58,27 +59,27 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
}
/**
- * return prompt for admin menu
+ * Return prompt for admin menu
*/
- function getMenuText($language) {
+ public function getMenuText($language) {
if (!is_null($this->_auth))
return parent::getMenuText($language);
- return $this->getLang('menu').' '.$this->disabled;
+ return $this->getLang('menu').' '.$this->_disabled;
}
/**
* return sort order for position in admin menu
*/
- function getMenuSort() {
+ public function getMenuSort() {
return 2;
}
/**
- * handle user request
+ * Handle user request
*/
- function handle() {
+ public function handle() {
global $INPUT;
if (is_null($this->_auth)) return false;
@@ -122,12 +123,13 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
case 'last' : $this->_start = $this->_user_total; break;
}
$this->_validatePagination();
+ return true;
}
/**
- * output appropriate html
+ * Output appropriate html
*/
- function html() {
+ public function html() {
global $ID;
if(is_null($this->_auth)) {
@@ -136,13 +138,12 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
}
$user_list = $this->_auth->retrieveUsers($this->_start, $this->_pagesize, $this->_filter);
- $users = array_keys($user_list);
$page_buttons = $this->_pagination();
$delete_disable = $this->_auth->canDo('delUser') ? '' : 'disabled="disabled"';
$editable = $this->_auth->canDo('UserMod');
- $export_label = empty($this->_filter) ? $this->lang['export_all'] : $this->lang[export_filtered];
+ $export_label = empty($this->_filter) ? $this->lang['export_all'] : $this->lang['export_filtered'];
print $this->locale_xhtml('intro');
print $this->locale_xhtml('list');
@@ -153,7 +154,12 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
if ($this->_user_total > 0) {
ptln("<p>".sprintf($this->lang['summary'],$this->_start+1,$this->_last,$this->_user_total,$this->_auth->getUserCount())."</p>");
} else {
- ptln("<p>".sprintf($this->lang['nonefound'],$this->_auth->getUserCount())."</p>");
+ if($this->_user_total < 0) {
+ $allUserTotal = 0;
+ } else {
+ $allUserTotal = $this->_auth->getUserCount();
+ }
+ ptln("<p>".sprintf($this->lang['nonefound'], $allUserTotal)."</p>");
}
ptln("<form action=\"".wl($ID)."\" method=\"post\">");
formSecurityToken();
@@ -177,6 +183,12 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
ptln(" <tbody>");
foreach ($user_list as $user => $userinfo) {
extract($userinfo);
+ /**
+ * @var string $name
+ * @var string $pass
+ * @var string $mail
+ * @var array $grps
+ */
$groups = join(', ',$grps);
ptln(" <tr class=\"user_info\">");
ptln(" <td class=\"centeralign\"><input type=\"checkbox\" name=\"delete[".$user."]\" ".$delete_disable." /></td>");
@@ -251,13 +263,18 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
$this->_htmlImportForm();
}
ptln("</div>");
+ return true;
}
-
/**
- * @todo disable fields which the backend can't change
+ * Display form to add or modify a user
+ *
+ * @param string $cmd 'add' or 'modify'
+ * @param string $user id of user
+ * @param array $userdata array with name, mail, pass and grps
+ * @param int $indent
*/
- function _htmlUserForm($cmd,$user='',$userdata=array(),$indent=0) {
+ protected function _htmlUserForm($cmd,$user='',$userdata=array(),$indent=0) {
global $conf;
global $ID;
@@ -327,7 +344,17 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
ptln("</form>",$indent);
}
- function _htmlInputField($id, $name, $label, $value, $cando, $indent=0) {
+ /**
+ * Prints a inputfield
+ *
+ * @param string $id
+ * @param string $name
+ * @param string $label
+ * @param string $value
+ * @param bool $cando whether auth backend is capable to do this action
+ * @param int $indent
+ */
+ protected function _htmlInputField($id, $name, $label, $value, $cando, $indent=0) {
$class = $cando ? '' : ' class="disabled"';
echo str_pad('',$indent);
@@ -355,12 +382,23 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
echo "</tr>";
}
- function _htmlFilter($key) {
+ /**
+ * Returns htmlescaped filter value
+ *
+ * @param string $key name of search field
+ * @return string html escaped value
+ */
+ protected function _htmlFilter($key) {
if (empty($this->_filter)) return '';
return (isset($this->_filter[$key]) ? hsc($this->_filter[$key]) : '');
}
- function _htmlFilterSettings($indent=0) {
+ /**
+ * Print hidden inputs with the current filter values
+ *
+ * @param int $indent
+ */
+ protected function _htmlFilterSettings($indent=0) {
ptln("<input type=\"hidden\" name=\"start\" value=\"".$this->_start."\" />",$indent);
@@ -369,7 +407,12 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
}
}
- function _htmlImportForm($indent=0) {
+ /**
+ * Print import form and summary of previous import
+ *
+ * @param int $indent
+ */
+ protected function _htmlImportForm($indent=0) {
global $ID;
$failure_download_link = wl($ID,array('do'=>'admin','page'=>'usermanager','fn[importfails]'=>1));
@@ -378,7 +421,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
print $this->locale_xhtml('import');
ptln(' <form action="'.wl($ID).'" method="post" enctype="multipart/form-data">',$indent);
formSecurityToken();
- ptln(' <label>User list file (csv): <input type="file" name="import" /></label>',$indent);
+ ptln(' <label>'.$this->lang['import_userlistcsv'].'<input type="file" name="import" /></label>',$indent);
ptln(' <input type="submit" name="fn[import]" value="'.$this->lang['import'].'" />',$indent);
ptln(' <input type="hidden" name="do" value="admin" />',$indent);
ptln(' <input type="hidden" name="page" value="usermanager" />',$indent);
@@ -391,7 +434,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
if ($this->_import_failures) {
$digits = strlen(count($this->_import_failures));
ptln('<div class="level3 import_failures">',$indent);
- ptln(' <h3>Most Recent Import - Failures</h3>');
+ ptln(' <h3>'.$this->lang['import_header'].'</h3>');
ptln(' <table class="import_failures">',$indent);
ptln(' <thead>',$indent);
ptln(' <tr>',$indent);
@@ -416,13 +459,18 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
}
ptln(' </tbody>',$indent);
ptln(' </table>',$indent);
- ptln(' <p><a href="'.$failure_download_link.'">Download Failures as CSV for correction</a></p>');
+ ptln(' <p><a href="'.$failure_download_link.'">'.$this->lang['import_downloadfailures'].'</a></p>');
ptln('</div>');
}
}
- function _addUser(){
+ /**
+ * Add an user to auth backend
+ *
+ * @return bool whether succesful
+ */
+ protected function _addUser(){
global $INPUT;
if (!checkSecurityToken()) return false;
if (!$this->_auth->canDo('addUser')) return false;
@@ -483,9 +531,11 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
}
/**
- * Delete user
+ * Delete user from auth backend
+ *
+ * @return bool whether succesful
*/
- function _deleteUser(){
+ protected function _deleteUser(){
global $conf, $INPUT;
if (!checkSecurityToken()) return false;
@@ -518,12 +568,14 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
/**
* Edit user (a user has been selected for editing)
+ *
+ * @param string $param id of the user
+ * @return bool whether succesful
*/
- function _editUser($param) {
+ protected function _editUser($param) {
if (!checkSecurityToken()) return false;
if (!$this->_auth->canDo('UserMod')) return false;
-
- $user = cleanID(preg_replace('/.*:/','',$param));
+ $user = $this->_auth->cleanUser(preg_replace('/.*[:\/]/','',$param));
$userdata = $this->_auth->getUserData($user);
// no user found?
@@ -539,16 +591,18 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
}
/**
- * Modify user (modified user data has been recieved)
+ * Modify user in the auth backend (modified user data has been recieved)
+ *
+ * @return bool whether succesful
*/
- function _modifyUser(){
+ protected function _modifyUser(){
global $conf, $INPUT;
if (!checkSecurityToken()) return false;
if (!$this->_auth->canDo('UserMod')) return false;
// get currently valid user data
- $olduser = cleanID(preg_replace('/.*:/','',$INPUT->str('userid_old')));
+ $olduser = $this->_auth->cleanUser(preg_replace('/.*[:\/]/','',$INPUT->str('userid_old')));
$oldinfo = $this->_auth->getUserData($olduser);
// get new user data subject to change
@@ -609,9 +663,14 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
}
/**
- * send password change notification email
+ * Send password change notification email
+ *
+ * @param string $user id of user
+ * @param string $password plain text
+ * @param bool $status_alert whether status alert should be shown
+ * @return bool whether succesful
*/
- function _notifyUser($user, $password, $status_alert=true) {
+ protected function _notifyUser($user, $password, $status_alert=true) {
if ($sent = auth_sendPassword($user,$password)) {
if ($status_alert) {
@@ -627,11 +686,13 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
}
/**
- * retrieve & clean user data from the form
+ * Retrieve & clean user data from the form
*
+ * @param bool $clean whether the cleanUser method of the authentication backend is applied
* @return array (user, password, full name, email, array(groups))
*/
- function _retrieveUser($clean=true) {
+ protected function _retrieveUser($clean=true) {
+ /** @var DokuWiki_Auth_Plugin $auth */
global $auth;
global $INPUT;
@@ -650,7 +711,12 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
return $user;
}
- function _setFilter($op) {
+ /**
+ * Set the filter with the current search terms or clear the filter
+ *
+ * @param string $op 'new' or 'clear'
+ */
+ protected function _setFilter($op) {
$this->_filter = array();
@@ -664,7 +730,12 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
}
}
- function _retrieveFilter() {
+ /**
+ * Get the current search terms
+ *
+ * @return array
+ */
+ protected function _retrieveFilter() {
global $INPUT;
$t_filter = $INPUT->arr('filter');
@@ -680,7 +751,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
return $filter;
}
- function _validatePagination() {
+ /**
+ * Validate and improve the pagination values
+ */
+ protected function _validatePagination() {
if ($this->_start >= $this->_user_total) {
$this->_start = $this->_user_total - $this->_pagesize;
@@ -690,10 +764,12 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
$this->_last = min($this->_user_total, $this->_start + $this->_pagesize);
}
- /*
- * return an array of strings to enable/disable pagination buttons
+ /**
+ * Return an array of strings to enable/disable pagination buttons
+ *
+ * @return array with enable/disable attributes
*/
- function _pagination() {
+ protected function _pagination() {
$disabled = 'disabled="disabled"';
@@ -709,10 +785,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
return $buttons;
}
- /*
- * export a list of users in csv format using the current filter criteria
+ /**
+ * Export a list of users in csv format using the current filter criteria
*/
- function _export() {
+ protected function _export() {
// list of users for export - based on current filter criteria
$user_list = $this->_auth->retrieveUsers(0, 0, $this->_filter);
$column_headings = array(
@@ -741,12 +817,14 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
die;
}
- /*
- * import a file of users in csv format
+ /**
+ * Import a file of users in csv format
*
* csv file should have 4 columns, user_id, full name, email, groups (comma separated)
+ *
+ * @return bool whether succesful
*/
- function _import() {
+ protected function _import() {
// check we are allowed to add users
if (!checkSecurityToken()) return false;
if (!$this->_auth->canDo('addUser')) return false;
@@ -806,9 +884,17 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
$_SESSION['import_failures'] = $this->_import_failures;
session_write_close();
}
+ return true;
}
- function _cleanImportUser($candidate, & $error){
+ /**
+ * Returns cleaned user data
+ *
+ * @param array $candidate raw values of line from input file
+ * @param $error
+ * @return array|bool cleaned data or false
+ */
+ protected function _cleanImportUser($candidate, & $error){
global $INPUT;
// kludgy ....
@@ -847,7 +933,16 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
return $cleaned;
}
- function _addImportUser($user, & $error){
+ /**
+ * Adds imported user to auth backend
+ *
+ * Required a check of canDo('addUser') before
+ *
+ * @param array $user data of user
+ * @param string &$error reference catched error message
+ * @return bool whether succesful
+ */
+ protected function _addImportUser($user, & $error){
if (!$this->_auth->triggerUserMod('create', $user)) {
$error = $this->lang['import_error_create'];
return false;
@@ -856,7 +951,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
return true;
}
- function _downloadImportFailures(){
+ /**
+ * Downloads failures as csv file
+ */
+ protected function _downloadImportFailures(){
// ==============================================================================================
// GENERATE OUTPUT
@@ -868,7 +966,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
// output the csv
$fd = fopen('php://output','w');
- foreach ($this->_import_failures as $line => $fail) {
+ foreach ($this->_import_failures as $fail) {
fputs($fd, $fail['orig']);
}
fclose($fd);