46e77ec3087625950aa6454346e73276fc032774
3 * Contain a class for special pages
14 var $searchTerms = array();
15 var $namespaces = array( 0 );
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 ) {
54 # Exact match? No need to look further.
55 $title = Title
::newFromText( $term );
56 if ( $title->getNamespace() == NS_SPECIAL ||
$title->exists() ) {
60 # Now try all lower case (i.e. first letter capitalized)
62 $title = Title
::newFromText( strtolower( $term ) );
63 if ( $title->exists() ) {
67 # Now try capitalized string
69 $title = Title
::newFromText( ucwords( strtolower( $term ) ) );
70 if ( $title->exists() ) {
74 # Now try all upper case
76 $title = Title
::newFromText( strtoupper( $term ) );
77 if ( $title->exists() ) {
81 $title = Title
::newFromText( $term );
83 # Entering an IP address goes to the contributions page
84 if ( ( $title->getNamespace() == NS_USER
&& User
::isIP($title->getText() ) )
85 || User
::isIP( trim( $term ) ) ) {
86 return Title
::makeTitle( NS_SPECIAL
, "Contributions/" . $title->getDbkey() );
90 # Entering a user goes to the user page whether it's there or not
91 if ( $title->getNamespace() == NS_USER
) {
95 # Quoted term? Try without the quotes...
96 if( preg_match( '/^"([^"]+)"$/', $term, $matches ) ) {
97 return SearchEngine
::getNearMatch( $matches[1] );
103 function legalSearchChars() {
104 return "A-Za-z_'0-9\\x80-\\xFF\\-";
108 * Set the maximum number of results to return
109 * and how many to skip before returning the first.
115 function setLimitOffset( $limit, $offset = 0 ) {
116 $this->limit
= IntVal( $limit );
117 $this->offset
= IntVal( $offset );
121 * Set which namespaces the search should include.
122 * Give an array of namespace index numbers.
124 * @param array $namespaces
127 function setNamespaces( $namespaces ) {
128 $this->namespaces
= $namespaces;
132 * Make a list of searchable namespaces and their canonical names.
136 function searchableNamespaces() {
139 foreach( $wgContLang->getNamespaces() as $ns => $name ) {
140 if( $ns >= NS_MAIN
) {
148 * Return a 'cleaned up' search string
153 function filter( $text ) {
154 $lc = $this->legalSearchChars();
155 return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
158 * Load up the appropriate search engine class for the currently
159 * active database backend, and return a configured instance.
161 * @return SearchEngine
165 global $wgDBtype, $wgDBmysql4, $wgSearchType;
166 if( $wgSearchType ) {
167 $class = $wgSearchType;
168 } elseif( $wgDBtype == 'mysql' ) {
170 $class = 'SearchMySQL4';
171 require_once( 'SearchMySQL4.php' );
173 $class = 'SearchMysql3';
174 require_once( 'SearchMySQL3.php' );
176 } else if ( $wgDBtype == 'PostgreSQL' ) {
177 $class = 'SearchTsearch2';
178 require_once( 'SearchTsearch2.php' );
180 $class = 'SearchEngineDummy';
182 $search = new $class( wfGetDB( DB_SLAVE
) );
183 $search->setLimitOffset(0,0);
188 * Create or update the search index record for the given page.
189 * Title and text should be pre-processed.
192 * @param string $title
193 * @param string $text
196 function update( $id, $title, $text ) {
201 * Update a search index record's title only.
202 * Title should be pre-processed.
205 * @param string $title
208 function updateTitle( $id, $title ) {
213 class SearchResultSet
{
215 * Fetch an array of regular expression fragments for matching
216 * the search terms as parsed by this engine in a text extract.
222 function termMatches() {
231 * Return true if results are included in this result set.
235 function hasResults() {
240 * Some search modes return a total hit count for the query
241 * in the entire article database. This may include pages
242 * in namespaces that would not be matched on the given
245 * Return null if no total hits number is supported.
250 function getTotalHits() {
255 * Some search modes return a suggested alternate term if there are
256 * no exact hits. Returns true if there is one on this set.
261 function hasSuggestion() {
266 * Some search modes return a suggested alternate term if there are
267 * no exact hits. Check hasSuggestion() first.
272 function getSuggestion() {
277 * Fetches next search result, or false.
278 * @return SearchResult
288 function SearchResult( $row ) {
289 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
296 function getTitle() {
297 return $this->mTitle
;
301 * @return double or null if not supported
303 function getScore() {
311 class SearchEngineDummy
{
312 function search( $term ) {