3 * Contain a class for special pages
9 var $searchTerms = array();
10 var $namespaces = array( NS_MAIN
);
11 var $showRedirects = false;
14 * Perform a full text search query and return a result set.
15 * If title searches are not supported or disabled, return null.
17 * @param string $term - Raw search term
18 * @return SearchResultSet
22 function searchText( $term ) {
27 * Perform a title-only search query and return a result set.
28 * If title searches are not supported or disabled, return null.
30 * @param string $term - Raw search term
31 * @return SearchResultSet
35 function searchTitle( $term ) {
40 * If an exact title match can be find, or a very slightly close match,
41 * return the title. If no match, returns NULL.
48 function getNearMatch( $searchterm ) {
51 $allSearchTerms = array($searchterm);
53 if($wgContLang->hasVariants()){
54 $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm));
57 foreach($allSearchTerms as $term){
59 # Exact match? No need to look further.
60 $title = Title
::newFromText( $term );
64 if ( $title->getNamespace() == NS_SPECIAL ||
$title->exists() ) {
68 # Now try all lower case (i.e. first letter capitalized)
70 $title = Title
::newFromText( $wgContLang->lc( $term ) );
71 if ( $title->exists() ) {
75 # Now try capitalized string
77 $title = Title
::newFromText( $wgContLang->ucwords( $term ) );
78 if ( $title->exists() ) {
82 # Now try all upper case
84 $title = Title
::newFromText( $wgContLang->uc( $term ) );
85 if ( $title->exists() ) {
89 # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
90 $title = Title
::newFromText( $wgContLang->ucwordbreaks($term) );
91 if ( $title->exists() ) {
95 global $wgCapitalLinks, $wgContLang;
96 if( !$wgCapitalLinks ) {
97 // Catch differs-by-first-letter-case-only
98 $title = Title
::newFromText( $wgContLang->ucfirst( $term ) );
99 if ( $title->exists() ) {
102 $title = Title
::newFromText( $wgContLang->lcfirst( $term ) );
103 if ( $title->exists() ) {
109 $title = Title
::newFromText( $searchterm );
111 # Entering an IP address goes to the contributions page
112 if ( ( $title->getNamespace() == NS_USER
&& User
::isIP($title->getText() ) )
113 || User
::isIP( trim( $searchterm ) ) ) {
114 return SpecialPage
::getTitleFor( 'Contributions', $title->getDbkey() );
118 # Entering a user goes to the user page whether it's there or not
119 if ( $title->getNamespace() == NS_USER
) {
123 # Quoted term? Try without the quotes...
125 if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) {
126 return SearchEngine
::getNearMatch( $matches[1] );
132 public static function legalSearchChars() {
133 return "A-Za-z_'0-9\\x80-\\xFF\\-";
137 * Set the maximum number of results to return
138 * and how many to skip before returning the first.
144 function setLimitOffset( $limit, $offset = 0 ) {
145 $this->limit
= intval( $limit );
146 $this->offset
= intval( $offset );
150 * Set which namespaces the search should include.
151 * Give an array of namespace index numbers.
153 * @param array $namespaces
156 function setNamespaces( $namespaces ) {
157 $this->namespaces
= $namespaces;
161 * Make a list of searchable namespaces and their canonical names.
165 function searchableNamespaces() {
168 foreach( $wgContLang->getNamespaces() as $ns => $name ) {
169 if( $ns >= NS_MAIN
) {
177 * Return a 'cleaned up' search string
182 function filter( $text ) {
183 $lc = $this->legalSearchChars();
184 return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
187 * Load up the appropriate search engine class for the currently
188 * active database backend, and return a configured instance.
190 * @return SearchEngine
192 public static function create() {
193 global $wgDBtype, $wgSearchType;
194 if( $wgSearchType ) {
195 $class = $wgSearchType;
196 } elseif( $wgDBtype == 'mysql' ) {
197 $class = 'SearchMySQL4';
198 } else if ( $wgDBtype == 'postgres' ) {
199 $class = 'SearchPostgres';
200 } else if ( $wgDBtype == 'oracle' ) {
201 $class = 'SearchOracle';
203 $class = 'SearchEngineDummy';
205 $search = new $class( wfGetDB( DB_SLAVE
) );
206 $search->setLimitOffset(0,0);
211 * Create or update the search index record for the given page.
212 * Title and text should be pre-processed.
215 * @param string $title
216 * @param string $text
219 function update( $id, $title, $text ) {
224 * Update a search index record's title only.
225 * Title should be pre-processed.
228 * @param string $title
231 function updateTitle( $id, $title ) {
240 class SearchResultSet
{
242 * Fetch an array of regular expression fragments for matching
243 * the search terms as parsed by this engine in a text extract.
249 function termMatches() {
258 * Return true if results are included in this result set.
262 function hasResults() {
267 * Some search modes return a total hit count for the query
268 * in the entire article database. This may include pages
269 * in namespaces that would not be matched on the given
272 * Return null if no total hits number is supported.
277 function getTotalHits() {
282 * Some search modes return a suggested alternate term if there are
283 * no exact hits. Returns true if there is one on this set.
288 function hasSuggestion() {
293 * Some search modes return a suggested alternate term if there are
294 * no exact hits. Check hasSuggestion() first.
299 function getSuggestion() {
304 * Fetches next search result, or false.
305 * @return SearchResult
319 function SearchResult( $row ) {
320 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
327 function getTitle() {
328 return $this->mTitle
;
332 * @return double or null if not supported
334 function getScore() {
342 class SearchEngineDummy
{
343 function search( $term ) {
346 function setLimitOffset($l, $o) {}
347 function legalSearchChars() {}
349 function setnamespaces() {}
350 function searchtitle() {}
351 function searchtext() {}