Page MenuHomePhabricator

Fatal error: Uncaught Error: Call to a member function getCode() on null in /includes/user/User.php:1578 in getDefaultOptions()
Open, Needs TriagePublic

Description

The above error shows directly after a fresh install of a Mediawiki 1.29
see e.g. https://stackoverflow.com/questions/46169560/mediawiki-500-internal-error-when-visit-the-home-page

steps to reproduce:

  1. use Ubuntu 16.04.1 server with Apache 2.4.18, PHP 7.0.22 and mysql 5.0.12-dev
  2. download mediawiki-1.29.1.tar.gz
  3. unzip
  4. go thru setup the wiki steps - only modify:
    1. wiki languag en
    2. set database name
    3. supply mysql admin user and password
    4. setup database user and password and let installation create user
    5. set name of wiki

From here I do not 100% remember whether I supplied a user or have forgotten to do so and used the mysql admin user.
It may also have been that the user already existed from a prior installation attempt.

the Problem went away after reinstalling with the following steps:

  • dropping database
  • removing user from mysql.users
  • strangely the "user exists" error still appeared on installation
  • granting access rights was therefore necessary on the mysql database.

and then going over the steps above again.

Event Timeline

Aklapper renamed this task from Fatal error: Uncaught Error: Call to a member function getCode() on null in /var/www/wiki/includes/user/User.php:1578 to Fatal error: Uncaught Error: Call to a member function getCode() on null in /includes/user/User.php:1578 in getDefaultOptions() .Oct 9 2017, 3:50 PM
Aklapper added a project: MediaWiki-General.

Thanks for reporting this!
For the records, that line is $defOptLang = $wgContLang->getCode();

Sorry for the necropost, but since this is something people are likely to land on when supporting older MW versions, I thought I should mention the solution that worked for me, which I found in the wild on the internet.

The problem appears to occur when $wgLanguageCode is set to anything other than en. Even English variants, en-ca in my case, won't work. As soon as I changed it to the default en, the error disappeared.