r5335 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5334‎ | r5335 | r5336 >
Date:21:41, 20 September 2004
Author:hashar
Status:old
Tags:
Comment:
Fix bug 479 : parsing [[RFC 1234]] as internal link
I forgot to commit it :(
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -2211,35 +2211,65 @@
22122212 return $text;
22132213 }
22142214
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 ) {
22172221 global $wgLang;
 2222+
 2223+ $valid = '0123456789';
 2224+ $internal = false;
22182225
22192226 $a = split( 'RFC ', ' '.$text );
22202227 if ( count ( $a ) < 2 ) return $text;
22212228 $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; }
22232235
22242236 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+
22252243 $rfc = $blank = '' ;
2226 - while ( ' ' == $x{0} ) {
 2244+
 2245+ /** remove and save whitespaces in $blank */
 2246+ while ( $x{0} == ' ' ) {
22272247 $blank .= ' ';
22282248 $x = substr( $x, 1 );
22292249 }
 2250+
 2251+ /** remove and save the rfc number in $rfc */
22302252 while ( strstr( $valid, $x{0} ) != false ) {
22312253 $rfc .= $x{0};
22322254 $x = substr( $x, 1 );
22332255 }
22342256
2235 - if ( '' == $rfc ) {
 2257+ if ( $rfc == '') {
 2258+ /* call back stripped spaces*/
22362259 $text .= "RFC $blank$x";
 2260+ } elseif( $internal) {
 2261+ /* normal link */
 2262+ $text .= "RFC $rfc$x";
22372263 } else {
 2264+ /* build the external link*/
22382265 $url = wfmsg( 'rfcurl' );
22392266 $url = str_replace( '$1', $rfc, $url);
22402267 $sk =& $this->mOptions->getSkin();
22412268 $la = $sk->getExternalLinkAttributes( $url, 'RFC '.$rfc );
22422269 $text .= "<a href='{$url}'{$la}>RFC {$rfc}</a>{$x}";
22432270 }
 2271+
 2272+ /* Check if the next RFC keyword is preceed by [[ */
 2273+ $internal = (substr($x,-2) == '[[');
22442274 }
22452275 return $text;
22462276 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r5551Fix problem with RFC magic links, as noted at bug 479wmahan17:59, 26 September 2004
r9617* Marking the two RFC testcases as being parsertests for bug 479avar12:56, 24 June 2005
r17481Fix parserTests regression introduced in r17479....nickj06:03, 8 November 2006

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r5327bug 479 : parsing [[RFC 1234]] as internal linkhashar15:54, 20 September 2004

Status & tagging log