close
Mantis + Dokuwiki + Subversion + Active Directory - Part 3
整合 Dokuwiki, 並使用 Mantis 的認證系統, 以讓 Mantis 裡面個別的 Issue, Project 可以有自己的 Wiki.
1. 設定 Mantis Wiki 整合
#
# 編輯 config_inc.php 以打開 wiki 整合功能
#
cd /var/www/html/mantis
cp config_inc.php config_inc.php.`date +"%Y%m%d%H%M%S"`
sed -i 's/?>//g' config_inc.php
cat << EOF >> config_inc.php
# Dokuwiki
\$g_wiki_enable = ON;
\$g_wiki_engine = 'dokuwiki';
\$g_wiki_root_namespace = 'mantis';
\$g_wiki_engine_url = \$t_protocol . '://' . \$t_host . '/' . \$g_wiki_engine . '/';
?>
EOF
2. 安裝 Dokuwiki
# # 假設: # 1. Dokuwiki 版本是 2012-01-25a, 檔名是 dokuwiki-2012-01-25a.tgz # cd ~ wget http://www.splitbrain.org/_media/projects/dokuwiki/dokuwiki-2012-01-25a.tgz cd /var/www/html tar -xvzf ~/dokuwiki-2012-01-25a.tgz mv dokuwiki-2012-01-25a dokuwiki chown -R apache.apache dokuwiki
2. 設定 Dokuwiki
- 用瀏覽器打開 Dokuwiki 網址: https://<mantis 的 hostname or ip>/dokuwiki/install.php
- 填入必要資訊
- 按 "儲存" 結束設定
3. 移除 install.php
# # 移除 install.php # rm -f /var/www/html/dokuwiki/install.php
4. 安裝 WYSIWYG
- 取得 WYSIWYG 下載網址
- 以瀏覽器打開網址 http://www.dokuwiki.org
- 找到需要的 Plugins (Fckglite plugin) (注意!! 要留意 Plugin 有無相容於目前安裝的 Dokuwiki 版本), 並複製檔案的網址連結

