Commit graph

138 commits

Author SHA1 Message Date
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
Umherirrender
f910edce6d Add @phan-mandatory-param for function name arguments
Providing the function name is often optional from the php code,
but it is needed for better logging, so make it mandatory and let phan
report issues about this.

Bug: T374546
Depends-On: Iaed5489a85a5a6e685829e151436afc94310fbd0
Depends-On: Ie2a1e5052e5b61bbb5b89905de942f47d3f1413d
Change-Id: I5227f2fa65850ac8c6f620900f22d1f4e7bfd470
2024-09-20 16:23:17 +00:00
jenkins-bot
bc644fbf77 Merge "http: Remove timestamp from 'http' channel logs" 2024-09-17 22:23:10 +00:00
Adam Wight
188d2cbbb0 Remove unchecked exception annotations
Callers should not catch an unchecked exception, so it doesn't belong
in a function signature.  Unchecked exceptions indicate a coding error,
which by definition the code will not be able to handle correctly.

If any of these exceptions were supposed to be in response to an edge
case, user input, or initial conditions, then they should be changed
to a runtime error.  If the exception class cannot be changed, then
the annotation should include a comment explaining its purpose and
prognosis.

Bug: T240672
Change-Id: I2e640b9737cb68090a8e1cb70067d1b74037d647
2024-09-17 22:20:58 +02:00
Bartosz Dziewoński
806fbaaed5 http: Remove timestamp from 'http' channel logs
The timestamp is redundant with the timestamp that should be injected
by the log formatter, and it makes it more difficult to find identical
log messages.

Change-Id: Ifa0529a5f8233be5adc16fa7632542f39916fda9
2024-09-17 20:26:03 +02:00
Umherirrender
3a24944de4 http: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: I6dd402a5bca0c2136595faedae315959bbcf17d9
2024-09-14 10:04:40 +02:00
James D. Forrester
2b11d61577 Migrate all uses of deprecated URL global functions to use wfGetUrlUtils()
wfGetUrlUtils() is also deprecated, but less so, so we can do this first
and then properly replace the individual uses with dependency injection
in local pieces of work.

Also:
* Switching Parser::getExternalLinkRel to UrlUtils::matchesDomainList
  exposed a type error in media.txt where $wgNoFollowDomainExceptions
  was set to a string (which is invalid) instead of an array.

Bug: T319340
Change-Id: Icb512d7241954ee155b64c57f3782b86acfd9a4c
2024-09-10 16:50:02 -07:00
Ebrahim Byagowi
a5c7a67fca Avoid use of deprecated global functions in MWHttpRequest
Bug: T319340
Change-Id: I757180bd8aa59bd51bd42661724dc99f8d56016f
2024-09-09 20:55:47 +00:00
Bartosz Dziewoński
d46fdf645b Replace a few more uses of deprecated Status / StatusValue methods
Change-Id: I017bcaffe6945d633d7387f9391803845369bfed
2024-08-22 19:34:51 +00:00
Ebrahim Byagowi
6e093bbe2d Add namespace and deprecation alias to MultiHttpClient
This patch introduces a namespace declaration for the
Wikimedia\Http to MultiHttpClient and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I4ebc1a3b496de08b2b430301da376578d13fcfe6
2024-05-20 00:32:45 +03:30
Martin Urbanec
9538ab8435 Do not mark HttpRequestFactory as @internal
The @internal annotation was added
in  I3e5e54afa21f8c099877b3765c769f2d2f8f5d61
with no explanation. The current annotations advise extensions
to not use HttpRequestFactory, which renders extensions
unable to make HTTP requests when they need to.

This appears to be a declaration added by a mistake,
intending to make the constructor itself as @internal.
Since constructors are unstable by default, this patch
removes the @internal annotation with no replacement.

Change-Id: I9696034fb014c6a87b4532bff22d8c9d494e9bb1
2024-05-13 17:07:11 +02:00
Piotr Miazga
93867c106f MWHttpRequest: Drop support for creating without timeout or connectionTimeout, deprecated in 1.35
In 1.35 we deprecated not passing the timeout and connectionTimeout settings
when constructing the MWHttpRequest object.

