? mediawik_db_config.patch
? mediawiki_db_config.patch
Index: mediawikiauth.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mediawikiauth/mediawikiauth.module,v
retrieving revision 1.4
diff -u -p -r1.4 mediawikiauth.module
--- mediawikiauth.module	1 Apr 2009 21:07:16 -0000	1.4
+++ mediawikiauth.module	1 Oct 2010 10:42:43 -0000
@@ -53,29 +53,132 @@ global $wgAuthDrupal_security_key, $wgAu
  *   $GLOBALS['wgAuthDrupal_wiki_settings'
  */
 
-foreach( $GLOBALS['wgAuthDrupal_wiki_settings'] as $key => $vals) {
 
-	if ( $vals['wgDBprefix'] ) {
-		$GLOBALS['wgAuthDrupal_wiki_settings'][$key]['wgCookiePrefix'] =
-			$vals['wgDBname'] . '_' . $vals['wgDBprefix'];
-	}
-	elseif ( $vals['wgSharedDB'] ) {
-		// This is not supported yet--haven't researched it--Maarten.
-		// XXX should throw an error into watchdog log?
-		$GLOBALS['wgAuthDrupal_wiki_settings'][$key]['wgCookiePrefix'] =
-			$vals['wgSharedDB'];
-	}
-	else {
-		$GLOBALS['wgAuthDrupal_wiki_settings'][$key]['wgCookiePrefix'] =
-			$vals['wgDBname'];
-	}
+function mediawikiauth_menu() {
+    $items = array();
+    $items['admin/settings/mediawikiauth'] = array(
+    'title' => 'Media Wiki Auth',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('mediawikiauth_admin_settings_form'),
+    'access arguments' => array('administer mediawikiauth'),
+    'type' => MENU_NORMAL_ITEM,
+    );
+    return $items;
+
+}
+
+function mediawikiauth_perm(){
+    return array('administer mediawikiauth');
+}
+
+function mediawikiauth_admin_settings_form() {
+    $form = array();
+
+    $form['mediawiki_security_key'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Security String'),
+        '#default_value' => variable_get('mediawiki_security_key', 'ReplaceThisString'),
+        '#description' => t("Replace this key string with something non-trivial to prevent
+user login spoofing.<br /> Make it hard to guess, as if it is a password.<br />
+  
+YOU MUST CHANGE THIS to something unique to your site."),
+    );
+
+
+
+
+    $wikicount = variable_get('mediawiki_wikicount', 1) > 0 ? variable_get('mediawiki_wikicount', 1) : 1;
+
+
+    for ($i=1; $i<=$wikicount; $i++) {
+        $form["mediawiki_settings_$i"] = array(
+        '#type' => 'fieldset',
+        '#title' => "Wiki $i",
+        '#descriptions' => 'settings should match those in wiki/LocalSettings.php',
+        );
+
+      $form["mediawiki_settings_$i"]["mediawiki_dbname_$i"] = array(
+            '#title'         => 'Database Name',
+            '#type'          => 'textfield',
+            '#required'      => TRUE,
+            '#default_value' => variable_get("mediawiki_dbname_$i", ''),
+            '#description'   => 'wgDBname ',
+        );
+        
+        $form["mediawiki_settings_$i"]["mediawiki_dbprefix_$i"] = array(
+            '#title'   => 'Database Prefix',
+            '#type'    => 'textfield',
+            '#default_value' => variable_get("mediawiki_dbprefix_$i", ''),
+            '#description'   => 'wgDBprefix',
+        );
+        
+        $form["mediawiki_settings_$i"]["mediawiki_cookiedomain_$i"] = array(
+            '#title'   => 'Cookie Domain',
+            '#type'    => 'textfield',
+            '#default_value' => variable_get("mediawiki_cookiedomain_$i", $_SERVER['HTTP_HOST']),
+            '#description'   => 'wgCookieDomain',
+        );
+
+        $form["mediawiki_settings_$i"]["mediawiki_cookiepath_$i"] = array(
+            '#title'   => 'Cookie Path',
+            '#type'    => 'textfield',
+            '#default_value' => variable_get("mediawiki_cookiepath_$i", '/'),
+            '#description'   => 'wgCookiePath - IF you set wgCookiePath in wiki/LocalSettings, set it to the same thing here; if don\'t see it in wiki/LocalSettings.php, leave it alone.',
+        );
+
+
+
+
+
+    }
+
+    $form['mediawikiscount'] = array(
+      '#title' => 'Multiple wikis',
+      '#type' => 'fieldset',
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+    );
+    $form['mediawikiscount']['mediawiki_wikicount'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Number of wikis'),
+        '#default_value' => variable_get('mediawiki_wikicount', 1),
+        '#description' => t("If you want to manage more than one wiki connection, enter the number, submit this form and a suitable number of connection settings will be dispalyed."),
+    );
+
+    return system_settings_form($form);
+
 }
 
+/**
+* Load config from database to global variables.
+*/
+function mediawikiauth_load_config() {
+    global $wgAuthDrupal_security_key, $wgAuthDrupal_wiki_settings;
+    $wgAuthDrupal_security_key = variable_get('mediawiki_security_key', 'ReplaceThisString');
+    $wgAuthDrupal_wiki_settings = array();
+    
+    $wikicount = variable_get('mediawiki_wikicount', 1);
+    if ($wikicount <= 0) {
+        $wikicount = 1;
+    }
+
+    for ($i=1; $i<=$wikicount; $i++)
+    {
+        $wgAuthDrupal_wiki_settings[] = array(
+                      'wgCookieDomain' => variable_get("mediawiki_cookiedomain_$i", $_SERVER['HTTP_HOST']),
+                      'wgCookiePath'   => variable_get("mediawiki_cookiepath_$i", '/'),
+           // cookie prefix can be set seperately in wiki LocalSettings 
+         	          'wgCookiePrefix' => variable_get("mediawiki_dbname_$i", '') . variable_get("mediawiki_dbprefix_$i", '') ,
+        );
+        
+    }
+
+
 // this lifted from wiki/include/DefaultSettings.php
 $proto = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
 $GLOBALS['wgCookieSecure'] = ($proto == 'https');
 
-
+}
 
 function mediawikiauth_StaticUserLogout() {
   require_once('AuthDrupalEncode.php');
@@ -93,6 +196,7 @@ function mediawikiauth_user($op, &$edit,
 	 
   switch ($op) {
     case 'login':
+        mediawikiauth_load_config();
 		// create seperate session id so mediawiki can see the user!
 		$exp = time() + 2592000; // one month in seconds
 		$encoded_name = authdrupal_encode($user->name); 
@@ -108,6 +212,7 @@ function mediawikiauth_user($op, &$edit,
       break;
 
     case 'logout':
+        mediawikiauth_load_config();
 		foreach( $GLOBALS['wgAuthDrupal_wiki_settings'] as $vals) {
 			// delete the cookie that communicates the username
 			setcookie("DRXtrArgs", "", time() - 3600, $vals['wgCookiePath'], $vals['wgCookieDomain']);
