[FileBackend] Added back ability to delete file HTTP headers.
[lhc/web/wiklou.git] / includes / User.php
index e210eba..0aa613a 100644 (file)
@@ -1102,10 +1102,10 @@ class User {
                }
 
                if ( is_array( $data ) ) {
-                       if ( is_array( $data['user_groups'] ) ) {
+                       if ( isset( $data['user_groups'] ) && is_array( $data['user_groups'] ) ) {
                                $this->mGroups = $data['user_groups'];
                        }
-                       if ( is_array( $data['user_properties'] ) ) {
+                       if ( isset( $data['user_properties'] ) && is_array( $data['user_properties'] ) ) {
                                $this->loadOptions( $data['user_properties'] );
                        }
                }
@@ -1169,13 +1169,17 @@ class User {
                                }
                                $newGroups = array_merge( $oldGroups, $toPromote ); // all groups
 
-                               $log = new LogPage( 'rights', $wgAutopromoteOnceLogInRC /* in RC? */ );
-                               $log->addEntry( 'autopromote',
-                                       $this->getUserPage(),
-                                       '', // no comment
-                                       // These group names are "list to texted"-ed in class LogPage.
-                                       array( implode( ', ', $oldGroups ), implode( ', ', $newGroups ) )
-                               );
+                               $logEntry = new ManualLogEntry( 'rights', 'autopromote' );
+                               $logEntry->setPerformer( $this );
+                               $logEntry->setTarget( $this->getUserPage() );
+                               $logEntry->setParameters( array(
+                                       '4::oldgroups' => $oldGroups,
+                                       '5::newgroups' => $newGroups,
+                               ) );
+                               $logid = $logEntry->insert();
+                               if ( $wgAutopromoteOnceLogInRC ) {
+                                       $logEntry->publish( $logid );
+                               }
                        }
                }
                return $toPromote;
@@ -1216,6 +1220,14 @@ class User {
        public static function getDefaultOptions() {
                global $wgNamespacesToBeSearchedDefault, $wgDefaultUserOptions, $wgContLang, $wgDefaultSkin;
 
+               static $defOpt = null;
+               if ( !defined( 'MW_PHPUNIT_TEST' ) && $defOpt !== null ) {
+                       // Disabling this for the unit tests, as they rely on being able to change $wgContLang
+                       // mid-request and see that change reflected in the return value of this function.
+                       // Which is insane and would never happen during normal MW operation
+                       return $defOpt;
+               }
+
                $defOpt = $wgDefaultUserOptions;
                # default language setting
                $defOpt['variant'] = $wgContLang->getCode();
@@ -1225,12 +1237,6 @@ class User {
                }
                $defOpt['skin'] = $wgDefaultSkin;
 
-               // FIXME: Ideally we'd cache the results of this function so the hook is only run once,
-               // but that breaks the parser tests because they rely on being able to change $wgContLang
-               // mid-request and see that change reflected in the return value of this function.
-               // Which is insane and would never happen during normal MW operation, but is also not
-               // likely to get fixed unless and until we context-ify everything.
-               // See also https://www.mediawiki.org/wiki/Special:Code/MediaWiki/101488#c25275
                wfRunHooks( 'UserGetDefaultOptions', array( &$defOpt ) );
 
                return $defOpt;
@@ -2213,13 +2219,6 @@ class User {
                global $wgHiddenPrefs;
                $this->loadOptions();
 
-               if ( is_null( $this->mOptions ) ) {
-                       if($defaultOverride != '') {
-                               return $defaultOverride;
-                       }
-                       $this->mOptions = User::getDefaultOptions();
-               }
-
                # We want 'disabled' preferences to always behave as the default value for
                # users, even if they have set the option explicitly in their settings (ie they
                # set it, and then it was disabled removing their ability to change it).  But
@@ -2295,15 +2294,11 @@ class User {
         * @param $val mixed New value to set
         */
        public function setOption( $oname, $val ) {
-               $this->load();
                $this->loadOptions();
 
                // Explicitly NULL values should refer to defaults
                if( is_null( $val ) ) {
-                       $defaultOption = self::getDefaultOption( $oname );
-                       if( !is_null( $defaultOption ) ) {
-                               $val = $defaultOption;
-                       }
+                       $val = self::getDefaultOption( $oname );
                }
 
                $this->mOptions[$oname] = $val;
@@ -2362,7 +2357,7 @@ class User {
                        $this->mRights = self::getGroupPermissions( $this->getEffectiveGroups() );
                        wfRunHooks( 'UserGetRights', array( $this, &$this->mRights ) );
                        // Force reindexation of rights when a hook has unset one of them
-                       $this->mRights = array_values( $this->mRights );
+                       $this->mRights = array_values( array_unique( $this->mRights ) );
                }
                return $this->mRights;
        }
@@ -2394,6 +2389,8 @@ class User {
                        ) );
                        # Hook for additional groups
                        wfRunHooks( 'UserEffectiveGroups', array( &$this, &$this->mEffectiveGroups ) );
+                       // Force reindexation of groups when a hook has unset one of them
+                       $this->mEffectiveGroups = array_values( array_unique( $this->mEffectiveGroups ) );
                        wfProfileOut( __METHOD__ );
                }
                return $this->mEffectiveGroups;
@@ -2474,7 +2471,7 @@ class User {
                                        $count = $this->initEditCount();
                                }
                                wfProfileOut( __METHOD__ );
-                               $this->mEditCount = $count;
+                               $this->mEditCount = intval( $count );
                        }
                        return $this->mEditCount;
                } else {
@@ -3984,7 +3981,7 @@ class User {
                // Pull from a slave to be less cruel to servers
                // Accuracy isn't the point anyway here
                $dbr = wfGetDB( DB_SLAVE );
-               $count = $dbr->selectField(
+               $count = (int) $dbr->selectField(
                        'revision',
                        'COUNT(rev_user)',
                        array( 'rev_user' => $this->getId() ),