View Issue Details

IDProjectCategoryView StatusLast Update
0008757mantisbtintegrationpublic2012-04-11 06:29
Reporterfoo Assigned Tovboctor  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version1.1.0 
Fixed in Version1.2.0a1 
Summary0008757: Add wiki integration for TWiki
Description

Attached is my first stab at TWiki integration, based off the xwiki code. I've tested it against TWiki 4.1.2 and Mantis 1.1.0, and everything seems to work for me.

To make the TWiki integration, well, more TWiki-like, I used the following formatting conventions:

  • Issue links look like IssueNumber$bug_id (IssueNumber123), so TWiki doesn't complain that it's not a valid WikiWord.
  • Project links try a few ways to make the project name into a WikiWord, in this order:
    • Removing whitespace (My Project => MyProject).
    • Uppercasing words (my project => MyProject).
    • Prepending the string 'ProjectName' (XYZ => ProjectNameXYZ).

The last one is kinda ghetto, but was the only thing I could think of right off that would make acronyms, single words, or numeric project names into valid WikiWords. I figure it's worth the trade off of not having all the existing TWiki users complain that the titles won't link.

Tagswiki
Attached Files
wiki_twiki_api.php (3,352 bytes)   
<?php
# Mantis - a php based bugtracking system

# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net

# Mantis is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Mantis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
 
	# --------------------------------------------------------
	# $Id: 
	# --------------------------------------------------------

	# ----------------------
	# Gets the URL for the page with the specified page id.  This function is used
	# internally by this API.
	function wiki_twiki_get_url_for_page_id( $p_page_id ) {
		$t_root_url = config_get_global( 'wiki_engine_url' );
		return $t_root_url . $p_page_id ;
	}
 
	# ----------------------
	# Gets the page id for the specified issue.  The page id can then be converted
	# to a URL using wiki_twiki_get_url_for_page_id().
	function wiki_twiki_get_page_id_for_issue( $p_issue_id ) {
		 
		$t_project_id = project_get_name (bug_get_field( $p_issue_id, 'project_id' ));
		$c_issue_id = 'IssueNumber' . db_prepare_int( $p_issue_id );
		return $c_issue_id;
 		return $t_project_id.'/'.$c_issue_id;
	}
 
 	# ----------------------
	# Gets the page url for the specified issue id.
	function wiki_twiki_get_url_for_issue( $p_issue_id ) {
		return wiki_twiki_get_url_for_page_id( wiki_twiki_get_page_id_for_issue( $p_issue_id ) );
	}
 
	# ----------------------
	# Gets the page id for the specified project.  The project id can be ALL_PROJECTS
	# The page id can then be converted to URL using wiki_twiki_get_url_for_page_id().
	function wiki_twiki_get_page_id_for_project( $p_project_id ) {
		if ( $p_project_id == ALL_PROJECTS ) {
			return config_get( 'wiki_root_namespace' );
		} else {
			$t_project_name = project_get_name( $p_project_id );
			$wikiword_regex = '/^[A-Z][^A-Z]+[A-Z]+.*$/';
			
			// Normalize (remove) all whitespace
			$project_name_normalized = preg_replace('/\s\s*/', '', $t_project_name);
			// Try uppercasing each word first
			$project_name_uppercased = preg_replace('/\s\s*/', '', ucwords($t_project_name));
			// Then try adding 'ProjectName' to the front
			$project_name_prepended = "ProjectName" . preg_replace('/\s\s*/', '', ucwords($t_project_name));
			
			// See if normalized name looks like a WikiWord
			if (preg_match($wikiword_regex, $project_name_normalized, $matches)){
				return $project_name_normalized;
			}elseif (preg_match($wikiword_regex, $project_name_uppercased, $matches)){
				return $project_name_uppercased;
			}else {
				return $project_name_prepended;
			}
		}
	}
 
 	# ----------------------
	# Get URL for the specified project id.  The project is can be ALL_PROJECTS.
	function wiki_twiki_get_url_for_project( $p_project_id ) {
		return wiki_twiki_get_url_for_page_id( wiki_twiki_get_page_id_for_project( $p_project_id ) );
	}
?>
wiki_twiki_api.php (3,352 bytes)   
wiki_twiki_api_v2.php (3,181 bytes)   
<?php
# Mantis - a php based bugtracking system

# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net

