MediaWiki  master
Http.php
Go to the documentation of this file.
1 <?php
23 
29 class Http {
31  public static $httpEngine = null;
32 
45  public static function request( $method, $url, array $options = [], $caller = __METHOD__ ) {
46  $ret = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
47  $method, $url, $options, $caller );
48  return is_string( $ret ) ? $ret : false;
49  }
50 
64  public static function get( $url, array $options = [], $caller = __METHOD__ ) {
65  $args = func_get_args();
66  if ( isset( $args[1] ) && ( is_string( $args[1] ) || is_numeric( $args[1] ) ) ) {
67  // Second was used to be the timeout
68  // And third parameter used to be $options
69  wfWarn( "Second parameter should not be a timeout.", 2 );
70  $options = isset( $args[2] ) && is_array( $args[2] ) ?
71  $args[2] : [];
72  $options['timeout'] = $args[1];
73  $caller = __METHOD__;
74  }
75  return self::request( 'GET', $url, $options, $caller );
76  }
77 
88  public static function post( $url, array $options = [], $caller = __METHOD__ ) {
89  return self::request( 'POST', $url, $options, $caller );
90  }
91 
98  public static function userAgent() {
99  return MediaWikiServices::getInstance()->getHttpRequestFactory()->getUserAgent();
100  }
101 
118  public static function isValidURI( $uri ) {
119  return MWHttpRequest::isValidURI( $uri );
120  }
121 
128  public static function getProxy() {
129  wfDeprecated( __METHOD__, '1.34' );
130 
131  global $wgHTTPProxy;
132  return (string)$wgHTTPProxy;
133  }
134 
142  public static function createMultiClient( array $options = [] ) {
143  wfDeprecated( __METHOD__, '1.34' );
144 
146 
147  return new MultiHttpClient( $options + [
148  'connTimeout' => $wgHTTPConnectTimeout,
149  'reqTimeout' => $wgHTTPTimeout,
150  'userAgent' => self::userAgent(),
151  'proxy' => $wgHTTPProxy,
152  'logger' => LoggerFactory::getInstance( 'http' )
153  ] );
154  }
155 }
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
static isValidURI( $uri)
Check that the given URI is a valid one.
static getProxy()
Gets the relevant proxy from $wgHTTPProxy.
Definition: Http.php:128
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1982
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
int $wgHTTPTimeout
Timeout for HTTP requests done internally, in seconds.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
$wgHTTPProxy
Proxy to use for CURL requests.
static post( $url, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( &#39;POST&#39; )
Definition: Http.php:88
static userAgent()
A standard user-agent we can use for external requests.
Definition: Http.php:98
if( $line===false) $args
Definition: cdb.php:64
static request( $method, $url, array $options=[], $caller=__METHOD__)
Perform an HTTP request.
Definition: Http.php:45
static $httpEngine
Definition: Http.php:31
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1982
Various HTTP related functions.
Definition: Http.php:29
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging a wrapping ErrorException create2 Corresponds to logging log_action database field and which is displayed in the UI similar to $comment or false if none Defaults to false if not set multiOccurrence Can this option be passed multiple times Defaults to false if not set this hook should only be used to add variables that depend on the current page request
Definition: hooks.txt:2159
static isValidURI( $uri)
Check that the given URI is a valid one.
Definition: Http.php:118
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$wgHTTPConnectTimeout
Timeout for connections done internally (in seconds) Only works for curl.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
MediaWiki Logger LoggerFactory implements a PSR [0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method. MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances. The "Spi" in MediaWiki\Logger\Spi stands for "service provider interface". An SPI is an API intended to be implemented or extended by a third party. This software design pattern is intended to enable framework extension and replaceable components. It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki. The service provider interface allows the backend logging library to be implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime. This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance. Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
Class to handle multiple HTTP requests.
static createMultiClient(array $options=[])
Get a configured MultiHttpClient.
Definition: Http.php:142