Commit graph

2864 commits

Author SHA1 Message Date
Máté Szabó
b99dcc23bc parser: Gracefully handle invalid ParsoidRenderID keys
Why:

- ParsoidRenderID::newFromKey() validates incoming keys and throws an
  InvalidArgumentException if a required key component was missing.
- It does so by eagerly destructuring the return value of explode(),
  which causes a PHP Notice for invalid inputs as the expected offsets
  won't exist then.

What:

- Check the count of key parts before destructuring.
- Add unit tests.

Bug: T385567
Change-Id: I1d936ae038f85ffa2e5d1d3d8a75fdc75e4c8ef8
(cherry picked from commit eec130925c081c2da1c475f9a9ce719e6838ca51)
2025-02-04 14:54:31 +00:00
Máté Szabó
6ed44af225 tests: Disable flaky test ClockTest::testShouldReturnCurrentTime
Why:

- The test ClockTest::testShouldReturnCurrentTime is flaky.
- Ie48d9400cf3bb99467a16b9ea0cce6172e2e2568 recently augmented
  the ConvertibleTimestamp library to allow faking hrtime(), which will
  be a better solution for this class and test than the current
  assertion.

What:

- Skip the test until core is updated to the latest version of
  ConvertibleTimestamp.

Bug: T379562
Change-Id: Iae502ed0344f45f89da575f1c5d1e0fb9c1e4dfa
(cherry picked from commit a930114b4240ec311a56eef7f814f378cc3d5f88)
2024-11-22 17:10:22 +00:00
Jdlrobson
276627160f Merge "Hard deprecate soft deprecated skin methods" into REL1_43 2024-11-13 00:27:38 +00:00
Bartosz Dziewoński
4efe6fe7e2 Message: Downgrade exception on bool/null param to warning
Bug: T378876
Change-Id: Iecbf83dd060b2a1dc30bd33bfc4f2a42cfbd2a1f
2024-11-02 12:18:56 +00:00
Jon Robson
72ab4c0398 Hard deprecate soft deprecated skin methods
Bug: T377521
Depends-On: I4f66ce9929e0240e1c89f59ef781d0a378263322
Change-Id: I4c249acb1fcd0848428c99b8d3badebbc38b5dac
(cherry picked from commit 8767d589fe6e26034dab5c39f2546ec2ce8fed39)
2024-10-30 21:22:46 +00:00
Lucas Werkmeister
054d8d334a SECURITY: Message: Don’t call is_callable() on strings
This can cause PHP to try to load the param value as a class, with
potentailly disastrous results (though it’s not quite clear if this can
actually cause attacker-supplied code execution or not).

Bug: T377912
Change-Id: I0239b3e65cf516c6fdf287882f05e47a01f963c1
(cherry picked from commit cdf11b23474024dfe39057993372f2126302e244)
2024-10-26 21:41:52 +00:00
Reedy
e4bee84a27 AutoLoader: Use require_once rather than require
This was seen in WMF production during a train deployment, where namespacing of classes,
which had been serialized (for example CacheTime), along with our PSR-4 definitions may result
in cases where PHP tries to load the same PHP file more than once. Combined with non obvious
error messages, require_once gives us better behaviour and error messages.

More explicitly:
In T378006, the autoloader is entered from class_exists(), and the class has a filename
resolvable with PSR-4 which is already loaded by a non-PSR-4 class name. Using require_once
would allow class_exists() to return false in that case.

In T372500, the autoloader is entered from unserialize(). It looks like require_once would
just give you a more informative error message.

Bug: T378006
Bug: T372500
Change-Id: I928f29198af9baf81a3cae604b3adf41595c2176
(cherry picked from commit 03dd4ae7ae0e2ce7e45f0bf2cb913642eef842a8)
2024-10-24 01:36:18 +00:00
James D. Forrester
f660c1d936 Add a test freezing extension.schema.v1.json in it current form
Bug: T258668
Change-Id: I609cb3caa9d73c611253b80d5c068197a5c92dda
2024-10-23 19:53:38 +00:00
Andre Klapper
aab00c9530 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.

