[Fusionforge-commits] r8204 - in trunk/gforge: debian packaging/dirs plugins/mediawiki/etc/httpd.d plugins/mediawiki/mediawiki-skin plugins/mediawiki/www www www/plugins

Roland Mas lolando at libremir.placard.fr.eu.org
Tue Sep 29 17:07:51 CEST 2009


Author: lolando
Date: 2009-09-29 17:07:51 +0200 (Tue, 29 Sep 2009)
New Revision: 8204

Added:
   trunk/gforge/plugins/mediawiki/www/LocalSettings.php
Removed:
   trunk/gforge/plugins/mediawiki/www/index.php
   trunk/gforge/www/plugins/mediawiki
   trunk/gforge/www/plugins/scmcvs
Modified:
   trunk/gforge/debian/changelog
   trunk/gforge/debian/rules
   trunk/gforge/packaging/dirs/plugin-mediawiki
   trunk/gforge/plugins/mediawiki/etc/httpd.d/03mediawiki
   trunk/gforge/plugins/mediawiki/mediawiki-skin/GForge.php
   trunk/gforge/www/env.inc.php
Log:
Started converting the mediawiki plugin so each project gets its own independent wiki

Modified: trunk/gforge/debian/changelog
===================================================================
--- trunk/gforge/debian/changelog	2009-09-28 12:36:35 UTC (rev 8203)
+++ trunk/gforge/debian/changelog	2009-09-29 15:07:51 UTC (rev 8204)
@@ -12,6 +12,7 @@
     up, and new plugins added: scmcpold (as a proof of concept), scmarch,
     scmbzr, scmdarcs, scmgit and scmhg.  Mercurial (scmhg) and Arch are
     not quite complete yet.
+  * Patched mediawiki plugin to enable one wiki per project.
 
  -- Roland Mas <lolando at debian.org>  Wed, 23 Sep 2009 14:44:50 +0200
 

Modified: trunk/gforge/debian/rules
===================================================================
--- trunk/gforge/debian/rules	2009-09-28 12:36:35 UTC (rev 8203)
+++ trunk/gforge/debian/rules	2009-09-29 15:07:51 UTC (rev 8204)
@@ -141,6 +141,7 @@
 	# Install few links
 	ln -s database-pgsql.php $(CURDIR)/debian/$(PACKAGE)-common/usr/share/$(PACKAGE)/common/include/database.php
 	ln -s /usr/share/mediawiki/skins/$(PACKAGE)/loader.php $(CURDIR)/debian/$(PACKAGE)-plugin-mediawiki/etc/mediawiki-extensions/extensions-available/GforgeAuth.php
+	for i in includes opensearch_desc.php redirect.php thumb.php api.php extensions img_auth.php index.php languages maintenance profileinfo.php StartProfiler.php trackback.php ; do ln -s /usr/share/mediawiki/$$i $(CURDIR)/debian/$(PACKAGE)-plugin-mediawiki/usr/share/gforge/www/plugins/mediawiki/ ; done
 
 	# Fix permissions
 	for i in $(addprefix $(CURDIR)/debian/,$(shell dh_listpackages)) ; do find $$i -type f -exec chmod 644 {} \;  ; done

Modified: trunk/gforge/packaging/dirs/plugin-mediawiki
===================================================================
--- trunk/gforge/packaging/dirs/plugin-mediawiki	2009-09-28 12:36:35 UTC (rev 8203)
+++ trunk/gforge/packaging/dirs/plugin-mediawiki	2009-09-29 15:07:51 UTC (rev 8204)
@@ -4,3 +4,4 @@
 usr/share/gforge/www/plugins/mediawiki
 usr/share/gforge/etc/httpd.d
 usr/share/mediawiki/skins
+var/lib/gforge/plugins/mediawiki/wikidata

