From 4b283918204bed0d4a572c54542ef78c4fa838e6 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Mon, 23 Mar 2015 11:51:39 -0700 Subject: [PATCH] Deprecate wfDiff() This function is backwards: * The stated purpose is to generate a list of differences for callers to parse, however we already have DiffEngine that returns a list of differences that you don't need to parse manually shooting your feet off in process. * With improvements in PHP performance in the last 10 years, shelling out instead of using a pure-PHP diff has a doubtful performance benefit. * Even in configurations where it's faster on predominant diffs (which have to be huge), shelling out has its own security implications. This function is not used in core. The only extensons using it are Echo (which just parses its output so would be better off with DiffEngine) and AbuseFilter, let's not add more users by tolerating this function. Also, add error checking while I'm at it. Change-Id: Ia67debce39de8252312fd887ebfbe6fb89f9edc9 --- RELEASE-NOTES-1.25 | 1 + includes/GlobalFunctions.php | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 1a0c0d97b3..01ab7391ad 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -410,6 +410,7 @@ changes to languages because of Bugzilla reports. instead just returns the Status object. Extension calling it should be aware of this. * Removed class DBObject. (unused since 1.10) +* wfDiff() is deprecated. == Compatibility == diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 47e7a151ea..a9ed60fe6e 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3115,7 +3115,9 @@ function wfMerge( $old, $mine, $yours, &$result ) { /** * Returns unified plain-text diff of two texts. - * Useful for machine processing of diffs. + * "Useful" for machine processing of diffs. + * + * @deprecated since 1.25, use DiffEngine/UnifiedDiffFormatter directly * * @param string $before The text before the changes. * @param string $after The text after the changes. @@ -3155,6 +3157,11 @@ function wfDiff( $before, $after, $params = '-u' ) { $cmd = "$wgDiff " . $params . ' ' . wfEscapeShellArg( $oldtextName, $newtextName ); $h = popen( $cmd, 'r' ); + if ( !$h ) { + unlink( $oldtextName ); + unlink( $newtextName ); + throw new Exception( __METHOD__ . '(): popen() failed' ); + } $diff = ''; -- 2.20.1