r32975 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32974‎ | r32975 | r32976 >
Date:18:52, 8 April 2008
Author:ialex
Status:old
Tags:
Comment:
Document a bit.
Modified paths:
  • /trunk/phase3/includes/StubObject.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/StubObject.php
@@ -17,32 +17,74 @@
1818 */
1919 class StubObject {
2020 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+ */
2130 function __construct( $global = null, $class = null, $params = array() ) {
2231 $this->mGlobal = $global;
2332 $this->mClass = $class;
2433 $this->mParams = $params;
2534 }
2635
 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+ */
2743 static function isRealObject( $obj ) {
2844 return is_object( $obj ) && !($obj instanceof StubObject);
2945 }
3046
 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+ */
3157 function _call( $name, $args ) {
3258 $this->_unstub( $name, 5 );
3359 return call_user_func_array( array( $GLOBALS[$this->mGlobal], $name ), $args );
3460 }
3561
 62+ /**
 63+ * Create a new object to replace this stub object.
 64+ */
3665 function _newObject() {
3766 return wfCreateObject( $this->mClass, $this->mParams );
3867 }
3968
 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+ */
4076 function __call( $name, $args ) {
4177 return $this->_call( $name, $args );
4278 }
4379
4480 /**
 81+ * This function creates a new object of the real class and replace it in
 82+ * the global variable.
4583 * This is public, for the convenience of external callers wishing to access
4684 * 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.
4789 */
4890 function _unstub( $name = '_unstub', $level = 2 ) {
4991 static $recursionLevel = 0;
@@ -61,13 +103,18 @@
62104 }
63105 }
64106
 107+/**
 108+ * Stub object for the content language of this wiki. This object have to be in
 109+ * $wgContLang global.
 110+ */
65111 class StubContLang extends StubObject {
 112+
66113 function __construct() {
67114 parent::__construct( 'wgContLang' );
68115 }
69116
70117 function __call( $name, $args ) {
71 - return StubObject::_call( $name, $args );
 118+ return $this->_call( $name, $args );
72119 }
73120
74121 function _newObject() {
@@ -78,7 +125,14 @@
79126 return $obj;
80127 }
81128 }
 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+ */
82135 class StubUserLang extends StubObject {
 136+
83137 function __construct() {
84138 parent::__construct( 'wgLang' );
85139 }
@@ -89,13 +143,13 @@
90144
91145 function _newObject() {
92146 global $wgContLanguageCode, $wgRequest, $wgUser, $wgContLang;
93 - $code = $wgRequest->getVal('uselang', $wgUser->getOption('language') );
 147+ $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
94148
95149 // if variant is explicitely selected, use it instead the one from wgUser
96150 // see bug #7605
97 - if($wgContLang->hasVariants()){
 151+ if( $wgContLang->hasVariants() ){
98152 $variant = $wgContLang->getPreferredVariant();
99 - if($variant != $wgContLanguageCode)
 153+ if( $variant != $wgContLanguageCode )
100154 $code = $variant;
101155 }
102156
@@ -113,7 +167,15 @@
114168 }
115169 }
116170 }
 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+ */
117178 class StubUser extends StubObject {
 179+
118180 function __construct() {
119181 parent::__construct( 'wgUser' );
120182 }
@@ -128,10 +190,8 @@
129191 $user = new User;
130192 } else {
131193 $user = User::newFromSession();
132 - wfRunHooks('AutoAuthenticate',array(&$user));
 194+ wfRunHooks( 'AutoAuthenticate', array( &$user ) );
133195 }
134196 return $user;
135197 }
136198 }
137 -
138 -

Status & tagging log