X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialActiveusers.php;h=7e29be0a295468a71099ff35dd1135f2a0281e6f;hb=12601ff7d2796752404bfb331fccc41083d31f9f;hp=c697ca70379e7dc7dd801bdf46696b585a0fe63d;hpb=a303296f2730d6279a249bde77f3e0b9b42e494f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialActiveusers.php b/includes/specials/SpecialActiveusers.php index c697ca7037..e7c9423c7f 100644 --- a/includes/specials/SpecialActiveusers.php +++ b/includes/specials/SpecialActiveusers.php @@ -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 @@ -51,6 +49,9 @@ class SpecialActiveUsers extends SpecialPage { $opts = new FormOptions(); $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 ); @@ -60,32 +61,42 @@ class SpecialActiveUsers extends SpecialPage { $opts->setValue( 'username', $par ); } - // Mention the level of cache staleness... - $cacheText = ''; - $dbr = wfGetDB( DB_SLAVE, 'recentchanges' ); - $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ ); - if ( $rcMax ) { - $cTime = $dbr->selectField( 'querycache_info', - 'qci_timestamp', - [ 'qci_type' => 'activeusers' ], - __METHOD__ + $pager = new ActiveUsersPager( $this->getContext(), $opts ); + $usersBody = $pager->getBody(); + + $this->buildForm(); + + if ( $usersBody ) { + $out->addHTML( + $pager->getNavigationBar() . + Html::rawElement( 'ul', [], $usersBody ) . + $pager->getNavigationBar() ); - 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 ) { - $cacheTxt = '
' . $this->msg( 'cachedspecial-viewing-cached-ttl' ) - ->durationParams( $secondsOld ); - } + } else { + $out->addWikiMsg( 'activeusers-noresult' ); } + } - $pager = new ActiveUsersPager( $this->getContext(), $opts ); - $usersBody = $pager->getBody(); + /** + * Generate and output the form + */ + protected function buildForm() { + $groups = User::getAllGroups(); - $days = $this->getConfig()->get( 'ActiveUserDays' ); + foreach ( $groups as $group ) { + $msg = htmlspecialchars( UserGroupMembership::getGroupName( $group ) ); + $options[$msg] = $group; + } + + // Backwards-compatibility with old URLs + $req = $this->getRequest(); + $excludeDefault = []; + if ( $req->getCheck( 'hidebots' ) ) { + $excludeDefault[] = 'bot'; + } + if ( $req->getCheck( 'hidesysops' ) ) { + $excludeDefault[] = 'sysop'; + } $formDescriptor = [ 'username' => [ @@ -93,39 +104,69 @@ class SpecialActiveUsers extends SpecialPage { 'name' => 'username', 'label-message' => 'activeusers-from', ], - - 'hidebots' => [ - 'type' => 'check', - 'name' => 'hidebots', - 'label-message' => 'activeusers-hidebots', - 'default' => false, + 'groups' => [ + 'type' => 'multiselect', + 'dropdown' => true, + 'flatlist' => true, + 'name' => 'groups', + 'label-message' => 'activeusers-groups', + 'options' => $options, ], - - 'hidesysops' => [ - 'type' => 'check', - 'name' => 'hidesysops', - 'label-message' => 'activeusers-hidesysops', - 'default' => false, + 'excludegroups' => [ + 'type' => 'multiselect', + 'dropdown' => true, + 'flatlist' => true, + 'name' => 'excludegroups', + 'label-message' => 'activeusers-excludegroups', + 'options' => $options, + 'default' => $excludeDefault, ], ]; - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) - ->setIntro( $this->msg( 'activeusers-intro' )->numParams( $days ) . $cacheText ) + 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 ); + } - if ( $usersBody ) { - $out->addHTML( - $pager->getNavigationBar() . - Html::rawElement( 'ul', [], $usersBody ) . - $pager->getNavigationBar() + /** + * Return introductory message. + * @return string + */ + 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__ ); - } else { - $out->addWikiMsg( 'activeusers-noresult' ); + 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(); + } } + + return $intro; } protected function getGroupName() {