Mediawiki Elgg 1.5 Integration v0.1

Release Notes

This is not a standard Elgg Plugin, read README.txt

        How to integrate MediaWiki and Elgg 1.5

1) Install your wiki on the same server as Elgg
2) Open the media wiki file "include/GlobalFunctions.php"
3) Add the line "wfRunHooks( 'BeforeSetupSession');" after "function wfSetupSession() {"

include/GlobalFunctions.php

/**
 * Initialise php session
 */
function wfSetupSession() {
    wfRunHooks( 'BeforeSetupSession');
    global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgCookieHttpOnly;

4) Install the plugin, blacklist (http://www.mediawiki.org/wiki/Extension:Blacklist) by copying the file blacklist.php to your wiki's extensions directory

5) Open LocalSettings.php for the wiki and add the following at the bottom:
include_once("extensions/blacklist.php");
$wgBlacklist['*']['read'] = array("Special:UserLogin", "Special:UserLogout");

function fnElggAuth($user, &$result) {
        $result=1;//Abort normal Auth process
        $ElggUser=get_loggedin_user();//Elgg (sessions.php) call
        if (!(isset($ElggUser)) || !($ElggUser->guid > 0)){
            $user->loadDefaults();
            return false;
        } else {

            //var username,name,email,lang,guid;
            $username=$ElggUser->get("username");
            $name=$ElggUser->get("name");
            $email=$ElggUser->get("email");
            $lang=$ElggUser->get("language");
            //Makeuser name in Wiki format, init cap and all lower
            $username = strtolower($username);
                // uppercase first letter to make mediawiki happy
            $username[0] = strtoupper($username[0]);

        $user->loadDefaults($username);         // Added as it's done this way in CentralAuth.
 
        $user->mEmail              = $email;
        $user->mName               = $username; // Redundant given use of loadDefaults...?
        $user->mRealName           = $name;
        $user->mEmailAuthenticated = wfTimestamp();

        }
    return false;
}

function fnElggInit() {
    define('externalpage',true);
        require_once("/full/path/to/elgg/engine/start.php");
        global $CONFIG;
    return true;
}
$wgHooks['UserLoadFromSession'][] = 'fnElggAuth';
$wgHooks['BeforeSetupSession'][] = 'fnElggInit';

6) Also in local settings adjust the default permissions for unregistered users, etc.
e.g.
Adding "$wgGroupPermissions['*']['edit'] = false; " will prevent unregistered users from editing pages
Adding "$wgGroupPermissions['*']['view'] = false;" will prevent unregistred users from viewing pages, etc.

7) Hide the login/logout links. Edit the css for your wiki skin (that file by default is skins/monobook/main.css)
li#pt-anonlogin, li#pt-logout, li#pt-login, li#pt-anonlogout
{
    display: none;
}
 8) To add a menu link, customise start.php to the proper path of your wiki and what the text for the link should be and then install this directory (less all other files) as a plugin in Elgg.

  • Hi,

    Great to see this. As mentioned here:

    http://groups.google.com/group/elgg-development/browse_thread/thread/fd8a6526225e3b8c

    I've also created a fairly elaborate Mediawiki integration for a client which I expect will be released in a couple of weeks. Is your integration SSO only or does it include some of the other features I mentioned in that post?

    Just curious ...

  • Hi,

    this sounds great. Is there a live-site or a demo to see how it works?

     

    thx

  • @Kevin , Currently this is SSO only. I'm just getting started with Elgg--I didn't see anything in the plugins for mediawiki and Elgg 1.5 at the time, so I thought I would make a first attempt at this. My title is probably overly broad (sorry), but I guess it was hopes of where I want to go.

    I greatly look forward to the Mediawiki integration plugin you are planing. Your other plugins are all great. Your community involvement is a fantastic role-model for me. Thanks!

    @hollosch

    There is no live-site/demo currently. The summary of it is:

    • Login is handle through Elgg only (WikiLogin is disabled)
    • When visiting the wiki, if an Elgg session is active the user appears logged into the wiki as that user
    • If no Elgg session is active, the user is anonymous on the wiki and whatever permissions are set for anonymous users in the wiki apply.
    • There is no real visual integration / activity flow between the two yet (this should be regarded as alpha/concept code), but I hope this may be built by myself or others in the future.
    • Another limitation applies to wiki permissions.....ultimately I want groups/admin status propigate from Elgg, but currently this is not done. (Though admin status should be a two line tweak to fnElggAuth() )

    Regards,
    Scott

  • The plugin below provides some information on more visual integration between the Wiki and Elgg:
    http://community.elgg.org/pg/plugins/Facyla/read/64639/elgg-plugin-for-mediawiki

    Anyone looking to integrate might do well to examine both plugins. Facyla/Aperto's plugin rely on replicating code from Elgg into a Mediawiki extension. My approach has tried to call Elgg functions (i.e. use the Elgg library/engine) from Mediawiki rather than replicate the code. I hope that this will provide great forward compatability as well as a more elegant design. That said, Facyla/Aperto's plugin is certainly a more mature codebase and also offers the option of having both wiki-only and Elgg logins.

  • Hello,

    I've done all these things, but get these error:
    "Fatal error: Call to undefined function get_loggedin_user() in /home/www/kunden/lionculture.de/architektur/LocalSettings.php on line 132"
    What have I done wrong?

    Regards,
    Kai

  • @Kai, The "get_loggedin_user()" function is the Elgg function that returns the currently logged in user. This function is not getting included. My first guess is to look at this part in your LocalSettings.php:

    function fnElggInit() {
        define('externalpage',true);
            require_once("/full/path/to/elgg/engine/start.php");
            global $CONFIG;
        return true;
    }

     

    Make sure to change "/full/path/to/elgg/engine/start.php" to the correct path for your installation. In my case this is simply "/engine/start.php" because I have elgg in the root folder. In your case it may be slightly different. Please let me know if this helps or if not, what are the particulars of your installation? Elgg version? Wiki version? Path to wiki? Path to elgg?

    Scott

  • Hey,

    After tinking for a couple hours I finally got the code to work. I do have one big problem though.

    After visiting the wiki, it properly displays the logged in name in the upper right (whatever I was logged in on elgg). The problem however is the wiki is not recognizing that name as a registered user.

    For example, if I add the code to block visitors from editing the page, it also prevents my logged in account from editing it as well.

    It seems that it only recognizes the logged in name from elgg, but doesnt pass on the status of being a wiki user.

    Can you help me?

    - Nick

     

  • Hi Nick, sorry for the trouble. I will take a more detailed look later this week and see what the issue may be. I had somewhat stopped devloping this code based on a comment from Kevin (see earlier posts) that a much more elaborate solution was already built and to be released soon.

    My best guess is that the fnElggAuth(....) function is not probably intializing the user. I thought this was working for me correctly, but I will try again and verify. Try to change the fnElggAuth(....) function to this:

    *****************

    function fnElggAuth($user, &$result) {
            $result=1;//Abort normal Auth process
            $ElggUser=get_loggedin_user();//Elgg (sessions.php) call
            if (!(isset($ElggUser)) || !($ElggUser->guid > 0)){
                $user->loadDefaults();
                return false;
            } else {

                //var username,name,email,lang,guid;
                $username=$ElggUser->get("username");
                $name=$ElggUser->get("name");
                $email=$ElggUser->get("email");
                $lang=$ElggUser->get("language");
            $guid=$ElggUser->get("guid");//New v.02
                //Makeuser name in Wiki format, init cap and all lower
                $username = strtolower($username);
                    // uppercase first letter to make mediawiki happy
                $username[0] = strtoupper($username[0]);

        $user = new User();//New v0.02
            $user->loadDefaults($username);         // Added as it's done this way in CentralAuth.
     
            $user->mEmail              = $email;
            $user->mName               = $username; // Redundant given use of loadDefaults...?
            $user->mRealName           = $name;
            $user->mEmailAuthenticated = wfTimestamp();
        $user->mId           = $guid; //New v.02
        $user->mTouched            = wfTimestamp();//New v.02
        $user->saveToCache() ; //New v.02 # This loads the user's group membership!
       


            }
        return false;
    }

    *****************

    There is greater reference on the media wiki site here:
    http://www.mediawiki.org/wiki/Manual_talk:Hooks/UserLoadFromSession

    and at the ElggUser object properties here:
    http://docs.elgg.org/wiki/Engine/DataModel/Entities/ElggUser

    Let me know if the above change has any effect. If it still doesn't work I will try to recreate and solve the problem Friday. (Unfortunately, my schedule does not allow much work prior to that).

    Cheers!
    Scott

     

  • Ah yeah, I tried looking for Kevin's work, but it seems it still hasn't been posted?

    Anyways, I haven't tried out the new code you posted, but I have another problem (should be an easy on however though).

    It involves this piece of code:
    #########################
    function fnElggInit() {
        define('externalpage',true);
            require_once("/home/content/l/i/n/linxgws/html/bizbox/engine/start.php");
            global $CONFIG;
        return true;
    #########################

    And I am having a similar problem to the other guy who had the "Fatal error: Call to undefined function get_loggedin_user()" error.

    The above code works only part of the time.

    If the URL I am using to access the page is "http://mysite.com/wiki/" then it works just fine.
    But if I am using the more common URL (with 'www.' added) as in "http://www.mysite.com/wiki/" then it gets the get_loggedin_user error as above.

    Whats going on here?

  • I implemented the new "v0.02" code, and it didn't seem to help. It oddly redirected me to the Elgg layout and gave me a random error:

    MWException

    SkinTemplate::makeTalkUrlDetails given invalid pagename User:

    And if it helps any, for my original problem (wiki shows it is logged in as the Elgg user, but doesn't recognize it as a wiki user) I took a screenshot:
  • Okay I solved one problem!

    Using the code you gave me, but commenting out the line "$user = new User();" seems to work.
    ########################################
    function fnElggAuth($user, &$result) {
            $result=1;//Abort normal Auth process
            $ElggUser=get_loggedin_user();//Elgg (sessions.php) call
            if (!(isset($ElggUser)) || !($ElggUser->guid > 0)){
                $user->loadDefaults();
                return false;
            } else {

                //var username,name,email,lang,guid;
                $username=$ElggUser->get("username");
                $name=$ElggUser->get("name");
                $email=$ElggUser->get("email");
                $lang=$ElggUser->get("language");

    $guid=$ElggUser->get("guid");//New v.02

                //Makeuser name in Wiki format, init cap and all lower
                $username = strtolower($username);
                    // uppercase first letter to make mediawiki happy
                $username[0] = strtoupper($username[0]);

    //$user = new User();//New v0.02 <---------------- CODE NOT USED

            $user->loadDefaults($username);         // Added as it's done this way in CentralAuth.
     
            $user->mEmail              = $email;
            $user->mName               = $username; // Redundant given use of loadDefaults...?
            $user->mRealName           = $name;
            $user->mEmailAuthenticated = wfTimestamp();

    $user->mId = $guid;                //New v.02
    $user->mTouched = wfTimestamp();        //New v.02
    $user->saveToCache() ;                //New v.02 # This loads the user's group membership!

            }
        return false;
    }
    ###################################

    My Elgg now correctly logs into mediawiki automatically and recognizes the Elgg user as a mediawiki user.

    Problems Still Left:
    - The domain problem I listed earlier (http://site.com -vs- http://www.site.com)
    - Although it is working as intended, it still displays this warning "User account "Geekwithstyle" is not registered. Please check if you want to create/edit this page." like in the above picture. But like I said, it is still functioning as intended. This is merely a wrongly displayed string.

     

  • Great work, Nick. To my knowledge as well, Kevin's code has not been released. I guess it is in his clients hands. I think I know the source of the two remaining problems, but I ended up doing a pretty major change to the LocalSettings code in the process:

    Problems Before
    - "Fatal error: Call to undefined function get_loggedin_user()" error.

    Apparently under some circumstances a session object does not exist when fnElggAuth is being called. This means that fnElggInit() has never been called to include the files. Adding a check for an active session fixes this error (at least for me).

    -Errant Text

    It seems like the previous code somehow did not add the user to the "Users" group; so, they were being treated the same as an unregistered user. When we added the v.02 code it fixed this issue only halfway. I refactored the code in a big change to now create a full account in the Wiki database. This (at least for my solution) is probably better long term anyway; so that users can add wikipedia preferences, etc.

    The code in my LocalSettings.php now looks like this (in relevant part)

    #******Inserts for Elgg Integration***********
    include_once("extensions/blacklist.php");
    $wgBlacklist['*']['read'] = array("Special:UserLogin", "Special:UserLogout");

    function fnElggAuth($user, &$result) {
        global $wgUser, $wgCookieExpiration;
     
        # Ensure we have a PHP session in place.
        //This fixes the get_loggedin_user() not defined error in previous release.
        if( session_id() == '' ) {
            wfSetupSession();
        }

        #Get Elgg User Object
            global $CONFIG;
            $result=1;//Abort normal Auth process
            $ElggUser=get_loggedin_user();//Elgg (sessions.php) call
            if (!(isset($ElggUser)) || !($ElggUser->guid > 0)){ //No Elgg User
                $user->loadDefaults();
                return false;
            }
       
        $username=$ElggUser->get("username");

        # If no account exists, autocreate one.
        # Check validity just in case.
        $name = User::getCanonicalName( strtolower( $username ), 'creatable' );
        if ( $name == false) {
            die("here1" . $name);
            $result = false;
            return true;
        }
        //$user = new User(); //!!!Do Not Call User!! After User() you cannot change mName?! //Thanks Skrypt for tracking down this error.
        $user->mName = $name;
        $userId = $user->idForName();
        if ( 0 == $userId ) {
            fnCreateElggAcct( $user, $ElggUser );    # see below
        } else {
            $user->setId( $userId );
        }
     
        # Finally, automagically login based on the corporate credentials
        $user->loadfromDatabase();
        $user->saveToCache();        # this also loads the user's group membership
        $wgUser = $user;
     
        # here, use fixed offset, but elsewhere try to align with actual corporate credentials expiry
        $wgCookieExpiration = 13 * 60 * 60;
        $wgUser->setCookies();
        $result = true;                # user is logged in
        return true;
    }

    function fnCreateElggAcct($WikiUser, $ElggUser) {
        $name=$ElggUser->get("name");
            $email=$ElggUser->get("email");
            $lang=$ElggUser->get("language");
            $guid=$ElggUser->get("guid");//New v.02
        $username=$WikiUser->mName;

        /**
         * Add a user to the database, return the user object
         *
         * @param $name \string Username to add
         * @param $params \type{\arrayof{\string}} Non-default parameters to save to the database:
         *   - password             The user's password. Password logins will be disabled if this is omitted.
         *   - newpassword          A temporary password mailed to the user
         *   - email                The user's email address
         *   - email_authenticated  The email authentication timestamp
         *   - real_name            The user's real name
         *   - options              An associative array of non-default options
         *   - token                Random authentication token. Do not set.
         *   - registration         Registration timestamp. Do not set.
         *
         * @return \type{User} A new User object, or null if the username already exists
         */
        $params = array(
                'email' => $email,
                'email_authenticated' => wfTimestampNow(),
                'real_name' => $name,
        );
        $WikiUser = User::createNew($username,$params);
       
    }

    function fnElggInit() {
        define('externalpage',true);
            require_once("/full/path/to/elgg/installation/engine/start.php");
            global $CONFIG;
        return true;
    }
    $wgHooks['UserLoadFromSession'][] = 'fnElggAuth';
    $wgHooks['BeforeSetupSession'][] = 'fnElggInit';

    $wgGroupPermissions['*']['edit'] = false;

    #******End Inserts for Elgg Integration***********

    Current Limitations:

    - Accounts in the wiki database are created with then current information. If a user changes his/her name, email, etc. in Elgg these changes will not currently be propriaged over to the Wiki. (Also applies visa-versa)

    -Currently all users are justed added to the standard "Users" group in the wiki. It would be possible for any user to be upgraded by the SysOp; however, currently no sysOp is created. The current work around is to desigate the sysOp by going directly into the Wiki database; this is obviously not an elegant solution long term. Eventually, we should probably pull Elgg groups and associate users with Wikigroups of the same name.

    Let me know if this helps. Also, let me know what other issues you find, and I will see what more I can get working.

    All the best,
    Scott

  • Seems like a handful of people are working on this.  The Elgg comminity custom work page indicates that there is the possibility of getting paid to do Mediawiki integration.  http://docs.elgg.org/wiki/Custom_work

    Have the developers looked at that?  Would be nice to get a skilled dev to duplicate some of the work others say they have done for clients.

  • hey guys i have tryed all codes (new and old) and i still cant get this to work. i get taken to a blank page when i insert the following code into localsettings.php

     

    =====**Code**=====

    include_once("extensions/blacklist.php");
    $wgBlacklist['*']['read'] = array("Special:UserLogin", "Special:UserLogout");

    function fnElggAuth($user, &$result) {
        global $wgUser, $wgCookieExpiration;
     
        # Ensure we have a PHP session in place.
        //This fixes the get_loggedin_user() not defined error in previous release.
        if( session_id() == '' ) {
            wfSetupSession();
        }

        #Get Elgg User Object
            global $CONFIG;
            $result=1;//Abort normal Auth process
            $ElggUser=get_loggedin_user();//Elgg (sessions.php) call
            if (!(isset($ElggUser)) || !($ElggUser->guid > 0)){ //No Elgg User
                $user->loadDefaults();
                return false;
            }
      
        $username=$ElggUser->get("username");

        # If no account exists, autocreate one.
        # Check validity just in case.
        $name = User::getCanonicalName( strtolower( $username ), 'creatable' );
        if ( $name == false) {
            die("here1" . $name);
            $result = false;
            return true;
        }
        //$user = new User(); //!!!Do Not Call User!! After User() you cannot change mName?! //Thanks Skrypt for tracking down this

    error.
        $user->mName = $name;
        $userId = $user->idForName();
        if ( 0 == $userId ) {
            fnCreateElggAcct( $user, $ElggUser );    # see below
        } else {
            $user->setId( $userId );
        }
     
        # Finally, automagically login based on the corporate credentials
        $user->loadfromDatabase();
        $user->saveToCache();        # this also loads the user's group membership
        $wgUser = $user;
     
        # here, use fixed offset, but elsewhere try to align with actual corporate credentials expiry
        $wgCookieExpiration = 13 * 60 * 60;
        $wgUser->setCookies();
        $result = true;                # user is logged in
        return true;
    }

    function fnCreateElggAcct($WikiUser, $ElggUser) {
        $name=$ElggUser->get("name");
            $email=$ElggUser->get("email");
            $lang=$ElggUser->get("language");
            $guid=$ElggUser->get("guid");//New v.02
        $username=$WikiUser->mName;

        /**
         * Add a user to the database, return the user object
         *
         * @param $name \string Username to add
         * @param $params \type{\arrayof{\string}} Non-default parameters to save to the database:
         *   - password             The user's password. Password logins will be disabled if this is omitted.
         *   - newpassword          A temporary password mailed to the user
         *   - email                The user's email address
         *   - email_authenticated  The email authentication timestamp
         *   - real_name            The user's real name
         *   - options              An associative array of non-default options
         *   - token                Random authentication token. Do not set.
         *   - registration         Registration timestamp. Do not set.
         *
         * @return \type{User} A new User object, or null if the username already exists
         */
        $params = array(
                'email' => $email,
                'email_authenticated' => wfTimestampNow(),
                'real_name' => $name,
        );
        $WikiUser = User::createNew($username,$params);
      
    }

    function fnElggInit() {
        define('externalpage',true);
            require_once("/engine/start.php");
            global $CONFIG;
        return true;
    }
    $wgHooks['UserLoadFromSession'][] = 'fnElggAuth';
    $wgHooks['BeforeSetupSession'][] = 'fnElggInit';

    $wgGroupPermissions['*']['edit'] = false;

    ====**End**====

    So please help me out as i can not see what is wrong

  • i looked back at the code and add one function or line at a time and found the problem is with the following

    $wgHooks['UserLoadFromSession'][] = 'fnElggAuth';
    $wgHooks['BeforeSetupSession'][] = 'fnElggInit';

    Dont know why as i followed it all to a tea

  • sorry about all the posts im just trying to work it out and let you guys know what im doing. Any way i was playing around with the code above  and one i deleted [] from both functions i get an error like follows:

    The Hub Wiki error

    Hooks array for event 'BeforeSetupSession' is not an array!

    Backtrace:

    #0 C:\xampp\htdocs\wikitest\includes\GlobalFunctions.php(2656): wfRunHooks('BeforeSetupSess...')
    #1 C:\xampp\htdocs\wikitest\includes\Setup.php(245): wfSetupSession()
    #2 C:\xampp\htdocs\wikitest\includes\WebStart.php(129): require_once('C:\xampp\htdocs...')
    #3 C:\xampp\htdocs\wikitest\index.php(42): require_once('C:\xampp\htdocs...')
    #4 {main}

     

     

  • well i got it working (changed operating systems from Vista to Ubuntu now my problem is as follows "Strict Standards: Creating default object from empty value in /opt/lampp/htdocs/elgg/engine/lib/elgglib.php on line 1486" this shows at the very top of the page if you would like to see go to http://thehub.ath.cx/wiki

     

Stats

  • Category: Uncategorized
  • License: GNU General Public License (GPL) version 3
  • Updated: 2014-11-17
  • Downloads: 5812
  • Recommendations: 0