r3254 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r3253‎ | r3254 | r3255 >
Date:23:52, 21 April 2004
Author:jeluf
Status:old
Tags:
Comment:
fixed prefixed links (for arabic wikipedia)
Modified paths:
  • /trunk/phase3/includes/Tokenizer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Tokenizer.php
@@ -8,8 +8,11 @@
99
1010 /* private */ function Tokenizer()
1111 {
 12+ global $wgLang;
 13+
1214 $this->mPos=0;
1315 $this->mTokenQueue=array();
 16+ $this->linkPrefixExtension = $wgLang->linkPrefixExtension();
1417 }
1518
1619 # factory function
@@ -54,8 +57,7 @@
5558 // proceeds character by character through the text, looking for characters needing
5659 // special attention. Those are currently: I, R, ', [, ], newline
5760 //
58 - // TODO: prefixed links for Arabic wikipedia not implemented yet
59 - // handling of French blanks not yet implemented
 61+ // TODO: handling of French blanks not yet implemented
6062 function nextToken()
6163 {
6264 $fname = "Tokenizer::nextToken";
@@ -64,8 +66,8 @@
6567 if ( count( $this->mQueuedToken ) != 0 ) {
6668 // still one token from the last round around. Return that one first.
6769 $token = array_shift( $this->mQueuedToken );
68 - } else if ( $this->mPos > $this->mTextLength )
69 - { // If no text is left, return "false".
 70+ } else if ( $this->mPos > $this->mTextLength ) {
 71+ // If no text is left, return "false".
7072 $token = false;
7173 } else {
7274
@@ -98,8 +100,21 @@
99101 $this->mPos += 3;
100102 break 2; // switch + while
101103 } else if ( $this->continues("[") ) {
102 - $queueToken["type"] = "[[";
 104+ $queueToken["type"] = "[[";
103105 $queueToken["text"] = "";
 106+ // Check for a "prefixed link", e.g. Al[[Khazar]]
 107+ // Mostly for arabic wikipedia
 108+ if ( $this->linkPrefixExtension ) {
 109+ while ( $this->linkPrefixExtension
 110+ && ($len = strlen( $token["text"] ) ) > 0
 111+ && !ctype_space( $token["text"][$len-1] ) )
 112+ {
 113+ //prepend the character to the link's open tag
 114+ $queueToken["text"] = $token["text"][$len-1] . $queueToken["text"];
 115+ //remove character from the end of the text token
 116+ $token["text"] = substr( $token["text"], 0, -1);
 117+ }
 118+ }
104119 $this->mQueuedToken[] = $queueToken;
105120 $this->mPos += 2;
106121 break 2; // switch + while
@@ -158,7 +173,7 @@
159174
160175 // function continues
161176 // checks whether the mText continues with $cont from mPos+1
162 - function continues( $cont )
 177+ /* private */ function continues( $cont )
163178 {
164179 // If string is not long enough to contain $cont, return false
165180 if ( $this->mTextLength < $this->mPos + strlen( $cont ) )

Status & tagging log