SpecialMovepage: Convert form to use OOUI controls
authorBartosz Dziewoński <matma.rex@gmail.com>
Fri, 16 Jan 2015 22:42:54 +0000 (14:42 -0800)
committerBartosz Dziewoński <matma.rex@gmail.com>
Tue, 1 Sep 2015 19:03:38 +0000 (21:03 +0200)
Recreated the form with OOUI widgets. This required putting together
ComplexTitleInputWidget to handle the split namespace+title field on
this page.

Bug: T86865
Change-Id: Ice69df851137e3454ae2c9f4c75494b18cf8a75a

autoload.php
includes/specials/SpecialMovepage.php
includes/widget/ComplexTitleInputWidget.php [new file with mode: 0644]
includes/widget/NamespaceInputWidget.php
resources/Resources.php
resources/src/mediawiki.special/mediawiki.special.movePage.css [new file with mode: 0644]
resources/src/mediawiki.special/mediawiki.special.movePage.js
resources/src/mediawiki.widgets/mw.widgets.ComplexTitleInputWidget.base.css [new file with mode: 0644]
resources/src/mediawiki.widgets/mw.widgets.ComplexTitleInputWidget.js [new file with mode: 0644]
resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js
resources/src/mediawiki.widgets/mw.widgets.TitleInputWidget.js

index 82a45b4..d91b704 100644 (file)
@@ -762,6 +762,7 @@ $wgAutoloadLocalClasses = array(
        'MediaWiki\\Logger\\NullSpi' => __DIR__ . '/includes/debug/logger/NullSpi.php',
        'MediaWiki\\Logger\\Spi' => __DIR__ . '/includes/debug/logger/Spi.php',
        'MediaWiki\\Widget\\ComplexNamespaceInputWidget' => __DIR__ . '/includes/widget/ComplexNamespaceInputWidget.php',
+       'MediaWiki\\Widget\\ComplexTitleInputWidget' => __DIR__ . '/includes/widget/ComplexTitleInputWidget.php',
        'MediaWiki\\Widget\\NamespaceInputWidget' => __DIR__ . '/includes/widget/NamespaceInputWidget.php',
        'MediaWiki\\Widget\\TitleInputWidget' => __DIR__ . '/includes/widget/TitleInputWidget.php',
        'MediaWiki\\Widget\\UserInputWidget' => __DIR__ . '/includes/widget/UserInputWidget.php',
index eb8a274..8091f1b 100644 (file)
@@ -147,6 +147,7 @@ class MovePageForm extends UnlistedSpecialPage {
                $out = $this->getOutput();
                $out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) );
                $out->addModules( 'mediawiki.special.movePage' );
+               $out->addModuleStyles( 'mediawiki.special.movePage.styles' );
                $this->addHelpLink( 'Help:Moving a page' );
 
                $newTitle = $this->newTitle;
