Commit graph

238 commits

Author SHA1 Message Date
Aaron Schulz
52511952de objectcache: add and use adaptiveTTL() method
* This better handles delayed/lost cache purges by
  having lower TTLs for entries that often changes.
* Use this for foreign upload description page caches,
  we purges are never received from the source wiki.
* Also use this for User and LocalFile cache TTLs.
* Also move the Database::getCacheSetOptions() call in
  User *before* doing the queries, which is preferred.
* Fixed some IDEA errors too, like the undeclared
  mApiBase field.

Change-Id: I70f8ebb29ac853c2a530d9eedb9e7facc1b7b710
2016-08-31 03:40:56 +00:00
Chad Horohoe
b47c196943 HttpFunctions: Move isLocalUrl() into MWHttpRequest and make it private
Nothing else calls this, and it really shouldn't be used except for
determining if a request should be proxied.

While we're here, actually support HTTPS.

Change-Id: I5edf47f75ebb7c1705d0c406ee7d19425f348eb4
2016-07-19 11:03:10 -07:00
Chad Horohoe
425ee18e3b Remove support for getenv('http_proxy') in MediaWiki
PHP (and other programming languages) are vulnerable to an exploit
when making external requests via a proxy when a client provides a
Proxy header. See https://httpoxy.org/ for more information.

MediaWiki now requires $wgHTTPProxy to be set when attempting to
use a proxy for requests and can no longer rely on http_proxy
environment variables. As it exists, this code is inherently unsafe
on case-insensitive platforms (eg: Windows) and hard to be sure of
for other platforms.

All users using a proxy for MediaWiki and *not* setting $wgHTTPProxy
are advised to do so immediately to mitigate this problem. This will
be required as of the next security release.

All extensions maintained in Git/Gerrit appear to be Doing The Right
Thing and not trying to use getenv('http_proxy') directly. This would
be a bad thing to start doing. Call Http::getProxy() if you need to
manually get a proxy from MW for external requests.

Bug: T140658
Change-Id: I122583ad98d867c5855c3e2f955fe47787668589
2016-07-19 08:37:12 -07:00
umherirrender
932c37e3cb Use english messages for background use of Status::getWikiText
Status::getWikiText is used for internal logging, api error messages and
maintenance scripts. All this places are usually in english, so pass an
english language to getWikiText.

Change-Id: I3010fca8eb5740a3a851c55a8b12e171714c78f7
2016-04-12 20:01:44 +02:00
jenkins-bot
e3bd13db0c Merge "Http::getProxy() method to get proxy configuration" 2016-03-25 15:38:18 +00:00
Sébastien Santoro
6ae9367cdd Http::getProxy() method to get proxy configuration
MediaWiki currently uses two sources for proxy configuration:
	* the $wgHTTPProxy global configuration variable
	* the http_proxy environment variable

The HTTP proxy adress to use is a valuable information for
extensions handling directly HTTP requests instead of use
helper classes provided by the core to construct them.

This change offers an Http::getProxy() utility method to get
the configuration, regardless of the source.

Bug: T117954
Change-Id: I5df31845df71f05ac581f532cc9bd7a1fea25583
2016-03-25 15:10:56 +00:00
Reedy
b5656b6953 Many more function case mismatches
Change-Id: I5d3a5eb8adea1ecbf136415bb9fd7a162633ccca
2016-03-19 00:20:58 +00:00
Brad Jorsch
a92a23e8a2 HttpFunctions: Log in English
Bug: T127233
Change-Id: Ie61030a21f5a5f5e46452c1b6b15db594d741b71
2016-03-10 00:44:36 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
jenkins-bot
554ca56fd5 Merge "Stop using SiteConfiguration::isLocalVHost()" 2016-02-16 23:19:38 +00:00
Kunal Mehta
1b198a836d Document that Http::get() and Http::post() can return false
Change-Id: I6d48ac011ee221050c7b8a05103d028fe2bed66a
2016-02-14 00:12:31 -08:00
Kevin Israel
94e5b80fee Remove references to safe_mode INI setting
The feature no longer exists starting in PHP 5.4.0, and MediaWiki
now only supports PHP 5.5.9 or newer.

Change-Id: I3f2d1b564c50f0a28ec1ec0abd7d1b242e26953b
2016-02-12 19:18:26 -05:00
Chad Horohoe
3d4a3bd1e4 Stop using SiteConfiguration::isLocalVHost()
It's deprecated and nothing sets it anymore