# Mantis is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Mantis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
 
	# --------------------------------------------------------
	# $Id: 
	# --------------------------------------------------------

	# ----------------------
	# Gets the URL for the page with the specified page id.  This function is used
	# internally by this API.
	function wiki_twiki_get_url_for_page_id( $p_page_id ) {
		$t_root_url = config_get_global( 'wiki_engine_url' );
		$t_wiki_namespace = config_get( 'wiki_root_namespace' );
		return $t_root_url . $t_wiki_namespace . '/' . $p_page_id ;
	}
 
	# ----------------------
	# Gets the page id for the specified issue.  The page id can then be converted
	# to a URL using wiki_twiki_get_url_for_page_id().
	function wiki_twiki_get_page_id_for_issue( $p_issue_id ) {
		return 'IssueNumber' . db_prepare_int( $p_issue_id );
	}
 
 	# ----------------------
	# Gets the page url for the specified issue id.
	function wiki_twiki_get_url_for_issue( $p_issue_id ) {
		return wiki_twiki_get_url_for_page_id( wiki_twiki_get_page_id_for_issue( $p_issue_id ) );
	}
 
	# ----------------------
	# Gets the page id for the specified project.  The project id can be ALL_PROJECTS
	# The page id can then be converted to URL using wiki_twiki_get_url_for_page_id().
	function wiki_twiki_get_page_id_for_project( $p_project_id ) {
		if ( $p_project_id == ALL_PROJECTS ) {
			return;
		} else {
			$t_project_name = project_get_name( $p_project_id );
			$wikiword_regex = '/^[A-Z][^A-Z]+[A-Z]+.*$/';
			
			// Normalize (remove) all whitespace
			$project_name_normalized = preg_replace('/\s\s*/', '', $t_project_name);
			if (preg_match($wikiword_regex, $project_name_normalized, $matches)){
				return $project_name_normalized;
			}

			// Try uppercasing each word first
			$project_name_uppercased = preg_replace('/\s\s*/', '', ucwords($t_project_name));
			if (preg_match($wikiword_regex, $project_name_uppercased, $matches)){
				return $project_name_uppercased;
			}

			// Then try adding 'ProjectName' to the front
			$project_name_prepended = "ProjectName" . preg_replace('/\s\s*/', '', ucwords($t_project_name));
			return $project_name_prepended;
		}
	}
 
 	# ----------------------
	# Get URL for the specified project id.  The project is can be ALL_PROJECTS.
	function wiki_twiki_get_url_for_project( $p_project_id ) {
		return wiki_twiki_get_url_for_page_id( wiki_twiki_get_page_id_for_project( $p_project_id ) );
	}
?>
wiki_twiki_api_v2.php (3,181 bytes)   
wiki_twiki_api_v3.php (3,212 bytes)   
<?php
# Mantis - a php based bugtracking system

# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2008  Mantis Team   - mantisbt-dev@lists.sourceforge.net

# Mantis is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Mantis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
 
	# --------------------------------------------------------
	# $Id: 
	# --------------------------------------------------------

	# ----------------------
	# Gets the URL for the page with the specified page id.  This function is used
	# internally by this API.
	function wiki_twiki_get_url_for_page_id( $p_page_id ) {
		$t_root_url = config_get_global( 'wiki_engine_url' );
		$t_wiki_namespace = config_get( 'wiki_root_namespace' );
		return $t_root_url . $t_wiki_namespace . '/' . $p_page_id ;
	}
 
	# ----------------------
	# Gets the page id for the specified issue.  The page id can then be converted
	# to a URL using wiki_twiki_get_url_for_page_id().
	function wiki_twiki_get_page_id_for_issue( $p_issue_id ) {
		return 'IssueNumber' . db_prepare_int( $p_issue_id );
	}
 
	# ----------------------
	# Gets the page url for the specified issue id.
	function wiki_twiki_get_url_for_issue( $p_issue_id ) {
		return wiki_twiki_get_url_for_page_id( wiki_twiki_get_page_id_for_issue( $p_issue_id ) );
	}
 
	# ----------------------
	# Gets the page id for the specified project.  The project id can be ALL_PROJECTS
	# The page id can then be converted to URL using wiki_twiki_get_url_for_page_id().
	function wiki_twiki_get_page_id_for_project( $p_project_id ) {
		if ( $p_project_id == ALL_PROJECTS ) {
			return '';
		}

		$t_project_name = project_get_name( $p_project_id );
		$wikiword_regex = '/^[A-Z][^A-Z]+[A-Z]+.*$/';

		// Normalize (remove) all whitespace
		$t_project_name_normalized = preg_replace( '/\s\s*/', '', $t_project_name );
		if ( preg_match( $wikiword_regex, $t_project_name_normalized, $matches ) ) {
			return $t_project_name_normalized;
		}

		// Try uppercasing each word first
		$t_project_name_uppercased = preg_replace( '/\s\s*/', '', ucwords( $t_project_name_normalized ) );
		if ( preg_match( $wikiword_regex, $t_project_name_uppercased, $matches ) ) {
			return $t_project_name_uppercased;
		}

		// Then try adding 'ProjectName' to the front
		$t_project_name_prepended = 'ProjectName' . preg_replace( '/\s\s*/', '', ucwords( $t_project_name_uppercased ) );
		return $t_project_name_prepended;
	}
 
	# ----------------------
	# Get URL for the specified project id.  The project is can be ALL_PROJECTS.
	function wiki_twiki_get_url_for_project( $p_project_id ) {
		return wiki_twiki_get_url_for_page_id( wiki_twiki_get_page_id_for_project( $p_project_id ) );
	}
