3 * Contain a class for special pages
12 var $searchTerms = array();
13 var $namespaces = array( NS_MAIN
);
14 var $showRedirects = false;
17 * Perform a full text search query and return a result set.
18 * If title searches are not supported or disabled, return null.
20 * @param string $term - Raw search term
21 * @return SearchResultSet
25 function searchText( $term ) {
30 * Perform a title-only search query and return a result set.
31 * If title searches are not supported or disabled, return null.
33 * @param string $term - Raw search term
34 * @return SearchResultSet
38 function searchTitle( $term ) {
43 * If an exact title match can be find, or a very slightly close match,
44 * return the title. If no match, returns NULL.
51 function getNearMatch( $searchterm ) {
54 $allSearchTerms = array($searchterm);
56 if($wgContLang->hasVariants()){
57 $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm));
60 foreach($allSearchTerms as $term){
62 # Exact match? No need to look further.
63 $title = Title
::newFromText( $term );
67 if ( $title->getNamespace() == NS_SPECIAL ||
$title->exists() ) {
71 # Now try all lower case (i.e. first letter capitalized)
73 $title = Title
::newFromText( $wgContLang->lc( $term ) );
74 if ( $title->exists() ) {
78 # Now try capitalized string
80 $title = Title
::newFromText( $wgContLang->ucwords( $term ) );
81 if ( $title->exists() ) {
85 # Now try all upper case
87 $title = Title
::newFromText( $wgContLang->uc( $term ) );
88 if ( $title->exists() ) {
92 # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
93 $title = Title
::newFromText( $wgContLang->ucwordbreaks($term) );
94 if ( $title->exists() ) {
98 global $wgCapitalLinks, $wgContLang;
99 if( !$wgCapitalLinks ) {
100 // Catch differs-by-first-letter-case-only
101 $title = Title
::newFromText( $wgContLang->ucfirst( $term ) );
102 if ( $title->exists() ) {
105 $title = Title
::newFromText( $wgContLang->lcfirst( $term ) );
106 if ( $title->exists() ) {
112 $title = Title
::newFromText( $searchterm );
114 # Entering an IP address goes to the contributions page
115 if ( ( $title->getNamespace() == NS_USER
&& User
::isIP($title->getText() ) )
116 || User
::isIP( trim( $searchterm ) ) ) {
117 return SpecialPage
::getTitleFor( 'Contributions', $title->getDbkey() );
121 # Entering a user goes to the user page whether it's there or not
122 if ( $title->getNamespace() == NS_USER
) {
126 # Quoted term? Try without the quotes...
128 if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) {
129 return SearchEngine
::getNearMatch( $matches[1] );
135 public static function legalSearchChars() {
136 return "A-Za-z_'0-9\\x80-\\xFF\\-";
140 * Set the maximum number of results to return
141 * and how many to skip before returning the first.
147 function setLimitOffset( $limit, $offset = 0 ) {
148 $this->limit
= intval( $limit );
149 $this->offset
= intval( $offset );
153 * Set which namespaces the search should include.
154 * Give an array of namespace index numbers.
156 * @param array $namespaces
159 function setNamespaces( $namespaces ) {
160 $this->namespaces
= $namespaces;
164 * Make a list of searchable namespaces and their canonical names.
168 function searchableNamespaces() {
171 foreach( $wgContLang->getNamespaces() as $ns => $name ) {
172 if( $ns >= NS_MAIN
) {
180 * Return a 'cleaned up' search string
185 function filter( $text ) {
186 $lc = $this->legalSearchChars();
187 return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
190 * Load up the appropriate search engine class for the currently
191 * active database backend, and return a configured instance.
193 * @return SearchEngine
195 public static function create() {
196 global $wgDBtype, $wgSearchType;
197 if( $wgSearchType ) {
198 $class = $wgSearchType;
199 } elseif( $wgDBtype == 'mysql' ) {
200 $class = 'SearchMySQL4';
201 } else if ( $wgDBtype == 'postgres' ) {
202 $class = 'SearchPostgres';
203 } else if ( $wgDBtype == 'oracle' ) {
204 $class = 'SearchOracle';
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 class SearchResultSet
{
241 * Fetch an array of regular expression fragments for matching
242 * the search terms as parsed by this engine in a text extract.
248 function termMatches() {
257 * Return true if results are included in this result set.
261 function hasResults() {
266 * Some search modes return a total hit count for the query
267 * in the entire article database. This may include pages
268 * in namespaces that would not be matched on the given
271 * Return null if no total hits number is supported.
276 function getTotalHits() {
281 * Some search modes return a suggested alternate term if there are
282 * no exact hits. Returns true if there is one on this set.
287 function hasSuggestion() {
292 * Some search modes return a suggested alternate term if there are
293 * no exact hits. Check hasSuggestion() first.
298 function getSuggestion() {
303 * Fetches next search result, or false.
304 * @return SearchResult
314 function SearchResult( $row ) {
315 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
322 function getTitle() {
323 return $this->mTitle
;
327 * @return double or null if not supported
329 function getScore() {
336 class SearchEngineDummy
{
337 function search( $term ) {
340 function setLimitOffset($l, $o) {}
341 function legalSearchChars() {}
343 function setnamespaces() {}
344 function searchtitle() {}
345 function searchtext() {}