DokuWiki is a fine product, and its extensibility is a big element of that. I’ve known for a while that it has different authentication classes, and I’ve even used some of the different ones it comes with. Recently I had cause to write my own, to marry up with some user information stored in an Oracle database table, and used to access the company intranet. Working with DokuWiki’s skeleton classes to create my own was much easier than I expected and here’s my experience.
Choosing the class to extend
Since my requirements are pretty simple, my new class extends auth_basic – and I used the plain.class.php that comes with DokuWiki (for plain text authentication) as a template to guide me.
The first step was to chop out most of the functionality. This is done by setting the class’ cando properties to false, which was quick. My system has all its user maintenance and so on done elsewhere so I don’t want users to be able to change passwords or anything. My declaration now reads:
class auth_symphony extends auth_basic {
var $users = null;
var $_pattern = array();
/**
* Constructor
*
* Carry out sanity checks to ensure the object is
* able to operate. Set capabilities.
*
* @author Christopher Smith <[email protected]>
*/
function auth_plain() {
$this->cando['addUser'] = false;
$this->cando['delUser'] = false;
$this->cando['modLogin'] = false;
$this->cando['modPass'] = false;
$this->cando['modName'] = false;
$this->cando['modMail'] = false;
$this->cando['modGroups'] = false;
$this->cando['getUsers'] = false;
$this->cando['getUserCount'] = false;
}
Getting the information to dokuwiki
I included the standard library that we use here with all PHP pages, that handles things like database connection setup and so on. Then I altered the function _loadUserData(), creating a new empty array for $this-users and then then running a select statement and populating the array with the results. I found it useful to get the wiki working with plain text authentication first and just a couple of users set up so I could observe the output of the various functions. Here’s the altered function:
function _loadUserData(){
$this->users = array();
$L_sql = "
SELECT u.user_name
,u.extranet_pass
, d.dept_code
,u.full_name
,u.email
FROM vis_users u
, vis_subdepts d
WHERE d.subdept_code = u.subdept_code
AND u.extranet_valid = 'Y'
";
$L_bind_in = array();
$L_results = exec_sql($L_sql,$L_bind_in);
foreach($L_results as $L_result) {
$this->users[$L_result['USER_NAME']]['pass'] = md5($L_result['EXTRANET_PASS']);
$this->users[$L_result['USER_NAME']]['name'] = $L_result['FULL_NAME'];
$this->users[$L_result['USER_NAME']]['mail'] = $L_result['EMAIL'];
$this->users[$L_result['USER_NAME']]['grps'] = array('user',$L_result['DEPT_CODE']);
}
}
if anyone can make any suggestions about pasting clean code snippets in textpattern, I’d be grateful! In the meantime, I apologise for the state of the above example
I removed the functions for creating, modifying and deleting users as I had already told my class it couldn’t use those.
The results
All in all this was quite simple to get working, and DokuWiki is designed to have its authentication functions replaced in this way which is invaluable. We also created a new template for the site and hey presto we’re ready to go with no further modifications1 and no hassle when upgrades come around.
1 OK so actually I added some class definition to the breadcrumb hyperlinks because I changed the bar colour, but that’s almost no modification!