6 /* private */ var $mId, $mNamespace, $mTitle, $mText;
7 /* private */ var $mTitleWords;
9 function SearchUpdate( $id, $title, $text = false )
14 $nt = Title
::newFromText( $title );
15 $this->mNamespace
= $nt->getNamespace();
16 $this->mTitle
= $nt->getText(); # Discard namespace
18 $this->mTitleWords
= $this->mTextWords
= array();
23 global $wgDBminWordLen, $wgLang, $wgDisableSearchUpdate;
25 if( $wgDisableSearchUpdate ) {
28 $lc = SearchEngine
::legalSearchChars() . "&#;";
29 if( $this->mText
== false ) {
30 # Just update the title
31 $sql = "UPDATE LOW_PRIORITY searchindex SET si_title='" .
32 wfStrencode( Title
::indexTitle( $this->mNamespace
, $this->mTitle
) ) .
33 "' WHERE si_page={$this->mId}";
34 wfQuery( $sql, DB_WRITE
, "SearchUpdate::doUpdate" );
38 # Language-specific strip/conversion
39 $text = $wgLang->stripForSearch( $this->mText
);
41 $text = preg_replace( "/<\\/?\\s*[A-Za-z][A-Za-z0-9]*\\s*([^>]*?)>/",
42 " ", strtolower( " " . $text /*$this->mText*/ . " " ) ); # Strip HTML markup
43 $text = preg_replace( "/(^|\\n)\\s*==\\s+([^\\n]+)\\s+==\\s/sD",
44 "\\2 \\2 \\2 ", $text ); # Emphasize headings
47 $uc = "A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\xA0-\\xFF";
48 $protos = "http|https|ftp|mailto|news|gopher";
49 $pat = "/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
50 $text = preg_replace( $pat, "\\1 \\3", $text );
52 $p1 = "/([^\\[])\\[({$protos}):[{$uc}]+]/";
53 $p2 = "/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
54 $text = preg_replace( $p1, "\\1 ", $text );
55 $text = preg_replace( $p2, "\\1 \\3 ", $text );
57 # Internal image links
58 $pat2 = "/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
59 $text = preg_replace( $pat2, " \\1 \\3", $text );
61 $text = preg_replace( "/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
62 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
64 # Strip all remaining non-search characters
65 $text = preg_replace( "/[^{$lc}]+/", " ", $text );
68 $text = preg_replace( "/([{$lc}]+)'s /", "\\1 \\1's ", $text );
69 $text = preg_replace( "/([{$lc}]+)s' /", "\\1s ", $text );
71 # Strip wiki '' and '''
72 $text = preg_replace( "/''[']*/", " ", $text );
74 $sql = "REPLACE DELAYED INTO searchindex (si_page,si_title,si_text) VALUES ({$this->mId},'" .
75 wfStrencode( Title
::indexTitle( $this->mNamespace
, $this->mTitle
) ) . "','" .
76 wfStrencode( $text ) . "')";
77 wfQuery( $sql, DB_WRITE
, "SearchUpdate::doUpdate" );