Change-Id: Idad23551c7c31c9d05fd9e1be2efadc941860058
2016-02-11 10:26:30 -08:00
Roan Kattouw
e95721aae1 SECURITY: Work around CURL insanity breaking POST parameters that start with '@'
CURL has a "feature" where passing array( 'foo' => '@bar' )
in CURLOPT_POSTFIELDS results in the contents of the file named "bar"
being POSTed. This makes it impossible to POST the literal string "@bar",
because array( 'foo' => '%40bar' ) gets double-encoded to foo=%2540bar.

Disable this "feature" by setting CURLOPT_SAFE_UPLOAD to true,
if available. According to the PHP manual, this option became
available in 5.5 and started defaulting to true in 5.6.
However, we support versions as low as 5.3, and this option
doesn't exist at all in 5.6.99-hhvm, which we run in production.

For versions where this option is not available (pre-5.5 versions
and HHVM), serialize POSTFIELDS arrays to strings. This works
around the issue because the '@' "feature" only works
for arrays, not strings, as of PHP 5.2. (We don't support pre-5.2
versions, and I've verified 5.6.99-hhvm behaves this way as well.)

Bug: T118032
Signed-off-by: Chad Horohoe <chadh@wikimedia.org>
Change-Id: I3f996e2eb87c7bd3b94ca9d3cc14a3e12f34f241
2015-12-18 01:22:30 -08:00
physikerwelt
1c0004c10f Improve error message for failing HTTP requests
Before this change, the information that is written
to the log for requests with a non 200 return status
is not very helpful. A variable $errors is created,
but never used.

This patch writes the $errors and the request body
to the log.

Change-Id: If62ec801d59b2343890f4238e5a534d034d934ad
2015-11-21 17:17:17 +00:00
Brian Wolff
b78d7626f9 When using fopen on https streams, disable weak ciphers and compression
Per recomendation of
http://www.docnet.nu/tech-portal/2014/06/26/ssl-and-php-streams-part-1-you-are-doing-it-wrongtm/C0

Change-Id: I69d063ff4aa4248dd4f3d03de5a168c4b5a99c50
2015-10-11 03:00:10 +00:00
Amir E. Aharoni
c37d6549fd Fix Generic.Files.LineLength phpcs failure in 11 files under includes/
Bug: T102614
Change-Id: I0d759be6ef568c2c6f28606d3002484ad77a1830
2015-10-03 17:08:26 +00:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Reedy
8882634112 Re-enable MediaWiki.WhiteSpace.SpaceAfterControlStructure.Incorrect
Change-Id: I1b756909a1080108c5147d46950f826871ef6dc1
2015-09-26 18:32:32 +01:00
jenkins-bot
4f21e6be66 Merge "CurlHttpRequest: Follow redirects even under open_basedir" 2015-09-24 23:16:00 +00:00
Gergő Tisza
b020612f64 Log useful error messages on SSL errors in PhpHttpRequest
Work around PHP's crappy stream error handling to extract the
OpenSSL message that gives actually useful information.

Change-Id: I9eba0f90935e25e2d07995f6181fa90b7d52ea55
2015-09-10 01:08:22 +00:00
Brian Wolff
bcc31a9a0f Use system default location for cafile when using php fopen.
Up to 5.5, PHP does not accept any certificates if cafile/capath
is not set. (From 5.6 it uses the system default CA budle, which is
going to be a better choice than anything we can guess.) So try
to guess the location of the system default CA bundle.

Won't work on windows, but that's a lost cause anyway because PHP
(pre-5.6) can't handle the windows CA file format.

Bug: T75203
Change-Id: I07736c150fe0783e09d297395ed25adf335edbd3
2015-09-04 22:42:32 +00:00
Brian Wolff
bb2adc2394 Workaround fopen lack of SubjectAltName support for instantCommons
Hacky work around, where on php < 5.6.0 where SubjectAltName is not
supported, if a request to commons.wikimedia.org fails, retry the
request but telling php fopen wrapper to treat it as if it came
from en.wikipedia.org for validation purposes, since as of
c02fab71422a that's what the common name of the cert will be.

In the ideal world, everyone would just have curl installed.

I know this is super hacky, but I'd really like instant commons to
work out of the box even without curl installed.

Note: I'm basing the php 5.6 part on documentation, I have not tested
this with a copy of that version of php.

Bug: T75199
Change-Id: Ibde59be61a5b3d7cd5397ba352dce9be11e1b06f
2015-08-30 01:47:50 +00:00
Gergő Tisza
6444639792 Log errors in Http::request()
Instead of silently discarding errors in server-side HTTP requests,
log them to a 'http' channel.

Make ForeignAPIFile::httpGet() (which sort of reimplements Http::get())
log to the same channel, for consistency.

Bug: T103043
Change-Id: Ibf552e22adc7fde4a751f92e92dad6ceba2f335c
2015-07-28 22:24:00 +00:00
Brian Wolff
e47982e128 The http-invalid-url message has a parameter, so send it
Currently was outputting raw $1 to user.

Change-Id: If1d10270f4d446c4d1703457903034e8356c1503
2015-07-24 07:11:11 -06:00
Kunal Mehta
f6e5079a69 Use mediawiki/at-ease library for suppressing warnings
wfSuppressWarnings() and wfRestoreWarnings() were split out into a
separate library. All usages in core were replaced with the new
functions, and the wf* global functions are marked as deprecated.

Additionally, some uses of @ were replaced due to composer's autoloader
being loaded even earlier.

Ie1234f8c12693408de9b94bf6f84480a90bd4f8e adds the library to
mediawiki/vendor.

Bug: T100923
Change-Id: I5c35079a0a656180852be0ae6b1262d40f6534c4
2015-06-11 18:49:29 +00:00
Niklas Laxström
95cca8960c Make wfWarn name the caller in Http::get
The warning is useless as of now, unless you have stracktraces.

Bug: T91764
Change-Id: I8fcae49f3943ab2f6d13519c5f8d370ed147b185
2015-03-26 10:46:10 +00:00
Chad Horohoe
7ee5b7d23b Allow profiling of Http requests
Http::get/set/request() now all take a new $caller parameter
which is like $fname in databases. Pass it __METHOD__ so all
of your external requests can be grouped together in profiling.

Change-Id: Ibad219452903a9678378044595cff1231bf605d8
2015-03-03 20:54:24 -08:00
Gilles Dubuc
1c9c0e4911 $timeout was optional in Http::get()
Change-Id: I6cd2918412395d1d5f811f0d47bb080f22b598ec
2015-03-02 20:25:29 +01:00
Chad Horohoe
a718795dea Remove $timeout parameter from Http::get()
It is inconsistent with request() and post() and there's a couple
of mistaken usages in core and extensions that think they have the
same signature.

Change-Id: I834278639a3648edec7bcb57db7bb61f456d2a92
2015-03-02 10:15:49 -08:00
Kevin Israel
45a6214c1e CurlHttpRequest: Follow redirects even under open_basedir
As of PHP 5.6.0, this is now allowed provided that libcurl is version
7.19.4 or newer (to not follow redirects to file:// URLs, which would
circumvent the open_basedir restriction).

https://bugs.php.net/bug.php?id=65646
fba290c061

Change-Id: I1233dca563a185d12923736d8d397a3acf87a71e
2015-01-31 04:56:23 -05:00
Ricordisamoa
2ae155da52 Fix phpcs errors in includes/
Mostly Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines

Change-Id: I678b2f0902f11cd1dfa1611b9da24e7237df9122
2015-01-08 20:15:07 +01:00
Aaron Schulz
4ff8136807 Removed remaining profile calls
Change-Id: I31c81c78715048004fc8fca0f27d09c1fa71c118
2015-01-08 02:49:33 -08:00
Chad Horohoe
aa21e125a3 Remove obvious function-level profiling
Xhprof generates this data now. Custom profiling of various
sub-function units are kept.

Calls to profiler represented about 3% of page execution
time on Special:BlankPage (1.5% in/out); after this change
it's down to about 0.98% of page execution time.

Change-Id: Id9a1dc9d8f80bbd52e42226b724a1e1213d07af7
2015-01-07 11:14:24 -08:00
Alexandre Emsenhuber
3114dbea04 Replace $wgConf->localVHosts by $wgLocalVirtualHosts
The former is independent of the remaining of the SiteConfiguration
class, and as thus makes more sense to be defined as an explicit
configuration setting rather that being hidden in $wgConf.

Change-Id: I25204d37c5cfffb6953fe53e14316dc3df5b5b10
2014-10-03 03:54:44 -07:00
Kevin Israel
0d707a21ba CurlHttpRequest: Check library version, not CURLOPT_REDIR_PROTOCOLS
This works around <https://github.com/facebook/hhvm/issues/3702>.
We don't actually use the constant, so checking the library version
should suffice.

Bug: 70570
Change-Id: I732d8f7eb2908bae10100594f693cf7a63f8b5b1
2014-09-08 18:22:50 -04:00
umherirrender
1c68a1ee86 Cleanup some docs (includes/*.php)
- Swap "$variable type" to "type $variable"
- Added missing types
- Fixed spacing inside docs
- Makes beginning of @param/@return/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: I783e4dbfe5f6f98b32b9a03ccf6439e13e132bcc
2014-07-24 19:42:24 +02:00
umherirrender
4ee680a8b3 Fixed spacing
- Removed spaces after not operator (!)
- Removed spaces inside array index
- use tab as indent instead of spaces
- Add newline at end of file
- Removed spaces after casts

Change-Id: I9ba17c4385fcb43d38998d45f89cf42952bc791b
2014-07-24 11:53:04 +02:00
umherirrender
a3983418d5 Fixed some @params documentation (includes/*)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I0056b4a8df243cfc0c5f25378de48f7a35170aca
2014-04-22 13:07:02 +02:00
umherirrender
23fab68274 Fix spacing after @param and friends in comments
Searched for:
\@(param|return|throws|since|deprecated|access|todo|var)[ \t]{2,}

Change-Id: Icce22ba9fe0635455691ca58d9872d618151f346
2014-04-05 20:02:29 +00:00
jenkins-bot
55605dfbee Merge "Fixed stream wrapper in PhpHttpRequest" 2014-01-30 23:12:44 +00:00
Chad Horohoe
609a76b147 Remove setting referrer from HttpFunctions
It was introduced in 5d210b50 but no callers have ever been updated
so this always falls back on $wgTitle (which is usually wrong). It
only works on cURL, and is marginally useful at best.

Change-Id: Ic498108af9f466cefbd0072f94f0efa4055cd169
2014-01-27 16:39:20 -08:00
Tyler Anthony Romeo
499e5fd487 Fixed stream wrapper in PhpHttpRequest
Issue introduced when SSL verification was added to PHPHttpRequest.
For HTTP and HTTPS stream, PHP expects "http" as the steam context
name, regardless of SSL.

Change-Id: I12c5d3d9aded6e704ebabe85b86e556fd0e99479
Follows-Up: 1c927b1df2 (Iab2bda1ebc)
Bug: 56047
2014-01-03 09:01:42 +00:00
umherirrender
2e871f7087 Fixed spacing
- Removed double spaces in arrays
- Added space after for
- Added spaces around string concat

Change-Id: Ifbcaf35f9bfef1f97226a38b5bd74c237f61c99e
2013-12-15 20:56:09 +01:00
Mark A. Hershberger
eba84959ef Attempt to fix problems noted in phpcs.
Seen at
https://integration.wikimedia.org/ci/job/mediawiki-core-regression-phpcs-HEAD/3256/console

Change-Id: If1272366fa242ccdf1191ba1686f2d1cdf046872
2013-12-15 19:16:16 +00:00
Kevin Israel
33bc02fad1 Restore compatibility with curl < 7.16.2
Follows-up 58f71c7e9e, which assumed that the CURLOPT_CONNECTTIMEOUT_MS
constant was defined.

Bug: 58178
Change-Id: Id31a3ec56e4c7cac7d3edb2653c87be467d1a471
2013-12-09 11:34:22 -05:00
umherirrender
5ca5672aac Fixed spacing
- Place commas correct
- Moved comments
- Add space after if/foreach/catch
- Reformat some conditions
- Removed trailing spaces/tabs

Change-Id: I40ccda72c418c4a33fcd675773cb08d971510cdb
2013-12-01 20:58:51 +01:00
umherirrender
24bfde2710 Fix spacing and break some lines
Change-Id: Ia57685d8858e02e399ad5c75ce64d12609d340ac
2013-08-24 17:06:25 +02:00
jenkins-bot
94f26422ef Merge "Added SSL verification to PHPHttpRequest." 2013-06-26 21:56:40 +00:00
Brian Wolff
c1d900337c Follow up I6e64a missing global deceleration for $wgHTTPConnectTimeout
Bug: 47027
Change-Id: I3e2a84ee8a759dd2bdb2fd0837e0cd5605541816
2013-06-05 17:00:42 +00:00