r11582 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r11581‎ | r11582 | r11583 >
Date:11:24, 30 October 2005
Author:avar
Status:old
Tags:
Comment:
* Rewrote the url protocol thing to not suck
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -1498,4 +1498,20 @@
14991499 function in_string( $needle, $str ) {
15001500 return strpos( $str, $needle ) !== false;
15011501 }
 1502+
 1503+/**
 1504+ * Returns a regular expression of url protocols
 1505+ *
 1506+ * @return string
 1507+ */
 1508+function wfUrlProtocols() {
 1509+ global $wgUrlProtocols;
 1510+
 1511+ $x = array();
 1512+ foreach ($wgUrlProtocols as $protocol)
 1513+ $x[] = preg_quote( $protocol, '/' );
 1514+
 1515+ return implode( '|', $x );
 1516+}
 1517+
15021518 ?>
Index: trunk/phase3/includes/Parser.php
@@ -54,7 +54,7 @@
5555 define( 'EXT_LINK_TEXT_CLASS', '[^\]\\x00-\\x1F\\x7F]' );
5656 define( 'EXT_IMAGE_FNAME_CLASS', '[A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]' );
5757 define( 'EXT_IMAGE_EXTENSIONS', 'gif|png|jpg|jpeg' );
58 -define( 'EXT_LINK_BRACKETED', '/\[(\b('.$wgUrlProtocols.')'.EXT_LINK_URL_CLASS.'+) *('.EXT_LINK_TEXT_CLASS.'*?)\]/S' );
 58+define( 'EXT_LINK_BRACKETED', '/\[(\b(' . wfUrlProtocols() . ')'.EXT_LINK_URL_CLASS.'+) *('.EXT_LINK_TEXT_CLASS.'*?)\]/S' );
5959 define( 'EXT_IMAGE_REGEX',
6060 '/^('.HTTP_PROTOCOLS.')'. # Protocol
6161 '('.EXT_LINK_URL_CLASS.'+)\\/'. # Hostname and path
@@ -1121,12 +1121,11 @@
11221122 * @access private
11231123 */
11241124 function replaceFreeExternalLinks( $text ) {
1125 - global $wgUrlProtocols;
11261125 global $wgContLang;
11271126 $fname = 'Parser::replaceFreeExternalLinks';
11281127 wfProfileIn( $fname );
11291128
1130 - $bits = preg_split( '/(\b(?:'.$wgUrlProtocols.'))/S', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
 1129+ $bits = preg_split( '/(\b(?:' . wfUrlProtocols() . '))/S', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
11311130 $s = array_shift( $bits );
11321131 $i = 0;
11331132
@@ -1208,7 +1207,7 @@
12091208 * @access private
12101209 */
12111210 function replaceInternalLinks( $s ) {
1212 - global $wgContLang, $wgLinkCache, $wgUrlProtocols;
 1211+ global $wgContLang, $wgLinkCache;
12131212 static $fname = 'Parser::replaceInternalLinks' ;
12141213
12151214 wfProfileIn( $fname );
@@ -1310,7 +1309,7 @@
13111310 # Don't allow internal links to pages containing
13121311 # PROTO: where PROTO is a valid URL protocol; these
13131312 # should be external links.
1314 - if (preg_match('/^(\b(?:'.$wgUrlProtocols.'))/', $m[1])) {
 1313+ if (preg_match('/^(\b(?:' . wfUrlProtocols() . '))/', $m[1])) {
13151314 $s .= $prefix . '[[' . $line ;
13161315 continue;
13171316 }
@@ -1406,7 +1405,7 @@
14071406 $text = $this->replaceInternalLinks($text);
14081407
14091408 # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
1410 - $s .= $prefix . preg_replace("/\b($wgUrlProtocols)/", UNIQ_PREFIX."NOPARSE$1", $this->makeImage( $nt, $text) ) . $trail;
 1409+ $s .= $prefix . preg_replace( "/\b(" . wfUrlProtocols() . ')/', UNIQ_PREFIX."NOPARSE$1", $this->makeImage( $nt, $text) ) . $trail;
14111410 $wgLinkCache->addImageLinkObj( $nt );
14121411
14131412 wfProfileOut( "$fname-image" );
Index: trunk/phase3/includes/Sanitizer.php
@@ -525,7 +525,6 @@
526526 * @todo Check for unique id attribute :P
527527 */
528528 function fixTagAttributes( $text, $element ) {
529 - global $wgUrlProtocols;
530529 if( trim( $text ) == '' ) {
531530 return '';
532531 }
@@ -585,7 +584,7 @@
586585
587586 # Stupid hack
588587 $value = preg_replace_callback(
589 - '/(' . $wgUrlProtocols . ')/',
 588+ '/(' . wfUrlProtocols() . ')/',
590589 array( 'Sanitizer', 'armorLinksCallback' ),
591590 $value );
592591
Index: trunk/phase3/includes/Skin.php
@@ -1272,8 +1272,7 @@
12731273 # If url string starts with http, consider as external URL, else
12741274 # internal
12751275 /*static*/ function makeInternalOrExternalUrl( $name ) {
1276 - global $wgUrlProtocols;
1277 - if ( preg_match( '/^(?:' . $wgUrlProtocols . ')/', $name ) ) {
 1276+ if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
12781277 return $name;
12791278 } else {
12801279 return $this->makeUrl( $name );

Status & tagging log