?>
wiki_twiki_api_v3.php (3,212 bytes)   

Relationships

related to 0014146 confirmed integration with TWiki does not work out of the box 

Activities

vboctor

vboctor

2008-01-16 22:57

manager   ~0016687

  1. wiki_twiki_get_page_id_for_issue(): There are two return statements.

  2. wiki_twiki_get_page_id_for_project(): In case of ALL PROJECTS, you return the home namespace, otherwise, you return a project name without the namespace. Isn't this a problem?

  3. wiki_twiki_get_page_id_for_project(): Here you are calculating all possible alterntatives and then validating them against the regex. It would be more efficient to generate each one, validate it, if value return, otherwise, move on to generate the next, etc.

  4. I'll create the Wiki page associated with this issue. I would appreciate it, if you can update the Wiki page with the how this extensions works. Also with any steps required to activate this integration, specially if there are steps required on the TWiki side.

foo

foo

2008-01-16 23:30

reporter   ~0016688

1) Yeah, that's in wiki_xwiki_api.php as well, now that I look at it - looks like an earlier copy-paste error.

2) I was totally misusing the namespace as a default wiki page for ALL PROJECTS, because there wasn't a "home" page of sorts in my TWiki install. That was lame. I just didn't like the idea setting up a separate TWiki instance for Mantis-related pages if I didn't want to, as not all users would have that ability. I guess it would be better to do that, or define a config value for a default wiki page (called Mantis Issues, or Bug Tracking or something).

3) Good call - I'll test that and attach the fixed version tomorrow.

4) Will do.

foo

foo

2008-01-17 14:11

reporter   ~0016701

Uploaded new wiki_twiki_api.php file, which cleaned things up to properly use the wiki namespace config, address Victor's comments, and better describe how to use it. More deatails will be in the wiki.

foo

foo

2008-01-18 15:43

reporter   ~0016719

We have this running in production now, and so far so good. However, I've noticed that browsing away from Mantis can get a little annoying after a while. I added a top link back to Mantis from TWiki, but was wondering; how difficult it would be to make wiki links open in a new window?

I was thinking you could have a default config option like this:
$g_wiki_open_in_new_window = OFF;

When set to ON, wiki links would always open in a specific target, like "mantis_wiki" or something.

I know lots of people are anti-new window, but heavy users of systems like defect trackers are probably accustomed to multi-window environments. I know I'd like the option of keeping the wiki and Mantis in their own windows, and just have links open where I want them to.

Thoughts? Maybe I should put this in the forum and see what people think.

vboctor

vboctor

2008-01-20 21:24

manager   ~0016736

Thanks for putting together the wiki page.

  1. Please upload the latest API.

  2. Converting a project name into a valid WikiWord should be a reusable function in wiki_api.php that is used by all wiki engines. Any prefix used should be configurable through a configuration option.

  3. I would suggest that we look at all the existing engines and see how we can make them consistent in the approach they use to come up with the page names for projects and issues.

foo

foo

2008-01-21 10:18

reporter   ~0016745

No problem.

  1. My bad - I didn't realize I don't have delete access to this bug, so I had to choose a different filename.

  2. Trying that now, but something is driving me nuts. I set some config variables ($g_wiki_default_project_prefix, g_wiki_default_issue_prefix), but I can't read them in wiki_api.php. I'm probably misunderstanding config_get and config_get_global, but my config values keep coming back as blank strings. I tried defining them in both config_inc and config_defaults_inc; no dice.

  3. Agreed - that would make a good forum topic, to plumb folks for best practices.

foo

foo

2008-01-22 13:36

reporter   ~0016760

Ack, still don't know why the new config vars I create come back empty. Is there something else I need to do?

vboctor

vboctor

2008-02-09 21:16

manager   ~0016994

Fixed in 4984
http://mantisbt.svn.sourceforge.net/mantisbt/?rev=4984&view=rev