initial checkin of the atutor mediawiki integration module
authorgreg gay <ggay@ocad.ca>
Tue, 14 Jun 2011 19:52:31 +0000 (19:52 -0000)
committergreg gay <ggay@ocad.ca>
Tue, 14 Jun 2011 19:52:31 +0000 (19:52 -0000)
23 files changed:
mods/mediawiki/MySQL_Auth/Auth_viaMySQL/Auth_viaMySQL.php [new file with mode: 0644]
mods/mediawiki/MySQL_Auth/Auth_viaMySQL/CacheTimer_viaMySQL.php [new file with mode: 0644]
mods/mediawiki/MySQL_Auth/MySQLActiveUser.php [new file with mode: 0644]
mods/mediawiki/README [new file with mode: 0644]
mods/mediawiki/index.php [new file with mode: 0644]
mods/mediawiki/index_admin.php [new file with mode: 0644]
mods/mediawiki/index_instructor.php [new file with mode: 0644]
mods/mediawiki/index_mystart.php [new file with mode: 0644]
mods/mediawiki/index_public.php [new file with mode: 0644]
mods/mediawiki/module.css [new file with mode: 0644]
mods/mediawiki/module.php [new file with mode: 0644]
mods/mediawiki/module.sql [new file with mode: 0644]
mods/mediawiki/module.xml [new file with mode: 0644]
mods/mediawiki/module_delete.php [new file with mode: 0644]
mods/mediawiki/module_install.php [new file with mode: 0644]
mods/mediawiki/module_news.php [new file with mode: 0644]
mods/mediawiki/module_uninstall.php [new file with mode: 0644]
mods/mediawiki/mw_config.php [new file with mode: 0644]
mods/mediawiki/mw_connect.php [new file with mode: 0644]
mods/mediawiki/mw_icon_sm.png [new file with mode: 0644]
mods/mediawiki/mw_logo.png [new file with mode: 0644]
mods/mediawiki/side_menu.inc.php [new file with mode: 0644]
mods/mediawiki/sublinks.php [new file with mode: 0644]