Modified: trunk/gforge/plugins/mediawiki/etc/httpd.d/03mediawiki
===================================================================
--- trunk/gforge/plugins/mediawiki/etc/httpd.d/03mediawiki	2009-09-28 12:36:35 UTC (rev 8203)
+++ trunk/gforge/plugins/mediawiki/etc/httpd.d/03mediawiki	2009-09-29 15:07:51 UTC (rev 8204)
@@ -1,21 +1,19 @@
-Alias /mediawiki /var/lib/mediawiki
+AliasMatch ^/plugins/mediawiki/wiki/[-a-zA-Z0-9_]*/index.php /usr/share/gforge/www/plugins/mediawiki/index.php
+AliasMatch ^/plugins/mediawiki/wiki/([-a-zA-Z0-9_]*)/images/(.*) /var/lib/gforge/plugins/mediawiki/wikidata/$1/images/$2
+AliasMatch ^/plugins/mediawiki/wiki/([-a-zA-Z0-9_]*)/skins/(.*) /usr/share/mediawiki/skins/$2
 
-<Directory /var/lib/mediawiki/>
-	Options +FollowSymLinks
-	AllowOverride All
-	order allow,deny
-	allow from all
-	# Allow mediawiki to connect to gforge
-	Include /etc/gforge/httpd.secrets
-	php_admin_value include_path "/etc/gforge/custom:/etc/gforge:/usr/share/gforge:/usr/share/gforge/www/include:."
+<Directory /var/lib/gforge/plugins/mediawiki>
+        Options +FollowSymLinks
+        AllowOverride All
+        order allow,deny
+        allow from all
+        # Allow mediawiki to connect to gforge
+        Include /etc/gforge/httpd.secrets
+        php_admin_value include_path "/etc/gforge/custom:/etc/gforge:/usr/share/gforge:/usr/share/gforge/www/include:."
 </Directory>
 
 # some directories must be protected
-<Directory /var/lib/mediawiki/config>
-	Options -FollowSymLinks
-	AllowOverride None
-</Directory>
-<Directory /var/lib/mediawiki/upload>
-	Options -FollowSymLinks
-	AllowOverride None
-</Directory>
+<DirectoryMatch /var/lib/gforge/plugins/mediawiki/wikidata/[-a-zA-Z0-9_]*/upload>
+        Options -FollowSymLinks
+        AllowOverride None
+</DirectoryMatch>

Modified: trunk/gforge/plugins/mediawiki/mediawiki-skin/GForge.php
===================================================================
--- trunk/gforge/plugins/mediawiki/mediawiki-skin/GForge.php	2009-09-28 12:36:35 UTC (rev 8203)
+++ trunk/gforge/plugins/mediawiki/mediawiki-skin/GForge.php	2009-09-29 15:07:51 UTC (rev 8204)
@@ -37,9 +37,11 @@
 $GLOBALS['HTTP_USER_AGENT'] = getStringFromServer('HTTP_USER_AGENT') ;
 
 function GforgeRegisterMWHook() {
-	$GLOBALS['wgHooks']['AutoAuthenticate'][]='GforgeMWAuth';
+	$GLOBALS['wgHooks']['UserLoadFromSession'][]='GforgeMWAuth';
 }
