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
@@ -17,6 +17,13 @@
1818 die( "This file is part of MediaWiki and is not a valid entry point\n" );
1919 }
2020
 21+/**
 22+ * Create a site configuration object
 23+ * Not used for much in a default install
 24+ */
 25+require_once( 'includes/SiteConfiguration.php' );
 26+$wgConf = new SiteConfiguration;
 27+
2128 /** MediaWiki version number */
2229 $wgVersion = '1.5beta1';
2330
@@ -1540,5 +1547,9 @@
15411548 */
15421549 $wgAllowSpecialInclusion = true;
15431550
 1551+/**
 1552+ * Timeout for HTTP requests done via CURL
 1553+ */
 1554+$wgHTTPTimeout = 3;
15441555
15451556 ?>
Index: trunk/phase3/includes/HttpFunctions.php
@@ -0,0 +1,63 @@
 2+<?php
 3+
 4+/**
 5+ * Get the contents of a file by HTTP
 6+ *
 7+ * if $timeout is 'default', $wgHTTPTimeout is used
 8+ */
 9+function wfGetHTTP( $url, $timeout = 'default' ) {
 10+ global $wgServer, $wgHTTPTimeout;
 11+
 12+
 13+ # Use curl if available
 14+ if ( function_exists( 'curl_init' ) ) {
 15+ $c = curl_init( $url );
 16+ if ( wfIsLocalURL( $url ) ) {
 17+ curl_setopt( $c, CURLOPT_PROXY, 'localhost:80' );
 18+ }
 19+ if ( $timeout == 'default' ) {
 20+ $timeout = $wgHTTPTimeout;
 21+ }
 22+ curl_setopt( $c, CURLOPT_TIMEOUT, $timeout );
 23+ ob_start();
 24+ curl_exec();
 25+ $text = ob_get_contents();
 26+ ob_end_clean();
 27+ } else {
 28+ # Otherwise use file_get_contents, or its compatibility function from GlobalFunctions.php
 29+ # This may take 3 minutes to time out, and doesn't have local fetch capabilities
 30+ $url_fopen = ini_set( 'allow_url_fopen', 1 );
 31+ $text = file_get_contents( $url );
 32+ ini_set( 'allow_url_fopen', $url_fopen );
 33+ }
 34+ return $text;
 35+}
 36+
 37+/**
 38+ * Check if the URL can be served by localhost
 39+ */
 40+function wfIsLocalURL( $url ) {
 41+ global $wgConf;
 42+ // Extract host part
 43+ if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) {
 44+ $host = $matches[1];
 45+ // Split up dotwise
 46+ $domainParts = explode( '.', $host );
 47+ // Check if this domain or any superdomain is listed in $wgConf as a local virtual host
 48+ $domainParts = array_reverse( $domainParts );
 49+ for ( $i = 0; $i < count( $domainParts ); $i++ ) {
 50+ $domainPart = $domainParts[$i];
 51+ if ( $i == 0 ) {
 52+ $domain = $domainPart;
 53+ } else {
 54+ $domain = $domainPart . '.' . $domain;
 55+ }
 56+ if ( $wgConf->isLocalVHost( $domain ) ) {
 57+ return true;
 58+ }
 59+ }
 60+ }
 61+ return false;
 62+}
 63+
 64+?>
Property changes on: trunk/phase3/includes/HttpFunctions.php
___________________________________________________________________
Added: svn:eol-style
165 + native
Added: svn:keywords
266 + Author Date Id Revision
Index: trunk/phase3/includes/SiteConfiguration.php
@@ -1,8 +1,6 @@
22 <?php
33 /**
4 - *This file is used to configure the live Wikimedia wikis. The file that
5 - * includes it contains passwords and other sensitive data, and there's
6 - * currently no public equivalent.
 4+ * This is a class used to hold configuration settings, particularly for multi-wiki sites.
75 *
86 * @package MediaWiki
97 */
@@ -21,8 +19,11 @@
2220 define('SITE_CONFIGURATION', 1);
2321
2422 class SiteConfiguration {
25 - var $suffixes, $wikis, $settings;
26 - var $localDatabases;
 23+ var $suffixes = array();
 24+ var $wikis = array();
 25+ var $settings = array();
 26+ var $localDatabases = array();
 27+ var $localVHosts = array();
2728
2829 function get( $setting, $wiki, $suffix, $params = array() ) {
2930 if ( array_key_exists( $wiki, $this->settings[$setting] ) ) {
@@ -92,6 +93,10 @@
9394 }
9495 return array( $site, $lang );
9596 }
 97+
 98+ function isLocalVHost( $vhost ) {
 99+ return in_array( $vhost, $this->localVHosts );
 100+ }
96101 }
97102 }
98103

Status & tagging log

  • 01:56, 13 October 2010 ^demon (talk | contribs) changed the status of r9670 [removed: new added: old]