Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/332750 )

Change subject: Do not try to save options for anonymous users
......................................................................

Do not try to save options for anonymous users

This is what this code does:
* $user *can* be anonymous. I dug deep into the code and it looks like
  this is an expected behavior.
* $oldUser will be null for IP users, possibly crashing any code doing
  something with $oldUser->… below.
* But this code is usually not exectued, because the $betaFeatures array
  is empty.
* But the array is not *guaranteed* to be empty. It is filled by all kinds
  of extensions that may or may not check if the user is anonymous.

This error showed up in the Wikibase CI. There are many, many ways to fix
this, but I found this the most obvious one. An other one is a
 if ( $user->isAnon() ) {
     return;
 }
at the top of this static function.

I removed the return because a positive "true" is the default for a long,
long time now for all hooks.

Change-Id: I2a09062e60e5abe19017a2bb98f7b22e76efc933
---
M BetaFeaturesHooks.php
1 file changed, 7 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BetaFeatures 
refs/changes/50/332750/1

diff --git a/BetaFeaturesHooks.php b/BetaFeaturesHooks.php
index 745979a..153f2c3 100644
--- a/BetaFeaturesHooks.php
+++ b/BetaFeaturesHooks.php
@@ -64,13 +64,18 @@
        /**
         * @param User $user User who's just saved their preferences
         * @param array &$options List of options
-        * @return bool
         */
-       static function updateUserCounts( $user, &$options ) {
+       static function updateUserCounts( User $user, &$options ) {
                global $wgBetaFeatures;
 
                // Let's find out what's changed
                $oldUser = User::newFromName( $user->getName() );
+
+               if ( !$oldUser ) {
+                       // Anonymous users do not have options, shorten out.
+                       return;
+               }
+
                $betaFeatures = $wgBetaFeatures;
                Hooks::run( 'GetBetaFeaturePreferences', array( $user, 
&$betaFeatures ) );
 
@@ -91,8 +96,6 @@
                                )
                        );
                }
-
-               return true;
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/332750
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a09062e60e5abe19017a2bb98f7b22e76efc933
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BetaFeatures
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to