]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialActiveusers.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialActiveusers.php
index f016ab9292947fb1e5b0be0fb500e22c8f74f98f..902878781cf0f050ebd86383bedb0c59df8b4ddf 100644 (file)
@@ -2,8 +2,6 @@
 /**
  * Implements Special:Activeusers
  *
- * Copyright © 2008 Aaron Schulz
- *
  * 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
  */
 
 /**
- * This class is used to get a list of active users. The ones with specials
- * rights (sysop, bureaucrat, developer) will have them displayed
- * next to their names.
+ * Implements Special:Activeusers
  *
  * @ingroup SpecialPage
  */
-class ActiveUsersPager extends UsersPager {
-
-       function __construct( $group = null ) {
-               global $wgRequest, $wgActiveUserDays;
-               $this->RCMaxAge = $wgActiveUserDays;
-               $un = $wgRequest->getText( 'username' );
-               $this->requestedUser = '';
-               if ( $un != '' ) {
-                       $username = Title::makeTitleSafe( NS_USER, $un );
-                       if( !is_null( $username ) ) {
-                               $this->requestedUser = $username->getText();
-                       }
-               }
-
-               $this->setupOptions();
+class SpecialActiveUsers extends SpecialPage {
 
-               parent::__construct();
+       public function __construct() {
+               parent::__construct( 'Activeusers' );
        }
 
-       public function setupOptions() {
-               global $wgRequest;
-
-               $this->opts = new FormOptions();
-
-               $this->opts->add( 'hidebots', false, FormOptions::BOOL );
-               $this->opts->add( 'hidesysops', false, FormOptions::BOOL );
+       /**
+        * Show the special page
+        *
+        * @param string $par Parameter passed to the page or null
+        */
+       public function execute( $par ) {
+               $out = $this->getOutput();
 
-               $this->opts->fetchValuesFromRequest( $wgRequest );
+               $this->setHeaders();
+               $this->outputHeader();
 
-               $this->groups = array();
-               if ( $this->opts->getValue( 'hidebots' ) == 1 ) {
-                       $this->groups['bot'] = true;
-               }
-               if ( $this->opts->getValue( 'hidesysops' ) == 1 ) {
-                       $this->groups['sysop'] = true;
-               }
-       }
+               $opts = new FormOptions();
 
-       function getIndexField() {
-               return 'rc_user_text';
-       }
+               $opts->add( 'username', '' );
+               $opts->add( 'groups', [] );
+               $opts->add( 'excludegroups', [] );
+               // Backwards-compatibility with old URLs
+               $opts->add( 'hidebots', false, FormOptions::BOOL );
+               $opts->add( 'hidesysops', false, FormOptions::BOOL );
 
-       function getQueryInfo() {
-               $dbr = wfGetDB( DB_SLAVE );
-               $conds = array( 'rc_user > 0' ); // Users - no anons
-               $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
-               $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
-               $conds[] = "rc_timestamp >= '{$dbr->timestamp( wfTimestamp( TS_UNIX ) - $this->RCMaxAge*24*3600 )}'";
+               $opts->fetchValuesFromRequest( $this->getRequest() );
 
-               if( $this->requestedUser != '' ) {
-                       $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
+               if ( $par !== null ) {
+                       $opts->setValue( 'username', $par );
                }
 
-               $query = array(
-                       'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
-                       'fields' => array( 'rc_user_text AS user_name', // inheritance
-                               'rc_user_text', // for Pager
-                               'user_id',
-                               'COUNT(*) AS recentedits',
-                               'MAX(ipb_user) AS blocked'
-                       ),
-                       'options' => array(
-                               'GROUP BY' => 'rc_user_text, user_id',
-                               'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
-                       ),
-                       'join_conds' => array(
-                               'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
-                               'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
-                       ),
-                       'conds' => $conds
-               );
-               return $query;
-       }
-
-       function formatRow( $row ) {
-               global $wgLang;
-               $userName = $row->user_name;
+               $pager = new ActiveUsersPager( $this->getContext(), $opts );
+               $usersBody = $pager->getBody();
 
-               $ulinks = $this->getSkin()->userLink( $row->user_id, $userName );
-               $ulinks .= $this->getSkin()->userToolLinks( $row->user_id, $userName );
+               $this->buildForm();
 
-               $list = array();
-               foreach( self::getGroups( $row->user_id ) as $group ) {
-                       if ( isset( $this->groups[$group] ) ) {
-                               return;
-                       }
-                       $list[] = self::buildGroupLink( $group );
+               if ( $usersBody ) {
+                       $out->addHTML(
+                               $pager->getNavigationBar() .
+                               Html::rawElement( 'ul', [], $usersBody ) .
+                               $pager->getNavigationBar()
+                       );
+               } else {
+                       $out->addWikiMsg( 'activeusers-noresult' );
                }
-               $groups = $wgLang->commaList( $list );
-
-               $item = wfSpecialList( $ulinks, $groups );
-               $count = wfMsgExt( 'activeusers-count',
-                       array( 'parsemag' ),
-                       $wgLang->formatNum( $row->recentedits ),
-                       $userName,
-                       $wgLang->formatNum ( $this->RCMaxAge )
-               );
-               $blocked = $row->blocked ? ' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
-
-               return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
        }
 
-       function getPageHeader() {
-               global $wgScript;
-
-               $self = $this->getTitle();
-               $limit = $this->mLimit ? Html::hidden( 'limit', $this->mLimit ) : '';
-
-               $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
-               $out .= Xml::fieldset( wfMsg( 'activeusers' ) ) . "\n";
-               $out .= Html::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
-
-               $out .= Xml::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser ) . '<br />';# Username field
-
-               $out .= Xml::checkLabel( wfMsg('activeusers-hidebots'), 'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ) );
-
-               $out .= Xml::checkLabel( wfMsg('activeusers-hidesysops'), 'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ) ) . '<br />';
-
-               $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n";# Submit button and form bottom
-               $out .= Xml::closeElement( 'fieldset' );
-               $out .= Xml::closeElement( 'form' );
+       /**
+        * Generate and output the form
+        */
+       protected function buildForm() {
+               $groups = User::getAllGroups();
 
-               return $out;
-       }
-}
+               foreach ( $groups as $group ) {
+                       $msg = htmlspecialchars( UserGroupMembership::getGroupName( $group ) );
+                       $options[$msg] = $group;
+               }
 
-/**
- * @ingroup SpecialPage
- */
-class SpecialActiveUsers extends SpecialPage {
+               // Backwards-compatibility with old URLs
+               $req = $this->getRequest();
+               $excludeDefault = [];
+               if ( $req->getCheck( 'hidebots' ) ) {
+                       $excludeDefault[] = 'bot';
+               }
+               if ( $req->getCheck( 'hidesysops' ) ) {
+                       $excludeDefault[] = 'sysop';
+               }
 
-       /**
-        * Constructor
-        */
-       public function __construct() {
-               parent::__construct( 'Activeusers' );
+               $formDescriptor = [
+                       'username' => [
+                               'type' => 'user',
+                               'name' => 'username',
+                               'label-message' => 'activeusers-from',
+                       ],
+                       'groups' => [
+                               'type' => 'multiselect',
+                               'dropdown' => true,
+                               'flatlist' => true,
+                               'name' => 'groups',
+                               'label-message' => 'activeusers-groups',
+                               'options' => $options,
+                       ],
+                       'excludegroups' => [
+                               'type' => 'multiselect',
+                               'dropdown' => true,
+                               'flatlist' => true,
+                               'name' => 'excludegroups',
+                               'label-message' => 'activeusers-excludegroups',
+                               'options' => $options,
+                               'default' => $excludeDefault,
+                       ],
+               ];
+
+               HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
+                       // For the 'multiselect' field values to be preserved on submit
+                       ->setFormIdentifier( 'specialactiveusers' )
+                       ->setIntro( $this->getIntroText() )
+                       ->setWrapperLegendMsg( 'activeusers' )
+                       ->setSubmitTextMsg( 'activeusers-submit' )
+                       // prevent setting subpage and 'username' parameter at the same time
+                       ->setAction( $this->getPageTitle()->getLocalURL() )
+                       ->setMethod( 'get' )
+                       ->prepareForm()
+                       ->displayForm( false );
        }
 
        /**
-        * Show the special page
-        *
-        * @param $par Mixed: parameter passed to the page or null
+        * Return introductory message.
+        * @return string
         */
-       public function execute( $par ) {
-               global $wgOut, $wgLang, $wgActiveUserDays;
-
-               $this->setHeaders();
-               $this->outputHeader();
-
-               $up = new ActiveUsersPager();
-
-               # getBody() first to check, if empty
-               $usersbody = $up->getBody();
-
-               $s = Html::rawElement( 'div', array( 'class' => 'mw-activeusers-intro' ),
-                       wfMsgExt( 'activeusers-intro', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgActiveUserDays ) )
-               );
-
-               $s .= $up->getPageHeader();
-               if( $usersbody ) {
-                       $s .= $up->getNavigationBar();
-                       $s .= Html::rawElement( 'ul', array(), $usersbody );
-                       $s .= $up->getNavigationBar();
-               } else {
-                       $s .= Html::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
+       protected function getIntroText() {
+               $days = $this->getConfig()->get( 'ActiveUserDays' );
+
+               $intro = $this->msg( 'activeusers-intro' )->numParams( $days )->parse();
+
+               // Mention the level of cache staleness...
+               $dbr = wfGetDB( DB_REPLICA, 'recentchanges' );
+               $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ );
+               if ( $rcMax ) {
+                       $cTime = $dbr->selectField( 'querycache_info',
+                               'qci_timestamp',
+                               [ 'qci_type' => 'activeusers' ],
+                               __METHOD__
+                       );
+                       if ( $cTime ) {
+                               $secondsOld = wfTimestamp( TS_UNIX, $rcMax ) - wfTimestamp( TS_UNIX, $cTime );
+                       } else {
+                               $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
+                               $secondsOld = time() - wfTimestamp( TS_UNIX, $rcMin );
+                       }
+                       if ( $secondsOld > 0 ) {
+                               $intro .= $this->msg( 'cachedspecial-viewing-cached-ttl' )
+                                       ->durationParams( $secondsOld )->parseAsBlock();
+                       }
                }
 
-               $wgOut->addHTML( $s );
+               return $intro;
        }
 
+       protected function getGroupName() {
+               return 'users';
+       }
 }