Automatic URL linking to MediaWiki and ViewVC from Mantis

From ASCEND
Revision as of 13:29, 13 May 2010 by UploadBot (talk | contribs) (Restored page from Google Cache, uploaded by John Pye)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The ASCEND project uses Mantis for our bug tracker combined with Mediawiki (for our wiki) and ViewVC for our subversion code browser. We have but 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. This page gives info on how ViewVC can be tweaked to give that ability.


This screenshot shows links to our code browser and wiki as they appear in Mantis:

Patch file

This patch file should be applied to the file core/string_api.php in the Mantis distribution. This patch was recently tested with Mantis 1.1.6 and still works (on our current installation, click below).

--- 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>". " [<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&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