WPMW – Integrating MediaWiki with WordPress

Update: For the latest version and up to date documentation, please see the project page.

I got a sudden overwhelming desire to have a wiki, so I decided to set up a MediaWiki installation alongside WordPress. By the time I’d installed it I’d forgotten why I wanted the wiki in the first place, so instead I started looking for a way to integrate the user authentication systems between the two.

Unfortunately, nothing particularly inspiring seemed to exist – just incremental improvements on previously abandoned attempts. The most up to date of those can be found here – it’s an authentication plugin for MediaWiki that looks up the user details directly in the WordPress database. I tried it out and it worked, but left a lot to be desired in terms of functionality so I decided to start from scratch and create my own solution that would leave different things to be desired.

Here’s a brief overview of what I’ve done so far:

  • The main component is a MediaWiki authentication plugin that pulls in the relevant code from WordPress and lets that handle authentication rather than poking around in the database.
  • Users that register on WordPress can use the same details to log in to MediaWiki and vice versa. The accounts are synchronised between the two databases, but authentication itself is delegated to WordPress.
  • If you’re logged in to WordPress, you’re automatically logged in to MediaWiki, and if you log out of MediaWiki, you’re automatically logged out of WordPress. The other two possible combinations of those two statements aren’t true (yet).

I wasn’t sure pulling the WordPress codebase into the MediaWiki sessions was entirely a good idea – in fact, I was pleasantly surprised that it worked at all, and so far there have been only a few little issues to deal with. It definitely isn’t a good idea performance-wise though, but on the plus side it means that WordPress plugins will be respected, as will WordPress database changes.

So, I have this up and running, as you can see by the Wiki link above. Feel free to play around. Issues still to be resolved include:

  1. WordPress lets you register a username that is not valid on the Wiki.
  2. MediaWiki lets you omit the email address when registering, in which case you won’t be able to log in at the WordPress end.

If you’re brave enough to want to try it for yourself, take a look at the documentation.

