Commit graph

62 commits

Author SHA1 Message Date
Fomafix
7be5a303d1 WebRequest: Add PHP return type hint for getRawVal
Improve the code to avoid phan errors detected by this type hint.

Change-Id: I134d962e1cf95f6b135f3e8959669dc41ccec877
2024-10-10 14:01:26 +00:00
Fomafix
9208216d6b WebRequest: Deprecate parameter $default in getRawVal
Use
	$request->getRawVal( 'key' ) ?? 'default'
instead of
	$request->getRawVal( 'key', 'default' )

The ?? is more flexible, avoids a wrong type detection by phan and
avoids the evaluation of the default value if not needed.

Bug: T376245
Depends-On: I3ed6b85c0d117ed7cb3a8b79f73a3eb42977891e
Change-Id: I8b02f9297b76d04e21f8cb9194f3b85631956eca
2024-10-03 15:49:33 +00:00
Umherirrender
6eec17e9a9 Add missing documentation to class properties (miscellaneous classes)
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: I1da4b272a6b28c419cc8e860d142dae19ca0bbcf
2024-09-14 10:12:18 +02:00
jenkins-bot
d4c4753514 Merge "Use type declaration for class properties holding type hinted arguments" 2024-09-12 22:53:44 +00:00
Umherirrender
512aadac31 Use type declaration for class properties holding type hinted arguments
Provided arguments already have type declaration on the construtor
and it is safe to use the same type on the class property

Change-Id: Ia8bbdc4dee59dfb487582dd514486ec8542951be
2024-09-11 20:08:50 +00: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
jenkins-bot
1243bdf8ec Merge "Remove wfRemoveDotSegments, deprecated since 1.39" 2024-09-06 19:12:40 +00:00
Ebrahim Byagowi
ea43a44a2e Remove wfRemoveDotSegments, deprecated since 1.39
It didn't have any use outside the core so went for the removal
instead of raising warning and hard deprecation.

Change-Id: I08dab348a89f1fe1adccfad4f003d9fb8b233f0d
2024-09-06 22:00:09 +03:30
Ebrahim Byagowi
ab136421a8 Hard deprecating wfGetServerUrl
wfGetServerUrl is deprecated since 1.39, let's remove the
only use and turn it into a hard deprecation.

Change-Id: I82be851fe411cd002c9c5847fe3924a6c0a4ba50
2024-09-06 16:54:31 +03:30
Derick Alangi
efb049d37e
Request: Docs should be in line with property typehint
This avoids IDEs from complaining about the divergence. Web response
can be nullable.

Change-Id: Ic5dd3c3b00e2663820fa8515742e254976f3b96d
2024-07-24 13:20:41 +02:00
WMDE-Fisch
eee356da58 Replace deprecated url functions in WebRequest
Change-Id: I5df31c330ad6a3b77fc38dc6b210007bcbb0ce2f
2024-05-04 17:01:00 +03:00
jenkins-bot
8254591942 Merge "namespace MWDebug" 2024-05-03 21:43:37 +00:00
Amir Sarabadani
214674d6b1 namespace MWDebug
Bug: T353458
Change-Id: I99d728bd111ff882220cd175ff09d4da20b81eae
2024-05-03 22:59:47 +02:00
Máté Szabó
530b6a408b WebRequest: Gracefully handle array values in getCookie()
Given a cookie header like "Cookie: foo[]=bar;foo[]=bar2', PHP will
assign $_COOKIE['foo'] = [ 'bar','bar2']. This is not expected by
callers in MediaWiki and can trigger various errors in code that does
not expect to be dealing with arrays in this situation, nor is it
specified by RFC 6265[1] or any of its predecessors. So, stick to RFC
semantics here and treat the cookie as absent, since the name foo[] is
not the same as foo.

[1] https://datatracker.ietf.org/doc/html/rfc6265

Bug: T363980
Change-Id: Idaa175234de2d25a90e6be8fb6279c39089726bd
2024-05-02 12:05:43 +02:00
jenkins-bot
8f440393be Merge "WebRequest: improve documentation" 2024-04-08 22:06:56 +00:00
Novem Linguae
5703ec35ed WebRequest: improve documentation
It wasn't at all obvious to me what $request->getText()
and similar actually get. I noticed that all of them read the
$this->data variable, and the comment for that variable
states that it is the $_GET, $_POST, and path router data,
so I have explicitly added this to the comments for each
related get method.

