MediaWiki 1.40.4
Http.php
Go to the documentation of this file.
1<?php
23
29class Http {
42 public static function request( $method, $url, array $options = [], $caller = __METHOD__ ) {
43 wfDeprecated( __METHOD__, '1.34' );
44 $ret = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
45 $method, $url, $options, $caller );
46 return is_string( $ret ) ? $ret : false;
47 }
48
62 public static function get( $url, array $options = [], $caller = __METHOD__ ) {
63 wfDeprecated( __METHOD__, '1.34' );
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 wfDeprecated( __METHOD__, '1.34' );
89 return self::request( 'POST', $url, $options, $caller );
90 }
91
98 public static function userAgent() {
99 wfDeprecated( __METHOD__, '1.34' );
100 return MediaWikiServices::getInstance()->getHttpRequestFactory()->getUserAgent();
101 }
102
119 public static function isValidURI( $uri ) {
120 wfDeprecated( __METHOD__, '1.34' );
121 return MWHttpRequest::isValidURI( $uri );
122 }
123
130 public static function getProxy() {
131 wfDeprecated( __METHOD__, '1.34' );
132
133 $httpProxy = MediaWikiServices::getInstance()->getMainConfig()->get(
134 MainConfigNames::HTTPProxy );
135 return (string)$httpProxy;
136 }
137
145 public static function createMultiClient( array $options = [] ) {
146 wfDeprecated( __METHOD__, '1.34' );
147 $httpProxy = MediaWikiServices::getInstance()->getMainConfig()->get(
148 MainConfigNames::HTTPProxy );
149 return MediaWikiServices::getInstance()->getHttpRequestFactory()
150 ->createMultiClient( $options + [ 'proxy' => $httpProxy ] );
151 }
152}
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 a deprecated feature was used.
Various HTTP related functions.
Definition Http.php:29
static request( $method, $url, array $options=[], $caller=__METHOD__)
Perform an HTTP request.
Definition Http.php:42
static isValidURI( $uri)
Check that the given URI is a valid one.
Definition Http.php:119
static userAgent()
A standard user-agent we can use for external requests.
Definition Http.php:98
static createMultiClient(array $options=[])
Get a configured MultiHttpClient.
Definition Http.php:145
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:130
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.