Revert "Deprecate no longer used Skin::getCommonStylePath."
[lhc/web/wiklou.git] / includes / specials / SpecialListusers.php
index 48d6a85..75be397 100644 (file)
@@ -3,7 +3,7 @@
  * Implements Special:Listusers
  *
  * Copyright © 2004 Brion Vibber, lcrocker, Tim Starling,
- * Domas Mituzas, Ashar Voultoiz, Jens Frank, Zhengzhu,
+ * Domas Mituzas, Antoine Musso, Jens Frank, Zhengzhu,
  * 2006 Rob Church <robchur@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  */
 class UsersPager extends AlphabeticPager {
 
-       function __construct( $par=null ) {
-               global $wgRequest;
-               $parms = explode( '/', ($par = ( $par !== null ) ? $par : '' ) );
+       function __construct( IContextSource $context = null, $par = null ) {
+               if ( $context ) {
+                       $this->setContext( $context );
+               }
+
+               $request = $this->getRequest();
+               $par = ( $par !== null ) ? $par : '';
+               $parms = explode( '/', $par );
                $symsForAll = array( '*', 'user' );
                if ( $parms[0] != '' && ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) ) ) {
                        $this->requestedGroup = $par;
-                       $un = $wgRequest->getText( 'username' );
-               } else if ( count( $parms ) == 2 ) {
+                       $un = $request->getText( 'username' );
+               } elseif ( count( $parms ) == 2 ) {
                        $this->requestedGroup = $parms[0];
                        $un = $parms[1];
                } else {
-                       $this->requestedGroup = $wgRequest->getVal( 'group' );
-                       $un = ( $par != '' ) ? $par : $wgRequest->getText( 'username' );
+                       $this->requestedGroup = $request->getVal( 'group' );
+                       $un = ( $par != '' ) ? $par : $request->getText( 'username' );
                }
                if ( in_array( $this->requestedGroup, $symsForAll ) ) {
                        $this->requestedGroup = '';
                }
-               $this->editsOnly = $wgRequest->getBool( 'editsOnly' );
-               $this->creationSort = $wgRequest->getBool( 'creationSort' );
+               $this->editsOnly = $request->getBool( 'editsOnly' );
+               $this->creationSort = $request->getBool( 'creationSort' );
 
                $this->requestedUser = '';
                if ( $un != '' ) {
@@ -64,17 +69,15 @@ class UsersPager extends AlphabeticPager {
                parent::__construct();
        }
 
-
        function getIndexField() {
                return $this->creationSort ? 'user_id' : 'user_name';
        }
 
        function getQueryInfo() {
-               global $wgUser;
                $dbr = wfGetDB( DB_SLAVE );
                $conds = array();
                // Don't show hidden names
-               if( !$wgUser->isAllowed('hideuser') ) {
+               if( !$this->getUser()->isAllowed('hideuser') ) {
                        $conds[] = 'ipb_deleted IS NULL';
                }
 
@@ -123,33 +126,37 @@ class UsersPager extends AlphabeticPager {
        }
 
        function formatRow( $row ) {
-               global $wgLang;
-
                if ($row->user_id == 0) #Bug 16487
                        return '';
 
+               $userName = $row->user_name;
+
+               $ulinks = Linker::userLink( $row->user_id, $userName );
+               $ulinks .= Linker::userToolLinks( $row->user_id, $userName );
+
                $userPage = Title::makeTitle( NS_USER, $row->user_name );
                $name = Linker::link( $userPage, htmlspecialchars( $userPage->getText() ) );
 
+               $lang = $this->getLanguage();
+
                $groups_list = self::getGroups( $row->user_id );
                if( count( $groups_list ) > 0 ) {
                        $list = array();
                        foreach( $groups_list as $group )
-                               $list[] = self::buildGroupLink( $group );
-                       $groups = $wgLang->commaList( $list );
+                               $list[] = self::buildGroupLink( $group, $userName );
+                       $groups = $lang->commaList( $list );
                } else {
                        $groups = '';
                }
 
-               $item = wfSpecialList( $name, $groups );
+               $item = $lang->specialList( $ulinks, $groups );
                if( $row->ipb_deleted ) {
                        $item = "<span class=\"deleted\">$item</span>";
                }
 
                global $wgEdititis;
                if ( $wgEdititis ) {
-                       $editCount = $wgLang->formatNum( $row->edits );
-                       $edits = ' [' . wfMsgExt( 'usereditcount', array( 'parsemag', 'escape' ), $editCount ) . ']';
+                       $edits = ' [' . $this->msg( 'usereditcount' )->numParams( $row->edits )->escaped() . ']';
                } else {
                        $edits = '';
                }
@@ -157,60 +164,59 @@ class UsersPager extends AlphabeticPager {
                $created = '';
                # Some rows may be NULL
                if( $row->creation ) {
-                       $d = $wgLang->date( wfTimestamp( TS_MW, $row->creation ), true );
-                       $t = $wgLang->time( wfTimestamp( TS_MW, $row->creation ), true );
-                       $created = ' (' . wfMsg( 'usercreated', $d, $t ) . ')';
-                       $created = htmlspecialchars( $created );
+                       $user = $this->getUser();
+                       $d = $lang->userDate( $row->creation, $user );
+                       $t = $lang->userTime( $row->creation, $user );
+                       $created = $this->msg( 'usercreated', $d, $t, $row->user_name )->escaped();
+                       $created = ' ' . $this->msg( 'parentheses' )->rawParams( $created )->escaped();
                }
 
                wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
                return "<li>{$item}{$edits}{$created}</li>";
        }
 
-       function getBody() {
-               if( !$this->mQueryDone ) {
-                       $this->doQuery();
-               }
-               $this->mResult->rewind();
-               $batch = new LinkBatch;
+       function doBatchLookups() {
+               $batch = new LinkBatch();
+               # Give some pointers to make user links
                foreach ( $this->mResult as $row ) {
-                       $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
+                       $batch->add( NS_USER, $row->user_name );
+                       $batch->add( NS_USER_TALK, $row->user_name );
                }
                $batch->execute();
                $this->mResult->rewind();
-               return parent::getBody();
        }
 
        function getPageHeader( ) {
                global $wgScript;
-               $self = $this->getTitle();
+               // @todo Add a PrefixedBaseDBKey
+               list( $self ) = explode( '/', $this->getTitle()->getPrefixedDBkey() );
 
                # Form tag
                $out  = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) .
-                       Xml::fieldset( wfMsg( 'listusers' ) ) .
-                       Html::hidden( 'title', $self->getPrefixedDbKey() );
+                       Xml::fieldset( $this->msg( 'listusers' )->text() ) .
+                       Html::hidden( 'title', $self );
 
                # Username field
-               $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' .
+               $out .= Xml::label( $this->msg( 'listusersfrom' )->text(), 'offset' ) . ' ' .
                        Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
 
                # Group drop-down list
-               $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' .
+               $out .= Xml::label( $this->msg( 'group' )->text(), 'group' ) . ' ' .
                        Xml::openElement('select',  array( 'name' => 'group', 'id' => 'group' ) ) .
-                       Xml::option( wfMsg( 'group-all' ), '' );
+                       Xml::option( $this->msg( 'group-all' )->text(), '' );
                foreach( $this->getAllGroups() as $group => $groupText )
                        $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup );
                $out .= Xml::closeElement( 'select' ) . '<br />';
-               $out .= Xml::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly );
+               $out .= Xml::checkLabel( $this->msg( 'listusers-editsonly' )->text(), 'editsOnly', 'editsOnly', $this->editsOnly );
                $out .= '&#160;';
-               $out .= Xml::checkLabel( wfMsg('listusers-creationsort'), 'creationSort', 'creationSort', $this->creationSort );
+               $out .= Xml::checkLabel( $this->msg( 'listusers-creationsort' )->text(), 'creationSort', 'creationSort', $this->creationSort );
                $out .= '<br />';
 
                wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
 
                # Submit button and form bottom
                $out .= Html::hidden( 'limit', $this->mLimit );
-               $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
+               $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() );
                wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
                $out .= Xml::closeElement( 'fieldset' ) .
                        Xml::closeElement( 'form' );
@@ -253,7 +259,7 @@ class UsersPager extends AlphabeticPager {
         */
        protected static function getGroups( $uid ) {
                $user = User::newFromId( $uid );
-               $groups = array_diff( $user->getEffectiveGroups(), $user->getImplicitGroups() );
+               $groups = array_diff( $user->getEffectiveGroups(), User::getImplicitGroups() );
                return $groups;
        }
 
@@ -261,13 +267,11 @@ class UsersPager extends AlphabeticPager {
         * Format a link to a group description page
         *
         * @param $group String: group name
+        * @param $username String Username
         * @return string
         */
-       protected static function buildGroupLink( $group ) {
-               static $cache = array();
-               if( !isset( $cache[$group] ) )
-                       $cache[$group] = User::makeGroupLinkHtml( $group, htmlspecialchars( User::getGroupMember( $group ) ) );
-               return $cache[$group];
+       protected static function buildGroupLink( $group, $username ) {
+               return User::makeGroupLinkHtml( $group, htmlspecialchars( User::getGroupMember( $group, $username ) ) );
        }
 }
 
@@ -289,12 +293,10 @@ class SpecialListUsers extends SpecialPage {
         * @param $par string (optional) A group to list users from
         */
        public function execute( $par ) {
-               global $wgOut;
-
                $this->setHeaders();
                $this->outputHeader();
 
-               $up = new UsersPager( $par );
+               $up = new UsersPager( $this->getContext(), $par );
 
                # getBody() first to check, if empty
                $usersbody = $up->getBody();
@@ -305,9 +307,9 @@ class SpecialListUsers extends SpecialPage {
                        $s .= Html::rawElement( 'ul', array(), $usersbody );
                        $s .= $up->getNavigationBar();
                } else {
-                       $s .= wfMessage( 'listusers-noresult' )->parseAsBlock();
+                       $s .= $this->msg( 'listusers-noresult' )->parseAsBlock();
                }
 
-               $wgOut->addHTML( $s );
+               $this->getOutput()->addHTML( $s );
        }
 }