@@ -290,7 +291,6 @@ class MovePageForm extends UnlistedSpecialPage {
                // is enforced in the mediawiki.special.movePage module
 
                $immovableNamespaces = array();
-
                foreach ( array_keys( $this->getLanguage()->getNamespaces() ) as $nsId ) {
                        if ( !MWNamespace::isMovable( $nsId ) ) {
                                $immovableNamespaces[] = $nsId;
@@ -299,202 +299,207 @@ class MovePageForm extends UnlistedSpecialPage {
 
                $handler = ContentHandler::getForTitle( $this->oldTitle );
 
-               $out->addHTML(
-                       Xml::openElement(
-                               'form',
-                               array(
-                                       'method' => 'post',
-                                       'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
-                                       'id' => 'movepage'
-                               )
-                       ) .
-                       Xml::openElement( 'fieldset' ) .
-                       Xml::element( 'legend', null, $this->msg( 'move-page-legend' )->text() ) .
-                       Xml::openElement( 'table', array( 'id' => 'mw-movepage-table' ) )
+               $out->enableOOUI();
+               $fields = array();
+
+               $fields[] = new OOUI\FieldLayout(
+                       new OOUI\LabelWidget( array(
+                               'label' => new OOUI\HtmlSnippet( "<strong>$oldTitleLink</strong>" )
+                       ) ),
+                       array(
+                               'label' => $this->msg( 'movearticle' )->text(),
+                               'align' => 'top',
+                       )
                );
 
-               $out->addHTML(
-                       "<tr>
-                               <td class='mw-label'>" .
-                                       $this->msg( 'movearticle' )->escaped() .
-                               "</td>
-                               <td class='mw-input'>
-                                       <strong>{$oldTitleLink}</strong>
-                               </td>
-                       </tr>
-                       <tr>
-                               <td class='mw-label'>" .
-                                       Xml::label( $this->msg( 'newtitle' )->text(), 'wpNewTitleMain' ) .
-                               "</td>
-                               <td class='mw-input'>" .
-                                       Html::namespaceSelector(
-                                               array(
-                                                       'selected' => $newTitle->getNamespace(),
-                                                       'exclude' => $immovableNamespaces
-                                               ),
-                                               array( 'name' => 'wpNewTitleNs', 'id' => 'wpNewTitleNs' )
-                                       ) .
-                                       Xml::input(
-                                               'wpNewTitleMain',
-                                               60,
-                                               $wgContLang->recodeForEdit( $newTitle->getText() ),
-                                               array(
-                                                       'type' => 'text',
-                                                       'id' => 'wpNewTitleMain',
-                                                       'maxlength' => 255
-                                               )
-                                       ) .
-                                       Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
-                               "</td>
-                       </tr>
-                       <tr>
-                               <td class='mw-label'>" .
-                                       Xml::label( $this->msg( 'movereason' )->text(), 'wpReason' ) .
-                               "</td>
-                               <td class='mw-input'>" .
-                                       Xml::input( 'wpReason', 60, $this->reason, array(
-                                               'type' => 'text',
-                                               'id' => 'wpReason',
-                                               'maxlength' => 200,
-                                       ) ) .
-                               "</td>
-                       </tr>"
+               $fields[] = new OOUI\FieldLayout(
+                       new MediaWiki\Widget\ComplexTitleInputWidget( array(
+                               'id' => 'wpNewTitle',
+                               'namespace' => array(
+                                       'id' => 'wpNewTitleNs',
+                                       'name' => 'wpNewTitleNs',
+                                       'value' => $newTitle->getNamespace(),
+                                       'exclude' => $immovableNamespaces,
+                               ),
+                               'title' => array(
+                                       'id' => 'wpNewTitleMain',
+                                       'name' => 'wpNewTitleMain',
+                                       'value' => $wgContLang->recodeForEdit( $newTitle->getText() ),
+                                       // Inappropriate, since we're expecting the user to input a non-existent page's title
+                                       'suggestions' => false,
+                               ),
+                               'infusable' => true,
+                       ) ),
+                       array(
+                               'label' => $this->msg( 'newtitle' )->text(),
+                               'align' => 'top',
+                       )
+               );
+
+               $fields[] = new OOUI\FieldLayout(
+                       new OOUI\TextInputWidget( array(
+                               'name' => 'wpReason',
+                               'id' => 'wpReason',
+                               'maxLength' => 200,
+                               'infusable' => true,
+                       ) ),
+                       array(
+                               'label' => $this->msg( 'movereason' )->text(),
+                               'align' => 'top',
+                       )
                );
 
                if ( $considerTalk ) {
-                       $out->addHTML( "
-                               <tr>
-                                       <td></td>
-                                       <td class='mw-input'>" .
-                                               Xml::checkLabel(
-                                                       $this->msg( 'movetalk' )->text(),
-                                                       'wpMovetalk',
-                                                       'wpMovetalk',
-                                                       $this->moveTalk
-                                               ) .
-                                       "</td>
-                               </tr>"
+                       $fields[] = new OOUI\FieldLayout(
+                               new OOUI\CheckboxInputWidget( array(
+                                       'name' => 'wpMovetalk',
+                                       'id' => 'wpMovetalk',
+                                       'value' => '1',
+                                       'selected' => $this->moveTalk,
+                               ) ),
+                               array(
+                                       'label' => $this->msg( 'movetalk' )->text(),
+                                       'align' => 'inline',
+                               )
                        );
                }
 
                if ( $user->isAllowed( 'suppressredirect' ) ) {
                        if ( $handler->supportsRedirects() ) {
                                $isChecked = $this->leaveRedirect;
-                               $options = array();
+                               $isDisabled = false;
                        } else {
                                $isChecked = false;
-                               $options = array(
-                                       'disabled' => 'disabled'
-                               );
+                               $isDisabled = true;
                        }
-                       $out->addHTML( "
-                               <tr>
-                                       <td></td>
-                                       <td class='mw-input'>" .
-                                               Xml::checkLabel(
-                                                       $this->msg( 'move-leave-redirect' )->text(),
-                                                       'wpLeaveRedirect',
-                                                       'wpLeaveRedirect',
-                                                       $isChecked,
-                                                       $options
-                                               ) .
-                                       "</td>
-                               </tr>"
+                       $fields[] = new OOUI\FieldLayout(
+                               new OOUI\CheckboxInputWidget( array(
+                                       'name' => 'wpLeaveRedirect',
+                                       'id' => 'wpLeaveRedirect',
+                                       'value' => '1',
+                                       'selected' => $isChecked,
+                                       'disabled' => $isDisabled,
+                               ) ),
+                               array(
+                                       'label' => $this->msg( 'move-leave-redirect' )->text(),
+                                       'align' => 'inline',
+                               )
                        );
                }
 
                if ( $hasRedirects ) {
-                       $out->addHTML( "
-                               <tr>
-                                       <td></td>
-                                       <td class='mw-input'>" .
-                                               Xml::checkLabel(
-                                                       $this->msg( 'fix-double-redirects' )->text(),
-                                                       'wpFixRedirects',
-                                                       'wpFixRedirects',
-                                                       $this->fixRedirects
-                                               ) .
-                                       "</td>
-                               </tr>"
+                       $fields[] = new OOUI\FieldLayout(
+                               new OOUI\CheckboxInputWidget( array(
+                                       'name' => 'wpFixRedirects',
+                                       'id' => 'wpFixRedirects',
+                                       'value' => '1',
+                                       'selected' => $this->fixRedirects,
+                               ) ),
+                               array(
+                                       'label' => $this->msg( 'fix-double-redirects' )->text(),
+                                       'align' => 'inline',
+                               )
                        );
                }
 
                if ( $canMoveSubpage ) {
                        $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
-                       $out->addHTML( "
-                               <tr>
-                                       <td></td>
-                                       <td class='mw-input'>" .
-                                               Xml::check(
-                                                       'wpMovesubpages',
-                                                       # Don't check the box if we only have talk subpages to
-                                                       # move and we aren't moving the talk page.
-                                                       $this->moveSubpages && ( $this->oldTitle->hasSubpages() || $this->moveTalk ),
-                                                       array( 'id' => 'wpMovesubpages' )
-                                               ) . '&#160;' .
-                                               Xml::tags(
-                                                       'label',
-                                                       array( 'for' => 'wpMovesubpages' ),
-                                                       $this->msg(
-                                                               ( $this->oldTitle->hasSubpages()
-                                                                       ? 'move-subpages'
-                                                                       : 'move-talk-subpages' )
-                                                       )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
-                                               ) .
-                                       "</td>
-                               </tr>"
+                       $fields[] = new OOUI\FieldLayout(
+                               new OOUI\CheckboxInputWidget( array(
+                                       'name' => 'wpMovesubpages',
+                                       'id' => 'wpMovesubpages',
+                                       'value' => '1',
+                                       # Don't check the box if we only have talk subpages to
+                                       # move and we aren't moving the talk page.
+                                       'selected' => $this->moveSubpages && ( $this->oldTitle->hasSubpages() || $this->moveTalk ),
+                               ) ),
+                               array(
+                                       'label' => new OOUI\HtmlSnippet(
+                                               $this->msg(
+                                                       ( $this->oldTitle->hasSubpages()
+                                                               ? 'move-subpages'
+                                                               : 'move-talk-subpages' )
+                                               )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
+                                       ),
+                                       'align' => 'inline',
+                               )
                        );
                }
 
-               $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' )
-                       || $user->isWatched( $this->oldTitle ) );
                # Don't allow watching if user is not logged in
                if ( $user->isLoggedIn() ) {
-                       $out->addHTML( "
-                               <tr>
-                                       <td></td>
-                                       <td class='mw-input'>" .
-                                               Xml::checkLabel(
-                                                       $this->msg( 'move-watch' )->text(),
-                                                       'wpWatch',
-                                                       'watch',
-                                                       $watchChecked
-                                               ) .
-                                       "</td>
-                               </tr>"
+                       $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' )
+                               || $user->isWatched( $this->oldTitle ) );
+                       $fields[] = new OOUI\FieldLayout(
+                               new OOUI\CheckboxInputWidget( array(
+                                       'name' => 'wpWatch',
+                                       'id' => 'watch', # ew
+                                       'value' => '1',
+                                       'selected' => $watchChecked,
+                               ) ),
+                               array(
+                                       'label' => $this->msg( 'move-watch' )->text(),
+                                       'align' => 'inline',
+                               )
                        );
                }
 
                if ( $confirm ) {
-                       $out->addHTML( "
-                               <tr>
-                                       <td></td>
-                                       <td class='mw-input'>" .
-                                               Xml::checkLabel(
-                                                       $this->msg( 'delete_and_move_confirm' )->text(),
-                                                       'wpConfirm',
-                                                       'wpConfirm'
-                                               ) .
-                                       "</td>
-                               </tr>"
+                       $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' )
+                               || $user->isWatched( $this->oldTitle ) );
+                       $fields[] = new OOUI\FieldLayout(
+                               new OOUI\CheckboxInputWidget( array(
+                                       'name' => 'wpConfirm',
+                                       'id' => 'wpConfirm',
+                                       'value' => '1',
+                               ) ),
+                               array(
+                                       'label' => $this->msg( 'delete_and_move_confirm' )->text(),
+                                       'align' => 'inline',
+                               )
                        );
                }
 
-               $out->addHTML( "
-                       <tr>
-                               <td></td>
-                               <td class='mw-submit'>" .
-                                       Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
-                               "</td>
-                       </tr>"
+               $fields[] = new OOUI\FieldLayout(
+                       new OOUI\ButtonInputWidget( array(
+                               'name' => $submitVar,
+                               'value' => $movepagebtn,
+                               'label' => $movepagebtn,
+                               'flags' => array( 'progressive', 'primary' ),
+                               'type' => 'submit',
+                       ) ),
+                       array(
+                               'align' => 'top',
+                       )
+               );
+
+               $fieldset = new OOUI\FieldsetLayout( array(
+                       'label' => $this->msg( 'move-page-legend' )->text(),
+                       'id' => 'mw-movepage-table',
+                       'items' => $fields,
+               ) );
+
+               $form = new OOUI\FormLayout( array(
+                       'method' => 'post',
+                       'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
+                       'id' => 'movepage',
+               ) );
+               $form->appendContent(
+                       $fieldset,
+                       new OOUI\HtmlSnippet(
+                               Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
+                               Html::hidden( 'wpEditToken', $user->getEditToken() )
+                       )
                );
 
                $out->addHTML(
-                       Xml::closeElement( 'table' ) .
-                       Html::hidden( 'wpEditToken', $user->getEditToken() ) .
-                       Xml::closeElement( 'fieldset' ) .
-                       Xml::closeElement( 'form' ) .
-                       "\n"
+                       new OOUI\PanelLayout( array(
+                               'classes' => array( 'movepage-wrapper' ),
+                               'expanded' => false,
+                               'padded' => true,
+                               'framed' => true,
+                               'content' => $form,
+                       ) )
                );
 
                $this->showLogFragment( $this->oldTitle );
diff --git a/includes/widget/ComplexTitleInputWidget.php b/includes/widget/ComplexTitleInputWidget.php
new file mode 100644 (file)
index 0000000..73ef54c
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+/**
+ * MediaWiki Widgets – ComplexTitleInputWidget class.
+ *
+ * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+namespace MediaWiki\Widget;
+
+/**
+ * Complex title input widget.
+ */
+class ComplexTitleInputWidget extends \OOUI\Widget {
+
+       protected $namespace = null;
+       protected $title = null;
+
+       /**
+        * Like TitleInputWidget, but the namespace has to be input through a separate dropdown field.
+        *
+        * @param array $config Configuration options
+        * @param array $config['namespace'] Configuration for the NamespaceInputWidget dropdown with list
+        *     of namespaces
+        * @param array $config['title'] Configuration for the TitleInputWidget text field
+        */
+       public function __construct( array $config = array() ) {
+               // Configuration initialization
+               $config = array_merge(
+                       array(
+                               'namespace' => array(),
+                               'title' => array(),
+                       ),
+                       $config
+               );
+
+               // Parent constructor
+               parent::__construct( $config );
+
+               // Properties
+               $this->config = $config;
+               $this->namespace = new NamespaceInputWidget( $config['namespace'] );
+               $this->title = new TitleInputWidget( array_merge(
+                       $config['title'],
+                       array(
+                               // The inner TitleInputWidget shouldn't be infusable, only the ComplexTitleInputWidget itself can be.
+                               'infusable' => false,
+                               'relative' => true,
+                               'namespace' => isset( $config['namespace']['value'] ) ? $config['namespace']['value'] : null,
+                       )
+               ) );
+
+               // Initialization
+               $this
+                       ->addClasses( array( 'mw-widget-complexTitleInputWidget' ) )
+                       ->appendContent( $this->namespace, $this->title );
+       }
+
+       protected function getJavaScriptClassName() {
+               return 'mw.widgets.ComplexTitleInputWidget';
+       }
+
+       public function getConfig( &$config ) {
+               $config['namespace'] = $this->config['namespace'];
+               $config['title'] = $this->config['title'];
+               return parent::getConfig( $config );
+       }
+}
index a99227e..696c8ad 100644 (file)
@@ -18,6 +18,7 @@ class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
         * @param array $config Configuration options
         * @param string $config['includeAllValue'] If specified, add a "all namespaces" option to the
         *     namespace dropdown, and use this as the input value for it
+        * @param number[] $config['exclude'] List of namespace numbers to exclude from the selector
         */
        public function __construct( array $config = array() ) {
                // Configuration initialization
@@ -28,14 +29,17 @@ class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
 
                // Properties
                $this->includeAllValue = isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null;
+               $this->exclude = isset( $config['exclude'] ) ? $config['exclude'] : array();
 
                // Initialization
                $this->addClasses( array( 'mw-widget-namespaceInputWidget' ) );
        }
 
        protected function getNamespaceDropdownOptions( array $config ) {
-               $namespaceOptionsParams = isset( $config['includeAllValue'] ) ?
-                       array( 'all' => $config['includeAllValue'] ) : array();
+               $namespaceOptionsParams = array(
+                       'all' => isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null,
+                       'exclude' => isset( $config['exclude'] ) ? $config['exclude'] : null
+               );
                $namespaceOptions = \Html::namespaceSelectorOptions( $namespaceOptionsParams );
 
                $options = array();
@@ -55,6 +59,7 @@ class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
 
        public function getConfig( &$config ) {
                $config['includeAllValue'] = $this->includeAllValue;
+               $config['exclude'] = $this->exclude;
                // Skip DropdownInputWidget's getConfig(), we don't need 'options' config
                return \OOUI\InputWidget::getConfig( $config );
        }
index e21deb9..8579d05 100644 (file)
@@ -1567,7 +1567,14 @@ return array(
        ),
        'mediawiki.special.movePage' => array(
                'scripts' => 'resources/src/mediawiki.special/mediawiki.special.movePage.js',
-               'dependencies' => 'jquery.byteLimit',
+               'dependencies' => array(
+                       'jquery.byteLimit',
+                       'mediawiki.widgets',
+               ),
+       ),
+       'mediawiki.special.movePage.styles' => array(
+               'styles' => 'resources/src/mediawiki.special/mediawiki.special.movePage.css',
+               'position' => 'top',
        ),
        'mediawiki.special.pageLanguage' => array(
                'scripts' => 'resources/src/mediawiki.special/mediawiki.special.pageLanguage.js',
@@ -1845,6 +1852,7 @@ return array(
                        'resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js',
                        'resources/src/mediawiki.widgets/mw.widgets.ComplexNamespaceInputWidget.js',
                        'resources/src/mediawiki.widgets/mw.widgets.TitleInputWidget.js',
+                       'resources/src/mediawiki.widgets/mw.widgets.ComplexTitleInputWidget.js',
                        'resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js',
                        'resources/src/mediawiki.widgets/mw.widgets.UserInputWidget.js',
                ),
@@ -1885,6 +1893,7 @@ return array(
                'skinStyles' => array(
                        'default' => array(
                                'resources/src/mediawiki.widgets/mw.widgets.ComplexNamespaceInputWidget.base.css',
+                               'resources/src/mediawiki.widgets/mw.widgets.ComplexTitleInputWidget.base.css',
                        ),
                ),
                'position' => 'top',
diff --git a/resources/src/mediawiki.special/mediawiki.special.movePage.css b/resources/src/mediawiki.special/mediawiki.special.movePage.css
new file mode 100644 (file)
index 0000000..dd1c2aa
--- /dev/null
@@ -0,0 +1,8 @@
+/*!
+ * Styles for Special:MovePage
+ */
+
+.movepage-wrapper {
+       width: 50em;
+       margin: 1em 0;
+}
index 7e56050..6d88c51 100644 (file)
@@ -1,6 +1,7 @@
 /*!
  * JavaScript for Special:MovePage
  */
-jQuery( function ( $ ) {
-       $( '#wpReason, #wpNewTitleMain' ).byteLimit();
+jQuery( function () {
+       OO.ui.infuse( 'wpNewTitle' );
+       OO.ui.infuse( 'wpReason' ).$input.byteLimit();
 } );
diff --git a/resources/src/mediawiki.widgets/mw.widgets.ComplexTitleInputWidget.base.css b/resources/src/mediawiki.widgets/mw.widgets.ComplexTitleInputWidget.base.css
new file mode 100644 (file)
index 0000000..73a50d8
--- /dev/null
@@ -0,0 +1,20 @@
+/*!
+ * MediaWiki Widgets - base ComplexTitleInputWidget styles.
+ *
+ * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+
+.mw-widget-complexTitleInputWidget .mw-widget-namespaceInputWidget,
+.mw-widget-complexTitleInputWidget .mw-widget-titleInputWidget {
+       display: inline-block;
+}
+
+.mw-widget-complexTitleInputWidget .mw-widget-namespaceInputWidget {
+       max-width: 20em;
+       margin-right: 0.5em;
+}
+
+.mw-widget-complexTitleInputWidget .mw-widget-titleInputWidget {
+       max-width: 29.5em;
+}
diff --git a/resources/src/mediawiki.widgets/mw.widgets.ComplexTitleInputWidget.js b/resources/src/mediawiki.widgets/mw.widgets.ComplexTitleInputWidget.js
new file mode 100644 (file)
index 0000000..0c6c15e
--- /dev/null
@@ -0,0 +1,63 @@
+/*!
+ * MediaWiki Widgets - ComplexTitleInputWidget class.
+ *
+ * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+( function ( $, mw ) {
+
+       /**
+        * Like TitleInputWidget, but the namespace has to be input through a separate dropdown field.
+        *
+        * @class
+        * @extends OO.ui.Widget
+        *
+        * @constructor
+        * @param {Object} [config] Configuration options
+        * @cfg {Object} namespace Configuration for the NamespaceInputWidget dropdown with list of
+        *     namespaces
+        * @cfg {Object} title Configuration for the TitleInputWidget text field
+        */
+       mw.widgets.ComplexTitleInputWidget = function MwWidgetsComplexTitleInputWidget( config ) {
+               // Parent constructor
+               mw.widgets.ComplexTitleInputWidget.parent.call( this, config );
+
+               // Properties
+               this.namespace = new mw.widgets.NamespaceInputWidget( config.namespace );
+               this.title = new mw.widgets.TitleInputWidget( $.extend(
+                       {},
+                       config.title,
+                       {
+                               relative: true,
+                               namespace: config.namespace.value || null
+                       }
+               ) );
+
+               // Events
+               this.namespace.connect( this, { change: 'updateTitleNamespace' } );
+
+               // Initialization
+               this.$element
+                       .addClass( 'mw-widget-complexTitleInputWidget' )
+                       .append(
+                               this.namespace.$element,
+                               this.title.$element
+                       );
+               this.updateTitleNamespace();
+       };
+
+       /* Setup */
+
+       OO.inheritClass( mw.widgets.ComplexTitleInputWidget, OO.ui.Widget );
+
+       /* Methods */
+
+       /**
+        * Update the namespace to use for search suggestions of the title when the value of namespace
+        * dropdown changes.
+        */
+       mw.widgets.ComplexTitleInputWidget.prototype.updateTitleNamespace = function () {
+               this.title.setNamespace( Number( this.namespace.getValue() ) );
+       };
+
+}( jQuery, mediaWiki ) );
index ef42dc1..4f1b874 100644 (file)
@@ -14,7 +14,8 @@
         *
         * @constructor
         * @param {Object} [config] Configuration options
-        * @cfg {string|null} includeAllValue Value for "all namespaces" option, if any
+        * @cfg {string|null} [includeAllValue] Value for "all namespaces" option, if any
+        * @cfg {number[]} [exclude] List of namespace numbers to exclude from the selector
         */
        mw.widgets.NamespaceInputWidget = function MwWidgetsNamespaceInputWidget( config ) {
                // Configuration initialization
         */
        mw.widgets.NamespaceInputWidget.prototype.getNamespaceDropdownOptions = function ( config ) {
                var options,
+                       exclude = config.exclude || [],
                        NS_MAIN = 0;
 
                options = $.map( mw.config.get( 'wgFormattedNamespaces' ), function ( name, ns ) {
-                       if ( ns < NS_MAIN ) {
+                       if ( ns < NS_MAIN || exclude.indexOf( Number( ns ) ) !== -1 ) {
                                return null; // skip
                        }
                        ns = String( ns );
index cf4d788..c9c9f03 100644 (file)
 
        /* Methods */
 
+       /**
+        * Get the namespace to prepend to titles in suggestions, if any.
+        *
+        * @return {number|null} Namespace number
+        */
+       mw.widgets.TitleInputWidget.prototype.getNamespace = function () {
+               return this.namespace;
+       };
+
+       /**
+        * Set the namespace to prepend to titles in suggestions, if any.
+        *
+        * @param {number|null} namespace Namespace number
+        */
+       mw.widgets.TitleInputWidget.prototype.setNamespace = function ( namespace ) {
+               this.namespace = namespace;
+               this.lookupCache = {};
+               this.closeLookupMenu();
+       };
+
        /**
         * @inheritdoc
         */