r10229 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10228‎ | r10229 | r10230 >
Date:20:58, 21 July 2005
Author:avar
Status:old
Tags:
Comment:
* (bug 431) Make external URL protocols configurable in DefaultSettings
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -47,7 +47,6 @@
4848 define( 'UNIQ_PREFIX', 'NaodW29');
4949
5050 # Constants needed for external link processing
51 -define( 'URL_PROTOCOLS', 'http:\/\/|https:\/\/|ftp:\/\/|irc:\/\/|gopher:\/\/|news:|mailto:' );
5251 define( 'HTTP_PROTOCOLS', 'http:\/\/|https:\/\/' );
5352 # Everything except bracket, space, or control characters
5453 define( 'EXT_LINK_URL_CLASS', '[^]<>"\\x00-\\x20\\x7F]' );
@@ -55,7 +54,7 @@
5655 define( 'EXT_LINK_TEXT_CLASS', '[^\]\\x00-\\x1F\\x7F]' );
5756 define( 'EXT_IMAGE_FNAME_CLASS', '[A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]' );
5857 define( 'EXT_IMAGE_EXTENSIONS', 'gif|png|jpg|jpeg' );
59 -define( 'EXT_LINK_BRACKETED', '/\[(\b('.URL_PROTOCOLS.')'.EXT_LINK_URL_CLASS.'+) *('.EXT_LINK_TEXT_CLASS.'*?)\]/S' );
 58+define( 'EXT_LINK_BRACKETED', '/\[(\b('.$wgUrlProtcols.')'.EXT_LINK_URL_CLASS.'+) *('.EXT_LINK_TEXT_CLASS.'*?)\]/S' );
6059 define( 'EXT_IMAGE_REGEX',
6160 '/^('.HTTP_PROTOCOLS.')'. # Protocol
6261 '('.EXT_LINK_URL_CLASS.'+)\\/'. # Hostname and path
@@ -1105,11 +1104,12 @@
11061105 * @access private
11071106 */
11081107 function replaceFreeExternalLinks( $text ) {
 1108+ global $wgUrlProtcols;
11091109 global $wgContLang;
11101110 $fname = 'Parser::replaceFreeExternalLinks';
11111111 wfProfileIn( $fname );
11121112
1113 - $bits = preg_split( '/(\b(?:'.URL_PROTOCOLS.'))/S', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
 1113+ $bits = preg_split( '/(\b(?:'.$wgUrlProtcols.'))/S', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
11141114 $s = array_shift( $bits );
11151115 $i = 0;
11161116
@@ -1187,7 +1187,7 @@
11881188 * @access private
11891189 */
11901190 function replaceInternalLinks( $s ) {
1191 - global $wgContLang, $wgLinkCache;
 1191+ global $wgContLang, $wgLinkCache, $wgUrlProtcols;
11921192 static $fname = 'Parser::replaceInternalLinks' ;
11931193
11941194 wfProfileIn( $fname );
@@ -1290,7 +1290,7 @@
12911291 # Don't allow internal links to pages containing
12921292 # PROTO: where PROTO is a valid URL protocol; these
12931293 # should be external links.
1294 - if (preg_match('/^(\b(?:'.URL_PROTOCOLS.'))/', $m[1])) {
 1294+ if (preg_match('/^(\b(?:'.$wgUrlProtcols.'))/', $m[1])) {
12951295 $s .= $prefix . '[[' . $line ;
12961296 continue;
12971297 }
Index: trunk/phase3/includes/Sanitizer.php
@@ -525,6 +525,7 @@
526526 * @todo Check for unique id attribute :P
527527 */
528528 function fixTagAttributes( $text, $element ) {
 529+ global $wgUrlProtcols;
529530 if( trim( $text ) == '' ) {
530531 return '';
531532 }
@@ -571,7 +572,7 @@
572573 'PMID' => '&#80;MID',
573574 ) );
574575 $value = preg_replace(
575 - '/(' . URL_PROTOCOLS . '):/',
 576+ '/(' . $wgUrlProtcols . '):/',
576577 '\\1&#58;', $value );
577578
578579 // If this attribute was previously set, override it.
Index: trunk/phase3/includes/DefaultSettings.php
@@ -121,6 +121,11 @@
122122 $wgUploadBaseUrl = "";
123123 /**#@-*/
124124
 125+/**
 126+ * The external URL protocols (regexp)
 127+ */
 128+$wgUrlProtcols = 'http:\/\/|https:\/\/|ftp:\/\/|irc:\/\/|gopher:\/\/|news:|mailto:';
 129+
125130 /** internal name of virus scanner. This servers as a key to the $wgAntivirusSetup array.
126131 * Set this to NULL to disable virus scanning. If not null, every file uploaded will be scanned for viruses.
127132 * @global string $wgAntivirus

Status & tagging log