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 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:675
SpecialActiveUsers\execute
execute( $par)
Show the special page.
Definition: SpecialActiveusers.php:40
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:793
SpecialActiveUsers\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialActiveusers.php:169
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:722
UserGroupMembership\getGroupName
static getGroupName( $group)
Gets the localized friendly name for a group, if it exists.
Definition: UserGroupMembership.php:442
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1980
$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:864
SpecialActiveUsers\buildForm
buildForm()
Generate and output the form.
Definition: SpecialActiveusers.php:80
SpecialActiveUsers\__construct
__construct()
Definition: SpecialActiveusers.php:31
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:37
$dbr
$dbr
Definition: testCompression.php:50
ActiveUsersPager
This class is used to get a list of active users.
Definition: ActiveUsersPager.php:29
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:761
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2812
HTMLForm\factory
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:279
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:527
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
SpecialActiveUsers\getIntroText
getIntroText()
Return introductory message.
Definition: SpecialActiveusers.php:140
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:695
$options
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
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:712
User\getAllGroups
static getAllGroups()
Return the set of defined explicit groups.
Definition: User.php:5099
$req
this hook is for auditing only $req
Definition: hooks.txt:990
SpecialActiveUsers
Implements Special:Activeusers.
Definition: SpecialActiveusers.php:29
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:22
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:629
FormOptions\BOOL
const BOOL
Boolean type, maps guessType() to WebRequest::getBool()
Definition: FormOptions.php:50