| Index: trunk/phase3/includes/DefaultSettings.php |
| — | — | @@ -17,6 +17,13 @@ |
| 18 | 18 | die( "This file is part of MediaWiki and is not a valid entry point\n" ); |
| 19 | 19 | } |
| 20 | 20 | |
| | 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 | + |
| 21 | 28 | /** MediaWiki version number */ |
| 22 | 29 | $wgVersion = '1.5beta1'; |
| 23 | 30 | |
| — | — | @@ -1540,5 +1547,9 @@ |
| 1541 | 1548 | */ |
| 1542 | 1549 | $wgAllowSpecialInclusion = true; |
| 1543 | 1550 | |
| | 1551 | +/** |
| | 1552 | + * Timeout for HTTP requests done via CURL |
| | 1553 | + */ |
| | 1554 | +$wgHTTPTimeout = 3; |
| 1544 | 1555 | |
| 1545 | 1556 | ?> |
| 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 |
| 1 | 65 | + native |
| Added: svn:keywords |
| 2 | 66 | + Author Date Id Revision |
| Index: trunk/phase3/includes/SiteConfiguration.php |
| — | — | @@ -1,8 +1,6 @@ |
| 2 | 2 | <?php |
| 3 | 3 | /** |
| 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. |
| 7 | 5 | * |
| 8 | 6 | * @package MediaWiki |
| 9 | 7 | */ |
| — | — | @@ -21,8 +19,11 @@ |
| 22 | 20 | define('SITE_CONFIGURATION', 1); |
| 23 | 21 | |
| 24 | 22 | 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(); |
| 27 | 28 | |
| 28 | 29 | function get( $setting, $wiki, $suffix, $params = array() ) { |
| 29 | 30 | if ( array_key_exists( $wiki, $this->settings[$setting] ) ) { |
| — | — | @@ -92,6 +93,10 @@ |
| 93 | 94 | } |
| 94 | 95 | return array( $site, $lang ); |
| 95 | 96 | } |
| | 97 | + |
| | 98 | + function isLocalVHost( $vhost ) { |
| | 99 | + return in_array( $vhost, $this->localVHosts ); |
| | 100 | + } |
| 96 | 101 | } |
| 97 | 102 | } |
| 98 | 103 | |