Edward Z. Yang wrote:
Tim Starling wrote:
MessageCache is a cache of the MediaWiki
namespace, a cache which is
conceptually merged with various other message sources. Sometimes Language
needs to access the MediaWiki namespace, and it does so via MessageCache.
Language::getMessageFromDB is a helper function to facilitate such access.
This is required to support important features such as per-wiki
customisation of month names.
Ah, when put in that context, that makes sense. Not such an ugly hack,
then. (referring to the docblock on line 335 of Language.php)
The way MessageCache supports multiple language
objects is hackish,
because the ability to support multiple language objects was added after
MessageCache was designed, and it was never properly refactored.
After refactoring, what would MessageCache look like?
MessageCache::get could accept a language code as input instead of a
boolean for-content flag. That would avoid the ugly hack in
Language::getMessageFromDB(), i.e. the comparison of the language code
against the content and user languages.
Would you have all the language objects cached in
their own registry?
That doesn't appear to be necessary, all the language data that
MessageCache needs is available via the static member function
Language::getMessagesFor().
This has a relationship to the key/lang syntax?
In part, yes.
The object is named after the data it contains.
The member functions are
tools for operating on that data. We could call it MessageUtilities, but
then it would sound like a mere collection of functions, and it would not
be clear what happens when you instantiate, clone or serialize one of them.
In that context, the name makes sense. However, there are still quite a
bit of methods that aren't really tied to that. What if you seperated
the less related methods (get() stands out as one) into
MessageUtilities, so that only methods directly manipulating the
MediaWiki cache are in the MessageCache object. An extra file, yes, but
possibly the difference between caching MediaWiki messages, and
retrieving a message from multiple sources is sufficiently great enough
to merit another include.
I'm happy with it as it is.
-- Tim Starling