Move setting of targetStr to outside of loop

Change-Id: Ibdcd83ce5d4368bf06f2d57261985a71f7b666ab
This commit is contained in:
Yaron Koren 2023-03-29 18:23:48 +00:00
parent 5190b2cd39
commit 8c890f5ce9

View file

@ -872,6 +872,13 @@ class SpecialReplaceText extends SpecialPage {
$cuts[] = [ $index, $len ]; $cuts[] = [ $index, $len ];
} }
if ( $use_regex ) {
$targetStr = "/$target/Uu";
} else {
$targetq = preg_quote( $this->convertWhiteSpaceToHTML( $target ), '/' );
$targetStr = "/$targetq/i";
}
$context = ''; $context = '';
foreach ( $cuts as $_ ) { foreach ( $cuts as $_ ) {
[ $index, $len, ] = $_; [ $index, $len, ] = $_;
@ -883,12 +890,6 @@ class SpecialReplaceText extends SpecialPage {
$context .= $this->convertWhiteSpaceToHTML( $contextBefore ); $context .= $this->convertWhiteSpaceToHTML( $contextBefore );
$snippet = $this->convertWhiteSpaceToHTML( substr( $text, $index, $len ) ); $snippet = $this->convertWhiteSpaceToHTML( substr( $text, $index, $len ) );
if ( $use_regex ) {
$targetStr = "/$target/Uu";
} else {
$targetq = preg_quote( $this->convertWhiteSpaceToHTML( $target ), '/' );
$targetStr = "/$targetq/i";
}
$context .= preg_replace( $targetStr, '<span class="ext-replacetext-searchmatch">\0</span>', $snippet ); $context .= preg_replace( $targetStr, '<span class="ext-replacetext-searchmatch">\0</span>', $snippet );
$context .= $this->convertWhiteSpaceToHTML( $contextAfter ); $context .= $this->convertWhiteSpaceToHTML( $contextAfter );