Change-Id: I89ad4016622bbc6c8c3abf5e47d273e19b38d5dc
2024-04-08 11:47:21 -07:00
jenkins-bot
638236e3fe Merge "Introduce entry point classes for media files." 2024-04-03 15:50:32 +00:00
daniel
9638fa314a Introduce entry point classes for media files.
This moves a code out of file scope into classes to make it
testable. The code is left in the same structure as it was before,
global functions have been converted into methods on the new
ThumbnailEntryPoint and Thumbnail404EntryPoint classes.

This test introduces comprehensive phpunit tests covering all functional
code paths in ThumbnailEntryPoint. This is intended to support
refactoring of this code.

Change-Id: I459abc7b11d0ab4ee682a863c9525a945048296f
2024-03-30 21:14:05 +01:00
Robert Timm
7026c5cd0b WebRequest: detectServer appends default ports that should be omitted
In MediaWiki 1.41.0 the function WebRequest::detectServer() started to generate server URL strings containing default ports such as 80
for http and 443 for https.

Before 1.41.0: https://my.wiki
After  1.41.0: https://my.wiki:443

detectServer() uses IPUtils::combineHostAndPort() to build the URL. The
latter function has actually a mechanism built in that intends to omit
standard ports, so the new behavior in MW 1.41.0 seems unintended.

As this broke WDQS over here in our Wikibase Suite bundle, I
investigated the cause.

MediaWiki 1.41.0 updates IPUtils from 4 to 5. With this update, there
was a change that compares the port now via === instead of ==.
(e68cf6a14e%5E%21/#F1
Line 383) The new behavior is correct, as the function expects an int.
MediaWiki passes in a string though. This bug was hidden with IPUtils 4,
but is triggered now in IPUtils 5.

I think this should be backported to REL1_41.

Change-Id: Ib707ee72e02cf99225168d268d5fedab3f548ead
Bug: T360608
2024-03-28 11:03:28 +00:00
Umherirrender
723134eade Add explicit parentheses around mixed boolean operator
Mixing different binary boolean operators within an expression
without using parentheses to clarify precedence is not allowed (T358966)

Change-Id: I24ca752d5dac7c948fdbcabf721f6f0aef8a466f
2024-03-23 01:58:59 +01:00
James D. Forrester
8e940c4f21 Standardise all our class alias deprecation comments for ease of grepping
Change-Id: I7f85d931d3b79da23e87b4e5692b2e14be8fcaa0
2024-03-19 20:11:29 +00: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
Brooke Vibber
dcd9c3ae26 Update name & email for bvibber
Updating name & email addresses for Brooke Vibber.

Re-ran updateCredits.php as well so there are some new entries in
there as well.

There are a couple of files in resources/libs that will have to
be changed upstream to keep tests happy, I will do patches
later. :D

Change-Id: I2f2e75d3fa42e8cf6de19a8fbb615bac28efcd54
2024-02-08 17:02:16 -08:00
jenkins-bot
41a6db4c0e Merge "WebRequest: Remove 'deprecated' mark from unstable Telemetry pointer" 2024-02-07 18:13:32 +00:00
Timo Tijhof
63270f35cd WebRequest: Remove 'deprecated' mark from unstable Telemetry pointer
While not formally specified in the Stable interface policy, it is
imho not recommended to deprecate a method in a stable class with a
pointer to a method in an `@unstable` class. This sends a mixed signal
to developers.

Keeping this as wrapper method is harmless either way, but I suggest
removing this so that we do not create send automatic nudges to
contributors to change existing code (yet).

Bug: T346211
Change-Id: Iddf8f286e3ffdfce32a8fc2cc95a4e1d4893e146
2024-02-07 17:37:55 +00:00
Tim Starling
7c81d82d76
Stop using $wgUseSameSiteLegacyCookies
* Deprecate the wgUseSameSiteLegacyCookies configuration variable and
  imply false (the previous default).
