Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -74,20 +74,20 @@ function search_help($route_name, RouteMatchInterface $route_match) {
case 'help.page.search':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Search module provides the ability to set up search pages based on plugins provided by other modules. In Drupal core, there are two page-type plugins: the Content page type provides keyword searching for content managed by the Node module, and the Users page type provides keyword searching for registered users. Contributed modules may provide other page-type plugins. For more information, see the <a href=":search-module">online documentation for the Search module</a>.', array(':search-module' => 'https://www.drupal.org/documentation/modules/search')) . '</p>';
$output .= '<p>' . t('The Search module provides the ability to set up search pages based on plugins provided by other modules. In Drupal core, there are two page-type plugins: the Content page type provides keyword searching for content managed by the Node module, and the Users page type provides keyword searching for registered users. Contributed modules may provide other page-type plugins. For more information, see the <a href=":search-module">online documentation for the Search module</a>.', [':search-module' => 'https://www.drupal.org/documentation/modules/search']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Configuring search pages') . '</dt>';
$output .= '<dd>' . t('To configure search pages, visit the <a href=":search-settings">Search pages page</a>. In the Search pages section, you can add a new search page, edit the configuration of existing search pages, enable and disable search pages, and choose the default search page. Each enabled search page has a URL path starting with <em>search</em>, and each will appear as a tab or local task link on the <a href=":search-url">search page</a>; you can configure the text that is shown in the tab. In addition, some search page plugins have additional settings that you can configure for each search page.', array(':search-settings' => \Drupal::url('entity.search_page.collection'), ':search-url' => \Drupal::url('search.view'))) . '</dd>';
$output .= '<dd>' . t('To configure search pages, visit the <a href=":search-settings">Search pages page</a>. In the Search pages section, you can add a new search page, edit the configuration of existing search pages, enable and disable search pages, and choose the default search page. Each enabled search page has a URL path starting with <em>search</em>, and each will appear as a tab or local task link on the <a href=":search-url">search page</a>; you can configure the text that is shown in the tab. In addition, some search page plugins have additional settings that you can configure for each search page.', [':search-settings' => \Drupal::url('entity.search_page.collection'), ':search-url' => \Drupal::url('search.view')]) . '</dd>';
$output .= '<dt>' . t('Managing the search index') . '</dt>';
$output .= '<dd>' . t('Some search page plugins, such as the core Content search page, index searchable text using the Drupal core search index, and will not work unless content is indexed. Indexing is done during <em>cron</em> runs, so it requires a <a href=":cron">cron maintenance task</a> to be set up. There are also several settings affecting indexing that can be configured on the <a href=":search-settings">Search pages page</a>: the number of items to index per cron run, the minimum word length to index, and how to handle Chinese, Japanese, and Korean characters.', array(':cron' => \Drupal::url('system.cron_settings'), ':search-settings' => \Drupal::url('entity.search_page.collection'))) . '</dd>';
$output .= '<dd>' . t('Modules providing search page plugins generally ensure that content-related actions on your site (creating, editing, or deleting content and comments) automatically cause affected content items to be marked for indexing or reindexing at the next cron run. When content is marked for reindexing, the previous content remains in the index until cron runs, at which time it is replaced by the new content. However, there are some actions related to the structure of your site that do not cause affected content to be marked for reindexing. Examples of structure-related actions that affect content include deleting or editing taxonomy terms, enabling or disabling modules that add text to content (such as Taxonomy, Comment, and field-providing modules), and modifying the fields or display parameters of your content types. If you take one of these actions and you want to ensure that the search index is updated to reflect your changed site structure, you can mark all content for reindexing by clicking the "Re-index site" button on the <a href=":search-settings">Search pages page</a>. If you have a lot of content on your site, it may take several cron runs for the content to be reindexed.', array(':search-settings' => \Drupal::url('entity.search_page.collection'))) . '</dd>';
$output .= '<dd>' . t('Some search page plugins, such as the core Content search page, index searchable text using the Drupal core search index, and will not work unless content is indexed. Indexing is done during <em>cron</em> runs, so it requires a <a href=":cron">cron maintenance task</a> to be set up. There are also several settings affecting indexing that can be configured on the <a href=":search-settings">Search pages page</a>: the number of items to index per cron run, the minimum word length to index, and how to handle Chinese, Japanese, and Korean characters.', [':cron' => \Drupal::url('system.cron_settings'), ':search-settings' => \Drupal::url('entity.search_page.collection')]) . '</dd>';
$output .= '<dd>' . t('Modules providing search page plugins generally ensure that content-related actions on your site (creating, editing, or deleting content and comments) automatically cause affected content items to be marked for indexing or reindexing at the next cron run. When content is marked for reindexing, the previous content remains in the index until cron runs, at which time it is replaced by the new content. However, there are some actions related to the structure of your site that do not cause affected content to be marked for reindexing. Examples of structure-related actions that affect content include deleting or editing taxonomy terms, enabling or disabling modules that add text to content (such as Taxonomy, Comment, and field-providing modules), and modifying the fields or display parameters of your content types. If you take one of these actions and you want to ensure that the search index is updated to reflect your changed site structure, you can mark all content for reindexing by clicking the "Re-index site" button on the <a href=":search-settings">Search pages page</a>. If you have a lot of content on your site, it may take several cron runs for the content to be reindexed.', [':search-settings' => \Drupal::url('entity.search_page.collection')]) . '</dd>';
$output .= '<dt>' . t('Displaying the Search block') . '</dt>';
$output .= '<dd>' . t('The Search module includes a block, which can be enabled and configured on the <a href=":blocks">Block layout page</a>, if you have the Block module enabled; the default block title is Search, and it is the Search form block in the Forms category, if you wish to add another instance. The block is available to users with the <a href=":search_permission">Use search</a> permission, and it performs a search using the configured default search page.', array(':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#', ':search_permission' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-search')))) . '</dd>';
$output .= '<dd>' . t('The Search module includes a block, which can be enabled and configured on the <a href=":blocks">Block layout page</a>, if you have the Block module enabled; the default block title is Search, and it is the Search form block in the Forms category, if you wish to add another instance. The block is available to users with the <a href=":search_permission">Use search</a> permission, and it performs a search using the configured default search page.', [':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#', ':search_permission' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-search'])]) . '</dd>';
$output .= '<dt>' . t('Searching your site') . '</dt>';
$output .= '<dd>' . t('Users with <a href=":search_permission">Use search</a> permission can use the Search block and <a href=":search">Search page</a>. Users with the <a href=":node_permission">View published content</a> permission can use configured search pages of type <em>Content</em> to search for content containing exact keywords; in addition, users with <a href=":search_permission">Use advanced search</a> permission can use more complex search filtering. Users with the <a href=":user_permission">View user information</a> permission can use configured search pages of type <em>Users</em> to search for active users containing the keyword anywhere in the username, and users with the <a href=":user_permission">Administer users</a> permission can search for active and blocked users, by email address or username keyword.', array(':search' => \Drupal::url('search.view'), ':search_permission' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-search')), ':node_permission' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-node')), ':user_permission' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-user')))) . '</dd>';
$output .= '<dd>' . t('Users with <a href=":search_permission">Use search</a> permission can use the Search block and <a href=":search">Search page</a>. Users with the <a href=":node_permission">View published content</a> permission can use configured search pages of type <em>Content</em> to search for content containing exact keywords; in addition, users with <a href=":search_permission">Use advanced search</a> permission can use more complex search filtering. Users with the <a href=":user_permission">View user information</a> permission can use configured search pages of type <em>Users</em> to search for active users containing the keyword anywhere in the username, and users with the <a href=":user_permission">Administer users</a> permission can search for active and blocked users, by email address or username keyword.', [':search' => \Drupal::url('search.view'), ':search_permission' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-search']), ':node_permission' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-node']), ':user_permission' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-user'])]) . '</dd>';
$output .= '<dt>' . t('Extending the Search module') . '</dt>';
$output .= '<dd>' . t('By default, the Search module only supports exact keyword matching in content searches. You can modify this behavior by installing a language-specific stemming module for your language (such as <a href=":porterstemmer_url">Porter Stemmer</a> for American English), which allows words such as walk, walking, and walked to be matched in the Search module. Another approach is to use a third-party search technology with stemming or partial word matching features built in, such as <a href=":solr_url">Apache Solr</a> or <a href=":sphinx_url">Sphinx</a>. There are also contributed modules that provide additional search pages. These and other <a href=":contrib-search">search-related contributed modules</a> can be downloaded by visiting Drupal.org.', array(':contrib-search' => 'https://www.drupal.org/project/project_module?f[2]=im_vid_3%3A105', ':porterstemmer_url' => 'https://www.drupal.org/project/porterstemmer', ':solr_url' => 'https://www.drupal.org/project/apachesolr', ':sphinx_url' => 'https://www.drupal.org/project/sphinx')) . '</dd>';
$output .= '<dd>' . t('By default, the Search module only supports exact keyword matching in content searches. You can modify this behavior by installing a language-specific stemming module for your language (such as <a href=":porterstemmer_url">Porter Stemmer</a> for American English), which allows words such as walk, walking, and walked to be matched in the Search module. Another approach is to use a third-party search technology with stemming or partial word matching features built in, such as <a href=":solr_url">Apache Solr</a> or <a href=":sphinx_url">Sphinx</a>. There are also contributed modules that provide additional search pages. These and other <a href=":contrib-search">search-related contributed modules</a> can be downloaded by visiting Drupal.org.', [':contrib-search' => 'https://www.drupal.org/project/project_module?f[2]=im_vid_3%3A105', ':porterstemmer_url' => 'https://www.drupal.org/project/porterstemmer', ':solr_url' => 'https://www.drupal.org/project/apachesolr', ':sphinx_url' => 'https://www.drupal.org/project/sphinx']) . '</dd>';
$output .= '</dl>';
return $output;
}
@ -97,12 +97,12 @@ function search_help($route_name, RouteMatchInterface $route_match) {
* Implements hook_theme().
*/
function search_theme() {
return array(
'search_result' => array(
'variables' => array('result' => NULL, 'plugin_id' => NULL),
return [
'search_result' => [
'variables' => ['result' => NULL, 'plugin_id' => NULL],
'file' => 'search.pages.inc',
),
);
],
];
}
/**
@ -167,7 +167,7 @@ function search_index_clear($type = NULL, $sid = NULL, $langcode = NULL) {
* total counts in the search_total table, and need to be recounted.
*/
function search_dirty($word = NULL) {
$dirty = &drupal_static(__FUNCTION__, array());
$dirty = &drupal_static(__FUNCTION__, []);
if ($word !== NULL) {
$dirty[$word] = TRUE;
}
@ -206,18 +206,18 @@ function search_update_totals() {
// Update word IDF (Inverse Document Frequency) counts for new/changed words.
foreach (search_dirty() as $word => $dummy) {
// Get total count
$total = db_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", array(':word' => $word), array('target' => 'replica'))->fetchField();
$total = db_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", [':word' => $word], ['target' => 'replica'])->fetchField();
// Apply Zipf's law to equalize the probability distribution.
$total = log10(1 + 1 / (max(1, $total)));
db_merge('search_total')
->key('word', $word)
->fields(array('count' => $total))
->fields(['count' => $total])
->execute();
}
// Find words that were deleted from search_index, but are still in
// search_total. We use a LEFT JOIN between the two tables and keep only the
// rows which fail to join.
$result = db_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL", array(), array('target' => 'replica'));
$result = db_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL", [], ['target' => 'replica']);
$or = db_or();
foreach ($result as $word) {
$or->condition('word', $word->realword);
@ -329,7 +329,7 @@ function search_expand_cjk($matches) {
}
$tokens = ' ';
// Build a FIFO queue of characters.
$chars = array();
$chars = [];
for ($i = 0; $i < $length; $i++) {
// Add the next character off the beginning of the string to the queue.
$current = Unicode::substr($str, 0, 1);
@ -382,7 +382,7 @@ function search_index_split($text, $langcode = NULL) {
function _search_index_truncate(&$text) {
// Use a static array to avoid re-truncating text we've done before.
// The same words may often be passed in during excerpt generation.
static $truncated = array();
static $truncated = [];
if (isset($truncated[$text])) {
$text = $truncated[$text];
return;
@ -408,7 +408,7 @@ function _search_index_truncate(&$text) {
*/
function search_invoke_preprocess(&$text, $langcode = NULL) {
foreach (\Drupal::moduleHandler()->getImplementations('search_preprocess') as $module) {
$text = \Drupal::moduleHandler()->invoke($module, 'search_preprocess', array($text, $langcode));
$text = \Drupal::moduleHandler()->invoke($module, 'search_preprocess', [$text, $langcode]);
}
}
@ -437,7 +437,7 @@ function search_index($type, $sid, $langcode, $text) {
// Strip off all ignored tags to speed up processing, but insert space before
// and after them to keep word boundaries.
$text = str_replace(array('<', '>'), array(' <', '> '), $text);
$text = str_replace(['<', '>'], [' <', '> '], $text);
$text = strip_tags($text, '<' . implode('><', array_keys($tags)) . '>');
// Split HTML tags from plain text.
@ -448,11 +448,11 @@ function search_index($type, $sid, $langcode, $text) {
$tag = FALSE; // Odd/even counter. Tag or no tag.
$score = 1; // Starting score per word
$accum = ' '; // Accumulator for cleaned up data
$tagstack = array(); // Stack with open tags
$tagstack = []; // Stack with open tags
$tagwords = 0; // Counter for consecutive words
$focus = 1; // Focus state
$scored_words = array(); // Accumulator for words for index
$scored_words = []; // Accumulator for words for index
foreach ($split as $value) {
if ($tag) {
@ -464,7 +464,7 @@ function search_index($type, $sid, $langcode, $text) {
$tagname = substr($tagname, 1);
// If we encounter unexpected tags, reset score to avoid incorrect boosting.
if (!count($tagstack) || $tagstack[0] != $tagname) {
$tagstack = array();
$tagstack = [];
$score = 1;
}
else {
@ -476,7 +476,7 @@ function search_index($type, $sid, $langcode, $text) {
if (isset($tagstack[0]) && $tagstack[0] == $tagname) {
// None of the tags we look for make sense when nested identically.
// If they are, it's probably broken HTML.
$tagstack = array();
$tagstack = [];
$score = 1;
}
else {
@ -508,7 +508,7 @@ function search_index($type, $sid, $langcode, $text) {
$tagwords++;
// Too many words inside a single tag probably mean a tag was accidentally left open.
if (count($tagstack) && $tagwords >= 15) {
$tagstack = array();
$tagstack = [];
$score = 1;
}
}
@ -523,13 +523,13 @@ function search_index($type, $sid, $langcode, $text) {
// Insert cleaned up data into dataset
db_insert('search_dataset')
->fields(array(
->fields([
'sid' => $sid,
'langcode' => $langcode,
'type' => $type,
'data' => $accum,
'reindex' => 0,
))
])
->execute();
// Insert results into search index
@ -538,14 +538,14 @@ function search_index($type, $sid, $langcode, $text) {
// appropriately. If not, we create a new record with the appropriate
// starting score.
db_merge('search_index')
->keys(array(
->keys([
'word' => $word,
'sid' => $sid,
'langcode' => $langcode,
'type' => $type,
))
->fields(array('score' => $score))
->expression('score', 'score + :score', array(':score' => $score))
])
->fields(['score' => $score])
->expression('score', 'score + :score', [':score' => $score])
->execute();
search_dirty($word);
}
@ -571,7 +571,7 @@ function search_index($type, $sid, $langcode, $text) {
*/
function search_mark_for_reindex($type = NULL, $sid = NULL, $langcode = NULL) {
$query = db_update('search_dataset')
->fields(array('reindex' => REQUEST_TIME))
->fields(['reindex' => REQUEST_TIME])
// Only mark items that were not previously marked for reindex, so that
// marked items maintain their priority by request time.
->condition('reindex', 0);
@ -650,14 +650,14 @@ function search_excerpt($keys, $text, $langcode = NULL) {
$keys = array_merge($matches[2], $matches[3]);
// Prepare text by stripping HTML tags and decoding HTML entities.
$text = strip_tags(str_replace(array('<', '>'), array(' <', '> '), $text));
$text = strip_tags(str_replace(['<', '>'], [' <', '> '], $text));
$text = Html::decodeEntities($text);
$text_length = strlen($text);
// Make a list of unique keywords that are actually found in the text,
// which could be items in $keys or replacements that are equivalent through
// search_simplify().
$temp_keys = array();
$temp_keys = [];
foreach ($keys as $key) {
$key = _search_find_match_with_simplify($key, $text, $boundary_character, $langcode);
if (isset($key)) {
@ -672,13 +672,13 @@ function search_excerpt($keys, $text, $langcode = NULL) {
// Extract fragments of about 60 characters around keywords, bounded by word
// boundary characters. Try to reach 256 characters, using second occurrences
// if necessary.
$ranges = array();
$ranges = [];
$length = 0;
$look_start = array();
$look_start = [];
$remaining_keys = $keys;
while ($length < 256 && !empty($remaining_keys)) {
$found_keys = array();
$found_keys = [];
foreach ($remaining_keys as $key) {
if ($length >= 256) {
break;
@ -693,7 +693,7 @@ function search_excerpt($keys, $text, $langcode = NULL) {
// See if we can find $key after where we found it the last time. Since
// we are requiring a match on a word boundary, make sure $text starts
// and ends with a space.
$matches = array();
$matches = [];
if (preg_match('/' . $preceded_by_boundary . $key . $followed_by_boundary . '/iu', ' ' . $text . ' ', $matches, PREG_OFFSET_CAPTURE, $look_start[$key])) {
$found_position = $matches[0][1];
$look_start[$key] = $found_position + 1;
@ -741,7 +741,7 @@ function search_excerpt($keys, $text, $langcode = NULL) {
ksort($ranges);
// Collapse overlapping text ranges into one. The sorting makes it O(n).
$new_ranges = array();
$new_ranges = [];
$max_end = 0;
foreach ($ranges as $this_from => $this_to) {
$max_end = max($max_end, $this_to);
@ -766,7 +766,7 @@ function search_excerpt($keys, $text, $langcode = NULL) {
$new_ranges[$working_from] = $working_to;
// Fetch text within the combined ranges we found.
$out = array();
$out = [];
foreach ($new_ranges as $from => $to) {
$out[] = substr($text, $from, $to - $from);
}
@ -846,7 +846,7 @@ function _search_find_match_with_simplify($key, $text, $boundary, $langcode = NU
// Split $text into words, keeping track of where the word boundaries are.
$words = preg_split('/' . $boundary . '+/u', $text, NULL, PREG_SPLIT_OFFSET_CAPTURE);
// Add an entry pointing to the end of the string, for the loop below.
$words[] = array('', strlen($text));
$words[] = ['', strlen($text)];
// Using a binary search, find the earliest possible ending position in
// $text where it will still match the keyword after applying