Upgrade hard-deprecation via wfDeprecated() to instead throw an InvalidArgumentException.

Change-Id: I260469c6235fa9022b264757b0a17d498cee1396
2024-05-05 15:16:32 +03:00
Umherirrender
ba7b6a5bbd build: Resolve MediaWikiNoEmptyIfDefined suppression
Follow-Up: Id183ab60994cd9c6dc80401d4ce4de0ddf2b3da0
Change-Id: Iac6aa104331ffc26460f8360b252e03d2307e6fd
2024-02-14 21:47:18 +01:00
James D. Forrester
102a4f8a35 build: Upgrade mediawiki/mediawiki-phan-config from 0.13.0 to 0.14.0 manually
* Switch out raw Exceptions, mostly for InvalidArgumentExceptions.
  * Fake exceptions triggered to give Monolog a backtrace are for
    some reason "traditionally" RuntimeExceptions, instead, so we
    continue to use that pattern in remaining locations.
* Just entirely give up on PostgresResultWrapper's resource vs. object mess.
* Drop now-unneeded false positive hits.

Change-Id: Id183ab60994cd9c6dc80401d4ce4de0ddf2b3da0
2024-02-10 02:22:41 +00:00
thiemowmde
7e70b8042c Use the instanceof and ::class features instead of strings
This makes it much easier for IDEs and tools like Phan to understand
what's going on. Note this syntax is perfectly valid even if a class
is undefined. Language features like `use`, `instanceof`, and
`class_exists` work perfectly fine. We do this a lot in existing
code.

Change-Id: I4d397621ebcc6a7e842150f7641c1b23d082b730
2024-02-02 14:50:15 +00:00
Bartosz Dziewoński
6876ccf177 Replace $wgCommandLineMode checks with MW_ENTRY_POINT in other places
I'm not sure if there's a good way to split this up into
logical chunks.

Bug: T313841
Change-Id: I3b35a2e475b5143f383d4085fbc6a0ed3bbc32b8
2024-01-02 22:17:14 +01:00
Piotr Miazga
fbbe0ca2d9 shellbox: Use Telemetry class instead of WebRequest::getRequestId()
ShellboxClientFactory should depend upon HttpRequestFactory to provide
a fully initialized HTTP Client. It shouldn't handle things like
`X-Request-Id` as it's HTTP layer responsibility. More over the
`WebRequest::getRequestId()` got deprecated in favour of Telemetry class.

Bug: T346209
Change-Id: If7630f81be4d7ca94ab0cac02b2a30126e3a297d
2023-09-19 14:00:25 +02:00
jenkins-bot
7f9538e32a Merge "http: MultiHttpClient supports TelemetryHeadersInterface" 2023-09-12 20:42:27 +00:00
Piotr Miazga
8009e9d027 http: MultiHttpClient supports TelemetryHeadersInterface
Introduce a new interface Wikimedia/Http/TelemetryHeadersInterface
that provides telemetry information that could be attached to
HTTP Requests. MultiHttpClient is expecting `telemetry` option
of TelemetryHeadersInterface type.

The MediaWiki/Http/Telemetry implements the interface, therefore
ObjectCache can inject it to RESTBagOStuff, that further injects
it to MultiHttpClient.

Bug: T344926
Change-Id: I59a3f1048c403fe2e4ef0c74353dfe74ff9ca893
2023-09-12 18:05:17 +02:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
Reedy
f0c6a74779 HttpRequestFactory: Minor cleanup
Change-Id: Ia764e1b4a4d306ab4fe294aa45fd0f8306810b19
2023-08-26 19:39:22 +01:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Piotr Miazga
1981e704c7 http: fix JobRunner overriding requestId with null
After deploying T320559 we found out that JobRunner sometimes calls
the WebRequest::overrideRequestId() with a null. This caused the
TelemetryService to fail due to $newId not being a string.

As a solution there is a new method called regenerateRequestId()
that will handle the regeneration as it's recommended to keep the
overrideRequestId() strict.

