Merge "Return correct values and types"
[lhc/web/wiklou.git] / includes / UserRightsProxy.php
index 6c2a5f1..a8a22be 100644 (file)
@@ -1,4 +1,24 @@
 <?php
+/**
+ * Representation of an user on a other locally-hosted wiki.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
 
 /**
  * Cut-down copy of User interface for local-interwiki-database
@@ -12,8 +32,8 @@ class UserRightsProxy {
         * @see newFromId()
         * @see newFromName()
         * @param $db DatabaseBase: db connection
-        * @param $database String: database name
-        * @param $name String: user name
+        * @param string $database database name
+        * @param string $name user name
         * @param $id Integer: user ID
         */
        private function __construct( $db, $database, $name, $id ) {
@@ -36,7 +56,7 @@ class UserRightsProxy {
        /**
         * Confirm the selected database name is a valid local interwiki database name.
         *
-        * @param $database String: database name
+        * @param string $database database name
         * @return Boolean
         */
        public static function validDatabase( $database ) {
@@ -47,14 +67,14 @@ class UserRightsProxy {
        /**
         * Same as User::whoIs()
         *
-        * @param $database String: database name
+        * @param string $database database name
         * @param $id Integer: user ID
         * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases
         * @return String: user name or false if the user doesn't exist
         */
        public static function whoIs( $database, $id, $ignoreInvalidDB = false ) {
                $user = self::newFromId( $database, $id, $ignoreInvalidDB );
-               if( $user ) {
+               if ( $user ) {
                        return $user->name;
                } else {
                        return false;
@@ -64,7 +84,7 @@ class UserRightsProxy {
        /**
         * Factory function; get a remote user entry by ID number.
         *
-        * @param $database String: database name
+        * @param string $database database name
         * @param $id Integer: user ID
         * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases
         * @return UserRightsProxy or null if doesn't exist
@@ -76,8 +96,8 @@ class UserRightsProxy {
        /**
         * Factory function; get a remote user entry by name.
         *
-        * @param $database String: database name
-        * @param $name String: user name
+        * @param string $database database name
+        * @param string $name user name
         * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases
         * @return UserRightsProxy or null if doesn't exist
         */
@@ -85,14 +105,21 @@ class UserRightsProxy {
                return self::newFromLookup( $database, 'user_name', $name, $ignoreInvalidDB );
        }
 
+       /**
+        * @param $database
+        * @param $field
+        * @param $value
+        * @param $ignoreInvalidDB bool
+        * @return null|UserRightsProxy
+        */
        private static function newFromLookup( $database, $field, $value, $ignoreInvalidDB = false ) {
                $db = self::getDB( $database, $ignoreInvalidDB );
-               if( $db ) {
+               if ( $db ) {
                        $row = $db->selectRow( 'user',
                                array( 'user_id', 'user_name' ),
                                array( $field => $value ),
                                __METHOD__ );
-                       if( $row !== false ) {
+                       if ( $row !== false ) {
                                return new UserRightsProxy( $db, $database,
                                        $row->user_name,
                                        intval( $row->user_id ) );
@@ -111,8 +138,8 @@ class UserRightsProxy {
         */
        public static function getDB( $database, $ignoreInvalidDB = false ) {
                global $wgDBname;
-               if( self::validDatabase( $database ) ) {
-                       if( $database == $wgDBname ) {
+               if ( $ignoreInvalidDB || self::validDatabase( $database ) ) {
+                       if ( $database == $wgDBname ) {
                                // Hmm... this shouldn't happen though. :)
                                return wfGetDB( DB_MASTER );
                        } else {
@@ -122,10 +149,16 @@ class UserRightsProxy {
                return null;
        }
 
+       /**
+        * @return int
+        */
        public function getId() {
                return $this->id;
        }
 
+       /**
+        * @return bool
+        */
        public function isAnon() {
                return $this->getId() == 0;
        }
@@ -150,6 +183,7 @@ class UserRightsProxy {
 
        /**
         * Replaces User::getUserGroups()
+        * @return array
         */
        function getGroups() {
                $res = $this->db->select( 'user_groups',
@@ -187,14 +221,14 @@ class UserRightsProxy {
                        ),
                        __METHOD__ );
        }
-       
+
        /**
         * Replaces User::setOption()
         */
        public function setOption( $option, $value ) {
                $this->newOptions[$option] = $value;
        }
-       
+
        public function saveSettings() {
                $rows = array();
                foreach ( $this->newOptions as $option => $value ) {