Migrate doubleredirect and brokenredirect subpages from SpecialMaintenance.php to...
[lhc/web/wiklou.git] / includes / SearchUpdate.php
index 9e9ff2a..9cbbb61 100644 (file)
@@ -1,37 +1,49 @@
-<?
+<?php
+# $Id$
 # See deferred.doc
 
 class SearchUpdate {
 
-       /* private */ var $mId, $mNamespace, $mTitle, $mText;
+       /* private */ var $mId = 0, $mNamespace, $mTitle, $mText;
        /* private */ var $mTitleWords;
 
        function SearchUpdate( $id, $title, $text = false )
        {
-               $this->mId = $id;
-               $this->mText = $text;
-
                $nt = Title::newFromText( $title );
-               $this->mNamespace = $nt->getNamespace();
-               $this->mTitle = $nt->getText(); # Discard namespace
+               if( $nt ) {
+                       $this->mId = $id;
+                       $this->mText = $text;
+
+                       $this->mNamespace = $nt->getNamespace();
+                       $this->mTitle = $nt->getText(); # Discard namespace
 
-               $this->mTitleWords = $this->mTextWords = array();
+                       $this->mTitleWords = $this->mTextWords = array();
+               } else {
+                       wfDebug( "SearchUpdate object created with invalid title '$title'\n" );
+               }
        }
 
        function doUpdate()
        {
-               global $wgDBminWordLen, $wgLang;
+               global $wgDBminWordLen, $wgLang, $wgDisableSearchUpdate;
+
+               if( $wgDisableSearchUpdate || !$this->mId ) {
+                       return false;
+               }
                $lc = SearchEngine::legalSearchChars() . "&#;";
+               $db =& wfGetDB( DB_MASTER );
+               $searchindex = $db->tableName( 'searchindex' );
                
                if( $this->mText == false ) {
                        # Just update the title
-                       $sql = "UPDATE LOW_PRIORITY searchindex SET si_title='" .
-                         wfStrencode( Title::indexTitle( $this->mNamespace, $this->mTitle ) ) .
+                       $lowpri = $db->lowPriorityOption();
+                       $sql = "UPDATE $lowpri $searchindex SET si_title='" .
+                         $db->strencode( Title::indexTitle( $this->mNamespace, $this->mTitle ) ) .
                          "' WHERE si_page={$this->mId}";
-                       wfQuery( $sql, "SearchUpdate::doUpdate" );
+                       $db->query( $sql, "SearchUpdate::doUpdate" );
                        return;
                }
-               
+
                # Language-specific strip/conversion
                $text = $wgLang->stripForSearch( $this->mText );
 
@@ -67,11 +79,11 @@ class SearchUpdate {
 
                # Strip wiki '' and '''
                $text = preg_replace( "/''[']*/", " ", $text );
-
-               $sql = "REPLACE DELAYED INTO searchindex (si_page,si_title,si_text) VALUES ({$this->mId},'" .
-                 wfStrencode( Title::indexTitle( $this->mNamespace, $this->mTitle ) ) . "','" .
-                 wfStrencode( $text ) . "')";
-               wfQuery( $sql, "SearchUpdate::doUpdate" );
+               
+               $sql = "REPLACE  INTO $searchindex (si_page,si_title,si_text) VALUES ({$this->mId},'" .
+                 $db->strencode( Title::indexTitle( $this->mNamespace, $this->mTitle ) ) . "','" .
+                 $db->strencode( $text ) . "')";
+               $db->query( $sql, "SearchUpdate::doUpdate" );
        }
 }