MediaWiki REL1_31
SpecialActiveusers.php
Go to the documentation of this file.
1<?php
30
31 public function __construct() {
32 parent::__construct( 'Activeusers' );
33 }
34
40 public function execute( $par ) {
41 $out = $this->getOutput();
42
43 $this->setHeaders();
44 $this->outputHeader();
45
46 $opts = new FormOptions();
47
48 $opts->add( 'username', '' );
49 $opts->add( 'groups', [] );
50 $opts->add( 'excludegroups', [] );
51 // Backwards-compatibility with old URLs
52 $opts->add( 'hidebots', false, FormOptions::BOOL );
53 $opts->add( 'hidesysops', false, FormOptions::BOOL );
54
55 $opts->fetchValuesFromRequest( $this->getRequest() );
56
57 if ( $par !== null ) {
58 $opts->setValue( 'username', $par );
59 }
60
61 $pager = new ActiveUsersPager( $this->getContext(), $opts );
62 $usersBody = $pager->getBody();
63
64 $this->buildForm();
65
66 if ( $usersBody ) {
67 $out->addHTML(
68 $pager->getNavigationBar() .
69 Html::rawElement( 'ul', [], $usersBody ) .
70 $pager->getNavigationBar()
71 );
72 } else {
73 $out->addWikiMsg( 'activeusers-noresult' );
74 }
75 }
76
80 protected function buildForm() {
81 $groups = User::getAllGroups();
82
83 foreach ( $groups as $group ) {
84 $msg = htmlspecialchars( UserGroupMembership::getGroupName( $group ) );
85 $options[$msg] = $group;
86 }
87
88 // Backwards-compatibility with old URLs
89 $req = $this->getRequest();
90 $excludeDefault = [];
91 if ( $req->getCheck( 'hidebots' ) ) {
92 $excludeDefault[] = 'bot';
93 }
94 if ( $req->getCheck( 'hidesysops' ) ) {
95 $excludeDefault[] = 'sysop';
96 }
97
98 $formDescriptor = [
99 'username' => [
100 'type' => 'user',
101 'name' => 'username',
102 'label-message' => 'activeusers-from',
103 ],
104 'groups' => [
105 'type' => 'multiselect',
106 'dropdown' => true,
107 'flatlist' => true,
108 'name' => 'groups',
109 'label-message' => 'activeusers-groups',
110 'options' => $options,
111 ],
112 'excludegroups' => [
113 'type' => 'multiselect',
114 'dropdown' => true,
115 'flatlist' => true,
116 'name' => 'excludegroups',
117 'label-message' => 'activeusers-excludegroups',
118 'options' => $options,
119 'default' => $excludeDefault,
120 ],
121 ];
122
123 HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
124 // For the 'multiselect' field values to be preserved on submit
125 ->setFormIdentifier( 'specialactiveusers' )
126 ->setIntro( $this->getIntroText() )
127 ->setWrapperLegendMsg( 'activeusers' )
128 ->setSubmitTextMsg( 'activeusers-submit' )
129 // prevent setting subpage and 'username' parameter at the same time
130 ->setAction( $this->getPageTitle()->getLocalURL() )
131 ->setMethod( 'get' )
132 ->prepareForm()
133 ->displayForm( false );
134 }
135
140 protected function getIntroText() {
141 $days = $this->getConfig()->get( 'ActiveUserDays' );
142
143 $intro = $this->msg( 'activeusers-intro' )->numParams( $days )->parse();
144
145 // Mention the level of cache staleness...
146 $dbr = wfGetDB( DB_REPLICA, 'recentchanges' );
147 $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ );
148 if ( $rcMax ) {
149 $cTime = $dbr->selectField( 'querycache_info',
150 'qci_timestamp',
151 [ 'qci_type' => 'activeusers' ],
152 __METHOD__
153 );
154 if ( $cTime ) {
155 $secondsOld = wfTimestamp( TS_UNIX, $rcMax ) - wfTimestamp( TS_UNIX, $cTime );
156 } else {
157 $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
158 $secondsOld = time() - wfTimestamp( TS_UNIX, $rcMin );
159 }
160 if ( $secondsOld > 0 ) {
161 $intro .= $this->msg( 'cachedspecial-viewing-cached-ttl' )
162 ->durationParams( $secondsOld )->parseAsBlock();
163 }
164 }
165
166 return $intro;
167 }
168
169 protected function getGroupName() {
170 return 'users';
171 }
172}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
This class is used to get a list of active users.
Helper class to keep track of options when mixing links and form elements.
const BOOL
Boolean type, maps guessType() to WebRequest::getBool()
Implements Special:Activeusers.
buildForm()
Generate and output the form.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getIntroText()
Return introductory message.
execute( $par)
Show the special page.
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
static getAllGroups()
Return the set of defined explicit groups.
Definition User.php:5099
this hook is for auditing only $req
Definition hooks.txt:990
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:2001
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:864
const DB_REPLICA
Definition defines.php:25