-function GforgeMWAuth( &$user ) {
+function GforgeMWAuth( &$user, &$result ) {
+	global $fusionforgeproject ;
+
 	$cookie = getStringFromCookie ('session_ser') ;
         if ($cookie != '') {
                 $s = session_check_session_cookie ($cookie);
@@ -62,12 +64,28 @@
                 $mwu->setCookies ();
                 $mwu->saveSettings ();
 
+		$g = group_get_object_by_name ($fusionforgeproject) ;
+		$perm =& $g->getPermission($u);
+
+		$mwu->loadGroups() ;
+		$current_groups = $mwu->getGroups() ;
+		
+                if ($perm && is_object($perm) && $perm->isAdmin()) {
+                        if (!in_array ('Administrators', $current_groups)) {
+                                $mwu->addGroup ('Administrators') ;
+                        }
+                } else {
+                        if (in_array ('Administrators', $current_groups)) {
+                                $mwu->removeGroup ('Administrators') ;
+                        }
+                }
+		
                 $user = $mwu ;
-                return true ;	// Ignored by MW, but required anyway
         } else {
                 // print "Not logged in (according to gforge) ";
-                return false ;	// Ignored by MW, but required anyway
+		$user->logout ();
         }
+	return true ;
 }
 /**
  * Inherit main code from SkinTemplate, set the CSS and template filter.

Added: trunk/gforge/plugins/mediawiki/www/LocalSettings.php
===================================================================
--- trunk/gforge/plugins/mediawiki/www/LocalSettings.php	                        (rev 0)
+++ trunk/gforge/plugins/mediawiki/www/LocalSettings.php	2009-09-29 15:07:51 UTC (rev 8204)
@@ -0,0 +1,160 @@
+<?php
+
+$fusionforgeproject = 'siteadmin' ;
+$exppath = explode ('/', $_SERVER['PHP_SELF']) ;
+while (count ($exppath) >= 4) {
+        if (($exppath[0] == 'plugins') && ($exppath[1] == 'mediawiki') && ($exppath[2] == 'wiki') && ($exppath[4] == 'index.php')) {
+                $fusionforgeproject = $exppath[3] ;
+                break ;
+        } else {
+                array_shift ($exppath) ;
+        }
+}
+
+define('MW_INSTALL_PATH','/usr/share/gforge/www/plugins/mediawiki');
+$wikidata = "/var/lib/gforge/plugins/mediawiki/wikidata/$fusionforgeproject" ;
+
+if (file_exists ("$wikidata/LocalSettings.php")) {
+        require ("$wikidata/LocalSettings.php") ;
+}
+
+if( defined( 'MW_INSTALL_PATH' ) ) {
+        $IP = MW_INSTALL_PATH;
+} else {
+        $IP = dirname( __FILE__ );
+}
+
+$path = array( $IP, "$IP/includes", "$IP/languages" );
+set_include_path( implode( PATH_SEPARATOR, $path ) . PATH_SEPARATOR . get_include_path() );
+
+require_once( "$IP/includes/DefaultSettings.php" );
+
+if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
+        require_once ('/etc/gforge/local.inc') ;
+        require_once ('/usr/share/gforge/www/env.inc.php') ;
+} else {
+        require_once ('/etc/gforge/database.inc') ;
+}
+$sys_dbport = 5432;
+
+if ( $wgCommandLineMode ) {
+        if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
+                die( "This script must be run from the command line\n" );
+        }
+}
+$wgSitename         = "$system_name Wiki";
+$wgScriptPath       = "/plugins/mediawiki/wiki/$fusionforgeproject" ;
+
+$wgEmergencyContact = "webmaster at fusionforge.org";
+$wgPasswordSender = "webmaster at fusionforge.org";
+
+$wgDBtype           = "postgres";
+$wgDBserver         = $sys_dbhost ;
+$wgDBname           = $sys_dbname;
+$wgDBuser           = $sys_dbuser ;
+$wgDBpassword       = $sys_dbpasswd ;
+$wgDBadminuser           = $sys_dbuser ;
+$wgDBadminpassword       = $sys_dbpasswd ;
+$wgDBport           = $sys_dbport ;
+$wgDBmwschema       = str_replace ('-', '_', "plugin_mediawiki_$fusionforgeproject") ;
+$wgDBts2schema      = str_replace ('-', '_', "plugin_mediawiki_$fusionforgeproject") ;
+$wgMainCacheType = CACHE_NONE;
+$wgMemCachedServers = array();
+
+## To enable image uploads, make sure the 'images' directory
+## is writable, then set this to true:
+$wgEnableUploads       = true;
+$wgUploadDirectory = "$wikidata/images";
+# $wgUseImageMagick = true;
+# $wgImageMagickConvertCommand = "/usr/bin/convert";
+# $wgHashedUploadDirectory = false;
+$wgLocalInterwiki   = $wgSitename;
+$wgShowExceptionDetails = true ;
+
+$wgLanguageCode = "en";
+# $wgDefaultSkin = 'gforge';
+$wgStyleDirectory = '/usr/share/mediawiki/skins' ;
+
+require ('/etc/gforge/local.inc') ;
+require ('/usr/share/gforge/www/env.inc.php') ;
+$GLOBALS['sys_dbhost'] = $sys_dbhost ;
+$GLOBALS['sys_dbport'] = $sys_dbport ;
+$GLOBALS['sys_dbname'] = $sys_dbname ;
+$GLOBALS['sys_dbuser'] = $sys_dbuser ;
+$GLOBALS['sys_dbpasswd'] = $sys_dbpasswd ;
+$GLOBALS['sys_plugins_path'] = $sys_plugins_path ;
+$GLOBALS['sys_urlprefix'] = $sys_urlprefix ;
+$GLOBALS['sys_use_ssl'] = $sys_use_ssl ;
+$GLOBALS['sys_default_domain'] = $sys_default_domain ;
+$GLOBALS['sys_custom_path'] = $sys_custom_path ;
+$GLOBALS['gfwww'] = $gfwww ;
+$GLOBALS['gfplugins'] = $gfplugins ;
+$GLOBALS['sys_lang'] = $sys_lang ;
+require ($gfwww.'include/pre.php') ;
+$GLOBALS['sys_urlroot'] = $sys_urlroot;
+$GLOBALS['sys_session_key'] = $sys_session_key;
+$GLOBALS['sys_session_expire'] = $sys_session_expire;
+$GLOBALS['REMOTE_ADDR'] = getStringFromServer('REMOTE_ADDR') ;
+$GLOBALS['HTTP_USER_AGENT'] = getStringFromServer('HTTP_USER_AGENT') ;
+
+function GforgeMWAuth( &$user, &$result ) {
+	global $fusionforgeproject ;
+
+	$cookie = getStringFromCookie ('session_ser') ;
+        if ($cookie != '') {
+                $s = session_check_session_cookie ($cookie);
+        } else {
+                $s = false ;
+        }
+        if ($s) {
+                $u = user_get_object ($s);
+                $mwname = ucfirst($u->getUnixName ()) ;
+                $mwu = User::newFromName ($mwname);
+                if($mwu->getID() == 0) {
+                        $mwu->addToDatabase ();
+                        $mwu->setPassword (User::randomPassword());
+                        $mwu->setRealName ($u->getRealName ()) ;
+                        $mwu->setToken ();
+                } else {
+                        $mwu->loadFromDatabase ();
+                }
+                $mwu->setCookies ();
+                $mwu->saveSettings ();
+
+		$g = group_get_object_by_name ($fusionforgeproject) ;
+		$perm =& $g->getPermission($u);
+
+		$mwu->loadGroups() ;
+		$current_groups = $mwu->getGroups() ;
+		
+                if ($perm && is_object($perm) && $perm->isAdmin()) {
+                        if (!in_array ('Administrators', $current_groups)) {
+                                $mwu->addGroup ('Administrators') ;
+                        }
+                } else {
+                        if (in_array ('Administrators', $current_groups)) {
+                                $mwu->removeGroup ('Administrators') ;
+                        }
+                }
+		
+                $user = $mwu ;
+        } else {
+		$user->logout ();
+        }
+	return true ;
+}
+
+if (is_file("/etc/mediawiki-extensions/extensions.php")) {
+        include( "/etc/mediawiki-extensions/extensions.php" );
+}
+
+$GLOBALS['wgHooks']['UserLoadFromSession'][]='GforgeMWAuth';
+
+$wgGroupPermissions['*']['createaccount'] = false;
+$wgGroupPermissions['*']['edit']          = false;
+$wgGroupPermissions['*']['createpage']    = false;
+$wgGroupPermissions['*']['createtalk']    = false;
+
+$wgFavicon = '/images/icon.png' ;
+$wgBreakFrames = false ;
+ini_set ('memory_limit', '50M') ;

Deleted: trunk/gforge/plugins/mediawiki/www/index.php
===================================================================
--- trunk/gforge/plugins/mediawiki/www/index.php	2009-09-28 12:36:35 UTC (rev 8203)
+++ trunk/gforge/plugins/mediawiki/www/index.php	2009-09-29 15:07:51 UTC (rev 8204)
@@ -1,115 +0,0 @@
-<?php
-
-/*
- * MediaWiki plugin
- *
- * Daniel Perez <danielperez.arg at gmail.com>
- *
- * This is an example to watch things in action. You can obviously modify things and logic as you see fit
- */
-
-require_once('../../env.inc.php');
-require_once $gfwww.'include/pre.php';
-//require_once ('plugins/mediawiki/config.php');
-
-// the header that displays for the user portion of the plugin
-function mediawiki_Project_Header($params) {                                                                                                                                         
-	global $DOCUMENT_ROOT,$HTML,$id;                                                                            
-	$params['toptab']='mediawiki'; 
-	$params['group']=$id;
-	/*                                                                                                                                                              
-		Show horizontal links                                                                                                                                   
-	*/                                                                                                                                                              
-	site_project_header($params);														
-}
-
-// the header that displays for the project portion of the plugin
-function mediawiki_User_Header($params) {
-	global $DOCUMENT_ROOT,$HTML,$user_id;                                                                            
-	$params['toptab']='mediawiki'; 
-	$params['user']=$user_id;
-	/*                                                                                                                                                              
-	 Show horizontal links                                                                                                                                   
-	 */                                                                                                                                                              
-	site_user_header($params);    
-}
-
-
-$user = session_get_user(); // get the session user
-
-if (!$user || !is_object($user) || $user->isError() || !$user->isActive()) {
-	// exit_error("Invalid User", "Cannot Process your request for this user.");
-}
-
-$type = 'group' ;
-$id = getStringFromRequest('group_id');
-$pluginname = 'mediawiki' ;
-	
-	if (!$type) {
-		exit_error("Cannot Process your request","No TYPE specified"); // you can create items in Base.tab and customize this messages
-	} elseif (!$id) {
-		exit_error("Cannot Process your request","No ID specified");
-	} else {
-		if ($type == 'group') {
-			$group = group_get_object($id);
-			if ( !$group) {
-				exit_error("Invalid Project", "Inexistent Project");
-			}
-			if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the MediaWiki plugin active
-				exit_error("Error", "First activate the $pluginname plugin through the Project's Admin Interface");			
-			}
-			$userperm = $group->getPermission($user);//we'll check if the user belongs to the group (optional)
-			if ( !$userperm->IsMember()) {
-				// exit_error("Access Denied", "You are not a member of this project");
-			}
-			// other perms checks here...
-			mediawiki_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));    
-			// DO THE STUFF FOR THE PROJECT PART HERE
-			// echo "We are in the Project MediaWiki plugin <br>";
-			// echo "Greetings from planet " . $world; // $world comes from the config file in /etc
-
-			echo '<iframe src="'.util_make_url('/mediawiki/index.php?title='.$group->getUnixName()).'" frameborder="no" width=100% height=700></iframe>' ;
-		} elseif ($type == 'user') {
-			$realuser = user_get_object($id);// 
-			if (!($realuser) || !($realuser->usesPlugin($pluginname))) {
-				exit_error("Error", "First activate the User's $pluginname plugin through Account Manteinance Page");
-			}
-			if ( (!$user) || ($user->getID() != $id)) { // if someone else tried to access the private MediaWiki part of this user
-				exit_error("Access Denied", "You cannot access other user's personal $pluginname");
-			}
-			mediawiki_User_Header(array('title'=>'My '.$pluginname,'pagename'=>"$pluginname",'sectionvals'=>array($realuser->getUnixName())));    
-			// DO THE STUFF FOR THE USER PART HERE
-			echo "We are in the User MediaWiki plugin <br>";
-			echo "Greetings from planet " . $world; // $world comes from the config file in /etc
-		} elseif ($type == 'admin') {
-			$group = group_get_object($id);
-			if ( !$group) {
-				exit_error("Invalid Project", "Inexistent Project");
-			}
-			if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the MediaWiki plugin active
-				exit_error("Error", "First activate the $pluginname plugin through the Project's Admin Interface");			
-			}
-			$userperm = $group->getPermission($user);//we'll check if the user belongs to the group
-			if ( !$userperm->IsMember()) {
-				exit_error("Access Denied", "You are not a member of this project");
-			}
-			//only project admin can access here
-			if ( $userperm->isAdmin() ) {
-				mediawiki_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));    
-				// DO THE STUFF FOR THE PROJECT ADMINISTRATION PART HERE
-				echo "We are in the Project MediaWiki plugin <font color=\"#ff0000\">ADMINISTRATION</font> <br>";
-				echo "Greetings from planet " . $world; // $world comes from the config file in /etc
-			} else {
-				exit_error("Access Denied", "You are not a project Admin");
-			}
-		}
-	}	 
-	
-	site_project_footer(array());
-
-// Local Variables:
-// mode: php
-// c-file-style: "bsd"
-// End:
-
-?>

