Deprecate wfDiff()
authorMax Semenik <maxsem.wiki@gmail.com>
Mon, 23 Mar 2015 18:51:39 +0000 (11:51 -0700)
committerKunal Mehta <legoktm@gmail.com>
Thu, 26 Mar 2015 04:19:32 +0000 (21:19 -0700)
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
includes/GlobalFunctions.php

index 1a0c0d9..01ab739 100644 (file)
@@ -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 ==
 
index 47e7a15..a9ed60f 100644 (file)
@@ -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 = '';