Use HTMLForm for Special:LinkSerach
authorFlorian <florian.schmidt.welzow@t-online.de>
Sun, 19 Apr 2015 19:10:45 +0000 (21:10 +0200)
committerFlorian <florian.schmidt.welzow@t-online.de>
Sun, 19 Apr 2015 19:10:45 +0000 (21:10 +0200)
* Convert Special:LinkSearch to use HTMLForm for preparation of MediaWiki
  UI everywhere
* Add support for dir= tag in HTMLTextField

Bug: T73439
Change-Id: I8503c391a40f1654f8570578a9de9015d86c9845

includes/htmlform/HTMLForm.php
includes/htmlform/HTMLFormField.php
includes/htmlform/HTMLTextField.php
includes/specials/SpecialLinkSearch.php

index 39ed24f..dcd8508 100644 (file)
@@ -51,6 +51,7 @@
  *    'id'                  -- HTML id attribute
  *    'cssclass'            -- CSS class
  *    'csshelpclass'        -- CSS class used to style help text
+ *    'dir'                 -- Direction of the element.
  *    'options'             -- associative array mapping labels to values.
  *                             Some field types support multi-level arrays.
  *    'options-messages'    -- associative array mapping message keys to values.
index 9576c77..0c3fe44 100644 (file)
@@ -10,6 +10,7 @@ abstract class HTMLFormField {
        protected $mValidationCallback;
        protected $mFilterCallback;
        protected $mName;
+       protected $mDir;
        protected $mLabel; # String label.  Set on construction
        protected $mID;
        protected $mClass = '';
@@ -377,6 +378,10 @@ abstract class HTMLFormField {
                        $this->mName = $params['name'];
                }
 
+               if ( isset( $params['dir'] ) ) {
+                       $this->mDir = $params['dir'];
+               }
+
                $validName = Sanitizer::escapeId( $this->mName );
                $validName = str_replace( array( '.5B', '.5D' ), array( '[', ']' ), $validName );
                if ( $this->mName != $validName && !isset( $params['nodata'] ) ) {
index 88df49d..a67e52e 100644 (file)
@@ -11,6 +11,7 @@ class HTMLTextField extends HTMLFormField {
                                'name' => $this->mName,
                                'size' => $this->getSize(),
                                'value' => $value,
+                               'dir' => $this->mDir,
                        ) + $this->getTooltipAndAccessKey();
 
                if ( $this->mClass !== '' ) {
index 75ff8f3..0c02628 100644 (file)
@@ -121,43 +121,39 @@ class LinkSearchPage extends QueryPage {
                        '<nowiki>' . $this->getLanguage()->commaList( $protocols_list ) . '</nowiki>',
                        count( $protocols_list )
                );
-               $s = Html::openElement(
-                       'form',
-                       array( 'id' => 'mw-linksearch-form', 'method' => 'get', 'action' => wfScript() )
-               ) . "\n" .
-                       Html::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) . "\n" .
-                       Html::openElement( 'fieldset' ) . "\n" .
-                       Html::element( 'legend', array(), $this->msg( 'linksearch' )->text() ) . "\n" .
-                       Xml::inputLabel(
-                               $this->msg( 'linksearch-pat' )->text(),
-                               'target',
-                               'target',
-                               50,
-                               $target,
-                               array(
-                                       // URLs are always ltr
-                                       'dir' => 'ltr',
-                               )
-                       ) . "\n";
-
+               $fields = array(
+                       'target' => array(
+                               'type' => 'text',
+                               'name' => 'target',
+                               'id' => 'target',
+                               'size' => 50,
+                               'label-message' => 'linksearch-pat',
+                               'default' => $target,
+                               'dir' => 'ltr',
+                       )
+               );
                if ( !$this->getConfig()->get( 'MiserMode' ) ) {
-                       $s .= Html::namespaceSelector(
-                               array(
-                                       'selected' => $namespace,
-                                       'all' => '',
-                                       'label' => $this->msg( 'linksearch-ns' )->text()
-                               ), array(
+                       $fields += array(
+                               'namespace' => array(
+                                       'class' => 'HTMLSelectNamespace',
                                        'name' => 'namespace',
+                                       'label-message' => 'linksearch-ns',
+                                       'default' => $namespace,
                                        'id' => 'namespace',
-                                       'class' => 'namespaceselector',
-                               )
+                                       'cssclass' => 'namespaceselector',
+                               ),
                        );
                }
-
-               $s .= Xml::submitButton( $this->msg( 'linksearch-ok' )->text() ) . "\n" .
-                       Html::closeElement( 'fieldset' ) . "\n" .
-                       Html::closeElement( 'form' ) . "\n";
-               $out->addHTML( $s );
+               $hiddenFields = array(
+                       'title' => $this->getPageTitle()->getPrefixedDBkey(),
+               );
+               $htmlForm = HTMLForm::factory( 'inline', $fields, $this->getContext() );
+               $htmlForm->addHiddenFields( $hiddenFields );
+               $htmlForm->setSubmitTextMsg( 'linksearch-ok' );
+               $htmlForm->setWrapperLegendMsg( 'linksearch' );
+               $htmlForm->setAction( wfScript() );
+               $htmlForm->setMethod( 'get' );
+               $htmlForm->prepareForm()->displayForm( false );
 
                if ( $target != '' ) {
                        $this->setParams( array(