Followup to e662614f, using PHPStan.

Bug: T376276
Change-Id: I60d639b042b537bf2f531cc132f1b75a66b85acb
(cherry picked from commit da0a395efa7847916371f9c0a6b271faa022ff59)
2024-10-23 17:20:01 +00:00
Umherirrender
1b29f07440 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I73fb416573f5af600e529d224b5beb5d2e3d27d3
2024-10-21 20:41:20 +02:00
Umherirrender
839613ff77 tests: Use namespaced classes
Changes to the use statements and some additions
are done automatically via script
This also updates @covers tag for the namespaced classes

Change-Id: I859ba6d05018c99710b744e2becab432410d3bca
2024-10-21 18:53:02 +02:00
Bartosz Dziewoński
9d56257d8c Make Message and MessageValue compatible
Fix two problems that made it difficult to convert between Message
and MessageValue, or to write code that could accept both of them,
as exemplified by the StatusValue class:

* Implement a common interface
* Use the same internal format for message parameters

While these changes should be compatible with most of existing code,
where the authors were courteous enough to simply call methods such
as Message::numParam() and not look inside the values they return,
it is potentially a breaking change for anything that depended on
the formatted params being arrays or accessed their keys.
Example patches: https://gerrit.wikimedia.org/r/q/topic:message-param

Notable changes:

* Message and MessageValue now both implement MessageSpecifier
  (only Message implemented it before).

* Message::numParam() and other static methods for encoding params
  now return MessageParam objects, instead of special arrays.
  Use these MessageParam objects internally in Message.

* Narrow down the return type of MessageSpecifier::getParams() (it
  was just `array`, allowing any type in the array). Narrow down the
  types for Message::params() and MessageValue::params() to match.

* Deprecate MediaWiki\Message\Converter. As a replacement add
  MessageValue::newFromSpecifier(), which is analogous to
  Message::newFromSpecifier(), but without weird legacy edge cases.

* Make StatusValue::getMessages() return MessageValues. Remove code
  that converted between Message and MessageValue, no longer needed.

* Update many type declarations and comments to use MessageSpecifier
  instead of MessageValue, as well as a couple of tests that depended
  on implementation details.

Bug: T358779
Change-Id: I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83
2024-10-19 15:00:07 +02:00
jenkins-bot
abc8da60be Merge "Use explicit nullable type on parameter arguments" 2024-10-16 23:10:14 +00:00
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
James D. Forrester
e7db78e8d6 Replace uses of deprecated ChangeTags static methods
Bug: T360664
Change-Id: I3363a225e54bb2cae01ba066d432a8b7b21933d2
2024-10-16 13:30:12 -04:00
jenkins-bot
12f1cf5e59 Merge "ConditionalDefaultsLookup: allow to dynamically add conditions for evaluation" 2024-10-16 16:49:03 +00:00
Sergio Gimeno
37985a198d ConditionalDefaultsLookup: allow to dynamically add conditions for evaluation
Why:
To facilitate the evaluation of conditions not directly
"known" by the lookup, eg: owned by extensions

What:
- Add ConditionalDefaultOptionsAddCondition hook which
runs before instantiating ConditionalDefaultsLookup allowing
to add conditions for evaluation in the $extraConditions
array.
- Evaluate the configured conditional default against the
 extra added conditions after evaluation of "known"
conditions.

Bug: T376918
Change-Id: Ife6f96397eafd61fdb40528aac315ddde1ef2774
2024-10-16 17:39:12 +02:00
jenkins-bot
0b45e77a8b Merge "Language: Introduce getContentLanguageCode() service" 2024-10-16 14:15:12 +00:00
Amir Sarabadani
c65e133f18 Language: Introduce getContentLanguageCode() service
And use that as much as possible. This makes bootstraping services much
faster since Language object is extremely heavy (specially to
initialize) and that's why in LanguageFactory it's behind a cache (see
LanguageFactory::getRawLanguage)

