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->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() ) {
113 // Give hooks a chance at better match variants
115 if( !wfRunHooks( 'SearchGetNearMatch', array( $term, &$title ) ) ) {
120 $title = Title
::newFromText( $searchterm );
122 # Entering an IP address goes to the contributions page
123 if ( ( $title->getNamespace() == NS_USER
&& User
::isIP($title->getText() ) )
124 || User
::isIP( trim( $searchterm ) ) ) {
125 return SpecialPage
::getTitleFor( 'Contributions', $title->getDBkey() );
129 # Entering a user goes to the user page whether it's there or not
130 if ( $title->getNamespace() == NS_USER
) {
134 # Go to images that exist even if there's no local page.
135 # There may have been a funny upload, or it may be on a shared
136 # file repository such as Wikimedia Commons.
137 if( $title->getNamespace() == NS_IMAGE
) {
138 $image = wfFindFile( $title );
144 # MediaWiki namespace? Page may be "implied" if not customized.
145 # Just return it, with caps forced as the message system likes it.
146 if( $title->getNamespace() == NS_MEDIAWIKI
) {
147 return Title
::makeTitle( NS_MEDIAWIKI
, $wgContLang->ucfirst( $title->getText() ) );
150 # Quoted term? Try without the quotes...
152 if( preg_match( '/^"([^"]+)"$/', $searchterm, $matches ) ) {
153 return SearchEngine
::getNearMatch( $matches[1] );
159 public static function legalSearchChars() {
160 return "A-Za-z_'0-9\\x80-\\xFF\\-";
164 * Set the maximum number of results to return
165 * and how many to skip before returning the first.
171 function setLimitOffset( $limit, $offset = 0 ) {
172 $this->limit
= intval( $limit );
173 $this->offset
= intval( $offset );
177 * Set which namespaces the search should include.
178 * Give an array of namespace index numbers.
180 * @param array $namespaces
183 function setNamespaces( $namespaces ) {
184 $this->namespaces
= $namespaces;
188 * Parse some common prefixes: all (search everything)
191 * @param string $query
193 function replacePrefixes( $query ){
196 if( strpos($query,':') === false )
197 return $query; // nothing to do
200 $allkeyword = wfMsgForContent('searchall').":";
201 if( strncmp($query, $allkeyword, strlen($allkeyword)) == 0 ){
202 $this->namespaces
= null;
203 $parsed = substr($query,strlen($allkeyword));
204 } else if( strpos($query,':') !== false ) {
205 $prefix = substr($query,0,strpos($query,':'));
206 $index = $wgContLang->getNsIndex($prefix);
207 if($index !== false){
208 $this->namespaces
= array($index);
209 $parsed = substr($query,strlen($prefix)+
1);
212 if(trim($parsed) == '')
213 return $query; // prefix was the whole query
219 * Make a list of searchable namespaces and their canonical names.
222 public static function searchableNamespaces() {
225 foreach( $wgContLang->getNamespaces() as $ns => $name ) {
226 if( $ns >= NS_MAIN
) {
234 * Extract default namespaces to search from the given user's
235 * settings, returning a list of index numbers.
241 public static function userNamespaces( &$user ) {
243 foreach( SearchEngine
::searchableNamespaces() as $ns => $name ) {
244 if( $user->getOption( 'searchNs' . $ns ) ) {
252 * Find snippet highlight settings for a given user
255 * @return array contextlines, contextchars
258 public static function userHighlightPrefs( &$user ){
259 //$contextlines = $user->getOption( 'contextlines', 5 );
260 //$contextchars = $user->getOption( 'contextchars', 50 );
261 $contextlines = 2; // Hardcode this. Old defaults sucked. :)
262 $contextchars = 75; // same as above.... :P
263 return array($contextlines, $contextchars);
267 * An array of namespaces indexes to be searched by default
272 public static function defaultNamespaces(){
273 global $wgNamespacesToBeSearchedDefault;
275 return array_keys($wgNamespacesToBeSearchedDefault, true);
279 * Return a 'cleaned up' search string
284 function filter( $text ) {
285 $lc = $this->legalSearchChars();
286 return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
289 * Load up the appropriate search engine class for the currently
290 * active database backend, and return a configured instance.
292 * @return SearchEngine
294 public static function create() {
295 global $wgDBtype, $wgSearchType;
296 if( $wgSearchType ) {
297 $class = $wgSearchType;
298 } elseif( $wgDBtype == 'mysql' ) {
299 $class = 'SearchMySQL';
300 } else if ( $wgDBtype == 'postgres' ) {
301 $class = 'SearchPostgres';
302 } else if ( $wgDBtype == 'oracle' ) {
303 $class = 'SearchOracle';
305 $class = 'SearchEngineDummy';
307 $search = new $class( wfGetDB( DB_SLAVE
) );
308 $search->setLimitOffset(0,0);
313 * Create or update the search index record for the given page.
314 * Title and text should be pre-processed.
317 * @param string $title
318 * @param string $text
321 function update( $id, $title, $text ) {
326 * Update a search index record's title only.
327 * Title should be pre-processed.
330 * @param string $title
333 function updateTitle( $id, $title ) {
338 * Get OpenSearch suggestion template
343 public static function getOpenSearchTemplate() {
344 global $wgOpenSearchTemplate, $wgServer, $wgScriptPath;
345 if($wgOpenSearchTemplate)
346 return $wgOpenSearchTemplate;
348 $ns = implode(',',SearchEngine
::defaultNamespaces());
350 return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace='.$ns;
355 * Get internal MediaWiki Suggest template
360 public static function getMWSuggestTemplate() {
361 global $wgMWSuggestTemplate, $wgServer, $wgScriptPath;
362 if($wgMWSuggestTemplate)
363 return $wgMWSuggestTemplate;
365 return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace={namespaces}';
372 class SearchResultSet
{
374 * Fetch an array of regular expression fragments for matching
375 * the search terms as parsed by this engine in a text extract.
381 function termMatches() {
390 * Return true if results are included in this result set.
394 function hasResults() {
399 * Some search modes return a total hit count for the query
400 * in the entire article database. This may include pages
401 * in namespaces that would not be matched on the given
404 * Return null if no total hits number is supported.
409 function getTotalHits() {
414 * Some search modes return a suggested alternate term if there are
415 * no exact hits. Returns true if there is one on this set.
420 function hasSuggestion() {
425 * @return string suggested query, null if none
427 function getSuggestionQuery(){
432 * @return string highlighted suggested query, '' if none
434 function getSuggestionSnippet(){
439 * Return information about how and from where the results were fetched,
440 * should be useful for diagnostics and debugging
449 * Return a result set of hits on other (multiple) wikis associated with this one
451 * @return SearchResultSet
453 function getInterwikiResults() {
458 * Check if there are results on other wikis
462 function hasInterwikiResults() {
463 return $this->getInterwikiResults() != null;
468 * Fetches next search result, or false.
469 * @return SearchResult
478 * Frees the result set, if applicable.
490 class SearchResultTooMany
{
491 ## Some search engines may bail out if too many matches are found
499 var $mRevision = null;
501 function SearchResult( $row ) {
502 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
503 if( !is_null($this->mTitle
) )
504 $this->mRevision
= Revision
::newFromTitle( $this->mTitle
);
508 * Check if this is result points to an invalid title
513 function isBrokenTitle(){
514 if( is_null($this->mTitle
) )
520 * Check if target page is missing, happens when index is out of date
525 function isMissingRevision(){
526 if( !$this->mRevision
)
535 function getTitle() {
536 return $this->mTitle
;
540 * @return double or null if not supported
542 function getScore() {
547 * Lazy initialization of article text from DB
549 protected function initText(){
550 if( !isset($this->mText
) ){
551 $this->mText
= $this->mRevision
->getText();
556 * @param array $terms terms to highlight
557 * @return string highlighted text snippet, null (and not '') if not supported
559 function getTextSnippet($terms){
560 global $wgUser, $wgAdvancedSearchHighlighting;
562 list($contextlines,$contextchars) = SearchEngine
::userHighlightPrefs($wgUser);
563 $h = new SearchHighlighter();
564 if( $wgAdvancedSearchHighlighting )
565 return $h->highlightText( $this->mText
, $terms, $contextlines, $contextchars );
567 return $h->highlightSimple( $this->mText
, $terms, $contextlines, $contextchars );
571 * @param array $terms terms to highlight
572 * @return string highlighted title, '' if not supported
574 function getTitleSnippet($terms){
579 * @param array $terms terms to highlight
580 * @return string highlighted redirect name (redirect to this page), '' if none or not supported
582 function getRedirectSnippet($terms){
587 * @return Title object for the redirect to this page, null if none or not supported
589 function getRedirectTitle(){
594 * @return string highlighted relevant section name, null if none or not supported
596 function getSectionSnippet(){
601 * @return Title object (pagename+fragment) for the section, null if none or not supported
603 function getSectionTitle(){
608 * @return string timestamp
610 function getTimestamp(){
611 return $this->mRevision
->getTimestamp();
615 * @return int number of words
617 function getWordCount(){
619 return str_word_count( $this->mText
);
623 * @return int size in bytes
625 function getByteSize(){
627 return strlen( $this->mText
);
631 * @return boolean if hit has related articles
633 function hasRelated(){
638 * @return interwiki prefix of the title (return iw even if title is broken)
640 function getInterwikiPrefix(){
646 * Highlight bits of wikitext
650 class SearchHighlighter
{
651 var $mCleanWikitext = true;
653 function SearchHighlighter($cleanupWikitext = true){
654 $this->mCleanWikitext
= $cleanupWikitext;
658 * Default implementation of wikitext highlighting
660 * @param string $text
661 * @param array $terms Terms to highlight (unescaped)
662 * @param int $contextlines
663 * @param int $contextchars
666 public function highlightText( $text, $terms, $contextlines, $contextchars ) {
667 global $wgLang, $wgContLang;
668 global $wgSearchHighlightBoundaries;
674 // spli text into text + templates/links/tables
675 $spat = "/(\\{\\{)|(\\[\\[[^\\]:]+:)|(\n\\{\\|)";
676 // first capture group is for detecting nested templates/links/tables/references
677 $endPatterns = array(
678 1 => '/(\{\{)|(\}\})/', // template
679 2 => '/(\[\[)|(\]\])/', // image
680 3 => "/(\n\\{\\|)|(\n\\|\\})/"); // table
682 // FIXME: this should prolly be a hook or something
683 if(function_exists('wfCite')){
684 $spat .= '|(<ref>)'; // references via cite extension
685 $endPatterns[4] = '/(<ref>)|(<\/ref>)/';
688 $textExt = array(); // text extracts
689 $otherExt = array(); // other extracts
690 wfProfileIn( "$fname-split" );
692 $textLen = strlen($text);
693 $count = 0; // sequence number to maintain ordering
694 while( $start < $textLen ){
695 // find start of template/image/table
696 if( preg_match( $spat, $text, $matches, PREG_OFFSET_CAPTURE
, $start ) ){
698 foreach($matches as $key => $val){
699 if($key > 0 && $val[1] != -1){
701 // see if this is an image link
702 $ns = substr($val[0],2,-1);
703 if( $wgContLang->getNsIndex($ns) != NS_IMAGE
)
707 $epat = $endPatterns[$key];
708 $this->splitAndAdd( $textExt, $count, substr( $text, $start, $val[1] - $start ) );
714 // find end (and detect any nested elements)
716 $offset = $start +
1;
718 while( preg_match( $epat, $text, $endMatches, PREG_OFFSET_CAPTURE
, $offset ) ){
719 if( array_key_exists(2,$endMatches) ){
722 $len = strlen($endMatches[2][0]);
723 $off = $endMatches[2][1];
724 $this->splitAndAdd( $otherExt, $count,
725 substr( $text, $start, $off +
$len - $start ) );
726 $start = $off +
$len;
730 // end of nested element
737 $offset = $endMatches[0][1] +
strlen($endMatches[0][0]);
740 // couldn't find appropriate closing tag, skip
741 $this->splitAndAdd( $textExt, $count, substr( $text, $start, strlen($matches[0][0]) ) );
742 $start +
= strlen($matches[0][0]);
747 // else: add as text extract
748 $this->splitAndAdd( $textExt, $count, substr($text,$start) );
752 $all = $textExt +
$otherExt; // these have disjunct key sets
754 wfProfileOut( "$fname-split" );
757 foreach( $terms as $index => $term ) {
758 $terms[$index] = preg_quote( $term, '/' );
759 // manually do upper/lowercase stuff for utf-8 since PHP won't do it
760 if(preg_match('/[\x80-\xff]/', $term) ){
761 $terms[$index] = preg_replace_callback('/./us',array($this,'caseCallback'),$terms[$index]);
766 $anyterm = implode( '|', $terms );
767 $phrase = implode("$wgSearchHighlightBoundaries+", $terms );
769 // FIXME: a hack to scale contextchars, a correct solution
770 // would be to have contextchars actually be char and not byte
771 // length, and do proper utf-8 substrings and lengths everywhere,
772 // but PHP is making that very hard and unclean to implement :(
773 $scale = strlen($anyterm) / mb_strlen($anyterm);
774 $contextchars = intval( $contextchars * $scale );
776 $patPre = "(^|$wgSearchHighlightBoundaries)";
777 $patPost = "($wgSearchHighlightBoundaries|$)";
779 $pat1 = "/(".$phrase.")/ui";
780 $pat2 = "/$patPre(".$anyterm.")$patPost/ui";
782 wfProfileIn( "$fname-extract" );
784 $left = $contextlines;
789 // show beginning only if it contains all words
792 foreach($textExt as $index => $line){
793 if(strlen($line)>0 && $line[0] != ';' && $line[0] != ':'){
794 $firstText = $this->extract( $line, 0, $contextchars * $contextlines );
801 // check if first text contains all terms
802 foreach($terms as $term){
803 if( ! preg_match("/$patPre".$term."$patPost/ui", $firstText) ){
809 $snippets[$first] = $firstText;
810 $offsets[$first] = 0;
814 // match whole query on text
815 $this->process($pat1, $textExt, $left, $contextchars, $snippets, $offsets);
816 // match whole query on templates/tables/images
817 $this->process($pat1, $otherExt, $left, $contextchars, $snippets, $offsets);
818 // match any words on text
819 $this->process($pat2, $textExt, $left, $contextchars, $snippets, $offsets);
820 // match any words on templates/tables/images
821 $this->process($pat2, $otherExt, $left, $contextchars, $snippets, $offsets);
826 // add extra chars to each snippet to make snippets constant size
828 if( count( $snippets ) == 0){
829 // couldn't find the target words, just show beginning of article
830 $targetchars = $contextchars * $contextlines;
831 $snippets[$first] = '';
832 $offsets[$first] = 0;
834 // if begin of the article contains the whole phrase, show only that !!
835 if( array_key_exists($first,$snippets) && preg_match($pat1,$snippets[$first])
836 && $offsets[$first] < $contextchars * 2 ){
837 $snippets = array ($first => $snippets[$first]);
840 // calc by how much to extend existing snippets
841 $targetchars = intval( ($contextchars * $contextlines) / count ( $snippets ) );
844 foreach($snippets as $index => $line){
845 $extended[$index] = $line;
846 $len = strlen($line);
847 if( $len < $targetchars - 20 ){
848 // complete this line
849 if($len < strlen( $all[$index] )){
850 $extended[$index] = $this->extract( $all[$index], $offsets[$index], $offsets[$index]+
$targetchars, $offsets[$index]);
851 $len = strlen( $extended[$index] );
856 while( $len < $targetchars - 20
857 && array_key_exists($add,$all)
858 && !array_key_exists($add,$snippets) ){
860 $tt = "\n".$this->extract( $all[$add], 0, $targetchars - $len, $offsets[$add] );
861 $extended[$add] = $tt;
862 $len +
= strlen( $tt );
868 //$snippets = array_map('htmlspecialchars', $extended);
869 $snippets = $extended;
872 foreach($snippets as $index => $line){
874 $extract .= $line; // first line
875 elseif($last+
1 == $index && $offsets[$last]+
strlen($snippets[$last]) >= strlen($all[$last]))
876 $extract .= " ".$line; // continous lines
878 $extract .= '<b> ... </b>' . $line;
883 $extract .= '<b> ... </b>';
885 $processed = array();
886 foreach($terms as $term){
887 if( ! isset($processed[$term]) ){
888 $pat3 = "/$patPre(".$term.")$patPost/ui"; // highlight word
889 $extract = preg_replace( $pat3,
890 "\\1<span class='searchmatch'>\\2</span>\\3", $extract );
891 $processed[$term] = true;
895 wfProfileOut( "$fname-extract" );
901 * Split text into lines and add it to extracts array
903 * @param array $extracts index -> $line
905 * @param string $text
907 function splitAndAdd(&$extracts, &$count, $text){
908 $split = explode( "\n", $this->mCleanWikitext?
$this->removeWiki($text) : $text );
909 foreach($split as $line){
912 $extracts[$count++
] = $tt;
917 * Do manual case conversion for non-ascii chars
919 * @param unknown_type $matches
921 function caseCallback($matches){
923 if( strlen($matches[0]) > 1 ){
924 return '['.$wgContLang->lc($matches[0]).$wgContLang->uc($matches[0]).']';
930 * Extract part of the text from start to end, but by
931 * not chopping up words
932 * @param string $text
935 * @param int $posStart (out) actual start position
936 * @param int $posEnd (out) actual end position
939 function extract($text, $start, $end, &$posStart = null, &$posEnd = null ){
943 $start = $this->position( $text, $start, 1 );
944 if( $end >= strlen($text) )
945 $end = strlen($text);
947 $end = $this->position( $text, $end );
949 if(!is_null($posStart))
951 if(!is_null($posEnd))
955 return substr($text, $start, $end-$start);
961 * Find a nonletter near a point (index) in the text
963 * @param string $text
965 * @param int $offset to found index
966 * @return int nearest nonletter index, or beginning of utf8 char if none
968 function position($text, $point, $offset=0 ){
970 $s = max( 0, $point - $tolerance );
971 $l = min( strlen($text), $point +
$tolerance ) - $s;
973 if( preg_match('/[ ,.!?~!@#$%^&*\(\)+=\-\\\|\[\]"\'<>]/', substr($text,$s,$l), $m, PREG_OFFSET_CAPTURE
) ){
974 return $m[0][1] +
$s +
$offset;
976 // check if point is on a valid first UTF8 char
977 $char = ord( $text[$point] );
978 while( $char >= 0x80 && $char < 0xc0 ) {
979 // skip trailing bytes
981 if($point >= strlen($text))
982 return strlen($text);
983 $char = ord( $text[$point] );
991 * Search extracts for a pattern, and return snippets
993 * @param string $pattern regexp for matching lines
994 * @param array $extracts extracts to search
995 * @param int $linesleft number of extracts to make
996 * @param int $contextchars length of snippet
997 * @param array $out map for highlighted snippets
998 * @param array $offsets map of starting points of snippets
1001 function process( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets ){
1003 return; // nothing to do
1004 foreach($extracts as $index => $line){
1005 if( array_key_exists($index,$out) )
1006 continue; // this line already highlighted
1009 if ( !preg_match( $pattern, $line, $m, PREG_OFFSET_CAPTURE
) )
1013 $len = strlen($m[0][0]);
1014 if($offset +
$len < $contextchars)
1016 elseif( $len > $contextchars)
1019 $begin = $offset +
intval( ($len - $contextchars) / 2 );
1021 $end = $begin +
$contextchars;
1024 // basic snippet from this line
1025 $out[$index] = $this->extract($line,$begin,$end,$posBegin);
1026 $offsets[$index] = $posBegin;
1034 * Basic wikitext removal
1037 function removeWiki($text) {
1038 $fname = __METHOD__
;
1039 wfProfileIn( $fname );
1041 //$text = preg_replace("/'{2,5}/", "", $text);
1042 //$text = preg_replace("/\[[a-z]+:\/\/[^ ]+ ([^]]+)\]/", "\\2", $text);
1043 //$text = preg_replace("/\[\[([^]|]+)\]\]/", "\\1", $text);
1044 //$text = preg_replace("/\[\[([^]]+\|)?([^|]]+)\]\]/", "\\2", $text);
1045 //$text = preg_replace("/\\{\\|(.*?)\\|\\}/", "", $text);
1046 //$text = preg_replace("/\\[\\[[A-Za-z_-]+:([^|]+?)\\]\\]/", "", $text);
1047 $text = preg_replace("/\\{\\{([^|]+?)\\}\\}/", "", $text);
1048 $text = preg_replace("/\\{\\{([^|]+\\|)(.*?)\\}\\}/", "\\2", $text);
1049 $text = preg_replace("/\\[\\[([^|]+?)\\]\\]/", "\\1", $text);
1050 $text = preg_replace_callback("/\\[\\[([^|]+\\|)(.*?)\\]\\]/", array($this,'linkReplace'), $text);
1051 //$text = preg_replace("/\\[\\[([^|]+\\|)(.*?)\\]\\]/", "\\2", $text);
1052 $text = preg_replace("/<\/?[^>]+>/", "", $text);
1053 $text = preg_replace("/'''''/", "", $text);
1054 $text = preg_replace("/('''|<\/?[iIuUbB]>)/", "", $text);
1055 $text = preg_replace("/''/", "", $text);
1057 wfProfileOut( $fname );
1062 * callback to replace [[target|caption]] kind of links, if
1063 * the target is category or image, leave it
1065 * @param array $matches
1067 function linkReplace($matches){
1068 $colon = strpos( $matches[1], ':' );
1069 if( $colon === false )
1070 return $matches[2]; // replace with caption
1072 $ns = substr( $matches[1], 0, $colon );
1073 $index = $wgContLang->getNsIndex($ns);
1074 if( $index !== false && ($index == NS_IMAGE ||
$index == NS_CATEGORY
) )
1075 return $matches[0]; // return the whole thing
1082 * Simple & fast snippet extraction, but gives completely unrelevant
1085 * @param string $text
1086 * @param array $terms
1087 * @param int $contextlines
1088 * @param int $contextchars
1091 public function highlightSimple( $text, $terms, $contextlines, $contextchars ) {
1092 global $wgLang, $wgContLang;
1093 $fname = __METHOD__
;
1095 $lines = explode( "\n", $text );
1097 $terms = implode( '|', $terms );
1098 $terms = str_replace( '/', "\\/", $terms);
1099 $max = intval( $contextchars ) +
1;
1100 $pat1 = "/(.*)($terms)(.{0,$max})/i";
1105 wfProfileIn( "$fname-extract" );
1106 foreach ( $lines as $line ) {
1107 if ( 0 == $contextlines ) {
1112 if ( ! preg_match( $pat1, $line, $m ) ) {
1116 $pre = $wgContLang->truncate( $m[1], -$contextchars, ' ... ' );
1118 if ( count( $m ) < 3 ) {
1121 $post = $wgContLang->truncate( $m[3], $contextchars, ' ... ' );
1126 $line = htmlspecialchars( $pre . $found . $post );
1127 $pat2 = '/(' . $terms . ")/i";
1128 $line = preg_replace( $pat2,
1129 "<span class='searchmatch'>\\1</span>", $line );
1131 $extract .= "${line}\n";
1133 wfProfileOut( "$fname-extract" );
1143 class SearchEngineDummy
{
1144 function search( $term ) {
1147 function setLimitOffset($l, $o) {}
1148 function legalSearchChars() {}
1149 function update() {}
1150 function setnamespaces() {}
1151 function searchtitle() {}
1152 function searchtext() {}