Experiments with Wiki

This is a purely tech post, and so if you do not have a nerdy side, please skip.

I have had to work with Mediawiki quite a lot in recent times. As I am not very well versed with PHP or the Mediawiki software in general, I have had to depend on the Wiki community at Mediawiki Forums. Its an amazingly helpful and quick forum and you would get you answers pretty quick. Just one advice. Try out your changes on a local setup.

This post is a listing of the problems I have faced and how to tweak your way around it.

1. Installation problem

I was using 1and1 shared hosting to host the wiki. Also, I was first emulating all steps on a XAMPP installation on my system. I was able to install Mediawiki on XAMPP, but the installation failed on the 1and1 account. Google then came to resuce. I saw that many more were facing this problem. You would have to rename the config folder to config2 (or anything else you want), change permissions to 777. Then run http://www.youdomain.com/config2/index.php and take it forward from there. Also, you might need to create a .htaccess file with the following line:

AddType x-mapp-php5 .php

2. Restricted user access

Due to some security concerns, I had to restrict the access to the wiki. Here is the what you need to do to disallow any unregistered user from accessing the wiki. Add the lines below to your wiki.

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

3. Redirect to login page

After you block unregistered users above, mediawiki takes you to an error page instead of the login page. To go directly to the login page make the following pages. Add 2 entries in Localsettings.php

$wgUseAlternateLandingPage = true;
$wgAlternateLandingPage = "Special:Userlogin";

Also, make the following changes to index.php

CODE BEFORE
# Query string fields
$action = $wgRequest->getVal( 'action', 'view' );
$title = $wgRequest->getVal( 'title' ); // This is the line that is changed
$wgTitle = $mediaWiki->checkInitialQueries( $title,$action,$wgOut, $wgRequest, $wgContLang );
if ($wgTitle == NULL) {
unset( $wgTitle );
}

CODE AFTER
$action = $wgRequest->getVal( 'action', 'view' );
$title = ( $wgUseAlternateLandingPage && ($wgUser->getID() == 0 ) ) ? Title::newFromText($wgAlternateLandingPage) : $wgRequest->getVal( 'title' ); //This is the line that is changed
$wgTitle = $mediaWiki->checkInitialQueries( $title,$action,$wgOut, $wgRequest, $wgContLang );
if ($wgTitle == NULL) {
unset( $wgTitle );
}

4. Redirect after login

For a reason that still eludes me, Wiki redirects to a stupid intermediate page instead of the page itself. To implement this make the following changes in SpecialUserLogin.php.

Before:

function successfulLogin( $msg, $auto = true ) {
global $wgUser;
global $wgOut;

# Run any hooks; ignore results

wfRunHooks('UserLoginComplete', array(&$wgUser));

$wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
$wgOut->setArticleRelated( false );
$wgOut->addWikiText( $msg );
if ( !empty( $this->mReturnTo ) ) {
$wgOut->returnToMain( $auto, $this->mReturnTo );
} else {
$wgOut->returnToMain( $auto );
}
}

After:

function successfulLogin( $msg, $auto = true ) {
global $wgUser;
global $wgOut;

# Run any hooks; ignore results

wfRunHooks('UserLoginComplete', array(&$wgUser));

$wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
$wgOut->setArticleRelated( false );
$wgOut->addWikiText( $msg );
if ( !empty( $this->mReturnTo ) ) {
$wgOut->returnToMain( $auto, $this->mReturnTo );
} else {
$wgOut->returnToMain( $auto );
}
//
header('Location: ./index.php?title=' . $this->mReturnTo);
}

Also, incidentally this the first post from home. More regular updates expected.


Posted

in

by

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.