3 * Contain a class for special pages
14 var $searchTerms = array();
15 var $namespaces = array( NS_MAIN
);
16 var $showRedirects = false;
19 * Perform a full text search query and return a result set.
20 * If title searches are not supported or disabled, return null.
22 * @param string $term - Raw search term
23 * @return SearchResultSet
27 function searchText( $term ) {
32 * Perform a title-only search query and return a result set.
33 * If title searches are not supported or disabled, return null.
35 * @param string $term - Raw search term
36 * @return SearchResultSet
40 function searchTitle( $term ) {
45 * If an exact title match can be find, or a very slightly close match,
46 * return the title. If no match, returns NULL.
53 function getNearMatch( $searchterm ) {
56 $allSearchTerms = array($searchterm);
58 if($wgContLang->hasVariants()){
59 $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm));
62 foreach($allSearchTerms as $term){
64 # Exact match? No need to look further.
65 $title = Title
::newFromText( $term );
69 if ( $title->getNamespace() == NS_SPECIAL ||
$title->exists() ) {
73 # Now try all lower case (i.e. first letter capitalized)
75 $title = Title
::newFromText( $wgContLang->lc( $term ) );
76 if ( $title->exists() ) {
80 # Now try capitalized string
82 $title = Title
::newFromText( $wgContLang->ucwords( $term ) );
83 if ( $title->exists() ) {
87 # Now try all upper case
89 $title = Title
::newFromText( $wgContLang->uc( $term ) );
90 if ( $title->exists() ) {
94 # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
95 $title = Title
::newFromText( $wgContLang->ucwordbreaks($term) );
96 if ( $title->exists() ) {
100 global $wgCapitalLinks, $wgContLang;
101 if( !$wgCapitalLinks ) {
102 // Catch differs-by-first-letter-case-only
103 $title = Title
::newFromText( $wgContLang->ucfirst( $term ) );
104 if ( $title->exists() ) {
107 $title = Title
::newFromText( $wgContLang->lcfirst( $term ) );
108 if ( $title->exists() ) {
114 $title = Title
::newFromText( $searchterm );
116 # Entering an IP address goes to the contributions page
117 if ( ( $title->getNamespace() == NS_USER
&& User
::isIP($title->getText() ) )
118 || User
::isIP( trim( $searchterm ) ) ) {
119 return SpecialPage
::getTitleFor( 'Contributions', $title->getDbkey() );
123 # Entering a user goes to the user page whether it's there or not
124 if ( $title->getNamespace() == NS_USER
) {
128 # Quoted term? Try without the quotes...
130 if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) {
131 return SearchEngine
::getNearMatch( $matches[1] );
137 function legalSearchChars() {
138 return "A-Za-z_'0-9\\x80-\\xFF\\-";
142 * Set the maximum number of results to return
143 * and how many to skip before returning the first.
149 function setLimitOffset( $limit, $offset = 0 ) {
150 $this->limit
= intval( $limit );
151 $this->offset
= intval( $offset );
155 * Set which namespaces the search should include.
156 * Give an array of namespace index numbers.
158 * @param array $namespaces
161 function setNamespaces( $namespaces ) {
162 $this->namespaces
= $namespaces;
166 * Make a list of searchable namespaces and their canonical names.
170 function searchableNamespaces() {
173 foreach( $wgContLang->getNamespaces() as $ns => $name ) {
174 if( $ns >= NS_MAIN
) {
182 * Return a 'cleaned up' search string
187 function filter( $text ) {
188 $lc = $this->legalSearchChars();
189 return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
192 * Load up the appropriate search engine class for the currently
193 * active database backend, and return a configured instance.
195 * @return SearchEngine
199 global $wgDBtype, $wgSearchType;
200 if( $wgSearchType ) {
201 $class = $wgSearchType;
202 } elseif( $wgDBtype == 'mysql' ) {
203 $class = 'SearchMySQL4';
204 } else if ( $wgDBtype == 'postgres' ) {
205 $class = 'SearchPostgres';
207 $class = 'SearchEngineDummy';
209 $search = new $class( wfGetDB( DB_SLAVE
) );
210 $search->setLimitOffset(0,0);
215 * Create or update the search index record for the given page.
216 * Title and text should be pre-processed.
219 * @param string $title
220 * @param string $text
223 function update( $id, $title, $text ) {
228 * Update a search index record's title only.
229 * Title should be pre-processed.
232 * @param string $title
235 function updateTitle( $id, $title ) {
240 /** @package MediaWiki */
241 class SearchResultSet
{
243 * Fetch an array of regular expression fragments for matching
244 * the search terms as parsed by this engine in a text extract.
250 function termMatches() {
259 * Return true if results are included in this result set.
263 function hasResults() {
268 * Some search modes return a total hit count for the query
269 * in the entire article database. This may include pages
270 * in namespaces that would not be matched on the given
273 * Return null if no total hits number is supported.
278 function getTotalHits() {
283 * Some search modes return a suggested alternate term if there are
284 * no exact hits. Returns true if there is one on this set.
289 function hasSuggestion() {
294 * Some search modes return a suggested alternate term if there are
295 * no exact hits. Check hasSuggestion() first.
300 function getSuggestion() {
305 * Fetches next search result, or false.
306 * @return SearchResult
315 /** @package MediaWiki */
317 function SearchResult( $row ) {
318 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
325 function getTitle() {
326 return $this->mTitle
;
330 * @return double or null if not supported
332 function getScore() {
340 class SearchEngineDummy
{
341 function search( $term ) {
344 function setLimitOffset($l, $o) {}
345 function legalSearchChars() {}
347 function setnamespaces() {}
348 function searchtitle() {}
349 function searchtext() {}