* Deprecate WebRequest::getCrossSiteCookie(), which was introduced to
  support this feature.
* Ignore the sameSiteLegacy option if it is passed to
  WebResponse::setCookie() or mediawiki.cookie.set(). The configuration
  variable can't be removed until the after the JS change is deployed.

Bug: T344791
Change-Id: I30392ebc02809bc6b6ee2070d3e468e48d5d1fae
2024-02-06 16:25:38 -08:00
Taavi Väänänen
c68b993860
WebRequest: Fix default for backwards compat
Fixes an unintentional breaking change in commit
24d0aee05e.

Bug: T356800
Change-Id: I86d7f1c3845141db301c86accbdf677bef71561d
2024-02-06 22:04:20 +02:00
jenkins-bot
bf22917ed1 Merge "entrypoint: Isolate entry points from PHP runtime for testing" 2024-02-02 19:59:11 +00:00
daniel
24d0aee05e entrypoint: Isolate entry points from PHP runtime for testing
1) Introduce EntryPointEnvironment which wraps functions that interact
with the PHP runtime, so they can be mocked for testing.

2) Allow server info fields to be overwritten in FauxRequest.

3) Make MediaWikiEntryPoint use WebResponse to set headers

Bug: T354216
Change-Id: Ic21950c956de5d2b5a7dd66a1e2de58f807cfd9f
2024-02-02 13:03:29 +01:00
Amir Sarabadani
4c68983623 Drop deprecated config $wgAllowImageTag
Soft-deprecated since 1.35 and hard-deprecated since at least
I9776d11d4e2d184 (1.39).

Not set in production.

Change-Id: I68b68ffcdff22daafad34c186d1cc609dcecbf32
2024-01-30 11:42:54 +00:00
Tim Starling
9c02258a04 Use thousands separators in selected integer literals
For readability. Allowed since PHP 7.4.

I searched for integer literals of 6 or more digits, and also changed
some nearby smaller numbers for consistency.

Bug: T353205
Change-Id: I8518e04889ba8fd52e0f9476a74f8e3e1454b678
2023-12-12 09:22:45 +11:00
jenkins-bot
317bcdbbbc Merge "ContentSecurityPolicy: Expose directives" 2023-11-15 20:11:33 +00:00
Gergő Tisza
6fbd223f1d
ContentSecurityPolicy: Expose directives
Instead of only exposing the ability to send CSP headers, expose
the values of the headers so they can be set via other mechanisms.

Bug: T169027
Change-Id: Ie9f7a29218392e3bc3215ce879ed2a3c48847a7c
2023-11-14 20:43:35 -08:00
Máté Szabó
ddbd5735a0 WebRequest: Fix PHP 8.1 deprecations in getFuzzyBool()
WebRequest::getFuzzyBool() will emit a deprecation warning on PHP 8.1 or
newer if the parameter to be fetched is absent and the $default value is
set to `true`, because strcasecmp() no longer accepts nulls. Fix it by
returning out if the parameter is wholly absent and add a test for this
scenario.

Bug: T351088
Change-Id: I85bbfec6aabef4e85859a76b6e50c80781024ae5
2023-11-13 15:35:55 +01:00
Derick Alangi
0ee08d6616 Request: Deprecate methods in WebRequest class
Deprecated methods are:
* WebRequest::isSafeRequest()
* WebRequest::markAsSafeRequest()

Introduced in I43f4bc06c19d823d7d1f (549af8bf) and used in
I01ae2f045726208d2af7 (ce3a25be), then later removed in I4eb10817cccb40aa255
(e34fd634) which became unused in core.

As a result, it made markAsSafeRequest useless as there is really no
consumer at this point.

No known usage (confirmation) per our code search tool today. See below:
https://codesearch.wmcloud.org/search/?q=isSafeRequest&files=&excludeFiles=&repos=

Change-Id: I39cfb04c46374153d374fe0bb88690fa48ad7250
2023-10-03 11:31:03 +00:00
Daimona Eaytoy
95d75e831a Add first batch of taint-check annotations
These are the same as taint-check's MediaWikiSecurityCheckPlugin.php.

