* (bug 431) Make external URL protocols configurable in DefaultSettings
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Thu, 21 Jul 2005 20:58:44 +0000 (20:58 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Thu, 21 Jul 2005 20:58:44 +0000 (20:58 +0000)
includes/DefaultSettings.php
includes/Parser.php
includes/Sanitizer.php

index 23e1f6b..c571df2 100644 (file)
@@ -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
index 48f5123..c60a76b 100644 (file)
@@ -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;
                        }
index 2b59108..88cc440 100644 (file)
@@ -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' => '&#80;MID',
                        ) );
                        $value = preg_replace(
-                               '/(' . URL_PROTOCOLS . '):/',
+                               '/(' . $wgUrlProtcols . '):/',
                                '\\1&#58;', $value );
                        
                        // If this attribute was previously set, override it.