[Fusionforge-commits] FusionForge branch master updated. v6.0.3-175-g2d78252

Franck Villaume nerville at libremir.placard.fr.eu.org
Sun Oct 25 18:01:09 CET 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, master has been updated
       via  2d7825278d55318cb5e39d2a76503f8f467efdbf (commit)
       via  81da26a8863c514df3680430b86e1aa9fe7fb3ca (commit)
      from  2b2a644982287e13b06147c54112e1134181a236 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=2d7825278d55318cb5e39d2a76503f8f467efdbf

commit 2d7825278d55318cb5e39d2a76503f8f467efdbf
Author: Franck Villaume <franck.villaume at trivialdev.com>
Date:   Sun Oct 25 18:00:29 2015 +0100

    use FusionForge instance rather than new object. save memory

diff --git a/src/www/admin/index.php b/src/www/admin/index.php
index 9223350..70e9a26 100644
--- a/src/www/admin/index.php
+++ b/src/www/admin/index.php
@@ -43,7 +43,7 @@ $abc_array = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','
 echo html_ao('div', array('class' => 'info-box'));
 echo html_e('h2', array(), _('User Maintenance'));
 $lielements = array();
-$forge = new FusionForge();
+$forge = FusionForge::getInstance();
 $lielements[] = array('content' => sprintf(_('Active site users: <strong>%d</strong>'), $forge->getNumberOfActiveUsers()));
 $lielements[] = array('content' => util_make_link('/admin/userlist.php', _('Display Full User List/Edit Users')));
 $localcontent = _('Display Users Beginning with')._(': ');
diff --git a/src/www/include/Layout.class.php b/src/www/include/Layout.class.php
index 0467d1b..84d0312 100644
--- a/src/www/include/Layout.class.php
+++ b/src/www/include/Layout.class.php
@@ -397,7 +397,7 @@ class Layout extends Error {
 		 * Forge-Identification Meta Header, Version 1.0
 		 * cf. http://home.gna.org/forgeplucker/forge-identification.html
 		 */
-		$ff = new FusionForge();
+		$ff = FusionForge::getInstance();
 		echo html_e('meta', array('name' => 'Forge-Identification', 'content' => $ff->software_name.':'.$ff->software_version));
 	}
 
