Commit graph

18 commits

Author SHA1 Message Date
Bartosz Dziewoński
c045fa0291 Replace gettype() with get_debug_type() in exception messages
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
2024-07-31 19:24:39 +02:00
Bartosz Dziewoński
c9f73efd5a Namespace MessageSpecifier under Wikimedia\Message\
In change I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83 I am planning to
make Wikimedia\Message\MessageValue use it, and we try to pretend that
it is a library separate from MediaWiki, so it makes sense to move
MessageSpecifier to the same namespace under Wikimedia\.

Bug: T353458
Change-Id: I9ff4ff7beb098b60c92f564591937c7d789c6684
2024-07-28 14:21:32 +02:00
Bartosz Dziewoński
159dad8abb language: Improve behavior of RawMessage used as MessageSpecifier
We have some code that expects that if you disassemble a
MessageSpecifier using its getKey() and getParams() methods,
then assemble a new MessageSpecifier using the return values,
you will get (at least approximately) the same message.

This was not the case with RawMessage, even though it implements
the MessageSpecifier interface, because its "keys" are not real
message keys, and this operation would mess it up.

Override the MessageSpecifier methods on RawMessage so that they're
compatible with how everyone expects a MessageSpecifier to work.

Add some tests for OutputPage, Message\Converter and Status
to verify some scenarios that would previously have failed.

Depends-On: I41991989515b4791bc1746f26bd404bf4f17dbdb
Depends-On: I612361dd20ff8aad4c0069f1c5af78e3e13b9692
Change-Id: Iddd14efa8b9536277c372257d5a7be135f26a540
2024-07-16 15:06:26 +01:00
Bartosz Dziewoński
f5f1548508 Move code comment that breaks Gerrit's syntax highlighting
Weird. https://phabricator.wikimedia.org/F55883982

Change-Id: I16a60c2240f6cfeb8419d42e7f512d84803036ca
2024-06-26 02:04:59 +00:00
Bartosz Dziewoński
0c2fb030e2 Message: Rename 'interface' prop because of syntax highlighting
Some syntax highlighters, in particular Gerrit's, incorrectly handle
code that uses a property named 'interface' (which is a PHP keyword).
https://phabricator.wikimedia.org/F55884039

Rename it to avoid problems.

Message isn't '@stable to extend', so this is not a breaking change.
I couldn't find any extensions that refer to it anyway.

Change-Id: I6676421222921b7bb1aeeefef79dd06072c1c2ac
2024-06-26 02:04:59 +00:00
jenkins-bot
7650245641 Merge "Fix $msg->params( getMockMessage( … ) ) not mocking inner message" 2024-06-16 09:54:39 +00:00
Bartosz Dziewoński
96dc5467c8 Fix $msg->params( getMockMessage( … ) ) not mocking inner message
When using MediaWikiTestCaseTrait::getMockMessage(), if the mock
message was passed as a parameter to another non-mock message, its
format() method was called, which is private and can't be mocked,
and causes "LogicException: Premature access to service container"
in unit tests. Call the public toString() instead.

Change-Id: I8718cf7890f05c09a6e5712ee3dc4d171a6637cf
2024-06-13 12:43:20 +02:00
Bartosz Dziewoński
ccd423225f Add "implements Stringable" to every class with "function __toString()"
In PHP 8, but not in PHP 7.4, every class with a __toString() function
implicitly implements the Stringable interface. Therefore, the
behavior of checks like "instanceof Stringable" differs between these
PHP versions when such classes are involved. Make every such class
implement the interface so that the behavior will be consistent.

The PHP 7.4 fallback for the Stringable interface is provided by
symfony/polyfill-php80.

Change-Id: I3f0330c2555c7d3bf99b654ed3c0b0303e257ea1
2024-06-13 00:23:39 +00:00
Bartosz Dziewoński
f18362ccce Deprecate Message::objectParams() and related code
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
2024-05-28 22:03:46 +00:00
jenkins-bot
66773d2053 Merge "Show overridden message keys when using &uselang=qqx" 2024-05-04 19:57:18 +00:00
Jon Harald Søby
35e59fd021 Don't use content language in Message::getTitle()
Change the Message::getTitle() function to not use the
wiki's content language when generating links to pages in the
MediaWiki namespace.

Message::getTitle() returns the uppercased version of the message
name as a title object. For some languages, such as Azeri and Turkish,
this can lead to some transformations we don't want. For instance,
when you uppercase "i" in Azerbaijani, it becomes "İ" (dotted I),
leading to links to "MediaWiki:İpbreason-dropdown" on Special:Block.

Bug: T362654
Change-Id: Id37c226270c53352760790ddd461ca98920b5910
2024-05-01 08:17:10 +00:00
Bartosz Dziewoński
f93a690d5b Show overridden message keys when using &uselang=qqx
When displaying messages, the requested message key can be overridden
by hooks such as 'MessageCacheFetchOverrides'. If this happened,
display the overridden key when using &uselang=qqx, to help users and
developers track down where a message is coming from.

Bug: T363729
Change-Id: I81d814278ca810035066ce4632f617f30536f1ab
2024-04-30 18:38:34 +00:00
C. Scott Ananian
dd0004c6eb Message: add strict type to protected Message::$language
Change-Id: Idbb28719cc6561b236d47ca99ea2d217021981a8
2024-04-10 14:24:05 -04:00
C. Scott Ananian
c23cf3b0b1 Message::inLanguage(): accept Bcp47Code as well as string and Language
Bug: T327379
Followup-To: I982e0df706a633b05dcc02b5220b737c19adc401
Followup-To: I24932449b8c40e3a5072748d87667184f4befa67
Change-Id: Id99e5695bcfd347170cb4f2f80a557d189df6d44
2024-04-10 14:24:05 -04: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
Tim Starling
e98f23c885 message: Don't load user language when a specific language was requested
Message::setContext() called $context->getLanguage(), loading the user
options from the database, which is unnecessary if
Message::inLanguage() is called immediately afterwards.

In a ResourceLoader module, RequestContext::getLanguage() throws an
exception due to MW_NO_SESSION being defined. For example, an exception
was thrown if any HTTP client error was encountered, since log message
formatting includes a call to Message::setContext().

So defer the call to RequestContext::getLanguage() by having
Message::setContext() make a closure which later fetches the language if
necessary.

Add an integration test which previously failed.

Change-Id: I326c7e3a9492952d721fb52f1868ab9c1033e683
2024-03-04 12:03:38 +11:00
Subramanya Sastry
e55cc517da Move Parser to Mediawiki\Parser namespace
Bug: T166010
Co-Authored-By: Daimona Eaytoy <daimona.wiki@gmail.com>
Co-Authored-By: James Forrester <jforrester@wikimedia.org>
Co-Authored-By: Subramanya Sastry <ssastry@wikimedia.org>
Change-Id: I79b4e732c45095eedbaa80afa5eb7479b387ed8a
2024-02-16 09:18:38 -05:00
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05:00
Renamed from includes/language/Message.php (Browse further)