]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialListusers.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialListusers.php
index aa0578015fe103d2fe38518c08750e8c0dc1a700..abc0363a369ebc510a8310354a5b2c97cd293497 100644 (file)
@@ -1,27 +1,26 @@
 <?php
-
-# Copyright (C) 2004 Brion Vibber, lcrocker, Tim Starling,
-# Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu.
-#
-# © 2006 Rob Church <robchur@gmail.com>
-#
-# 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.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-# http://www.gnu.org/copyleft/gpl.html
 /**
+ * Implements Special:Listusers
+ *
+ * Copyright © 2004 Brion Vibber, lcrocker, Tim Starling,
+ * Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu,
+ * 2006 Rob Church <robchur@gmail.com>
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup SpecialPage
  */
@@ -71,10 +70,12 @@ class UsersPager extends AlphabeticPager {
        }
 
        function getQueryInfo() {
+               global $wgUser;
                $dbr = wfGetDB( DB_SLAVE );
                $conds = array();
                // Don't show hidden names
-               $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0';
+               if( !$wgUser->isAllowed('hideuser') )
+                       $conds[] = 'ipb_deleted IS NULL';
                if( $this->requestedGroup != '' ) {
                        $conds['ug_group'] = $this->requestedGroup;
                        $useIndex = '';
@@ -84,7 +85,7 @@ class UsersPager extends AlphabeticPager {
                if( $this->requestedUser != '' ) {
                        # Sorted either by account creation or name
                        if( $this->creationSort ) {
-                               $conds[] = 'user_id >= ' . User::idFromName( $this->requestedUser );
+                               $conds[] = 'user_id >= ' . intval( User::idFromName( $this->requestedUser ) );
                        } else {
                                $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser );
                        }
@@ -97,14 +98,16 @@ class UsersPager extends AlphabeticPager {
 
                $query = array(
                        'tables' => " $user $useIndex LEFT JOIN $user_groups ON user_id=ug_user
-                               LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_auto=0 ",
+                               LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_deleted=1 AND ipb_auto=0 ",
                        'fields' => array(
                                $this->creationSort ? 'MAX(user_name) AS user_name' : 'user_name',
                                $this->creationSort ? 'user_id' : 'MAX(user_id) AS user_id',
                                'MAX(user_editcount) AS edits',
                                'COUNT(ug_group) AS numgroups',
-                               'MAX(ug_group) AS singlegroup',
-                               'MIN(user_registration) AS creation'),
+                               'MAX(ug_group) AS singlegroup', // the usergroup if there is only one
+                               'MIN(user_registration) AS creation',
+                               'MAX(ipb_deleted) AS ipb_deleted' // block/hide status
+                       ),
                        'options' => array('GROUP BY' => $this->creationSort ? 'user_id' : 'user_name'),
                        'conds' => $conds
                );
@@ -116,26 +119,31 @@ class UsersPager extends AlphabeticPager {
        function formatRow( $row ) {
                global $wgLang;
 
+               if ($row->user_id == 0) #Bug 16487
+                       return '';
+
                $userPage = Title::makeTitle( NS_USER, $row->user_name );
-               $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
+               $name = $this->getSkin()->link( $userPage, htmlspecialchars( $userPage->getText() ) );
 
-               if( $row->numgroups > 1 || ( $this->requestedGroup && $row->numgroups == 1 ) ) {
+               $groups_list = self::getGroups( $row->user_id );
+               if( count( $groups_list ) > 0 ) {
                        $list = array();
-                       foreach( self::getGroups( $row->user_id ) as $group )
+                       foreach( $groups_list as $group )
                                $list[] = self::buildGroupLink( $group );
                        $groups = $wgLang->commaList( $list );
-               } elseif( $row->numgroups == 1 ) {
-                       $groups = self::buildGroupLink( $row->singlegroup );
                } else {
                        $groups = '';
                }
 
                $item = wfSpecialList( $name, $groups );
+               if( $row->ipb_deleted ) {
+                       $item = "<span class=\"deleted\">$item</span>";
+               }
 
                global $wgEdititis;
                if ( $wgEdititis ) {
                        $editCount = $wgLang->formatNum( $row->edits );
-                       $edits = ' [' . wfMsgExt( 'usereditcount', 'parsemag', $editCount ) . ']';
+                       $edits = ' [' . wfMsgExt( 'usereditcount', array( 'parsemag', 'escape' ), $editCount ) . ']';
                } else {
                        $edits = '';
                }
@@ -145,7 +153,8 @@ class UsersPager extends AlphabeticPager {
                if( $row->creation ) {
                        $d = $wgLang->date( wfTimestamp( TS_MW, $row->creation ), true );
                        $t = $wgLang->time( wfTimestamp( TS_MW, $row->creation ), true );
-                       $created = ' (' . wfMsgHtml( 'usercreated', $d, $t ) . ')';
+                       $created = ' (' . wfMsg( 'usercreated', $d, $t ) . ')';
+                       $created = htmlspecialchars( $created );
                }
 
                wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
@@ -158,7 +167,7 @@ class UsersPager extends AlphabeticPager {
                }
                $this->mResult->rewind();
                $batch = new LinkBatch;
-               while ( $row = $this->mResult->fetchObject() ) {
+               foreach ( $this->mResult as $row ) {
                        $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
                }
                $batch->execute();
@@ -167,13 +176,13 @@ class UsersPager extends AlphabeticPager {
        }
 
        function getPageHeader( ) {
-               global $wgScript, $wgRequest;
+               global $wgScript;
                $self = $this->getTitle();
 
                # Form tag
                $out  = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) .
                        Xml::fieldset( wfMsg( 'listusers' ) ) .
-                       Xml::hidden( 'title', $self->getPrefixedDbKey() );
+                       Html::hidden( 'title', $self->getPrefixedDbKey() );
 
                # Username field
                $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
@@ -185,16 +194,16 @@ class UsersPager extends AlphabeticPager {
                        Xml::option( wfMsg( 'group-all' ), '' );
                foreach( $this->getAllGroups() as $group => $groupText )
                        $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup );
-               $out .= Xml::closeElement( 'select' ) . '<br/>';
+               $out .= Xml::closeElement( 'select' ) . '<br />';
                $out .= Xml::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly );
-               $out .= '&nbsp;';
+               $out .= '&#160;';
                $out .= Xml::checkLabel( wfMsg('listusers-creationsort'), 'creationSort', 'creationSort', $this->creationSort );
-               $out .= '<br/>';
+               $out .= '<br />';
 
                wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
 
                # Submit button and form bottom
-               $out .= Xml::hidden( 'limit', $this->mLimit );
+               $out .= Html::hidden( 'limit', $this->mLimit );
                $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
                wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
                $out .= Xml::closeElement( 'fieldset' ) .
@@ -233,7 +242,7 @@ class UsersPager extends AlphabeticPager {
        /**
         * Get a list of groups the specified user belongs to
         *
-        * @param int $uid
+        * @param $uid Integer: user id
         * @return array
         */
        protected static function getGroups( $uid ) {
@@ -245,13 +254,13 @@ class UsersPager extends AlphabeticPager {
        /**
         * Format a link to a group description page
         *
-        * @param string $group
+        * @param $group String: group name
         * @return string
         */
        protected static function buildGroupLink( $group ) {
                static $cache = array();
                if( !isset( $cache[$group] ) )
-                       $cache[$group] = User::makeGroupLinkHtml( $group, User::getGroupMember( $group ) );
+                       $cache[$group] = User::makeGroupLinkHtml( $group, htmlspecialchars( User::getGroupMember( $group ) ) );
                return $cache[$group];
        }
 }
@@ -261,13 +270,13 @@ class UsersPager extends AlphabeticPager {
  * $par string (optional) A group to list users from
  */
 function wfSpecialListusers( $par = null ) {
-       global $wgRequest, $wgOut;
+       global $wgOut;
 
        $up = new UsersPager($par);
 
        # getBody() first to check, if empty
        $usersbody = $up->getBody();
-       $s = XML::openElement( 'div', array('class' => 'mw-spcontent') );
+       $s = Xml::openElement( 'div', array('class' => 'mw-spcontent') );
        $s .= $up->getPageHeader();
        if( $usersbody ) {
                $s .=   $up->getNavigationBar();
@@ -276,6 +285,6 @@ function wfSpecialListusers( $par = null ) {
        } else {
                $s .=   '<p>' . wfMsgHTML('listusers-noresult') . '</p>';
        };
-       $s .= XML::closeElement( 'div' );
+       $s .= Xml::closeElement( 'div' );
        $wgOut->addHTML( $s );
 }