At the same time, most uses of Language object only need the language
code (after normalization and mapping and validation) and this allows
such change to happen fast and way more decoupled from Language object
that has more than 100 methods.

Bug: T376565
Change-Id: I1c3d94454896842939dfaad8cbf742e5a3ae5438
2024-10-16 11:02:01 +02:00
jenkins-bot
5579e0647c Merge "[JsonCodec] Use wikimedia/json-codec to implement JsonCodec" 2024-10-16 00:54:33 +00:00
C. Scott Ananian
3bc172d0e4 [JsonCodec] Use wikimedia/json-codec to implement JsonCodec
This adds support for serializing/deserializing objects which
implement the JsonCodecable interface from the wikimedia/json-codec
library used by Parsoid.  JsonCodecable allows customizing the encoding
of objects of a given class using a class-specific codec object, and
JsonCodecable is an interface which is defined and can be used outside
mediawiki core.

In addition json-codec supports deserialization in the presence of
aliased class names, fixing T353883.

Backward and forward compatibility established via the mechanism
described in
https://www.mediawiki.org/wiki/Manual:Parser_cache/Serialization_compatibility

Test data generated by this patch was added in
I109640b510cef9b3b870a8c188f3b4f086d75d06 to ensure forward
compatibility with the output after this patch is merged.

Benchmarks:
                        PHP 7.4.33          PHP 8.2.19          PHP 8.3.6
                      BEFORE    AFTER     BEFORE    AFTER     BEFORE    AFTER
Serialize:            926.7/s  1424.8/s   978.5/s  1542.4/s  1023.5/s  1488.6/s
Serialize (assoc):    930.2/s  1378.6/s   974.6/s  1541.9/s  1022.4/s  1463.4/s
Deserialize:         1942.7/s  1961.3/s  2118.8/s  2175.9/s  2129.8/s  2063.5/s
Deserialize (assoc): 1952.0/s  1905.7/s  2107.5/s  2192.1/s  2153.3/s  2011.1/s

These numbers definitely do not have as many significant digits as
written here.  But they should be sufficient to demonstrate that
performance is not impaired by this patch and in fact serialization
speed improves slightly.

Bug: T273540
Bug: T327439
Bug: T346829
Bug: T353883
Depends-On: If1d70ba18712839615c1f4fea236843ffebc8645
Change-Id: Ia1017dcef462f3ac1ff5112106f7df81f5cc384f
2024-10-15 20:09:51 -04:00
James D. Forrester
a5387c7c20 Namespace all remaining classes in includes/parser
Bug: T353458
Change-Id: If02cc9b1ff78e26c1cf8c91ee4695845eb133829
2024-10-15 23:54:32 +01:00
jenkins-bot
23ec5ff94e Merge "Add namespace to maintenance/includes classes" 2024-10-15 22:50:33 +00:00
jenkins-bot
deba2439b7 Merge "REST: Allow specifying param descriptions as MessageValue objects" 2024-10-15 15:24:56 +00:00
jenkins-bot
55c4bb3cac Merge "statslib: Add MetricInterface::setLabels() convenience method" 2024-10-14 10:14:39 +00:00
jenkins-bot
17d6efe4c3 Merge "objectcache: Add support for sister keys in SqlBagOStuff" 2024-10-12 14:04:18 +00:00
James D. Forrester
9f02d18eac Add namespace to maintenance/includes classes
Also a few other fixes of PHP class aliases spotted by phan.