diff --git a/mods/mediawiki/MySQL_Auth/Auth_viaMySQL/Auth_viaMySQL.php b/mods/mediawiki/MySQL_Auth/Auth_viaMySQL/Auth_viaMySQL.php
new file mode 100644 (file)
index 0000000..317653c
--- /dev/null
@@ -0,0 +1,105 @@
+<?php
+/**
+ * Auth_viaMySQL MediaWiki extension MediaWiki version 1.14.0rc1
+ *
+ * @file
+ * @ingroup Extensions
+ * @version 1.0
+ * @author John Derby Russell
+ * @link http://www.mediawiki.org/w/index.php/Extension:Auth_viaMySQL
+ */
+# Not a valid entry point, skip unless MEDIAWIKI is defined
+if( !defined( 'MEDIAWIKI' ) )
+{
+        echo "Auth_viaMySQL extension";
+        die();
+}
+// Extension credits that will show up on Special:Version
+$wgExtensionCredits['other'][] = array(
+      'name' => 'MySQL Auto Authentication -> Auth_viaMySQL',
+      'version' => '1.0',
+      'author' => 'John Derby Russell',
+      'url' => 'http://www.mediawiki.org/w/index.php/Extension:Auth_viaMySQL',
+      'description' => 'Auto-authenticates users using MySQL database',
+);
+/**
+ *
+ * MySQL Login Database Integration
+ *
+ */
+require_once(MW_INSTALL_PATH.'/MySQLActiveUser.php') ;
+$wgHooks['UserLoadFromSession'][] = 'Auth_viaMySQL';
+// Kill logout url
+$wgHooks['PersonalUrls'][] = 'PersonalUrls_killLogout'; /* Disallow logout link */
+function Auth_viaMySQL( $user, $result ) {
+    global $MySQLActiveUserData;
+    $MySQLActiveUserData->distribute_cookie_data() ;
+    wfSetupSession();
+    /**
+     * A lot of this is from User::newFromName
+     */
+    // Force usernames to capital
+    global $wgContLang;
+    $name = $wgContLang->ucfirst( $MySQLActiveUserData->active_user_name );
+    // Clean up name according to title rules
+    $t = Title::newFromText( $name );
+    if( is_null( $t ) ) {
+        return(true) ;
+    }
+    $canonicalName = $t->getText();
+    if( !User::isValidUserName( $canonicalName ) ) {
+        return(true) ;
+    }
+    $user->setName( $canonicalName );
+    $user_id_fromMW_DB = $user->idFromName( $MySQLActiveUserData->active_user_name ) ;
+    $user->setId( $user_id_fromMW_DB );
+    if ( $user->getID() == 0 ) {
+        /**
+        * A lot of this is from LoginForm::initUser
+        * LoginForm in in the file called SpecialUserLogin.php line 342 (version 1.14.0rc1)
+        */
+        $canonicalName = $t->getText();
+        $user->setName( $canonicalName );
+        $user->addToDatabase();
+        $user->setEmail( $MySQLActiveUserData->active_user_email );
+        $user->setRealName( '' );
+        $user->setToken();
+        $user->saveSettings();
+    } else {
+        if ( !$user->loadFromDatabase() ) {
+            // Can't load from ID, user is anonymous
+            return(true) ;
+        }
+        $user->saveToCache();
+    }
+    $result = 1; // This causes the rest of the authentication process to be skipped.
+    return(false);   // As should this, according to the internal error report:
+}
+// Kill logout url
+function PersonalUrls_killLogout($personal_urls, $title) {
+    $personal_urls['logout'] = null ;
+    $personal_urls['login'] = null ;
+    $personal_urls['anonlogin'] = null ;
+    return true ;
+}
+?>
diff --git a/mods/mediawiki/MySQL_Auth/Auth_viaMySQL/CacheTimer_viaMySQL.php b/mods/mediawiki/MySQL_Auth/Auth_viaMySQL/CacheTimer_viaMySQL.php
new file mode 100644 (file)
index 0000000..1d4b496
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * CacheTimer_viaMySQL MediaWiki extension
+ *
+ * @file
+ * @ingroup Extensions
+ * @version 1.0
+ * @author John Derby Russell
+ * @link http://www.mediawiki.org/w/index.php/Extension:Auth_viaMySQL
+ */
+// Extension credits that will show up on Special:Version
+$wgExtensionCredits['other'][] = array(
+      'name' => 'MySQL Cache Timer',
+      'version' => '1.0',
+      'author' => 'John Derby Russell',
+      'url' => 'http://www.mediawiki.org/w/index.php/Extension:Auth_viaMySQL',
+      'description' => 'Tells Wiki when to regenerate client cache for users',
+);
+require_once(MW_INSTALL_PATH.'/MySQLActiveUser.php') ;
+/**
+ *
+ * The MySQL cache epoche timer is for when to rebuild the cache stored on the client side.
+ * This is ussually done at login.
+ *
+ */
+function CacheTimer_viaMySQL( ) {
+    global $MySQLActiveUserData ;
+    $MySQLActiveUserData->distribute_cookie_data() ;
+    return $MySQLActiveUserData->active_user_login_time ;
+}
+?>
diff --git a/mods/mediawiki/MySQL_Auth/MySQLActiveUser.php b/mods/mediawiki/MySQL_Auth/MySQLActiveUser.php
new file mode 100644 (file)
index 0000000..e3bc3e8
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+class MySQLActiveUser
+{
+    var $active_user_id ;
+    var $active_user_name ;
+    var $active_user_password;
+    var $active_user_email ;
+    var $active_user_login_time ;
+    function MySQLActiveUser()  {
+    }
+    function set_cookie($username, $user_id, $password_hash, $user_email, $login_time) {
+        setcookie("mysql_active_user",
+                  serialize(array($username, $user_id, $password_hash, $user_email, $login_time)), time()+60*60*24*100, "/") ;
+        $this->active_user_name = $username ;
+        $this->active_user_id = $user_id ;
+        $this->active_user_password = $password_hash ;
+        $this->active_user_email = $user_email ;
+        $this->active_user_login_time = $login_time ;
+    }
+    function clear_cookie() {
+        $this->active_user_name = "" ;
+        $this->active_user_id = 0 ;
+        $this->active_user_password = 0 ;
+        $this->active_user_email = "" ;
+        $this->active_user_login_time = 0 ;
+        setcookie("mysql_active_user",
+                serialize(array("", "", "", "")), time()-60*60*24*100, "/") ;
+    }
+    function distribute_cookie_data() {
+        $mysql_cookie_name = "mysql_active_user" ;
+        if (isset($_COOKIE[$mysql_cookie_name]))
+                list($this->active_user_name,
+                     $this->active_user_id,
+                     $this->active_user_password,
+                     $this->active_user_email,
+                     $this->active_user_login_time) = @unserialize($_COOKIE[$mysql_cookie_name]);
+    }
+}
+$MySQLActiveUserData = new MySQLActiveUser();
+?>
\ No newline at end of file
diff --git a/mods/mediawiki/README b/mods/mediawiki/README
new file mode 100644 (file)
index 0000000..6360c22
--- /dev/null
@@ -0,0 +1,95 @@
+## MediaWiki Integration module for ATutor
+
+####################
+
+This module allows you to manage MediaWiki as a course tool and open MediaWiki in an iframe within ATutor courses, and MyStart areas. It is a community wiki, meaning all users in all courses can access it. It also creates a single sign-on. When a user logs into ATutor, they  are automatically logged into Mediawiki.
+
+**MediaWiki needs to be installed and configured before installing this module. See the MediaWiki documentation for instructions on installing and configuring it. MediaWiki needs to be installed on the same server as ATutor, though it may be installed in its own database.
+
+http://www.mediawiki.org/wiki/Installation
+
+
+####################
+Installing the ATutor MediaWiki Module:
+
+1. Unzip the atutor_mediawiki.x.x.x.zip module file into the ATutor mods/ directory to create a "mediawiki/" directory.
+2. Login to ATutor as the admin, click on the Modules tab then click Install Modules. Mediawiki should be listed. Select it and press the Install button.
+3. Follow the installer instructions.
+4. Once the module is installed, select the Mediawiki module now listed in the available modules in the Module Manager, then press the Enable button. This inserts another main navigation tab above.
+5. Click the MediaWiki tab then enter the URL to the base directory under which Mediawiki is run (e.g. http://myserver.com/mediawiki/ , including the trailing slash), then press the Save button. MediaWiki should then appear below.
+6. Next set the database access information for MediaWiki in the mw_config.php file in the  module directory (e.g mods/mediawiki), then save the file. This information is required if you intended on using the module detailed view to display recent changes in the wiki on the course home page, or on the student tools page.
+
+
+#####################
+Authenticate MediaWiki Users from the ATutor Members table (Single Sign-on)
+
+This section is optional. If not implented, users will need to create an account on MediaWiki, and they'll need to manually login.
+
+To remove the need to setup separate accounts in MediaWiki and ATutor, you can install the Auth viaMySQL extention. This effectively creates a single sign-on between ATutor and MediaWiki based on ATutor member accounts.
+
+Extention details can be found at:
+http://www.mediawiki.org/wiki/Extension:Auth_viaMySQL
+(Just for information about the extension's origin. Instead follow the instructions below)
+
+Note that you will probably want to install this extension before you start using MediaWiki with ATutor. Otherwise you may have conflicts between ATutor users and independent Mediawiki users owbership of content. The only account that should exist before installing the extension is the admin account created during the MediaWiki installation.
+
+Copy Auth_viaMySQL.php, CacheTimer_viaMySQL.php, and  MySQLActiveUser.php from the ATutor MediaWiki module directory (mods/mediawiki/MySQL_Auth/) to the MediaWiki installation directory as follows:
+
+MediaWiki/extensions/Auth_viaMySQL/Auth_viaMySQL.php
+MediaWiki/extensions/Auth_viaMySQL/CacheTimer_viaMySQL.php
+MediaWiki/MySQLActiveUser.php
+
+(**You'll probably need to create the extensions/Auth_viaMySQL directory, and depending on how MediaWiki was installed, you may need root access to do that and to copy the files into the MediaWiki directory)
+
+After the files are copied to the MediaWiki installation directory, copy the following code and paste it immediately before the first instance of the "$msg->addFeedback('LOGIN_SUCCESS');" statement of the login.php file located in the root directory of ATutor. This sets the MediaWiki authentication cookie for student and instructor users, but not for admin users. The admin user must login manually using the "MediaWiki Login" link under the MediaWiki tab in the admin area, using the admin login information created during the MediaWiki installation.
+
+#####
+# adjust the path in the first line below to the location of your MediaWiki installation directory. 
+
+       $mediawiki_install_path = "/var/lib/mediawiki/";
+       require_once($mediawiki_install_path.'MySQLActiveUser.php');
+       global $MySQLActiveUserData ;
+       global $db ;
+
+       $userName = $_POST['login'] ;
+       $command = "SELECT * FROM ".TABLE_PREFIX."members WHERE login='".$userName."';" ;
+       $result = mysql_query($command, $db);
+       $account = mysql_fetch_assoc($result) ;
+       if ($account)
+       {
+               $current_mw_timecode = gmdate( 'YmdHis' ) ;
+               $MySQLActiveUserData->set_cookie($account['login'],
+                                                                                       $account['member_id'],
+                                                                                       $account['password'],
+                                                                                       $account['email'],
+                                                                                       $current_mw_timecode) ;
+       }
+#####
+
+Copy the following code and paste it immediately after the "require(AT_INCLUDE_PATH.'vitals.inc.php');" statement of the logout.php file located in the root directory of ATutor. This deletes the MediaWiki authentication cookie when a user logs out of ATutor.
+
+#####
+# adjust the path in the first line below to the location of your MediaWiki installation directory. 
+
+       $mediawiki_install_path = "/var/lib/mediawiki/";
+       require_once($mediawiki_install_path.'MySQLActiveUser.php');
+       global $MySQLActiveUserData ;
+       $MySQLActiveUserData->clear_cookie() ;
+
+#####
+
+Add the following lines to the end of the MediaWiki LocalSettings.php file
+
+#####
+
+       require_once($IP."/extensions/Auth_viaMySQL/Auth_viaMySQL.php");
+       require_once($IP."/extensions/Auth_viaMySQL/CacheTimer_viaMySQL.php");
+
+       $local_var_login_time = CacheTimer_viaMySQL() ;
+       $wgCacheEpoch = max( $wgCacheEpoch, $local_var_login_time ) ;
+       $wgCachePages = false ;
+
+#####
+
+
+
diff --git a/mods/mediawiki/index.php b/mods/mediawiki/index.php
new file mode 100644 (file)
index 0000000..d3581fc
--- /dev/null
@@ -0,0 +1,26 @@
+<?php\r
+define('AT_INCLUDE_PATH', '../../include/');\r
+require (AT_INCLUDE_PATH.'vitals.inc.php');\r
+$_custom_css = $_base_path . 'mods/mediawiki/module.css'; // use a custom stylesheet\r
+global $_config;\r
+require (AT_INCLUDE_PATH.'header.inc.php');\r
+\r
+if($_GET['p']){\r
+       $p = $addslashes($_GET['p']);\r
+}\r
+\r
+if(!$_COOKIE['mysql_active_user']){\r
+       echo '<a href="'.$_config['mw-url'].'index.php?title=Special:UserLogin&returnto=Special:UserLogin" target="toolframe">'._AT('mediawiki_login').'</a>';\r
+}\r
+\r
+?>\r
+\r
+<iframe src="<?php echo $_config['mw-url']; ?><?php if($p){ echo "index.php/".$p;} ?>" width="95%" height="500" style="border:none;" name="toolframe">\r
+<p><?php echo _AT('mediawiki_no_iframe',$_config['mw-url']); ?>"><?php echo _AT('mediawiki_login'); ?></a></p>\r
+</iframe>\r
+<script>\r
+window.toolframe.wgNamespaceNumber = 1;\r
+</script>\r
+\r
+<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>\r
+\r
diff --git a/mods/mediawiki/index_admin.php b/mods/mediawiki/index_admin.php
new file mode 100644 (file)
index 0000000..b2d5786
--- /dev/null
@@ -0,0 +1,48 @@
+<?php\r
+define('AT_INCLUDE_PATH', '../../include/');\r
+require (AT_INCLUDE_PATH.'vitals.inc.php');\r
+$_custom_css = $_base_path . 'mods/mediawiki/module.css'; // use a custom stylesheet\r
+admin_authenticate(AT_ADMIN_PRIV_MEDIAWIKI);\r
+\r
+$_POST['mw-url'] = $addslashes($_POST['mw-url']);\r
+\r
+if($_POST['submit']){\r
+       foreach($_POST as $key=>$mw_config)\r
+       if($key != "submit"){\r
+       $sql="REPLACE INTO ".TABLE_PREFIX."config SET name='$key', value='".$mw_config."'";\r
+       if($result= mysql_query($sql, $db)){\r
+               $msg->addFeedback("MW_CONFIG_SAVED");\r
+               $_config['mw-url'] = $_POST['mw-url'];\r
+\r
+       }else{\r
+               $msg->addError("WP_CONFIG_FAIL");\r
+       }\r
+\r
+       }\r
+}\r
+\r
+require (AT_INCLUDE_PATH.'header.inc.php');\r
+\r
+?>\r
+\r
+<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">\r
+<label for="mw-url"><?php echo _AT('mediawiki_login_url'); ?></label>\r
+<input type="text" name="mw-url" id="mw-url" value="<?php if($_config['mw-url']){echo $_config['mw-url'];}else{ echo 'http://';} ?>" size="60" /><br />\r
+\r
+<input type="submit" name="submit" value="<?php echo _AT('mediawiki_save'); ?>">\r
+</form>\r
+\r
+\r
+<?php\r
+if($_config['mw-url']){?>\r
+       <br /><br /><a href="<?php echo $_config['mw-url']; ?>index.php?title=Special:UserLogin&returnto=Special:UserLogin" target="toolframe"><?php echo _AT('mediawiki_login'); ?></a>\r
+       <iframe name="toolframe" src="<?php echo $_config['mw-url']; ?>" width="95%" height="450" id="frame_set">\r
+       <p><?php echo _AT('mediawiki_no_iframes',$_config['mw-url']); ?> ?></p>\r
+       </iframe>\r
+<?php }else{ ?>\r
+       <p><?php echo _AT('mediawiki_do_setup'); ?> ?></p>\r
+\r
+<?php } ?>\r
+\r
+\r
+<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\ No newline at end of file
diff --git a/mods/mediawiki/index_instructor.php b/mods/mediawiki/index_instructor.php
new file mode 100644 (file)
index 0000000..94aacac
--- /dev/null
@@ -0,0 +1,18 @@
+<?php\r
+define('AT_INCLUDE_PATH', '../../include/');\r
+require (AT_INCLUDE_PATH.'vitals.inc.php');\r
+authenticate(AT_PRIV_MEDIAWIKI);\r
+require (AT_INCLUDE_PATH.'header.inc.php');\r
+\r
+\r
+if(!$_COOKIE['mysql_active_user']){\r
+       echo '<a href="'.$_config['mw-url'].'index.php?title=Special:UserLogin&returnto=Special:UserLogin" target="toolframe">'._AT('mediawiki_login').'</a>';\r
+}\r
+?>\r
+\r
+<iframe src="<?php echo $_config['mw-url']; ?>" width="95%" height="450" style="border:none;" name="blog_frame">\r
+<p><?php echo _AT('mediawiki_no_iframe',$_config['mw-url']); ?>"><?php echo _AT('mediawiki_login'); ?></a></p>\r
+</iframe>\r
+\r
+\r
+<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\ No newline at end of file
diff --git a/mods/mediawiki/index_mystart.php b/mods/mediawiki/index_mystart.php
new file mode 100644 (file)
index 0000000..ee93ef8
--- /dev/null
@@ -0,0 +1,25 @@
+<?php\r
+$_user_location        = 'users';\r
+define('AT_INCLUDE_PATH', '../../include/');\r
+require (AT_INCLUDE_PATH.'vitals.inc.php');\r
+$_custom_css = $_base_path . 'mods/mediawiki/module.css'; // use a custom stylesheet\r
+require (AT_INCLUDE_PATH.'header.inc.php');\r
+\r
+\r
+if($_GET['p']){\r
+       $p = $addslashes($_GET['p']);\r
+}\r
+\r
+if(!$_COOKIE['mysql_active_user']){\r
+\r
+echo '<a href="'.$_config['mw-url'].'index.php?title=Special:UserLogin&returnto=Special:UserLogin" target="toolframe">'._AT('mediawiki_login').'</a>';\r
+\r
+}\r
+?>\r
+\r
+<iframe src="<?php echo $_config['mw-url']; ?><?php if($p){ echo "index.php/".$p;} ?>" width="95%" height="500" style="border:none;" name="toolframe">\r
+<p><?php echo _AT('mediawiki_no_iframe',$_config['mw-url']); ?>"><?php echo _AT('mediawiki_login'); ?></a></p>\r
+</iframe>\r
+\r
+\r
+<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\ No newline at end of file
diff --git a/mods/mediawiki/index_public.php b/mods/mediawiki/index_public.php
new file mode 100644 (file)
index 0000000..a7ca3d6
--- /dev/null
@@ -0,0 +1,26 @@
+<?php\r
+// This file is disabled by default. To enable it, modify the "public pages" \r
+// section in the module.php file for this module\r
+\r
+\r
+$_user_location        = 'public';\r
+\r
+define('AT_INCLUDE_PATH', '../../include/');\r
+require (AT_INCLUDE_PATH.'vitals.inc.php');\r
+$_custom_css = $_base_path . 'mods/mediawiki/module.css'; // use a custom stylesheet\r
+require (AT_INCLUDE_PATH.'header.inc.php');\r
+\r
+\r
+if(!$_COOKIE['mysql_active_user']){\r
+\r
+echo '<a href="'.$_config['mw-url'].'index.php?title=Special:UserLogin&returnto=Special:UserLogin" target="toolframe">'._AT('mediawiki_login').'</a>';\r
+\r
+}\r
+?>\r
+<iframe src="<?php echo $_config['mw-url']; ?><?php if($p){ echo "index.php/".$p;} ?>" width="95%" height="500" style="border:none;" name="toolframe">\r
+<p><?php echo _AT('mediawiki_no_iframe',$_config['mw-url']); ?>"><?php echo _AT('mediawiki_login'); ?></a></p>\r
+</iframe>\r
+\r
+\r
+\r
+<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\ No newline at end of file
diff --git a/mods/mediawiki/module.css b/mods/mediawiki/module.css
new file mode 100644 (file)
index 0000000..0d3ed71
--- /dev/null
@@ -0,0 +1,5 @@
+\r
+\r
+#frame_set{\r
+       border:none;\r
+}
\ No newline at end of file
diff --git a/mods/mediawiki/module.php b/mods/mediawiki/module.php
new file mode 100644 (file)
index 0000000..257abdf
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+/*******
+ * doesn't allow this file to be loaded with a browser.
+ */
+if (!defined('AT_INCLUDE_PATH')) { exit; }
+
+/******
+ * this file must only be included within a Module obj
+ */
+if (!isset($this) || (isset($this) && (strtolower(get_class($this)) != 'module'))) { exit(__FILE__ . ' is not a Module'); }
+
+/*******
+ * assign the instructor and admin privileges to the constants.
+ * not technically need for instructors for the current version of the module
+ */
+define('AT_PRIV_MEDIAWIKI',       $this->getPrivilege());
+define('AT_ADMIN_PRIV_MEDIAWIKI', $this->getAdminPrivilege());
+
+/*******
+ * create a side menu box/stack.
+ */
+// Sidemenu block is disbaled by default in this version of the module
+//$this->_stacks['mediawiki'] = array('title_var'=>'mediawiki', 'file'=>'mods/mediawiki/side_menu.inc.php');
+// ** possible alternative: **
+// $this->addStack('mediawiki', array('title_var' => 'mediawiki', 'file' => './side_menu.inc.php');
+
+/*******
+ * create optional sublinks for module "detail view" on course home page
+ * when this line is uncommented, "mods/mediawiki/sublinks.php" need to be created to return an array of content to be displayed
+ */
+$this->_list['mediawiki'] = array('title_var'=>'mediawiki','file'=>'mods/mediawiki/sublinks.php');
+
+// Uncomment for tiny list bullet icon for module sublinks "icon view" on course home page
+$this->_pages['mods/mediawiki/index.php']['icon']      = 'mods/mediawiki/mw_icon_sm.png';
+
+// Uncomment for big icon for module sublinks "detail view" on course home page
+//$this->_pages['mods/mediawiki/index.php']['img']      = 'mods/mediawiki/mediawiki.jpg';
+
+// ** possible alternative: **
+// the text to display on module "detail view" when sublinks are not available
+$this->_pages['mods/mediawiki/index.php']['text']      = _AT('mediawiki_text');
+
+/*******
+ * if this module is to be made available to students on the Home or Main Navigation.
+ */
+$_group_tool = $_student_tool = 'mods/mediawiki/index.php';
+
+/*******
+ * add the admin pages when needed.
+ */
+if (admin_authenticate(AT_ADMIN_PRIV_MEDIAWIKI, TRUE) || admin_authenticate(AT_ADMIN_PRIV_ADMIN, TRUE)) {
+       $this->_pages[AT_NAV_ADMIN] = array('mods/mediawiki/index_admin.php');
+       $this->_pages['mods/mediawiki/index_admin.php']['title_var'] = 'mediawiki';
+       $this->_pages['mods/mediawiki/index_admin.php']['parent']    = AT_NAV_ADMIN;
+}
+
+/*******
+ * instructor Manage section:
+ */
+$this->_pages['mods/mediawiki/index_instructor.php']['title_var'] = 'mediawiki';
+$this->_pages['mods/mediawiki/index_instructor.php']['parent']   = 'tools/index.php';
+// ** possible alternative: **
+// $this->pages['./index_instructor.php']['title_var'] = 'mediawiki';
+// $this->pages['./index_instructor.php']['parent']    = 'tools/index.php';
+
+/*******
+ * student page.
+ */
+$this->_pages['mods/mediawiki/index.php']['title_var'] = 'mediawiki';
+$this->_pages['mods/mediawiki/index.php']['img']       = 'mods/mediawiki/mw_logo.png';
+
+// /* public pages */
+// Uncomment the following three lines if MediaWiki should be accessible from public pages
+// for users who are not logged into ATutor
+
+// $this->_pages[AT_NAV_PUBLIC] = array('mods/mediawiki/index_public.php');
+// $this->_pages['mods/mediawiki/index_public.php']['title_var'] = 'mediawiki';
+// $this->_pages['mods/mediawiki/index_public.php']['parent'] = AT_NAV_PUBLIC;
+
+/* my start page pages */
+$this->_pages[AT_NAV_START]  = array('mods/mediawiki/index_mystart.php');
+$this->_pages['mods/mediawiki/index_mystart.php']['title_var'] = 'mediawiki';
+$this->_pages['mods/mediawiki/index_mystart.php']['parent'] = AT_NAV_START;
+
+function mediawiki_get_group_url($group_id) {
+       return 'mods/mediawiki/index.php';
+}
+
+?>
\ No newline at end of file
diff --git a/mods/mediawiki/module.sql b/mods/mediawiki/module.sql
new file mode 100644 (file)
index 0000000..c504ac1
--- /dev/null
@@ -0,0 +1,13 @@
+# sql file for mediawiki integration module\r
+\r
+\r
+INSERT INTO `language_text` VALUES ('en', '_module','mediawiki','MediaWiki',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','mediawiki_text','A sample mediawiki text for detailed homepage.',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','mediawiki_admin_login','Login to Administer MediaWiki',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','mediawiki_login_url','MediaWiki Base URL',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','mediawiki_login','MediaWiki Login',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','mediawiki_save','Save',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','mediawiki_no_iframes','Your browser does not support iframes. Got to <a href="'.%s.'">MediaWiki Login</a>',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','mediawiki_do_setup','Enter the URL to the MediaWiki based Web accessible directory (e.g, http://myserver.com/mediawiki/, including the trailing slash), to have MediaWiki appear here.',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_msgs','AT_FEEDBACK_MW_CONFIG_SAVED','MediaWiki configuration successfully saved',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_msgs','AT_FEEDBACK_MW_CONFIG_FAIL','MediaWiki configuration failed to save. ',NOW(),'');
\ No newline at end of file
diff --git a/mods/mediawiki/module.xml b/mods/mediawiki/module.xml
new file mode 100644 (file)
index 0000000..816adef
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="ISO-8859-1"?> \r
+<module version="1.0"> \r
+    <name lang="en">MediaWiki Integration</name> \r
+       <description lang="en">This module integrates MediaWiki with ATutor, creating a single sign-on, and making MediaWiki available as a single shared wiki used as a course tool across all courses.</description> \r
+    <maintainers>\r
+        <maintainer> \r
+            <name>ATutor Team</name> \r
+            <email>info@atutor.ca</email> \r
+        </maintainer>\r
+    </maintainers> \r
+    <url>http://atutor.ca</url> \r
+    <license>BSD</license> \r
+       <release> \r
+        <version>1.0</version> \r
+        <date>2011-06-14</date> \r
+        <state>Stable</state> \r
+        <notes> Be sure to read the README file for the module for details on setting up single sign-on. While usable without single sign-on, it needs to be setup manually. You will be required to enable the module once installed, then enter the URL to MediaWiki through the MediaWiki tab added once enabled. </notes> \r
+    </release> \r
+</module>\r
diff --git a/mods/mediawiki/module_delete.php b/mods/mediawiki/module_delete.php
new file mode 100644 (file)
index 0000000..322d3a6
--- /dev/null
@@ -0,0 +1,21 @@
+<?php\r
+/*******\r
+ * this function named [module_name]_delete is called whenever a course content is deleted\r
+ * which includes when restoring a backup with override set, or when deleting an entire course.\r
+ * the function must delete all module-specific material associated with this course.\r
+ * $course is the ID of the course to delete.\r
+ */\r
+\r
+function hello_world_delete($course) {\r
+       global $db;\r
+\r
+       // delete hello_world course table entries\r
+       $sql = "DELETE FROM ".TABLE_PREFIX."hello_world WHERE course_id=$course";\r
+       mysql_query($sql, $db);\r
+\r
+       // delete hello_world course files\r
+       $path = AT_CONTENT_DIR .'hello_world/' . $course .'/';\r
+       clr_dir($path);\r
+}\r
+\r
+?>
\ No newline at end of file
diff --git a/mods/mediawiki/module_install.php b/mods/mediawiki/module_install.php
new file mode 100644 (file)
index 0000000..9a82811
--- /dev/null
@@ -0,0 +1,67 @@
+<?php\r
+/*******\r
+ * the line below safe-guards this file from being accessed directly from\r
+ * a web browser. It will only execute if required from within an ATutor script,\r
+ * in our case the Module::install() method.\r
+ */\r
+if (!defined('AT_INCLUDE_PATH')) { exit; }\r
+\r
+/*******\r
+ * Note: the many options for these variables are used to decrease confusion.\r
+ *       TRUE | FALSE | 1 will be the convention.\r
+ *\r
+ * $_course_privilege\r
+ *     specifies the type of instructor privilege this module uses.\r
+ *     set to empty | FALSE | 0   to disable any privileges.\r
+ *     set to 1 | AT_PRIV_ADMIN   to use the instructor only privilege.\r
+ *     set to TRUE | 'new'        to create a privilege specifically for this module:\r
+ *                                will make this module available as a student privilege.\r
+ *\r
+ * $_admin_privilege\r
+ *    specifies the type of ATutor administrator privilege this module uses.\r
+ *    set to FALSE | AT_ADMIN_PRIV_ADMIN   to use the super administrator only privilege.\r
+ *    set to TRUE | 'new'                  to create a privilege specifically for this module:\r
+ *                                         will make this module available as an administrator privilege.\r
+ *\r
+ *\r
+ * $_cron_interval\r
+ *    if non-zero specifies in minutes how often the module's cron job should be run.\r
+ *    set to 0 or not set to disable.\r
+ */\r
+$_course_privilege = TRUE; // possible values: FALSE | AT_PRIV_ADMIN | TRUE\r
+$_admin_privilege  = TRUE; // possible values: FALSE | TRUE\r
+$_cron_interval    = 35; // run every 30 minutes\r
+\r
+\r
+/********\r
+ * the following code is used for creating a module-specific directory.\r
+ * it generates appropriate error messages to aid in its creation.\r
+ */\r
+$directory = AT_CONTENT_DIR .'hello_world';\r
+\r
+// check if the directory is writeable\r
+if (!is_dir($directory) && !@mkdir($directory)) {\r
+       $msg->addError(array('MODULE_INSTALL', '<li>'.$directory.' does not exist. Please create it.</li>'));\r
+} else if (!is_writable($directory) && @chmod($directory, 0666)) {\r
+       $msg->addError(array('MODULE_INSTALL', '<li>'.$directory.' is not writeable. On Unix issue the command <kbd>chmod a+rw</kbd>.</li>'));\r
+}\r
+\r
+\r
+/******\r
+ * the following code checks if there are any errors (generated previously)\r
+ * then uses the SqlUtility to run any database queries it needs, ie. to create\r
+ * its own tables.\r
+ */\r
+if (!$msg->containsErrors() && file_exists(dirname(__FILE__) . '/module.sql')) {\r
+       // deal with the SQL file:\r
+       require(AT_INCLUDE_PATH . 'classes/sqlutility.class.php');\r
+       $sqlUtility =& new SqlUtility();\r
+\r
+       /*\r
+        * the SQL file could be stored anywhere, and named anything, "module.sql" is simply\r
+        * a convention we're using.\r
+        */\r
+       $sqlUtility->queryFromFile(dirname(__FILE__) . '/module.sql', TABLE_PREFIX);\r
+}\r
+\r
+?>
\ No newline at end of file
diff --git a/mods/mediawiki/module_news.php b/mods/mediawiki/module_news.php
new file mode 100644 (file)
index 0000000..92f9eea
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/*
+* Rename the function to match the name of the module. Names of all news functions must be unique
+* across all modules installed on a system. Return a variable called $news
+*/
+require('mw_connect.php');
+               // Number of links to be displayed on "detail view" box
+function mediawiki_news() {
+       global $db_mw, $_config;
+               $link_limit = "3";
+       if($_GET['p'] == "all"){
+               $link_limit = "100";
+       }
+       $news = array();
+       $sql = "SELECT  P.page_id, P.page_title, R.rev_timestamp FROM ".MW_DB_PREFIX."page P, ".MW_DB_PREFIX."revision R WHERE R.rev_page = P.page_id ORDER BY R.rev_timestamp DESC";
+       $result = mysql_query($sql, $db_mw);
+       if($result){
+               $news_count = 0;
+               $page_ids = array();
+               while($row = mysql_fetch_assoc($result)){
+
+                       if($news_count < $link_limit && !in_array( $row['page_id'],$page_ids)){
+                               $this_time = AT_date("%Y-%m-%d %G:%i:%s", $row['rev_timestamp'],AT_DATE_MYSQL_TIMESTAMP_14);
+                               $page_ids[] = $row['page_id'];
+                               $news[] = array('time'=> $this_time, 
+                                       'alt'=>_AT('mediawiki_update'),
+                                       'thumb'=>'mods/mediawiki/mw_icon_sm.png', 
+                                       'link'=>'<a href="'.AT_BASE_HREF.url_rewrite('mods/mediawiki/index_mystart.php?p='.$row['page_title']).'"'.
+                                       (strlen($row['page_title']) > SUBLINK_TEXT_LEN ? ' title="'.$row['page_title'].'"' : '') .'>'. 
+                                       validate_length($row['page_title'], SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY) .'</a>');
+                               $news_count++;
+                       }
+               }
+       }
+       return $news;
+
+}
+?>
diff --git a/mods/mediawiki/module_uninstall.php b/mods/mediawiki/module_uninstall.php
new file mode 100644 (file)
index 0000000..9ed6969
--- /dev/null
@@ -0,0 +1,44 @@
+<?php\r
+/*******\r
+ * module_uninstall.php performs reversion of module_install.php\r
+ */\r
+\r
+/*******\r
+ * the line below safe-guards this file from being accessed directly from\r
+ * a web browser. It will only execute if required from within an ATutor script,\r
+ * in our case the Module::uninstall() method.\r
+ */\r
+if (!defined('AT_INCLUDE_PATH')) { exit; }\r
+\r
+/********\r
+ * the following code is used for removing a module-specific directory created in module_install.php.\r
+ * it generates appropriate error messages to aid in its creation.\r
+ */\r
+$directory = AT_CONTENT_DIR .'hello_world';\r
+\r
+// check if the directory exists\r
+if (is_dir($directory)) {\r
+       require(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');\r
+\r
+       if (!clr_dir($directory))\r
+               $msg->addError(array('MODULE_UNINSTALL', '<li>'.$directory.' can not be removed. Please manually remove it.</li>'));\r
+}\r
+\r
+/******\r
+ * the following code checks if there are any errors (generated previously)\r
+ * then uses the SqlUtility to run reverted database queries of module.sql, \r
+ * ie. "create table" statement in module.sql is run as drop according table.\r
+ */\r
+if (!$msg->containsErrors() && file_exists(dirname(__FILE__) . '/module.sql')) {\r
+       // deal with the SQL file:\r
+       require(AT_INCLUDE_PATH . 'classes/sqlutility.class.php');\r
+       $sqlUtility = new SqlUtility();\r
+\r
+       /*\r
+        * the SQL file could be stored anywhere, and named anything, "module.sql" is simply\r
+        * a convention we're using.\r
+        */\r
+       $sqlUtility->revertQueryFromFile(dirname(__FILE__) . '/module.sql', TABLE_PREFIX);\r
+}\r
+\r
+?>
\ No newline at end of file
diff --git a/mods/mediawiki/mw_config.php b/mods/mediawiki/mw_config.php
new file mode 100644 (file)
index 0000000..9212614
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+// MediaWiki database access information.
+// Set the values below to those needed to access your MediaWiki database
+// Mediawiki needs to be installed in the same server as ATutor
+
+define('MW_DB_USER',   'root');           # enter your mysql database user name
+define('MW_DB_PWD',    '4rft6yhu');           # enter your mysql database password
+define('MW_DB_NAME',   'wikidb');         #default "wikidb"
+define('MW_DB_PREFIX', 'mw_');            #default "mw_"
+define('MW_DB_HOST',   'localhost');      #default "localhost"
+define('MW_DB_PORT',   '3600');           #default "3600"
+
+?>
\ No newline at end of file
diff --git a/mods/mediawiki/mw_connect.php b/mods/mediawiki/mw_connect.php
new file mode 100644 (file)
index 0000000..ea367b8
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+// MediaWiki database connection setup for atutor_mediawiki integration module
+require('mw_config.php');
+global $db_mw;
+
+if (AT_INCLUDE_PATH !== 'NULL') {
+       $db_mw= @mysql_connect(MW_DB_HOST.':'.MW_DB_PORT, MW_DB_USER, MW_DB_PWD);       
+
+       if (!$db_mw) {
+               /* AT_ERROR_NO_DB_CONNECT */
+               require_once(AT_INCLUDE_PATH . 'classes/ErrorHandler/ErrorHandler.class.php');
+               $err = new ErrorHandler();
+               trigger_error('VITAL#Unable to connect to db. Set database information in the module\'s mw_config.php file.', E_USER_ERROR);
+               exit;
+       }
+       if (!@mysql_select_db(MW_DB_NAME, $db_mw)) {
+               require_once(AT_INCLUDE_PATH . 'classes/ErrorHandler/ErrorHandler.class.php');
+               $err = new ErrorHandler();
+               trigger_error('VITAL#DB connection established, but database "'.MW_DB_NAME.'" cannot be selected.',
+                                               E_USER_ERROR);
+               exit;
+       }
+
+}
+?>
\ No newline at end of file
diff --git a/mods/mediawiki/mw_icon_sm.png b/mods/mediawiki/mw_icon_sm.png
new file mode 100644 (file)
index 0000000..e78f017
Binary files /dev/null and b/mods/mediawiki/mw_icon_sm.png differ
diff --git a/mods/mediawiki/mw_logo.png b/mods/mediawiki/mw_logo.png
new file mode 100644 (file)
index 0000000..01d2d92
Binary files /dev/null and b/mods/mediawiki/mw_logo.png differ
diff --git a/mods/mediawiki/side_menu.inc.php b/mods/mediawiki/side_menu.inc.php
new file mode 100644 (file)
index 0000000..d594369
--- /dev/null
@@ -0,0 +1,15 @@
+<?php \r
+/* start output buffering: */\r
+// disabled by default in this version of the module\r
+\r
+ob_start(); ?>\r
+\r
+hello world\r
+\r
+<?php\r
+$savant->assign('dropdown_contents', ob_get_contents());\r
+ob_end_clean();\r
+\r
+$savant->assign('title', _AT('mediawiki')); // the box title\r
+$savant->display('include/box.tmpl.php');\r
+?>
\ No newline at end of file
diff --git a/mods/mediawiki/sublinks.php b/mods/mediawiki/sublinks.php
new file mode 100644 (file)
index 0000000..1010a6e
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+if (!defined('AT_INCLUDE_PATH')) { exit; }
+
+/*****
+* Free form PHP can appear here to retreive current information
+* from the module, or a text description of the module where there is
+* not current information
+*****/
+require('mw_connect.php');
+global $db_mw;
+
+$link_limit = 3;               // Number of links to be displayed on "detail view" box
+
+$sql = "SELECT P.page_title, R.rev_timestamp FROM ".MW_DB_PREFIX."page P, ".MW_DB_PREFIX."revision R ORDER BY R.rev_timestamp DESC LIMIT  $link_limit";
+
+// $sql = "SELECT hello_world_id, value FROM ".TABLE_PREFIX."hello_world WHERE course_id=".$_SESSION[course_id].
+//        " ORDER BY value LIMIT $link_limit";
+$result = mysql_query($sql, $db_mw);
+
+if (mysql_num_rows($result) > 0) {
+       while ($row = mysql_fetch_assoc($result)) {
+               /****
+               * SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY are defined in include/lib/constance.lib.inc
+               * SUBLINK_TEXT_LEN determins the maxium length of the string to be displayed on "detail view" box.
+               *****/
+               $list[] = '<a href="'.AT_BASE_HREF.url_rewrite('mods/mediawiki/index.php?p='.$row['page_title']).'"'.
+                         (strlen($row['page_title']) > SUBLINK_TEXT_LEN ? ' title="'.$row['page_title'].'"' : '') .'>'. 
+                         validate_length($row['page_title'], SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY) .'</a>';
+       }
+       return $list;   
+} else {
+       return 0;
+}
+
+?>
\ No newline at end of file