22use Psr\Log\LoggerInterface;
23use Psr\Log\LoggerAwareInterface;
24use Psr\Log\NullLogger;
87 $url,
$options = [], $caller = __METHOD__, $profiler =
null
97 $this->logger =
new NullLogger();
100 if ( !$this->parsedUrl || !Http::isValidURI( $this->url ) ) {
101 $this->status = Status::newFatal(
'http-invalid-url',
$url );
103 $this->status = Status::newGood( 100 );
107 $this->timeout =
$options[
'timeout'];
111 if ( isset(
$options[
'connectTimeout'] ) &&
$options[
'connectTimeout'] !=
'default' ) {
112 $this->connectTimeout =
$options[
'connectTimeout'];
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;
147 $this->logger = $logger;
156 return function_exists(
'curl_init' ) ||
wfIniGetBool(
'allow_url_fopen' );
169 if ( !Http::$httpEngine ) {
170 Http::$httpEngine = function_exists(
'curl_init' ) ?
'curl' :
'php';
171 } elseif ( Http::$httpEngine ==
'curl' && !function_exists(
'curl_init' ) ) {
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' );
184 switch ( Http::$httpEngine ) {
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 ) {
236 $this->proxy = Http::getProxy();
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;
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 ) {
441 return (
int)$this->respStatus;
450 if ( !$this->respHeaders ) {
454 $status = (int)$this->respStatus;
472 if ( !$this->respHeaders ) {
476 return $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 ) {
517 return $this->cookieJar;
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];
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgHTTPTimeout
Timeout for HTTP requests done internally, in seconds.
$wgHTTPConnectTimeout
Timeout for connections done internally (in seconds) Only works for curl.
$wgLocalVirtualHosts
Local virtual hosts.
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
global $wgCommandLineMode
setCookie( $name, $value, $attr)
Set a cookie in the cookie jar.
MWHttpRequest implemented using internal curl compiled into PHP.
This wrapper class will call out to curl (if available) or fallback to regular PHP if necessary for h...
getContent()
Get the body, or content, of the response to the request.
setLogger(LoggerInterface $logger)
getResponseHeaders()
Returns an associative array of response headers after the request has been executed.
static isLocalURL( $url)
Check if the URL can be served by localhost.
setHeader( $name, $value)
Set an arbitrary header.
getCookieJar()
Returns the cookie jar in use.
__construct( $url, $options=[], $caller=__METHOD__, $profiler=null)
isRedirect()
Returns true if the last status code was a redirect.
read( $fh, $content)
A generic callback to read the body of the response from a remote server.
getFinalUrl()
Returns the final URL after all redirections.
setStatus()
Sets HTTPRequest status member to a fatal value with the error message if the returned integer value ...
setUserAgent( $UA)
Set the user agent.
parseHeader()
Parses the headers, including the HTTP status code and any Set-Cookie headers.
static factory( $url, $options=null, $caller=__METHOD__)
Generate a new request object.
canFollowRedirects()
Returns true if the backend can follow redirects.
setCallback( $callback)
Set a read callback to accept data read from the HTTP request.
static canMakeRequests()
Simple function to test if we can make any sort of requests at all, using cURL or fopen()
getStatus()
Get the integer value of the HTTP status code (e.g.
const SUPPORTS_FILE_POSTS
execute()
Take care of whatever is necessary to perform the URI request.
getResponseHeader( $header)
Returns the value of the given response header.
proxySetup()
Take care of setting up the proxy (do nothing if "noProxy" is set)
parseCookies()
Parse the cookies in the response headers and store them in the cookie jar.
setCookie( $name, $value=null, $attr=null)
Sets a cookie.
setCookieJar( $jar)
Tells the MWHttpRequest object to use this pre-loaded CookieJar.
getHeaderList()
Get an array of the headers.
setData( $args)
Set the parameters of the request.
Profiler base class that defines the interface and some trivial functionality.
static instance()
Singleton.
per default it will return the text for text based content
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
when a variable name is used in a it is silently declared as a new local masking the global
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
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
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 $content
Allows to change the fields on the form that will be generated $name
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
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