Merge "Show whether tags are active on Special:Tags"
[lhc/web/wiklou.git] / includes / search / SearchUpdate.php
index 7146917..82a413e 100644 (file)
@@ -66,7 +66,7 @@ class SearchUpdate implements DeferrableUpdate {
                if ( $nt ) {
                        $this->id = $id;
                        // is_string() check is back-compat for ApprovedRevs
-                       if( is_string( $c ) ) {
+                       if ( is_string( $c ) ) {
                                $this->content = new TextContent( $c );
                        } else {
                                $this->content = $c ?: false;
@@ -89,27 +89,33 @@ class SearchUpdate implements DeferrableUpdate {
 
                wfProfileIn( __METHOD__ );
 
-               $search = SearchEngine::create();
-               $normalTitle = $search->normalizeText(
-                       Title::indexTitle( $this->title->getNamespace(), $this->title->getText() ) );
+               $page = WikiPage::newFromId( $this->id, WikiPage::READ_LATEST );
+               $indexTitle = Title::indexTitle( $this->title->getNamespace(), $this->title->getText() );
 
-               if ( WikiPage::newFromId( $this->id ) === null ) {
-                       $search->delete( $this->id, $normalTitle );
-                       wfProfileOut( __METHOD__ );
-                       return;
-               } elseif ( $this->content === false ) {
-                       $search->updateTitle( $this->id, $normalTitle );
-                       wfProfileOut( __METHOD__ );
-                       return;
-               }
+               foreach ( SearchEngine::getSearchTypes() as $type ) {
+                       $search = SearchEngine::create( $type );
+                       if ( !$search->supports( 'search-update' ) ) {
+                               continue;
+                       }
 
-               $text = $search->getTextFromContent( $this->title, $this->content );
-               if( wfRunHooks( 'SearchUpdate', array( $this->id, $this->title, &$text, $this->content ) ) ) {
-                       $text = self::updateText( $text );
-               }
+                       $normalTitle = $search->normalizeText( $indexTitle );
 
-               # Perform the actual update
-               $search->update( $this->id, $normalTitle, $search->normalizeText( $text ) );
+                       if ( $page === null ) {
+                               $search->delete( $this->id, $normalTitle );
+                               continue;
+                       } elseif ( $this->content === false ) {
+                               $search->updateTitle( $this->id, $normalTitle );
+                               continue;
+                       }
+
+                       $text = $search->getTextFromContent( $this->title, $this->content );
+                       if ( !$search->textAlreadyUpdatedForIndex() ) {
+                               $text = self::updateText( $text );
+                       }
+
+                       # Perform the actual update
+                       $search->update( $this->id, $normalTitle, $search->normalizeText( $text ) );
+               }
 
                wfProfileOut( __METHOD__ );
        }