6 /* private */ var $mId = 0, $mNamespace, $mTitle, $mText;
7 /* private */ var $mTitleWords;
9 function SearchUpdate( $id, $title, $text = false )
11 $nt = Title
::newFromText( $title );
16 $this->mNamespace
= $nt->getNamespace();
17 $this->mTitle
= $nt->getText(); # Discard namespace
19 $this->mTitleWords
= $this->mTextWords
= array();
21 wfDebug( "SearchUpdate object created with invalid title '$title'\n" );
27 global $wgDBminWordLen, $wgLang, $wgDisableSearchUpdate;
29 if( $wgDisableSearchUpdate ||
!$this->mId
) {
32 $lc = SearchEngine
::legalSearchChars() . "&#;";
33 if( $this->mText
== false ) {
34 # Just update the title
35 $sql = "UPDATE LOW_PRIORITY searchindex SET si_title='" .
36 wfStrencode( Title
::indexTitle( $this->mNamespace
, $this->mTitle
) ) .
37 "' WHERE si_page={$this->mId}";
38 wfQuery( $sql, DB_WRITE
, "SearchUpdate::doUpdate" );
42 # Language-specific strip/conversion
43 $text = $wgLang->stripForSearch( $this->mText
);
45 $text = preg_replace( "/<\\/?\\s*[A-Za-z][A-Za-z0-9]*\\s*([^>]*?)>/",
46 " ", strtolower( " " . $text /*$this->mText*/ . " " ) ); # Strip HTML markup
47 $text = preg_replace( "/(^|\\n)\\s*==\\s+([^\\n]+)\\s+==\\s/sD",
48 "\\2 \\2 \\2 ", $text ); # Emphasize headings
51 $uc = "A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\xA0-\\xFF";
52 $protos = "http|https|ftp|mailto|news|gopher";
53 $pat = "/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
54 $text = preg_replace( $pat, "\\1 \\3", $text );
56 $p1 = "/([^\\[])\\[({$protos}):[{$uc}]+]/";
57 $p2 = "/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
58 $text = preg_replace( $p1, "\\1 ", $text );
59 $text = preg_replace( $p2, "\\1 \\3 ", $text );
61 # Internal image links
62 $pat2 = "/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
63 $text = preg_replace( $pat2, " \\1 \\3", $text );
65 $text = preg_replace( "/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
66 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
68 # Strip all remaining non-search characters
69 $text = preg_replace( "/[^{$lc}]+/", " ", $text );
72 $text = preg_replace( "/([{$lc}]+)'s /", "\\1 \\1's ", $text );
73 $text = preg_replace( "/([{$lc}]+)s' /", "\\1s ", $text );
75 # Strip wiki '' and '''
76 $text = preg_replace( "/''[']*/", " ", $text );
78 $sql = "REPLACE DELAYED INTO searchindex (si_page,si_title,si_text) VALUES ({$this->mId},'" .
79 wfStrencode( Title
::indexTitle( $this->mNamespace
, $this->mTitle
) ) . "','" .
80 wfStrencode( $text ) . "')";
81 wfQuery( $sql, DB_WRITE
, "SearchUpdate::doUpdate" );