From 1c757c865000e70ecd47f3775a971d29aabe6e68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 21 Jul 2005 20:58:44 +0000 Subject: [PATCH] * (bug 431) Make external URL protocols configurable in DefaultSettings --- includes/DefaultSettings.php | 5 +++++ includes/Parser.php | 10 +++++----- includes/Sanitizer.php | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 23e1f6b508..c571df2187 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -121,6 +121,11 @@ $wgTmpDirectory = "{$wgUploadDirectory}/tmp"; $wgUploadBaseUrl = ""; /**#@-*/ +/** + * The external URL protocols (regexp) + */ +$wgUrlProtcols = 'http:\/\/|https:\/\/|ftp:\/\/|irc:\/\/|gopher:\/\/|news:|mailto:'; + /** internal name of virus scanner. This servers as a key to the $wgAntivirusSetup array. * Set this to NULL to disable virus scanning. If not null, every file uploaded will be scanned for viruses. * @global string $wgAntivirus diff --git a/includes/Parser.php b/includes/Parser.php index 48f512308d..c60a76bdf4 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -47,7 +47,6 @@ define( 'STRIP_COMMENTS', 'HTMLCommentStrip' ); define( 'UNIQ_PREFIX', 'NaodW29'); # Constants needed for external link processing -define( 'URL_PROTOCOLS', 'http:\/\/|https:\/\/|ftp:\/\/|irc:\/\/|gopher:\/\/|news:|mailto:' ); define( 'HTTP_PROTOCOLS', 'http:\/\/|https:\/\/' ); # Everything except bracket, space, or control characters define( 'EXT_LINK_URL_CLASS', '[^]<>"\\x00-\\x20\\x7F]' ); @@ -55,7 +54,7 @@ define( 'EXT_LINK_URL_CLASS', '[^]<>"\\x00-\\x20\\x7F]' ); define( 'EXT_LINK_TEXT_CLASS', '[^\]\\x00-\\x1F\\x7F]' ); define( 'EXT_IMAGE_FNAME_CLASS', '[A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]' ); define( 'EXT_IMAGE_EXTENSIONS', 'gif|png|jpg|jpeg' ); -define( 'EXT_LINK_BRACKETED', '/\[(\b('.URL_PROTOCOLS.')'.EXT_LINK_URL_CLASS.'+) *('.EXT_LINK_TEXT_CLASS.'*?)\]/S' ); +define( 'EXT_LINK_BRACKETED', '/\[(\b('.$wgUrlProtcols.')'.EXT_LINK_URL_CLASS.'+) *('.EXT_LINK_TEXT_CLASS.'*?)\]/S' ); define( 'EXT_IMAGE_REGEX', '/^('.HTTP_PROTOCOLS.')'. # Protocol '('.EXT_LINK_URL_CLASS.'+)\\/'. # Hostname and path @@ -1105,11 +1104,12 @@ class Parser * @access private */ function replaceFreeExternalLinks( $text ) { + global $wgUrlProtcols; global $wgContLang; $fname = 'Parser::replaceFreeExternalLinks'; wfProfileIn( $fname ); - $bits = preg_split( '/(\b(?:'.URL_PROTOCOLS.'))/S', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); + $bits = preg_split( '/(\b(?:'.$wgUrlProtcols.'))/S', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); $s = array_shift( $bits ); $i = 0; @@ -1187,7 +1187,7 @@ class Parser * @access private */ function replaceInternalLinks( $s ) { - global $wgContLang, $wgLinkCache; + global $wgContLang, $wgLinkCache, $wgUrlProtcols; static $fname = 'Parser::replaceInternalLinks' ; wfProfileIn( $fname ); @@ -1290,7 +1290,7 @@ class Parser # Don't allow internal links to pages containing # PROTO: where PROTO is a valid URL protocol; these # should be external links. - if (preg_match('/^(\b(?:'.URL_PROTOCOLS.'))/', $m[1])) { + if (preg_match('/^(\b(?:'.$wgUrlProtcols.'))/', $m[1])) { $s .= $prefix . '[[' . $line ; continue; } diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index 2b5910862f..88cc440bd0 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -525,6 +525,7 @@ class Sanitizer { * @todo Check for unique id attribute :P */ function fixTagAttributes( $text, $element ) { + global $wgUrlProtcols; if( trim( $text ) == '' ) { return ''; } @@ -571,7 +572,7 @@ class Sanitizer { 'PMID' => 'PMID', ) ); $value = preg_replace( - '/(' . URL_PROTOCOLS . '):/', + '/(' . $wgUrlProtcols . '):/', '\\1:', $value ); // If this attribute was previously set, override it. -- 2.20.1