r12987 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12986‎ | r12987 | r12988 >
Date:13:04, 9 February 2006
Author:timstarling
Status:old
Tags:
Comment:
Added support for wikidiff2 and similar external diff engines.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/DifferenceEngine.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DifferenceEngine.php
@@ -44,7 +44,7 @@
4545 $this->mTitle = $titleObj;
4646 wfDebug("DifferenceEngine old '$old' new '$new' rcid '$rcid'\n");
4747
48 - if ( 'prev' == $new ) {
 48+ if ( 'prev' === $new ) {
4949 # Show diff between revision $old and the previous one.
5050 # Get previous one from DB.
5151 #
@@ -52,7 +52,7 @@
5353
5454 $this->mOldid = $this->mTitle->getPreviousRevisionID( $this->mNewid );
5555
56 - } elseif ( 'next' == $new ) {
 56+ } elseif ( 'next' === $new ) {
5757 # Show diff between revision $old and the previous one.
5858 # Get previous one from DB.
5959 #
@@ -316,8 +316,10 @@
317317 * Returns false on error
318318 */
319319 function getDiffBody() {
320 - global $wgUseExternalDiffEngine, $wgContLang, $wgMemc, $wgDBname;
321 -
 320+ global $wgExternalDiffEngine, $wgContLang, $wgMemc, $wgDBname;
 321+ $fname = 'DifferenceEngine::getDiffBody';
 322+ wfProfileIn( $fname );
 323+
322324 // Cacheable?
323325 $key = false;
324326 if ( $this->mOldid && $this->mNewid ) {
@@ -328,17 +330,19 @@
329331 wfIncrStats( 'diff_cache_hit' );
330332 $difftext = $this->localiseLineNumbers( $difftext );
331333 $difftext .= "\n<!-- diff cache key $key -->\n";
 334+ wfProfileOut( $fname );
332335 return $difftext;
333336 }
334337 }
335338
336339 if ( !$this->loadText() ) {
 340+ wfProfileOut( $fname );
337341 return false;
338342 }
339343
340344 $otext = $wgContLang->segmentForDiff($this->mOldtext);
341345 $ntext = $wgContLang->segmentForDiff($this->mNewtext);
342 - if ( $wgUseExternalDiffEngine ) {
 346+ if ( $wgExternalDiffEngine == 'wikidiff' ) {
343347 # For historical reasons, external diff engine expects
344348 # input text to be HTML-escaped already
345349 $otext = str_replace( "\r\n", "\n", htmlspecialchars ( $otext ) );
@@ -347,6 +351,43 @@
348352 dl('php_wikidiff.so');
349353 }
350354 $difftext = wikidiff_do_diff( $otext, $ntext, 2 );
 355+ } elseif ( $wgExternalDiffEngine == 'wikidiff2' ) {
 356+ # Better external diff engine, the 2 may some day be dropped
 357+ # This one does the escaping itself
 358+ $otext = str_replace( "\r\n", "\n", $otext );
 359+ $ntext = str_replace( "\r\n", "\n", $ntext );
 360+ if ( !function_exists( 'wikidiff2_do_diff' ) ) {
 361+ dl('php_wikidiff2.so');
 362+ }
 363+ $difftext = wikidiff2_do_diff( $otext, $ntext, 2 );
 364+ } elseif ( $wgExternalDiffEngine !== false ) {
 365+ # Diff via the shell
 366+ global $wgTmpDirectory;
 367+ $otext = str_replace( "\r\n", "\n", $otext );
 368+ $ntext = str_replace( "\r\n", "\n", $ntext );
 369+ $tempName1 = tempnam( $wgTmpDirectory, 'diff_' );
 370+ $tempName2 = tempnam( $wgTmpDirectory, 'diff_' );
 371+
 372+ $tempFile1 = fopen( $tempName1, "w" );
 373+ if ( !$tempFile1 ) {
 374+ wfProfileOut( $fname );
 375+ return false;
 376+ }
 377+ $tempFile2 = fopen( $tempName2, "w" );
 378+ if ( !$tempFile2 ) {
 379+ wfProfileOut( $fname );
 380+ return false;
 381+ }
 382+ fwrite( $tempFile1, $otext );
 383+ fwrite( $tempFile2, $ntext );
 384+ fclose( $tempFile1 );
 385+ fclose( $tempFile2 );
 386+ $cmd = wfEscapeShellArg( $wgExternalDiffEngine, $tempName1, $tempName2 );
 387+ wfProfileIn( "$fname-shellexec" );
 388+ $difftext = wfShellExec( $cmd );
 389+ wfProfileOut( "$fname-shellexec" );
 390+ unlink( $tempName1 );
 391+ unlink( $tempName2 );
351392 } else {
352393 $ota = explode( "\n", str_replace( "\r\n", "\n", $otext ) );
353394 $nta = explode( "\n", str_replace( "\r\n", "\n", $ntext ) );
@@ -365,6 +406,7 @@
366407 }
367408 // Replace line numbers with the text in the user's language
368409 $difftext = $this->localiseLineNumbers( $difftext );
 410+ wfProfileOut( $fname );
369411 return $difftext;
370412 }
371413
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1474,8 +1474,8 @@
14751475 /** Maximum indent level of toc. */
14761476 $wgMaxTocLevel = 999;
14771477
1478 -/** Use external C++ diff engine (module wikidiff from the extensions package) */
1479 -$wgUseExternalDiffEngine = false;
 1478+/** Name of the external diff engine to use */
 1479+$wgExternalDiffEngine = false;
14801480
14811481 /** Use RC Patrolling to check for vandalism */
14821482 $wgUseRCPatrol = true;
Index: trunk/phase3/RELEASE-NOTES
@@ -232,6 +232,7 @@
233233 * (bug 4267) Switch dv sd ug ks arc languages to RTL
234234 * Default main page content improved per bug 4690
235235 * (bug 4615) Update for Portuguese language (pt)
 236+* Separated MessagesSl.php as the other languages.
236237
237238 Parser:
238239 * (bug 2522) {{CURRENTDAY2}} now shows the current day number with two digits
@@ -606,7 +607,7 @@
607608 * (bug 4147) Added cleanupWatchlist.php to clear out bogus watchlist entries
608609 * (partial bug 3456) Disable auto redirect to Main Page after account creation
609610 * (bug 4824) Separate out IE7 CSS compat hacks, fix for RTL pages
610 -* Separated MessagesSl.php as the other languages.
 611+* Added support for wikidiff2 and similar external diff engines.
611612
612613
613614 === Caveats ===

Status & tagging log