r10229 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r10228 | r10229 (on ViewVC) | r10230 >
Date:20:58, 21 July 2005
Author:avar
Status:new
Tags:
Comment:* (bug 431) Make external URL protocols configurable in DefaultSettings
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Parser.php
===================================================================
--- trunk/phase3/includes/Parser.php	(revision 10228)
+++ trunk/phase3/includes/Parser.php	(revision 10229)
@@ -47,7 +47,6 @@
 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_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 @@
 	 * @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 @@
 	 * @access private
 	 */
 	function replaceInternalLinks( $s ) {
-		global $wgContLang, $wgLinkCache;
+		global $wgContLang, $wgLinkCache, $wgUrlProtcols;
 		static $fname = 'Parser::replaceInternalLinks' ;
 
 		wfProfileIn( $fname );
@@ -1290,7 +1290,7 @@
 			# 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: trunk/phase3/includes/Sanitizer.php
===================================================================
--- trunk/phase3/includes/Sanitizer.php	(revision 10228)
+++ trunk/phase3/includes/Sanitizer.php	(revision 10229)
@@ -525,6 +525,7 @@
 	 * @todo Check for unique id attribute :P
 	 */
 	function fixTagAttributes( $text, $element ) {
+		global $wgUrlProtcols;
 		if( trim( $text ) == '' ) {
 			return '';
 		}
@@ -571,7 +572,7 @@
 				'PMID' => '&#80;MID',
 			) );
 			$value = preg_replace(
-				'/(' . URL_PROTOCOLS . '):/',
+				'/(' . $wgUrlProtcols . '):/',
 				'\\1&#58;', $value );
 			
 			// If this attribute was previously set, override it.
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 10228)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 10229)
@@ -121,6 +121,11 @@
 $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
Views
Toolbox