protected $searchEngineType;
/** @var array For links */
- protected $extraParams = array();
+ protected $extraParams = [];
/**
* @var string The prefix url parameter. Set on the searcher and the
$this->outputHeader();
$out = $this->getOutput();
$out->allowClickjacking();
- $out->addModuleStyles( array(
+ $out->addModuleStyles( [
'mediawiki.special', 'mediawiki.special.search', 'mediawiki.ui', 'mediawiki.ui.button',
'mediawiki.ui.input',
- ) );
+ ] );
$this->addHelpLink( 'Help:Searching' );
// Strip underscores from title parameter; most of the time we'll want
return;
}
- $out->addJsConfigVars( array( 'searchTerm' => $search ) );
+ $out->addJsConfigVars( [ 'searchTerm' => $search ] );
$this->searchEngineType = $request->getVal( 'srbackend' );
if ( $request->getVal( 'fulltext' )
# If there's an exact or very near match, jump right there.
$title = SearchEngine::getNearMatch( $term );
- if ( !is_null( $title ) ) {
- $this->getOutput()->redirect( $title->getFullURL() );
+ if ( !is_null( $title ) &&
+ Hooks::run( 'SpecialSearchGoResult', [ $term, $title, &$url ] )
+ ) {
+ if ( $url === null ) {
+ $url = $title->getFullURL();
+ }
+ $this->getOutput()->redirect( $url );
return;
}
# No match, generate an edit URL
$title = Title::newFromText( $term );
if ( !is_null( $title ) ) {
- Hooks::run( 'SpecialSearchNogomatch', array( &$title ) );
+ Hooks::run( 'SpecialSearchNogomatch', [ &$title ] );
}
$this->showResults( $term );
}
$search->prefix = $this->mPrefix;
$term = $search->transformSearchTerm( $term );
- Hooks::run( 'SpecialSearchSetupEngine', array( $this, $this->profile, $search ) );
+ Hooks::run( 'SpecialSearchSetupEngine', [ $this, $this->profile, $search ] );
$this->setupPage( $term );
Xml::element( 'legend', null, $this->msg( 'search-external' )->text() ) .
Xml::element(
'p',
- array( 'class' => 'mw-searchdisabled' ),
+ [ 'class' => 'mw-searchdisabled' ],
$this->msg( 'searchdisabled' )->text()
) .
$this->msg( 'googlesearch' )->rawParams(
}
}
- if ( !Hooks::run( 'SpecialSearchResultsPrepend', array( $this, $out, $term ) ) ) {
+ if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) {
# Hook requested termination
return;
}
$out->addHtml(
Xml::openElement(
'form',
- array(
+ [
'id' => ( $this->isPowerSearch() ? 'powersearch' : 'search' ),
'method' => 'get',
'action' => wfScript(),
- )
+ ]
)
);
# This is an awful awful ID name. It's not a table, but we
# named it poorly from when this was a table so now we're
# stuck with it
- Xml::openElement( 'div', array( 'id' => 'mw-search-top-table' ) ) .
+ Xml::openElement( 'div', [ 'id' => 'mw-search-top-table' ] ) .
$this->shortDialog( $term, $num, $totalRes ) .
Xml::closeElement( 'div' ) .
$this->searchProfileTabs( $term ) .
$this->getPageTitle(),
$this->offset,
$this->limit,
- $this->powerSearchOptions() + array( 'search' => $term ),
+ $this->powerSearchOptions() + [ 'search' => $term ],
$this->limit + $this->offset >= $totalRes
);
}
}
- Hooks::run( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
+ Hooks::run( 'SpecialSearchResults', [ $term, &$titleMatches, &$textMatches ] );
$out->parserOptions()->setEditSection( false );
if ( $titleMatches ) {
} else {
$this->showCreateLink( $title, $num, $titleMatches, $textMatches );
$out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>",
- array( $hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound',
+ [ $hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound',
wfEscapeWikiText( $term )
- ) );
+ ] );
}
}
$out->addHtml( "</div>" );
- Hooks::run( 'SpecialSearchResultsAppend', array( $this, $out, $term ) );
+ Hooks::run( 'SpecialSearchResultsAppend', [ $this, $out, $term ] );
}
*/
protected function getDidYouMeanHtml( SearchResultSet $textMatches ) {
# mirror Go/Search behavior of original request ..
- $params = array( 'search' => $textMatches->getSuggestionQuery() );
+ $params = [ 'search' => $textMatches->getSuggestionQuery() ];
if ( $this->fulltext != null ) {
$params['fulltext'] = $this->fulltext;
}
$suggest = Linker::linkKnown(
$this->getPageTitle(),
$textMatches->getSuggestionSnippet() ?: null,
- array( 'id' => 'mw-search-DYM-suggestion' ),
+ [ 'id' => 'mw-search-DYM-suggestion' ],
$stParams
);
# HTML of did you mean... search suggestion link
return Html::rawElement(
'div',
- array( 'class' => 'searchdidyoumean' ),
+ [ 'class' => 'searchdidyoumean' ],
$this->msg( 'search-suggest' )->rawParams( $suggest )->parse()
);
}
// Showing results for '$rewritten'
// Search instead for '$orig'
- $params = array( 'search' => $textMatches->getQueryAfterRewrite() );
+ $params = [ 'search' => $textMatches->getQueryAfterRewrite() ];
if ( $this->fulltext != null ) {
$params['fulltext'] = $this->fulltext;
}
$rewritten = Linker::linkKnown(
$this->getPageTitle(),
$textMatches->getQueryAfterRewriteSnippet() ?: null,
- array( 'id' => 'mw-search-DYM-rewritten' ),
+ [ 'id' => 'mw-search-DYM-rewritten' ],
$stParams
);
$original = Linker::linkKnown(
$this->getPageTitle(),
htmlspecialchars( $term ),
- array( 'id' => 'mw-search-DYM-original' ),
+ [ 'id' => 'mw-search-DYM-original' ],
$stParams
);
return Html::rawElement(
'div',
- array( 'class' => 'searchdidyoumean' ),
+ [ 'class' => 'searchdidyoumean' ],
$this->msg( 'search-rewritten' )->rawParams( $rewritten, $original )->escaped()
);
}
}
}
- $params = array(
+ $params = [
$messageName,
wfEscapeWikiText( $title->getPrefixedText() ),
Message::numParam( $num )
- );
- Hooks::run( 'SpecialSearchCreateLink', array( $title, &$params ) );
+ ];
+ Hooks::run( 'SpecialSearchCreateLink', [ $title, &$params ] );
// Extensions using the hook might still return an empty $messageName
if ( $messageName ) {
* @return array
*/
protected function powerSearch( &$request ) {
- $arr = array();
+ $arr = [];
foreach ( SearchEngine::searchableNamespaces() as $ns => $name ) {
if ( $request->getCheck( 'ns' . $ns ) ) {
$arr[] = $ns;
* @return array
*/
protected function powerSearchOptions() {
- $opt = array();
+ $opt = [];
if ( !$this->isPowerSearch() ) {
$opt['profile'] = $this->profile;
} else {
}
$link_t = clone $title;
- $query = array();
+ $query = [];
Hooks::run( 'ShowSearchHitTitle',
- array( &$link_t, &$titleSnippet, $result, $terms, $this, &$query ) );
+ [ &$link_t, &$titleSnippet, $result, $terms, $this, &$query ] );
$link = Linker::linkKnown(
$link_t,
$titleSnippet,
- array( 'data-serp-pos' => $position ), // HTML attributes
+ [ 'data-serp-pos' => $position ], // HTML attributes
$query
);
$this->msg( 'search-file-match' )->escaped() . "</span>";
}
if ( $img ) {
- $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
+ $thumb = $img->transform( [ 'width' => 120, 'height' => 120 ] );
if ( $thumb ) {
$desc = $this->msg( 'parentheses' )->rawParams( $img->getShortDesc() )->escaped();
// Float doesn't seem to interact well with the bullets.
'<table class="searchResultImage">' .
'<tr>' .
'<td style="width: 120px; text-align: center; vertical-align: top;">' .
- $thumb->toHtml( array( 'desc-link' => true ) ) .
+ $thumb->toHtml( [ 'desc-link' => true ] ) .
'</td>' .
'<td style="vertical-align: top;">' .
"{$link} {$redirect} {$category} {$section} {$fileMatch}" .
$score = '';
$related = '';
- if ( Hooks::run( 'ShowSearchHit', array(
+ if ( Hooks::run( 'ShowSearchHit', [
$this, $result, $terms,
&$link, &$redirect, &$section, &$extract,
&$score, &$size, &$date, &$related,
&$html
- ) ) ) {
+ ] ) ) {
$html = "<li><div class='mw-search-result-heading'>" .
"{$link} {$redirect} {$category} {$section} {$fileMatch}</div> {$extract}\n" .
"<div class='mw-search-result-data'>{$size} - {$date}</div>" .
*/
protected function getCustomCaptions() {
if ( is_null( $this->customCaptions ) ) {
- $this->customCaptions = array();
+ $this->customCaptions = [];
// format per line <iwprefix>:<caption>
$customLines = explode( "\n", $this->msg( 'search-interwiki-custom' )->text() );
foreach ( $customLines as $line ) {
$this->getCustomCaptions();
if ( !is_array( $matches ) ) {
- $matches = array( $matches );
+ $matches = [ $matches ];
}
foreach ( $matches as $set ) {
$searchLink = Linker::linkKnown(
$searchTitle,
$this->msg( 'search-interwiki-more' )->text(),
- array(),
- array(
+ [],
+ [
'search' => $query,
'fulltext' => 'Search'
- )
+ ]
);
$out .= "</ul><div class='mw-search-interwiki-project'><span class='mw-search-interwiki-more'>
{$searchLink}</span>{$caption}</div>\n<ul>";
global $wgContLang;
// Groups namespaces into rows according to subject
- $rows = array();
+ $rows = [];
foreach ( SearchEngine::searchableNamespaces() as $namespace => $name ) {
$subject = MWNamespace::getSubject( $namespace );
if ( !array_key_exists( $subject, $rows ) ) {
$namespaceTables .= Xml::closeElement( 'table' );
}
- $showSections = array( 'namespaceTables' => $namespaceTables );
+ $showSections = [ 'namespaceTables' => $namespaceTables ];
- Hooks::run( 'SpecialSearchPowerBox', array( &$showSections, $term, $opts ) );
+ Hooks::run( 'SpecialSearchPowerBox', [ &$showSections, $term, $opts ] );
$hidden = '';
foreach ( $opts as $key => $value ) {
false,
// The token goes here rather than in a hidden field so it
// is only sent when necessary (not every form submission).
- array( 'value' => $user->getEditToken(
+ [ 'value' => $user->getEditToken(
'searchnamespace',
$this->getRequest()
- ) )
+ ) ]
);
}
// Return final output
- return Xml::openElement( 'fieldset', array( 'id' => 'mw-searchoptions' ) ) .
+ return Xml::openElement( 'fieldset', [ 'id' => 'mw-searchoptions' ] ) .
Xml::element( 'legend', null, $this->msg( 'powersearch-legend' )->text() ) .
Xml::tags( 'h4', null, $this->msg( 'powersearch-ns' )->parse() ) .
- Xml::element( 'div', array( 'id' => 'mw-search-togglebox' ), '', false ) .
- Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
- implode( Xml::element( 'div', array( 'class' => 'divider' ), '', false ), $showSections ) .
+ Xml::element( 'div', [ 'id' => 'mw-search-togglebox' ], '', false ) .
+ Xml::element( 'div', [ 'class' => 'divider' ], '', false ) .
+ implode( Xml::element( 'div', [ 'class' => 'divider' ], '', false ), $showSections ) .
$hidden .
- Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
+ Xml::element( 'div', [ 'class' => 'divider' ], '', false ) .
$remember .
Xml::closeElement( 'fieldset' );
}
// Builds list of Search Types (profiles)
$nsAllSet = array_keys( SearchEngine::searchableNamespaces() );
- $profiles = array(
- 'default' => array(
+ $profiles = [
+ 'default' => [
'message' => 'searchprofile-articles',
'tooltip' => 'searchprofile-articles-tooltip',
'namespaces' => SearchEngine::defaultNamespaces(),
'namespace-messages' => SearchEngine::namespacesAsText(
SearchEngine::defaultNamespaces()
),
- ),
- 'images' => array(
+ ],
+ 'images' => [
'message' => 'searchprofile-images',
'tooltip' => 'searchprofile-images-tooltip',
- 'namespaces' => array( NS_FILE ),
- ),
- 'all' => array(
+ 'namespaces' => [ NS_FILE ],
+ ],
+ 'all' => [
'message' => 'searchprofile-everything',
'tooltip' => 'searchprofile-everything-tooltip',
'namespaces' => $nsAllSet,
- ),
- 'advanced' => array(
+ ],
+ 'advanced' => [
'message' => 'searchprofile-advanced',
'tooltip' => 'searchprofile-advanced-tooltip',
'namespaces' => self::NAMESPACES_CURRENT,
- )
- );
+ ]
+ ];
- Hooks::run( 'SpecialSearchProfiles', array( &$profiles ) );
+ Hooks::run( 'SpecialSearchProfiles', [ &$profiles ] );
foreach ( $profiles as &$data ) {
if ( !is_array( $data['namespaces'] ) ) {
* @return string
*/
protected function searchProfileTabs( $term ) {
- $out = Xml::openElement( 'div', array( 'class' => 'mw-search-profile-tabs' ) );
+ $out = Xml::openElement( 'div', [ 'class' => 'mw-search-profile-tabs' ] );
$bareterm = $term;
if ( $this->startsWithImage( $term ) ) {
$lang = $this->getLanguage();
// Outputs XML for Search Types
- $out .= Xml::openElement( 'div', array( 'class' => 'search-types' ) );
+ $out .= Xml::openElement( 'div', [ 'class' => 'search-types' ] );
$out .= Xml::openElement( 'ul' );
foreach ( $profiles as $id => $profile ) {
if ( !isset( $profile['parameters'] ) ) {
- $profile['parameters'] = array();
+ $profile['parameters'] = [];
}
$profile['parameters']['profile'] = $id;
$lang->commaList( $profile['namespace-messages'] ) : null;
$out .= Xml::tags(
'li',
- array(
+ [
'class' => $this->profile === $id ? 'current' : 'normal'
- ),
+ ],
$this->makeSearchLink(
$bareterm,
- array(),
+ [],
$this->msg( $profile['message'] )->text(),
$this->msg( $profile['tooltip'], $tooltipParam )->text(),
$profile['parameters']
}
$out .= Xml::closeElement( 'ul' );
$out .= Xml::closeElement( 'div' );
- $out .= Xml::element( 'div', array( 'style' => 'clear:both' ), '', false );
+ $out .= Xml::element( 'div', [ 'style' => 'clear:both' ], '', false );
$out .= Xml::closeElement( 'div' );
return $out;
*/
protected function searchOptions( $term ) {
$out = '';
- $opts = array();
+ $opts = [];
$opts['profile'] = $this->profile;
if ( $this->isPowerSearch() ) {
$out .= $this->powerSearchBox( $term, $opts );
} else {
$form = '';
- Hooks::run( 'SpecialSearchProfileForm', array( $this, &$form, $this->profile, $term, $opts ) );
+ Hooks::run( 'SpecialSearchProfileForm', [ $this, &$form, $this->profile, $term, $opts ] );
$out .= $form;
}
$out = Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
$out .= Html::hidden( 'profile', $this->profile ) . "\n";
// Term box
- $out .= Html::input( 'search', $term, 'search', array(
+ $out .= Html::input( 'search', $term, 'search', [
'id' => $this->isPowerSearch() ? 'powerSearchText' : 'searchText',
'size' => '50',
'autofocus' => trim( $term ) === '',
'class' => 'mw-ui-input mw-ui-input-inline',
- ) ) . "\n";
+ // identifies the location of the search bar for tracking purposes
+ 'data-search-loc' => 'content',
+ ] ) . "\n";
$out .= Html::hidden( 'fulltext', 'Search' ) . "\n";
$out .= Html::submitButton(
$this->msg( 'searchbutton' )->text(),
- array( 'class' => 'mw-ui-button mw-ui-progressive' ),
- array( 'mw-ui-progressive' )
+ [ 'class' => 'mw-ui-button mw-ui-progressive' ],
+ [ 'mw-ui-progressive' ]
) . "\n";
// Results-info
->numParams( $this->offset + 1, $this->offset + $resultsShown, $totalNum )
->numParams( $resultsShown )
->parse();
- $out .= Xml::tags( 'div', array( 'class' => 'results-info' ), $top ) .
- Xml::element( 'div', array( 'style' => 'clear:both' ), '', false );
+ $out .= Xml::tags( 'div', [ 'class' => 'results-info' ], $top ) .
+ Xml::element( 'div', [ 'style' => 'clear:both' ], '', false );
}
return $out;
* @param array $params Query string parameters
* @return string HTML fragment
*/
- protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params = array() ) {
+ protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params = [] ) {
$opt = $params;
foreach ( $namespaces as $n ) {
$opt['ns' . $n] = 1;
}
$stParams = array_merge(
- array(
+ [
'search' => $term,
'fulltext' => $this->msg( 'search' )->text()
- ),
+ ],
$opt
);
return Xml::element(
'a',
- array(
+ [
'href' => $this->getPageTitle()->getLocalURL( $stParams ),
'title' => $tooltip
- ),
+ ],
$label
);
}