Ritchie Swann

RSS

Thoughts for a dull June

You know you've made it as a developer when Raymond Chen answers one of your questions, without dismissing it as blindingly obvious, silly or spam.

Mind you, I'd completely forgotten about the question in the first place, but there we go. Cheers, Raymond.

0 comments
Thursday, 11 June 2009

Auth_xphpBB

Well, it's been a while since I've blogged on here, due to getting snowed under with coding, but I've now got something you might find useful.

If you run a user interactive site, you might well use phpbb as your bulletin board software, and MediaWiki for your user generated documentation. (Well, at least I've run a site or two doing this).

There's already a nice extension here that allows MediaWiki to use phpBB login credentials, so you don't have to keep shuffling two sets of users around, but I thought it would be nice to go one further and use the actual phpBB API. This is the result.

This extension requires PHP5.2, MediaWiki 1.11+ and phpBB3. To get this working, you'll need to do the following:

  1. Because MediaWiki and PHPBB both make prominent use of a class called 'user', and because PHP 5.2 doesn't provide a nice way of using include or require and yanking the whole lot into a separate namespace, you'll have to modify one codebase or the other to avoid conflicing class names. I recommend changing phpBB, and renaming user to phpbbuser. You will need to change the class definition and constructor in includes/session.php and the single instantiation point in common.php.
  2. Download the source here, unpack it and put it in the extensions subdirectory where you've installed MediaWiki.
  3. Add the following code to the bottom of LocalSettings.php:
    
    require_once './extensions/Auth_xphpBB.php';
    
    $wgAuth_Config = array();
    // Name of your PHPBB group
    // users need to be a member
    // of to use the wiki. (i.e. wiki)
    // This can also be set to an array 
    // of group names to use more then 
    // one. (ie. 
    // $wgAuth_Config['WikiGroupName'][] = 'Wiki';
    // $wgAuth_Config['WikiGroupName'][] = 'Wiki2';
    // or
    // $wgAuth_Config['WikiGroupName'] = array('Wiki', 'Wiki2');
    // )
    $wgAuth_Config['WikiGroupName'] = 'Wiki';
     
    // This tells the Plugin to require
    // a user to be a member of the above
    // phpBB group. (ie. wiki) Setting
    // this to false will let any phpBB
    // user edit the wiki.
    
    $wgAuth_Config['UseWikiGroup'] = true;
    // Path from this file to your phpBB install.
    $wgAuth_Config['PathToPHPBB']    = '../phpbb3/';
     
    // Localize the messages
    $wgAuth_Config['LoginMessage']   =
    'You need a phpBB account to login.';
    $wgAuth_Config['NoWikiError']    =
    'You are not a member of the required phpBB group.';
     
    $wgAuth = new Auth_phpBB($wgAuth_Config);
    
    These settings should be familiar if you've used the Auth_phpBB.php extension, though you'll notice there are a lot less options.

    Any thoughts, comments, praise to the skies or flamewars, do let me know!

0 comments
Monday, 04 May 2009

OpenID considered pointless

Why is everybody and their pet gerbil banging on about OpenID like it's the second coming?

Let me see, I guess this is trying to solve the problem that you can't remember 72 gazillion passwords for all the online services you use.

Well, guess what, my browser lets me cache passwords so I don't need to. So does my IPhone. This problem was solved at least five years ago, and my current browser seems to manage quite well with it.

I don't have accounts on any of the so-called "popular" providers listed on OpenID's site, and I can't be faffed to roll my own on here because there's no point.

If your site uses OpenID to log in, feel free to flame me to a crisp 'cause I'll never read it.

0 comments
Tuesday, 03 February 2009

PRJ0050

Here's another totally non obvious error message you can get when building old C++ code.

PRJ0050: Failed to register output. Please ensure you have the appropriate permissions to modify the registry.

Turns out it's not necessarily related to permissions or the registry at all. You can simply get this if you try and register a DLL that has a direct dependency on another native DLL that can't be found. So, for example, if you have a COM DLL foo.dll that uses functions in a non-com DLL called bar.dll, and you link directly against bar.lib, you'll need to have bar.dll either in the same path as foo.dll (or in one of the other system paths) when it comes to registering it.

Easy when you know how.

0 comments
Thursday, 22 January 2009

'Switch' considered harmful

Last night, I felt it was high time I learned some Python, since it's been around for years and since Eric S Raymond recommends it as a first language, it can't bee too hard to pick up for a grizzly old git like me.

Now, while I can do things in three lines of python that would take several pages to do in C (which is pretty much the raison d'etre for any high level language), one thing struck me as being slightly odd - there's no switch statement. (The DBA weenies among you will know this as the SELECT CASE statement - it's the same animal). So you can't do things like:


switch( viking ) {
  case 1 :
    menu = "eggs";
    break;
  case 2 :
    menu = "bacon";
    break;
  default :
    menu = "spam";
    break;
}

(At this point, all of you python lovers out there are saying : "Eggs? Bacon? Spam? You really have been drinking the python kool-aid haven't you?" Shut up.)

And this doesn't actually strike me as a bad thing. Why's that? Well, switch is easy to abuse. Here's a popular example :


switch( type ) {
  case sprocket :
    DoSprocketThing();
    break;
  case widget :
    DoWidgetThing();
    break;
}
What's wrong with this? Well basically, when you add a new type, like a grommit, you've got to plumb your DoGrommitThing into the switch block. And what are we doing here? Calling a different method depending on what type we've got? Hmm, smells like polymorphism to me. Call the object oriented police!

And that example's a nice one. I've seen much worse, like where you don't just have one function call, but great steaming piles of code in each case block. Home baked state machine handlers are the biggest offenders for this. (Especially if they're written in VB. With nested With statements. Can you tell I've had to debug a few of these in the past?)

Anyway, python works around the lack of a switch by allowing you to associate values with functions. Pop onto the wikipedia page above and you'll see an example. I like this, because you're abstracting away the algorithm to do the switch as a data structure. C's been doing this for years (with function pointers), but the nice thing about python is it makes this easy, and doing silly stuff hard. I mean, you can still do insane state machine abuse by using lambdas though, just it's just a bit harder to think about what code to write, so you're less likely to do it.

I don't miss switch. Do you?

0 comments
Friday, 19 December 2008

Archives: