aboutsummaryrefslogtreecommitdiffstats
path: root/includes/libs/Message/ScalarParam.php
Commit message (Collapse)AuthorAgeFilesLines
* Replace wfDeprecatedMsg with trigger_error in ScalarParam.phpDoğu Abaris2025-02-021-1/+4
| | | | | | | wfDeprecatedMsg was replaced with trigger_error for better alignment with non-MediaWiki environments. Change-Id: Icc5a58cb2eccf26def393a9715ab5089cf4b7951
* includes/libs/Message: Add return type hints, update methodsDoğu Abaris2024-11-211-8/+9
| | | | | | | | | | | | | | | | | | | Applied return type hints to improve type safety in Message classes. Adjusted constructors to specify parameter types for consistency. Enhanced `newFromJsonArray` in `ScalarParam`, `DataMessageValue`, and `MessageParam` to clarify deserialization logic. Key updates: - Added `: string` return types for `getLangCode`, `getKey`, `dump`. - Added `: array` return type for `getParams`, `getData`, `toJsonArray`. - Revised `ScalarParam` JSON parsing to ensure a consistent return. These adjustments enhance type safety across the Message classes. Depends-On: Id7cc576693f5f1830e1d261cb13c626c901fb40f Depends-On: I260e3f526be10f7b11e5c77a1e300590c6fc5b2b Depends-On: I3c318273856d15407c71cb9b4ab7c23a0debb314 Change-Id: I7e50be91c01b4b70e1d1380651f001e35bd60523
* Message: Downgrade exception on bool/null param to warningBartosz Dziewoński2024-11-021-4/+9
| | | | | Bug: T378876 Change-Id: Iecbf83dd060b2a1dc30bd33bfc4f2a42cfbd2a1f
* Make MessageValue JsonCodecable instead of JsonDeserializableIsabelle Hurbain-Palatin2024-10-281-3/+5
| | | | Change-Id: I8ed6498acb4657c69b58a24fc3cc45f585a31b7d
* Remove Message::objectParams() and related codeBartosz Dziewoński2024-10-271-9/+1
| | | | | | | Deprecated in I492edabb7ea1d75774b45eb9fd18261b39963f9f. Bug: T278482 Change-Id: Ie9350ed0d7b2604fb4d2f440dee66964fe198c0e
* SECURITY: Message: Don’t call is_callable() on stringsLucas Werkmeister2024-10-241-1/+3
| | | | | | | | | 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
* Make Message and MessageValue compatibleBartosz Dziewoński2024-10-191-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Message: Make toJsonArray() methods protectedBartosz Dziewoński2024-08-211-1/+1
| | | | | | | They're protected in JsonDeserializableTrait, and weren't meant to be made public. Change-Id: Icda0c58d42730b1dd66a9eb69245bb1f9a15962b
* Message: Validate ScalarParam and ListParam typesBartosz Dziewoński2024-08-211-0/+3
| | | | | | | | | * Add getters for the lists of valid types (named cases() like in PHP 8.1 enums) * Validate that the provided type is in the list * Replace funky use of reflection in Converter Change-Id: I8da89edbb943fae8920c15b1bc6856ce97a4de7a
* Replace gettype() with get_debug_type() in exception messagesBartosz Dziewoński2024-07-311-1/+1
| | | | | | | | | | | | | | | | | | | get_debug_type() does the same thing but better (spelling type names in the same way as in type declarations, and including names of object classes and resource types). It was added in PHP 8, but the symfony/polyfill-php80 package provides it while we still support 7.4. Also remove uses of get_class() and get_resource_type() where the new method already provides the same information. For reference: https://www.php.net/manual/en/function.get-debug-type.php https://www.php.net/manual/en/function.gettype.php To keep this safe and simple to review, I'm only changing cases where the type is immediately used in an exception message. Change-Id: I325efcddcb58be63b1592b9c20ac0845393c15e2
* ScalarParam: Un-deprecate Stringable, deprecate ParamType::OBJECT insteadBartosz Dziewoński2024-07-221-4/+7
| | | | | | | | | | | | | | | | Follow-up to f18362cccec27335084d35e1c2dfc1e9ddd1893c. While working on I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83, I learned that Stringable objects are sometimes also used as normal params, intended to be stringified when rendering. For example, see `this->target` in the UnblockUser class. That code uses Message objects, so it's not causing trouble, but converting them to MessageValue would emit warnings. I didn't actually intend to deprecate that, and it won't cause issues with JSON-serializability (assuming we stringify the objects in time), so tweak how the warnings are emitted. Change-Id: I26dfd4f1ac8ed08a422692de4e39d072242c08df
* Make MessageValue implement JsonDeserializableBartosz Dziewoński2024-06-121-0/+25
| | | | | | | | | | | | | | | MessageValue and friends are pure value objects and newable, so it makes sense for them to be (de)serializable too. There are some places where we want to serialize messages, such as in ParserOutput. The structure of the resulting JSON is inspired by the way we represent Message objects as plain values elsewhere in MediaWiki, e.g. StatusValue::getStatusArray(). Co-Authored-By: C. Scott Ananian <cscott@cscott.net> Depends-On: Ia32f95a6bdf342262b4ef044140527f0676402b9 Depends-On: I7bafe80cd36c2558517f474871148286350a4e76 Change-Id: Id47d58b5e26707fa0e0dbdd37418c0d54c8dd503
* Deprecate Message::objectParams() and related codeBartosz Dziewoński2024-05-281-2/+6
| | | | | | | | | | | | | | | | | | | | This functionality was introduced in 2021 (commit 349819dc5a) to support the addition of UserGroupMembershipParam, which was never used, and no other use case appeared. Its existence is now preventing us from allowing serializing of MessageValue objects as JSON (since the parameters can't be guaranteed to be serializable). Deprecate: * method: MessageValue::objectParams() * method: Message::objectParams() * method: Message::objectParam() * class: UserGroupMembershipParam * constant: ParamType::OBJECT * Passing Stringable objects to ScalarParam Change-Id: I492edabb7ea1d75774b45eb9fd18261b39963f9f
* Import InvalidArgumentException at top of the sourceEbrahim Byagowi2024-05-191-2/+3
| | | | | | | | | | | | | | It was asked in a patch review to apply fully import InvalidArgumentException where possible. I was guessing some of my other already merged patches have but turned out such thing exists other places style so for the sake of consistency I've turned rest of inline import of the specific exception at top of the file. There are instances of source files that aren't in any namespace but have fully qualified import which this patch doesn't touch. Change-Id: I4071fc698b65746d9594cf4d5f45bae82843d436
* Add Message/MessageValue user group member parameter typeTChin2021-11-161-3/+6
| | | | | | | * Added ParamType::OBJECT, which allows Stringable objects to be passed into MessageValue Bug: T278482 Change-Id: Ib4990f87d4ad70b7525d7aa05c8b97e90c121674
* Replace "@stable for calling" by "@stable to call"daniel2020-07-131-1/+1
| | | | | | | | | | | For compliance with the new version of the table interface policy (T255803). This patch was created by an automated search & replace operation on the includes/ directory. Bug: T257789 Change-Id: If560596f5e1e0a3da91afc36e656e7c27f040968
* Annotate newable classesdaniel2020-07-071-0/+4
| | | | | | | | This annotates classes that can safely be instantiated by extensions, per the Stable Interface Policy. Bug: T247862 Change-Id: Ia280f559874fc0750265ddeb7f831e65fd7d7d6a
* libs/Message: Improve parameter validationBrad Jorsch2019-10-171-0/+12
| | | | | | | Validate that all parameters are of expected types, not just list parameter values. Change-Id: Id47c6f9ad1cf3a3dfc1f6d0c3766ba607c4ef633
* libs/Message: Improve documentationBrad Jorsch2019-08-291-0/+30
Among other things, this removed mention of MediaWiki classes from the library and adds a README.md that attempts to define constraints for interoperability between libraries producing MessageValues and formatter implementations that are expected to handle them. This also renames "TextParam" to "ScalarParam", as that seems a more accurate name for the class. Change-Id: I264dd4de394d734a87929cf4740779e7b7d0e04a