MediaWiki fundraising/REL1_35
Http.php
Go to the documentation of this file.
1<?php
22
28class 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}
$wgHTTPProxy
Proxy to use for CURL requests.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Various HTTP related functions.
Definition Http.php:28
static $httpEngine
Definition Http.php:30
static request( $method, $url, array $options=[], $caller=__METHOD__)
Perform an HTTP request.
Definition Http.php:44
static isValidURI( $uri)
Check that the given URI is a valid one.
Definition Http.php:117
static userAgent()
A standard user-agent we can use for external requests.
Definition Http.php:97
static createMultiClient(array $options=[])
Get a configured MultiHttpClient.
Definition Http.php:141
static post( $url, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'POST' )
Definition Http.php:87
static getProxy()
Gets the relevant proxy from $wgHTTPProxy.
Definition Http.php:127
MediaWikiServices is the service locator for the application scope of MediaWiki.
if( $line===false) $args
Definition mcc.php:124