MediaWiki  master
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  $out->addModuleStyles( 'mediawiki.interface.helpers.styles' );
71  } else {
72  $out->addWikiMsg( 'activeusers-noresult' );
73  }
74  }
75 
79  protected function buildForm() {
80  $groups = User::getAllGroups();
81 
82  $options = [];
83  foreach ( $groups as $group ) {
84  $msg = htmlspecialchars( UserGroupMembership::getGroupName( $group ) );
85  $options[$msg] = $group;
86  }
87  asort( $options );
88 
89  // Backwards-compatibility with old URLs
90  $req = $this->getRequest();
91  $excludeDefault = [];
92  if ( $req->getCheck( 'hidebots' ) ) {
93  $excludeDefault[] = 'bot';
94  }
95  if ( $req->getCheck( 'hidesysops' ) ) {
96  $excludeDefault[] = 'sysop';
97  }
98 
99  $formDescriptor = [
100  'username' => [
101  'type' => 'user',
102  'name' => 'username',
103  'label-message' => 'activeusers-from',
104  ],
105  'groups' => [
106  'type' => 'multiselect',
107  'dropdown' => true,
108  'flatlist' => true,
109  'name' => 'groups',
110  'label-message' => 'activeusers-groups',
111  'options' => $options,
112  ],
113  'excludegroups' => [
114  'type' => 'multiselect',
115  'dropdown' => true,
116  'flatlist' => true,
117  'name' => 'excludegroups',
118  'label-message' => 'activeusers-excludegroups',
119  'options' => $options,
120  'default' => $excludeDefault,
121  ],
122  ];
123 
124  HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
125  // For the 'multiselect' field values to be preserved on submit
126  ->setFormIdentifier( 'specialactiveusers' )
127  ->setIntro( $this->getIntroText() )
128  ->setWrapperLegendMsg( 'activeusers' )
129  ->setSubmitTextMsg( 'activeusers-submit' )
130  // prevent setting subpage and 'username' parameter at the same time
131  ->setAction( $this->getPageTitle()->getLocalURL() )
132  ->setMethod( 'get' )
133  ->prepareForm()
134  ->displayForm( false );
135  }
136 
141  protected function getIntroText() {
142  $days = $this->getConfig()->get( 'ActiveUserDays' );
143 
144  $intro = $this->msg( 'activeusers-intro' )->numParams( $days )->parse();
145 
146  // Mention the level of cache staleness...
147  $dbr = wfGetDB( DB_REPLICA, 'recentchanges' );
148  $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ );
149  if ( $rcMax ) {
150  $cTime = $dbr->selectField( 'querycache_info',
151  'qci_timestamp',
152  [ 'qci_type' => 'activeusers' ],
153  __METHOD__
154  );
155  if ( $cTime ) {
156  $secondsOld = wfTimestamp( TS_UNIX, $rcMax ) - wfTimestamp( TS_UNIX, $cTime );
157  } else {
158  $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
159  $secondsOld = time() - wfTimestamp( TS_UNIX, $rcMin );
160  }
161  if ( $secondsOld > 0 ) {
162  $intro .= $this->msg( 'cachedspecial-viewing-cached-ttl' )
163  ->durationParams( $secondsOld )->parseAsBlock();
164  }
165  }
166 
167  return $intro;
168  }
169 
170  protected function getGroupName() {
171  return 'users';
172  }
173 }
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
const BOOL
Boolean type, maps guessType() to WebRequest::getBool()
Definition: FormOptions.php:50
getContext()
Gets the context this SpecialPage is executed in.
Implements Special:Activeusers.
This class is used to get a list of active users.
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:2051
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
getIntroText()
Return introductory message.
getOutput()
Get the OutputPage being used for this instance.
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:299
static getAllGroups()
Return the set of defined explicit groups.
Definition: User.php:4864
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:767
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static getGroupName( $group)
Gets the localized friendly name for a group, if it exists.
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:1972
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
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 null
Definition: hooks.txt:767
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
Definition: distributors.txt:9
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:35
this hook is for auditing only $req
Definition: hooks.txt:960
buildForm()
Generate and output the form.
getConfig()
Shortcut to get main config object.
msg( $key)
Wrapper around wfMessage that sets the current context.
const DB_REPLICA
Definition: defines.php:25
getRequest()
Get the WebRequest being used for this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
getPageTitle( $subpage=false)
Get a self-referential title object.