MediaWiki  master
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  $options = [];
84  foreach ( $groups as $group ) {
85  $msg = htmlspecialchars( UserGroupMembership::getGroupName( $group ) );
86  $options[$msg] = $group;
87  }
88  asort( $options );
89 
90  // Backwards-compatibility with old URLs
91  $req = $this->getRequest();
92  $excludeDefault = [];
93  if ( $req->getCheck( 'hidebots' ) ) {
94  $excludeDefault[] = 'bot';
95  }
96  if ( $req->getCheck( 'hidesysops' ) ) {
97  $excludeDefault[] = 'sysop';
98  }
99 
100  $formDescriptor = [
101  'username' => [
102  'type' => 'user',
103  'name' => 'username',
104  'label-message' => 'activeusers-from',
105  ],
106  'groups' => [
107  'type' => 'multiselect',
108  'dropdown' => true,
109  'flatlist' => true,
110  'name' => 'groups',
111  'label-message' => 'activeusers-groups',
112  'options' => $options,
113  ],
114  'excludegroups' => [
115  'type' => 'multiselect',
116  'dropdown' => true,
117  'flatlist' => true,
118  'name' => 'excludegroups',
119  'label-message' => 'activeusers-excludegroups',
120  'options' => $options,
121  'default' => $excludeDefault,
122  ],
123  ];
124 
125  HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
126  // For the 'multiselect' field values to be preserved on submit
127  ->setFormIdentifier( 'specialactiveusers' )
128  ->setIntro( $this->getIntroText() )
129  ->setWrapperLegendMsg( 'activeusers' )
130  ->setSubmitTextMsg( 'activeusers-submit' )
131  // prevent setting subpage and 'username' parameter at the same time
132  ->setAction( $this->getPageTitle()->getLocalURL() )
133  ->setMethod( 'get' )
134  ->prepareForm()
135  ->displayForm( false );
136  }
137 
142  protected function getIntroText() {
143  $days = $this->getConfig()->get( 'ActiveUserDays' );
144 
145  $intro = $this->msg( 'activeusers-intro' )->numParams( $days )->parse();
146 
147  // Mention the level of cache staleness...
148  $dbr = wfGetDB( DB_REPLICA, 'recentchanges' );
149  $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ );
150  if ( $rcMax ) {
151  $cTime = $dbr->selectField( 'querycache_info',
152  'qci_timestamp',
153  [ 'qci_type' => 'activeusers' ],
154  __METHOD__
155  );
156  if ( $cTime ) {
157  $secondsOld = wfTimestamp( TS_UNIX, $rcMax ) - wfTimestamp( TS_UNIX, $cTime );
158  } else {
159  $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
160  $secondsOld = time() - wfTimestamp( TS_UNIX, $rcMin );
161  }
162  if ( $secondsOld > 0 ) {
163  $intro .= $this->msg( 'cachedspecial-viewing-cached-ttl' )
164  ->durationParams( $secondsOld )->parseAsBlock();
165  }
166  }
167 
168  return $intro;
169  }
170 
171  protected function getGroupName() {
172  return 'users';
173  }
174 }
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
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:785
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:2075
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
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:284
static getAllGroups()
Return the set of defined explicit groups.
Definition: User.php:5131
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.
execute( $par)
Show the special page.
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:1996
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
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:990
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.