The notable exception is methods in WebRequest that were previously
hardcoded as returning a safe value. This was a consequence of said
methods return safe types (e.g., int, bool). Instead of adding
taint-check annotations, add return typehints instead, which let
taint-check remove any taintedness.

Fix some taint-check issues that were previously not spotted or whose
suppressions were removed in other patches.

Also fix the following bugs spotted by phan thanks to the type hints:
- SpecialExport did not have explicit handling of null $depth, and just
  returned 0 because null fails both the < and the > comparisons.
- Improve documentation of params and props in ProtectedPagesPager.
  SpecialProtectedPages can pass null $namespace and $size.
- Remove unused parameter from SpecialProtectedPages::showOptions, of
  which $ns and $size were not documented as nullable.
- Add FIXMEs in SpecialVersion about very inconsistent escaping.

Bug: T321806
Change-Id: I726f528856614c92329683a0ad8936a42e262748
2023-09-23 17:51:06 +02:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
468e69bccc Namespace Sanitizer under \MediaWiki\Parser
Bug: T166010
Change-Id: Id13dcbf7a0372017495958dbc4f601f40c122508
2023-09-21 05:39:23 +00:00
Piotr Miazga
7f7712b1dd http: HeaderCallback should inject all telemetry headers
With OpenTelemetry standard we should inject all `X-Request-Id`,
`tracestate` and `traceparet` headers to MediaWiki response.

Bug: T340573
Change-Id: Id0343fc8fdc04c21bb5067df7e643ca9cfb68abb
2023-09-14 20:33:45 +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
James D. Forrester
af850fdd85 Follow-up 9743136: Add in-code comment on alias for when it was added
Change-Id: Idb5019228f4b1d4fce88702853eeee3f08a77edf
2023-08-29 01:29:03 +00:00
James D. Forrester
28efa12cc2 Follow-up 7690ab4: Add in-code comment on alias for when it was added
Change-Id: I27f796db7a7f8f05380204eb72be8c7a4456af24
2023-08-28 14:34:10 -04:00
James D. Forrester
1e6030e111 Follow-up bc1af1a: Add in-code comment on aliases for when they were added
Change-Id: I4efc89a13637cbc4ad78882d50a35641f3e426bd
2023-08-28 14:32:59 -04:00
James D. Forrester
e0d1e6e174 Follow-up bbe704b: Add in-code comment on aliases for when they were added
Change-Id: I1883eaf8b58d2da9b989584efa203745fd512640
2023-08-28 14:31:53 -04:00
James D. Forrester
f08a920152 Follow-up bfedab2: Add in-code comment on alias for when it was added
Change-Id: I20731e435a6fbf8d7f507a1627ea49d6aeb54469
2023-08-28 14:29:40 -04:00
jenkins-bot
267af890e1 Merge "ResourceLoader: Remove support for CSP nonce" 2023-08-10 23:25:21 +00:00
Timo Tijhof
b28faecb2b ResourceLoader: Remove support for CSP nonce
The "nonce" CSP feature has been never been properly tested and is not
on track to be enabled at WMF or in MW by default. The use of
nonce-protected eval is not particularly meaningful. It is trivially
bypassed by mw.loader.implement, mw.loader.store, or importScript();
all of which allow any code to be executed directly, or to be stored
and loaded from a first-party origin.

The "nonce" feature is not required for the T208188 roadmap, and with
change I51b8535b2b21a3 there is now also a (small) performance reason
to keep this disabled long-term.

Until and unless there is a plan for enabling this particular aspect
of CSP, we might as well remove it so that we don't waste time our
time building abstraction layers and satisfying dependency injection
through many years for something that might never be used.

Note that this does not remove CSP support from ResourceLoader, and
does not take away from the future of enabling CSP in MediaWiki to
e.g. strictly block third-party scripts, or to require domains to
opt-in by site config or user pref (T208188).

Change-Id: I5a176c41a06a484a11e64bdacdc42b40811fe72e
2023-08-09 02:30:39 +01:00
jenkins-bot
49cb8edc37 Merge "http: Propagate tracestate and traceparent headers" 2023-08-08 01:07:08 +00: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
jenkins-bot
2ee9beafb5 Merge "ResourceLoader: use Function constructor for module implementations" 2023-08-06 21:35:24 +00:00