r77980 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77979‎ | r77980 | r77981 >
Date:14:45, 7 December 2010
Author:dantman
Status:resolved
Tags:
Comment:
Add makeSearchInput and makeSearchButton to BaseTemplate and make use of it in Vector and MonoBook to abstract away the various inputs inside search forms.
Modified paths:
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/skins/MonoBook.php (modified) (history)
  • /trunk/phase3/skins/Vector.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/Vector.php
@@ -745,13 +745,14 @@
746746 <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
747747 <?php if ( $wgVectorUseSimpleSearch && $wgUser->getOption( 'vector-simplesearch' ) ): ?>
748748 <div id="simpleSearch">
749 - <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; ?> />
750 - <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>
 749+ <?php echo $this->makeSearchInput(array( "id" => "searchInput" )); ?>
 750+ <?php echo $this->makeSearchButton("image", array( "id" => "searchButton",
 751+ "src" => $this->skin->getSkinStylePath('images/search-' . ( $this->data['rtl'] ? 'rtl' : 'ltr' ) . '.png') )); ?>
751752 </div>
752753 <?php else: ?>
753 - <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; ?> />
754 - <input type='submit' name="go" class="searchButton" id="searchGoButton" value="<?php $this->msg( 'searcharticle' ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-go' ); ?> />
755 - <input type="submit" name="fulltext" class="searchButton" id="mw-searchButton" value="<?php $this->msg( 'searchbutton' ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?> />
 754+ <?php echo $this->makeSearchInput(array( "id" => "searchInput" )); ?>
 755+ <?php echo $this->makeSearchButton("go", array( "id" => "searchGoButton", "class" => "searchButton" )); ?>
 756+ <?php echo $this->makeSearchButton("fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" )); ?>
756757 <?php endif; ?>
757758 </form>
758759 </div>
Index: trunk/phase3/skins/MonoBook.php
@@ -241,19 +241,15 @@
242242 <div id="searchBody" class="pBody">
243243 <form action="<?php $this->text('wgScript') ?>" id="searchform">
244244 <input type='hidden' name="title" value="<?php $this->text('searchtitle') ?>"/>
245 - <?php
246 - echo Html::input( 'search',
247 - isset( $this->data['search'] ) ? $this->data['search'] : '', 'search',
248 - array(
249 - 'id' => 'searchInput',
250 - 'title' => $this->skin->titleAttrib( 'search' ),
251 - 'accesskey' => $this->skin->accesskey( 'search' )
252 - ) ); ?>
 245+ <?php echo $this->makeSearchInput(array( "id" => "searchInput" )); ?>
253246
254 - <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;
255 - <input type='submit' name="fulltext" class="searchButton" id="mw-searchButton" value="<?php $this->msg('searchbutton') ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?> /><?php } else { ?>
 247+ <?php echo $this->makeSearchButton("go", array( "id" => "searchGoButton", "class" => "searchButton" ));
 248+ if ($wgUseTwoButtonsSearchForm): ?>&#160;
 249+ <?php echo $this->makeSearchButton("fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" ));
 250+ else: ?>
256251
257 - <div><a href="<?php $this->text('searchaction') ?>" rel="search"><?php $this->msg('powersearch-legend') ?></a></div><?php } ?>
 252+ <div><a href="<?php $this->text('searchaction') ?>" rel="search"><?php $this->msg('powersearch-legend') ?></a></div><?php
 253+ endif; ?>
258254
259255 </form>
260256 </div>
Index: trunk/phase3/includes/SkinTemplate.php
@@ -1355,6 +1355,44 @@
13561356 return Html::rawElement( isset($options["tag"]) ? $options["tag"] : "li", $attrs, $html );
13571357 }
13581358
 1359+ function makeSearchInput($attrs = array()) {
 1360+ $realAttrs = array(
 1361+ "type" => "search",
 1362+ "name" => "search",
 1363+ "value" => isset($this->data['search']) ? $this->data['search'] : '',
 1364+ );
 1365+ $realAttrs = array_merge($realAttrs, $this->skin->tooltipAndAccesskeyAttribs('search'), $attrs);
 1366+ return Html::element( "input", $realAttrs );
 1367+ }
13591368
 1369+ function makeSearchButton($mode, $attrs = array()) {
 1370+ switch($mode) {
 1371+ case "go":
 1372+ case "fulltext":
 1373+ $realAttrs = array(
 1374+ "type" => "submit",
 1375+ "name" => $mode,
 1376+ "value" => $this->translator->translate( $mode == "go" ? "searcharticle" : "searchbutton" ),
 1377+ );
 1378+ $realAttrs = array_merge($realAttrs, $this->skin->tooltipAndAccesskeyAttribs("search-$mode"), $attrs);
 1379+ return Html::element( "input", $realAttrs );
 1380+ case "image":
 1381+ $buttonAttrs = array(
 1382+ "type" => "submit",
 1383+ "name" => "button",
 1384+ );
 1385+ $buttonAttrs = array_merge($buttonAttrs, $this->skin->tooltipAndAccesskeyAttribs("search-fulltext"), $attrs);
 1386+ unset($buttonAttrs["src"]);
 1387+ unset($buttonAttrs["alt"]);
 1388+ $imgAttrs = array(
 1389+ "src" => $attrs["src"],
 1390+ "alt" => isset($attrs["alt"]) ? $attrs["alt"] : $this->translator->translate( "searchbutton" ),
 1391+ );
 1392+ return Html::rawElement( "button", $buttonAttrs, Html::element( "img", $imgAttrs ) );
 1393+ default:
 1394+ throw new MWException("Unknown mode passed to BaseTemplate::makeSearchButton");
 1395+ }
 1396+ }
 1397+
13601398 }
13611399

Follow-up revisions

RevisionCommit summaryAuthorDate
r77997Followup r77980, for simplesearch I guess we'll have to stick with type=text ...dantman18:18, 7 December 2010

Status & tagging log