Blitzed.org

Blitzed MediaWiki modifications

From Blitzed

Jump to: navigation, search

This wiki is running MediaWiki software, which had to be modified slightly in order to integrate it neatly with Blitzed services. This page documents these modifications for MediaWiki 1.4.

Contents

[edit] Modifications

[edit] Registered nickname authentication

Instead of allowing anonymous access and letting users create their own wiki accounts, we decided that it would be a better idea to use the "account database" we already have in the form of our Blitzed IRC services database, i.e. every registered nickname should be able to be used as a wiki account as well. Because anyone can freely register nicknames on the IRC network, we hope that this does not severely violate the wiki spirit. It gives us the advantage of easy mapping of user names and user pages to IRC nicks, and slightly more access control. After all, this wiki is meant for Blitzed IRC users.

This does pose a few problems. The set of allowed characters for IRC nicknames is not entirely the same as the set of allowed characters in Mediawiki accounts. A notable example is the '_' underscore character, which is allowed in nicknames, but replaced with a space in wiki accounts.

[edit] Channel namespace

MediaWiki has the concept of namespaces to separate pages with certain goals that is not directly related to the main content of the wiki. For example, there is a User namespace to allow wiki users to express their own ideas, a Talk namespace with pages to discuss the main wiki content, a Mediawiki namespace for interface messages, etc. We use the User namespace to allow Blitzed IRC users to have their own homepage. It would be nice to have a similar Channel namespace to be used by IRC channels as well.

[edit] Implementation

[edit] Blitzed Services authentication plugin

MediaWiki supports custom authentication plugins. Prior to version 1.4, we had to modify the User class (includes/User.php) directly to make it authenticate off our services database. In 1.4 this is cleaner, with an overrideable class AuthPlugin in includes/AuthPlugin.php. Documentation is available as comments in this file.

mark has written a custom AuthBlitzed plugin that authenticates off the Blitzed services database running on the same MySQL server as the wiki database itself. It implements/overrides the following methods:

  • userExists(), which allows Mediawiki to check whether a given username exists in the external account database
  • authenticate(), which given a username and password grants or denies access
  • autoCreate(), which allows the wiki to automatically create accounts in its own database
  • strict(), which disallows the wiki to authenticate against its own account database when the external account database denies access
  • initUser(), which provides the wiki account db with an e-mail address and full name out of the external database
  • cleanupName(), a non standard extension that implements our own username syntax rules.

The last method is currently not supported by MediaWiki, so User.php and AuthPlugin.php had to be modified slightly:

[edit] User.php

function newFromName( $name ) {
    $u = new User();

    # Clean up name
    global $wgAuth;
    $t = $wgAuth->cleanupName( $name );

    if( is_null( $t ) ) {
        return NULL;
    } else {
        $u->setName( $t );
        $u->setId( $u->idFromName( $t ) );
        return $u;
    }
}

function idFromName( $name ) {
    $fname = "User::idFromName";

    # Clean up name
    global $wgAuth;
    $nt = $wgAuth->cleanupName( $name );
    if( is_null( $nt ) ) {
        # Illegal name
        return null;
    }
    $dbr =& wfGetDB( DB_SLAVE );
    $s = $dbr->selectRow( 'user', array( 'user_id' ), array( 'user_name' => $nt ), $fname );

    if ( $s === false ) {
        return 0;
    } else {
        return $s->user_id;
    }
}

[edit] AuthPlugin.php

/**
 * Allow an auth plugin to redefine the way a username as entered by the
 * user is cleaned up. By default, this is using the standard Title rules.
 *
 * @param string $username
 * @return string
 * @access public
 */
function cleanupName( $username ) {
    # Override this to allow different usernames
    $t = Title::newFromText( $username );
    return ( is_null( $t ) ? NULL : $t->getText() );
}

[edit] SpecialPreferences.php

Furthermore, includes/SpecialPreferences.php had to be modified slightly, in order to disable the changing of passwords by users. Both the snippets of code that outputs the password fields and the code that saves the new passwords were commented out.

[edit] Configuration

To activate the Blitzed services authentication plugin, place it in the extensions/ directory, and add this snippet to LocalSettings.php:

# Use Blitzed Authentication
require_once( 'extensions/AuthBlitzed.php' );
$wgAuth = new AuthBlitzed();

[edit] Namespaces

Custom namespaces can easily be added from the configuration file, without having to touch the actual code. To define the namespaces Channel and Channel Talk, add this to LocalSettings.php:

$wgExtraNamespaces = array(
       100 => "Channel",
       101 => "Channel_Talk"
       );

To allow sub pages and searching by default:

$wgNamespacesWithSubpages = array( -1 => 0, 0 => 0, 1 => 1,
 2 => 1, 3 => 1, 4 => 0, 5 => 1, 6 => 0, 7 => 1, 8 => 0,
 9 => 1, 10 => 0, 11 => 1, 100 => 1, 101 => 1);
$wgNamespacesToBeSearchedDefault = array( -1 => 0, 0 => 1, 1 => 0,
 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 1,
10 => 0, 11 => 1, 100 => 1, 101 => 0 );

[edit] Known problems

  • Links to userpages in RecentChanges don't work properly.
Personal tools