6af1e415965439952dbcf553340fa00a81435832
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( $term ) {
55 # Exact match? No need to look further.
56 $title = Title
::newFromText( $term );
60 if ( $title->getNamespace() == NS_SPECIAL ||
$title->exists() ) {
64 # Now try all lower case (i.e. first letter capitalized)
66 $title = Title
::newFromText( $wgContLang->lc( $term ) );
67 if ( $title->exists() ) {
71 # Now try capitalized string
73 $title = Title
::newFromText( $wgContLang->ucwords( $term ) );
74 if ( $title->exists() ) {
78 # Now try all upper case
80 $title = Title
::newFromText( $wgContLang->uc( $term ) );
81 if ( $title->exists() ) {
85 # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
86 $title = Title
::newFromText( $wgContLang->ucwordbreaks($term) );
87 if ( $title->exists() ) {
91 global $wgCapitalLinks, $wgContLang;
92 if( !$wgCapitalLinks ) {
93 // Catch differs-by-first-letter-case-only
94 $title = Title
::newFromText( $wgContLang->ucfirst( $term ) );
95 if ( $title->exists() ) {
98 $title = Title
::newFromText( $wgContLang->lcfirst( $term ) );
99 if ( $title->exists() ) {
104 $title = Title
::newFromText( $term );
106 # Entering an IP address goes to the contributions page
107 if ( ( $title->getNamespace() == NS_USER
&& User
::isIP($title->getText() ) )
108 || User
::isIP( trim( $term ) ) ) {
109 return Title
::makeTitle( NS_SPECIAL
, "Contributions/" . $title->getDbkey() );
113 # Entering a user goes to the user page whether it's there or not
114 if ( $title->getNamespace() == NS_USER
) {
118 # Quoted term? Try without the quotes...
119 if( preg_match( '/^"([^"]+)"$/', $term, $matches ) ) {
120 return SearchEngine
::getNearMatch( $matches[1] );
126 function legalSearchChars() {
127 return "A-Za-z_'0-9\\x80-\\xFF\\-";
131 * Set the maximum number of results to return
132 * and how many to skip before returning the first.
138 function setLimitOffset( $limit, $offset = 0 ) {
139 $this->limit
= intval( $limit );
140 $this->offset
= intval( $offset );
144 * Set which namespaces the search should include.
145 * Give an array of namespace index numbers.
147 * @param array $namespaces
150 function setNamespaces( $namespaces ) {
151 $this->namespaces
= $namespaces;
155 * Make a list of searchable namespaces and their canonical names.
159 function searchableNamespaces() {
162 foreach( $wgContLang->getNamespaces() as $ns => $name ) {
163 if( $ns >= NS_MAIN
) {
171 * Return a 'cleaned up' search string
176 function filter( $text ) {
177 $lc = $this->legalSearchChars();
178 return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
181 * Load up the appropriate search engine class for the currently
182 * active database backend, and return a configured instance.
184 * @return SearchEngine
188 global $wgDBtype, $wgSearchType;
189 if( $wgSearchType ) {
190 $class = $wgSearchType;
191 } elseif( $wgDBtype == 'mysql' ) {
192 $class = 'SearchMySQL4';
193 } else if ( $wgDBtype == 'postgres' ) {
194 $class = 'SearchPostgres';
196 $class = 'SearchEngineDummy';
198 $search = new $class( wfGetDB( DB_SLAVE
) );
199 $search->setLimitOffset(0,0);
204 * Create or update the search index record for the given page.
205 * Title and text should be pre-processed.
208 * @param string $title
209 * @param string $text
212 function update( $id, $title, $text ) {
217 * Update a search index record's title only.
218 * Title should be pre-processed.
221 * @param string $title
224 function updateTitle( $id, $title ) {
229 /** @package MediaWiki */
230 class SearchResultSet
{
232 * Fetch an array of regular expression fragments for matching
233 * the search terms as parsed by this engine in a text extract.
239 function termMatches() {
248 * Return true if results are included in this result set.
252 function hasResults() {
257 * Some search modes return a total hit count for the query
258 * in the entire article database. This may include pages
259 * in namespaces that would not be matched on the given
262 * Return null if no total hits number is supported.
267 function getTotalHits() {
272 * Some search modes return a suggested alternate term if there are
273 * no exact hits. Returns true if there is one on this set.
278 function hasSuggestion() {
283 * Some search modes return a suggested alternate term if there are
284 * no exact hits. Check hasSuggestion() first.
289 function getSuggestion() {
294 * Fetches next search result, or false.
295 * @return SearchResult
304 /** @package MediaWiki */
306 function SearchResult( $row ) {
307 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
314 function getTitle() {
315 return $this->mTitle
;
319 * @return double or null if not supported
321 function getScore() {
329 class SearchEngineDummy
{
330 function search( $term ) {
333 function setLimitOffset($l, $o) {}
334 function legalSearchChars() {}
336 function setnamespaces() {}
337 function searchtitle() {}
338 function searchtext() {}