Sajaki has posted an updated PHPBB3 to WikkaWiki bridge here: https://github.com/Sajaki/Wikkamod
<<
::c::
=====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
- WikkaWithphpBB / WikkaWithphpBB3
- UrduWeb
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:
- phpBB takes full responsibility for User management (Register, Log in, Log out, Change Profile, etc.)
- Output the Wiki through the phpBB Template System (So you can change your global layout at a central place and everything looks equal)
- Using phpBB Groups to controll Access to wikipages
- Separation between Wikka and phpBB files
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:
%%(php)
/**
* Start session.
*/
$base_url_path = preg_replace('/wikka\.php/', '', $_SERVER['SCRIPT_NAME']);%%
Replace With:
%%(php)
/**
* 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:
%%(php)
/**
* Save session ID
*/
$user = $wakka->GetUser();%%
Afterwards add:
%%(php)
// 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:
%%(php)
$etag = md5($content);
header('ETag: '.$etag);
header('Content-Length: '.$page_length);
ob_end_clean();
/**
* Output the page
*/
echo $page_output;
?>%%
Replace with:
%%(php)
/* 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:
%%(php)
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:
%%(php)
/* 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:
%%(php)
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:
%%(php)
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:
%%(php) // 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
* see http://wikkawiki.org/WikkaWithphpBB3
*/
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
* see http://wikkawiki.org/WikkaWithphpBB3
*/
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
* @return true => Member, false => Not Member
*/
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:
%%(php)
function GetUser() { return (isset($_SESSION["user"])) ? $_SESSION["user"] : NULL; }%%
Replace with:
%%(php)
/* BEGIN phpBB3 Integration
* original:
* function GetUser() { return (isset($_SESSION["user"])) ? $_SESSION["user"] : NULL; }
*/
function GetUser() { global $phpbb_username; return ($phpbb_username != 'anonymous') ? $this->LoadUser($this->getOwnWikkaName($phpbb_username)) : NULL ;}
// END phpBB3 Integration%%
Find:
%%(php)
case "+":
// return ($registered) ? !$negate : false;
return ($registered) ? !$negate : $negate;
// aha! a user entry.
default:
if ($line == $user)
{
return !$negate;
}%%
Replace with:
%%(php)
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 /wikka/plugins/templates/default/ . Copy all folders inside /wikka/templates/default/ to /wikka/plugins/templates/default/ . Create the file footer.php with the following content:
%%(php)
%%
===/wikka/images/*===
Move all images to /images
====How to use====
===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===
As you might have noticed, english is not my native language so if someone who is more familiar with it can have a closer look at this document to wipe out typos or strange grammar, thanks in advance!
====Todo====
- 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
- Introduce this modification at http://wikkawiki.org/WikkaIntegration