This patch adds an ug_expiry column to the user_groups table, a timestamp giving a date when the user group expires. A new UserGroupMembership class, based on the Block class, manages entries in this table. When the expiry date passes, the row in user_groups is ignored, and will eventually be purged from the DB when UserGroupMembership::insert is next called. Old, expired user group memberships are not kept; instead, the log entries are available to find the history of these memberships, similar to the way it has always worked for blocks and protections. Anyone getting user group info through the User object will get correct information. However, code that reads the user_groups table directly will now need to skip over rows with ug_expiry < wfTimestampNow(). See UsersPager for an example of how to do this. NULL is used to represent infinite (no) expiry, rather than a string 'infinity' or similar (except in the API). This allows existing user group assignments and log entries, which are all infinite in duration, to be treated the same as new, infinite-length memberships, without special casing everything. The whole thing is behind the temporary feature flag $wgDisableUserGroupExpiry, in accordance with the WMF schema change policy. The opportunity has been taken to refactor some static user-group-related functions out of User into UserGroupMembership, and also to add a primary key (ug_user, ug_group) to the user_groups table. There are a few breaking changes: - UserRightsProxy-like objects are now required to have a getGroupMemberships() function. - $user->mGroups (on a User object) is no longer present. - Some protected functions in UsersPager are altered or removed. - The UsersPagerDoBatchLookups hook (unused in any Wikimedia Git-hosted extension) has a change of parameter. Bug: T12493 Depends-On: Ia9616e1e35184fed9058d2d39afbe1038f56d7fa Depends-On: I86eb1d5619347ce54a5f33a591417742ebe5d6f8 Change-Id: I93c955dc7a970f78e32aa503c01c67da30971d1a
177 lines
4.6 KiB
PHP
177 lines
4.6 KiB
PHP
<?php
|
|
/**
|
|
* 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
|
|
* (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
|
|
*/
|
|
|
|
/**
|
|
* Implements Special:Activeusers
|
|
*
|
|
* @ingroup SpecialPage
|
|
*/
|
|
class SpecialActiveUsers extends SpecialPage {
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct() {
|
|
parent::__construct( 'Activeusers' );
|
|
}
|
|
|
|
/**
|
|
* Show the special page
|
|
*
|
|
* @param string $par Parameter passed to the page or null
|
|
*/
|
|
public function execute( $par ) {
|
|
$out = $this->getOutput();
|
|
|
|
$this->setHeaders();
|
|
$this->outputHeader();
|
|
|
|
$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 );
|
|
|
|
$opts->fetchValuesFromRequest( $this->getRequest() );
|
|
|
|
if ( $par !== null ) {
|
|
$opts->setValue( 'username', $par );
|
|
}
|
|
|
|
$pager = new ActiveUsersPager( $this->getContext(), $opts );
|
|
$usersBody = $pager->getBody();
|
|
|
|
$this->buildForm();
|
|
|
|
if ( $usersBody ) {
|
|
$out->addHTML(
|
|
$pager->getNavigationBar() .
|
|
Html::rawElement( 'ul', [], $usersBody ) .
|
|
$pager->getNavigationBar()
|
|
);
|
|
} else {
|
|
$out->addWikiMsg( 'activeusers-noresult' );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generate and output the form
|
|
*/
|
|
protected function buildForm() {
|
|
$groups = User::getAllGroups();
|
|
|
|
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' => [
|
|
'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 );
|
|
}
|
|
|
|
/**
|
|
* 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__
|
|
);
|
|
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() {
|
|
return 'users';
|
|
}
|
|
}
|