<?php
-# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
-# http://www.mediawiki.org/
-#
-# 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
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# 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
+/**
+ * Copyright (C) 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * 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
* Set up basic search parameters from the request and user settings.
* Typically you'll pass $wgRequest and $wgUser.
*
- * @param WebRequest $request
- * @param User $user
- * @public
+ * @param $request WebRequest
+ * @param $user User
*/
- function __construct( &$request, &$user ) {
+ public function __construct( &$request, &$user ) {
list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, 'searchlimit' );
$this->mPrefix = $request->getVal('prefix', '');
# Extract requested namespaces
/**
* If an exact title match can be found, jump straight ahead to it.
- * @param string $term
+ *
+ * @param $term String
*/
public function goResult( $term ) {
global $wgOut;
# If there's an exact or very near match, jump right there.
$t = SearchEngine::getNearMatch( $term );
if( !is_null( $t ) ) {
+ wfRunHooks( 'SpecialSearchGomatch', array( &$t ) );
$wgOut->redirect( $t->getFullURL() );
return;
}
}
/**
- * @param string $term
+ * @param $term String
*/
public function showResults( $term ) {
global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript;
wfProfileIn( __METHOD__ );
$sk = $wgUser->getSkin();
-
+
+ $beginSearchForm = Xml::openElement(
+ 'form',
+ array(
+ 'id' => ( $this->searchAdvanced ? 'powersearch' : 'search' ),
+ 'method' => 'get',
+ 'action' => $wgScript
+ )
+ );
+ $mwSearchTopTable =
+ Xml::openElement( 'table', array( 'id' => 'mw-search-top-table', 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0 ) ) .
+ Xml::openElement( 'tr' ) .
+ Xml::openElement( 'td' ) . "\n" .
+ $this->shortDialog( $term ) .
+ Xml::closeElement( 'td' ) .
+ Xml::closeElement( 'tr' ) .
+ Xml::closeElement( 'table' );
+
+ // moved to check for empty or null search string before running query
+ // to prevent NULL fulltext search error in SQL Server
+ $filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':';
+ if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
+ $wgOut->addHTML( $beginSearchForm );
+ $wgOut->addHTML( $mwSearchTopTable );
+ $wgOut->addHTML( $this->searchFocus() );
+ $wgOut->addHTML( $this->formHeader( $term, 0, 0 ) );
+ if ( $this->searchAdvanced ) {
+ $wgOut->addHTML( $this->powerSearchBox( $term ) );
+ }
+ $wgOut->addHTML( Xml::closeElement( 'form' ) );
+ // Empty query -- straight view of search form
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+
$this->searchEngine = SearchEngine::create();
$search =& $this->searchEngine;
$search->setLimitOffset( $this->limit, $this->offset );
}
// start rendering the page
$wgOut->addHtml(
- Xml::openElement(
- 'form',
- array(
- 'id' => ( $this->searchAdvanced ? 'powersearch' : 'search' ),
- 'method' => 'get',
- 'action' => $wgScript
- )
- )
+ $beginSearchForm
);
$wgOut->addHtml(
- Xml::openElement( 'table', array( 'id'=>'mw-search-top-table', 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) .
- Xml::openElement( 'tr' ) .
- Xml::openElement( 'td' ) . "\n" .
- $this->shortDialog( $term ) .
- Xml::closeElement('td') .
- Xml::closeElement('tr') .
- Xml::closeElement('table')
+ $mwSearchTopTable
);
// Sometimes the search engine knows there are too many hits
return;
}
- $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__ );
- return;
- }
-
// Get number of results
$titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0;
$textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
$messageName = 'searchmenu-exists';
} elseif( $t->userCan( 'create' ) ) {
$messageName = 'searchmenu-new';
+ } else {
+ $messageName = 'searchmenu-new-nocreate';
}
}
if( $messageName ) {
$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' );
}
/**
* Extract "power search" namespace settings from the request object,
* returning a list of index numbers to search.
*
- * @param WebRequest $request
- * @return array
+ * @param $request WebRequest
+ * @return Array
*/
protected function powerSearch( &$request ) {
$arr = array();
/**
* Reconstruct the 'power search' options for links
- * @return array
+ *
+ * @return Array
*/
protected function powerSearchOptions() {
$opt = array();
/**
* Show whole set of results
*
- * @param SearchResultSet $matches
+ * @param $matches SearchResultSet
*/
protected function showMatches( &$matches ) {
global $wgContLang;
/**
* Format a single hit result
- * @param SearchResult $result
- * @param array $terms terms to highlight
+ *
+ * @param $result SearchResult
+ * @param $terms Array: terms to highlight
*/
protected function showHit( $result, $terms ) {
- global $wgContLang, $wgLang, $wgUser;
+ global $wgLang, $wgUser;
wfProfileIn( __METHOD__ );
if( $result->isBrokenTitle() ) {
$this->sk->formatSize( $byteSize ),
$wgLang->formatNum( $wordCount )
);
+
+ if( $t->getNamespace() == NS_CATEGORY ) {
+ $cat = Category::newFromTitle( $t );
+ $size = wfMsgExt(
+ 'search-result-category-size',
+ array( 'parsemag', 'escape' ),
+ $wgLang->formatNum( $cat->getPageCount() ),
+ $wgLang->formatNum( $cat->getSubcatCount() ),
+ $wgLang->formatNum( $cat->getFileCount() )
+ );
+ }
+
$date = $wgLang->timeanddate( $timestamp );
// link to related articles if supported
}
wfProfileOut( __METHOD__ );
- return "<li>{$link} {$redirect} {$section} {$extract}\n" .
+ return "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section}</div> {$extract}\n" .
"<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
"</li>\n";
/**
* Show results from other wikis
*
- * @param SearchResultSet $matches
+ * @param $matches SearchResultSet
+ * @param $query String
*/
protected function showInterwiki( &$matches, $query ) {
global $wgContLang;
/**
* Show single interwiki link
*
- * @param SearchResult $result
- * @param string $lastInterwiki
- * @param array $terms
- * @param string $query
- * @param array $customCaptions iw prefix -> caption
+ * @param $result SearchResult
+ * @param $lastInterwiki String
+ * @param $terms Array
+ * @param $query String
+ * @param $customCaptions Array: iw prefix -> caption
*/
protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) {
wfProfileIn( __METHOD__ );
- global $wgContLang, $wgLang;
if( $result->isBrokenTitle() ) {
wfProfileOut( __METHOD__ );
/**
* Generates the power search box at bottom of [[Special:Search]]
- * @param $term string: search term
- * @return $out string: HTML form
+ *
+ * @param $term String: search term
+ * @return String: HTML form
*/
protected function powerSearchBox( $term ) {
- global $wgScript, $wgContLang;
-
// Groups namespaces into rows according to subject
$rows = array();
foreach( SearchEngine::searchableNamespaces() as $namespace => $name ) {
}
protected function formHeader( $term, $resultsShown, $totalNum ) {
- global $wgContLang, $wgLang;
+ global $wgLang;
$out = Xml::openElement('div', array( 'class' => 'mw-search-formheader' ) );
$bareterm = substr( $term, strpos( $term, ':' ) + 1 );
}
-
$profiles = $this->getSearchProfiles();
// Outputs XML for Search Types
return $out . $this->didYouMeanHtml;
}
- /** Make a search link with some target namespaces */
+ /**
+ * Make a search link with some target namespaces
+ *
+ * @param $term String
+ * @param $namespaces Array
+ * @param $label String: link's text
+ * @param $tooltip String: link's tooltip
+ * @param $params Array: query string parameters
+ * @return String: HTML fragment
+ */
protected function makeSearchLink( $term, $namespaces, $label, $tooltip, $params=array() ) {
$opt = $params;
foreach( $namespaces as $n ) {
);
}
- /** Check if query starts with image: prefix */
+ /**
+ * Check if query starts with image: prefix
+ *
+ * @param $term String: the string to check
+ * @return Boolean
+ */
protected function startsWithImage( $term ) {
global $wgContLang;
return false;
}
- /** Check if query starts with all: prefix */
+ /**
+ * Check if query starts with all: prefix
+ *
+ * @param $term String: the string to check
+ * @return Boolean
+ */
protected function startsWithAll( $term ) {
$allkeyword = wfMsgForContent('searchall');