MediaWiki  1.29.2
SpecialActiveusers.php
Go to the documentation of this file.
1 <?php
32 
36  public function __construct() {
37  parent::__construct( 'Activeusers' );
38  }
39 
45  public function execute( $par ) {
46  $out = $this->getOutput();
47 
48  $this->setHeaders();
49  $this->outputHeader();
50 
51  $opts = new FormOptions();
52 
53  $opts->add( 'username', '' );
54  $opts->add( 'groups', [] );
55  $opts->add( 'excludegroups', [] );
56  // Backwards-compatibility with old URLs
57  $opts->add( 'hidebots', false, FormOptions::BOOL );
58  $opts->add( 'hidesysops', false, FormOptions::BOOL );
59 
60  $opts->fetchValuesFromRequest( $this->getRequest() );
61 
62  if ( $par !== null ) {
63  $opts->setValue( 'username', $par );
64  }
65 
66  $pager = new ActiveUsersPager( $this->getContext(), $opts );
67  $usersBody = $pager->getBody();
68 
69  $this->buildForm();
70 
71  if ( $usersBody ) {
72  $out->addHTML(
73  $pager->getNavigationBar() .
74  Html::rawElement( 'ul', [], $usersBody ) .
75  $pager->getNavigationBar()
76  );
77  } else {
78  $out->addWikiMsg( 'activeusers-noresult' );
79  }
80  }
81 
85  protected function buildForm() {
86  $groups = User::getAllGroups();
87 
88  foreach ( $groups as $group ) {
89  $msg = htmlspecialchars( UserGroupMembership::getGroupName( $group ) );
90  $options[$msg] = $group;
91  }
92 
93  // Backwards-compatibility with old URLs
94  $req = $this->getRequest();
95  $excludeDefault = [];
96  if ( $req->getCheck( 'hidebots' ) ) {
97  $excludeDefault[] = 'bot';
98  }
99  if ( $req->getCheck( 'hidesysops' ) ) {
100  $excludeDefault[] = 'sysop';
101  }
102 
103  $formDescriptor = [
104  'username' => [
105  'type' => 'user',
106  'name' => 'username',
107  'label-message' => 'activeusers-from',
108  ],
109  'groups' => [
110  'type' => 'multiselect',
111  'dropdown' => true,
112  'flatlist' => true,
113  'name' => 'groups',
114  'label-message' => 'activeusers-groups',
115  'options' => $options,
116  ],
117  'excludegroups' => [
118  'type' => 'multiselect',
119  'dropdown' => true,
120  'flatlist' => true,
121  'name' => 'excludegroups',
122  'label-message' => 'activeusers-excludegroups',
123  'options' => $options,
124  'default' => $excludeDefault,
125  ],
126  ];
127 
128  HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
129  // For the 'multiselect' field values to be preserved on submit
130  ->setFormIdentifier( 'specialactiveusers' )
131  ->setIntro( $this->getIntroText() )
132  ->setWrapperLegendMsg( 'activeusers' )
133  ->setSubmitTextMsg( 'activeusers-submit' )
134  // prevent setting subpage and 'username' parameter at the same time
135  ->setAction( $this->getPageTitle()->getLocalURL() )
136  ->setMethod( 'get' )
137  ->prepareForm()
138  ->displayForm( false );
139  }
140 
145  protected function getIntroText() {
146  $days = $this->getConfig()->get( 'ActiveUserDays' );
147 
148  $intro = $this->msg( 'activeusers-intro' )->numParams( $days )->parse();
149 
150  // Mention the level of cache staleness...
151  $dbr = wfGetDB( DB_REPLICA, 'recentchanges' );
152  $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ );
153  if ( $rcMax ) {
154  $cTime = $dbr->selectField( 'querycache_info',
155  'qci_timestamp',
156  [ 'qci_type' => 'activeusers' ],
157  __METHOD__
158  );
159  if ( $cTime ) {
160  $secondsOld = wfTimestamp( TS_UNIX, $rcMax ) - wfTimestamp( TS_UNIX, $cTime );
161  } else {
162  $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
163  $secondsOld = time() - wfTimestamp( TS_UNIX, $rcMin );
164  }
165  if ( $secondsOld > 0 ) {
166  $intro .= $this->msg( 'cachedspecial-viewing-cached-ttl' )
167  ->durationParams( $secondsOld )->parseAsBlock();
168  }
169  }
170 
171  return $intro;
172  }
173 
174  protected function getGroupName() {
175  return 'users';
176  }
177 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:628
SpecialActiveUsers\execute
execute( $par)
Show the special page.
Definition: SpecialActiveusers.php:45
SpecialActiveUsers\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialActiveusers.php:174
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:675
UserGroupMembership\getGroupName
static getGroupName( $group)
Gets the localized friendly name for a group, if it exists.
Definition: UserGroupMembership.php:405
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1994
$req
this hook is for auditing only $req
Definition: hooks.txt:990
SpecialActiveUsers\buildForm
buildForm()
Generate and output the form.
Definition: SpecialActiveusers.php:85
SpecialActiveUsers\__construct
__construct()
Constructor.
Definition: SpecialActiveusers.php:36
php
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
ActiveUsersPager
This class is used to get a list of active users.
Definition: ActiveUsersPager.php:31
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:714
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
HTMLForm\factory
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:277
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:484
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
SpecialActiveUsers\getIntroText
getIntroText()
Return introductory message.
Definition: SpecialActiveusers.php:145
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:648
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:746
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:36
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:665
User\getAllGroups
static getAllGroups()
Return the set of defined explicit groups.
Definition: User.php:4860
SpecialActiveUsers
Implements Special:Activeusers.
Definition: SpecialActiveusers.php:31
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
as
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
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:583
$options
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1049
FormOptions\BOOL
const BOOL
Boolean type, maps guessType() to WebRequest::getBool()
Definition: FormOptions.php:50
$out
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:783