User Tools

Site Tools

Action disabled: register

Changing a Username in Mediawiki

I'm putting this blurb here because this action drove me crazy for a little while.

I recently did an install of Mediawiki for someone and realized that I set the username wrong. Well, I'm not a Mediawiki user (this is kind of obvious since this is a Dokuwiki site…), so I thought that I would just pop into the MySQL database and change the username there in a jiffy. This was what I thought anyway…

Enter the Bad Idea

Well, I fired up the MySQL cli and just did an update query:

UPDATE USER SET user_name = 'newname' WHERE user_id = 1;

Obviously, this changed the username that was there and I thought I was done…until I tried to log in. My login attempts with the new username were failing. After digging through the mountain PHP code that comprises Mediawiki for a while, I realized I was getting nowhere in a big hurry. I poked around the DB schema for a while and I couldn't find any relations I might have been missing. User authentication is pretty simple, right?

Finally, I decided to just see what the hell Mediawiki was throwing at the database in terms of raw queries. In case you don't know how to do this, you can turn general query logging on and off in the MySQL cli with the following:

SET @@global.general_log_file = '/var/tmp/mysql.query.log';
SET @@global.general_log = 1;
-- To turn off the general_log when you are done:
SET @@global.general_log = 0;

With this on, I tried a couple of logins and LO AND BEHOLD, I found the stupidity. Apparently, no matter what you type in the damn username field of the HTML form, Mediawiki uppercases the first letter of the username before querying the database. That means entering the following in the login form:

Username: newname
Password: password

turns into a query like:

SELECT user_id FROM USER WHERE user_name = 'Newname' LIMIT 1;

instead of the expected:

SELECT user_id FROM USER WHERE user_name = 'newname' LIMIT 1;

So, the rule of thumb here is that if you update the DB directly, always uppercase the first letter of the username you are changing.

apps/mediawiki/chusername.txt · Last modified: 2012/04/17 02:38 by jay