MediaWiki REL1_39
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 $ret = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
44 $method, $url, $options, $caller );
45 return is_string( $ret ) ? $ret : false;
46 }
47
61 public static function get( $url, array $options = [], $caller = __METHOD__ ) {
62 $args = func_get_args();
63 if ( isset( $args[1] ) && ( is_string( $args[1] ) || is_numeric( $args[1] ) ) ) {
64 // Second was used to be the timeout
65 // And third parameter used to be $options
66 wfWarn( "Second parameter should not be a timeout.", 2 );
67 $options = isset( $args[2] ) && is_array( $args[2] ) ?
68 $args[2] : [];
69 $options['timeout'] = $args[1];
70 $caller = __METHOD__;
71 }
72 return self::request( 'GET', $url, $options, $caller );
73 }
74
85 public static function post( $url, array $options = [], $caller = __METHOD__ ) {
86 return self::request( 'POST', $url, $options, $caller );
87 }
88
95 public static function userAgent() {
96 return MediaWikiServices::getInstance()->getHttpRequestFactory()->getUserAgent();
97 }
98
115 public static function isValidURI( $uri ) {
116 return MWHttpRequest::isValidURI( $uri );
117 }
118
125 public static function getProxy() {
126 wfDeprecated( __METHOD__, '1.34' );
127
128 $httpProxy = MediaWikiServices::getInstance()->getMainConfig()->get(
129 MainConfigNames::HTTPProxy );
130 return (string)$httpProxy;
131 }
132
140 public static function createMultiClient( array $options = [] ) {
141 wfDeprecated( __METHOD__, '1.34' );
142 $httpProxy = MediaWikiServices::getInstance()->getMainConfig()->get(
143 MainConfigNames::HTTPProxy );
144 return MediaWikiServices::getInstance()->getHttpRequestFactory()
145 ->createMultiClient( $options + [ 'proxy' => $httpProxy ] );
146 }
147}
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:115
static userAgent()
A standard user-agent we can use for external requests.
Definition Http.php:95
static createMultiClient(array $options=[])
Get a configured MultiHttpClient.
Definition Http.php:140
static post( $url, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'POST' )
Definition Http.php:85
static getProxy()
Gets the relevant proxy from $wgHTTPProxy.
Definition Http.php:125
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
if( $line===false) $args
Definition mcc.php:124