From b3492e41f93f54561a4af8d8127b37e59e157a84 Mon Sep 17 00:00:00 2001 From: Sethakill Date: Mon, 2 May 2016 09:46:56 +0200 Subject: [PATCH] Convert Special:Activeusers to use OOUI Moved FormOptions and form from pager and recreated it with HtmlForm. Bug: T117733 Change-Id: Ia330bee63ad17bb75e715cd95e407d5e43310177 --- includes/specialpage/SpecialPageFactory.php | 3 +- includes/specials/SpecialActiveusers.php | 68 ++++++++++++++---- includes/specials/pagers/ActiveUsersPager.php | 71 ++----------------- 3 files changed, 61 insertions(+), 81 deletions(-) diff --git a/includes/specialpage/SpecialPageFactory.php b/includes/specialpage/SpecialPageFactory.php index 725c4fc581..5c24ee00a4 100644 --- a/includes/specialpage/SpecialPageFactory.php +++ b/includes/specialpage/SpecialPageFactory.php @@ -86,6 +86,7 @@ class SpecialPageFactory { 'CreateAccount' => 'SpecialCreateAccount', // Users and rights + 'Activeusers' => 'SpecialActiveUsers', 'Block' => 'SpecialBlock', 'Unblock' => 'SpecialUnblock', 'BlockList' => 'SpecialBlockList', @@ -254,8 +255,6 @@ class SpecialPageFactory { self::$list['ChangeContentModel'] = 'SpecialChangeContentModel'; } - self::$list['Activeusers'] = 'SpecialActiveUsers'; - // Add extension special pages self::$list = array_merge( self::$list, $wgSpecialPages ); diff --git a/includes/specials/SpecialActiveusers.php b/includes/specials/SpecialActiveusers.php index d6d4500972..c697ca7037 100644 --- a/includes/specials/SpecialActiveusers.php +++ b/includes/specials/SpecialActiveusers.php @@ -24,6 +24,8 @@ */ /** + * Implements Special:Activeusers + * * @ingroup SpecialPage */ class SpecialActiveUsers extends SpecialPage { @@ -41,16 +43,25 @@ 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( "
\n$1\n
", - [ '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 ) { @@ -66,22 +77,51 @@ class SpecialActiveUsers extends SpecialPage { $secondsOld = time() - wfTimestamp( TS_UNIX, $rcMin ); } if ( $secondsOld > 0 ) { - $out->addWikiMsg( 'cachedspecial-viewing-cached-ttl', - $this->getLanguage()->formatDuration( $secondsOld ) ); + $cacheTxt = '
' . $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' ); diff --git a/includes/specials/pagers/ActiveUsersPager.php b/includes/specials/pagers/ActiveUsersPager.php index 0d3bc9aeee..73ab0ad729 100644 --- a/includes/specials/pagers/ActiveUsersPager.php +++ b/includes/specials/pagers/ActiveUsersPager.php @@ -52,15 +52,15 @@ class ActiveUsersPager extends UsersPager { /** * @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 ) ) { @@ -68,21 +68,10 @@ class ActiveUsersPager extends UsersPager { } } - $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'; } } @@ -203,52 +192,4 @@ class ActiveUsersPager extends UsersPager { 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' => '' ] : [] - ) - ) . '
'; - - $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 ] - ) . '
'; - - # 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; - } - } -- 2.20.1