Added RFC link magic, similar to ISBN magic
authorJens Frank <jeluf@users.mediawiki.org>
Sat, 6 Mar 2004 21:30:42 +0000 (21:30 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Sat, 6 Mar 2004 21:30:42 +0000 (21:30 +0000)
includes/Parser.php
includes/Tokenizer.php
languages/Language.php

index b10367c..98c0d55 100644 (file)
@@ -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 = "<a href='{$url}'{$la}>RFC {$rfc}</a>{$x}";
+                       }
+               } else {
+                       $text = "RFC ";
+               }
                return $text;
        }
 
index 96df633..1556dd4 100644 (file)
@@ -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
index be6bdad..fcd1371 100644 (file)
@@ -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"
 
+
 );
 
 #--------------------------------------------------------------------------