From 92a3bdd55954f40e3cf10df45c18779c9d6d9940 Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Sat, 6 Mar 2004 21:30:42 +0000 Subject: [PATCH] Added RFC link magic, similar to ISBN magic --- includes/Parser.php | 47 ++++++++++++++++++++++++++++++++++++++---- includes/Tokenizer.php | 2 +- languages/Language.php | 2 ++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index b10367cb31..98c0d55828 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -416,8 +416,6 @@ class Parser $text = $this->replaceInternalLinks ( $text ); $text = $this->doTableStuff ( $text ) ; - #$text = $this->magicISBN( $text ); - $text = $this->magicRFC( $text ); $text = $this->formatHeadings( $text ); $sk =& $this->mOptions->getSkin(); @@ -656,6 +654,9 @@ class Parser # empty token $txt=""; break; + case "RFC ": + $txt = $this->doMagicRFC( $tokenizer ); + break; case "ISBN ": $txt = $this->doMagicISBN( $tokenizer ); break; @@ -1352,9 +1353,47 @@ class Parser } return $text; } - - /* private */ function magicRFC( $text ) + /* private */ function doMagicRFC( &$tokenizer ) { + global $wgLang; + + # Check whether next token is a text token + # If yes, fetch it and convert the text into a + # link to an RFC source + $token = $tokenizer->previewToken(); + while ( $token["type"] == "" ) + { + $tokenizer->nextToken(); + $token = $tokenizer->previewToken(); + } + if ( $token["type"] == "text" ) + { + $token = $tokenizer->nextToken(); + $x = $token["text"]; + $valid = "0123456789"; + + $rfc = $blank = "" ; + while ( " " == $x{0} ) { + $blank .= " "; + $x = substr( $x, 1 ); + } + while ( strstr( $valid, $x{0} ) != false ) { + $rfc .= $x{0}; + $x = substr( $x, 1 ); + } + + if ( "" == $rfc ) { + $text .= "RFC $blank$x"; + } else { + $url = wfmsg( "rfcurl" ); + $url = str_replace( "$1", $rfc, $url); + $sk =& $this->mOptions->getSkin(); + $la = $sk->getExternalLinkAttributes( $url, "RFC {$rfc}" ); + $text = "RFC {$rfc}{$x}"; + } + } else { + $text = "RFC "; + } return $text; } diff --git a/includes/Tokenizer.php b/includes/Tokenizer.php index 96df63314a..1556dd4799 100644 --- a/includes/Tokenizer.php +++ b/includes/Tokenizer.php @@ -39,7 +39,7 @@ class Tokenizer { # Closing link $regex .= "|\]\]"; # Magic words that automatically generate links - $regex .= "|ISBN "; + $regex .= "|ISBN |RFC "; # Language-specific additions $regex .= $wgLang->tokenizerRegex(); # Finalize regex diff --git a/languages/Language.php b/languages/Language.php index be6bdad8a3..fcd1371b75 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1078,6 +1078,7 @@ sell new and used books, and may also have further information about books you are looking for. $wgSitename is not affiliated with any of these businesses, and this list should not be construed as an endorsement.", +"rfcurl" => "http://www.faqs.org/rfcs/rfc$1.html", "alphaindexline" => "$1 to $2", "version" => "Version", @@ -1397,6 +1398,7 @@ amusement.", "thumbnail-more" => "Enlarge" + ); #-------------------------------------------------------------------------- -- 2.20.1