Add makeSearchInput and makeSearchButton to BaseTemplate and make use of it in Vector...
authorDaniel Friesen <dantman@users.mediawiki.org>
Tue, 7 Dec 2010 14:45:40 +0000 (14:45 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Tue, 7 Dec 2010 14:45:40 +0000 (14:45 +0000)
includes/SkinTemplate.php
skins/MonoBook.php
skins/Vector.php

index a9324ce..7617194 100644 (file)
@@ -1355,6 +1355,44 @@ abstract class BaseTemplate extends QuickTemplate {
                return Html::rawElement( isset($options["tag"]) ? $options["tag"] : "li", $attrs, $html );
        }
 
+       function makeSearchInput($attrs = array()) {
+               $realAttrs = array(
+                       "type" => "search",
+                       "name" => "search",
+                       "value" => isset($this->data['search']) ? $this->data['search'] : '',
+               );
+               $realAttrs = array_merge($realAttrs, $this->skin->tooltipAndAccesskeyAttribs('search'), $attrs);
+               return Html::element( "input", $realAttrs );
+       }
+       
+       function makeSearchButton($mode, $attrs = array()) {
+               switch($mode) {
+               case "go":
+               case "fulltext":
+                       $realAttrs = array(
+                               "type" => "submit",
+                               "name" => $mode,
+                               "value" => $this->translator->translate( $mode == "go" ? "searcharticle" : "searchbutton" ),
+                       );
+                       $realAttrs = array_merge($realAttrs, $this->skin->tooltipAndAccesskeyAttribs("search-$mode"), $attrs);
+                       return Html::element( "input", $realAttrs );
+               case "image":
+                       $buttonAttrs = array(
+                               "type" => "submit",
+                               "name" => "button",
+                       );
+                       $buttonAttrs = array_merge($buttonAttrs, $this->skin->tooltipAndAccesskeyAttribs("search-fulltext"), $attrs);
+                       unset($buttonAttrs["src"]);
+                       unset($buttonAttrs["alt"]);
+                       $imgAttrs = array(
+                               "src" => $attrs["src"],
+                               "alt" => isset($attrs["alt"]) ? $attrs["alt"] : $this->translator->translate( "searchbutton" ),
+                       );
+                       return Html::rawElement( "button", $buttonAttrs, Html::element( "img", $imgAttrs ) );
+               default:
+                       throw new MWException("Unknown mode passed to BaseTemplate::makeSearchButton");
+               }
+       }
        
 }
 
index b57a45d..ad50090 100644 (file)
@@ -241,19 +241,15 @@ class MonoBookTemplate extends BaseTemplate {
                <div id="searchBody" class="pBody">
                        <form action="<?php $this->text('wgScript') ?>" id="searchform">
                                <input type='hidden' name="title" value="<?php $this->text('searchtitle') ?>"/>
-                               <?php
-               echo Html::input( 'search',
-                       isset( $this->data['search'] ) ? $this->data['search'] : '', 'search',
-                       array(
-                               'id' => 'searchInput',
-                               'title' => $this->skin->titleAttrib( 'search' ),
-                               'accesskey' => $this->skin->accesskey( 'search' )
-                       ) ); ?>
+                               <?php echo $this->makeSearchInput(array( "id" => "searchInput" )); ?>
 
-                               <input type='submit' name="go" class="searchButton" id="searchGoButton" value="<?php $this->msg('searcharticle') ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-go' ); ?> /><?php if ($wgUseTwoButtonsSearchForm) { ?>&#160;
-                               <input type='submit' name="fulltext" class="searchButton" id="mw-searchButton" value="<?php $this->msg('searchbutton') ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?> /><?php } else { ?>
+                               <?php echo $this->makeSearchButton("go", array( "id" => "searchGoButton", "class" => "searchButton" ));
+                               if ($wgUseTwoButtonsSearchForm): ?>&#160;
+                               <?php echo $this->makeSearchButton("fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" ));
+                               else: ?>
 
-                               <div><a href="<?php $this->text('searchaction') ?>" rel="search"><?php $this->msg('powersearch-legend') ?></a></div><?php } ?>
+                               <div><a href="<?php $this->text('searchaction') ?>" rel="search"><?php $this->msg('powersearch-legend') ?></a></div><?php
+                               endif; ?>
 
                        </form>
                </div>
index 197d6bb..bf970d9 100644 (file)
@@ -745,13 +745,14 @@ class VectorTemplate extends BaseTemplate {
                <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
                <?php if ( $wgVectorUseSimpleSearch && $wgUser->getOption( 'vector-simplesearch' ) ): ?>
                <div id="simpleSearch">
-                       <input id="searchInput" name="search" type="text" <?php echo $this->skin->tooltipAndAccesskey( 'search' ); ?> <?php if( isset( $this->data['search'] ) ): ?> value="<?php $this->text( 'search' ) ?>"<?php endif; ?> />
-                       <button id="searchButton" type='submit' name='button' <?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?>><img src="<?php echo $this->skin->getSkinStylePath('images/search-' . ( $this->data['rtl'] ? 'rtl' : 'ltr' ) . '.png'); ?>" alt="<?php $this->msg( 'searchbutton' ) ?>" /></button>
+                       <?php echo $this->makeSearchInput(array( "id" => "searchInput" )); ?>
+                       <?php echo $this->makeSearchButton("image", array( "id" => "searchButton",
+                               "src" => $this->skin->getSkinStylePath('images/search-' . ( $this->data['rtl'] ? 'rtl' : 'ltr' ) . '.png') )); ?>
                </div>
                <?php else: ?>
-               <input id="searchInput" name="search" type="text" <?php echo $this->skin->tooltipAndAccesskey( 'search' ); ?> <?php if( isset( $this->data['search'] ) ): ?> value="<?php $this->text( 'search' ) ?>"<?php endif; ?> />
-               <input type='submit' name="go" class="searchButton" id="searchGoButton" value="<?php $this->msg( 'searcharticle' ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-go' ); ?> />
-               <input type="submit" name="fulltext" class="searchButton" id="mw-searchButton" value="<?php $this->msg( 'searchbutton' ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?> />
+               <?php echo $this->makeSearchInput(array( "id" => "searchInput" )); ?>
+               <?php echo $this->makeSearchButton("go", array( "id" => "searchGoButton", "class" => "searchButton" )); ?>
+               <?php echo $this->makeSearchButton("fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" )); ?>
                <?php endif; ?>
        </form>
 </div>