Page MenuHomePhabricator

MW 1.27.0-wmf.11: wgUser sometimes null!
Closed, ResolvedPublic

Description

Hi everybody,
I recently installed Lockdown in a MediaWiki 1.27.0-wmf.11. After enabling it I got this in my error_log:

PHP Fatal error: Call to a member function getId() on a non-object in [...]/extensions/Lockdown/Lockdown.php on line 163

The code at that line is

if ( $wgUser->getId() === null && $wgUser->getName() === null ) {

At least in my installation (or in MediaWiki 1.27.0-wmf.11 in general) $wgUser is null on some occassions (but not on all - I checked that by adding a error_log()-call near that line).
My quick (and working) fix for this problem is adding a null-check before that line:

diff --git a/Lockdown.php b/Lockdown.php
index 04d3615..e32b237 100644
--- a/Lockdown.php
+++ b/Lockdown.php
@@ -159,6 +159,10 @@ function lockdownMediawikiPerformAction ( $output, $article, $title, $user, $req
 function lockdownSearchableNamespaces($arr) {
        global $wgUser, $wgNamespacePermissionLockdown;
 
+       if ( !$wgUser ) {
+               return true;
+       }
+
        //don't continue if $wgUser's name and id are both null (bug 28842)
        if ( $wgUser->getId() === null && $wgUser->getName() === null ) {
                return true;

Is this (or something similar) the solution?
Or should $wgUser never be null and I have a serious problem in my installation?

Greetings
Hermann

Event Timeline

Restricted Application added subscribers: StudiesWorld, Aklapper. · View Herald TranscriptFeb 19 2016, 3:31 PM
Kghbln closed this task as Resolved.EditedJun 4 2016, 5:07 PM
Kghbln assigned this task to Bhofmann.
Kghbln added subscribers: Bhofmann, Kghbln.

I just did a fresh install of MW 1.27.0-rc.0 and got the same fatal.

[Sat Jun 04 16:53:47.947772 2016] [:error] [pid 1254] [client 91.65.247.81:64031] PHP Fatal error: Call to a member function getId() on null in /.../w/extensions/Lockdown/Lockdown.php on line 167

This was using REL1_27. However user @Bhofmann checked in rELCK0d59ae7a7e0e3eb5a4638ba8f814a57926dada42 a fix and now after changing to master I am operational again. Thanks a lot for the fix!