Bug: T353458
Change-Id: Ie79d65722c47c24f8f20f1293355cfd3c2e8c2ad
2024-10-09 11:02:09 -04:00
Máté Szabó
16ec1a3703 Introduce minimal OTEL tracing library
In T340552, the official PHP OpenTelemetry client was effectively
rejected for inclusion in MediaWiki due to its size. Implement a minimal
tracing library instead that eschews conformance with the OTEL client
specification in favor of simplicity, while remaining capable of
emitting trace data in OTLP format and thus retaining compatibility with
any ingestion endpoint capable of handling OTLP.

In its current state, the library supports a basic feature set that
should be sufficient for basic tracing integration:

* Span creation, inclusive span activation and automatic parent span
  assignment,
* Span attributes and span kinds,
* Basic resource (process/request)-level metadata generation,
* Data export over OTLP.

Additional functionality, such as trace propagation, can then be
incrementally added to the library.

Bug: T340552
Change-Id: Ibc3910058cd7ed064cad293a3cdc091344e66b86
2024-10-09 15:55:31 +02:00
Amir Sarabadani
990c4c984f objectcache: Add support for sister keys in SqlBagOStuff
This would allow us to force parsercache idhash and idoptions keys next
to each other so when e.g. depooling 1 of 4 hosts in a parser cache cluster,
the amount of cache misses due to rehashing will be ~25% instead of ~%50.

This is similar to the implementation in WANCache and the same structure
has been used to make it consistent.

Bug: T373037
Change-Id: I920fe76e45298aeee6acf725324a5e1ed2b57a37
2024-10-09 12:15:52 +02:00
bpirkle
27b5faf93b REST: Allow specifying param descriptions as MessageValue objects
Previously, parameter descriptions could only be specified as
strings. We want OpenAPI specs generated from parameter
definitions to be internationalizable, so allow specifying
descriptions as MessageValue objects, which can be translated
using normal MediaWiki mechanisms.

Associated improvements to ResponseFactory.

Bug: T376493
Change-Id: If1cbe4f7bfd5c375e64b802b666c0247d65b1ee0
2024-10-08 16:42:52 -05:00
jenkins-bot
a37de059aa Merge "ParserOutput: ensure all created ParserOutputs have a "start of parse" time set" 2024-10-07 23:13:54 +00:00
jenkins-bot
a4a53d00ac Merge "status: Log getMessage()/getWikiText() calls on good Statuses" 2024-10-06 09:53:02 +00:00
C. Scott Ananian
1e2af489ae ParserOutput: ensure all created ParserOutputs have a "start of parse" time set
*Most* implementations of ContentHandler::fillParserOutput() ensure
that the returned ParserOutput has had
ParserOutput::resetParseStartTime() called on it at an appropriate
time -- but not *all*.  This is a belt-and-suspenders fix that ensures
that every code path which creates a ParserOutput has *some* "start
time" defined.  This could be misleading if the parsing is done first
and the parser output is created at the very end of the parse, but in
all the code that I've looked at the ParserOutput is the first thing
created and so this default should be reasonable.

While we're at it, remove the parseStartTime from the serialized form
of the ParserOutput, because it is useless after the object is
unserialized.

Bug: T376433
Change-Id: I3bdf3996401a7d5ac4d8e1e5e6afb7ca410cbe6c
2024-10-04 19:14:37 -04:00
Yiannis Giannelos
fec9daae4e Use statslib for metrics emitted by HtmlOutputRendererHelper
Bug: T359476
Change-Id: If8bc5a7f7383dcb67dadf1f4c02d1b69d7c8fa53
2024-10-04 14:52:30 -04:00
Máté Szabó
a5049b481f status: Log getMessage()/getWikiText() calls on good Statuses
Why:

- Calling getMessage()/getWikiText() with a good Status is a logic error
  that converts the Status being operated on into a fatal one.
- However, this error is never logged anywhere, which can make it
  difficult to diagnose such cases, as seen in
  I17166e988bf389a5b03d4a74f539f7bec7f5997f.

What:

- Add a warning-level log for the case when getMessage() or
  getWikiText() is invoked with a good Status.

