Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -469,14 +469,17 @@ |
470 | 470 | /** |
471 | 471 | * Returns a regular expression of url protocols |
472 | 472 | * |
| 473 | + * @param $includeProtocolRelative bool If false, remove '//' from the returned protocol list. |
| 474 | + * DO NOT USE this directy, use wfUrlProtocolsWithoutProtRel() instead |
473 | 475 | * @return String |
474 | 476 | */ |
475 | | -function wfUrlProtocols() { |
| 477 | +function wfUrlProtocols( $includeProtocolRelative = true ) { |
476 | 478 | global $wgUrlProtocols; |
477 | 479 | |
478 | | - static $retval = null; |
479 | | - if ( !is_null( $retval ) ) { |
480 | | - return $retval; |
| 480 | + // Cache return values separately based on $includeProtocolRelative |
| 481 | + static $retval = array( true => null, false => null ); |
| 482 | + if ( !is_null( $retval[$includeProtocolRelative] ) ) { |
| 483 | + return $retval[$includeProtocolRelative]; |
481 | 484 | } |
482 | 485 | |
483 | 486 | // Support old-style $wgUrlProtocols strings, for backwards compatibility |
— | — | @@ -484,17 +487,33 @@ |
485 | 488 | if ( is_array( $wgUrlProtocols ) ) { |
486 | 489 | $protocols = array(); |
487 | 490 | foreach ( $wgUrlProtocols as $protocol ) { |
488 | | - $protocols[] = preg_quote( $protocol, '/' ); |
| 491 | + // Filter out '//' if !$includeProtocolRelative |
| 492 | + if ( $includeProtocolRelative || $protocol !== '//' ) { |
| 493 | + $protocols[] = preg_quote( $protocol, '/' ); |
| 494 | + } |
489 | 495 | } |
490 | 496 | |
491 | | - $retval = implode( '|', $protocols ); |
| 497 | + $retval[$includeProtocolRelative] = implode( '|', $protocols ); |
492 | 498 | } else { |
493 | | - $retval = $wgUrlProtocols; |
| 499 | + // Ignore $includeProtocolRelative in this case |
| 500 | + // This case exists for pre-1.6 compatibility, and we can safely assume |
| 501 | + // that '//' won't appear in a pre-1.6 config because protocol-relative |
| 502 | + // URLs weren't supported until 1.18 |
| 503 | + $retval[$includeProtocolRelative] = $wgUrlProtocols; |
494 | 504 | } |
495 | | - return $retval; |
| 505 | + return $retval[$includeProtocolRelative]; |
496 | 506 | } |
497 | 507 | |
498 | 508 | /** |
| 509 | + * Like wfUrlProtocols(), but excludes '//' from the protocol list. Use this if |
| 510 | + * you need a regex that matches all URL protocols but does not match protocol- |
| 511 | + * relative URLs |
| 512 | + */ |
| 513 | +function wfUrlProtocolsWithoutProtRel() { |
| 514 | + return wfUrlProtocols( false ); |
| 515 | +} |
| 516 | + |
| 517 | +/** |
499 | 518 | * parse_url() work-alike, but non-broken. Differences: |
500 | 519 | * |
501 | 520 | * 1) Does not raise warnings on bad URLs (just returns false) |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -1230,7 +1230,7 @@ |
1231 | 1231 | */ |
1232 | 1232 | function doMagicLinks( $text ) { |
1233 | 1233 | wfProfileIn( __METHOD__ ); |
1234 | | - $prots = $this->mUrlProtocols; |
| 1234 | + $prots = wfUrlProtocolsWithoutProtRel(); |
1235 | 1235 | $urlChar = self::EXT_LINK_URL_CLASS; |
1236 | 1236 | $text = preg_replace_callback( |
1237 | 1237 | '!(?: # Start cases |
Index: trunk/phase3/includes/api/ApiFormatBase.php |
— | — | @@ -263,7 +263,7 @@ |
264 | 264 | // encode all comments or tags as safe blue strings |
265 | 265 | $text = preg_replace( '/\<(!--.*?--|.*?)\>/', '<span style="color:blue;"><\1></span>', $text ); |
266 | 266 | // identify URLs |
267 | | - $protos = wfUrlProtocols(); |
| 267 | + $protos = wfUrlProtocolsWithoutProtRel(); |
268 | 268 | // This regex hacks around bug 13218 (" included in the URL) |
269 | 269 | $text = preg_replace( "#(($protos).*?)(")?([ \\'\"<>\n]|<|>|")#", '<a href="\\1">\\1</a>\\3\\4', $text ); |
270 | 270 | // identify requests to api.php |
Index: trunk/extensions/CodeReview/backend/CodeCommentLinker.php |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | function link( $text ) { |
30 | 30 | # Catch links like http://www.mediawiki.org/wiki/Special:Code/MediaWiki/44245#c829 |
31 | 31 | # Ended by space or brackets (like those pesky <br /> tags) |
32 | | - $text = preg_replace_callback( '/(^|[^\w[])(' . wfUrlProtocols() . ')(' . Parser::EXT_LINK_URL_CLASS . '+)/', |
| 32 | + $text = preg_replace_callback( '/(^|[^\w[])(' . wfUrlProtocolsWithoutProtRel() . ')(' . Parser::EXT_LINK_URL_CLASS . '+)/', |
33 | 33 | array( $this, 'generalLink' ), $text ); |
34 | 34 | $text = preg_replace_callback( '/\br(\d+)\b/', |
35 | 35 | array( $this, 'messageRevLink' ), $text ); |