From 7e7069ea43ac71aad6601259bdbc94a4b1b70edb Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Sat, 6 Mar 2004 20:04:25 +0000 Subject: [PATCH] Moved ISBN magic to new parser --- includes/Parser.php | 36 ++++++++++++++++++++++++++---------- includes/Tokenizer.php | 2 ++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index a76f4d4271..b10367cb31 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -416,7 +416,7 @@ class Parser $text = $this->replaceInternalLinks ( $text ); $text = $this->doTableStuff ( $text ) ; - $text = $this->magicISBN( $text ); + #$text = $this->magicISBN( $text ); $text = $this->magicRFC( $text ); $text = $this->formatHeadings( $text ); @@ -656,6 +656,9 @@ class Parser # empty token $txt=""; break; + case "ISBN ": + $txt = $this->doMagicISBN( $tokenizer ); + break; default: # Call language specific Hook. $txt = $wgLang->processToken( $token, $tokenStack ); @@ -1304,35 +1307,48 @@ class Parser return $full; } - /* private */ function magicISBN( $text ) + /* private */ function doMagicISBN( &$tokenizer ) { global $wgLang; - $a = split( "ISBN ", " $text" ); - if ( count ( $a ) < 2 ) return $text; - $text = substr( array_shift( $a ), 1); - $valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + # Check whether next token is a text token + # If yes, fetch it and convert the text into a + # Special::BookSources link + $token = $tokenizer->previewToken(); + while ( $token["type"] == "" ) + { + $tokenizer->nextToken(); + $token = $tokenizer->previewToken(); + } + if ( $token["type"] == "text" ) + { + $token = $tokenizer->nextToken(); + $x = $token["text"]; + $valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - foreach ( $a as $x ) { $isbn = $blank = "" ; while ( " " == $x{0} ) { $blank .= " "; $x = substr( $x, 1 ); } - while ( strstr( $valid, $x{0} ) != false ) { + while ( strstr( $valid, $x{0} ) != false ) { $isbn .= $x{0}; $x = substr( $x, 1 ); } $num = str_replace( "-", "", $isbn ); $num = str_replace( " ", "", $num ); - + if ( "" == $num ) { $text .= "ISBN $blank$x"; } else { $titleObj = Title::makeTitle( NS_SPECIAL, "Booksources" ); - $text .= "getUrl( "isbn={$num}", false, true ) . "\" class=\"internal\">ISBN $isbn"; + $text .= "getUrl( "isbn={$num}", false, true ) . + "\" class=\"internal\">ISBN $isbn"; $text .= $x; } + } else { + $text = "ISBN "; } return $text; } diff --git a/includes/Tokenizer.php b/includes/Tokenizer.php index beeda47466..96df63314a 100644 --- a/includes/Tokenizer.php +++ b/includes/Tokenizer.php @@ -38,6 +38,8 @@ class Tokenizer { } # Closing link $regex .= "|\]\]"; + # Magic words that automatically generate links + $regex .= "|ISBN "; # Language-specific additions $regex .= $wgLang->tokenizerRegex(); # Finalize regex -- 2.20.1