37 comments

  1. kadin’s avatar

    I am very interested in your progress. I would love to see these two products being used in tandom. Please keep me informed of any further progress.

  2. Molly Lusk’s avatar

    Is it possible to use WPMW with Mediawiki installed on the domain and Wordpress on the sub-domain?

  3. CiaranG’s avatar

    @Molly – not as it stands, but it could be done with a few minor alterations I think.

  4. seph’s avatar

    I’m glad to hear someone is working on a nice solution to this. I downloaded your plugin and gave it a try. Sessions from WP didn’t seem to carry over to MW (I had to login twice) but that doesn’t seem like a big deal.

    Sometimes a user gets an error logging into MW, and I’m not really sure what to make of it:

    Fatal error: (seph) Call to undefined function username_exists() in AuthWP.php on line 108

    I know all the right things are being included.

  5. seph’s avatar

    I’m glad to see your plugin, it looks like it’s shaping up nicely. I did, however, run into a couple problems using it. I’m not sure there’s a better reporting channel, so this is it… I’m running WP 2.6.5 and MW 1.11.0.

    If I’m logged into WP, the session doesn’t transfer to MW.

    Sometimes, logging into MW produces an error. I think it’s when the user doesn’t yet exist in MW. I’m not really sure what to make of it:
    Fatal error: (seph) Call to undefined function username_exists() in AuthWP.php on line 108

  6. CiaranG’s avatar

    @seph – it sounds like something isn’t installed right, because the sessions are definitely transferring from WP to MW here, and we’re running the same versions of everything.

  7. seph’s avatar

    Weird. well, it is an alpha release.
    I’m not sure what I can usefully do to debug it, I’m likely to be more in production mode soon.

  8. Lacueste’s avatar

    Thanks for sharing the work you’ve done so far.

    I already have a live WordPress blog, and I’d like to add a wiki to the same site. Is it possible to install MediaWiki in a subfolder of a my WP-powered domain?

    MW would run completely separate from WP, with its own authentication and own database etc etc. The blog would remain a single-owner site (just me), but the wiki would, of course, be community-run.

  9. adrian Tysoe’s avatar

    Sounds very cool, you mention were free to try it but there is no alpha wordpress plugin so I’m not sure how this works exactly?

    Hope the plugin gets released soon.

  10. CiaranG’s avatar

    @Lacueste – yes, that will work fine – just install MediaWiki in the subdirectory and you’re done.

    @adrian – it doesn’t need a plugin at the Wordpress end (yet), everything is handled by the MediaWiki extension, so go ahead and try it – shout if you have any problems.

  11. adrian Tysoe’s avatar

    I tried it but am getting the same error message as seph. There are two versions of AuthWP on the site. I tried both and both get the error:

    Fatal error: Call to undefined function username_exists() in [path]/wiki/extensions/AuthWP.php on line 96

    with the new version, and

    Fatal error: Call to undefined function username_exists() in [path]/wiki/extensions/AuthWP.php on line 108

    with the original version.

    I’m using WP 2.7
    MediaWiki 1.13.3

    It’s obviously trying to do something. after loggin into WP and going media wiki from the link on the community page in WP when you try and loginto mediawiki the error pops up.

    if you like you can test with my dogs test account :) L/P bravy/bravy

    the WP site is at http://www.flow3d.org

    In the meantime, I’ll keep watching the blog incase someone else posts a solution. Thanks, it’s cool that someone is trying and some people are having success.

    P.S The one thing I didn’t do when following the instructions was the first section relating to .htaccess there isn’t such a file in my wiki root folder so I decided to leave the part listed below out.

    —————————-

    $wgUsePathInfo = false;
    $wgArticlePath = ‘/wiki/page/$1′;

    (when combined with something like this in .htaccess in the wiki directory:

    RewriteEngine on
    RewriteRule ^/$ /page/Main_Page
    RewriteRule ^page/(.*)$ index.php5?title=$1 [L]

  12. Isb1009’s avatar

    I also had the same error as adrian Tysoe, and I’m using WP2.7 and MW1.14.0-alpha.
    I fixed it adding
    require($WP_relpath.'/wp-includes/registration.php');

    just under
    require($WP_relpath.'/wp-load.php');

    I don’t know if it’s a correct way of fixing it, but it has worked for me and will keep it until you release a new version or someone tells me it’s dangerous and why.

    PS.: Thanks for this great plugin!

    ——–
    adrian,
    That code you didn’t use about the .htaccess is just if you want to have pretty URLs, just like when you set up WordPress to use custom permalinks. So, it’s not really necessary but it’s better for your visitors and search engines if you use it ;)

  13. adrian Tysoe’s avatar

    thanks Isb1009, I’ll play with the clean url stuff I left out. I’m not very familiar with the internet stuff and how it works.

    So long as I back up my files first hopefully it will be ok :)

    Thanks for the code snippet that worked for you, I’ll try that too and keep watching the board :)

  14. Isb1009’s avatar

    You’re welcome, adrian.

    Yesterday I found there’s also a problem with the registration on the wiki side, which won’t work unless you add
    global $WP_relpath;
    just after
    function addUser($user,$password) {

    I hope CiaranG fixes it soon.

    ;)

  15. Jeremy Blanchard’s avatar

    I’m crious to know more about how you imported the WordPress codebase into MediaWiki.

    When I tried importing MediaWiki’s codebase into WordPress, I encountered a bunch of errors. My very rough guess about the cause of this would be that they both try to use spl_autoload_register functions.

    The solution I ended up with was to run mediawiki’s API using exec(‘php myfile.php’) and grab the results. This resulted in the code bases not clashing. I wrote up my work here.

  16. Tom Des Jardins’s avatar

    Before I go trying Isb1009 and adrian Tysoe’s fix’s I thought I’d check to see if there was perhaps an updated version available?

    Tia.

  17. CiaranG’s avatar

    I didn’t have those problems on my installation for some reason, but the version in the git repository is the one I’m running here and it seems to be working fine.

    I need to catch up on the comments here and see what the differences are – if you have any further info to add in the meantime it would be gratefully received. :)

  18. victor’s avatar

    I am very interested in your plugin, but it looks like not available for download. Will you make it available again?

    1. CiaranG’s avatar

      It’s still available. I’ve improved the links on the wiki to hopefully make it easier to find.

    2. GhostLyrics’s avatar

      Maybe you just didn’t know how to reproduce these things? It’s very easy to reproduce the first issue. Simply create a new user in Wordpress via the admin panel and try to log into MediaWiki before logging into Wordpress the first time. – This is solved by the offered solution.

      I can’t test the second issue as I’ve turned off registration from the Wiki site.
      I hope that helps you improve this prescious piece of coding.

    3. CiaranG’s avatar

      @GhostLyrics – thanks – easy when you know how to reproduce it. I’ve fixed it now, using a slight variation of the fix supplied by Isb1009 (also thanks!). The include already existed, but just needed moving to the top of the file. That should also remove the need for the second supplied fix.

      Latest version, documentation, issue tracker etc. at http://projects.ciarang.com/p/WPMW/

    4. Geez’s avatar

      Great to see this is still moving ahead !

      One quick question though, you stated that this isn’t a good idea performance wise, can you perhaps elaborate a little please ?

    5. Patung’s avatar

      Hi Ciaran, I just installed the extension on a plain install of wiki with short urls enabled via httpd.conf and it works in terms of me being logged in with my wordpress acccount but I get a lot of blank white pages of death for some urls not all, like

      wiki/User:Myname
      wiki/User_talk:Myname
      wiki/Special:Contributions/Myname
      wiki/Special:SpecialPages
      wiki/Help:Contents
      wiki/Indonesia:Current_events

      Other pages work normal though.

      When I log out of wordpress (2.8.4) I’m still logged into wiki. But being logged in via wordpress means I’m logged into wiki.

    6. Ian’s avatar

      Hi Ciaran – I’m using your plug in to great effect, but hoping to close off one of the avenues spammers are using.

      I don’t want to allow people to sign up via Mediawiki – I want my Wordpress authentication to be the single point.

      Are you aware of any way to disable mediawiki’s inbuilt account creation, and use the WP plugin as the sole authentication mechanism?

      cheers – and thanks again!

    7. CiaranG’s avatar

      @Patung – I’ve never seen that problem, and I’m not sure how this plugin could cause it. Does everthing work normally if you disable the integration?

      @Ian – I haven’t tried it, but I think putting the following in youe MediaWiki config should be enough:

      $wgGroupPermissions[‘*’][‘createaccount’] = false;

    8. Patung’s avatar

      Hi Ciaran, yes, if I disable the integration the wiki functions perfectly. The integration just seems to cause fatal php errors for some of the urls, like those I mentioned. So I’ve basically just left the wiki install sitting there not knowing what to do.

    9. CiaranG’s avatar

      @Patung: Ok, two things: check that the versions (of Wordpress, MediaWiki, and WPMW) that you’re using are up to date, and if they are let me know some more specific details of the PHP errors you’re getting (either displayed, or from the logs) and I’ll see if I can figure it out.

    10. Patung’s avatar

      Hi Ciaran, it’s 2.8.4, and MediaWiki 1.15.1, and I just uploaded wpmw to make sure I had the latest. At the very bottom of localsettings I’ve got

      require_once(‘extensions/AuthWP.php’);
      $wgAuth=new AuthWP();

      It’s here – http://www.indonesiamatters.com/wiki/Main_Page
      Try the three footer links, none work. The ‘view source’ link works but not much else.

      In my error log, when I try to access the ‘broken’ pages, the only things are notices:

      [notice] child pid 16148 exit signal Segmentation fault (11)

      There is no client information.

      One of them for each attempt to access broken urls (which are entirely blank), different pid each time.

    11. Voyagerfan5761’s avatar

      I’ve been experimenting with a MediaWiki install this evening, and found your plugin. You might want to add that changing $WP_relpath allows a MediaWiki installation in a location other than a direct subdirectory of WordPress to use this extension.

      My setup has the wiki on a subdomain, and I made it work by changing just the one variable.

      Cheers! The plugin is working great so far; now I just have to figure out how to merge my wiki sysop account and my WordPress admin account in MediaWiki.

    12. qp’s avatar

      Thank you for your solution.

      It worked fine for 1 month, until today.

      Now, without changing / upgrading / moving anything, I get this message: “Fatal error: Cannot redeclare username_exists() in /home/[…]/wp-includes/registration.php on line 16″

      Could you/somebody help me?

    13. Scott’s avatar

      I tried using your plugin but when I went to my MediaWiki homepage after setting it up, all that loaded was a blank white page. Alternatively, this extension worked, but I’d like to use yours since it automatically picks up on the WordPress login cookie.

      I checked my PHP error_log and there was nothing relating to this extension. I have this in my .htaccess file (and my wiki is in a folder called “w”):
      # Wiki rewrite rules
      RewriteEngine On
      RewriteRule ^wiki/(.*)$ /w/index.php?title=$1 [PT,L,QSA]
      RewriteRule ^wiki/*$ /w/index.php [L,QSA]

      Any ideas how to get it to work? Thanks so much!

    14. Mark’s avatar

      Hi Ciaran, I’m trying to use the extension with the CUNY plugin. Having followed all the steps:

      It just redirects to the homepage. eg http://www.es.science3point0.com/cienciawiki directs to http://www.es.science3point0.com

      I’ve worked out it’s something to do with Auth WP, if I remove the code below it does not redirect:

      # Include the AuthWP.php extension
      require_once(’extensions/AuthWP/AuthWP.php’);
      $wgAuth = new AuthWP();

      I havent played with the usernames, but both usernames are set to Mark.

      Any help would be more than appreciated. (WP 3.0.1 BP 1.2.6)

      1. CiaranG’s avatar

        I’ve never tried this with BuddyPress, but perhaps there is something different in the setup for that internally.

        When does it redirect? When you try to log in, or whenever you visit the page?

      2. Rouffart’s avatar

        Hi ! I use WPMW between http://dubstage.be (wordpress + buddypress) and http://wiki.dubstage.be (MediaWiki). This plugin works perfectly with IE but I think that I’ve a cookie problem, with Firefox 4 and Chrome, nothing append. Have you an idea to resolve this ?

      3. Scott’s avatar

        Hello,
        I want to use you plugin for my site, but I am relucant to download it because the lasst update on your project page was 1 year and 3 months ago.

        Is this project still being worked on? Is there a new location to get updates?
        Thank you,
        ~Scott

        1. CiaranG’s avatar

          @Scott – that’s the latest version. I haven’t changed anything because it’s working fine for me.

        2. Josh Pollock’s avatar

          Ciaran-
          Thanks so much for this extension, I am now able to have a wiki that is unreadable unless you are logged into the wordpress site I am building. Awesome.

          After some tweaking, I am now successfully using it with Wordpress 3.3.2 (running in Multisite, with BuddyPress 1.5.5) and MediaWiki 1.19.0. Wp and Mw are sharing the same database. I am running this on a Godaddy shared linux host. I know Godaddy sucks, but I don’t have time to fix that right now.

          I did all of my setup and troubleshooting with the BuddyPress plugin deactivated and reactivated it once I had everything running.

          At first I followed all of the directions (skipping the modifications to .htaccess) using the following code in my localsettings.php:

          $wgUsePathInfo = false;
          $wgArticlePath = ‘/wiki/page/$1′;
          require_once( “$IP/extensions/AuthWP.php” );
          $wgAuth=new AuthWP();

          and it did not work. It told me it could not find AuthWP.php or Authplugin.php in my extensions folder. AuthWP was definetly there, AuthPlugin was not (I didn’t know it was ever supposed to be there.) I copied AuthPlugin from the includes folder to the extensions folder which made it work.
          I did have to remove the “$wgArticlePath = ‘/wiki/page/$1′;” line as it was redirecting to the wrong directory and since I am on shared hosting, I can not fix that. It then worked fine. Do you or anyone else know if this is a problem and if so, how to fix it?
          To tidy things up I created a WPMW folder in extensions and put AuthWP and AuthPlugin in there and changed the path for AuthWp to match.

          My additions to localsettings.php are now:

          # Disable reading by anonymous users
          $wgGroupPermissions[‘*’][‘read’] = false;
          $wgGroupPermissions[‘*’][‘edit’] = false;
          $wgGroupPermissions[‘*’][‘createaccount’] = false;

          # For WPMW wordpress/mediawiki integration
          $wgUsePathInfo = false;
          require_once( “$IP/extensions/WPMW/AuthWP.php” );
          $wgAuth=new AuthWP();

          My only two other issues were:
          1) After I activated the Buddypress plugin, I had to log out of mediawiki and wordpress before the system worked properly again. No big deal.
          2) If I try and login to the wiki through the wiki’s login with the admin account for the wiki, it tells me my password is incorrect (even though it is correct.) In order to make my wordpress user account a member of the sysop and beuracrat
          group in the wiki I had to disable WPMW, login through the wiki as the admin, use special:userrights to change the user group, log out, and then reactivate the WPMW extension. I tired doing it in phpMyAdmin, but even though it said it added the user to the right groups, it still didn’t give that account access in the wiki. Hopefully now that my wordpress user account has the right permissions in the wiki I will not have to do that whole work around again…

          Again thanks for the extension.
          -Josh

Comments are now closed.