From 41701080d2c9b0b37990f5d79e8eee1c9b3b4093 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 4 Jan 2006 00:27:48 +0000 Subject: [PATCH] * (bug 4453) fix for __TOC__ dollar-number breakage --- RELEASE-NOTES | 1 + includes/GlobalFunctions.php | 13 +++++++++++++ includes/MagicWord.php | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 24d344de1d..ef43bfcd9b 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -403,6 +403,7 @@ fully support the editing toolbar, but was found to be too confusing. which uses ipboptions * (bug 4446) $wgExportAllowHistory option to explicitly disable history in Special:Export form, 'exportnohistory' message to translate live hack. +* (bug 4453) fix for __TOC__ dollar-number breakage === Caveats === diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index c804bb7558..23d177701f 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1737,4 +1737,17 @@ function wfUseMW( $req_ver ) { wfDebugDieBacktrace( "MediaWiki $req_ver required--this is only $wgVersion" ); } +/** + * Escape a string to make it suitable for inclusion in a preg_replace() + * replacement parameter. + * + * @param string $string + * @return string + */ +function wfRegexReplacement( $string ) { + $string = str_replace( '\\', '\\\\', $string ); + $string = str_replace( '$', '\\$', $string ); + return $string; +} + ?> diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 7d38b0ee75..603ab8c049 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -272,7 +272,7 @@ class MagicWord { * Replaces the word with something else */ function replace( $replacement, $subject ) { - $res = preg_replace( $this->getRegex(), $replacement, $subject ); + $res = preg_replace( $this->getRegex(), wfRegexReplacement( $replacement ), $subject ); $this->mModified = !($res === $subject); return $res; } -- 2.20.1