Edward Z. Yang wrote:
Theoretically speaking, these two classes have very distinct roles. MessageCache is a cache of messages, where userland code should run off to get messages from. Language, while containing messages, defers this responsibility to MessageCache, and instead lets users call language-specific behavior like formatting dates. So, in theory, while MessageCache is dependent on Language, Language should not be dependent on MessageCache.
In reality, however, this is not the case. Certain functions in the Language objects will occasionally need to call getMessageFromDB (which calls the wfMsg* functions which call the MessageCache) to grab a possibly customized message. The whole thing is terribly convoluted and I'm not sure I understand.
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.
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.
I'm wondering, however, how this would be restructured if you had to chance to refactor this triumvirate of files without any regard to backwards-compatibility. Some questions:
- A global function is currently being used to do parameter
substitution: if you were to stuff this in a class, which class would go into?
MessageCache. Almost all of the wfMsg*() functionality should be in MessageCache.
- The message cache is currently used by extension authors to add their
own customizable messages to the mix. Is adding the messages straight to the cache the right thing to do, even if it is labeled mExtensionMessages? Would the cache be responsible for message retrieval? Should the class be renamed for sake of truthfulness?
Renamed to what?
- The cache is language aware in that it can accept messages for
specific languages but then figure out which one to use once based on $wgContLang or $wgLang (whichever is currently taking precedence).
It appears that MessageCache is not so much a cache but a loose confederation of tools for *getting* messages, performing some magic along with the global functions to figure out where to look, its own cache being only one of many places to look. Which is why I'm having trouble figuring this stuff out.
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.
-- Tim Starling