X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdeferred%2FSearchUpdate.php;h=62c8b00f39d3845007af7d9aa4844064b424e716;hb=8a43c5afdf0736f5c60ec587da5c230cf53a8ab1;hp=6ed1d001773c88e878a2c113483c6ec036a3247d;hpb=3de7e73bd0f0ddf5d7c38fd46edfae96d1a64e40;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/deferred/SearchUpdate.php b/includes/deferred/SearchUpdate.php index 6ed1d00177..62c8b00f39 100644 --- a/includes/deferred/SearchUpdate.php +++ b/includes/deferred/SearchUpdate.php @@ -23,6 +23,8 @@ * @ingroup Search */ +use MediaWiki\MediaWikiServices; + /** * Database independant search index updater * @@ -38,6 +40,9 @@ class SearchUpdate implements DeferrableUpdate { /** @var Content|bool Content of the page (not text) */ private $content; + /** @var WikiPage **/ + private $page; + /** * Constructor * @@ -72,24 +77,22 @@ class SearchUpdate implements DeferrableUpdate { * Perform actual update for the entry */ public function doUpdate() { - global $wgDisableSearchUpdate; + $config = MediaWikiServices::getInstance()->getSearchEngineConfig(); - if ( $wgDisableSearchUpdate || !$this->id ) { + if ( $config->getConfig()->get( 'DisableSearchUpdate' ) || !$this->id ) { return; } - $page = WikiPage::newFromID( $this->id, WikiPage::READ_LATEST ); - - foreach ( SearchEngine::getSearchTypes() as $type ) { - $search = SearchEngine::create( $type ); - $indexTitle = $this->indexTitle( $search ); + $seFactory = MediaWikiServices::getInstance()->getSearchEngineFactory(); + foreach ( $config->getSearchTypes() as $type ) { + $search = $seFactory->create( $type ); 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 ) { @@ -99,7 +102,7 @@ class SearchUpdate implements DeferrableUpdate { $text = $search->getTextFromContent( $this->title, $this->content ); if ( !$search->textAlreadyUpdatedForIndex() ) { - $text = self::updateText( $text ); + $text = $this->updateText( $text, $search ); } # Perform the actual update @@ -113,14 +116,16 @@ class SearchUpdate implements DeferrableUpdate { * If you're using a real search engine, you'll probably want to override * this behavior and do something nicer with the original wikitext. * @param string $text + * @param SearchEngine $se Search engine * @return string */ - public static function updateText( $text ) { + public function updateText( $text, SearchEngine $se = null ) { global $wgContLang; # Language-specific strip/conversion $text = $wgContLang->normalizeForSearch( $text ); - $lc = SearchEngine::legalSearchChars() . '&#;'; + $se = $se ?: MediaWikiServices::getInstance()->newSearchEngine(); + $lc = $se->legalSearchChars() . '&#;'; $text = preg_replace( "/<\\/?\\s*[A-Za-z][^>]*?>/", ' ', $wgContLang->lc( " " . $text . " " ) ); # Strip HTML markup @@ -174,13 +179,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 +222,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 ) ); } }