SpecialNewpages: Prepare for mw-ui
authorFlorianschmidtwelzow <florian.schmidt.welzow@t-online.de>
Sat, 4 Oct 2014 14:35:54 +0000 (16:35 +0200)
committerFlorianschmidtwelzow <florian.schmidt.welzow@t-online.de>
Wed, 15 Oct 2014 21:25:11 +0000 (23:25 +0200)
Use HTMLForm instead of self-built table structure, to be
prepared for use with MediaWiki UI.

Bug: 71446
Change-Id: I5c03dc543b910aab27a26a5a223341be50893cf3

includes/AutoLoader.php
includes/htmlform/HTMLForm.php
includes/htmlform/HTMLSelectNamespace.php [new file with mode: 0644]
includes/htmlform/HTMLTagFilter.php [new file with mode: 0644]
includes/specials/SpecialNewpages.php

index cd6a8ca..6909b8f 100644 (file)
@@ -106,6 +106,8 @@ $wgAutoloadLocalClasses = array(
        'HTMLSelectField' => 'includes/htmlform/HTMLSelectField.php',
        'HTMLSelectLimitField' => 'includes/htmlform/HTMLSelectLimitField.php',
        'HTMLSelectOrOtherField' => 'includes/htmlform/HTMLSelectOrOtherField.php',
+       'HTMLSelectNamespace' => 'includes/htmlform/HTMLSelectNamespace.php',
+       'HTMLTagFilter' => 'includes/htmlform/HTMLTagFilter.php',
        'HTMLSubmitField' => 'includes/htmlform/HTMLSubmitField.php',
        'HTMLTextAreaField' => 'includes/htmlform/HTMLTextAreaField.php',
        'HTMLTextField' => 'includes/htmlform/HTMLTextField.php',
index 4511046..62345b8 100644 (file)
@@ -115,6 +115,8 @@ class HTMLForm extends ContextSource {
                'info' => 'HTMLInfoField',
                'selectorother' => 'HTMLSelectOrOtherField',
                'selectandother' => 'HTMLSelectAndOtherField',
+               'namespaceselect' => 'HTMLSelectNamespace',
+               'tagfilter' => 'HTMLTagFilter',
                'submit' => 'HTMLSubmitField',
                'hidden' => 'HTMLHiddenField',
                'edittools' => 'HTMLEditTools',
diff --git a/includes/htmlform/HTMLSelectNamespace.php b/includes/htmlform/HTMLSelectNamespace.php
new file mode 100644 (file)
index 0000000..9638106
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Wrapper for Html::namespaceSelector to use in HTMLForm
+ */
+class HTMLSelectNamespace extends HTMLFormField {
+       function getInputHTML( $value ) {
+               return Html::namespaceSelector(
+                       array(
+                               'selected' => $value,
+                               'all' => 'all'
+                       ), array(
+                               'name' => $this->mName,
+                               'id' => $this->mID,
+                               'class' => 'namespaceselector',
+                       )
+               );
+       }
+}
diff --git a/includes/htmlform/HTMLTagFilter.php b/includes/htmlform/HTMLTagFilter.php
new file mode 100644 (file)
index 0000000..da5e85c
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Wrapper for ChgangeTags::buildTagFilterSelector to use in HTMLForm
+ */
+class HTMLTagFilter extends HTMLFormField {
+       function getInputHTML( $value ) {
+               $tagFilter = ChangeTags::buildTagFilterSelector( $value );
+               if ( $tagFilter ) {
+                       list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter;
+                       // we only need the select field, HTMLForm should handle the label
+                       return $tagFilterSelector;
+               }
+               return;
+       }
+}
index 3a74e7a..5b34297 100644 (file)
@@ -198,6 +198,7 @@ class SpecialNewpages extends IncludableSpecialPage {
        }
 
        protected function form() {
+               $out = $this->getOutput();
                // Consume values
                $this->opts->consumeValue( 'offset' ); // don't carry offset, DWIW
                $namespace = $this->opts->consumeValue( 'namespace' );
@@ -216,77 +217,62 @@ class SpecialNewpages extends IncludableSpecialPage {
                }
                $hidden = implode( "\n", $hidden );
 
-               $tagFilter = ChangeTags::buildTagFilterSelector( $tagFilterVal );
-               if ( $tagFilter ) {
-                       list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter;
-               }
+               $form = array(
+                       'namespace' => array(
+                               'type' => 'namespaceselect',
+                               'name' => 'namespace',
+                               'label-message' => 'namespace',
+                               'default' => $namespace,
+                       ),
+                       'nsinvert' => array(
+                               'type' => 'check',
+                               'name' => 'nsinvert',
+                               'label-message' => 'invert',
+                               'default' => $nsinvert,
+                               'tooltip' => $this->msg( 'tooltip-invert' )->text(),
+                       ),
+                       'tagFilter' => array(
+                               'type' => 'tagfilter',
+                               'name' => 'tagfilter',
+                               'label-raw' => wfMessage( 'tag-filter' )->parse(),
+                               'default' => $tagFilterVal,
+                       ),
+                       'username' => array(
+                               'type' => 'text',
+                               'name' => 'username',
+                               'label-message' => 'newpages-username',
+                               'default' => $userText,
+                               'id' => 'mw-np-username',
+                               'size' => 30,
+                               'cssclass' => 'mw-autocomplete-user', // used by mediawiki.userSuggest
+                       ),
+               );
+
+               $htmlForm = new HTMLForm( $form, $this->getContext() );
+
+               $htmlForm->setSubmitText( $this->msg( 'allpagessubmit' )->text() );
+               $htmlForm->setSubmitProgressive();
+               // The form should be visible on each request (inclusive requests with submitted forms), so
+               // return always false here.
+               $htmlForm->setSubmitCallback(
+                       function() {
+                               return false;
+                       }
+               );
+               $htmlForm->setMethod( 'get' );
+
+               $out->addHtml( Xml::fieldset( $this->msg( 'newpages' )->text() ) );
 
-               $this->getOutput()->addModules( 'mediawiki.userSuggest' );
-
-               $form = Xml::openElement( 'form', array( 'action' => wfScript() ) ) .
-                       Html::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
-                       Xml::fieldset( $this->msg( 'newpages' )->text() ) .
-                       Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
-                       '<tr>
-                               <td class="mw-label">' .
-                       Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ) .
-                       '</td>
-                       <td class="mw-input">' .
-                       Html::namespaceSelector(
-                               array(
-                                       'selected' => $namespace,
-                                       'all' => 'all',
-                               ), array(
-                                       'name' => 'namespace',
-                                       'id' => 'namespace',
-                                       'class' => 'namespaceselector',
-                               )
-                       ) . '&#160;' .
-                       Xml::checkLabel(
-                               $this->msg( 'invert' )->text(),
-                               'invert',
-                               'nsinvert',
-                               $nsinvert,
-                               array( 'title' => $this->msg( 'tooltip-invert' )->text() )
+               $htmlForm->show();
+
+               $out->addHtml(
+                       Html::rawElement(
+                               'div',
+                               null,
+                               $this->filterLinks()
                        ) .
-                       '</td>
-                       </tr>' . ( $tagFilter ? (
-                       '<tr>
-                               <td class="mw-label">' .
-                               $tagFilterLabel .
-                               '</td>
-                               <td class="mw-input">' .
-                               $tagFilterSelector .
-                               '</td>
-                       </tr>' ) : '' ) .
-                       '<tr>
-                               <td class="mw-label">' .
-                                       Xml::label( $this->msg( 'newpages-username' )->text(), 'mw-np-username' ) .
-                                       '</td>
-                               <td class="mw-input">' .
-                                       Xml::input( 'username', 30, $userText, array(
-                                               'id' => 'mw-np-username',
-                                               'class' => 'mw-autocomplete-user', // used by mediawiki.userSuggest
-                                       ) ) .
-                                       '</td>
-                       </tr>' .
-                       '<tr> <td></td>
-                               <td class="mw-submit">' .
-                       Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) .
-                       '</td>
-               </tr>' .
-                       '<tr>
-                               <td></td>
-                               <td class="mw-input">' .
-                       $this->filterLinks() .
-                       '</td>
-                       </tr>' .
-                       Xml::closeElement( 'table' ) .
-                       Xml::closeElement( 'fieldset' ) .
-                       $hidden .
-                       Xml::closeElement( 'form' );
-
-               $this->getOutput()->addHTML( $form );
+                       Xml::closeElement( 'fieldset' )
+               );
        }
 
        /**