Index: trunk/phase3/includes/Parser.php |
— | — | @@ -2211,35 +2211,65 @@ |
2212 | 2212 | return $text; |
2213 | 2213 | } |
2214 | 2214 | |
2215 | | - # Return an HTML link for the "RFC 1234" text |
2216 | | - /* private */ function magicRFC( $text ) { |
| 2215 | + /** |
| 2216 | + * Return an HTML link for the "RFC 1234" text |
| 2217 | + * @access private |
| 2218 | + * @param string $text text to be processed |
| 2219 | + */ |
| 2220 | + function magicRFC( $text ) { |
2217 | 2221 | global $wgLang; |
| 2222 | + |
| 2223 | + $valid = '0123456789'; |
| 2224 | + $internal = false; |
2218 | 2225 | |
2219 | 2226 | $a = split( 'RFC ', ' '.$text ); |
2220 | 2227 | if ( count ( $a ) < 2 ) return $text; |
2221 | 2228 | $text = substr( array_shift( $a ), 1); |
2222 | | - $valid = '0123456789'; |
| 2229 | + |
| 2230 | + /* Check if RFC keyword is preceed by [[. |
| 2231 | + * This test is made here cause of the array_shift above |
| 2232 | + * that prevent the test to be done in the foreach. |
| 2233 | + */ |
| 2234 | + if(substr($text, -2) == '[[') { $internal = true; } |
2223 | 2235 | |
2224 | 2236 | foreach ( $a as $x ) { |
| 2237 | + /* token might be empty if we have RFC RFC 1234 */ |
| 2238 | + if($x=='') { |
| 2239 | + $text.='RFC '; |
| 2240 | + continue; |
| 2241 | + } |
| 2242 | + |
2225 | 2243 | $rfc = $blank = '' ; |
2226 | | - while ( ' ' == $x{0} ) { |
| 2244 | + |
| 2245 | + /** remove and save whitespaces in $blank */ |
| 2246 | + while ( $x{0} == ' ' ) { |
2227 | 2247 | $blank .= ' '; |
2228 | 2248 | $x = substr( $x, 1 ); |
2229 | 2249 | } |
| 2250 | + |
| 2251 | + /** remove and save the rfc number in $rfc */ |
2230 | 2252 | while ( strstr( $valid, $x{0} ) != false ) { |
2231 | 2253 | $rfc .= $x{0}; |
2232 | 2254 | $x = substr( $x, 1 ); |
2233 | 2255 | } |
2234 | 2256 | |
2235 | | - if ( '' == $rfc ) { |
| 2257 | + if ( $rfc == '') { |
| 2258 | + /* call back stripped spaces*/ |
2236 | 2259 | $text .= "RFC $blank$x"; |
| 2260 | + } elseif( $internal) { |
| 2261 | + /* normal link */ |
| 2262 | + $text .= "RFC $rfc$x"; |
2237 | 2263 | } else { |
| 2264 | + /* build the external link*/ |
2238 | 2265 | $url = wfmsg( 'rfcurl' ); |
2239 | 2266 | $url = str_replace( '$1', $rfc, $url); |
2240 | 2267 | $sk =& $this->mOptions->getSkin(); |
2241 | 2268 | $la = $sk->getExternalLinkAttributes( $url, 'RFC '.$rfc ); |
2242 | 2269 | $text .= "<a href='{$url}'{$la}>RFC {$rfc}</a>{$x}"; |
2243 | 2270 | } |
| 2271 | + |
| 2272 | + /* Check if the next RFC keyword is preceed by [[ */ |
| 2273 | + $internal = (substr($x,-2) == '[['); |
2244 | 2274 | } |
2245 | 2275 | return $text; |
2246 | 2276 | } |