MediaWiki r9670 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r9669‎ | r9670 (on ViewVC)‎ | r9671 >
Date:06:34, 26 June 2005
Author:timstarling
Status:old
Tags:
Comment:
Made a SiteConfiguration object generally available. Added functions for performing an HTTP client request using curl. This will be used in the SpamBlacklist extension, and hopefully Lucene as well.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 9669)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 9670)
@@ -17,6 +17,13 @@
 	die( "This file is part of MediaWiki and is not a valid entry point\n" );
 }
 
+/** 
+ * Create a site configuration object
+ * Not used for much in a default install
+ */ 
+require_once( 'includes/SiteConfiguration.php' );
+$wgConf = new SiteConfiguration;
+
 /** MediaWiki version number */
 $wgVersion			= '1.5beta1';
 
@@ -1540,5 +1547,9 @@
  */
 $wgAllowSpecialInclusion = true;
 
+/**
+ * Timeout for HTTP requests done via CURL
+ */
+$wgHTTPTimeout = 3;
 
 ?>
Index: trunk/phase3/includes/HttpFunctions.php
===================================================================
--- trunk/phase3/includes/HttpFunctions.php	(revision 0)
+++ trunk/phase3/includes/HttpFunctions.php	(revision 9670)
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * Get the contents of a file by HTTP
+ * 
+ * if $timeout is 'default', $wgHTTPTimeout is used
+ */
+function wfGetHTTP( $url, $timeout = 'default' ) {
+	global $wgServer, $wgHTTPTimeout;
+	
+
+	# Use curl if available
+	if ( function_exists( 'curl_init' ) ) {
+		$c = curl_init( $url );
+		if ( wfIsLocalURL( $url ) ) {
+			curl_setopt( $c, CURLOPT_PROXY, 'localhost:80' );
+		}
+		if ( $timeout == 'default' ) {
+			$timeout = $wgHTTPTimeout;
+		}
+		curl_setopt( $c, CURLOPT_TIMEOUT, $timeout );
+		ob_start();
+		curl_exec();
+		$text = ob_get_contents();
+		ob_end_clean();
+	} else {
+		# Otherwise use file_get_contents, or its compatibility function from GlobalFunctions.php
+		# This may take 3 minutes to time out, and doesn't have local fetch capabilities
+		$url_fopen = ini_set( 'allow_url_fopen', 1 );
+		$text = file_get_contents( $url );
+		ini_set( 'allow_url_fopen', $url_fopen );
+	}
+	return $text;
+}
+
+/**
+ * Check if the URL can be served by localhost
+ */
+function wfIsLocalURL( $url ) {
+	global $wgConf;
+	// Extract host part
+	if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) {
+		$host = $matches[1];
+		// Split up dotwise
+		$domainParts = explode( '.', $host );
+		// Check if this domain or any superdomain is listed in $wgConf as a local virtual host
+		$domainParts = array_reverse( $domainParts );
+		for ( $i = 0; $i < count( $domainParts ); $i++ ) {
+			$domainPart = $domainParts[$i];
+			if ( $i == 0 ) {
+				$domain = $domainPart;
+			} else {
+				$domain = $domainPart . '.' . $domain;
+			}
+			if ( $wgConf->isLocalVHost( $domain ) ) {
+				return true;
+			}
+		}
+	}
+	return false;
+}
+
+?>

Property changes on: trunk/phase3/includes/HttpFunctions.php
___________________________________________________________________
Added: svn:eol-style
   + native
Added: svn:keywords
   + Author Date Id Revision

Index: trunk/phase3/includes/SiteConfiguration.php
===================================================================
--- trunk/phase3/includes/SiteConfiguration.php	(revision 9669)
+++ trunk/phase3/includes/SiteConfiguration.php	(revision 9670)
@@ -1,8 +1,6 @@
 <?php
 /**
- *This file is used to configure the live Wikimedia wikis. The file that
- * includes it contains passwords and other sensitive data, and there's
- * currently no public equivalent.
+ * This is a class used to hold configuration settings, particularly for multi-wiki sites. 
  *
  * @package MediaWiki
  */
@@ -21,8 +19,11 @@
 define('SITE_CONFIGURATION', 1);
 
 class SiteConfiguration {
-	var $suffixes, $wikis, $settings;
-	var $localDatabases;
+	var $suffixes = array();
+	var $wikis = array();
+	var $settings = array();
+	var $localDatabases = array();
+	var $localVHosts = array();
 	
 	function get( $setting, $wiki, $suffix, $params = array() ) {
 		if ( array_key_exists( $wiki, $this->settings[$setting] ) ) {
@@ -92,6 +93,10 @@
 		}
 		return array( $site, $lang );
 	}
+
+	function isLocalVHost( $vhost ) {
+		return in_array( $vhost, $this->localVHosts );
+	}
 }
 }
 	

Status & tagging log

  • 01:56, 13 October 2010 ^demon (Talk | contribs) changed the status of r9670 [removed: new added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox