Simple Machines Community Forum

Customizing SMF => Bridges and Integrations => Topic started by: nyall on February 04, 2012, 08:43:36 AM

Title: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 04, 2012, 08:43:36 AM
Hi all

Last night I was trying to install the new MW Auth bridge to allow my SMF 2.0.2 forum to be able to integrate a wiki, as used here for documentation.

I installed MediaWiki 1.18.1 in Spanish on the server successfully, and was able to open an account, login and use it without any integration. My SMF 2.0.2 + Simple Portal 2.3.3 forum was working without issues as has been for quite some time now.

I followed the instructions for bridging, copied the required file and did the required modifications. Unfortunately, to no avail.

Now I have everything messed up:

- The Home Page (http://www.domain.com) was managed by SimplePortal, now MediaWiki has overriden this and the Wiki is set as the Home Page

- When you try to login to the wiki, the link (http://www.domain.com/wiki/index.php?title=Especial:Entrar&returnto=P%C3%A1gina+principal) takes me to SMF login page, even if I am already logged in to the forum. If I enter username and password (the same for the user already logged in, or a different one, doesn't matter because it is ignored) I'm taken to the main forum page.

- And of course authentication does not work, I created a new tab in the forum menu for accessing http://www.domain.com/wiki and the link works, but all I get is my IP recognized and the "Login/Register" which, as mentioned, takes me to forum's login form.

What am I doing wrong? What logs or information can I provide to try to identify the root cause for this issue? Any help would be hughly appreciated.

Thanks in advance.
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 04, 2012, 09:15:16 AM
Follow up: I think .htaccess modifications have something to do with this
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: NanoSector on February 04, 2012, 09:53:05 AM
As far as I am aware, the MediaWiki bridge is outdated and will not work correctly with SMF 2.0.2. It's possible that I'm wrong though.

Where did you download the bridge? (meh that sounds weird :P)
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: Illori on February 04, 2012, 10:18:05 AM
http://www.simplemachines.org/community/index.php?topic=461612
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 04, 2012, 01:01:07 PM
Thanks for your answers. Right now I'm thinking it has to do with .htaccess and Short URLs.

As per mi initial post, I am using the latest brigde (as downloaded from https://github.com/SimpleMachines/smf-mw-auth ) and since it was released a couple of months ago, I was hoping it is compatible with the newer versions of SMF :-P

Oddly enough, my issue is exactly the same as http://www.simplemachines.org/community/index.php?topic=461612.msg3256089#msg3256089  (but I did not remove the '&' since I'm using PHP 5.2 )

Many thanks in advance.
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 04, 2012, 01:30:37 PM
OK, so I know now:

- The line causing the issue with the "Login/Register" link was this:

QuoteRewriteRule ^/*$ /w/index.php [L,QSA]

and removing it, the tab added in the menu works, and the Short URLs work more or less.

For example, this "Login/Register" link is show as [...]w/index.php?title=Especial:Entrar&returnto=Página+principal  (as said, it is in Spanish)

Now I need to figure out:

- Why the authentication is still not working. I cannot even login with the admin user and password specified during installation (maybe this is to be expected?  ??? )

- Why some links are using Short URLs correctly, while others don't  (probably can be solved with some .htaccess tweaking)

Any help appreciated
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 04, 2012, 02:30:10 PM
And more details:

The same behaviour apparently caused by the .htaccess line mentioned (clicking the "Login/Register" link takes me to the forum registration page, even though I am already logged in)  can be replicated if I enable the settings $wgSMFLogin and $wgCookieDomain

And, in that case, entering username and password said that there was an error with cookies and I could not be logged in. (that was because $wgCookieDomain was not properly set, using 'www.domain.com' instead of 'domain.com')

Still cannot make authentication to work.
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 04, 2012, 03:37:15 PM
OK, maybe a silly question, but: should I install MediaWiki in the same database than SMF? Now I have two databases, one for the forum and I've created another for the wiki.

Just occurred to me that either:

a) Both databases are not talking one to each other ??? Maybe I should have just one database with tables identified by prefix... Going to try that out now.

or

b) Cookies are not being read properly

Maybe both? Any hint? What logs should I check?

As always, any help is highly appreciated
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: Andre N on February 04, 2012, 06:22:33 PM
MediaWiki 1.18.1 and SMF 2.0.2?
Can I have a link to your site?
Or even better, a temporary ftp account? :)
I see lots of these  auth problems with MediaWiki. Would be nice to figure out what is wrong...
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 04, 2012, 06:49:08 PM
Yes, 1.18.1 and 2.0.2. Sure thing, thanks.

Right now I was about to install MediaWiki using the same database than the forum (scheduled maintenance and all that) and then try.

I will PM you the details after that (if it was not just a DB issue, which I am not sure it is...), if that's OK for you
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 04, 2012, 07:35:20 PM
And, for the record:

I have reinstalled MediaWiki, this time using the same database than the forum with tables using a different preffix.

I am trying to make it work for now, and will deal with Short URLs later. Still, authentication is not working for some reason  ???

And, even more strange: I was able to login into MediaWiki before the integration using the default user created during installation, now all I get is an "incorrect password" message  :o

Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: Andre N on February 04, 2012, 09:09:32 PM
I changed line 176 of mediawiki/extensions/Auth_SMF.php from

$smf_member_id = $user->getOption('smf_member_id');

to

$smf_member_id =  $user_settings['id_member'];


and the login integration works fine. $user doesn't have any data set up at that point and $smf_member_id is never set so the authentication fails down the line.

As for your account that always redirected you to login, it didn't work for me either; maybe when you reinstalled you forgot to create it? I made my own :D
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 04, 2012, 09:23:23 PM
Amazing, thank you very very much !

I could have never managed to solve it without your assistance. I owe you some "tapas" if you ever come to Spain  8)
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 05, 2012, 10:40:38 AM
Follow up:

The authentication works (at least, at the main page the account is detected), however:

- I had to INSERT via SQL queries the permissions for the users. SMF Administrator was successfully added as MW Administrator, but since the admin user created during the installation cannot be used to login, I had no other users in the 'bureaucrat' group. I set $wgSMFSpecialGroups at LocalSettings.php but somehow it is ignored ???

- Neither administrator nor bureaucrat nor registered users can edit pages. When I click the "save changes" button, I receive a message that edition was not successful due to loss of session data. It recommends to log off and login again, but that does not help. $wgSMFLogin and $wgCookieDomain are set, to 'true' and to 'http://www.domain.com' respectively.

So, still needs some fine tuning ???

Any idea where to look?
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 05, 2012, 11:07:58 AM
Quote from: nyall on February 05, 2012, 10:40:38 AM
- Neither administrator nor bureaucrat nor registered users can edit pages. When I click the "save changes" button, I receive a message that edition was not successful due to loss of session data. It recommends to log off and login again, but that does not help. $wgSMFLogin and $wgCookieDomain are set, to 'true' and to 'http://www.domain.com' respectively.

This is solved by setting $wgCookieDomain = 'domain.com' without any prefix such as www or http

@moderators: Still testing and configuring, please do not mark this topic as solved (unless you don't mind me changing the status if required), once I have the integration fully working I will leave it as solved by myself, in the meantime I'd like to have it open to include new comments and discoveries. In addition to that, I think the README would benefit from inclusion of details not so obvious such as the one above. Thanks!
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: ajbaldwin on February 07, 2012, 01:54:09 PM
Great thread (and I'm glad to hear that I'm not the only one that I'm struggling with this as well).

Here's some of the tracing I've done (keep in mind that I'm not a web developer - I basically know just enough PHP to be dangerous (usually to myself!). This is a cut and paste portion of an e-mail I just sent off about this:

QuoteThe ultimate issue that seems to be triggering my problems is that while
the code is able to derive $ID_MEMBER from the SMF cookie,
$smf_member_id (i.e. the double check from the database) never changes
from its default value of 0, so this bit of code runs:

// We have tried all we can, but the data just doesn't match up.
if (empty($smf_member_id) || $smf_member_id != $ID_MEMBER)
   {
      // TODO: Log errors if the ids don't match?
      if ($user->isLoggedIn())
         $user->logout();   
      return true;
   }

and thus I'm logged out (and if $wgSMFLogin is set to true, my SMF
session is killed as well). I also see the same logic running when
$wgSMFLogin isn't set:

      // No id, you must be unauthorized.
      if ($smf_member_id == 0)
         return false;

So I went hunting for smf_member_id and found it stored properly (i.e.
the value is the same as my account ID in the SMF database) as a BLOB in
the mw_user_properties table. What seems to be broken (at least right
now!) is that the getOption call to get that value never seems to
actually return the value stored in the database. The value (as far as
the bridge code is concerned) remains zero, thus the double check
continuously fails.

Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: nyall on February 07, 2012, 05:59:55 PM
@ajbaldwin, thanks for your input, hopefully we will manage to solve it somehow.

For the record, I have noticed that:

- If I access the forum first, I can login and then, when accessing the wiki, authentication is working (although I am still having an odd behavior with MediaWiki's Short URLs)

- If, on the other hand, I enter the wiki first and then I click the login link, it takes me as expected to the forum's login page. However, it is impossible to login, with the forum always complaining about cookie's settings on my browser.

It seems that:

- The cookie must be created by the forum, and the wiki can read it without problems
- The forum can't overwrite the cookie (or I have not found how)
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: Danoth on February 11, 2012, 04:47:24 PM
Here you go anyone wanting to use this :D

Go to around line 247

comment out the following


if (empty($smf_member_id) || $smf_member_id != $ID_MEMBER)
{
// TODO: Log errors if the ids don't match?
if ($user->isLoggedIn())
$user->logout();
return true;
}


It'll stop you being logged out  after everything setup. No need to use any other fixes. Keep $smf_member_id = $user->getOption('smf_member_id'); in.

EDIT: Just read above lol. Can't believe i missed that. Ah well ¬¬. Im sure we'll figure out the smf_member_id next :D
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: soloron on February 15, 2012, 09:29:17 PM
I had this working and then upgraded to Mediawiki 1.18 and SMF 2.0.2 and I ran into the same unable to login / getting redirected to the forums main page.

I got mine (mostly) working again with this fix:

QuoteI changed line 176 of mediawiki/extensions/Auth_SMF.php from
Code: [Select]

$smf_member_id = $user->getOption('smf_member_id');

to
Code: [Select]

$smf_member_id =  $user_settings['id_member'];

and the login integration works fine. $user doesn't have any data set up at that point and $smf_member_id is never set so the authentication fails down the line.

However, there were still some issues.  The new LocalSettings.php seemed to be missing some content:

Quote# NOTE: Make sure to configure the wgCookeDomain below

But the new LocalSettings file (see https:// github.com/SimpleMachines/smf-mw-auth) did not seem to contain the line that actually set the wgCookieDomain.  So I had to add that back in from my previous version of LocalSettings.

Quote# Make sure "Enable local storage of cookies" is unchecked in the
# SMF Admin -> Server Settings -> Feature Configuration section
# www . domain . org / wiki and www . domain . org / forums -> www . domain . org
# wiki . domain . org and forums . doman . org -> .domain . org
#$wgCookieDomain = 'www . domain . com';
$wgCookieDomain = 'domain . com';
#$wgCookiePath = '/'; // Optional, defaults to '/'
#$wgCookieSecure = false;  // Optional, only change on scheme mismatch

Also, if I logged in and out from the forums, all was good.

If I logged out from the logout link on the Wiki page, a cookie got set, and then I couldn't log back in at all.  Using the Login/Logout links from the Wiki didn't seem to work.  If I cleared the cookies and used just the login links from SMF, all seemed to work fine.

I borrowed code from http:// www . mediawiki . org / wiki / Extension:AutomaticREMOTE_USER#Disabling_Login_and_Logout_Links to remove the login/logout options from the Wiki page.  So, the user *has* to login/logout from the forums.  This seems to work.

(It wouldn't let me post actual links, so they are broken up with spaces.)




Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: Aleksi "Lex" Kilpinen on March 10, 2012, 05:34:00 AM
Hi nyall, any updates on this? :)
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: Andre N on March 15, 2012, 05:16:16 PM
Try this out. Back up your other one first just in case
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: ups on March 25, 2012, 05:50:37 PM
I used this script and noticed a few quirks.

On my setup, it log in, but not with User data (it would just appear the IP). This was due two things:

I noticed that $smf_member_id = $user->getOption('smf_member_id'); would always return 0 even if the Option was set to something else. This made the code to fail the authentication.
By checking the source, Mediawiki will return the option default value if the option is set to Hidden (as it is in this extension).

Also, even if everything checked out, the user data from mediawiki user would never be loaded. I added.


if ($user->getID() == 0)
{
...
}
else
{
$user->loadFromDatabase();
$user->saveToCache();
}


andre nickatina version seems a bit different and I might try it out.
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: SleePy on April 01, 2012, 03:26:18 PM
I've updated the MediaWiki auth file.  The problem was I used $wgHiddenPrefs that apparently makes getOption always return 0 for the result.  I've removed those and the auth appears to work fine.

You can download the new one from the repo: https://github.com/SimpleMachines/smf-mw-auth
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: Varsh on May 05, 2012, 02:26:03 PM
So far I've been reading through all of this quite a lot and I still unfortunately can't get this to work. So far these are the steps I've done:
Any steps I've missed or need to change? If I comment out $wgSMFLogin and $wgCookieDomain then my password isn't recognised.

Edit: Nevermind I didn't see the attachment Andre Nickatina had in his post till I posted, it works a treat. Only thing I noticed is that initially I got an error on top of the Wiki for line 873 but a forced refresh sorted that out and got rid of it. Also noticed that the only way to logout is via the forums, either way I'm happy now that it works. :)
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: pftq on May 21, 2012, 04:04:02 PM
Not sure what is different in the github version (1.14) but it wasn't letting mediawiki recognize I was logged into SMF.  Used the version Andre posted as well and it works fine here.

Edit: Tried the 1.14 version again and it's working fine now.  Just had a lot of logging in and out to get it working again.

Both versions seem to cause uncreated pages to throw 404 instead of the mediawiki message to create the page though.  Is anyone else getting this?
Title: Re: MediaWiki SMF Bridge not working - No auth, portal removed...
Post by: arthorg on June 25, 2012, 10:33:08 PM
Same as Varsh ans ptfq. The official repository version didn't work (SMF 2.0.2, MW 1.18), but the version posted by "Andre N" worked.