Extension:HttpAuth

Overview
This extension only works with MediaWiki instances setup behind HTTP authentication. It pulls usernames from. The extension will then either log the user on to MediaWiki if the user name exists in the database or create a new user if it does not.

Installation
Drop the extension in

Edit LocalSettings.php and add:

also remember to add session_start; at the top of the page.

Note: If authentification does not work try to replace 'PHP_AUTH_USER' with 'REMOTE_USER' in the code above and in HttpAuthPlugin.php

Name Substitution
This extension also supports name substitution. For example if the user's Http Auth username is foo and the user would like their wiki name to be bar we can do this:

Do this directly after instantiating the object

Allowing Anonymous Browsing
If you want to allow anonymous users to browse the site without hitting a basic auth popup and you have clean URLs configured you can place some code like this near the top of your LocalSettings.php script:

This will make sure that whenever a user clicks the 'log on' link they are redirected to /Special:Userlogin (if necessary). Apache can then be configured with the authentication inside a  directive, which will pop up the authentication box for that URL only. Finally, when they reach that URL (having authenticated) we redirect them to wherever they came from, if that information was provided by the link. The user should then be logged in.

Note: This code has not been tested in multiple server configurations - expect to need to tweak this code for your specific setup! Also note, this does not easily allow users to log out.

When it doesn't work
This plugin code fails with MediaWiki version 1.12.0 and PHP version 5.1.6 though this ammend may be applicable to other versions as well.

In the autoAuthenticate function you need to change the line that reads:

$this->initUser(&$user);

so that it now reads this:

$this->initUser($user);

Plus you need to change the function definition for initUser so that instead of:

function initUser( &$user ) {

it now reads:

function initUser( $user )

otherwise you get an error about pass by reference syntax which has been deprecated for PHP5.

Back in the autoAuthenticate function you need to change the one line that currently reads:

return 0;

to:

return false;

Plus add a new line after the last saveSettings line which reads:

return true;

I think this is because of some kind of change in either PHP's default return values or the MediaWiki API for auth plugins has become stricter.

Also - I've no idea what someone's going on about when they mention start_session earlier in this document... All I had to do was paste the one block of code in to the bottom of my LocalSettings.php and be done with it.