Automatic URL linking to MediaWiki and ViewVC from Mantis

From ASCEND
Jump to: navigation, search
Error creating thumbnail: File missing
We've got linking to bugs, changesets and code URLs
Error creating thumbnail: File missing
Also we can link to our wiki with [[links like this]]

The ASCEND project uses Mantis for our bug tracker combined with Mediawiki (for our wiki) and ViewVC for our subversion code browser. This page gives info on how ViewVC can be tweaked to give that ability.

Plugin for Mantis 1.2.x

In Mantis 1.2.x, a new plugin architecture was implemented. We needed to rewrite the old stuff. Our code is based on the BBCode plugin for Mantis 1.2.x by Kirill Krasnov.

Download Media:LinkText.tar.bz2 and unzip it into your Mantis 'plugins' directory. Then in the 'Manage' section of Mantis, turn on the plugin. You will need to edit LinkText.php because it contains specific strings for ASCEND, we haven't generalised this thing up to now.

Usage

The following text will trigger conversion to appropriate URLs:

bug 111
changeset 2222
[[page on wiki]]
[[page on wiki#section name]]
code/trunk/path/to/file.xxx
code/branches/name/path/to/file.xxx

Configuration

There are some settings that turn on/off this special formatting in emails, RSS and HTML. We need to add extra settings to allow the URLs produced to be customised. Future work.

Patch file for Mantis 1.1.x

We put in place a few of the integration tweaks listed on the mantis blog and also by Winfred Lu. However one that seemed to be missing was the ability to convert wiki links (eg '[[PageName]]') and 'changeset XXX' links into clickable URLs.

The following old patch worked with Mantis versions 1.1.x. It was last tested with Mantis 1.1.6.

--- core/string_api.php.orig	2007-11-11 00:37:10.000000000 -0500
+++ core/string_api.php	2007-11-11 00:37:18.000000000 -0500
@@ -101,6 +101,8 @@
 		$p_string = string_process_bug_link( $p_string );
 		$p_string = string_process_bugnote_link( $p_string );
 		$p_string = string_process_cvs_link( $p_string );
+        $p_string = string_process_wiki_link($p_string);
+        $p_string = string_process_changeset_link($p_string);
 		return $p_string;
 	}
@@ -143,6 +145,7 @@
 		$p_string = string_process_bug_link( $p_string, false );
 		$p_string = string_process_bugnote_link( $p_string, false );
 		$p_string = string_process_cvs_link( $p_string, false );
+        $p_string = string_process_wiki_link($p_string, false);
 		return $p_string;
 	}
@@ -230,6 +233,55 @@
 							 $p_string );
 	}
+   # Process the string, returning full HTML links to a wiki, if configured.
+
+   function string_process_wiki_link($string, $fullHTML = true) {
+       if (!config_get('wiki_link_url')) return $string;
+       if ($fullHTML) return preg_replace_callback('/\[\[(([^\]]*?))\]\]/', 'string_process_wiki_link_callback_fullhtml', $string);
+       return preg_replace_callback('/\[\[(([^\]]*?))\]\]/', 'string_process_wiki_link_callback_nohtml', $string);
+
+   }
+
+   # --------------------
+   # Subsitution callback for the regexp in string_process_wiki_link(); HTML version.
+   function string_process_wiki_link_callback_fullhtml($words) {
+       $p_url_text = $words[2];
+       $p_link = config_get('wiki_link_url').$p_url_text;
+       return '<span class="bracket-link">'. "<a href=\"$p_link\" target=\"_blank\">$p_url_text</a>". '</span> ';
+   }
+
+   # --------------------
+   # Subsitution callback for the regexp in string_process_wiki_link(); plaintext version.
+   function string_process_wiki_link_callback_nohtml($words) {
+       $p_url_text = $words[2];
+       $p_link = config_get('wiki_link_url').$p_url_text;
+       return "$p_url_text ($p_link)";
+   }
+
+   # ---------------------
+   # Process 'changeset' links to ViewCVS pages
+   function string_process_changeset_link($string, $fullHTML = true) {
+       if(!config_get('changeset_link_url'))return $string;
+       //$re = '/\b(version|revision|rev|changeset)\s+([0-9]+(\.[0-9]+)*)\b/';
+       $re = '/\b(version|revision|rev|changeset)\s+([0-9]+)\b(?!\.[0-9])/';
+       if($fullHTML)return preg_replace_callback($re,'string_process_changeset_link_callback_fullhtml', $string);
+       return preg_replace_callback($re,'string_process_changeset_link_callback_nohtml', $string);
+   }
+
+   function string_process_changeset_link_callback_fullhtml($words) {
+       $p_link_text = $words[0];
+       $p_changeset = $words[2];
+       $p_url = config_get('changeset_link_url').$p_changeset;
+       return '<span class="viewcvs-link">'. "<a href=\"$p_url\">$p_link_text</a>". "&nbsp;[<a title=\"open in a new window\" href=\"$p_url\" target=_blank>^</a>]".'</span> ';
+   }
+
+   function string_process_changeset_link_callback_nohtml($words) {
+       $p_link_text = $words[0];
+       $p_changeset = $words[2];
+       $p_url = config_get('changeset_link_url').$p_url_text;
+       return "$p_link_text ($p_url)";
+   }
+
 	# --------------------
 	# Process $p_string, looking for bug ID references and creating bug view
 	#  links for them.

Configuration settings

To make use of the above patch, you also need to edit your configuration file, config_inc.php and add the following lines:

$g_wiki_link_url = 'http://ascendwiki.cheme.cmu.edu/';

$g_changeset_link_url = 'http://ascendcode.cheme.cmu.edu/viewvc.cgi?view=rev&amp;rev=';

Obviously you will need to modify the values to suite your particular site.

Usage

Once this patch and settings changes are applied, you can make links from Mantis to Mediawiki and ViewVC as follows:

These changes discussed at [[WikiPageName]] and implemented in changeset 245

The [[WikiPageName]] link will be wikified, and the 'changeset 245' text will be converted to a link to your ViewVC site.

For an example of this on our Mantis site, see bug 297 and bug 288.

See also