Bug: T343893
Change-Id: I3e6daa238fd8de0d9ea88660b8ba32b922b1323d
2023-08-09 18:13:58 +02:00
Piotr Miazga
67c1e15469 http: Propagate tracestate and traceparent headers
Introduce a Telemetry singleton for propagating `tracestate` and
`traceheaders` during a MW web request. This class allows for easier
testing and mocking.

In the future we might use this as a wrapper for OpenTelemetry.

Bug: T320559
Change-Id: I3e5e54afa21f8c099877b3765c769f2d2f8f5d61
2023-08-07 21:04:19 +00:00
Umherirrender
8315e91863 Remove deprecated MWHttpRequest::factory
Bug: T324918
Change-Id: Ie03d4b25eb239bbbbc2346821a86f09c29e03524
2023-04-26 22:23:06 +02:00
Umherirrender
4a1479c9cc Remove deprecated class Http
The class and all functions are deprecated:
- Http::request()
- Http::get()
- Http::post()
- Http::userAgent()
- Http::isValidURI()
- Http::getProxy()
- Http::createMultiClient()

Bug: T305813
Change-Id: Icd8af4822b16b4bf4558b756e20171c3ae9a9fa1
2023-04-24 21:52:32 +02:00
jenkins-bot
709338ceb4 Merge "Hard-deprecate Http::request/get/post/userAgent/isValidURI" 2023-02-23 23:35:22 +00:00
Umherirrender
a486e302ac Hard-deprecate MWHttpRequest::factory
Bug: T324918
Change-Id: I360d57b5aa9e2e8cbfc8b5c5654ab1aaf1d944b3
2023-02-13 23:22:11 +01:00
Umherirrender
2406a2557a Hard-deprecate Http::request/get/post/userAgent/isValidURI
* Http::request
* Http::get
* Http::post
* Http::userAgent
* Http::isValidURI

Bug: T305813
Change-Id: I4f8410f43128c0f53742cca055027c2e9ebcde44
2023-02-13 22:57:23 +01:00
Gergő Tisza
2cef0d5bbe http: Log GuzzleHttpRequest requests
MwHttpRequest has a logger option, but GuzzleHttpRequest ignored
it; fix that.

This will log something like

  [2023-02-08T06:50:29+00:00] GET http://127.0.0.1:22100/ HTTP/1.1 - 301 NULL

to the http channel, at level INFO on successful and at level
ERROR on failed requests.

Change-Id: I2e4067c67aace434ed111a1a09f03888ea43e924
2023-02-08 17:34:33 +00:00
Reedy
eaf25da2d3 MWCallbackStream: Add explicit $stream property
Bug: T324895
Change-Id: Ic347beb30b50fe76f02855700f770195a5eabf8a
2022-12-27 17:03:25 +00:00
thiemowmde
70aa9c8e35 Make use of ?:, ?? and ??= operators in mostly trivial cases
The motivation is to make the code less confusing. I hope this is the
case.

?? is an older PHP 7.0 feature.
??= was added in PHP 7.4, which we can finally use.

Change-Id: Id807affa52bd1151a74c064623b41d950a389560
2022-12-05 21:37:13 +01:00
Umherirrender
ea5ea60b31 Various doc fixes about false on method arguments/return types
Doc-only changes

Change-Id: I5177f582ae7ee70c357e9389fed14819faf79463
2022-11-10 19:23:46 +00:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Aryeh Gregor
4a52bf553f Use MainConfigNames instead of string literals, #3
This edition brought to you by:

grep -ERIn $(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | tr
"\n" '|' | sed 's/|$/\n/') includes/

I only corrected a fraction of the results provided by that command. I'm
submitting the partial patch now so it doesn't bitrot.

Bug: T305805
Change-Id: If1918c0b3d88cdf90403921e4310740e206d6962
2022-04-26 14:31:26 +03:00
Aryeh Gregor
747bc81ac0 Use MainConfigNames instead of string literals
Part 1, proof of concept. Hundreds of files left to go. These changes
brought to you in large part by vim macros.

