'CreateAccount' => 'SpecialCreateAccount',
// Users and rights
+ 'Activeusers' => 'SpecialActiveUsers',
'Block' => 'SpecialBlock',
'Unblock' => 'SpecialUnblock',
'BlockList' => 'SpecialBlockList',
self::$list['ChangeContentModel'] = 'SpecialChangeContentModel';
}
- self::$list['Activeusers'] = 'SpecialActiveUsers';
-
// Add extension special pages
self::$list = array_merge( self::$list, $wgSpecialPages );
*/
/**
+ * Implements Special:Activeusers
+ *
* @ingroup SpecialPage
*/
class SpecialActiveUsers extends SpecialPage {
* @param string $par Parameter passed to the page or null
*/
public function execute( $par ) {
- $days = $this->getConfig()->get( 'ActiveUserDays' );
+ $out = $this->getOutput();
$this->setHeaders();
$this->outputHeader();
- $out = $this->getOutput();
- $out->wrapWikiMsg( "<div class='mw-activeusers-intro'>\n$1\n</div>",
- [ 'activeusers-intro', $this->getLanguage()->formatNum( $days ) ] );
+ $opts = new FormOptions();
+
+ $opts->add( 'username', '' );
+ $opts->add( 'hidebots', false, FormOptions::BOOL );
+ $opts->add( 'hidesysops', false, FormOptions::BOOL );
+
+ $opts->fetchValuesFromRequest( $this->getRequest() );
+
+ if ( $par !== null ) {
+ $opts->setValue( 'username', $par );
+ }
// Mention the level of cache staleness...
+ $cacheText = '';
$dbr = wfGetDB( DB_SLAVE, 'recentchanges' );
$rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', '', __METHOD__ );
if ( $rcMax ) {
$secondsOld = time() - wfTimestamp( TS_UNIX, $rcMin );
}
if ( $secondsOld > 0 ) {
- $out->addWikiMsg( 'cachedspecial-viewing-cached-ttl',
- $this->getLanguage()->formatDuration( $secondsOld ) );
+ $cacheTxt = '<br>' . $this->msg( 'cachedspecial-viewing-cached-ttl' )
+ ->durationParams( $secondsOld );
}
}
- $up = new ActiveUsersPager( $this->getContext(), null, $par );
+ $pager = new ActiveUsersPager( $this->getContext(), $opts );
+ $usersBody = $pager->getBody();
+
+ $days = $this->getConfig()->get( 'ActiveUserDays' );
+
+ $formDescriptor = [
+ 'username' => [
+ 'type' => 'user',
+ 'name' => 'username',
+ 'label-message' => 'activeusers-from',
+ ],
+
+ 'hidebots' => [
+ 'type' => 'check',
+ 'name' => 'hidebots',
+ 'label-message' => 'activeusers-hidebots',
+ 'default' => false,
+ ],
+
+ 'hidesysops' => [
+ 'type' => 'check',
+ 'name' => 'hidesysops',
+ 'label-message' => 'activeusers-hidesysops',
+ 'default' => false,
+ ],
+ ];
- # getBody() first to check, if empty
- $usersbody = $up->getBody();
+ $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
+ ->setIntro( $this->msg( 'activeusers-intro' )->numParams( $days ) . $cacheText )
+ ->setWrapperLegendMsg( 'activeusers' )
+ ->setSubmitTextMsg( 'activeusers-submit' )
+ ->setMethod( 'get' )
+ ->prepareForm()
+ ->displayForm( false );
- $out->addHTML( $up->getPageHeader() );
- if ( $usersbody ) {
+ if ( $usersBody ) {
$out->addHTML(
- $up->getNavigationBar() .
- Html::rawElement( 'ul', [], $usersbody ) .
- $up->getNavigationBar()
+ $pager->getNavigationBar() .
+ Html::rawElement( 'ul', [], $usersBody ) .
+ $pager->getNavigationBar()
);
} else {
$out->addWikiMsg( 'activeusers-noresult' );
/**
* @param IContextSource $context
- * @param null $group Unused
- * @param string $par Parameter passed to the page
+ * @param FormOptions $opts
*/
- function __construct( IContextSource $context = null, $group = null, $par = null ) {
+ function __construct( IContextSource $context = null, FormOptions $opts ) {
parent::__construct( $context );
$this->RCMaxAge = $this->getConfig()->get( 'ActiveUserDays' );
- $un = $this->getRequest()->getText( 'username', $par );
$this->requestedUser = '';
+
+ $un = $opts->getValue( 'username' );
if ( $un != '' ) {
$username = Title::makeTitleSafe( NS_USER, $un );
if ( !is_null( $username ) ) {
}
}
- $this->setupOptions();
- }
-
- public function setupOptions() {
- $this->opts = new FormOptions();
-
- $this->opts->add( 'hidebots', false, FormOptions::BOOL );
- $this->opts->add( 'hidesysops', false, FormOptions::BOOL );
-
- $this->opts->fetchValuesFromRequest( $this->getRequest() );
-
- if ( $this->opts->getValue( 'hidebots' ) == 1 ) {
+ if ( $opts->getValue( 'hidebots' ) == 1 ) {
$this->hideRights[] = 'bot';
}
- if ( $this->opts->getValue( 'hidesysops' ) == 1 ) {
+ if ( $opts->getValue( 'hidesysops' ) == 1 ) {
$this->hideGroups[] = 'sysop';
}
}
return Html::rawElement( 'li', [], "{$item} [{$count}]{$blocked}" );
}
- function getPageHeader() {
- $self = $this->getTitle();
- $limit = $this->mLimit ? Html::hidden( 'limit', $this->mLimit ) : '';
-
- # Form tag
- $out = Xml::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] );
- $out .= Xml::fieldset( $this->msg( 'activeusers' )->text() ) . "\n";
- $out .= Html::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
-
- # Username field (with autocompletion support)
- $this->getOutput()->addModules( 'mediawiki.userSuggest' );
- $out .= Xml::inputLabel(
- $this->msg( 'activeusers-from' )->text(),
- 'username',
- 'offset',
- 20,
- $this->requestedUser,
- [
- 'class' => 'mw-ui-input-inline mw-autocomplete-user',
- 'tabindex' => 1,
- ] + (
- // Set autofocus on blank input
- $this->requestedUser === '' ? [ 'autofocus' => '' ] : []
- )
- ) . '<br />';
-
- $out .= Xml::checkLabel( $this->msg( 'activeusers-hidebots' )->text(),
- 'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ), [ 'tabindex' => 2 ] );
-
- $out .= Xml::checkLabel(
- $this->msg( 'activeusers-hidesysops' )->text(),
- 'hidesysops',
- 'hidesysops',
- $this->opts->getValue( 'hidesysops' ),
- [ 'tabindex' => 3 ]
- ) . '<br />';
-
- # Submit button and form bottom
- $out .= Xml::submitButton(
- $this->msg( 'activeusers-submit' )->text(),
- [ 'tabindex' => 4 ]
- ) . "\n";
- $out .= Xml::closeElement( 'fieldset' );
- $out .= Xml::closeElement( 'form' );
-
- return $out;
- }
-
}