Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / deferred / SearchUpdate.php
index 6ed1d00..2abf028 100644 (file)
@@ -38,6 +38,9 @@ class SearchUpdate implements DeferrableUpdate {
        /** @var Content|bool Content of the page (not text) */
        private $content;
 
+       /** @var WikiPage **/
+       private $page;
+
        /**
         * Constructor
         *
@@ -78,18 +81,15 @@ class SearchUpdate implements DeferrableUpdate {
                        return;
                }
 
-               $page = WikiPage::newFromID( $this->id, WikiPage::READ_LATEST );
-
                foreach ( SearchEngine::getSearchTypes() as $type ) {
                        $search = SearchEngine::create( $type );
-                       $indexTitle = $this->indexTitle( $search );
                        if ( !$search->supports( 'search-update' ) ) {
                                continue;
                        }
 
-                       $normalTitle = $search->normalizeText( $indexTitle );
+                       $normalTitle = $this->getNormalizedTitle( $search );
 
-                       if ( $page === null ) {
+                       if ( $this->getLatestPage() === null ) {
                                $search->delete( $this->id, $normalTitle );
                                continue;
                        } elseif ( $this->content === false ) {
@@ -174,13 +174,30 @@ class SearchUpdate implements DeferrableUpdate {
        }
 
        /**
-        * Get a string representation of a title suitable for
+        * Get WikiPage for the SearchUpdate $id using WikiPage::READ_LATEST
+        * and ensure using the same WikiPage object if there are multiple
+        * SearchEngine types.
+        *
+        * Returns null if a page has been deleted or is not found.
+        *
+        * @return WikiPage|null
+        */
+       private function getLatestPage() {
+               if ( !isset( $this->page ) ) {
+                       $this->page = WikiPage::newFromID( $this->id, WikiPage::READ_LATEST );
+               }
+
+               return $this->page;
+       }
+
+       /**
+        * Get a normalized string representation of a title suitable for
         * including in a search index
         *
         * @param SearchEngine $search
         * @return string A stripped-down title string ready for the search index
         */
-       private function indexTitle( SearchEngine $search ) {
+       private function getNormalizedTitle( SearchEngine $search ) {
                global $wgContLang;
 
                $ns = $this->title->getNamespace();
@@ -200,6 +217,7 @@ class SearchUpdate implements DeferrableUpdate {
                if ( $ns == NS_FILE ) {
                        $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
                }
-               return trim( $t );
+
+               return $search->normalizeText( trim( $t ) );
        }
 }