Downloads: Getting DokuWiki to use Wordpress Authentication (v1.2)
This extension does not transform your Wordpress (WP) posts into DokuWiki (DW) entires. If your looking for that functionality, I’d recommend doing a google search for dwBliki plugin.
What this extension does is to get DokuWiki to use Wordpress’ authentication, i.e. DokuWiki to use Wordpress’ user database, using an authentication plugin for DokuWiki.
Download the DokuWiki Authentication Extension (v1.2)
Previous downloads:Download the DokuWiki Authentication Extension (v1.1) and Download the DokuWiki Authentication Extension
Before you begin, you’ll need to be able to run MySQL commands on your WP database and shouldn’t be afraid of modifying some code.
Much of this work was based on the DW splitbrain.org wiki documentation. I used the phpbb integration as a template. See:
http://wiki.splitbrain.org/wiki:auth:mysql
http://wiki.splitbrain.org/wiki:tips:integrate_with_phpbb
I’ve tested this with versions:
DokuWiki: 2006-03-09d
Wordpress: 2.0.4
I can’t speak for other versions.
Version History
1.2 (10/10/2006)
- The extension turns back on “magic quotes” which causes additional slashes in DW articles after editing.
1.1 (03/10/2006)
- Small fix for using Wordpress tags while logged in.
- Documentation/Instructions updates
1.0 (27/09/2006)
- First Release
Notes on using this authentication plugin
I’d recommend that you get your users to use the WP’s Register, Login and Logout interface rather than DW’s. However, DW’s Login and Logout should work fine and they should log in and out of WP at the same time.
BUT you should use WP to add new users. If you use DW, they won’t be configured correctly to use WP as you need to modify two SQL tables and DW will only modify one.
By default all users are a member of the “defaultgroup”. WP does not have any concept of user groups. It does have a concept of roles which I have ignored because I wanted the flexibility of DW’s user groups. You can’t really remove users from this group unless you modify “wordpress.class.php”.
You can use DW’s “User Manager” to add and remove your WP users from DW’s user groups but avoid the “Configuration Settings” as this overwrites your local.php and seems to cause problems for the WP authenication.
This plugin also introduces a useful feature. Because it pulls in your Wordpress files, you can then, anywhere else in DW, access Wordpress functions. This means, for example, you can use template functions like “get_header();” or “get_sidebar();” if your skinning your DW.
First up: Installing Wordpress and/or DokuWiki
For installing WP or DW, refer to the included installation documentation.
Install WP first and make sure everything is up and running before installing DW. Make sure that DW is installed in a directory at the same level as WP or as a subdirectory of WP. This is to make sure that the cookie domains are the same.
In my test environment I had wordpress installed @ ~/public_html/test/wp and DW installed @ ~/public_html/test/dw.
Now, configuring DokuWiki…
First, copy “wordpress.class.php” to
if(!defined(‘WP_ROOT’)) define(‘WP_ROOT’, DOKU_INC.’../wp/’);
I have it configured by default to assume that dokuwiki is installed at the same level as WP and that WP is installed in a directory called “wp”.
acl.auth.php
You probably created a “conf/acl.auth.php” when you installed DW initially. If you didn’t, make a copy of conf/acl.auth.php.dist and name it “acl.auth.php”.
local.php
You probably created a “conf/local.php” when you installed DW initially. If you didn’t, make a copy of conf/local.php.dist and name it “local.php”. Open it in your favorite text editor and add (or modify) these settings:
// Disable the ability to register: users should register via the Wordpress interface
$conf['openregister']= 0;
// Disable password autogen: not important if users can’t register
$conf['autopasswd'] = 1;
// Disable password resend: let wordpress do this
$conf['resendpasswd']= 0;
// Enable access control
$conf['useacl'] = 1;
// Use wordpress authentication
$conf['authtype'] = ‘wordpress’;
// Not sure what passcrypt needs to be set to, but this works
$conf['passcrypt'] = ’smd5′;
// Recommend you set defaultgroup to “user” and “superuser” admin group.
// as we’ll be creating them during our integration.
$conf['defaultgroup']= ‘user’;
$conf['superuser'] = ‘@admin’;
// Updating profile requires password
$conf['profileconfirm'] = ‘1′;
Finally, modifying your SQL Database
First, backup your database. You can do this quite easily via WP’s Database plugin.
You need to create two new tables to support DW. In the code below I’ve called these tables “wp_dw_groups” and “wp_dw_usergroups”. If you did not use “wp_” as your database prefix for Wordpress, you will need to modify these commands before you use them and replace “wp_” with the prefix you used. “wordpress.class.php” uses the database prefix to reference these tables.
Connect to your database and run these two commands:
CREATE TABLE `wp_dw_groups` (
`gid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL DEFAULT ”,
PRIMARY KEY (`gid`),
UNIQUE KEY `name` (`name`)
) TYPE = MYISAM;
CREATE TABLE `wp_dw_usergroup` (
`uid` int(10) UNSIGNED NOT NULL DEFAULT ‘0′,
`gid` int(10) UNSIGNED NOT NULL DEFAULT ‘0′,
PRIMARY KEY (`uid`,`gid`)
) TYPE = MYISAM;
These will create the two tables you need. However, you need to setup some groups too. So these two commands will create a user and an admin group.
INSERT INTO `wp_dw_groups` VALUES (1,”admin”);
INSERT INTO `wp_dw_groups` VALUES (2,”user”);
Now you need to give yourself admin rights. Normally the first user created in WP is the admin account. This normally has the ID of 1. So now we will add admin user to admin and user groups.
INSERT INTO `wp_dw_usergroup` VALUES (1,1);
INSERT INTO `wp_dw_usergroup` VALUES (1,2);
Finished
Now you should be able to login and logout using your WP’s users on DW!
Guest
September 27th, 2006 at 8:39 pm
hey,
thanks for the good work. have been looking for something like this. however, i installed everything the way you described it and for some reason it doesn’t work. i am using the correct versions as well.
i have wordpress installed in folder ‘wordpress’ and dokuwiki in folder ‘wiki’, both in my root directory.
so i changed wordpress.class.php to this:
‘if(!defined(‘WP_ROOT’)) define(‘WP_ROOT’, DOKU_INC.’../wordpress/’);’.
was this correct? thanks for the help, bo
Guest
September 27th, 2006 at 8:51 pm
me again,
ok, found the problem. in your description for local.php you had this:
‘// Use wordpress authentication
$conf['authtype'] = ‘wordpress’;
// Not sure what authtype and passcrypt need to be set to, but these work
$conf['authtype'] = ‘plain’;
$conf['passcrypt'] = ’smd5′;’
which means ‘$conf['authtype']‘ is there twice, once as wordpress and once as plain. i deleted the plain bit and now everything works like a charm. thanks again.
Administrator
September 28th, 2006 at 7:52 am
Hi Boris,
Sorry. Seems I did a cut and paste error there when I was writing up the installation notes. I’ll update the webpage and the instructions accordingly.
Thanks for that
Mark
Administrator
September 28th, 2006 at 12:32 pm
It seems my DokuWiki extension inadvertently (at least it wasn’t my original intention) introduces a useful feature!
Because it pulls in your Wordpress files, you can then, anywhere else in DokuWiki, access Wordpress functions. This means, for example, you can use template functions like “get_header();” or “get_sidebar();” if your skinning your DW.
It should make integrating DokuWiki and Wordpress tightly, much easier.
Guest
October 2nd, 2006 at 4:58 pm
hey mark,
found a bug i think. all the wp-functions work great, as long as nobody is signed in. but once i sign in, then loop functions don’t seem to work anymore. i use the loop to display post titles of a certain category in a css menu. once i’m signed in though, instead of the titles i get this note:
‘Warning: Invalid argument supplied for foreach() in /www/htdocs/w006dc1d/travelogues/wp-includes/classes.php on line 496′
line 496 being:’foreach ( $all_cat_ids as $cat_id ) {‘,
but me, being a complete php-idiot, i have no idea what this is supposed to tell me.
the login function still works though. do you have any idea, why this happens, mark?
thanks
Administrator
October 3rd, 2006 at 7:56 am
Hi Boris,
Right now, I don’t know. I’ll have to do some tests and see if I can reproduce it. So all your doing is printing titles of posts from a particular category? I should be able to reproduce that.
The error you describe indicates that the variable “all_cat_ids” in the statement:
foreach ( $all_cat_ids as $cat_id ) {
is not an array or is empty and so can’t be used in a foreach. I’m guessing the database call to pick up the category ids failed. This could be because DokuWiki shuts down the connection to the database after it’s authenticated the user.
It’ll be a little while before I look into this, but if you get the chance, if you can add these lines:
global $wpdb;
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
to your “wordpress.class.php” at the end of the function “function _closeDB()”. (It may be there, but commented out, you can just remove the “/*” and “*/” to un-comment it).
Alternativily, comment out everything in the function so that DokuWiki never tries to close the database connection.
Mark
Guest
October 3rd, 2006 at 8:36 am
hi mark,
thanks a lot. found the function ‘function _closeDB()’ in mysql.class.php. first i tried to add the 2 lines, but i got the same error like before, plus loads more.
then i uncommented it (lines 738-745) and got another error to do with line 162, which calls the close database function, so i uncommented that as well and it works great now.
thanks again,
boris
Administrator
October 3rd, 2006 at 8:45 am
Hi Boris,
Just to confirm what you did: you removed/commented out the __close function in mysql.class.php and then removed the call to use it “getUserData”. Sounds like my original diagnoise was correct.
I’ll try and do a few tests and update my wordpress.class.php, in a similar way, so you don’t have to modify mysql.class.php. I believe, all you need to do, is have the __close function in wordpress.class.php but that it is empty (i.e. does nothing).
Thanks for your testing and help!
Mark
Administrator
October 3rd, 2006 at 10:15 am
I’ve updated the extension to version 1.1 including the fix for using Wordpress template tags. With 1.1 you shouldn’t need to modify __close in mysql.class.php to access template tags when logged in.
Administrator
October 10th, 2006 at 9:49 am
I’ve updated the extension to version 1.2. This includes a fix for “magic quotes”. On my test sites, the extension turned back on magic quotes when it included Wordpress and so there was lots of stray slashes.
Administrator
October 16th, 2006 at 11:44 am
Sorry about this, but the link on the page for 1.2 was actually point to 1.1. Updated now. The proper link for 1.2 is http://thedeadone.net/wp-content/sw/Wordpress/Wordpress&DokuWiki1.2.zip
Guest
November 26th, 2006 at 4:44 am
hello,
I found out that version 1.2 won’t work with DokuWiki 2006-11-06.
in the new version of auth.php:
// do the login either by cookie or provided credentials
if($conf['useacl']){
if (!isset($_REQUEST['u'])) $_REQUEST['u'] = ”;
if (!isset($_REQUEST['p'])) $_REQUEST['p'] = ”;
if (!isset($_REQUEST['r'])) $_REQUEST['r'] = ”;
// if no credentials were given try to use HTTP auth (for SSO)
if(empty($_REQUEST['u']) && empty($_COOKIE[DOKU_COOKIE]) && !empty($_SERVER['PHP_AUTH_USER'])){
$_REQUEST['u'] = $_SERVER['PHP_AUTH_USER'];
$_REQUEST['p'] = $_SERVER['PHP_AUTH_PW'];
}
// external trust mechanism in place?
if(!is_null($auth) && $auth->canDo(‘external’)){
$auth->trustExternal($_REQUEST['u'],$_REQUEST['p'],$_REQUEST['r']);
}else{
auth_login($_REQUEST['u'],$_REQUEST['p'],$_REQUEST['r']);
}
and the current version of wordpress.class.php:
// someone used the login form!
if(isset($user)){
if($this->checkPass($user,$pass)){
/* Copied this from wp-login.php, not sure exactly what it’s doing!
But we know everything is good so we should be logged in! */
do_action(‘wp_authenticate’, array(&$user, &$pass));
$user_obj = new WP_User(0, $user);
wp_login($user, $pass, true);
auth.php will always call $auth->trustExternal with ’set’ $user and $pass.
so I’ve change:
// someone used the login form!
if(isset($user)){
to:
// someone used the login form!
//if(isset($user)){
if(!empty($user)){
maybe you should do something like that in the new version of wordpress.class.php
Guest
November 26th, 2006 at 6:02 am
BTW, I’m not a programer, so I don’t know so much about PHP and Cookie. I can’t get wordpress.class.php work unless I put DW as a subdir of WP. How can I get them work in the same level directory?
Thanks a lot.
Guest
November 26th, 2006 at 7:32 am
I got it, add this line to wp-config.php:
define(‘COOKIEPATH’, ‘/’);
BTW, these:
// grab the rest from the db
$info = $this->getUserData($user);
$USERINFO['grps'] = $info['grps'];
$USERINFO['mail'] = $info['mail'];
should change to:
// grab the rest from the db
$info = $this->getUserData($user);
$USERINFO['name'] = $info['name'];
$USERINFO['grps'] = $info['grps'];
$USERINFO['mail'] = $info['mail'];
for show the ‘nice name’ in wiki page.
sorry for the 3rd post..
Administrator
November 26th, 2006 at 10:44 pm
Thanks Camel for the updates! I’ll try and update the file over the next week.
March 22nd, 2007 at 4:38 pm
[...] my blog have all been about the Game Crafters Guild website and mostly technical in nature. Here, here and [...]
Guest
April 27th, 2007 at 9:38 am
the link still points on the bad version
* Version 1.1 (3rd October 2006)
Administrator
April 27th, 2007 at 9:42 am
Are you sure? It doesn’t look like it to me. It points to the 1.2 version and if I download it, it grabs the 1.2 zip. Does the zip contain the wrong files?
Guest
April 27th, 2007 at 9:57 am
In fact, the link is good, but not the code (in my case).
My php.ini says magic_quotes-* are off (as phpinfo says), so, the ‘get_magic_quotes_gpc()’ test returns ‘false’ and the remove_magic_quotes(*) does not apply.
I comment the test, and, all is ok on DK with your extension.
—8
Guest
April 27th, 2007 at 9:59 am
ooops, here is the code, i use
// kill magic quotes… again!
//if (get_magic_quotes_gpc()) {
if (!empty($_GET)) remove_magic_quotes($_GET);
if (!empty($_POST)) remove_magic_quotes($_POST);
if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE);
if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST);
if (!empty($_SESSION)) remove_magic_quotes($_SESSION); #FIXME needed ?
@ini_set(‘magic_quotes_gpc’, 0);
// }
@set_magic_quotes_runtime(0);
Thx for great this extension
Guest
July 17th, 2007 at 1:31 am
Thx for the great extension. But it doesn’t work for me.
I use the latest version of Dokuwiki (20070626) and wordpress (2.2.1).
Is there somebody can integrate dw to wp ?
November 30th, 2007 at 1:30 am
[...] Software: Getting DokuWiki to use Wordpress Authentication (v1.2) [ thedeadone.net ] – Skal jeg en dag fÃ¥ et wiki til at arbejde sammen med WordPress, virker det her som en lovende metode. [...]
December 1st, 2007 at 1:31 am
[...] Software: Getting DokuWiki to use Wordpress Authentication – Brug samme brugerdatabase i WordPress og DokuWiki [...]
Guest
February 6th, 2008 at 5:28 pm
Will there be an update, as this very usefull work-around is not working with newer versions either of DW or WP?
Begging: germ
Administrator
February 6th, 2008 at 6:24 pm
I’m no longer using Dokuwiki on my site at all. All my energy has got swallowed up by TDOMF. But some programmers in Thaliand sent me an update which I’ve left hanging in my email based on WP 2.3.0 and DW 2007-06-26b. I haven’t validated or test the code so I never merged it. If you want I can forward you a copy of it, if you wish to try it.
Guest
February 7th, 2008 at 5:00 pm
Sure…
can you see mail mail-address (being supderduperadmin here)?
Thank you for answering that quick and offering support!
g.
Guest
February 8th, 2008 at 11:40 am
Okay… maybe I don’t need support from Thailand (even though, using newer Version of DW & WP would be nice!).
I had a major problem with this solution, as the wp-Cookies weren’t available at the dw-address. I did follow the step-by-step-guide and installed the softwares under
my-address.tld/wordpress and
my-address.tld/wiki
A simple drag & drop of dokuwiki (which is friendly supported by its structure an “installing” without relation to a one-time-fixed-place) into my-address.tld/wordpress/wiki solved the problem.
I leave this as a note for those who do not want to scroll and test around in the codes for a day, like I did ;o)
Don’t hesitate to forward me newer versions. Maybe I can do the testing for you
germ
Guest
March 27th, 2008 at 9:00 pm
Germ may not need it, I could sure use the Thailand solution! Of course, being so far ahead of the curve (yet PHP-clueless) I’m working on WordPress 2.5 and DokuWiki 2007/06/26b.
Thanks tonnes for creating this!
Fang Langford
Administrator
March 28th, 2008 at 1:29 pm
Fang Langford, I’ve sent you a copy. Hopefully you find it useful.
Guest
March 31st, 2008 at 4:31 am
I’d like to see whatever extra stuff you’ve got. I’m trying to get a current version of DW working with WP.
Thanks,
=Austin
Guest
March 31st, 2008 at 4:04 pm
Thanks Austin, I sent you an email. Let me know if you don’t get it!
Fang
Administrator
March 31st, 2008 at 4:26 pm
Thanks Fang! Saving me the effort.
BTW Did I happen to see your name on story-games.com? (I’ve started lurker there recently)
Guest
March 31st, 2008 at 5:13 pm
Yeah, that is me. I used to big on The Forge until we fell out. I’m coming back and finishing Scattershot at the same time. Roleplay-Insight is the testbed for Universe6.ScattershotGames.com I need a wiki (for game rules) and a blog (for news) and a forum (to discuss). Your excellent work has brought be a hair’s breath away from a working site.
The Thailand solution works for WordPress 2.3 and the current DokuWiki. I just need to change the authentication to WordPress 2.5
I’m not sure I can.
Fang
Guest
April 1st, 2008 at 4:58 am
Fang,
I haven’t seen anything from you in my inbox. There’s some stuff about discount v1agra in my spam folder, but nothing that seems likely.
I’m using WP 2.1.3, at least according to WP. Since I had nothing to do after posting last night, I’ve “re-developed” the wordpressauth module as a DW action plugin. (With one file copied by hand into the inc/auth dir.)
Mine doesn’t use any of the WP functions, which doesn’t bother me at the moment. I can see where being able to call get_header() and friends might be helpful for integrating the two skins together. I haven’t tried skinning DW yet, so I don’t know how much of a help/hindrance/problem that will be.
Please do re-send whatever you emailed: Austin (underscore) Hastings (at) Longacre-scm (dot) com. I’m kind of proud of my plugin, now, but I want to see how some people that know what they’re doing chose to do it.
Thanks,
=Austin
April 1st, 2008 at 1:20 pm
[...] Einziges Problem: mein DokuWiki verwendet die Authentifizierung von Wordpress mittels der wordpress.class.php, welche die Funktion wp_get_cookie_login() aufruft, die kommentarlos deprecated und ersatzlos [...]
Guest
April 1st, 2008 at 7:22 pm
It’s Austin-underscore-Hastings (at) Longacre Blah Blah Blah, right? gMail says ‘Delivery…has been delayed’. Did I mis-send?
Fang
Guest
April 1st, 2008 at 7:46 pm
[Double posted?]
Weird. I sent it to Austin-underscore-Hastings (at) Longacre-blah blah blah. gMail said, ‘Delivery…has been delayed’. My above links to my eMail; shoot me a tag and I’ll send again.
Weird.
Fang
Administrator
April 2nd, 2008 at 4:38 pm
Fang, you may have some difficulty adapting the plugin to WP2.5. I’ve read they have changed the password mechanism and I’m not sure the impact it’ll have on integrating with DokuWiki.
Administrator
April 2nd, 2008 at 4:38 pm
Austin, have you tried your plugin with Wordpress 2.5?
Guest
April 2nd, 2008 at 6:53 pm
I have not tried it with 2.5. I just (last night) upgraded my WP install to 2.3, and I am coding an installer page for the Admin menu. Once that works, I’ll ship it, and anybody who wants to can update it to 2.5 for me. All the SQL is visible in the Config Manager, so I don’t imagine it’ll be that hard.
=Austin
Guest
April 2nd, 2008 at 7:02 pm
Also, FWIW, I found this info posted at http://wordpress.org/development/2008/03/wordpress-25-brecker/
Database optimization — we haven’t changed the table layout in this release, which is one of the reasons so many plugins work fine with 2.5. We have added a few new indicies and made a few default fields more flexible based on some bottlenecks we found on WordPress.com, which now hosts 2.7 million WordPress blogs. It should be invisible to the application, just a bit faster on the database side.
Guest
April 4th, 2008 at 11:06 am
I use Mark Cunningham’s one and code portions from http://jawe.net/2008/04/01/wordpress-upgrade/ and made this dw-wordpress-auth v.1.2.3,
which works with DokuWiki rc2008-03-31 and WordPress 2.5.
download link + change log is here
http://bact.blogspot.com/2008/04/wordpress-authentication-plugin-for.html
thanks Mark and Jawe to made this possible.
July 18th, 2008 at 11:04 pm
[...] Einzig die Benutzerintegration mit einem Wiki fehlt mir noch. Für DokuWiki gibt es wohl ein Plugin (funktioniert das?), zum MediaWiki (welches ich noch historisch im Einsatz ist) habe ich allerdings [...]