<?php
/**
- * Copyright (C) 2004 Brion Vibber <brion@pobox.com>
+ * Implements Special:Search
+ *
+ * Copyright © 2004 Brion Vibber <brion@pobox.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
- */
-
-/**
- * Run text & title search and display the output
+ *
* @file
* @ingroup SpecialPage
*/
-/**
- * Entry point
- *
- * @param $par String: (default '')
- */
-function wfSpecialSearch( $par = '' ) {
- global $wgRequest, $wgUser;
- // Strip underscores from title parameter; most of the time we'll want
- // text form here. But don't strip underscores from actual text params!
- $titleParam = str_replace( '_', ' ', $par );
- // Fetch the search term
- $search = str_replace( "\n", " ", $wgRequest->getText( 'search', $titleParam ) );
- $searchPage = new SpecialSearch( $wgRequest, $wgUser );
- if( $wgRequest->getVal( 'fulltext' )
- || !is_null( $wgRequest->getVal( 'offset' ))
- || !is_null( $wgRequest->getVal( 'searchx' )) )
- {
- $searchPage->showResults( $search );
- } else {
- $searchPage->goResult( $search );
- }
-}
-
/**
* implements Special:Search - Run text & title search and display the output
* @ingroup SpecialPage
*/
-class SpecialSearch {
+class SpecialSearch extends SpecialPage {
+
+ public function __construct() {
+ parent::__construct( 'Search' );
+ }
+
+ /**
+ * Entry point
+ *
+ * @param $par String or null
+ */
+ public function execute( $par ) {
+ global $wgRequest, $wgUser, $wgOut;
+
+ $this->setHeaders();
+ $this->outputHeader();
+ $wgOut->allowClickjacking();
+
+ // Strip underscores from title parameter; most of the time we'll want
+ // text form here. But don't strip underscores from actual text params!
+ $titleParam = str_replace( '_', ' ', $par );
+
+ // Fetch the search term
+ $search = str_replace( "\n", " ", $wgRequest->getText( 'search', $titleParam ) );
+
+ $this->load( $wgRequest, $wgUser );
+
+ if ( $wgRequest->getVal( 'fulltext' )
+ || !is_null( $wgRequest->getVal( 'offset' ) )
+ || !is_null( $wgRequest->getVal( 'searchx' ) ) )
+ {
+ $this->showResults( $search );
+ } else {
+ $this->goResult( $search );
+ }
+ }
/**
* Set up basic search parameters from the request and user settings.
* @param $request WebRequest
* @param $user User
*/
- public function __construct( &$request, &$user ) {
+ public function load( &$request, &$user ) {
list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, 'searchlimit' );
$this->mPrefix = $request->getVal('prefix', '');
# Extract requested namespaces
if( empty( $this->namespaces ) ) {
$this->namespaces = SearchEngine::userNamespaces( $user );
}
- $this->searchRedirects = $request->getcheck( 'redirs' ) ? true : false;
+ $this->searchRedirects = $request->getCheck( 'redirs' );
$this->searchAdvanced = $request->getVal( 'advanced' );
$this->active = 'advanced';
$this->sk = $user->getSkin();
}
# If there's an exact or very near match, jump right there.
$t = SearchEngine::getNearMatch( $term );
+
+ if ( !wfRunHooks( 'SpecialSearchGo', array( &$t, &$term ) ) ) {
+ # Hook requested termination
+ return;
+ }
+
if( !is_null( $t ) ) {
- wfRunHooks( 'SpecialSearchGomatch', array( &$t ) );
$wgOut->redirect( $t->getFullURL() );
return;
}
if( !is_null( $t ) ) {
global $wgGoToEdit;
wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
+ wfDebugLog( 'nogomatch', $t->getText(), false );
+
# If the feature is enabled, go straight to the edit page
if( $wgGoToEdit ) {
$wgOut->redirect( $t->getFullURL( array( 'action' => 'edit' ) ) );
$filePrefix = $wgContLang->getFormattedNsText(NS_FILE).':';
if( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
- $wgOut->addHTML( $this->searchFocus() );
$wgOut->addHTML( $this->formHeader($term, 0, 0));
if( $this->searchAdvanced ) {
$wgOut->addHTML( $this->powerSearchBox( $term ) );
- }
+ }
$wgOut->addHTML( '</form>' );
// Empty query -- straight view of search form
wfProfileOut( __METHOD__ );
$textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
// Total initial query matches (possible false positives)
$num = $titleMatchesNum + $textMatchesNum;
-
+
// Get total actual results (after second filtering, if any)
$numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
$titleMatches->getTotalHits() : $titleMatchesNum;
$totalRes += $titleMatches->getTotalHits();
if($textMatches && !is_null( $textMatches->getTotalHits() ))
$totalRes += $textMatches->getTotalHits();
-
+
// show number of results and current offset
$wgOut->addHTML( $this->formHeader($term, $num, $totalRes));
if( $this->searchAdvanced ) {
$wgOut->addHTML( $this->powerSearchBox( $term ) );
}
-
+
$wgOut->addHtml( Xml::closeElement( 'form' ) );
$wgOut->addHtml( "<div class='searchresults'>" );
wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
} else {
wfRunHooks( 'SpecialSearchNoResults', array( $term ) );
- }
+ }
+ $wgOut->parserOptions()->setEditSection( false );
if( $titleMatches ) {
if( $numTitleMatches > 0 ) {
$wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
$textMatches->free();
}
if( $num === 0 ) {
- $wgOut->addWikiMsg( 'search-nonefound', wfEscapeWikiText( $term ) );
+ $wgOut->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>", array( 'search-nonefound', wfEscapeWikiText( $term ) ) );
$this->showCreateLink( $t );
}
$wgOut->addHtml( "</div>" );
- if( $num === 0 ) {
- $wgOut->addHTML( $this->searchFocus() );
- }
if( $num || $this->offset ) {
$wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
}
wfProfileOut( __METHOD__ );
}
-
+
protected function showCreateLink( $t ) {
global $wgOut;
-
+
// show direct page/create link if applicable
$messageName = null;
if( !is_null($t) ) {
} else {
$messageName = 'searchmenu-new-nocreate';
}
- }
+ }
if( $messageName ) {
- $wgOut->addWikiMsg( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) );
+ $wgOut->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>", array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) );
} else {
// preserve the paragraph for margins etc...
$wgOut->addHtml( '<p></p>' );
protected function setupPage( $term ) {
global $wgOut;
// Figure out the active search profile header
- $nsAllSet = array_keys( SearchEngine::searchableNamespaces() );
- if( $this->searchAdvanced )
+ if( $this->searchAdvanced ) {
$this->active = 'advanced';
- else {
+ } else {
$profiles = $this->getSearchProfiles();
-
+
foreach( $profiles as $key => $data ) {
if ( $this->namespaces == $data['namespaces'] && $key != 'advanced')
$this->active = $key;
}
-
+
}
# Should advanced UI be used?
$this->searchAdvanced = ($this->active === 'advanced');
$wgOut->setPageTitle( wfMsg( 'searchresults') );
$wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) );
}
- $wgOut->setArticleRelated( false );
- $wgOut->setRobotPolicy( 'noindex,nofollow' );
// add javascript specific to special:search
- $wgOut->addScriptFile( 'search.js' );
-
- // Bug #16886: Sister projects box moves down the first extract on IE7
- $wgOut->addStyle( 'common/IE70Fixes.css', 'screen', 'IE 7' );
+ $wgOut->addModules( 'mediawiki.legacy.search' );
+ $wgOut->addModules( 'mediawiki.special.search' );
}
/**
if( !is_null($infoLine) ) {
$out .= "\n<!-- {$infoLine} -->\n";
}
- $off = $this->offset + 1;
$out .= "<ul class='mw-search-results'>\n";
while( $result = $matches->next() ) {
$out .= $this->showHit( $result, $terms );
if( $titleSnippet == '' )
$titleSnippet = null;
-
+
$link_t = clone $t;
-
+
wfRunHooks( 'ShowSearchHitTitle',
array( &$link_t, &$titleSnippet, $result, $terms, $this ) );
if( $img ) {
$thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
if( $thumb ) {
- $desc = $img->getShortDesc();
+ $desc = wfMsg( 'parentheses', $img->getShortDesc() );
wfProfileOut( __METHOD__ );
// Float doesn't seem to interact well with the bullets.
// Table messes up vertical alignment of the bullets.
$out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
wfMsg('search-interwiki-caption')."</div>\n";
- $off = $this->offset + 1;
$out .= "<ul class='mw-search-iwresults'>\n";
// work out custom project captions
}
$rows = array_values( $rows );
$numRows = count( $rows );
-
+
// Lays out namespaces in multiple floating two-column tables so they'll
// be arranged nicely while still accommodating different screen widths
$namespaceTables = '';
$namespaceTables .
Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
$redirects .
- Xml::hidden( 'title', SpecialPage::getTitleFor( 'Search' )->getPrefixedText() ) .
- Xml::hidden( 'advanced', $this->searchAdvanced ) .
- Xml::hidden( 'fulltext', 'Advanced search' ) .
+ Html::hidden( 'title', SpecialPage::getTitleFor( 'Search' )->getPrefixedText() ) .
+ Html::hidden( 'advanced', $this->searchAdvanced ) .
+ Html::hidden( 'fulltext', 'Advanced search' ) .
Xml::closeElement( 'fieldset' );
}
- protected function searchFocus() {
- $id = $this->searchAdvanced ? 'powerSearchText' : 'searchText';
- return Html::inlineScript(
- "hookEvent(\"load\", function() {" .
- "document.getElementById('$id').focus();" .
- "});" );
- }
-
protected function getSearchProfiles() {
// Builds list of Search Types (profiles)
$nsAllSet = array_keys( SearchEngine::searchableNamespaces() );
-
+
$profiles = array(
'default' => array(
'message' => 'searchprofile-articles',
'parameters' => array( 'advanced' => 1 ),
)
);
-
+
wfRunHooks( 'SpecialSearchProfiles', array( &$profiles ) );
- foreach( $profiles as $key => &$data ) {
+ foreach( $profiles as &$data ) {
sort($data['namespaces']);
}
-
+
return $profiles;
}
protected function formHeader( $term, $resultsShown, $totalNum ) {
global $wgLang;
-
+
$out = Xml::openElement('div', array( 'class' => 'mw-search-formheader' ) );
-
+
$bareterm = $term;
if( $this->startsWithImage( $term ) ) {
// Deletes prefixes
}
$profiles = $this->getSearchProfiles();
-
+
// Outputs XML for Search Types
$out .= Xml::openElement( 'div', array( 'class' => 'search-types' ) );
$out .= Xml::openElement( 'ul' );
$profile['namespaces'],
wfMsg( $profile['message'] ),
wfMsg( $profile['tooltip'], $tooltipParam ),
- isset( $profile['parameters'] ) ? $profile['parameters'] : array()
+ isset( $profile['parameters'] ) ? $profile['parameters'] : array()
)
);
}
Xml::tags( 'ul', null, Xml::tags( 'li', null, $top ) )
);
}
-
+
$out .= Xml::element( 'div', array( 'style' => 'clear:both' ), '', false );
$out .= Xml::closeElement('div');
-
+
// Adds hidden namespace fields
if ( !$this->searchAdvanced ) {
foreach( $this->namespaces as $ns ) {
- $out .= Xml::hidden( "ns{$ns}", '1' );
+ $out .= Html::hidden( "ns{$ns}", '1' );
}
}
-
+
return $out;
}
protected function shortDialog( $term ) {
$searchTitle = SpecialPage::getTitleFor( 'Search' );
- $searchable = SearchEngine::searchableNamespaces();
$out = Html::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
// Keep redirect setting
$out .= Html::hidden( "redirs", (int)$this->searchRedirects ) . "\n";
) ) . "\n";
$out .= Html::hidden( 'fulltext', 'Search' ) . "\n";
$out .= Xml::submitButton( wfMsg( 'searchbutton' ) ) . "\n";
- return $out . $this->didYouMeanHtml;
+ return $out . $this->didYouMeanHtml;
}
/**
'a',
array(
'href' => $st->getLocalURL( $stParams ),
- 'title' => $tooltip,
+ 'title' => $tooltip,
'onmousedown' => 'mwSearchHeaderClick(this);',
'onkeydown' => 'mwSearchHeaderClick(this);'),
$label
}
return false;
}
-
+
/**
* Check if query starts with all: prefix
*
protected function startsWithAll( $term ) {
$allkeyword = wfMsgForContent('searchall');
-
+
$p = explode( ':', $term );
if( count( $p ) > 1 ) {
return $p[0] == $allkeyword;
return false;
}
}
-