new feature: $wgBlockAllowsUTEdit
[lhc/web/wiklou.git] / includes / SearchMySQL3.php
1 <?php
2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21 * Search engine hook for MySQL 3.23.x
22 * @package MediaWiki
23 * @subpackage Search
24 */
25
26 /** */
27 require_once( 'SearchMySQL.php' );
28
29 /**
30 * @package MediaWiki
31 * @subpackage Search
32 */
33 class SearchMySQL3 extends SearchMySQL {
34 function SearchMySQL3( &$db ) {
35 $this->db =& $db;
36 }
37
38 function parseQuery( $filteredText, $fulltext ) {
39 global $wgDBminWordLen, $wgContLang;
40
41 $field = $this->getIndexField( $fulltext );
42
43 # on non mysql4 database: get list of words we don't want to search for
44 require_once( 'FulltextStoplist.php' );
45
46 $lc = SearchEngine::legalSearchChars() . '()';
47 $q = preg_replace( "/([()])/", " \\1 ", $filteredText );
48 $q = preg_replace( "/\\s+/", " ", $q );
49 $w = explode( ' ', trim( $q ) );
50
51 $last = $cond = '';
52 foreach ( $w as $word ) {
53 $word = $wgContLang->stripForSearch( $word );
54 if ( 'and' == $word || 'or' == $word || 'not' == $word
55 || '(' == $word || ')' == $word ) {
56 $cond .= ' ' . strtoupper( $word );
57 $last = '';
58 } else if ( strlen( $word ) < $wgDBminWordLen ) {
59 continue;
60 } else if ( FulltextStoplist::inList( $word ) ) {
61 continue;
62 } else {
63 if ( '' != $last ) { $cond .= ' AND'; }
64 $cond .= " (MATCH ($field) AGAINST ('" .
65 $this->db->strencode( $word ). "'))";
66 $last = $word;
67 $this->searchTerms[] = "\\b" . preg_quote( $word, '/' ) . "\\b";
68 }
69 }
70 if ( 0 == count( $this->searchTerms ) ) {
71 # No searchable terms remaining.
72 # We have to return a term for the query or we get an SQL error.
73 return "0";
74 }
75
76 return '(' . $cond . ' )';
77 }
78
79 }
80
81 ?>