Bug: T305805
Change-Id: I44789091e9f6394c800a11b29f22528c8dcacf71
2022-04-11 17:53:27 +03:00
jenkins-bot
6223ce2381 Merge "phan: Remove PhanTypePossiblyInvalidDimOffset suppression" 2022-03-29 17:15:46 +00:00
Umherirrender
830d8e9bb5 Check return of parse_url for used url parts
Found by phan (T304887)

Change-Id: I3105a5fd4826f8667b5232834defc5ec93be32a1
2022-03-29 18:43:33 +02:00
Umherirrender
7aa0884029 phan: Remove PhanTypePossiblyInvalidDimOffset suppression
Make phan stricter about array keys
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T304887
Depends-On: I3105a5fd4826f8667b5232834defc5ec93be32a1
Depends-On: Ie9610a6e83731468311edb3ed17f80fc509de385
Change-Id: I701f12ab94478c3b8e7fd82110ade74a8e6b04ef
2022-03-28 23:26:49 +02:00
Umherirrender
ce9388af05 http: Fix return types in MwHttpRequestToResponseInterfaceAdapter
Even all the function throws, the return type should match the interface

Found by phan strict checks

Change-Id: I43669320d7abfc5ee36602aea9ed21bf675dde96
2022-02-26 09:07:55 +01:00
daniel
d599a54e5f HttpRequestFactory: allow 0 to mean no max timeout.
$wgHTTPMaxTimeout and $wgHTTPMaxConnectTimeout used to default to INF,
the positive infinity float value. This value has no representation in
JSON. In order to allow default configuration values to be defined in
a JsonSchema, we allow 0 to be used to represent "no limit" instead.

Bug: T294788
Change-Id: Id1b832b46ac6984655dcf0c06d5af7d356cca800
2022-01-28 18:40:03 +01:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
jenkins-bot
479cde3fca Merge "Support $wgLocalHTTPProxy in MultiHttpClient" 2021-11-22 21:36:42 +00:00
Kunal Mehta
bfad87aae8 http: Don't set X-Forwarded-Proto when using a reverse proxy
Discussion on Ia16d8f86b1cb20 indicates that we want to go in the other
direction - MediaWiki shouldn't set X-Forwarded-Proto, rather the
reverse proxy (envoy in Wikimedia's case) should set it.

This follows-up cc241c2add.

Bug: T288848
Change-Id: Ifc5e9da9a02b45d9d1ad51c3e1389f9ac7325c86
2021-11-17 23:09:24 +00:00
Kunal Mehta
f539b6f58c Support $wgLocalHTTPProxy in MultiHttpClient
This follows the same approach as MWHttpRequest, we inject
$wgLocalVirtualHosts, and for each request check whether it matches that
domain list, rewriting the request as necessary.

Unfortunately this requires a decent amount of code duplication because
MultiHttpClient is in includes/libs/ and can't depend on the same code
in MWHttpRequest.

Bug: T288848
Change-Id: Ia16d8f86b1cb20dde9fe487729d67d92af650cfe
2021-11-16 11:13:10 -08:00
Reedy
2d27b46802 Update deprecated Guzzle Psr7 function calls
Change-Id: If7cc461559d4857a7bae8b71cc8283fbabfe9a28
2021-11-11 16:00:34 +00:00
Petr Pchelko
928f707731 Remove old HTTP request implementations
Since 1.34 setting non-default HTTP engine
has been deprecated. It's time to remove
the old implementations. Only Guzzle is
now available.

Change-Id: I978b75827e69db02cbc027fe0b89a028adfc6820
2021-11-08 07:04:06 -08:00
Kunal Mehta
cc241c2add Allow using a reverse proxy for local HTTP requests
$wgLocalHTTPProxy can be used to configure a reverse proxy
for requests to domains in $wgLocalVirtualHosts. The previous
implementation of using it as a proper HTTP proxy is no longer
supported and has been reverted out of REL1_37 (856da72363d1ba8bf).

It sets the hostname of the request as a "Host" header, scheme as
"X-Forwarded-Proto" and then sets the proxy's scheme, host and port as
those of the request.

Bug: T288848
Change-Id: Ibc3616f5ad925d464d937ab15461a88619c8b7a7
2021-10-15 10:56:46 -07:00