Mantis 與 Dokuwiki 整合作法

  1. 先安裝好 dokuwiki,可參考 DokuWiki安裝程序(Docker)
  2. 安裝完成後的 dokuwiki 環境假設網址是 http://192.168.11.250/dokuwiki 實體路徑 /var/www/html/dokuwiki
  3. 更改 dokuwiki 系統設定檔 /var/www/html/dokuwiki/conf/local.protected.php (如果改 local.php 透過網頁介面更改就會不見)
    <?php
    /* for intergrating with Mantis */
    define( 'MANTIS_ROOT', '/var/www/html/mantis/' );
    define( 'MANTIS_URL', 'http://localhost/mantis/' );
    ?>
  4. 建立 mantis 認證程式碼 /var/www/html/dokuwiki/inc/auth/mantis.class.php
    <?php
    /**
     * Mantis auth backend
     *
     * Uses external Trust mechanism to check against Mantis'
     * user cookie.
     *
     * @author    Victor Boctor (http://www.futureware.biz)
     */
     
    require_once( MANTIS_ROOT . 'core.php' );
     
    class auth_mantis extends auth_basic {
      /**
       * Constructor.
       *
       * Sets additional capabilities and config strings
       */
      function auth_mantis(){
        $this->cando['external'] = true;
      }
     
      /**
       * Authenticates the user using Mantis APIs.
       */
      function trustExternal($user,$pass,$sticky=false){
        global $USERINFO;
        global $conf;
     
        if ( auth_is_user_authenticated() ) {
          // okay we're logged in - set the globals
          $USERINFO['pass'] = current_user_get_field( 'password' );
          $USERINFO['name'] = current_user_get_field( 'username' );
          $USERINFO['mail'] = current_user_get_field( 'email' );
     
          $t_project_name = getNS( getID() );
          $t_project_id = project_get_id_by_name( $t_project_name );
          $t_access_level = access_get_project_level( $t_project_id );
          $t_access_level_string = strtoupper( get_enum_to_string( config_get( 'access_levels_enum_string' ),  $t_access_level ) );
     
          $USERINFO['grps'] = array( $t_access_level_string );
     
          $_SERVER['REMOTE_USER'] = $USERINFO['name'];
          $_SESSION[$conf['title']]['auth']['user'] = $USERINFO['name'];
          $_SESSION[$conf['title']]['auth']['info'] = $USERINFO;
     
          return true;
        }
     
        // to be sure
        auth_logoff();
     
        return false;
      }
     
      /**
       * Logout from Mantis
       */
      function logOff(){
            auth_logout();
      }
     
      /**
       * Retrieves the user data of the user identified by                                                                                                                                                        
       * username $user. This is used, e.g., by dokuwiki's
       * email notification feature.
       */
      function getUserData( $user ) {
        $userData = false;
        $mantis_uid = user_get_id_by_name( $user );
        if ( $mantis_uid ) {
          $userData['username'] = user_get_field( $mantis_uid, 'username' );
          $userData['mail'] = user_get_field( $mantis_uid, 'email' );
     
          $t_project_name = getNS( getID() );
          $t_project_id = project_get_id_by_name( $t_project_name );
          $t_access_level = access_get_project_level( $t_project_id , $mantis_uid );
          $t_access_level_string = strtoupper( get_enum_to_string( config_get( 'access_levels_enum_string' ),  $t_access_level ) );
     
          $userData['grps'] = array( $t_access_level_string );
        }
     
        return $userData;
      }
    }
    ?>
  5. 修改權限檔 /var/www/html/dokuwiki/conf/acl.auth.php
    :
    *       @ALL            0
    *       @VIEWER         1
    *       @REPORTER       2
    *       @DEVELOPER      8
    *       @MANAGER        8
    *       @ADMINISTRATOR  8
  6. 增加 Mantis Syntax Plug-in /var/www/html/dokuwiki/lib/plugins/mantis/syntax.php
    mkdir /var/www/html/dokuwiki/lib/plugins/mantis
    cd /var/www/html/dokuwiki/lib/plugins/mantis
    vi 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;
        }
    }
    ?>
  7. 透過 dokuwiki 原本設定介面來更動 /var/www/html/dokuwiki/conf/local.php
    1. Use access control lists → 打勾(應該已經打勾)
    2. Authentication backend → mantis(上面的步驟完成才會出現 mantis 選項)
    3. Default group → VIEWER
    4. Superuser → @ADMINISTRATOR
    5. 確認 /var/www/html/dokuwiki/conf/local.php 內應該要出現以下的設定值
      $conf['useacl'] = 1;
      $conf['authtype'] = 'mantis';
      $conf['defaultgroup'] = 'VIEWER';
      $conf['superuser'] = '@ADMINISTRATOR';
經過以上的設定,只要在 mantis 內登入, dokuwiki 也會依據 mantis 的身份權限出現在 dokuwiki 系統內
  1. Mantis 設定檔啟用 dokuwiki 整合定義 /var/www/html/mantis/config_inc.php
    :
    :
    	#####################
    	# Wiki Integration
    	#####################
     
    	# Wiki Integration Enabled?
    	$g_wiki_enable = ON;
     
    	# Wiki Engine
    	$g_wiki_engine = 'dokuwiki';
     
    	# Wiki namespace to be used as root for all pages relating to this mantis installation.
    	$g_wiki_root_namespace = 'mantis';
     
    	# URL under which the wiki engine is hosted.  Must be on the same server.
    	$g_wiki_engine_url = $t_protocol . '://' . $t_host . '/%wiki_engine%/';
  2. 其餘相關檔案 /var/www/html/mantis/core/wiki_api.php、wiki_dokuwiki_api.php、html_api.php 以及 /var/www/html/mantis/wiki.php 在 1.1.1 版本已經包含在內,不需要自己額外再建立
經過這樣的設定,Mantis 的檢視 Bug 頁面就會出現 wiki 可以直接連結整合的項目
  • tech/mantisdokuwiki.txt
  • 上一次變更: 2009/03/03 01:00
  • jonathan