48 private $latestPage =
null;
60 if ( is_string( $c ) ) {
61 wfDeprecated( __METHOD__ .
" with a string for the content",
'1.34' );
63 } elseif ( is_bool( $c ) ) {
64 wfDeprecated( __METHOD__ .
" with a boolean for the content",
'1.34' );
74 $services = MediaWikiServices::getInstance();
75 $config = $services->getSearchEngineConfig();
77 if ( $config->getConfig()->get( MainConfigNames::DisableSearchUpdate ) || !$this->id ) {
81 $seFactory = $services->getSearchEngineFactory();
82 foreach ( $config->getSearchTypes() as
$type ) {
83 $search = $seFactory->create(
$type );
84 if ( !$search->
supports(
'search-update' ) ) {
88 $normalTitle = $this->getNormalizedTitle( $search );
90 if ( $this->getLatestPage() ===
null ) {
91 $search->
delete( $this->
id, $normalTitle );
93 } elseif ( $this->content ===
null ) {
98 $text = $this->content !==
null ? $this->content->getTextForSearchIndex() :
'';
101 # Perform the actual update
115 $services = MediaWikiServices::getInstance();
116 $contLang = $services->getContentLanguage();
117 # Language-specific strip/conversion
118 $text = $contLang->normalizeForSearch( $text );
119 $se = $se ?: $services->newSearchEngine();
120 $lc = $se->legalSearchChars() .
'&#;';
123 $text = preg_replace(
"/<\\/?\\s*[A-Za-z][^>]*?>/",
124 ' ', $contLang->lc(
" " . $text .
" " ) );
125 $text = preg_replace(
"/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/sD",
126 "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
128 # Strip external URLs
129 $uc =
"A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\x80-\\xFF";
130 $protos =
"http|https|ftp|mailto|news|gopher";
131 $pat =
"/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
132 $text = preg_replace( $pat,
"\\1 \\3", $text );
134 $p1 =
"/([^\\[])\\[({$protos}):[{$uc}]+]/";
135 $p2 =
"/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
136 $text = preg_replace( $p1,
"\\1 ", $text );
137 $text = preg_replace( $p2,
"\\1 \\3 ", $text );
139 # Internal image links
140 $pat2 =
"/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
141 $text = preg_replace( $pat2,
" \\1 \\3", $text );
143 $text = preg_replace(
"/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
144 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
146 # Strip all remaining non-search characters
147 $text = preg_replace(
"/[^{$lc}]+/",
" ", $text );
165 $text = strrev( preg_replace(
"/ s'([{$lc}]+)/",
" s'\\1 \\1", strrev( $text ) ) );
166 $text = strrev( preg_replace(
"/ 's([{$lc}]+)/",
" s\\1", strrev( $text ) ) );
168 # Strip wiki '' and '''
169 $text = preg_replace(
"/''[']*/",
" ", $text );
183 private function getLatestPage() {
184 if ( !isset( $this->latestPage ) ) {
185 $this->latestPage = MediaWikiServices::getInstance()->getPageStore()
186 ->getPageById( $this->
id, PageStore::READ_LATEST );
189 return $this->latestPage;
199 private function getNormalizedTitle(
SearchEngine $search ) {
200 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
201 $ns = $this->page->getNamespace();
202 $title = str_replace(
'_',
' ', $this->page->getDBkey() );
205 $t = $contLang->normalizeForSearch(
$title );
206 $t = preg_replace(
"/[^{$lc}]+/",
' ',
$t );
207 $t = $contLang->lc(
$t );
210 $t = preg_replace(
"/([{$lc}]+)'s( |$)/",
"\\1 \\1's ",
$t );
211 $t = preg_replace(
"/([{$lc}]+)s'( |$)/",
"\\1s ",
$t );
213 $t = preg_replace(
"/\\s+/",
' ',
$t );
216 $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.
Interface that deferrable updates should implement.
Interface for objects (potentially) representing an editable wiki page.