Convert Special:Activeusers to use OOUI
authorSethakill <sethakill@outlook.com>
Mon, 2 May 2016 07:46:56 +0000 (09:46 +0200)
committerFlorian <florian.schmidt.stargatewissen@gmail.com>
Sun, 8 May 2016 22:51:55 +0000 (00:51 +0200)
Moved FormOptions and form from pager
and recreated it with HtmlForm.

Bug: T117733
Change-Id: Ia330bee63ad17bb75e715cd95e407d5e43310177

includes/specialpage/SpecialPageFactory.php
includes/specials/SpecialActiveusers.php
includes/specials/pagers/ActiveUsersPager.php

index 725c4fc..5c24ee0 100644 (file)
@@ -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 );
 
index d6d4500..c697ca7 100644 (file)
@@ -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( "<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 ) {
@@ -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 = '<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' );
index 0d3bc9a..73ab0ad 100644 (file)
@@ -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' => '' ] : []
-                               )
-                       ) . '<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;
-       }
-
 }