44 if ( !$this->status->isOK() ) {
52 if ( defined(
'CURLOPT_CONNECTTIMEOUT_MS' ) ) {
53 $this->curlOptions[CURLOPT_CONNECTTIMEOUT_MS] = $this->connectTimeout * 1000;
56 $this->curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
58 $this->curlOptions[CURLOPT_HEADERFUNCTION] = [ $this,
"readHeader" ];
60 $this->curlOptions[CURLOPT_ENCODING] =
""; # Enable compression
62 $this->curlOptions[CURLOPT_USERAGENT] = $this->reqHeaders[
'User-Agent'];
64 $this->curlOptions[CURLOPT_SSL_VERIFYHOST] = $this->sslVerifyHost ? 2 : 0;
67 if ( $this->caInfo ) {
71 if ( $this->headersOnly ) {
72 $this->curlOptions[CURLOPT_NOBODY] =
true;
73 $this->curlOptions[CURLOPT_HEADER] =
true;
74 } elseif ( $this->method ==
'POST' ) {
75 $this->curlOptions[CURLOPT_POST] =
true;
82 if ( defined(
'CURLOPT_SAFE_UPLOAD' ) ) {
83 $this->curlOptions[CURLOPT_SAFE_UPLOAD] =
true;
90 $this->curlOptions[CURLOPT_POSTFIELDS] =
$postData;
95 $this->reqHeaders[
'Expect'] =
'';
100 $this->curlOptions[CURLOPT_HTTPHEADER] = $this->
getHeaderList();
102 $curlHandle = curl_init( $this->url );
104 if ( !curl_setopt_array( $curlHandle, $this->curlOptions ) ) {
105 throw new MWException(
"Error setting curl options." );
109 MediaWiki\suppressWarnings();
110 if ( !curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION,
true ) ) {
111 $this->logger->debug( __METHOD__ .
": Couldn't set CURLOPT_FOLLOWLOCATION. " .
112 "Probably open_basedir is set.\n" );
116 MediaWiki\restoreWarnings();
119 if ( $this->profiler ) {
120 $profileSection = $this->profiler->scopedProfileIn(
121 __METHOD__ .
'-' . $this->profileName
125 $curlRes = curl_exec( $curlHandle );
126 if ( curl_errno( $curlHandle ) == CURLE_OPERATION_TIMEOUTED ) {
127 $this->status->fatal(
'http-timed-out', $this->url );
128 } elseif ( $curlRes ===
false ) {
129 $this->status->fatal(
'http-curl-error', curl_error( $curlHandle ) );
131 $this->headerList = explode(
"\r\n", $this->headerText );
134 curl_close( $curlHandle );
136 if ( $this->profiler ) {
137 $this->profiler->scopedProfileOut( $profileSection );
150 $curlVersionInfo = curl_version();
151 if ( $curlVersionInfo[
'version_number'] < 0x071304 ) {
152 $this->logger->debug(
"Cannot follow redirects with libcurl < 7.19.4 due to CVE-2009-0037\n" );
156 if ( version_compare( PHP_VERSION,
'5.6.0',
'<' ) ) {
157 if ( strval( ini_get(
'open_basedir' ) ) !==
'' ) {
158 $this->logger->debug(
"Cannot follow redirects when open_basedir is set\n" );
readHeader($fh, $content)
MWHttpRequest implemented using internal curl compiled into PHP.
const SUPPORTS_FILE_POSTS
getHeaderList()
Get an array of the headers.
setStatus()
Sets HTTPRequest status member to a fatal value with the error message if the returned integer value ...
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
wfArrayToCgi($array1, $array2=null, $prefix= '')
This function takes one or two arrays as input, and returns a CGI-style string, e.g.