Simetrical wrote:
On 9/9/07, werdna@svn.wikimedia.org werdna@svn.wikimedia.org wrote:
Revision: 25680 Author: werdna Date: 2007-09-09 08:11:58 +0000 (Sun, 09 Sep 2007)
Log Message:
- Allow userCan to take null $user - and replace it with $wgUser if passed.
. . .
First of all, why? We should be cutting down the use of $wgUser as much as possible, not adding it in extra places. The more methods that are free of any given global, the better. I'm not the only one who dreams fondly of elimination of things like $wgUser altogether. If someone forgets a function argument, they can get a fatal error and take two minutes to fix it.
I think $wgUser is the last global we should get rid of, if we get rid of it at all. I later regretted inventing hideous syntax such as:
$popt = ParserOptions::newFromUser( $wgUser );
...now you can do the same thing with just
$popt = new ParserOptions;
I did it with a user parameter with a default of null.
The problem is that the existence of a single global user is implied in many places. You don't gain any flexibility by having the "global $wgUser" in the caller instead of the callee. And in 99% of code there is no application for multiple user objects.
You could gain some flexibility by bundling variables like $wgUser, $wgRequest and the configuration variables into a single context object, and then using that context object as a factory for subsidiary objects. So you would have:
$popt = $mw->newParserOptions();
or in the userCan case:
$title = $mw->newTitle($titleText); $title->getUserPermissionsErrors( 'view' );
It still assumes a single fixed user object as part of an execution context, but it allows subclassing of core objects and comprehensive namespace separation to be implemented transparently to the caller. It also allows straightforward context generation and cloning, which gives you some amount of flexibility if you need to go outside the usual use case.
-- Tim Starling