missing parentheses
[lhc/web/wiklou.git] / includes / SearchUpdate.php
1 <?php
2 # See deferred.doc
3
4 class SearchUpdate {
5
6 /* private */ var $mId = 0, $mNamespace, $mTitle, $mText;
7 /* private */ var $mTitleWords;
8
9 function SearchUpdate( $id, $title, $text = false )
10 {
11 $nt = Title::newFromText( $title );
12 if( $nt ) {
13 $this->mId = $id;
14 $this->mText = $text;
15
16 $this->mNamespace = $nt->getNamespace();
17 $this->mTitle = $nt->getText(); # Discard namespace
18
19 $this->mTitleWords = $this->mTextWords = array();
20 } else {
21 wfDebug( "SearchUpdate object created with invalid title '$title'\n" );
22 }
23 }
24
25 function doUpdate()
26 {
27 global $wgDBminWordLen, $wgLang, $wgDisableSearchUpdate;
28
29 if( $wgDisableSearchUpdate || !$this->mId ) {
30 return false;
31 }
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" );
39 return;
40 }
41
42 # Language-specific strip/conversion
43 $text = $wgLang->stripForSearch( $this->mText );
44
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
49
50 # Strip external URLs
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 );
55
56 $p1 = "/([^\\[])\\[({$protos}):[{$uc}]+]/";
57 $p2 = "/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
58 $text = preg_replace( $p1, "\\1 ", $text );
59 $text = preg_replace( $p2, "\\1 \\3 ", $text );
60
61 # Internal image links
62 $pat2 = "/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
63 $text = preg_replace( $pat2, " \\1 \\3", $text );
64
65 $text = preg_replace( "/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
66 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
67
68 # Strip all remaining non-search characters
69 $text = preg_replace( "/[^{$lc}]+/", " ", $text );
70
71 # Handle 's, s'
72 $text = preg_replace( "/([{$lc}]+)'s /", "\\1 \\1's ", $text );
73 $text = preg_replace( "/([{$lc}]+)s' /", "\\1s ", $text );
74
75 # Strip wiki '' and '''
76 $text = preg_replace( "/''[']*/", " ", $text );
77
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" );
82 }
83 }
84
85 ?>