Update message initialiser to use Revision functions for backend-independence. No...
[lhc/web/wiklou.git] / includes / SpecialListusers.php
index 629776f..559ef6a 100644 (file)
-<?
+<?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
+ */
 
-function wfSpecialListusers()
-{
-       global $wgUser, $wgOut, $wgLang;
+/**
+ *
+ */
+require_once('QueryPage.php');
 
-       list( $limit, $offset ) = wfCheckLimits();
+/**
+ * This class is used to get a list of user. The ones with specials
+ * rights (sysop, bureaucrat, developer) will have them displayed
+ * next to their names.
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+class ListUsersPage extends QueryPage {
+       var $requestedGroup = '';
+       var $requestedUser = '';
+       var $previousResult = false;
+       var $concatGroups = '';
+       
+       function getName() {
+               return 'Listusers';
+       }
+       function isSyndicated() { return false; }
+
+       /**
+        * Show a drop down list to select a group as well as a user name
+        * search box.
+        * @todo localize
+        */
+       function getPageHeader( ) {
+               global $wgScript;
+               
+               // Various variables used for the form
+               $action = htmlspecialchars( $wgScript );
+               $title = Title::makeTitle( NS_SPECIAL, 'Listusers' );
+               $special = htmlspecialchars( $title->getPrefixedDBkey() );
+
+               // form header
+               $out = '<form method="get" action="'.$action.'">' .
+                               '<input type="hidden" name="title" value="'.$special.'" />' .
+                               'Group: <select name="group">';
+
+               // get all group names and id
+               $dbr = & wfGetDB( DB_SLAVE );
+               $group = $dbr->tableName( 'group' );
+               $sql = "SELECT group_id, group_name FROM $group;";
+               $result = $dbr->query($sql);
+               
+               // we want a default empty group
+               $out.= '<option value=""></option>';
+               
+               // build the dropdown list menu using datas from the database
+               while($agroup = $dbr->fetchObject( $result )) {
+                       $selected = ($agroup->group_id == $this->requestedGroup) ? ' selected ' : '' ;
+                       $out.= '<option value="'.$agroup->group_id.'" '.$selected.'>'.$agroup->group_name.'</option>';
+               }
+               $out .= '</select> ';
 
-       $top = wfShowingResults( $offset, $limit );
-       $wgOut->addHTML( "<p>{$top}\n" );
+               $out .= 'User: <input type="text" name="username" /> ';
 
-       $sl = wfViewPrevNext( $offset, $limit,
-         $wgLang->specialPage( "Listusers" ) );
-       $wgOut->addHTML( "<br>{$sl}\n<ol start=" . ( $offset + 1 ) . ">" );
+               // OK button, end of form.
+               $out .= '<input type="submit" /></form>';
+               // congratulations the form is now build
+               return $out;    
+       }
+       
+       function getSQL() {
+               $dbr =& wfGetDB( DB_SLAVE );
+       /* system showing possible actions for users
+               $user = $dbr->tableName( 'user' );
+               $user_rights = $dbr->tableName( 'user_rights' );
+               $userspace = Namespace::getUser();
+               return "SELECT ur_rights as type, $userspace as namespace, user_name as title, " .
+                       "user_name as value FROM $user LEFT JOIN $user_rights ON user_id = ur_user";
+       */
+       /** Show groups instead */
+               $user = $dbr->tableName( 'user' );
+               $group = $dbr->tableName( 'group' );
+               $user_groups = $dbr->tableName( 'user_groups' );
+               
+               $userspace = NS_USER;
+               $sql = "SELECT group_name as type, $userspace AS namespace, user_name AS title, user_name as value " .
+                       "FROM $user ".
+                       "LEFT JOIN $user_groups ON user_id =ug_user " .
+                       "LEFT JOIN $group ON ug_group = group_id ";
 
-       $sql = "SELECT user_name,user_rights FROM user ORDER BY " .
-         "user_name LIMIT {$offset}, {$limit}";
-       $res = wfQuery( $sql, DB_READ, "wfSpecialListusers" );
+               if($this->requestedGroup != '') {
+                       $sql .=  "WHERE group_id= '" . IntVal( $this->requestedGroup ) . "' ";
+                       if($this->requestedUser != '') {
+                               $sql .= "AND user_name = " . $dbr->addQuotes( $this->requestedUser ) . ' ';
+                       }
+               } else {
+                       if($this->requestedUser !='') {
+                               $sql .= "WHERE user_name = " . $dbr->addQuotes( $this->requestedUser ) . ' ';
+                       }       
+               }                               
+               
+               return $sql;
+       }
+       
+       /**
+        * When calling formatResult we output the previous result instead of the
+        * current one. We need an additional step to flush out the last result.
+        */
+       function tryLastResult( ) {
+               return true;
+       }
+       
+       function sortDescending() {
+               return false;
+       }
 
-       $sk = $wgUser->getSkin();
-       while ( $s = wfFetchObject( $res ) ) {
-               $n = $s->user_name;
-               $r = $s->user_rights;
+       function appendGroups($group) {
+               $this->concatGroups     .= $group.' ';  
+       }
 
-               $l = $sk->makeLink( $wgLang->getNsText(
-                 Namespace::getUser() ) . ":{$n}", $n );
+       function clearGroups() {
+               $this->concatGroups = '';       
+       }
+/*
+       var $previousResult = false;
+       var $concatGroups = '';
+*/
+       function formatResult( $skin, $result ) {
+               global $wgContLang;
+               $name = false;
 
-               if ( "" != $r ) {
-                       $link = $sk->makeKnownLink( wfMsg( "administrators" ), $r );
-                       $l .= " ({$link})";
+               if($this->previousResult->title != $result->title && $this->previousResult != false) {
+                       // Different username, give back name(group1,group2)
+                       $name = $skin->makeLink( $wgContLang->getNsText($this->previousResult->namespace) . ':' . $this->previousResult->title, $this->previousResult->title );
+                       $name .= $this->concatGroups ? '('.substr($this->concatGroups,0,-1).')' : '';
+                       $this->clearGroups();
                }
-               $wgOut->addHTML( "<li>{$l}</li>\n" );
+
+               if($result->type != '') {
+               $this->appendGroups( $skin->makeLink( wfMsgForContent( 'administrators' ), $result->type ) );
+               }                       
+
+               $this->previousResult = $result;
+               return $name;
        }
-       wfFreeResult( $res );
-       $wgOut->addHTML( "</ol><p>{$sl}\n" );
+}
+
+/**
+ * constructor
+ */
+function wfSpecialListusers() {
+       global $wgRequest;
+
+       list( $limit, $offset ) = wfCheckLimits();
+
+       $slu = new ListUsersPage();
+       
+       /**
+        * Get some parameters
+        */
+       $slu->requestedGroup = $wgRequest->getVal('group');
+       $slu->requestedUser = $wgRequest->getVal('username');
+
+       return $slu->doQuery( $offset, $limit );
 }
 
 ?>