89 global $wgHTTPTimeout, $wgHTTPConnectTimeout;
97 $this->logger =
new NullLogger();
107 $this->timeout =
$options[
'timeout'];
109 $this->timeout = $wgHTTPTimeout;
111 if ( isset(
$options[
'connectTimeout'] ) &&
$options[
'connectTimeout'] !=
'default' ) {
112 $this->connectTimeout =
$options[
'connectTimeout'];
114 $this->connectTimeout = $wgHTTPConnectTimeout;
116 if ( isset(
$options[
'userAgent'] ) ) {
120 $members = [
"postData",
"proxy",
"noProxy",
"sslVerifyHost",
"caInfo",
121 "method",
"followRedirects",
"maxRedirects",
"sslVerifyCert",
"callback" ];
123 foreach ( $members
as $o ) {
127 if ( $o ==
'method' ) {
134 if ( $this->noProxy ) {
140 $this->profileName = $caller;
156 return function_exists(
'curl_init' ) ||
wfIniGetBool(
'allow_url_fopen' );
172 throw new MWException( __METHOD__ .
': curl (http://php.net/curl) is not installed, but' .
173 ' Http::$httpEngine is set to "curl"' );
180 if ( !isset(
$options[
'logger'] ) ) {
181 $options[
'logger'] = LoggerFactory::getInstance(
'http' );
189 throw new MWException( __METHOD__ .
': allow_url_fopen ' .
190 'needs to be enabled for pure PHP http requests to ' .
191 'work. If possible, curl should be used instead. See ' .
192 'http://php.net/curl.'
197 throw new MWException( __METHOD__ .
': The setting of Http::$httpEngine is not valid.' );
217 $this->postData =
$args;
227 if ( $this->proxy && !$this->noProxy ) {
233 if ( self::isLocalURL( $this->url ) || $this->noProxy ) {
249 if ( $wgCommandLineMode ) {
255 if ( preg_match(
'!^https?://([\w.-]+)[/:].*$!',
$url,
$matches ) ) {
258 $domainParts = explode(
'.', $host );
260 $domainParts = array_reverse( $domainParts );
263 $countParts = count( $domainParts );
264 for ( $i = 0; $i < $countParts; $i++ ) {
265 $domainPart = $domainParts[$i];
267 $domain = $domainPart;
269 $domain = $domainPart .
'.' . $domain;
272 if ( in_array( $domain, $wgLocalVirtualHosts ) ) {
306 if ( $this->cookieJar ) {
307 $this->reqHeaders[
'Cookie'] =
308 $this->cookieJar->serializeToHttpRequest(
309 $this->parsedUrl[
'path'],
310 $this->parsedUrl[
'host']
315 $list[] =
"$name: $value";
341 throw new MWException(
'Invalid MwHttpRequest callback' );
368 if ( strtoupper( $this->method ) ==
"HEAD" ) {
369 $this->headersOnly =
true;
374 if ( !$this->callback ) {
378 if ( !isset( $this->reqHeaders[
'User-Agent'] ) ) {
393 foreach ( $this->headerList
as $header ) {
394 if ( preg_match(
"#^HTTP/([0-9.]+) (.*)#", $header, $match ) ) {
395 $this->respVersion = $match[1];
396 $this->respStatus = $match[2];
397 } elseif ( preg_match(
"#^[ \t]#", $header ) ) {
398 $last = count( $this->respHeaders[$lastname] ) - 1;
399 $this->respHeaders[$lastname][
$last] .=
"\r\n$header";
400 } elseif ( preg_match(
"#^([^:]*):[\t ]*(.*)#", $header, $match ) ) {
401 $this->respHeaders[strtolower( $match[1] )][] = $match[2];
402 $lastname = strtolower( $match[1] );
419 if ( !$this->respHeaders ) {
423 if ( (
int)$this->respStatus > 399 ) {
424 list(
$code, $message ) = explode(
" ", $this->respStatus, 2 );
425 $this->status->fatal(
"http-bad-status",
$code, $message );
437 if ( !$this->respHeaders ) {
450 if ( !$this->respHeaders ) {
454 $status = (int)$this->respStatus;
472 if ( !$this->respHeaders ) {
486 if ( !$this->respHeaders ) {
490 if ( isset( $this->respHeaders[strtolower(
$header )] ) ) {
491 $v = $this->respHeaders[strtolower(
$header )];
492 return $v[count( $v ) - 1];
504 $this->cookieJar = $jar;
513 if ( !$this->respHeaders ) {
530 if ( !$this->cookieJar ) {
542 if ( !$this->cookieJar ) {
546 if ( isset( $this->respHeaders[
'set-cookie'] ) ) {
548 foreach ( $this->respHeaders[
'set-cookie']
as $cookie ) {
549 $this->cookieJar->parseCookieResponseHeader( $cookie,
$url[
'host'] );
575 if ( isset( $headers[
'location'] ) ) {
576 $locations = $headers[
'location'];
578 $foundRelativeURI =
false;
579 $countLocations = count( $locations );
581 for ( $i = $countLocations - 1; $i >= 0; $i-- ) {
582 $url = parse_url( $locations[$i] );
584 if ( isset(
$url[
'host'] ) ) {
585 $domain =
$url[
'scheme'] .
'://' .
$url[
'host'];
588 $foundRelativeURI =
true;
592 if ( $foundRelativeURI ) {
594 return $domain . $locations[$countLocations - 1];
596 $url = parse_url( $this->url );
597 if ( isset(
$url[
'host'] ) ) {
598 return $url[
'scheme'] .
'://' .
$url[
'host'] .
599 $locations[$countLocations - 1];
603 return $locations[$countLocations - 1];
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
proxySetup()
Take care of setting up the proxy (do nothing if "noProxy" is set)
setCookie($name, $value=null, $attr=null)
Sets a cookie.
static getProxy()
Gets the relevant proxy from $wgHTTPProxy.
execute()
Take care of whatever is necessary to perform the URI request.
per default it will return the text for text based content
canFollowRedirects()
Returns true if the backend can follow redirects.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
setHeader($name, $value)
Set an arbitrary header.
static newFatal($message)
Factory function for fatal errors.
static instance()
Singleton.
setCookieJar($jar)
Tells the MWHttpRequest object to use this pre-loaded CookieJar.
isRedirect()
Returns true if the last status code was a redirect.
static isLocalURL($url)
Check if the URL can be served by localhost.
when a variable name is used in a it is silently declared as a new local masking the global
wfExpandUrl($url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
static canMakeRequests()
Simple function to test if we can make any sort of requests at all, using cURL or fopen() ...
MWHttpRequest implemented using internal curl compiled into PHP.
static userAgent()
A standard user-agent we can use for external requests.
parseCookies()
Parse the cookies in the response headers and store them in the cookie jar.
global $wgCommandLineMode
getCookieJar()
Returns the cookie jar in use.
getHeaderList()
Get an array of the headers.
getFinalUrl()
Returns the final URL after all redirections.
wfIniGetBool($setting)
Safety wrapper around ini_get() for boolean settings.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
setLogger(LoggerInterface $logger)
__construct($url, $options=[], $caller=__METHOD__, $profiler=null)
const SUPPORTS_FILE_POSTS
read($fh, $content)
A generic callback to read the body of the response from a remote server.
setStatus()
Sets HTTPRequest status member to a fatal value with the error message if the returned integer value ...
static newGood($value=null)
Factory function for good results.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
setCallback($callback)
Set a read callback to accept data read from the HTTP request.
getResponseHeaders()
Returns an associative array of response headers after the request has been executed.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
getStatus()
Get the integer value of the HTTP status code (e.g.
parseHeader()
Parses the headers, including the HTTP status code and any Set-Cookie headers.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
setUserAgent($UA)
Set the user agent.
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method.MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances.The"Spi"in MediaWiki\Logger\Spi stands for"service provider interface".An SPI is an API intended to be implemented or extended by a third party.This software design pattern is intended to enable framework extension and replaceable components.It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki.The service provider interface allows the backend logging library to be implemented in multiple ways.The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime.This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance.Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
static factory($url, $options=null, $caller=__METHOD__)
Generate a new request object.
getContent()
Get the body, or content, of the response to the request.
wfParseUrl($url)
parse_url() work-alike, but non-broken.
setData($args)
Set the parameters of the request.
setCookie($name, $value, $attr)
Set a cookie in the cookie jar.
static isValidURI($uri)
Checks that the given URI is a valid one.
getResponseHeader($header)
Returns the value of the given response header.
Allows to change the fields on the form that will be generated $name