On Sat, Apr 2, 2011 at 11:17 PM, Daniel Friesen lists@nadir-seen-fire.comwrote:
I've made some changes promoting better coding patterns in some contexts.
These are for MediaWiki 1.18, extensions can keep their old patterns till they drop support for pre-1.18.
[snip]
When working on special pages (ESPECIALLY includable special pages):
- Use $this->getOutput() instead of the $wgOut global.
- Use $this->getUser() instead of the $wgUser global.
- Use $this->getSkin() instead of using $wgUser->getSkin();
In contexts where you are working with $wgOut or another OutputPage instance and using $wgUser and skin instances fetched from it to render stuff being passed back to output:
- Use $out->getUser() instead of the $wgUser gobal.
- Use $out->getSkin() instead of using $wgUser->getSkin();
Seems like a good direction; this basically is encapsulating some of the 'global state' (which is really "web UI state") into one place, and letting us use a different set of state when appropriate.
I have some thought to go through on what to do about the Linker in some
contexts, but I have some plans I'm thinking of regarding Skin:
- I'm thinking of making $out->getSkin(); the primary point for getting
a skin instead of $wgUser->getSkin(); (I'll still keep BC), making OutputPage the focal point for things related to the output of the page. Having OutputPage track and manage skins also avoids some special case bugs, it's actually more sane for OutputPage to manage the skin when you examine various branches of code.
I'd be kind of inclined to separate out the Skin and Linker worlds a bit further; really, the HTML formatting of links and such doesn't depend on the user (except in some edge cases like stub links which could in principle be done differently). The surrounding *skin* depends on the user settings, but having to dive into a User object to get a Linker feels messy, especially if we're rendering a wiki page to go into a common cache.
IIRC the biggest remaining use case for link rendering actually being customized by skin was for the special skin used for creating static HTML dumps.
If we had another way to do that, and normalized stub linking in some way (say, by always sticking a magic class on and letting CSS deal with it) it might be cleaner to avoid having to touch a Skin object unless you're actually doing final HTML output. (This may be a bigger project though. :D)
-- brion