/** @var Title Title we're updating */
private $title;
- /** @var Content|bool Content of the page (not text) */
+ /** @var Content|null Content of the page (not text) */
private $content;
- /** @var WikiPage **/
+ /** @var WikiPage */
private $page;
/**
* @param int $id Page id to update
- * @param Title|string $title Title of page to update
- * @param Content|string|bool $c Content of the page to update. Default: false.
- * If a Content object, text will be gotten from it. String is for back-compat.
- * Passing false tells the backend to just update the title, not the content
+ * @param Title $title Title of page to update
+ * @param Content|null $c Content of the page to update.
*/
- public function __construct( $id, $title, $c = false ) {
+ public function __construct( $id, $title, $c = null ) {
if ( is_string( $title ) ) {
- $nt = Title::newFromText( $title );
+ wfDeprecated( __METHOD__ . " with a string for the title", 1.34 );
+ $this->title = Title::newFromText( $title );
+ if ( $this->title === null ) {
+ throw new InvalidArgumentException( "Cannot construct the title: $title" );
+ }
} else {
- $nt = $title;
+ $this->title = $title;
}
- if ( $nt ) {
- $this->id = $id;
- // is_string() check is back-compat for ApprovedRevs
- if ( is_string( $c ) ) {
- $this->content = new TextContent( $c );
- } else {
- $this->content = $c ?: false;
- }
- $this->title = $nt;
- } else {
- wfDebug( "SearchUpdate object created with invalid title '$title'\n" );
+ $this->id = $id;
+ // is_string() check is back-compat for ApprovedRevs
+ if ( is_string( $c ) ) {
+ wfDeprecated( __METHOD__ . " with a string for the content", 1.34 );
+ $c = new TextContent( $c );
+ } elseif ( is_bool( $c ) ) {
+ wfDeprecated( __METHOD__ . " with a boolean for the content", 1.34 );
+ $c = null;
}
+ $this->content = $c;
}
/**
* Perform actual update for the entry
*/
public function doUpdate() {
- $config = MediaWikiServices::getInstance()->getSearchEngineConfig();
+ $services = MediaWikiServices::getInstance();
+ $config = $services->getSearchEngineConfig();
if ( $config->getConfig()->get( 'DisableSearchUpdate' ) || !$this->id ) {
return;
}
- $seFactory = MediaWikiServices::getInstance()->getSearchEngineFactory();
+ $seFactory = $services->getSearchEngineFactory();
foreach ( $config->getSearchTypes() as $type ) {
$search = $seFactory->create( $type );
if ( !$search->supports( 'search-update' ) ) {
if ( $this->getLatestPage() === null ) {
$search->delete( $this->id, $normalTitle );
continue;
- } elseif ( $this->content === false ) {
+ } elseif ( $this->content === null ) {
$search->updateTitle( $this->id, $normalTitle );
continue;
}
- $text = $search->getTextFromContent( $this->title, $this->content );
- if ( !$search->textAlreadyUpdatedForIndex() ) {
- $text = $this->updateText( $text, $search );
- }
+ $text = $this->content !== null ? $this->content->getTextForSearchIndex() : '';
+ $text = $this->updateText( $text, $search );
# Perform the actual update
$search->update( $this->id, $normalTitle, $search->normalizeText( $text ) );
* @return string
*/
public function updateText( $text, SearchEngine $se = null ) {
+ $services = MediaWikiServices::getInstance();
+ $contLang = $services->getContentLanguage();
# Language-specific strip/conversion
- $text = MediaWikiServices::getInstance()->getContentLanguage()->normalizeForSearch( $text );
- $se = $se ?: MediaWikiServices::getInstance()->newSearchEngine();
+ $text = $contLang->normalizeForSearch( $text );
+ $se = $se ?: $services->newSearchEngine();
$lc = $se->legalSearchChars() . '&#;';
# Strip HTML markup
$text = preg_replace( "/<\\/?\\s*[A-Za-z][^>]*?>/",
- ' ', MediaWikiServices::getInstance()->getContentLanguage()->lc( " " . $text . " " ) );
+ ' ', $contLang->lc( " " . $text . " " ) );
$text = preg_replace( "/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/sD",
"\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
* @return string A stripped-down title string ready for the search index
*/
private function getNormalizedTitle( SearchEngine $search ) {
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$ns = $this->title->getNamespace();
$title = $this->title->getText();
$lc = $search->legalSearchChars() . '&#;';
- $t = MediaWikiServices::getInstance()->getContentLanguage()->normalizeForSearch( $title );
+ $t = $contLang->normalizeForSearch( $title );
$t = preg_replace( "/[^{$lc}]+/", ' ', $t );
- $t = MediaWikiServices::getInstance()->getContentLanguage()->lc( $t );
+ $t = $contLang->lc( $t );
# Handle 's, s'
$t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );