#
# Patch for MediaWiki to enable the magic identifiers in Wiki.
#

--- mediawiki-1.5.3-orig/includes/Parser.php
+++ mediawiki-1.5.3/includes/Parser.php
@@ -803,6 +803,9 @@
 	 */
 	function &doMagicLinks( &$text ) {
 		$text = $this->magicISBN( $text );
+		$text = $this->magicBVW( $text, 'BugID: ', 'bugurl' );
+		$text = $this->magicBVW( $text, 'VCS: ', 'vcsurl' );
+		$text = $this->magicBVW( $text, 'Wiki: ', 'wikiurl' );
 		$text = $this->magicRFC( $text, 'RFC ', 'rfcurl' );
 		$text = $this->magicRFC( $text, 'PMID ', 'pubmedurl' );
 		return $text;
@@ -2744,6 +2747,83 @@
 	}
 
 	/**
+	 * Return an HTML link for the following texts
+	 * "BugID: 1234"
+	 * "VCS: dir/file.x"
+	 * "Wiki: article"
+	 * @access private
+	 * @param string $text text to be processed
+	 */
+	function magicBVW( $text, $keyword, $urlmsg ) {
+		global $wgLang;
+		
+		$valid = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-._';
+		$internal = false;
+
+		$a = split( $keyword, ' '.$text );
+		if ( count ( $a ) < 2 ) {
+			return $text;
+		}
+		$text = substr( array_shift( $a ), 1);
+		
+		/* Check if keyword is preceed by [[.
+		 * This test is made here cause of the array_shift above
+		 * that prevent the test to be done in the foreach.
+		 */
+		if ( substr( $text, -2 ) == '[[' ) {
+			$internal = true;
+		}
+
+		foreach ( $a as $x ) {
+			/* token might be empty if we have id: id: 1234 */
+			if ( $x=='' ) {
+				$text.=$keyword;
+				continue;
+				}
+
+			$id = $blank = '' ;
+
+			/** remove and save whitespaces in $blank */
+			while ( $x{0} == ' ' ) {
+				$blank .= ' ';
+				$x = substr( $x, 1 );
+			}
+
+			/** remove and save the target string in $id */
+			while ( strstr( $valid, $x{0} ) != false ) {
+				$id .= $x{0};
+				$x = substr( $x, 1 );
+			}
+
+			/** remove possible trailing dot from the link */
+			$len = strlen ( $id ) - 1;
+			if ( $id{$len} == '.' ) {
+				$id = substr( $id, 0, $len );
+				$x = '.' . $x;
+			}
+
+			if ( $id == '' ) {
+				/* call back stripped spaces*/
+				$text .= $keyword.$blank.$x;
+			} elseif( $internal ) {
+				/* normal link */
+				$text .= $keyword.$id.$x;
+			} else {
+				/* build the external link*/
+				$url = wfmsg( $urlmsg );
+				$url = str_replace( '$1', $id, $url);
+				$sk =& $this->mOptions->getSkin();
+				$la = $sk->getExternalLinkAttributes( $url, $keyword.$id );
+				$text .= "{$keyword}<a href='{$url}'{$la}>{$id}</a>{$x}";
+			}
+			
+			/* Check if the next keyword is preceed by [[ */
+			$internal = ( substr($x,-2) == '[[' );
+		}
+		return $text;
+	}
+
+	/**
 	 * Return an HTML link for the "RFC 1234" text
 	 *
 	 * @access private
--- mediawiki-1.5.2-orig/languages/Language.php
+++ mediawiki-1.5.2/languages/Language.php
@@ -1153,6 +1153,9 @@
 sell new and used books, and may also have further information
 about books you are looking for.",
 'isbn'	=> 'ISBN',
+'bugurl' =>  '/bugzilla/show_bug.cgi?id=$1',
+'vcsurl' =>  '/cgi-bin/cvsweb.cgi/$1/',
+'wikiurl' => '/wiki/index.php/$1',
 'rfcurl' =>  'http://www.ietf.org/rfc/rfc$1.txt',
 'pubmedurl' =>  'http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=pubmed&dopt=Abstract&list_uids=$1',
 'alphaindexline' => "$1 to $2",

