MediaWiki REL1_33
SpecialActiveusers.php
Go to the documentation of this file.
1<?php
30
31 public function __construct() {
32 parent::__construct( 'Activeusers' );
33 }
34
38 public function execute( $par ) {
39 $out = $this->getOutput();
40
41 $this->setHeaders();
42 $this->outputHeader();
43
44 $opts = new FormOptions();
45
46 $opts->add( 'username', '' );
47 $opts->add( 'groups', [] );
48 $opts->add( 'excludegroups', [] );
49 // Backwards-compatibility with old URLs
50 $opts->add( 'hidebots', false, FormOptions::BOOL );
51 $opts->add( 'hidesysops', false, FormOptions::BOOL );
52
53 $opts->fetchValuesFromRequest( $this->getRequest() );
54
55 if ( $par !== null ) {
56 $opts->setValue( 'username', $par );
57 }
58
59 $pager = new ActiveUsersPager( $this->getContext(), $opts );
60 $usersBody = $pager->getBody();
61
62 $this->buildForm();
63
64 if ( $usersBody ) {
65 $out->addHTML(
66 $pager->getNavigationBar() .
67 Html::rawElement( 'ul', [], $usersBody ) .
68 $pager->getNavigationBar()
69 );
70 } else {
71 $out->addWikiMsg( 'activeusers-noresult' );
72 }
73 }
74
78 protected function buildForm() {
79 $groups = User::getAllGroups();
80
81 $options = [];
82 foreach ( $groups as $group ) {
83 $msg = htmlspecialchars( UserGroupMembership::getGroupName( $group ) );
84 $options[$msg] = $group;
85 }
86 asort( $options );
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
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.
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:5131
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
this hook is for auditing only $req
Definition hooks.txt:979
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:855
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead & $formDescriptor
Definition hooks.txt:2157
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:1999
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
const DB_REPLICA
Definition defines.php:25