- 安裝 WYSIWYG 插件
- 以瀏覽器打開網址 https://<mantis 的 hostname or ip>/dokuwiki
- 按 "登入", 出現登入畫面後, 輸入尚一個步驟設定的帳號與密碼 (例如 MantisAdmin) 登入
- 進入插件管理器, 貼上上面步驟複製的 Fckglite plugin 下載網址 (http://www.mturner.org/fckgLite/data/media/current/fckgLite.tgz) 後, 按 "下載"

5. 設定 Dokuwiki 使用外部認證 (Mantis)
編輯 /var/www/html/dokuwiki/conf/local.protected.php
#
# 設定 local.protected.php
#
cd /var/www/html/dokuwiki/conf
cat << EOF > local.protected.php
<?php
define( 'MANTIS_ROOT', '/var/www/html/mantis/' );
define( 'MANTIS_URL', 'https://<Mantis 的 Hostname or IP>/mantis/' );
require_once( MANTIS_ROOT . 'core.php' );
?>
EOF
chown apache.apache local.protected.php
編輯 /var/www/html/dokuwiki/conf/acl.auth.php
# # 設定 acl.auth.php # cd /var/www/html/dokuwiki/conf cp acl.auth.php acl.auth.php.`date +"%Y%m%d%H%M%S"` cat << EOF > acl.auth.php # acl.auth.php # <?php exit()?> # Don't modify the lines above # # Access Control Lists # # Auto-generated by install script # Date: Tue, 27 Dec 2011 06:35:00 +0000 : * @VIEWER 1 * @REPORTER 2 * @UPDATER 4 * @DEVELOPER 8 * @MANAGER 16 * @ADMINISTRATOR 16 * @ALL 0 EOF chown apache.apache acl.auth.php
編輯 /var/www/html/dokuwiki/inc/auth/mantis.class.php
#
# 設定 mantis.class.php
#
cd /var/www/html/dokuwiki/inc/auth
cat << EOF > mantis.class.php
<?php
/**
* Mantis auth backend
*
* Uses external Trust mechanism to check against Mantis'
* user cookie.
* 13/12/2009 ~ @Tiago Gomes:
* added modifications to make possible to set project related user rights.(http://www.mantisbt.org/bugs/view.php?id=8249)
* added modifications so that mantis support logging in/out from DokuWiki's login page (http://www.mantisbt.org/bugs/view.php?id=8277)
*
*
* @author Victor Boctor (http://www.futureware.biz)
*
*/
require_once( MANTIS_ROOT . 'core.php' );
#dbg(\$GLOBALS);
class auth_mantis extends auth_basic {
/**
* Constructor.
*
* Sets additional capabilities and config strings
*/
function auth_mantis(){
\$this->cando['external'] = true;
\$this->cando['logoff' ] = true; // module has a logoff method
}
/**
* Authenticates the user using Mantis APIs.
*/
function trustExternal(\$user,\$pass,\$sticky=false){
global \$USERINFO;
global \$conf;
\$ValidUser = false;
// Manage HTTP authentication with Negotiate protocol enabled
\$user = auth_prepare_username(\$user);
\$pass = auth_prepare_password(\$pass);
// This is necessary in all cases where Authorization HTTP header is always set
if(auth_is_user_authenticated())
{
\$user='';
}
// Has a user name been provided?
if ( !empty ( \$user ) )
{
// User name provided, so login via form in progress...
// Are the specified user name and password valid?
if ( auth_attempt_login ( \$user, \$pass, \$sticky ) )
{
// Credential accepted...
\$_SERVER['REMOTE_USER'] = \$user; // Set the user name (makes things work...)
\$ValidUser = true; // Report success.
}
else
{
// Invalid credentials
if ( !\$silent )
{
msg ( \$lang [ 'badlogin' ], -1 );
}
\$ValidUser = false;
}
}
else
{
// No user name provided.
// Is a user already logged in?
if ( auth_is_user_authenticated ( ) )
{
// Yes, a user is logged in, so set the globals...
// is it a media display or a page?
if (isset(\$_REQUEST['media'])) {
//media
\$t_project_name = explode( ':', getNS( getID("media",false) ) );
} else {
// normal page
\$t_project_name = explode( ':', getNS( getID() ) );
}
\$t_project_id = project_get_id_by_name( \$t_project_name[1] );
\$t_access_level = access_get_project_level( \$t_project_id );
\$t_access_level_string = strtoupper( MantisEnum::getLabel( config_get( 'access_levels_enum_string' ), \$t_access_level ) ); // mantis 1.2.0rc
// \$t_access_level_string = strtoupper( get_enum_to_string( config_get( 'access_levels_enum_string' ), \$t_access_level ) );
\$t_access_level_string_ex = strtoupper( \$t_project_name[1] ) . '_' . \$t_access_level_string;
\$USERINFO['grps'] = array( \$t_access_level_string, \$t_access_level_string_ex );
\$USERINFO[ 'pass' ] = current_user_get_field ( 'password' );
\$USERINFO[ 'name' ] = current_user_get_field ( 'username' );
\$USERINFO[ 'mail' ] = current_user_get_field ( 'email' );
\$_SERVER[ 'REMOTE_USER' ] = \$USERINFO[ 'name' ];
\$_SESSION[ \$conf[ 'title' ]][ 'auth' ][ 'user' ] = \$USERINFO[ 'name' ];
\$_SESSION[ \$conf[ 'title' ]][ 'auth' ][ 'info' ] = \$USERINFO;
\$ValidUser = true;
}
else
{
\$ValidUser = false;
}
}
// Is there a valid user login?
if ( true != \$ValidUser )
{
// No, so make sure any existing authentication is revoked.
auth_logoff ( );
}
return \$ValidUser;
}
/**
* Logout from Mantis
*/
function logOff(){
auth_logout();
}
}
EOF
chown apache.apache mantis.class.php
編輯 /var/www/html/dokuwiki/lib/plugins/mantis/syntax.php
mkdir -p /var/www/html/dokuwiki/lib/plugins/mantis
cd /var/www/html/dokuwiki/lib/plugins/mantis
cp syntax.php syntax.php.`date +"%Y%m%d%H%M%S"`
cat << EOF > syntax.php
<?php
/**
* Mantis Plugin: Hyperlinks references to Mantis Issues
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Victor Boctor (http://www.futureware.biz)
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
/**
* A plug-in that hyper links references to Mantis issues. References
* to Mantis issues should use the following format: ~~Mantis:123~~.
*
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_mantis extends DokuWiki_Syntax_Plugin {
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Victor Boctor',
'email' => 'vboctor at users . sourceforge . net',
'date' => '2006-05-18',
'name' => 'Mantis Issues Plugin',
'desc' => 'Support References to Mantis Issues',
'url' => 'http://www.futureware.biz',
);
}
/**
* What kind of syntax are we?
*/
function getType(){
return 'substition'; # typo is intentional
}
/**
* What about paragraphs?
*/
function getPType(){
return 'normal';
}
/**
* Where to sort in?
*/
function getSort(){
return 156;
}
/**
* Connect pattern to lexer
*/
function connectTo(\$mode) {
\$this->Lexer->addSpecialPattern('~~Mantis:[0-9]+~~', \$mode, 'plugin_mantis');
}
/**
* Handle the match
*/
function handle(\$match, \$state, \$pos, &\$handler){
\$match = substr( \$match, 9, -2 ); // strip "~~Mantis:" from start and "~~" from end
return array( strtolower( \$match ) );
}
/**
* Create output
*/
function render(\$format, &\$renderer, \$data) {
if ( \$format == 'xhtml' ) {
\$renderer->externallink( MANTIS_URL . 'view.php?id=' . \$data[0], \$data[0] );
return true;
}
return false;
}
}
EOF
chown apache.apache syntax.php
編輯 /var/www/html/dokuwiki/conf/local.php
cd /var/www/html/dokuwiki/conf cp local.php local.php.`date +"%Y%m%d%H%M%S"` sed -i 's/@admin/@ADMINISTRATOR/g' local.php cat << EOF >> local.php \$conf['authtype'] = 'mantis'; \$conf['defaultgroup'] = 'VIEWER'; EOF
5. 測試
Site Wiki
Project Wiki
Issue Wiki
建立 Wiki 內容
Wiki 內容
全站熱搜
留言列表

