MediaWiki  master
Http.php
Go to the documentation of this file.
1 <?php
22 
28 class Http {
30  public static $httpEngine = null;
31 
44  public static function request( $method, $url, array $options = [], $caller = __METHOD__ ) {
45  $ret = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
46  $method, $url, $options, $caller );
47  return is_string( $ret ) ? $ret : false;
48  }
49 
63  public static function get( $url, array $options = [], $caller = __METHOD__ ) {
64  $args = func_get_args();
65  if ( isset( $args[1] ) && ( is_string( $args[1] ) || is_numeric( $args[1] ) ) ) {
66  // Second was used to be the timeout
67  // And third parameter used to be $options
68  wfWarn( "Second parameter should not be a timeout.", 2 );
69  $options = isset( $args[2] ) && is_array( $args[2] ) ?
70  $args[2] : [];
71  $options['timeout'] = $args[1];
72  $caller = __METHOD__;
73  }
74  return self::request( 'GET', $url, $options, $caller );
75  }
76 
87  public static function post( $url, array $options = [], $caller = __METHOD__ ) {
88  return self::request( 'POST', $url, $options, $caller );
89  }
90 
97  public static function userAgent() {
98  return MediaWikiServices::getInstance()->getHttpRequestFactory()->getUserAgent();
99  }
100 
117  public static function isValidURI( $uri ) {
118  return MWHttpRequest::isValidURI( $uri );
119  }
120 
127  public static function getProxy() {
128  wfDeprecated( __METHOD__, '1.34' );
129 
130  global $wgHTTPProxy;
131  return (string)$wgHTTPProxy;
132  }
133 
141  public static function createMultiClient( array $options = [] ) {
142  wfDeprecated( __METHOD__, '1.34' );
143  global $wgHTTPProxy;
144  return MediaWikiServices::getInstance()->getHttpRequestFactory()
145  ->createMultiClient( $options + [ 'proxy' => $wgHTTPProxy ] );
146  }
147 }
Http\$httpEngine
static $httpEngine
Definition: Http.php:30
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:165
Http\post
static post( $url, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'POST' )
Definition: Http.php:87
Http\request
static request( $method, $url, array $options=[], $caller=__METHOD__)
Perform an HTTP request.
Definition: Http.php:44
Http\userAgent
static userAgent()
A standard user-agent we can use for external requests.
Definition: Http.php:97
$wgHTTPProxy
$wgHTTPProxy
Proxy to use for CURL requests.
Definition: DefaultSettings.php:8932
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1030
Http\getProxy
static getProxy()
Gets the relevant proxy from $wgHTTPProxy.
Definition: Http.php:127
$args
if( $line===false) $args
Definition: mcc.php:124
Http\createMultiClient
static createMultiClient(array $options=[])
Get a configured MultiHttpClient.
Definition: Http.php:141
MWHttpRequest\isValidURI
static isValidURI( $uri)
Check that the given URI is a valid one.
Definition: MWHttpRequest.php:694
Http\isValidURI
static isValidURI( $uri)
Check that the given URI is a valid one.
Definition: Http.php:117
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition: GlobalFunctions.php:1077
Http
Various HTTP related functions.
Definition: Http.php:28