Modified: trunk/gforge/www/env.inc.php
===================================================================
--- trunk/gforge/www/env.inc.php	2009-09-28 12:36:35 UTC (rev 8203)
+++ trunk/gforge/www/env.inc.php	2009-09-29 15:07:51 UTC (rev 8204)
@@ -16,9 +16,9 @@
 error_reporting( E_ALL );
 
 # Attempt to set up the include path, to fix problems with relative includes
-$IP = dirname(dirname( __FILE__ )) ;
+$fusionforge_basedir = dirname(dirname( __FILE__ )) ;
 $include_path = join(PATH_SEPARATOR, 
-	array("/etc/gforge/custom", "/etc/gforge", "$IP/common", "$IP/www",	"$IP/plugins", "$IP", ".", "/usr/share/php"));
+	array("/etc/gforge/custom", "/etc/gforge", "$fusionforge_basedir/common", "$fusionforge_basedir/www",	"$fusionforge_basedir/plugins", "$fusionforge_basedir", ".", "/usr/share/php"));
 
 // By default, the include_path is changed to include path needed by Gforge.
 // If this does not work, then set defines to real path directly.
@@ -35,21 +35,21 @@
 	$gfcgfile = getenv('sys_localinc');
 	$gfconfig = dirname($gfcgfile).'/';
 } elseif (isset($_SERVER['SERVER_NAME']) && 
-	file_exists($IP.'/config/'.$_SERVER['SERVER_NAME'].'/local.inc.php')) {
-	$gfcgfile = $IP.'/config/'.$_SERVER['SERVER_NAME'].'/local.inc.php';
-	$gfconfig = $IP.'/config/'.$_SERVER['SERVER_NAME'].'/';
-} elseif (file_exists($IP.'/config/local.inc.php')) {
-	$gfcgfile = $IP.'/config/local.inc.php';
-	$gfconfig = $IP.'/config/';
+	file_exists($fusionforge_basedir.'/config/'.$_SERVER['SERVER_NAME'].'/local.inc.php')) {
+	$gfcgfile = $fusionforge_basedir.'/config/'.$_SERVER['SERVER_NAME'].'/local.inc.php';
+	$gfconfig = $fusionforge_basedir.'/config/'.$_SERVER['SERVER_NAME'].'/';
+} elseif (file_exists($fusionforge_basedir.'/config/local.inc.php')) {
+	$gfcgfile = $fusionforge_basedir.'/config/local.inc.php';
+	$gfconfig = $fusionforge_basedir.'/config/';
 } else {
 	$gfcgfile = 'local.inc';
 	$gfconfig = '';
 }
 
 if( !ini_set('include_path', $include_path ) && !set_include_path( $include_path )) {
-	$gfcommon = $IP.'/common/';
-	$gfwww = $IP.'/www/';
-	$gfplugins = $IP.'/plugins/';
+	$gfcommon = $fusionforge_basedir.'/common/';
+	$gfwww = $fusionforge_basedir.'/www/';
+	$gfplugins = $fusionforge_basedir.'/plugins/';
 } else {
 	$gfcommon = '';
 	$gfwww = '';

Deleted: trunk/gforge/www/plugins/mediawiki
===================================================================
--- trunk/gforge/www/plugins/mediawiki	2009-09-28 12:36:35 UTC (rev 8203)
+++ trunk/gforge/www/plugins/mediawiki	2009-09-29 15:07:51 UTC (rev 8204)
@@ -1 +0,0 @@
-link ../../plugins/mediawiki/www
\ No newline at end of file

Deleted: trunk/gforge/www/plugins/scmcvs
===================================================================
--- trunk/gforge/www/plugins/scmcvs	2009-09-28 12:36:35 UTC (rev 8203)
+++ trunk/gforge/www/plugins/scmcvs	2009-09-29 15:07:51 UTC (rev 8204)
@@ -1 +0,0 @@
-link ../../plugins/scmcvs/www
\ No newline at end of file




More information about the Fusionforge-commits mailing list