diff --git a/filter/glossary/filter.php b/filter/glossary/filter.php index 5098d50327b..1f2591836a1 100644 --- a/filter/glossary/filter.php +++ b/filter/glossary/filter.php @@ -168,9 +168,8 @@ class filter_glossary extends moodle_text_filter { if (!empty($GLOSSARY_EXCLUDEENTRY)) { foreach ($conceptlist as $key => $filterobj) { - if (!is_object($filterobj)) { - continue; - } + // The original concept object was stored here in when $filterobj was constructed in + // get_all_concepts(). Get it back out now so we can check to see if it is excluded. $concept = $filterobj->replacementcallbackdata[0]; if (!$concept->category && $concept->id == $GLOSSARY_EXCLUDEENTRY) { unset($conceptlist[$key]); @@ -182,7 +181,7 @@ class filter_glossary extends moodle_text_filter { return $text; } - return filter_phrases($text, $conceptlist); // Actually search for concepts! + return filter_phrases($text, $conceptlist, null, null, false, true); } /** diff --git a/filter/upgrade.txt b/filter/upgrade.txt index ddfbd82c4bc..1dd24941a0a 100644 --- a/filter/upgrade.txt +++ b/filter/upgrade.txt @@ -1,6 +1,20 @@ This file describes API changes in core filter API and plugins, information provided here is intended especially for developers. +=== 3.6 === + +* Although there is no API change that require you to update your filter, + if you use the filter_phrases() helper method, you may wish to take + advantage of the changes that were made in MDL-47962 to improve performance. + + Now, instead of having to compute the replacement HTML for each phrase before + you construct the filterobject for it. You can instead pass a callback to + the filterobject constructor which is only called if the phrase is used. + + To understand how to use this, see the comment on filterobject::__construct and + look at the filter_glossary changes as an example: + https://github.com/timhunt/moodle/commit/0b9220b527b1d70d2a2fad46c71f1cf2928f8759 + === 3.0 === * New argument $skipfilters to filter_manager::filter_text to allow applying diff --git a/lib/filterlib.php b/lib/filterlib.php index 393fed0da71..d991075af96 100644 --- a/lib/filterlib.php +++ b/lib/filterlib.php @@ -1265,10 +1265,12 @@ function filter_context_may_have_filter_settings($context) { * @param array $ignoretagsopen an array of opening tags that we should ignore while filtering * @param array $ignoretagsclose an array of corresponding closing tags * @param bool $overridedefaultignore True to only use tags provided by arguments + * @param bool $linkarrayalreadyprepared True to say that filter_prepare_phrases_for_filtering + * has already been called for $linkarray. Default false. * @return string */ function filter_phrases($text, $linkarray, $ignoretagsopen = null, $ignoretagsclose = null, - $overridedefaultignore = false) { + $overridedefaultignore = false, $linkarrayalreadyprepared = false) { global $CFG; @@ -1279,7 +1281,7 @@ function filter_phrases($text, $linkarray, $ignoretagsopen = null, $ignoretagscl $ignoretags = array(); // To store all the enclosig tags to be completely ignored. $tags = array(); // To store all the simple tags to be ignored. - if (!isset($linkarray['__preparedmarker'])) { + if (!$linkarrayalreadyprepared) { $linkarray = filter_prepare_phrases_for_filtering($linkarray); } @@ -1326,11 +1328,9 @@ function filter_phrases($text, $linkarray, $ignoretagsopen = null, $ignoretagscl // Time to cycle through each phrase to be linked. foreach ($linkarray as $key => $linkobject) { - if ($key === '__preparedmarker') { - continue; - } - if ($linkobject->workregexp === null) { + // This is the case if, when preparing the phrases for filtering, + // we decided that this was not a suitable phrase to match. continue; } @@ -1429,8 +1429,6 @@ function filter_prepare_phrases_for_filtering(array $linkarray) { } } - $linkarray['__preparedmarker'] = 1; - return $linkarray; }