<?php
+
+use MediaWiki\Search\ParserOutputSearchDataExtractor;
+
/**
* Base class for content handling.
*
*
* @param string $event Event name
* @param array $args Parameters passed to hook functions
- * @param bool $warn Whether to log a warning.
- * Default to self::$enableDeprecationWarnings.
- * May be set to false for testing.
+ * @param string|null $deprecatedVersion Emit a deprecation notice
+ * when the hook is run for the provided version
*
* @return bool True if no handler aborted the hook
- *
- * @see ContentHandler::$enableDeprecationWarnings
*/
public static function runLegacyHooks( $event, $args = [],
- $warn = null
+ $deprecatedVersion = null
) {
- if ( $warn === null ) {
- $warn = self::$enableDeprecationWarnings;
- }
-
if ( !Hooks::isRegistered( $event ) ) {
return true; // nothing to do here
}
- if ( $warn ) {
- // Log information about which handlers are registered for the legacy hook,
- // so we can find and fix them.
-
- $handlers = Hooks::getHandlers( $event );
- $handlerInfo = [];
-
- MediaWiki\suppressWarnings();
-
- foreach ( $handlers as $handler ) {
- if ( is_array( $handler ) ) {
- if ( is_object( $handler[0] ) ) {
- $info = get_class( $handler[0] );
- } else {
- $info = $handler[0];
- }
-
- if ( isset( $handler[1] ) ) {
- $info .= '::' . $handler[1];
- }
- } elseif ( is_object( $handler ) ) {
- $info = get_class( $handler[0] );
- $info .= '::on' . $event;
- } else {
- $info = $handler;
- }
-
- $handlerInfo[] = $info;
- }
-
- MediaWiki\restoreWarnings();
-
- wfWarn( "Using obsolete hook $event via ContentHandler::runLegacyHooks()! Handlers: " .
- implode( ', ', $handlerInfo ), 2 );
- }
-
// convert Content objects to text
$contentObjects = [];
$contentTexts = [];
}
// call the hook functions
- $ok = Hooks::run( $event, $args );
+ $ok = Hooks::run( $event, $args, $deprecatedVersion );
// see if the hook changed the text
foreach ( $contentTexts as $k => $orig ) {
/**
* Get fields definition for search index
+ *
+ * @todo Expose title, redirect, namespace, text, source_text, text_bytes
+ * field mappings here. (see T142670 and T143409)
+ *
* @param SearchEngine $engine
* @return SearchIndexField[] List of fields this content handler can provide.
* @since 1.28
*/
public function getFieldsForSearchIndex( SearchEngine $engine ) {
- /* Default fields:
- /*
- * namespace
- * namespace_text
- * redirect
- * source_text
- * suggest
- * timestamp
- * title
- * text
- * text_bytes
- */
- return [];
+ $fields['category'] = $engine->makeSearchFieldMapping(
+ 'category',
+ SearchIndexField::INDEX_TYPE_TEXT
+ );
+
+ $fields['category']->setFlag( SearchIndexField::FLAG_CASEFOLD );
+
+ $fields['external_link'] = $engine->makeSearchFieldMapping(
+ 'external_link',
+ SearchIndexField::INDEX_TYPE_KEYWORD
+ );
+
+ $fields['outgoing_link'] = $engine->makeSearchFieldMapping(
+ 'outgoing_link',
+ SearchIndexField::INDEX_TYPE_KEYWORD
+ );
+
+ $fields['template'] = $engine->makeSearchFieldMapping(
+ 'template',
+ SearchIndexField::INDEX_TYPE_KEYWORD
+ );
+
+ $fields['template']->setFlag( SearchIndexField::FLAG_CASEFOLD );
+
+ return $fields;
}
/**
*/
public function getDataForSearchIndex( WikiPage $page, ParserOutput $output,
SearchEngine $engine ) {
- $fields = [];
+ $fieldData = [];
$content = $page->getContent();
+
if ( $content ) {
+ $searchDataExtractor = new ParserOutputSearchDataExtractor();
+
+ $fieldData['category'] = $searchDataExtractor->getCategories( $output );
+ $fieldData['external_link'] = $searchDataExtractor->getExternalLinks( $output );
+ $fieldData['outgoing_link'] = $searchDataExtractor->getOutgoingLinks( $output );
+ $fieldData['template'] = $searchDataExtractor->getTemplates( $output );
+
$text = $content->getTextForSearchIndex();
- $fields['text'] = $text;
- $fields['source_text'] = $text;
- $fields['text_bytes'] = $content->getSize();
+
+ $fieldData['text'] = $text;
+ $fieldData['source_text'] = $text;
+ $fieldData['text_bytes'] = $content->getSize();
}
- Hooks::run( 'SearchDataForIndex', [ &$fields, $this, $page, $output, $engine ] );
- return $fields;
+
+ Hooks::run( 'SearchDataForIndex', [ &$fieldData, $this, $page, $output, $engine ] );
+ return $fieldData;
}
/**