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 Title
::makeTitle( NS_SPECIAL
, "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...
129 if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) {
130 return SearchEngine
::getNearMatch( $matches[1] );
136 function legalSearchChars() {
137 return "A-Za-z_'0-9\\x80-\\xFF\\-";
141 * Set the maximum number of results to return
142 * and how many to skip before returning the first.
148 function setLimitOffset( $limit, $offset = 0 ) {
149 $this->limit
= intval( $limit );
150 $this->offset
= intval( $offset );
154 * Set which namespaces the search should include.
155 * Give an array of namespace index numbers.
157 * @param array $namespaces
160 function setNamespaces( $namespaces ) {
161 $this->namespaces
= $namespaces;
165 * Make a list of searchable namespaces and their canonical names.
169 function searchableNamespaces() {
172 foreach( $wgContLang->getNamespaces() as $ns => $name ) {
173 if( $ns >= NS_MAIN
) {
181 * Return a 'cleaned up' search string
186 function filter( $text ) {
187 $lc = $this->legalSearchChars();
188 return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
191 * Load up the appropriate search engine class for the currently
192 * active database backend, and return a configured instance.
194 * @return SearchEngine
198 global $wgDBtype, $wgSearchType;
199 if( $wgSearchType ) {
200 $class = $wgSearchType;
201 } elseif( $wgDBtype == 'mysql' ) {
202 $class = 'SearchMySQL4';
203 } else if ( $wgDBtype == 'postgres' ) {
204 $class = 'SearchPostgres';
206 $class = 'SearchEngineDummy';
208 $search = new $class( wfGetDB( DB_SLAVE
) );
209 $search->setLimitOffset(0,0);
214 * Create or update the search index record for the given page.
215 * Title and text should be pre-processed.
218 * @param string $title
219 * @param string $text
222 function update( $id, $title, $text ) {
227 * Update a search index record's title only.
228 * Title should be pre-processed.
231 * @param string $title
234 function updateTitle( $id, $title ) {
239 /** @package MediaWiki */
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
314 /** @package MediaWiki */
316 function SearchResult( $row ) {
317 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
324 function getTitle() {
325 return $this->mTitle
;
329 * @return double or null if not supported
331 function getScore() {
339 class SearchEngineDummy
{
340 function search( $term ) {
343 function setLimitOffset($l, $o) {}
344 function legalSearchChars() {}
346 function setnamespaces() {}
347 function searchtitle() {}
348 function searchtext() {}