From 20984575bbf141a530ee6d33567038703cd056b8 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Tue, 7 Dec 2010 14:45:40 +0000 Subject: [PATCH] Add makeSearchInput and makeSearchButton to BaseTemplate and make use of it in Vector and MonoBook to abstract away the various inputs inside search forms. --- includes/SkinTemplate.php | 38 ++++++++++++++++++++++++++++++++++++++ skins/MonoBook.php | 18 +++++++----------- skins/Vector.php | 11 ++++++----- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index a9324ce458..76171948d4 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -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"); + } + } } diff --git a/skins/MonoBook.php b/skins/MonoBook.php index b57a45d7ec..ad500900d1 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -241,19 +241,15 @@ class MonoBookTemplate extends BaseTemplate {
- data['search'] ) ? $this->data['search'] : '', 'search', - array( - 'id' => 'searchInput', - 'title' => $this->skin->titleAttrib( 'search' ), - 'accesskey' => $this->skin->accesskey( 'search' ) - ) ); ?> + makeSearchInput(array( "id" => "searchInput" )); ?> - skin->tooltipAndAccesskey( 'search-go' ); ?> />  - skin->tooltipAndAccesskey( 'search-fulltext' ); ?> /> + makeSearchButton("go", array( "id" => "searchGoButton", "class" => "searchButton" )); + if ($wgUseTwoButtonsSearchForm): ?>  + makeSearchButton("fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" )); + else: ?> -
+
diff --git a/skins/Vector.php b/skins/Vector.php index 197d6bb859..bf970d90c9 100644 --- a/skins/Vector.php +++ b/skins/Vector.php @@ -745,13 +745,14 @@ class VectorTemplate extends BaseTemplate { getOption( 'vector-simplesearch' ) ): ?>
- skin->tooltipAndAccesskey( 'search' ); ?> data['search'] ) ): ?> value="text( 'search' ) ?>" /> - + makeSearchInput(array( "id" => "searchInput" )); ?> + makeSearchButton("image", array( "id" => "searchButton", + "src" => $this->skin->getSkinStylePath('images/search-' . ( $this->data['rtl'] ? 'rtl' : 'ltr' ) . '.png') )); ?>
- skin->tooltipAndAccesskey( 'search' ); ?> data['search'] ) ): ?> value="text( 'search' ) ?>" /> - skin->tooltipAndAccesskey( 'search-go' ); ?> /> - skin->tooltipAndAccesskey( 'search-fulltext' ); ?> /> + makeSearchInput(array( "id" => "searchInput" )); ?> + makeSearchButton("go", array( "id" => "searchGoButton", "class" => "searchButton" )); ?> + makeSearchButton("fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" )); ?> -- 2.20.1