diff --git a/src/www/include/features_boxes.php b/src/www/include/features_boxes.php
index b2ccbf6..de72971 100644
--- a/src/www/include/features_boxes.php
+++ b/src/www/include/features_boxes.php
@@ -57,7 +57,7 @@ function show_features_boxes() {
 	$return .= $HTML->boxMiddle(_('Recently Registered Projects'), 'Recently_Registered_Projects');
 	$return .= show_newest_projects();
 	$return .= $HTML->boxMiddle(_('System Information'), 'System_Information');
-	$ff = new FusionForge();
+	$ff = FusionForge::getInstance();
 	$return .= sprintf(_('%s is running %s version %s'),
 			   forge_get_config ('forge_name'),
 			   $ff->software_name,
@@ -136,7 +136,7 @@ function stats_downloads_total() {
 }
 
 function show_sitestats() {
-	$fforge = new FusionForge();
+	$fforge = FusionForge::getInstance();
 	$return = '<p>';
 
 	$count_type = forge_get_config('sitestats_projects_count');
diff --git a/src/www/index_std.php b/src/www/index_std.php
index 373a1f2..7c1889b 100644
--- a/src/www/index_std.php
+++ b/src/www/index_std.php
@@ -159,7 +159,7 @@ echo show_features_boxes();
 
 <div id="ft">
 <?php
-		$forge = new FusionForge();
+		$forge = FusionForge::getInstance();
 		printf (_('This site is running %1$s version %2$s'),
 			$forge->software_name,
 			$forge->software_version) ;

https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=81da26a8863c514df3680430b86e1aa9fe7fb3ca

commit 81da26a8863c514df3680430b86e1aa9fe7fb3ca
Author: Franck Villaume <franck.villaume at trivialdev.com>
Date:   Sun Oct 25 17:59:13 2015 +0100

    implement [#799]: site admin userlist.php page: add a paging system to help on large FusionForge instance

diff --git a/src/CHANGES b/src/CHANGES
index e281877..2bcaf18 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -1,5 +1,6 @@
 FusionForge 6.X:
 * Spellcheck (Anders Jonsson)
+* Site Admin: add paging system in userlist page [#799] (TrivialDev)
 * Docman: limit number of returned documents on search query [#794] (TrivialDev)
 * Docman: limit search using from & to dates [#798] (TrivialDev)
 * Plugin AuthBuiltin: add captcha after 3 attempts with the same login [#795] (TrivialDev)
diff --git a/src/common/include/FusionForge.class.php b/src/common/include/FusionForge.class.php
index 96e5d37..75aed03 100644
--- a/src/common/include/FusionForge.class.php
+++ b/src/common/include/FusionForge.class.php
@@ -28,10 +28,12 @@ class FusionForge extends Error {
 	var $software_name = "FusionForge" ;
 	var $software_version ;
 
+	public static $instance;
+
 	/**
 	 *	FusionForge - FusionForge object constructor
 	 */
-	function FusionForge() {
+	function __construct() {
 		$this->Error();
 
 		$pkg = dirname(dirname(__FILE__)).'/pkginfo.inc.php';
@@ -45,14 +47,22 @@ class FusionForge extends Error {
 			$this->software_version = trim(file_get_contents(dirname(__FILE__).'/../../VERSION'));
 		}
 
+		self::$instance = $this;
 		return true;
 	}
 
+	public static function getInstance() {
+		if (self::$instance === null) {
+			self::$instance = new self();
+		}
+		return self::$instance;
+	}
+
 	/**
 	 * List full number of hosted projects, public and private
 	 */
 	function getNumberOfActiveProjects() {
-		$res = db_query_params ('SELECT count(*) FROM groups WHERE status=$1',
+		$res = db_query_params ('SELECT count(*) as count FROM groups WHERE status=$1',
 					array ('A'));
 		if (!$res) {
 			$this->setError('Unable to get hosted project count: '.db_error());
@@ -62,8 +72,34 @@ class FusionForge extends Error {
 	}
 
 	function getNumberOfActiveUsers() {
-		$res = db_query_params ('SELECT count(*) AS count FROM users WHERE status=$1 and user_id != 100',
-					array ('A'));
+		return $this->getNumberOfUsers('A');
+	}
+
+	function getNumberOfDeletedUsers() {
+		return $this->getNumberOfUsers('D');
+	}
+
+	function getNumberOfSuspendedUsers() {
+		return $this->getNumberOfUsers('S');
+	}
+
+	function getNumberOfUsersUsingAPlugin($plugin_name) {
+		$res = db_query_params ('SELECT count(u.user_id) AS count FROM plugins p, user_plugin up, users u WHERE p.plugin_name = $1 and up.user_id = u.user_id and p.plugin_id = up.plugin_id and users.user_id != 100',
+					array($plugin_name));
+		if (!$res || db_numrows($res) < 1) {
+			$this->setError('Unable to get user count: '.db_error());
+			return false;
+		}
+		return $this->parseCount($res);
+	}
+
+	function getNumberOfUsers($status) {
+		$qpa = db_construct_qpa();
+		$qpa = db_construct_qpa($qpa, 'SELECT count(*) AS count FROM users WHERE user_id != 100');
+		if ($status) {
+			$qpa = db_construct_qpa($qpa, ' and status = $1', array($status));
+		}
+		$res = db_query_qpa($qpa);
 		if (!$res || db_numrows($res) < 1) {
 			$this->setError('Unable to get user count: '.db_error());
 			return false;
diff --git a/src/common/include/User.class.php b/src/common/include/User.class.php
index cd203e7..eebe58c 100644
--- a/src/common/include/User.class.php
+++ b/src/common/include/User.class.php
@@ -5,7 +5,7 @@
  * Copyright 1999-2001, VA Linux Systems, Inc.
  * Copyright 2009-2010, Roland Mas
  * Copyright 2011, Franck Villaume - Capgemini
- * Copyright 2012-2014, Franck Villaume - TrivialDev
+ * Copyright 2012-2015, Franck Villaume - TrivialDev
  * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
  * http://fusionforge.org
  *
@@ -1731,6 +1731,64 @@ Email: %3$s
 	}
 }
 
+
+class UserComparator {
+	var $criterion = 'name';
+
+	function Compare($a, $b) {
+		switch ($this->criterion) {
+			case 'name':
+			case 'realname':
+			default:
+				$name_compare = strcoll($a->getRealName(), $b->getRealName());
+				if ($name_compare != 0) {
+					return $name_compare;
+				}
+				/* If several users share a same real name */
+				return strcoll($a->getUnixName(), $b->getUnixName());
+				break;
+			case 'unixname':
+			case 'user_name':
+				return strcmp($a->getUnixName(), $b->getUnixName());
+				break;
+			case 'user_id':
+			case 'id':
+				$aid = $a->getID();
+				$bid = $b->getID();
+				if ($aid == $bid) {
+					return 0;
+				}
+				return ($aid < $bid)? -1 : 1;
+				break;
+			case 'lastname':
+				return strcmp($a->getLastName(), $b->getLastName());
+				break;
+			case 'firstname':
+				return strcmp($a->getFirstName(), $b->getFirstName());
+				break;
+			case 'status':
+				return strcmp($a->getStatus(), $b->getStatus());
+				break;
+			case 'add_date':
+				$a_add_date = $a->getAddDate();
+				$b_add_date = $b->getAddDate();
+				if ($a_add_date == $b_add_date) {
+					return 0;
+				}
+				return ($a_add_date < $b_add_date)? -1 : 1;
+				break;
+		}
+	}
+}
+
+function sortUserList(&$list, $criterion = 'name') {
+	$cmp = new UserComparator ();
+	$cmp->criterion = $criterion;
+
+	return usort($list, array($cmp, 'Compare'));
+}
+
+
 /*
 
 		EVERYTHING BELOW HERE IS DEPRECATED
@@ -1789,42 +1847,6 @@ function user_getname($user_id = false) {
 	}
 }
 
-class UserComparator {
-	var $criterion = 'name';
-
-	function Compare($a, $b) {
-		switch ($this->criterion) {
-			case 'name':
-			default:
-				$name_compare = strcoll($a->getRealName(), $b->getRealName());
-				if ($name_compare != 0) {
-					return $name_compare;
-				}
-				/* If several projects share a same real name */
-				return strcoll($a->getUnixName(), $b->getUnixName());
-				break;
-			case 'unixname':
-				return strcmp($a->getUnixName(), $b->getUnixName());
-				break;
-			case 'id':
-				$aid = $a->getID();
-				$bid = $b->getID();
-				if ($a == $b) {
-					return 0;
-				}
-				return ($a < $b)? -1 : 1;
-				break;
-		}
-	}
-}
-
-function sortUserList(&$list, $criterion = 'name') {
-	$cmp = new UserComparator ();
-	$cmp->criterion = $criterion;
-
-	return usort($list, array($cmp, 'Compare'));
-}
-
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"
diff --git a/src/www/admin/userlist.php b/src/www/admin/userlist.php
index 3d7a0da..b80efdf 100644
--- a/src/www/admin/userlist.php
+++ b/src/www/admin/userlist.php
@@ -3,7 +3,7 @@
  *
  * Copyright 1999-2000 (c) The SourceForge Crew
  * Copyright 2010 (c) Franck Villaume - Capgemini
- * Copyright 2013-2014, Franck Villaume - TrivialDev
+ * Copyright 2013-2015, Franck Villaume - TrivialDev
  * http://fusionforge.org
  *
  * This file is part of FusionForge. FusionForge is free software;
@@ -24,6 +24,7 @@
 
 require_once '../env.inc.php';
 require_once $gfcommon.'include/pre.php';
+require_once $gfcommon.'include/UserManager.class.php';
 require_once $gfwww.'admin/admin_utils.php';
 
 // user must be forge admin to proceed
@@ -63,7 +64,7 @@ function performAction($newStatus, $statusString, $user_id) {
 	$feedback = sprintf(_('User updated to %s status'), $statusString);
 }
 
-function show_users_list($users, $filter = '', $sortorder = 'realname') {
+function show_users_list($users, $filter = '', $sortorder = 'realname', $offset, $rows, $paging, $totalUsers) {
 	global $HTML;
 	echo '<p>' ._('Status')._(': ').
 		util_make_link('/admin/userlist.php', _('All')). '
@@ -99,12 +100,19 @@ function show_users_list($users, $filter = '', $sortorder = 'realname') {
 
 	echo $HTML->listTableTop($headers, $headerLinks);
 
-	$res = db_query_params('SELECT * FROM users WHERE user_id = ANY ($1) ORDER BY '.$sortorder,
-					array(db_int_array_to_any_clause($users)));
-	$count = 0;
-	while ($arr = db_fetch_array($res)) {
+	printf('<p>' . _('Displaying results %1$s out of %2$d total.'),$rows ? ($offset + 1).'-'.($offset + $rows) : '0', $totalUsers);
+
+	echo $HTML->openForm(array('action' => '/admin/userlist.php?offset='.$offset, 'method' => 'post'));
+	printf(' ' . _('Displaying %2$s results.') . "\n\t<input " .
+			'type="submit" name="setpaging" value="%1$s" />' .
+			"\n</p>\n", _('Change'),
+			html_build_select_box_from_array(array(
+			'10', '25', '50', '100', '1000'), 'nres', $paging, 1));
+	echo $HTML->closeForm();
+
+	foreach ($users as $key => $uid) {
 		$cells = array();
-		$u = new GFUser($arr['user_id'], $arr);
+		$u = user_get_object($uid);
 		$nextcell = $u->getRealName().' ('.$u->getUnixName().')';
 		if ($u->getStatus() == 'P') {
 			$nextcell = '*'.$nextcell;
@@ -148,10 +156,65 @@ function show_users_list($users, $filter = '', $sortorder = 'realname') {
 		}
 		$cells[] = array($nextcell, 'width' => '15%', 'class' => 'align-center');
 		$cells[] = array(util_make_link('/admin/passedit.php?user_id='.$u->getID().$filter,_('Change Password')), 'width' => '12%', 'class' => 'align-center');
-		echo $HTML->multiTableRow(array('class' => $HTML->boxGetAltRowStyle($count, true)), $cells);
-		$count ++;
+		echo $HTML->multiTableRow(array('class' => $HTML->boxGetAltRowStyle($key, true)), $cells);
 	}
 	echo $HTML->listTableBottom();
+
+	/*
+	 Show extra rows for <-- Prev / Next -->
+	*/
+	if ($offset > 0) {
+		echo util_make_link('/admin/userlist.php?offset='.($offset-$paging),'<strong>ā† '._('previous').'</strong>');
+		echo '  ';
+	}
+	$pages = $totalUsers / $paging;
+	$currentpage = intval($offset / $paging);
+	if ($pages > 1) {
+		$skipped_pages=false;
+		for ($j=0; $j<$pages; $j++) {
+			if ($pages > 20) {
+				if ((($j > 4) && ($j < ($currentpage-5))) || (($j > ($currentpage+5)) && ($j < ($pages-5)))) {
+					if (!$skipped_pages) {
+						$skipped_pages=true;
+						echo ".... ";
+					}
+					continue;
+				} else {
+					$skipped_pages=false;
+				}
+			}
+			if ($j * $paging == $offset) {
+				echo '<strong>'.($j+1).'</strong>  ';
+			} else {
+				echo util_make_link('/admin/userlist.php?offset='.($j*$paging),'<strong>'.($j+1).'</strong>').'  ';
+			}
+		}
+	}
+	if ( $totalUsers > $offset + $paging) {
+		echo util_make_link('/admin/userlist.php?offset='.($offset+$paging),'<strong>'._('next').' ā†’</strong>');
+	} else {
+		echo ' ';
+	}
+
+}
+
+
+global $HTML;
+
+$paging = 0;
+$u = UserManager::instance()->getCurrentUser();
+if (getStringFromRequest('setpaging')) {
+	/* store paging preferences */
+	$paging = getIntFromRequest('nres');
+	if (!$paging) {
+		$paging = 25;
+	}
+	$u->setPreference('paging', $paging);
+} else {
+	$paging = $u->getPreference('paging');
+}
+if (!$paging) {
+	$paging = 25;
 }
 
 // Administrative functions
@@ -161,6 +224,12 @@ $action = getStringFromRequest('action');
 $user_id = getIntFromRequest('user_id');
 $status = getStringFromRequest('status');
 $usingplugin = getStringFromRequest('usingplugin');
+$offset = getIntFromRequest('offset');
+
+if ($offset < 0) {
+	$offset = 0 ;
+}
+$max_rows = getIntFromRequest('max_rows');
 
 if ($action=='delete') {
 	performAction('D', "DELETED", $user_id);
@@ -174,26 +243,34 @@ $HTML->header(array('title'=>_('User List')));
 
 //	Show list of users
 if ($usingplugin) {
-	echo "<p>"._('Users that use plugin'). " <strong>".$usingplugin."</strong></p>\n";
-	$res = db_query_params('SELECT u.user_id FROM plugins p, user_plugin up, users u WHERE p.plugin_name = $1 and up.user_id = u.user_id and p.plugin_id = up.plugin_id', array($usingplugin));
-	show_users_list(user_get_objects(util_result_column_to_array($res, 0)));
+	echo html_e('h2', array(), _('Users that use plugin').' '.$usingplugin);
+	$res = db_query_params('SELECT u.user_id FROM plugins p, user_plugin up, users u WHERE p.plugin_name = $1 and up.user_id = u.user_id and p.plugin_id = up.plugin_id and users.user_id != 100 ORDER BY users.realname LIMIT $2 OFFSET $3',
+				array($usingplugin, $paging, $offset));
+	$rows = db_numrows($res);
+	$totalUsers = FusionForge::getInstance()->getNumberOfUsersUsingAPlugin($usingplugin);
+	show_users_list(util_result_column_to_array($res, 0), '', 'realname', $offset, $rows, $paging, $totalUsers);
 
 } elseif (!$group_id) {
 	$user_name_search = getStringFromRequest('user_name_search');
+	$sort_order = getStringFromRequest('sortorder', 'realname');
+	util_ensure_value_in_set($sort_order,
+				array('realname','user_name','lastname','firstname','user_id','status','add_date'));
 
 	if ($user_name_search) {
-		$res = db_query_params('SELECT user_id FROM users WHERE lower(user_name) LIKE $1 OR lower(lastname) LIKE $1',
-					array(strtolower("$user_name_search%")));
-		$list_id = util_result_column_to_array($res,0);
+		$res = db_query_params('SELECT user_id FROM users WHERE lower(user_name) LIKE $1 OR lower(lastname) LIKE $1 and users.user_id != 100 ORDER BY '.$sort_order.' LIMIT $2 OFFSET $3',
+					array(strtolower("$user_name_search%"), $paging, $offset));
+		$rows = db_numrows($res);
+		$list_id = util_result_column_to_array($res, 0);
 		$msg = sprintf(_('User list beginning with ā€œ%sā€ for all projects'), $user_name_search);
 	} else {
 		$msg = _('User list for all projects');
 	}
-	print "<p><strong>$msg</strong></p>\n";
+	echo html_e('h2', array(), $msg);
 
 	if ($status) {
-		$res = db_query_params ('SELECT user_id FROM users WHERE status = $1',
-					   array ($status));
+		$res = db_query_params('SELECT user_id FROM users WHERE status = $1 and users.user_id != 100 ORDER BY '.$sort_order.' LIMIT $2 OFFSET $3',
+					   array($status, $paging, $offset));
+		$rows = db_numrows($res);
 		if (isset($list_id)) {
 			$list_id = array_merge($list_id, util_result_column_to_array($res, 0));
 		}
@@ -202,37 +279,42 @@ if ($usingplugin) {
 		}
 	}
 	if (! isset($list_id)) {
-		$res = db_query_params('SELECT user_id FROM users',
-				array());
+		$res = db_query_params('SELECT user_id FROM users where users.user_id != 100 ORDER BY '.$sort_order.' LIMIT $1 OFFSET $2',
+				array($paging, $offset));
 		$list_id = util_result_column_to_array($res, 0);
+		$rows = db_numrows($res);
 	}
 	$filter='';
 	if (in_array($status,array('D','A','S','P'))) {
 		$filter = '&status='.$status;
 	}
-	$sort_order = getStringFromRequest('sortorder', 'realname');
-	util_ensure_value_in_set($sort_order,
-				array('realname','user_name','lastname','firstname','user_id','status','add_date'));
-	show_users_list($list_id, $filter, $sort_order);
+	$totalUsers = FusionForge::getInstance()->getNumberOfUsers($filter);
+
+	show_users_list($list_id, $filter, $sort_order, $offset, $rows, $paging, $totalUsers);
 } else {
 	/*
 		Show list for one project
 	*/
 	$project = group_get_object($group_id);
-	print "<p>" ._('User list for project: ') . "<strong>" . $project->getPublicName() . "</strong></p>";
+	echo html_e('h2', array(), _('User list for project')._(': ').$project->getPublicName());
 	$users = $project->getUsers();
+	$totalUsers = count($users);
 	if ($users) {
-		foreach ($project->getUsers() as $user) {
-			$users_id[] = $user->getID();
-		}
-		$filter = '&group_id='.$group_id;
 		$sort_order = getStringFromRequest('sortorder', 'realname');
 		util_ensure_value_in_set($sort_order,
 					array('realname','user_name','lastname','firstname','user_id','status','add_date'));
-		show_users_list($users_id, $filter, $sort_order);
+		sortUserList($users, $sort_order);
+		$users_paged = array_slice($users, $offset, $paging);
+		unset($users);
+		foreach ($users_paged as $key => $user) {
+			$users_id[] = $user->getID();
+		}
+		$filter = '&group_id='.$group_id;
+
+		show_users_list($users_id, $filter, $sort_order, $offset, $rows, $paging, $totalUsers);
 	}
 	else {
-		echo '<p>'._('No user in this project').'</p>';
+		echo $HTML->information(_('No user in this project'));
 	}
 }
 

-----------------------------------------------------------------------

Summary of changes:
 src/CHANGES                              |   1 +
 src/common/include/FusionForge.class.php |  44 +++++++++-
 src/common/include/User.class.php        |  96 +++++++++++++--------
 src/www/admin/index.php                  |   2 +-
 src/www/admin/userlist.php               | 144 ++++++++++++++++++++++++-------
 src/www/include/Layout.class.php         |   2 +-
 src/www/include/features_boxes.php       |   4 +-
 src/www/index_std.php                    |   2 +-
 8 files changed, 218 insertions(+), 77 deletions(-)


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list