49 private $latestPage =
null;
61 if ( is_string( $c ) ) {
62 wfDeprecated( __METHOD__ .
" with a string for the content",
'1.34' );
64 } elseif ( is_bool( $c ) ) {
65 wfDeprecated( __METHOD__ .
" with a boolean for the content",
'1.34' );
75 $services = MediaWikiServices::getInstance();
76 $config = $services->getSearchEngineConfig();
78 if ( $config->getConfig()->get( MainConfigNames::DisableSearchUpdate ) || !$this->id ) {
79 LoggerFactory::getInstance(
"search" )
80 ->debug(
"Skipping update: search updates disabled by config" );
84 $seFactory = $services->getSearchEngineFactory();
85 foreach ( $config->getSearchTypes() as
$type ) {
86 $search = $seFactory->create(
$type );
87 if ( !$search->
supports(
'search-update' ) ) {
91 $normalTitle = $this->getNormalizedTitle( $search );
93 if ( $this->getLatestPage() ===
null ) {
94 $search->
delete( $this->
id, $normalTitle );
96 } elseif ( $this->content ===
null ) {
101 $text = $this->content !==
null ? $this->content->getTextForSearchIndex() :
'';
104 # Perform the actual update
118 $services = MediaWikiServices::getInstance();
119 $contLang = $services->getContentLanguage();
120 # Language-specific strip/conversion
121 $text = $contLang->normalizeForSearch( $text );
122 $se = $se ?: $services->newSearchEngine();
123 $lc = $se->legalSearchChars() .
'&#;';
126 $text = preg_replace(
"/<\\/?\\s*[A-Za-z][^>]*?>/",
127 ' ', $contLang->lc(
" " . $text .
" " ) );
128 $text = preg_replace(
"/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/sD",
129 "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
131 # Strip external URLs
132 $uc =
"A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\x80-\\xFF";
133 $protos =
"http|https|ftp|mailto|news|gopher";
134 $pat =
"/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
135 $text = preg_replace( $pat,
"\\1 \\3", $text );
137 $p1 =
"/([^\\[])\\[({$protos}):[{$uc}]+]/";
138 $p2 =
"/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
139 $text = preg_replace( $p1,
"\\1 ", $text );
140 $text = preg_replace( $p2,
"\\1 \\3 ", $text );
142 # Internal image links
143 $pat2 =
"/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
144 $text = preg_replace( $pat2,
" \\1 \\3", $text );
146 $text = preg_replace(
"/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
147 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
149 # Strip all remaining non-search characters
150 $text = preg_replace(
"/[^{$lc}]+/",
" ", $text );
168 $text = strrev( preg_replace(
"/ s'([{$lc}]+)/",
" s'\\1 \\1", strrev( $text ) ) );
169 $text = strrev( preg_replace(
"/ 's([{$lc}]+)/",
" s\\1", strrev( $text ) ) );
171 # Strip wiki '' and '''
172 $text = preg_replace(
"/''[']*/",
" ", $text );
186 private function getLatestPage() {
187 if ( !isset( $this->latestPage ) ) {
188 $this->latestPage = MediaWikiServices::getInstance()->getPageStore()
189 ->getPageById( $this->
id, PageStore::READ_LATEST );
192 return $this->latestPage;
202 private function getNormalizedTitle(
SearchEngine $search ) {
203 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
204 $ns = $this->page->getNamespace();
205 $title = str_replace(
'_',
' ', $this->page->getDBkey() );
208 $t = $contLang->normalizeForSearch(
$title );
209 $t = preg_replace(
"/[^{$lc}]+/",
' ',
$t );
210 $t = $contLang->lc(
$t );
213 $t = preg_replace(
"/([{$lc}]+)'s( |$)/",
"\\1 \\1's ",
$t );
214 $t = preg_replace(
"/([{$lc}]+)s'( |$)/",
"\\1s ",
$t );
216 $t = preg_replace(
"/\\s+/",
' ',
$t );
219 $t = preg_replace(
"/ (png|gif|jpg|jpeg|ogg)$/",
"",
$t );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
A class containing constants representing the names of configuration variables.
Contain a class for special pages.
delete( $id, $title)
Delete an indexed page Title should be pre-processed.
update( $id, $title, $text)
Create or update the search index record for the given page.
normalizeText( $string)
When overridden in derived class, performs database-specific conversions on text to be used for searc...
updateTitle( $id, $title)
Update a search index record's title only.
legalSearchChars( $type=self::CHARS_ALL)
Get chars legal for search.
Database independent search index updater.
updateText( $text, SearchEngine $se=null)
Clean text for indexing.
doUpdate()
Perform actual update for the entry.
__construct( $id, $page, $c=null)
Content object implementation for representing flat text.
Base interface for representing page content.
Interface that deferrable updates should implement.
Interface for objects (potentially) representing an editable wiki page.