52 if ( is_string(
$title ) ) {
53 wfDeprecated( __METHOD__ .
" with a string for the title",
'1.34' );
54 $this->title = Title::newFromText(
$title );
55 if ( $this->title ===
null ) {
56 throw new InvalidArgumentException(
"Cannot construct the title: $title" );
64 if ( is_string( $c ) ) {
65 wfDeprecated( __METHOD__ .
" with a string for the content",
'1.34' );
67 } elseif ( is_bool( $c ) ) {
68 wfDeprecated( __METHOD__ .
" with a boolean for the content",
'1.34' );
78 $services = MediaWikiServices::getInstance();
79 $config = $services->getSearchEngineConfig();
81 if ( $config->getConfig()->get(
'DisableSearchUpdate' ) || !$this->id ) {
85 $seFactory = $services->getSearchEngineFactory();
86 foreach ( $config->getSearchTypes() as
$type ) {
87 $search = $seFactory->create(
$type );
88 if ( !$search->supports(
'search-update' ) ) {
95 $search->delete( $this->
id, $normalTitle );
97 } elseif ( $this->content ===
null ) {
98 $search->updateTitle( $this->
id, $normalTitle );
102 $text = $this->content !==
null ? $this->content->getTextForSearchIndex() :
'';
105 # Perform the actual update
106 $search->update( $this->
id, $normalTitle, $search->normalizeText( $text ) );
119 $services = MediaWikiServices::getInstance();
120 $contLang = $services->getContentLanguage();
121 # Language-specific strip/conversion
122 $text = $contLang->normalizeForSearch( $text );
123 $se = $se ?: $services->newSearchEngine();
124 $lc = $se->legalSearchChars() .
'&#;';
127 $text = preg_replace(
"/<\\/?\\s*[A-Za-z][^>]*?>/",
128 ' ', $contLang->lc(
" " . $text .
" " ) );
129 $text = preg_replace(
"/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/sD",
130 "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
132 # Strip external URLs
133 $uc =
"A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\x80-\\xFF";
134 $protos =
"http|https|ftp|mailto|news|gopher";
135 $pat =
"/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
136 $text = preg_replace( $pat,
"\\1 \\3", $text );
138 $p1 =
"/([^\\[])\\[({$protos}):[{$uc}]+]/";
139 $p2 =
"/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
140 $text = preg_replace( $p1,
"\\1 ", $text );
141 $text = preg_replace( $p2,
"\\1 \\3 ", $text );
143 # Internal image links
144 $pat2 =
"/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
145 $text = preg_replace( $pat2,
" \\1 \\3", $text );
147 $text = preg_replace(
"/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
148 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
150 # Strip all remaining non-search characters
151 $text = preg_replace(
"/[^{$lc}]+/",
" ", $text );
169 $text = strrev( preg_replace(
"/ s'([{$lc}]+)/",
" s'\\1 \\1", strrev( $text ) ) );
170 $text = strrev( preg_replace(
"/ 's([{$lc}]+)/",
" s\\1", strrev( $text ) ) );
172 # Strip wiki '' and '''
173 $text = preg_replace(
"/''[']*/",
" ", $text );
188 if ( !isset( $this->page ) ) {
189 $this->page = WikiPage::newFromID( $this->
id, WikiPage::READ_LATEST );
203 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
204 $ns = $this->title->getNamespace();
205 $title = $this->title->getText();
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)
Throws a warning that $function is deprecated.
Contain a class for special pages.
normalizeText( $string)
When overridden in derived class, performs database-specific conversions on text to be used for searc...
legalSearchChars( $type=self::CHARS_ALL)
Get chars legal for search.
Database independant search index updater.
__construct( $id, $title, $c=null)
getLatestPage()
Get WikiPage for the SearchUpdate $id using WikiPage::READ_LATEST and ensure using the same WikiPage ...
updateText( $text, SearchEngine $se=null)
Clean text for indexing.
getNormalizedTitle(SearchEngine $search)
Get a normalized string representation of a title suitable for including in a search index.
doUpdate()
Perform actual update for the entry.
Content null $content
Content of the page (not text)
Title $title
Title we're updating.
int $id
Page id being updated.
Content object implementation for representing flat text.
Represents a title within MediaWiki.
Class representing a MediaWiki article and history.
Base interface for content objects.
Interface that deferrable updates should implement.