Index: trunk/phase3/includes/StubObject.php |
— | — | @@ -17,32 +17,74 @@ |
18 | 18 | */ |
19 | 19 | class StubObject { |
20 | 20 | var $mGlobal, $mClass, $mParams; |
| 21 | + |
| 22 | + /** |
| 23 | + * Constructor. |
| 24 | + * |
| 25 | + * @param String $global name of the global variable. |
| 26 | + * @param String $class name of the class of the real object. |
| 27 | + * @param Array $param array of parameters to pass to contructor of the real |
| 28 | + * object. |
| 29 | + */ |
21 | 30 | function __construct( $global = null, $class = null, $params = array() ) { |
22 | 31 | $this->mGlobal = $global; |
23 | 32 | $this->mClass = $class; |
24 | 33 | $this->mParams = $params; |
25 | 34 | } |
26 | 35 | |
| 36 | + /** |
| 37 | + * Returns a bool value whetever $obj is a stub object. Can be used to break |
| 38 | + * a infinite loop when unstubbing an object. |
| 39 | + * |
| 40 | + * @param Object $obj object to check. |
| 41 | + * @return bool true if $obj is not an instance of StubObject class. |
| 42 | + */ |
27 | 43 | static function isRealObject( $obj ) { |
28 | 44 | return is_object( $obj ) && !($obj instanceof StubObject); |
29 | 45 | } |
30 | 46 | |
| 47 | + /** |
| 48 | + * Function called if any function exists with that name in this object. |
| 49 | + * It is used to unstub the object. Only used internally, PHP will call |
| 50 | + * self::__call() function and that function will call this function. |
| 51 | + * This function will also call the function with the same name in the real |
| 52 | + * object. |
| 53 | + * |
| 54 | + * @param String $name name of the function called. |
| 55 | + * @param Array $args array of arguments. |
| 56 | + */ |
31 | 57 | function _call( $name, $args ) { |
32 | 58 | $this->_unstub( $name, 5 ); |
33 | 59 | return call_user_func_array( array( $GLOBALS[$this->mGlobal], $name ), $args ); |
34 | 60 | } |
35 | 61 | |
| 62 | + /** |
| 63 | + * Create a new object to replace this stub object. |
| 64 | + */ |
36 | 65 | function _newObject() { |
37 | 66 | return wfCreateObject( $this->mClass, $this->mParams ); |
38 | 67 | } |
39 | 68 | |
| 69 | + /** |
| 70 | + * Function called by PHP if no function with that name exists in this |
| 71 | + * object. |
| 72 | + * |
| 73 | + * @param String $name name of the function called |
| 74 | + * @param Array $args array of arguments |
| 75 | + */ |
40 | 76 | function __call( $name, $args ) { |
41 | 77 | return $this->_call( $name, $args ); |
42 | 78 | } |
43 | 79 | |
44 | 80 | /** |
| 81 | + * This function creates a new object of the real class and replace it in |
| 82 | + * the global variable. |
45 | 83 | * This is public, for the convenience of external callers wishing to access |
46 | 84 | * properties, e.g. eval.php |
| 85 | + * |
| 86 | + * @param String $name name of the method called in this object. |
| 87 | + * @param Integer $level level to go in the stact trace to get the function |
| 88 | + * who called this function. |
47 | 89 | */ |
48 | 90 | function _unstub( $name = '_unstub', $level = 2 ) { |
49 | 91 | static $recursionLevel = 0; |
— | — | @@ -61,13 +103,18 @@ |
62 | 104 | } |
63 | 105 | } |
64 | 106 | |
| 107 | +/** |
| 108 | + * Stub object for the content language of this wiki. This object have to be in |
| 109 | + * $wgContLang global. |
| 110 | + */ |
65 | 111 | class StubContLang extends StubObject { |
| 112 | + |
66 | 113 | function __construct() { |
67 | 114 | parent::__construct( 'wgContLang' ); |
68 | 115 | } |
69 | 116 | |
70 | 117 | function __call( $name, $args ) { |
71 | | - return StubObject::_call( $name, $args ); |
| 118 | + return $this->_call( $name, $args ); |
72 | 119 | } |
73 | 120 | |
74 | 121 | function _newObject() { |
— | — | @@ -78,7 +125,14 @@ |
79 | 126 | return $obj; |
80 | 127 | } |
81 | 128 | } |
| 129 | + |
| 130 | +/** |
| 131 | + * Stub object for the user language. It depends of the user preferences and |
| 132 | + * "uselang" parameter that can be passed to inde.php. This object have to be |
| 133 | + * in $wgLang global. |
| 134 | + */ |
82 | 135 | class StubUserLang extends StubObject { |
| 136 | + |
83 | 137 | function __construct() { |
84 | 138 | parent::__construct( 'wgLang' ); |
85 | 139 | } |
— | — | @@ -89,13 +143,13 @@ |
90 | 144 | |
91 | 145 | function _newObject() { |
92 | 146 | global $wgContLanguageCode, $wgRequest, $wgUser, $wgContLang; |
93 | | - $code = $wgRequest->getVal('uselang', $wgUser->getOption('language') ); |
| 147 | + $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) ); |
94 | 148 | |
95 | 149 | // if variant is explicitely selected, use it instead the one from wgUser |
96 | 150 | // see bug #7605 |
97 | | - if($wgContLang->hasVariants()){ |
| 151 | + if( $wgContLang->hasVariants() ){ |
98 | 152 | $variant = $wgContLang->getPreferredVariant(); |
99 | | - if($variant != $wgContLanguageCode) |
| 153 | + if( $variant != $wgContLanguageCode ) |
100 | 154 | $code = $variant; |
101 | 155 | } |
102 | 156 | |
— | — | @@ -113,7 +167,15 @@ |
114 | 168 | } |
115 | 169 | } |
116 | 170 | } |
| 171 | + |
| 172 | +/** |
| 173 | + * Stub object for the user. The initialisation of the will depend of |
| 174 | + * $wgCommandLineMode. If it's true, it will be an anonymous user and if it's |
| 175 | + * false, the user will be loaded from credidentails provided by cookies. This |
| 176 | + * object have to be in $wgUser global. |
| 177 | + */ |
117 | 178 | class StubUser extends StubObject { |
| 179 | + |
118 | 180 | function __construct() { |
119 | 181 | parent::__construct( 'wgUser' ); |
120 | 182 | } |
— | — | @@ -128,10 +190,8 @@ |
129 | 191 | $user = new User; |
130 | 192 | } else { |
131 | 193 | $user = User::newFromSession(); |
132 | | - wfRunHooks('AutoAuthenticate',array(&$user)); |
| 194 | + wfRunHooks( 'AutoAuthenticate', array( &$user ) ); |
133 | 195 | } |
134 | 196 | return $user; |
135 | 197 | } |
136 | 198 | } |
137 | | - |
138 | | - |