Wikia code/includes/specials/SpecialUserlogout.php

--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\specials\SpecialUserlogout.php	2011-07-18 22:31:17.708984400 +0100
+++ D:\Programming\SVN\wikia\trunk\includes\specials\SpecialUserlogout.php	2011-08-17 15:28:16.355468700 +0100
@@ -8,7 +8,7 @@
  * constructor
  */
 function wfSpecialUserlogout() {
-	global $wgUser, $wgOut;
+	global $wgUser, $wgOut, $wgRequest;
 
 	/**
 	 * Some satellite ISPs use broken precaching schemes that log people out straight after
@@ -29,5 +29,22 @@
 	wfRunHooks( 'UserLogoutComplete', array(&$wgUser, &$injected_html, $oldName) );
 
 	$wgOut->addHTML( wfMsgExt( 'logouttext', array( 'parse' ) ) . $injected_html );
-	$wgOut->returnToMain();
+	
+	$mReturnTo = $wgRequest->getVal( 'returnto' );		
+	$mReturnToQuery = $wgRequest->getVal( 'returntoquery' );
+		
+	$title = Title::newFromText($mReturnTo);
+	if (!empty($title))
+	{
+		$mResolvedReturnTo = strtolower(SpecialPage::resolveAlias($title->getDBKey()));
+		if(in_array($mResolvedReturnTo,array('userlogout','signup','connect')))
+		{
+			$titleObj = Title::newMainPage();
+			$mReturnTo = $titleObj->getText( );
+			$mReturnToQuery = '';
+		}			
+	}
+		
+		
+	$wgOut->returnToMain(false, $mReturnTo, $mReturnToQuery);
 }