Bug: T374436
Change-Id: I3efae5c4c336156924f1c9b4186fa9142aaed9ca
2024-10-04 18:32:24 +02:00
James D. Forrester
91a37f53b4 Switch over a bunch of class_alias uses to actuals
Change-Id: Id175a83e71cc910eaee5d5890a9106872a3ca3b8
2024-10-03 17:09:36 +00:00
jenkins-bot
4627fe60af Merge "Add namespace to remaining parts of Wikimedia\Mime and Wikimedia\Stats" 2024-10-03 14:16:24 +00:00
jenkins-bot
db7ee3db99 Merge "Add namespace to remaining parts of Wikimedia\ObjectCache" 2024-10-03 14:02:47 +00:00
Aaron Schulz
9508801cc7 rdbms: avoid pcre.backtrack_limit in QueryBuilderFromRawSql::generalizeSQL()
Add some unit tests for this method.

Bug: T366640
Change-Id: I466c83a8d2b8fabcd4c30eb079273dfd52a31b71
2024-10-01 12:00:44 -07:00
jenkins-bot
0b58fa9602 Merge "installer: Consistently use double quotes when outputting settings" 2024-09-28 10:50:24 +00:00
James D. Forrester
cc28acc455 Add namespace to remaining parts of Wikimedia\Mime and Wikimedia\Stats
Bug: T353458
Change-Id: If0137003ab625017d322d57870448a02569668c3
2024-09-27 16:19:10 -04:00
James D. Forrester
53b67ae0a6 Add namespace to remaining parts of Wikimedia\ObjectCache
Bug: T353458
Change-Id: I3b736346550953e3b2977c14dc3eb10edc07cf97
2024-09-27 16:19:10 -04:00
James D. Forrester
9e5c1e8ac7 Add namespace to IDBAccessObject and DBAccessObjectUtils
Bug: T353458
Change-Id: I23cf7991f8792d4d000d1780463d8ce76dc0aee0
2024-09-27 16:19:10 -04:00
Máté Szabó
3263182512 installer: Consistently use double quotes when outputting settings
Why:

- The installer feeds several user-provided values, such as the site
  name, directly into LocalSettingsGenerator.
- There, these get passed through escapePhpString(), the output of which
  is safe when rendered into a double-quoted string, but fails if the
  input string contained single quotes and was rendered into a
  single-quoted string.

What:

- Consistently output all strings in LocalSettingsGenerator as
  double-quoted strings.

Bug: T372569
Change-Id: I27bb3c31d8e9957b4880d0faba8b79d121126a11
2024-09-27 14:53:46 +02:00
James D. Forrester
984076f98e Add namespace to includes/api classes
Bug: T353458
Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
2024-09-25 19:31:14 +00:00
jenkins-bot
ef41dedbd4 Merge "objectcache: Add regression test for MultiWrite dependency injection" 2024-09-24 04:38:56 +00:00
Timo Tijhof
70f9eb8f91 objectcache: Add regression test for MultiWrite dependency injection
Follows-up 4e596f5112 (I59266726ad), which fixed bug T318272, but
did not add a regression test for it.

Bug: T318272
Bug: T327158
Change-Id: Ia8af6671887d3914fdc761d8e5d10fd33fb40f88
2024-09-23 15:07:23 -07:00
jenkins-bot
b145754452 Merge "tests: Use ::class for class name resolution" 2024-09-21 13:48:10 +00:00
Umherirrender
8e039f2101 tests: Use ::class for class name resolution
Also use namespaced version of the class

Change-Id: Idce009e4d0a8e77f95244d95db008d64a2025c5f
2024-09-20 21:19:22 +02:00
daniel
84fe1b9ccd REST: Introduce discovery endpoint
The discovery endpoint provides basic information about accessing the
wiki's APIs, as well as a directory of available modules.

Bug: T365753
Change-Id: I161aa68566da91867b650e13c8aadc87cd0c428c
2024-09-20 17:02:59 +00:00