daniel added a comment.

I doubt anyone would extend ContextSource for a class just to get a msg() method. That seems rather unnecessary. I would not consider that acceptable for code in MediaWiki core.

Well, using subclassing for this kind of thing shouldn't be done anyway. So in Wikibase, we use composition - that is, we inject a factory service. Defining an interface for that factory is what this ticket is about.

The Message object itself relies heavily on global state. If we want to fix that at some point, we should avoid direct constructor calls - if all Messages come from a factory, we can easily start injecting things. The global function essentially acts as a constructor, so it does not help us to get rid of global state.

I am skeptical of these kinds of interfaces as it usually doesn't end up being used. We'd specify the interface whenever we add such method, but never use it anywhere. It would help to have an example use case where a method would use MessageLocalizer as parameter type, or in what scenario one would want to instanceof-check for it?

We have several services in Wikibase that currently require an IContextSource in the constructor, solely for constructing messages. Having a more narrow interface to inject there was the original motivation for this ticket. We originally planned to put the interface into Wikibase, but we then figured it would be nice to have in core, too.

I think narrow interfaces should be preferred over one-covers-all things like IContextSource. If I Was King, we'd get rid of the ContextSource base class and IContextSource asap, and replace it by a bunch of narrow interfaces, and composition/injection. This ticket is a small first step in that direction.

If you feel that MessageLocalizer should not be in core, we can just introduce it to Wikibase for now.


TASK DETAIL
https://phabricator.wikimedia.org/T162594

EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Ladsgroup, daniel
Cc: Nikerabbit, Krinkle, Nemo_bis, Agabi10, gerritbot, Ladsgroup, Aklapper, daniel, GoranSMilovanovic, Adik2382, Th3d3v1ls, Ramalepe, Liugev6, QZanden, Lewizho99, Maathavan, MuhammadShuaib, Izno, LNDDYL, Psychoslave, Wikidata-bugs, aude, Gryllida, Shizhao, Arrbee, KartikMistry, Mbch331, Jay8g
_______________________________________________
Wikidata-bugs mailing list
Wikidata-bugs@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs

Reply via email to