Revision [21178]

This is an old revision of IntegrationWithphpBB3 made by MartinLuelf on 2010-04-24 10:53:52.

 

Integrating Wikka into PHPBB 3.x


Introduction


I'm running a phpBB Forum with a lot of users and would like to have an additional Wiki documentation and a few generic pages. They should look like normal pages and only very few users need access to the wiki behind it (edit, revisions etc.) Most of the Users only need read access but on different hierarchical levels which correlate with the forum hierarchy, so I want to use my Forumgroups for access control.

There are already two Solutions for this Problem
The first one reads the phpBB usertable and enables forumusers to login into wikka, but you have to log in into both systems, they look different and you have to manage permissions in both systems. In short: You have two systems running in parallel instead of one bigger system.
The second seems to go a step further but unfortunately the English page of the website is not reachable anymore and neither Google, nor any of the people around me can translate the Urdu version into a language I can understand. So there is no way for me to get these files.

So I have to pick up the first solution and modify it for my needs. Here is what I want:

As I am very familiar with phpBB but quite new to Wikka I will try to put Wikka into phpBB and not the other way round.
So lets start!

Versions:

Wikka: 1.2 (other versions might work as well)
phpBB: 3.0.7-PL1 (all versions with major release 3.0 should work, newer major releases (e.g. 3.1.*) might work. phpBB2 or phpBB4 won't work without modification)

At the time of writing (2010-04-23) these are the newest stable Versions.

Files

Download a phpBB Release and unzip it to your document root (I will use / to reffer to this folder from now on). Get a Wikka Release and unzip it in a subfolder called /wikka. Run both Setups.

/wikka/wikka.php

Find:
/**
 * Start session.
 */

$base_url_path = preg_replace('/wiki\.php/', '', $_SERVER['SCRIPT_NAME']);

Replace With:
/**
 * Start session.
 */

/* BEGIN phpBB3 Integration
 * original: $base_url_path = preg_replace('/wikka\.php/', '', $_SERVER['SCRIPT_NAME']);
 */

$base_url_path = preg_replace('/wiki\.php/', '', $_SERVER['SCRIPT_NAME']);
// END phpBB3 Integration


Find:
/**
 * Save session ID
 */

$user = $wakka->GetUser();

Afterwards add:
// BEGIN phpBB3 Integration
// TODO I am pretty sure that one of the three following ifs is to much, but without them login does not work or the user keeps loggin in and our on every refresh
// If we have a user logged in, do the usernames of the both systems match?
if($phpbb_username != $wakka->getOwnBBName($user['name']))
{
    // No, so prepare wikka to load the phpBB3 user
    $user = NULL;
}

// Does wikka still needs a Usersession and the user is already logged in into phpBB3?
if(NULL == $user && $phpbb_username != 'anonymous')
{
    // Yes, a phpBB3 user is logged in, but wikka dowsn't know yet. So change it!
    $user = $wakka->LoadUser($wakka->getOwnWikkaName($phpbb_username));
    // Did we load a user?
    if(NULL != $user)
    {
        // Yes, let wikka log him in
        $wakka->SetUser($user);
    }
}

// Do we have a wikka user but there is no phpBB3 Session?
if(!$user_phpbb->data['is_registered'] && $user != NULL)
{
    // Yes, let wikka perform a logout
    $wakka->LogoutUser();
    $user = NULL;
}
// END phpBB3 Integration


Find:
$etag =  md5($content);
header('ETag: '.$etag);

header('Content-Length: '.$page_length);
ob_end_clean();

/**
 * Output the page
 */

echo $page_output;
?>

Replace with:
/* BEGIN phpBB3 Integration
 * original:
 *   $etag =  md5($content);
 *   header('ETag: '.$etag);
 *   header('Content-Length: '.$page_length);
 * END phpBB3 Integration */


ob_end_clean();

/**
 * Output the page.
 */

/* BEGIN phpBB3 Integration
 * original:
 *   echo $page_output;
 * END phpBB3 Integration */

?>


/wikka/actions/highscores.php

(From: WikkaWithphpBB3 )

Find:
    switch($rank)
{
    case 'edits':  
    $label= 'edits';
    $query = 'SELECT COUNT(*) AS cnt, `name`  FROM '.$this->GetConfigValue('table_prefix').'users, '.$this->GetConfigValue('table_prefix').'pages WHERE `name` = `user` GROUP BY name ORDER BY cnt DESC LIMIT '.$limit;
    $total = $this->getCount('pages');
    break;
       
    case 'comments':
    $label= 'comments';
    $query = 'SELECT COUNT(*) AS cnt, `name`  FROM '.$this->GetConfigValue('table_prefix').'users, '.$this->GetConfigValue('table_prefix').'comments WHERE `name` = `user` GROUP BY name ORDER BY cnt DESC LIMIT '.$limit; 
    $total = $this->getCount('comments');
    break; 

    default:
    case 'pages':
    $label= 'pages owned';
    $query = 'SELECT COUNT(*) AS cnt, `name`  FROM '.$this->GetConfigValue('table_prefix').'users, '.$this->GetConfigValue('table_prefix').'pages WHERE `name` = `owner` AND `latest` = "Y" GROUP BY name ORDER BY cnt DESC LIMIT '.$limit;
    $total = $this->getCount('pages', "`latest` = 'Y'");
    break;
}

Replace with:
/* BEGIN phpBB3 Integration
 * original:
 *  switch($rank)
 *  {
 *      case 'edits':  
 *      $label= 'edits';
 *      $query = 'SELECT COUNT(*) AS cnt, `name`  FROM '.$this->GetConfigValue('table_prefix').'users, '.$this->GetConfigValue('table_prefix').'pages WHERE `name` = `user` GROUP BY name ORDER BY cnt DESC LIMIT '.$limit;
 *      $total = $this->getCount('pages');
 *      break;
 *         
 *      case 'comments':
 *      $label= 'comments';
 *      $query = 'SELECT COUNT(*) AS cnt, `name`  FROM '.$this->GetConfigValue('table_prefix').'users, '.$this->GetConfigValue('table_prefix').'comments WHERE `name` = `user` GROUP BY name ORDER BY cnt DESC LIMIT '.$limit; 
 *      $total = $this->getCount('comments');
 *      break; 
 * 
 *      default:
 *      case 'pages':
 *      $label= 'pages owned';
 *      $query = 'SELECT COUNT(*) AS cnt, `name`  FROM '.$this->GetConfigValue('table_prefix').'users, '.$this->GetConfigValue('table_prefix').'pages WHERE `name` = `owner` AND `latest` = "Y" GROUP BY name ORDER BY cnt DESC LIMIT '.$limit;
 *      $total = $this->getCount('pages', "`latest` = 'Y'");
 *      break;
 *  }
 */

/**
  * Contributed by Paul Young, using the example code by JeremyCoates
  * see http://wikkawiki.org/WikkaWithphpBB3
  */

switch($rank)
{
    case 'edits':  
    $label= 'edits';
    $query = 'SELECT COUNT(*) AS cnt, `username` AS name FROM phpbb3_users '.$this->GetConfigValue('table_prefix').'pages WHERE `username` = `user` GROUP BY username ORDER BY cnt DESC LIMIT '.$limit;
    $total = $this->getCount('pages');
    break;
       
    case 'comments':
    $label= 'comments';  
    $query = 'SELECT COUNT(*) AS cnt, `username` AS name FROM phpbb3_users '.$this->GetConfigValue('table_prefix').'comments WHERE `username` = `user` GROUP BY username ORDER BY cnt DESC LIMIT '.$limit;  
    $total = $this->getCount('comments');
    break;  

    default:
    case 'pages':
    $label= 'pages owned';
    $query = 'SELECT COUNT(*) AS cnt, `username` AS name FROM phpbb3_users '.$this->GetConfigValue('table_prefix').'pages WHERE `username` = `owner` AND `latest` = "Y" GROUP BY username ORDER BY cnt DESC LIMIT '.$limit;  
    $total = $this->getCount('pages', "`latest` = 'Y'");
    break;
}
// END phpBB3 Integration


/wikka/actions/usersetting.php

(From: WikkaWithphpBB3 )

Find:
            default: // input is valid
                $this->Query('UPDATE '.$this->config['table_prefix'].'users SET '.
                    "email = '".mysql_real_escape_string($email)."', ".
                    "doubleclickedit = '".mysql_real_escape_string($doubleclickedit)."', ".
                    "show_comments = '".mysql_real_escape_string($show_comments)."', ".
                    "revisioncount = '".mysql_real_escape_string($revisioncount)."', ".
                    "changescount = '".mysql_real_escape_string($changescount)."', ".
                    "theme = '".mysql_real_escape_string($usertheme)."' ".
                    "WHERE name = '".$user['name']."' LIMIT 1");
                $this->SetUser($this->LoadUser($user["name"]));

                // forward
                $params .= 'stored=true';
                $this->Redirect($url.$params);

Replace with:
default: // input is valid
               /* BEGIN phpBB3 Integration
                * original:
                *   $this->Query('UPDATE '.$this->config['table_prefix'].'users SET '.
                *       "email = '".mysql_real_escape_string($email)."', ".
                *       "doubleclickedit = '".mysql_real_escape_string($doubleclickedit)."', ".
                *       "show_comments = '".mysql_real_escape_string($show_comments)."', ".
                *       "revisioncount = '".mysql_real_escape_string($revisioncount)."', ".
                *       "changescount = '".mysql_real_escape_string($changescount)."', ".
                *       "theme = '".mysql_real_escape_string($usertheme)."' ".
                *       "WHERE name = '".$user['name']."' LIMIT 1");
                */

                $tmpUser = $this->LoadUser($user['name']);
                if (is_null($tmpUser['show_comments'])) {
                    $this->Query("INSERT INTO ".$this->config['table_prefix']."users SET ".
                        "signuptime = '".mysql_real_escape_string($user['signuptime'])."',".
                        "name = '".mysql_real_escape_string($user['name'])."', ".
                        "email = '".mysql_real_escape_string($user['email'])."'");
                }
                // END phpBB3 Integration
               
                $this->SetUser($this->LoadUser($user["name"]));

                // forward
                $params .= 'stored=true';
                $this->Redirect($url.$params);


/wikka/libs/Wakka.class.php

(With parts from: WikkaWithphpBB3 )

Find:
    // USERS
    function LoadUser($name, $password = 0) { return $this->LoadSingle("select * from ".$this->config['table_prefix']."users where name = '".mysql_real_escape_string($name)."' ".($password === 0 ? "" : "and password = '".mysql_real_escape_string($password)."'")." limit 1"); }
    function LoadUsers() { return $this->LoadAll("select * from ".$this->config['table_prefix']."users order by name"); }

Replace with:
    // USERS
    /* BEGIN phpBB3 Integration
     * original:
     *   function LoadUser($name, $password = 0) { return $this->LoadSingle("select * from ".$this->config['table_prefix']."users where name = '".mysql_real_escape_string($name)."' ".($password === 0 ? "" : "and password = '".mysql_real_escape_string($password)."'")." limit 1"); }
     *   function LoadUsers() { return $this->LoadAll("select * from ".$this->config['table_prefix']."users order by name"); }
     */

      * Contributed by Paul Young, using the example code by JeremyCoates
     function LoadUser($name, $password = 0) {
        $user = $this->LoadSingle("SELECT " .
            "CONCAT('".$this->config['user_prefix']."', p.username_clean) as name, " .
            "p.user_password as password, " .
            "p.user_email as email, " .
            "p.user_regdate as signuptime, " .
            "w.revisioncount, " .
            "w.changescount, " .
            "w.doubleclickedit, " .
            "w.show_comments " .
            "FROM ".phpbb3_."users p " .
            "left join " . $this->config['table_prefix'] . "users w ON p.username = w.name " .
            "WHERE p.username_clean = '".mysql_real_escape_string($this->getOwnBBName($name))."' and p.user_type != 1 limit 1");      
        // If we have a signuptime, format it!
        if (isset($user['signuptime'])) {
            $user['signuptime'] = date('Y-m-d H:i:s', $user['signuptime']);
        }
        return $user;
     }
   
      * Contributed by Paul Young, using the example code by JeremyCoates
     function LoadUsers() {
        $users = $this->LoadAll("SELECT " .
            "CONCAT('".$this->config['user_prefix']."', p.username_clean) as name, " .
            "p.user_password as password, " .
            "p.user_email as email, " .
            "p.user_regdate as signuptime, " .
            "w.revisioncount, " .
            "w.changescount, " .
            "w.doubleclickedit, " .
            "w.show_comments " .
            "FROM ".phpbb3_."users p " .
            "left join " . $this->config['table_prefix'] . "users w ON CONCAT('".$this->config['user_prefix']."', p.username_clean) = w.name " .
            "WHERE p.user_type != 1 AND p.user_type != 2 " .
            "ORDER BY username");
       
        foreach ($users as $key => $user) {
            // If we have a signuptime, format it!
            if (isset($user['signuptime'])) {
                $user['signuptime'] = date('Y-m-d H:i:s', $user['signuptime']);
            }
            // Save the changes into the array
            $users[$key] = $user;
        }
        return $users;
    }
   
     * Transform a Wikka Username into a phpBB Username (remove the user_prefix)
    function getOwnBBName($name)
    {
        $ret = substr($name, strlen($this->config['user_prefix']));
        //die('getOwnBBName('.$name.') =- '.$ret);
        return $ret;
    }
   
     * Transform a phpBB Username into a Wikka Username (add the user_prefix)
    function getOwnWikkaName($name)
    {
        return ($this->config['user_prefix'].$name);
    }
   
     * Returns wether user $who is a confirmed Member of the phpBB3 Group $group ir not
    function isGroupMember($who, $group)
    {
        $who = $this->getOwnBBName($who);
       
        $sql = 'SELECT ' .
                    'u.user_id ' .
                'FROM ' .
                    $this->config["group_table"] . ' as g, ' .
                    $this->config["user_group_table"] . ' as ug, ' .
                    $this->config["user_table"] . ' as u ' .
                'WHERE ' .
                    'g.group_id = ug.group_id AND ' .
                    'ug.user_id = u.user_id AND ' .
                    'u.username_clean = \''.strtolower($who).'\' AND ' .
                    'ug.user_pending = 0 AND ' .
                    'LOWER(g.group_name) = \''.strtolower($group).'\'';
       
        return (NULL !== $this->LoadSingle($sql));
    }
    // END phpBB3 Integration


Find:
    function GetUser() { return (isset($_SESSION["user"])) ? $_SESSION["user"] : NULL; }

Replace with:
    /* BEGIN phpBB3 Integration
     * original:
     *   function GetUser() { return (isset($_SESSION["user"])) ? $_SESSION["user"] : NULL; }
     */

    function GetUser() { global $phpbb_username; return ($phpbb_username != 'Anonymous') ? $this->getOwnWikkaName($phpbb_username) : NULL ;}
    // END phpBB3 Integration


Find:
                case "+":
                    // return ($registered) ? !$negate : false;
                    return ($registered) ? !$negate : $negate;
                // aha! a user entry.
                default:
                    if ($line == $user)
                    {
                        return !$negate;
                    }

Replace with:
                case "+":
                    // return ($registered) ? !$negate : false;
                    return ($registered) ? !$negate : $negate;
                // BEGIN phpBB3 Integration
                // group name
                case "~":
                    return ($this->isGroupMember($user, substr($line, 1))) ? !$negate : $negate;
                // END phpBB3 Integration
                // aha! a user entry.
                default:
                    if ($line == $user)
                    {
                        return !$negate;
                    }


/wikka/plugins/template/default/footer.php

Create the file (and folders in path) with the following content:
<!-- BEGIN PAGE FOOTER -->
<div id="footer">
<?php
    //page generation start
    global $tstart;
    echo $this->MakeMenu('options_menu');
    $wikka_patch_level = ($this->GetWikkaPatchLevel() == '0') ? '' : '-p'.$this->GetWikkaPatchLevel();
?>
</div>
<!-- END PAGE FOOTER -->
<!-- BEGIN SYSTEM INFO -->
<!-- END SYSTEM INFO -->
<?php
if ($this->GetConfigValue('sql_debugging'))
{
    echo '<div class="smallprint"><strong>Query log:</strong><br />'."\n";
    foreach ($this->queryLog as $query)
    {
        echo $query['query'].' ('.$query['time'].')<br />'."\n";
    }
    echo '</div>'."\n";
}
echo '<!--'.sprintf(PAGE_GENERATION_TIME, $this->microTimeDiff($tstart)).'-->'."\n";
?>
</div>
<!-- END PAGE WRAPPER -->


/wikka/plugins/templates/default/header.php

Create the file with the following content:
<?php
$message = $this->GetRedirectMessage();
$user = $this->GetUser();
$site_base = $this->GetConfigValue("base_url");
if ( substr_count($site_base, 'wikka.php?wakka=') > 0 ) $site_base = substr($site_base,0,-16);
?>
<?php
if ($this->GetMethod() != 'edit')
{
    $rsslink  = '   <link rel="alternate" type="application/rss+xml" title="'.$this->GetWakkaName().': revisions for '.$this->tag.' (RSS)" href="'.$this->Href('revisions.xml', $this->tag).'" />'."\n";
    $rsslink .= '   <link rel="alternate" type="application/rss+xml" title="'.$this->GetWakkaName().': recently edited pages (RSS)" href="'.$this->Href('recentchanges.xml', $this->tag).'" />'."\n";
    //echo $rsslink;   
}
?>
<!-- BEGIN PAGE WRAPPER -->
<div id="page">
<?php
//display system messages
if (isset($message) && strlen($message)>0)
{
    echo '<div class="success">'.$message.'</div>';
}
?>
<!-- BEGIN PAGE HEADER -->
<div id="header">
<h2><a id="homepage_link" href="<?php echo $this->href('', $this->config['root_page'], ''); ?>"><?php echo $this->config['wakka_name'];?></a> : <a href="<?php echo $this->href('backlinks', '', ''); ?>" title="Display a list of pages linking to <?php echo $this->tag ?>"><?php echo $this->GetPageTag(); ?></a></h2>
<?php echo $this->MakeMenu('main_menu'); ?>
</div>
<br style="clear:both;" />
<!-- END PAGE HEADER -->


Visit your Page / Wiki

Now you should be able to browse to your Documentroot and see the forum at example.com/index.php the wiki should be avaliable at example.com/wiki.php=Pagename

Group Permissions

You can give access to single Users just by putting their Names into the ACL just as usual (Remember to use the user_prefix, too). You can also put ~Groupname into the ACL which gives the selected rights to every confirmed Member of the phpBB Group Groupname. You can also prevent access to a certain group by negating it. E.g. put !kiddies into the ACL and all Members of kiddies can't acces the page.

URLRewrite

Up to now I did not have a detailed look at URLRewrite so if youre not sure what to do leave it disabled (leave /wikka/.htaccess untouched and set rewrite_mode to 0 in your /wikka/wikka.conf.php . If you are fammiliar with rewriting and want to enable it, please do so and document your steps in this wikipage.

Language
  • Make the large codeblocks smaller (use a scrollbar), especially the wikka.css file (any idea, how to do this?)
  • Set up a demo page
  • Try to reproduce the modification, to validate its completness
  • Other phpBB Integrations have trouble with the recent pages, check if this applies to this mod, too
  • Hav a look at the User Registration framework, like mentioned in comment #1 on WikkaWithphpBB3
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki