Greetings,
I'm convinced Drupal is the ultimate answer to my needs, with one possible exception;
Dokuwiki is exactly what I require to complete the package. So my question is,
is it possible, or has anyone else managed to get the two to talk to each other? That is;
if users are already registered in Drupal, they'll be registered in Dokuwiki, and if a user
registers in Dokuwiki, their information will be inserted into the Drupal DB, or they'll be
redirected to Drupal, where they'll start the registration process, and when completed,
they will then be registered in Dokuwiki.

I've spent that past 2 days reading/searching here, at Dokuwiki, and over the internet.
I've read hundreds of documents. I found a couple instances at Dokuwiki, and tried
them, but they were for Drupal-5.x, and wile the kind of worked. There seems
to be troubles sharing session/cookie data. Because, if I'm already logged into Drupal,
I must log on again in Dokuwiki. So something must not be woking as intended with
those.

If anyone has a solution, I'd be eternally grateful if you could share it.

Thank you for all your time and consideration.

--Chuck

P.S. Apologies if this was better suited for the modules forum.

Comments

charlie_’s picture

OK, here's what I have so far (doesn't yet work).
drupal_ext.class.php:

<?php

class auth_drupal_ext extends auth_basic {
  var $url;
  var $db_prefix = '';
  var $session_id;

  function auth_drupal_ext() {
    global $conf;

    $this->cando['external'] = true;

    // Drupal is using ini_set in the $drupal_file
    $ini = ini_get("error_reporting");
    ini_set("error_reporting", 0);

    //now we can load the file without PHP complaining
    $drupal_file = $conf['auth']['drupal']['file'];
    include ($drupal_file);

    ini_set("error_reporting", $ini);

    //Following Drupal variables are interesting for us:
    //  $db_url, $db_prefix
//    $this->url = parse_url($db_url);
    $this->url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
    $this->url['path'] = substr($this->url['path'], 1);
    $this->db_prefix = $db_prefix;

    //Decode url-encoded information in the db connection string
    $this->url['user'] = urldecode($this->url['user']);
    // Test if database url has a password.
    if(isset($this->url['pass'])) {
      $this->url['pass'] = urldecode($this->url['pass']);
    } else {
      $this->url['pass'] = '';
    }

    $this->url['host'] = urldecode($this->url['host']);
    $this->url['path'] = urldecode($this->url['path']);
    $this->session_id = ini_get('session.cookie_domain');
  }

  /**
    Strip the leading at-sign from role names.
   @param $role The original role name.
   @return string The role name without any preceding at-sign.
  */
  function _tg($role) {
    return preg_replace("/^@/", "", $role);
  }

  /**
   * Authenticate the user using Drupal session information.  User must login
   * via the Drupal interface; no login work is done here.
   *
   * @param   string  $user    Ignored.
   * @param   string  $pass    Ignored.
   * @param   bool    $sticky  Ignored.
   * @return bool             true on successful auth
   * @todo Drupal roles aren't recognized.  Only the super-user in Drupal has
   * Dokuwiki admin rights.
   */
  function trustExternal($user,$pass,$sticky=false) {
    global $conf;
    global $USERINFO;

    $logged_in = false;

    $link = mysql_connect($this->url['host'], $this->url['user'], $this->url['pass']);
    if (!$link) {
      msg('Could not connect: ' . mysql_error());
      return;
    }

    if (!mysql_select_db($this->url['path'], $link)) {
      msg('Cannot select the database: ' . mysql_error());
      mysql_close($link);
      return;
    }

    $query = 'SELECT u.uid,u.name,u.mail,s.hostname,s.timestamp FROM '.$this->db_prefix.
            'users u INNER JOIN '.$this->db_prefix.'sessions s ON u.uid=s.uid WHERE s.sid="'.
            $_COOKIE['PHPSESSID'].'" && u.status=1';

    $result = mysql_query($query);

    if ($result) {
      $tmp = mysql_fetch_row($result);
      if ($tmp) {
        $uid = $tmp[0];
        $USERINFO['name'] = $tmp[1];
        $USERINFO['mail'] = $tmp[2];
        $USERINFO['pass'] = '';

        $_SERVER['REMOTE_USER'] = $tmp[1];
        $_SESSION[DOKU_COOKIE]['auth']['user'] = $tmp[1];
        $_SESSION[DOKU_COOKIE]['auth']['buid'] = auth_browseruid();
        $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;

        /* now for the roles */
        if ($uid == 1) {/* super user, everything's allowed */
          $USERINFO['grps'] = array($this->_tg($conf['superuser']), $this->_tg($conf['defaultgroup']));
        } else {
          $query = 'SELECT r.name FROM '.$this->db_prefix.'users_roles u INNER JOIN '.
                  $this->db_prefix.'role r WHERE u.uid='.$uid.' && u.rid=r.rid';
          $result = mysql_query($query);

          if ($result) {
            $tmp = mysql_fetch_row($result);
            if ($tmp) {
              $USERINFO['grps'] = array($tmp[0], $this->_tg($conf['defaultgroup']));
            }
          } else {
            msg('Error querying the database [' . mysql_error() . ']');
          }
        }

        $logged_in = true;
      }
    } else {
      msg('Error querying the database [' . mysql_error() . ']');
    }

    mysql_close($link);

    return $logged_in;
  }
}
?>

...and here's my addition to local.php:

$conf['useacl'] = 1;
$conf['authtype'] = 'drupal_ext';
$conf['passcrypt'] = 'md5';
$conf['superuser'] = '@wiki_admin';
$conf['userewrite'] = '1';
$conf['auth']['drupal']['file'] = '/file/system/path/to/settings.php';

...lastly, here's my additions to the default Dokuwiki .htaccess file:

# drupal integration additions
RewriteCond %{QUERY_STRING} \bdo=login\b [NC]
RewriteRule ^.* /user/login [L]

RewriteCond %{QUERY_STRING} \bdo=logout\b [NC]
RewriteRule ^.* /logout [L]

Can anyone see why all this isn't working?

OH! I should also mention that I serve Drupal out of /
and I server Dokuwiki out of /wiki

Thank you for all your time and consideration.

--chuck

ey’s picture

Drupal's Session cookies aren't called PHPSESSID, at least that part of your code wouldn't work.

Old usernames: pc-wurm, Елин Й.