MediaWiki  master
Http.php
Go to the documentation of this file.
1 <?php
22 
28 class Http {
41  public static function request( $method, $url, array $options = [], $caller = __METHOD__ ) {
42  $ret = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
43  $method, $url, $options, $caller );
44  return is_string( $ret ) ? $ret : false;
45  }
46 
60  public static function get( $url, array $options = [], $caller = __METHOD__ ) {
61  $args = func_get_args();
62  if ( isset( $args[1] ) && ( is_string( $args[1] ) || is_numeric( $args[1] ) ) ) {
63  // Second was used to be the timeout
64  // And third parameter used to be $options
65  wfWarn( "Second parameter should not be a timeout.", 2 );
66  $options = isset( $args[2] ) && is_array( $args[2] ) ?
67  $args[2] : [];
68  $options['timeout'] = $args[1];
69  $caller = __METHOD__;
70  }
71  return self::request( 'GET', $url, $options, $caller );
72  }
73 
84  public static function post( $url, array $options = [], $caller = __METHOD__ ) {
85  return self::request( 'POST', $url, $options, $caller );
86  }
87 
94  public static function userAgent() {
95  return MediaWikiServices::getInstance()->getHttpRequestFactory()->getUserAgent();
96  }
97 
114  public static function isValidURI( $uri ) {
115  return MWHttpRequest::isValidURI( $uri );
116  }
117 
124  public static function getProxy() {
125  wfDeprecated( __METHOD__, '1.34' );
126 
127  $httpProxy = MediaWikiServices::getInstance()->getMainConfig()->get( 'HTTPProxy' );
128  return (string)$httpProxy;
129  }
130 
138  public static function createMultiClient( array $options = [] ) {
139  wfDeprecated( __METHOD__, '1.34' );
140  $httpProxy = MediaWikiServices::getInstance()->getMainConfig()->get( 'HTTPProxy' );
141  return MediaWikiServices::getInstance()->getHttpRequestFactory()
142  ->createMultiClient( $options + [ 'proxy' => $httpProxy ] );
143  }
144 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:203
Http\post
static post( $url, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'POST' )
Definition: Http.php:84
Http\request
static request( $method, $url, array $options=[], $caller=__METHOD__)
Perform an HTTP request.
Definition: Http.php:41
Http\userAgent
static userAgent()
A standard user-agent we can use for external requests.
Definition: Http.php:94
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:997
Http\getProxy
static getProxy()
Gets the relevant proxy from $wgHTTPProxy.
Definition: Http.php:124
$args
if( $line===false) $args
Definition: mcc.php:124
Http\createMultiClient
static createMultiClient(array $options=[])
Get a configured MultiHttpClient.
Definition: Http.php:138
MWHttpRequest\isValidURI
static isValidURI( $uri)
Check that the given URI is a valid one.
Definition: MWHttpRequest.php:732
Http\isValidURI
static isValidURI( $uri)
Check that the given URI is a valid one.
Definition: Http.php:114
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:1043
Http
Various HTTP related functions.
Definition: Http.php:28