<?php
# Copyright (C) 2004 Brion Vibber, lcrocker, Tim Starling,
# Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu.
#
# http://www.mediawiki.org/
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or 
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# http://www.gnu.org/copyleft/gpl.html
/**
 *
 * @package MediaWiki
 * @subpackage SpecialPage
 */

/**
 *
 */
require_once('QueryPage.php');

/**
 * This class is used to get a list of new users. The ones in the 
 * last 1% of all accounts created.
 *
 * @package MediaWiki
 * @subpackage SpecialPage
 */
class NewUsersPage extends QueryPage {
	var $previousResult = null;
	var $concatGroups = '';
	
	function getName() {
		return 'Newusers';
	}
	function isSyndicated() { return false; }

	/**
	 * Make title.  Presently no other functions.
	 * @todo localize
	 */
	function getPageHeader( ) {
		global $wgScript;
		
		// Various variables used for the form
		$action = htmlspecialchars( $wgScript );

		// *** Presently stealing title from Special Listusers, needs its own name. ***
		$title = Title::makeTitle( NS_SPECIAL, 'Listusers' );

		// congratulations the form is now build
		return $out;	
	}
	
	function getSQL() {
		$dbr =& wfGetDB( DB_SLAVE );
		$user = $dbr->tableName( 'user' );
		
		$userspace = NS_USER;

		$max = $dbr->selectField('user', 'max(user_id)', false, "getSQL");
		$condition = '>' . (int)($max - $max / 100);

		$sql = "SELECT 'Listusers' as type, $userspace AS namespace, user_name AS title, " .
			"user_name as value, user_id " .
			"FROM $user ".
			"WHERE user_id $condition ".
			"ORDER BY user_id DESC ";
		
		return $sql;
	}

	// Just list names.  Probably desirable to add links to talk, contributions, etc. in future.
	function formatResult( $skin, $result ) {
		global $wgContLang;
		
		$userPage = Title::makeTitle( $result->namespace, $result->title );
		$name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
		
		return $name;
	}	
}

/**
 * constructor
 * $par string (optional) A group to list users from
 */
function wfSpecialNewusers( $par = null ) {
	global $wgRequest;

	list( $limit, $offset ) = wfCheckLimits();

	$slu = new NewUsersPage();
	
	return $slu->doQuery( $offset, $limit );
}

?>
