3 * @defgroup Search Search
10 * Contain a class for special pages
16 var $searchTerms = array();
17 var $namespaces = array( NS_MAIN
);
18 var $showRedirects = false;
21 * Perform a full text search query and return a result set.
22 * If title searches are not supported or disabled, return null.
24 * @param string $term - Raw search term
25 * @return SearchResultSet
29 function searchText( $term ) {
34 * Perform a title-only search query and return a result set.
35 * If title searches are not supported or disabled, return null.
37 * @param string $term - Raw search term
38 * @return SearchResultSet
42 function searchTitle( $term ) {
47 * If an exact title match can be find, or a very slightly close match,
48 * return the title. If no match, returns NULL.
53 public static 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->isExternal()
70 ||
$title->exists() ) {
74 # Now try all lower case (i.e. first letter capitalized)
76 $title = Title
::newFromText( $wgContLang->lc( $term ) );
77 if ( $title && $title->exists() ) {
81 # Now try capitalized string
83 $title = Title
::newFromText( $wgContLang->ucwords( $term ) );
84 if ( $title && $title->exists() ) {
88 # Now try all upper case
90 $title = Title
::newFromText( $wgContLang->uc( $term ) );
91 if ( $title && $title->exists() ) {
95 # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
96 $title = Title
::newFromText( $wgContLang->ucwordbreaks($term) );
97 if ( $title && $title->exists() ) {
101 global $wgCapitalLinks, $wgContLang;
102 if( !$wgCapitalLinks ) {
103 // Catch differs-by-first-letter-case-only
104 $title = Title
::newFromText( $wgContLang->ucfirst( $term ) );
105 if ( $title && $title->exists() ) {
108 $title = Title
::newFromText( $wgContLang->lcfirst( $term ) );
109 if ( $title && $title->exists() ) {
114 // Give hooks a chance at better match variants
116 if( !wfRunHooks( 'SearchGetNearMatch', array( $term, &$title ) ) ) {
121 $title = Title
::newFromText( $searchterm );
123 # Entering an IP address goes to the contributions page
124 if ( ( $title->getNamespace() == NS_USER
&& User
::isIP($title->getText() ) )
125 || User
::isIP( trim( $searchterm ) ) ) {
126 return SpecialPage
::getTitleFor( 'Contributions', $title->getDBkey() );
130 # Entering a user goes to the user page whether it's there or not
131 if ( $title->getNamespace() == NS_USER
) {
135 # Go to images that exist even if there's no local page.
136 # There may have been a funny upload, or it may be on a shared
137 # file repository such as Wikimedia Commons.
138 if( $title->getNamespace() == NS_IMAGE
) {
139 $image = wfFindFile( $title );
145 # MediaWiki namespace? Page may be "implied" if not customized.
146 # Just return it, with caps forced as the message system likes it.
147 if( $title->getNamespace() == NS_MEDIAWIKI
) {
148 return Title
::makeTitle( NS_MEDIAWIKI
, $wgContLang->ucfirst( $title->getText() ) );
151 # Quoted term? Try without the quotes...
153 if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) {
154 return SearchEngine
::getNearMatch( $matches[1] );
160 public static function legalSearchChars() {
161 return "A-Za-z_'0-9\\x80-\\xFF\\-";
165 * Set the maximum number of results to return
166 * and how many to skip before returning the first.
172 function setLimitOffset( $limit, $offset = 0 ) {
173 $this->limit
= intval( $limit );
174 $this->offset
= intval( $offset );
178 * Set which namespaces the search should include.
179 * Give an array of namespace index numbers.
181 * @param array $namespaces
184 function setNamespaces( $namespaces ) {
185 $this->namespaces
= $namespaces;
189 * Parse some common prefixes: all (search everything)
192 * @param string $query
194 function replacePrefixes( $query ){
197 if( strpos($query,':') === false )
198 return $query; // nothing to do
201 $allkeyword = wfMsgForContent('searchall').":";
202 if( strncmp($query, $allkeyword, strlen($allkeyword)) == 0 ){
203 $this->namespaces
= null;
204 $parsed = substr($query,strlen($allkeyword));
205 } else if( strpos($query,':') !== false ) {
206 $prefix = substr($query,0,strpos($query,':'));
207 $index = $wgContLang->getNsIndex($prefix);
208 if($index !== false){
209 $this->namespaces
= array($index);
210 $parsed = substr($query,strlen($prefix)+
1);
213 if(trim($parsed) == '')
214 return $query; // prefix was the whole query
220 * Make a list of searchable namespaces and their canonical names.
223 public static function searchableNamespaces() {
226 foreach( $wgContLang->getNamespaces() as $ns => $name ) {
227 if( $ns >= NS_MAIN
) {
235 * Extract default namespaces to search from the given user's
236 * settings, returning a list of index numbers.
242 public static function userNamespaces( &$user ) {
244 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
245 if( $user->getOption( 'searchNs' . $ns ) ) {
253 * Find snippet highlight settings for a given user
256 * @return array contextlines, contextchars
259 public static function userHighlightPrefs( &$user ){
260 //$contextlines = $user->getOption( 'contextlines', 5 );
261 //$contextchars = $user->getOption( 'contextchars', 50 );
262 $contextlines = 2; // Hardcode this. Old defaults sucked. :)
263 $contextchars = 75; // same as above.... :P
264 return array($contextlines, $contextchars);
268 * An array of namespaces indexes to be searched by default
273 public static function defaultNamespaces(){
274 global $wgNamespacesToBeSearchedDefault;
276 return array_keys($wgNamespacesToBeSearchedDefault, true);
280 * Return a 'cleaned up' search string
285 function filter( $text ) {
286 $lc = $this->legalSearchChars();
287 return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
290 * Load up the appropriate search engine class for the currently
291 * active database backend, and return a configured instance.
293 * @return SearchEngine
295 public static function create() {
296 global $wgDBtype, $wgSearchType;
297 if( $wgSearchType ) {
298 $class = $wgSearchType;
299 } elseif( $wgDBtype == 'mysql' ) {
300 $class = 'SearchMySQL';
301 } else if ( $wgDBtype == 'postgres' ) {
302 $class = 'SearchPostgres';
303 } else if ( $wgDBtype == 'oracle' ) {
304 $class = 'SearchOracle';
306 $class = 'SearchEngineDummy';
308 $search = new $class( wfGetDB( DB_SLAVE
) );
309 $search->setLimitOffset(0,0);
314 * Create or update the search index record for the given page.
315 * Title and text should be pre-processed.
318 * @param string $title
319 * @param string $text
322 function update( $id, $title, $text ) {
327 * Update a search index record's title only.
328 * Title should be pre-processed.
331 * @param string $title
334 function updateTitle( $id, $title ) {
339 * Get OpenSearch suggestion template
344 public static function getOpenSearchTemplate() {
345 global $wgOpenSearchTemplate, $wgServer, $wgScriptPath;
346 if($wgOpenSearchTemplate)
347 return $wgOpenSearchTemplate;
349 $ns = implode(',',SearchEngine
::defaultNamespaces());
351 return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace='.$ns;
356 * Get internal MediaWiki Suggest template
361 public static function getMWSuggestTemplate() {
362 global $wgMWSuggestTemplate, $wgServer, $wgScriptPath;
363 if($wgMWSuggestTemplate)
364 return $wgMWSuggestTemplate;
366 return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace={namespaces}';
373 class SearchResultSet
{
375 * Fetch an array of regular expression fragments for matching
376 * the search terms as parsed by this engine in a text extract.
382 function termMatches() {
391 * Return true if results are included in this result set.
395 function hasResults() {
400 * Some search modes return a total hit count for the query
401 * in the entire article database. This may include pages
402 * in namespaces that would not be matched on the given
405 * Return null if no total hits number is supported.
410 function getTotalHits() {
415 * Some search modes return a suggested alternate term if there are
416 * no exact hits. Returns true if there is one on this set.
421 function hasSuggestion() {
426 * @return string suggested query, null if none
428 function getSuggestionQuery(){
433 * @return string highlighted suggested query, '' if none
435 function getSuggestionSnippet(){
440 * Return information about how and from where the results were fetched,
441 * should be useful for diagnostics and debugging
450 * Return a result set of hits on other (multiple) wikis associated with this one
452 * @return SearchResultSet
454 function getInterwikiResults() {
459 * Check if there are results on other wikis
463 function hasInterwikiResults() {
464 return $this->getInterwikiResults() != null;
469 * Fetches next search result, or false.
470 * @return SearchResult
479 * Frees the result set, if applicable.
491 class SearchResultTooMany
{
492 ## Some search engines may bail out if too many matches are found
500 var $mRevision = null;
502 function SearchResult( $row ) {
503 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
504 if( !is_null($this->mTitle
) )
505 $this->mRevision
= Revision
::newFromTitle( $this->mTitle
);
509 * Check if this is result points to an invalid title
514 function isBrokenTitle(){
515 if( is_null($this->mTitle
) )
521 * Check if target page is missing, happens when index is out of date
526 function isMissingRevision(){
527 if( !$this->mRevision
)
536 function getTitle() {
537 return $this->mTitle
;
541 * @return double or null if not supported
543 function getScore() {
548 * Lazy initialization of article text from DB
550 protected function initText(){
551 if( !isset($this->mText
) ){
552 $this->mText
= $this->mRevision
->getText();
557 * @param array $terms terms to highlight
558 * @return string highlighted text snippet, null (and not '') if not supported
560 function getTextSnippet($terms){
561 global $wgUser, $wgAdvancedSearchHighlighting;
563 list($contextlines,$contextchars) = SearchEngine
::userHighlightPrefs($wgUser);
564 $h = new SearchHighlighter();
565 if( $wgAdvancedSearchHighlighting )
566 return $h->highlightText( $this->mText
, $terms, $contextlines, $contextchars );
568 return $h->highlightSimple( $this->mText
, $terms, $contextlines, $contextchars );
572 * @param array $terms terms to highlight
573 * @return string highlighted title, '' if not supported
575 function getTitleSnippet($terms){
580 * @param array $terms terms to highlight
581 * @return string highlighted redirect name (redirect to this page), '' if none or not supported
583 function getRedirectSnippet($terms){
588 * @return Title object for the redirect to this page, null if none or not supported
590 function getRedirectTitle(){
595 * @return string highlighted relevant section name, null if none or not supported
597 function getSectionSnippet(){
602 * @return Title object (pagename+fragment) for the section, null if none or not supported
604 function getSectionTitle(){
609 * @return string timestamp
611 function getTimestamp(){
612 return $this->mRevision
->getTimestamp();
616 * @return int number of words
618 function getWordCount(){
620 return str_word_count( $this->mText
);
624 * @return int size in bytes
626 function getByteSize(){
628 return strlen( $this->mText
);
632 * @return boolean if hit has related articles
634 function hasRelated(){
639 * @return interwiki prefix of the title (return iw even if title is broken)
641 function getInterwikiPrefix(){
647 * Highlight bits of wikitext
651 class SearchHighlighter
{
652 var $mCleanWikitext = true;
654 function SearchHighlighter($cleanupWikitext = true){
655 $this->mCleanWikitext
= $cleanupWikitext;
659 * Default implementation of wikitext highlighting
661 * @param string $text
662 * @param array $terms Terms to highlight (unescaped)
663 * @param int $contextlines
664 * @param int $contextchars
667 public function highlightText( $text, $terms, $contextlines, $contextchars ) {
668 global $wgLang, $wgContLang;
669 global $wgSearchHighlightBoundaries;
675 // spli text into text + templates/links/tables
676 $spat = "/(\\{\\{)|(\\[\\[[^\\]:]+:)|(\n\\{\\|)";
677 // first capture group is for detecting nested templates/links/tables/references
678 $endPatterns = array(
679 1 => '/(\{\{)|(\}\})/', // template
680 2 => '/(\[\[)|(\]\])/', // image
681 3 => "/(\n\\{\\|)|(\n\\|\\})/"); // table
683 // FIXME: this should prolly be a hook or something
684 if(function_exists('wfCite')){
685 $spat .= '|(<ref>)'; // references via cite extension
686 $endPatterns[4] = '/(<ref>)|(<\/ref>)/';
689 $textExt = array(); // text extracts
690 $otherExt = array(); // other extracts
691 wfProfileIn( "$fname-split" );
693 $textLen = strlen($text);
694 $count = 0; // sequence number to maintain ordering
695 while( $start < $textLen ){
696 // find start of template/image/table
697 if( preg_match( $spat, $text, $matches, PREG_OFFSET_CAPTURE
, $start ) ){
699 foreach($matches as $key => $val){
700 if($key > 0 && $val[1] != -1){
702 // see if this is an image link
703 $ns = substr($val[0],2,-1);
704 if( $wgContLang->getNsIndex($ns) != NS_IMAGE
)
708 $epat = $endPatterns[$key];
709 $this->splitAndAdd( $textExt, $count, substr( $text, $start, $val[1] - $start ) );
715 // find end (and detect any nested elements)
717 $offset = $start +
1;
719 while( preg_match( $epat, $text, $endMatches, PREG_OFFSET_CAPTURE
, $offset ) ){
720 if( array_key_exists(2,$endMatches) ){
723 $len = strlen($endMatches[2][0]);
724 $off = $endMatches[2][1];
725 $this->splitAndAdd( $otherExt, $count,
726 substr( $text, $start, $off +
$len - $start ) );
727 $start = $off +
$len;
731 // end of nested element
738 $offset = $endMatches[0][1] +
strlen($endMatches[0][0]);
741 // couldn't find appropriate closing tag, skip
742 $this->splitAndAdd( $textExt, $count, substr( $text, $start, strlen($matches[0][0]) ) );
743 $start +
= strlen($matches[0][0]);
748 // else: add as text extract
749 $this->splitAndAdd( $textExt, $count, substr($text,$start) );
753 $all = $textExt +
$otherExt; // these have disjunct key sets
755 wfProfileOut( "$fname-split" );
758 foreach( $terms as $index => $term ) {
759 $terms[$index] = preg_quote( $term, '/' );
760 // manually do upper/lowercase stuff for utf-8 since PHP won't do it
761 if(preg_match('/[\x80-\xff]/', $term) ){
762 $terms[$index] = preg_replace_callback('/./us',array($this,'caseCallback'),$terms[$index]);
767 $anyterm = implode( '|', $terms );
768 $phrase = implode("$wgSearchHighlightBoundaries+", $terms );
770 // FIXME: a hack to scale contextchars, a correct solution
771 // would be to have contextchars actually be char and not byte
772 // length, and do proper utf-8 substrings and lengths everywhere,
773 // but PHP is making that very hard and unclean to implement :(
774 $scale = strlen($anyterm) / mb_strlen($anyterm);
775 $contextchars = intval( $contextchars * $scale );
777 $patPre = "(^|$wgSearchHighlightBoundaries)";
778 $patPost = "($wgSearchHighlightBoundaries|$)";
780 $pat1 = "/(".$phrase.")/ui";
781 $pat2 = "/$patPre(".$anyterm.")$patPost/ui";
783 wfProfileIn( "$fname-extract" );
785 $left = $contextlines;
790 // show beginning only if it contains all words
793 foreach($textExt as $index => $line){
794 if(strlen($line)>0 && $line[0] != ';' && $line[0] != ':'){
795 $firstText = $this->extract( $line, 0, $contextchars * $contextlines );
802 // check if first text contains all terms
803 foreach($terms as $term){
804 if( ! preg_match("/$patPre".$term."$patPost/ui", $firstText) ){
810 $snippets[$first] = $firstText;
811 $offsets[$first] = 0;
815 // match whole query on text
816 $this->process($pat1, $textExt, $left, $contextchars, $snippets, $offsets);
817 // match whole query on templates/tables/images
818 $this->process($pat1, $otherExt, $left, $contextchars, $snippets, $offsets);
819 // match any words on text
820 $this->process($pat2, $textExt, $left, $contextchars, $snippets, $offsets);
821 // match any words on templates/tables/images
822 $this->process($pat2, $otherExt, $left, $contextchars, $snippets, $offsets);
827 // add extra chars to each snippet to make snippets constant size
829 if( count( $snippets ) == 0){
830 // couldn't find the target words, just show beginning of article
831 $targetchars = $contextchars * $contextlines;
832 $snippets[$first] = '';
833 $offsets[$first] = 0;
835 // if begin of the article contains the whole phrase, show only that !!
836 if( array_key_exists($first,$snippets) && preg_match($pat1,$snippets[$first])
837 && $offsets[$first] < $contextchars * 2 ){
838 $snippets = array ($first => $snippets[$first]);
841 // calc by how much to extend existing snippets
842 $targetchars = intval( ($contextchars * $contextlines) / count ( $snippets ) );
845 foreach($snippets as $index => $line){
846 $extended[$index] = $line;
847 $len = strlen($line);
848 if( $len < $targetchars - 20 ){
849 // complete this line
850 if($len < strlen( $all[$index] )){
851 $extended[$index] = $this->extract( $all[$index], $offsets[$index], $offsets[$index]+
$targetchars, $offsets[$index]);
852 $len = strlen( $extended[$index] );
857 while( $len < $targetchars - 20
858 && array_key_exists($add,$all)
859 && !array_key_exists($add,$snippets) ){
861 $tt = "\n".$this->extract( $all[$add], 0, $targetchars - $len, $offsets[$add] );
862 $extended[$add] = $tt;
863 $len +
= strlen( $tt );
869 //$snippets = array_map('htmlspecialchars', $extended);
870 $snippets = $extended;
873 foreach($snippets as $index => $line){
875 $extract .= $line; // first line
876 elseif($last+
1 == $index && $offsets[$last]+
strlen($snippets[$last]) >= strlen($all[$last]))
877 $extract .= " ".$line; // continous lines
879 $extract .= '<b> ... </b>' . $line;
884 $extract .= '<b> ... </b>';
886 $processed = array();
887 foreach($terms as $term){
888 if( ! isset($processed[$term]) ){
889 $pat3 = "/$patPre(".$term.")$patPost/ui"; // highlight word
890 $extract = preg_replace( $pat3,
891 "\\1<span class='searchmatch'>\\2</span>\\3", $extract );
892 $processed[$term] = true;
896 wfProfileOut( "$fname-extract" );
902 * Split text into lines and add it to extracts array
904 * @param array $extracts index -> $line
906 * @param string $text
908 function splitAndAdd(&$extracts, &$count, $text){
909 $split = explode( "\n", $this->mCleanWikitext?
$this->removeWiki($text) : $text );
910 foreach($split as $line){
913 $extracts[$count++
] = $tt;
918 * Do manual case conversion for non-ascii chars
920 * @param unknown_type $matches
922 function caseCallback($matches){
924 if( strlen($matches[0]) > 1 ){
925 return '['.$wgContLang->lc($matches[0]).$wgContLang->uc($matches[0]).']';
931 * Extract part of the text from start to end, but by
932 * not chopping up words
933 * @param string $text
936 * @param int $posStart (out) actual start position
937 * @param int $posEnd (out) actual end position
940 function extract($text, $start, $end, &$posStart = null, &$posEnd = null ){
944 $start = $this->position( $text, $start, 1 );
945 if( $end >= strlen($text) )
946 $end = strlen($text);
948 $end = $this->position( $text, $end );
950 if(!is_null($posStart))
952 if(!is_null($posEnd))
956 return substr($text, $start, $end-$start);
962 * Find a nonletter near a point (index) in the text
964 * @param string $text
966 * @param int $offset to found index
967 * @return int nearest nonletter index, or beginning of utf8 char if none
969 function position($text, $point, $offset=0 ){
971 $s = max( 0, $point - $tolerance );
972 $l = min( strlen($text), $point +
$tolerance ) - $s;
974 if( preg_match('/[ ,.!?~!@#$%^&*\(\)+=\-\\\|\[\]"\'<>]/', substr($text,$s,$l), $m, PREG_OFFSET_CAPTURE
) ){
975 return $m[0][1] +
$s +
$offset;
977 // check if point is on a valid first UTF8 char
978 $char = ord( $text[$point] );
979 while( $char >= 0x80 && $char < 0xc0 ) {
980 // skip trailing bytes
982 if($point >= strlen($text))
983 return strlen($text);
984 $char = ord( $text[$point] );
992 * Search extracts for a pattern, and return snippets
994 * @param string $pattern regexp for matching lines
995 * @param array $extracts extracts to search
996 * @param int $linesleft number of extracts to make
997 * @param int $contextchars length of snippet
998 * @param array $out map for highlighted snippets
999 * @param array $offsets map of starting points of snippets
1002 function process( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets ){
1004 return; // nothing to do
1005 foreach($extracts as $index => $line){
1006 if( array_key_exists($index,$out) )
1007 continue; // this line already highlighted
1010 if ( !preg_match( $pattern, $line, $m, PREG_OFFSET_CAPTURE
) )
1014 $len = strlen($m[0][0]);
1015 if($offset +
$len < $contextchars)
1017 elseif( $len > $contextchars)
1020 $begin = $offset +
intval( ($len - $contextchars) / 2 );
1022 $end = $begin +
$contextchars;
1025 // basic snippet from this line
1026 $out[$index] = $this->extract($line,$begin,$end,$posBegin);
1027 $offsets[$index] = $posBegin;
1035 * Basic wikitext removal
1038 function removeWiki($text) {
1039 $fname = __METHOD__
;
1040 wfProfileIn( $fname );
1042 //$text = preg_replace("/'{2,5}/", "", $text);
1043 //$text = preg_replace("/\[[a-z]+:\/\/[^ ]+ ([^]]+)\]/", "\\2", $text);
1044 //$text = preg_replace("/\[\[([^]|]+)\]\]/", "\\1", $text);
1045 //$text = preg_replace("/\[\[([^]]+\|)?([^|]]+)\]\]/", "\\2", $text);
1046 //$text = preg_replace("/\\{\\|(.*?)\\|\\}/", "", $text);
1047 //$text = preg_replace("/\\[\\[[A-Za-z_-]+:([^|]+?)\\]\\]/", "", $text);
1048 $text = preg_replace("/\\{\\{([^|]+?)\\}\\}/", "", $text);
1049 $text = preg_replace("/\\{\\{([^|]+\\|)(.*?)\\}\\}/", "\\2", $text);
1050 $text = preg_replace("/\\[\\[([^|]+?)\\]\\]/", "\\1", $text);
1051 $text = preg_replace_callback("/\\[\\[([^|]+\\|)(.*?)\\]\\]/", array($this,'linkReplace'), $text);
1052 //$text = preg_replace("/\\[\\[([^|]+\\|)(.*?)\\]\\]/", "\\2", $text);
1053 $text = preg_replace("/<\/?[^>]+>/", "", $text);
1054 $text = preg_replace("/'''''/", "", $text);
1055 $text = preg_replace("/('''|<\/?[iIuUbB]>)/", "", $text);
1056 $text = preg_replace("/''/", "", $text);
1058 wfProfileOut( $fname );
1063 * callback to replace [[target|caption]] kind of links, if
1064 * the target is category or image, leave it
1066 * @param array $matches
1068 function linkReplace($matches){
1069 $colon = strpos( $matches[1], ':' );
1070 if( $colon === false )
1071 return $matches[2]; // replace with caption
1073 $ns = substr( $matches[1], 0, $colon );
1074 $index = $wgContLang->getNsIndex($ns);
1075 if( $index !== false && ($index == NS_IMAGE ||
$index == NS_CATEGORY
) )
1076 return $matches[0]; // return the whole thing
1083 * Simple & fast snippet extraction, but gives completely unrelevant
1086 * @param string $text
1087 * @param array $terms
1088 * @param int $contextlines
1089 * @param int $contextchars
1092 public function highlightSimple( $text, $terms, $contextlines, $contextchars ) {
1093 global $wgLang, $wgContLang;
1094 $fname = __METHOD__
;
1096 $lines = explode( "\n", $text );
1098 $terms = implode( '|', $terms );
1099 $terms = str_replace( '/', "\\/", $terms);
1100 $max = intval( $contextchars ) +
1;
1101 $pat1 = "/(.*)($terms)(.{0,$max})/i";
1106 wfProfileIn( "$fname-extract" );
1107 foreach ( $lines as $line ) {
1108 if ( 0 == $contextlines ) {
1113 if ( ! preg_match( $pat1, $line, $m ) ) {
1117 $pre = $wgContLang->truncate( $m[1], -$contextchars, ' ... ' );
1119 if ( count( $m ) < 3 ) {
1122 $post = $wgContLang->truncate( $m[3], $contextchars, ' ... ' );
1127 $line = htmlspecialchars( $pre . $found . $post );
1128 $pat2 = '/(' . $terms . ")/i";
1129 $line = preg_replace( $pat2,
1130 "<span class='searchmatch'>\\1</span>", $line );
1132 $extract .= "${line}\n";
1134 wfProfileOut( "$fname-extract" );
1144 class SearchEngineDummy
{
1145 function search( $term ) {
1148 function setLimitOffset($l, $o) {}
1149 function legalSearchChars() {}
1150 function update() {}
1151 function setnamespaces() {}
1152 function searchtitle() {}
1153 function searchtext() {}