Follow-up to:
#120955: Integrate Diff into Core
#1848264: Compare and merge PhpWiki diff*.php with MediaWiki's DairikiDiff.php and DiffEngine.php

Task

  1. Convert Drupal\Component\Diff\* into a proper, PSR-0-compatible PHP component.
Files: 
CommentFileSizeAuthor
#6 1848266.6.patch79.74 KBalexpott
PASSED: [[SimpleTest]]: [MySQL] 64,313 pass(es).
[ View ]
#6 3-6-interdiff.txt18.79 KBalexpott

Comments

Status:Postponed» Active

Probably it's time to make it active

Issue summary:View changes

Also @todo was added to core/lib/Drupal/Core/Config/ConfigManager.php in #2188595: Create a ConfigManager to be able to remove config.inc

Status:Active» Needs review
StatusFileSize
new59.99 KB
FAILED: [[SimpleTest]]: [MySQL] 64,296 pass(es), 6 fail(s), and 2 exception(s).
[ View ]

Here's a first cut of work - I've done this once before so I used that. We got a lot of work to tidy this up for docs, coding standards and to test.

What the patch does:

  • In #2102499: Convert DiffEngine to settings we converted some variables into Settings. The patch attached moves these properly into Config by separating the DrupalDiffFormatter into Drupal\Core\Diff\DiffFormatter - so it is allowed to have drupal specific code.
  • Global defines to class constants
  • A couple of functions that were returning a value to class constants too
  • Adds protected and public where necessary
  • Adds a new method to Diff to getEdits()

Still to do:

  • Unit tests
  • Documentation clean up
  • Refactor protected classes stating with _ to not

Assigned:sun» alexpott

Thanks for kick-starting this, @alexpott!

Q: Did you retain most the functional code as-is?

One of the primary goals of my original work in #120955: Integrate Diff into Core work was to retain 100% compatibility with the original Diff library of MediaWiki, so that our PSR-0-ified component can hopefully serve as a drop-in replacement for MediaWiki and any other FOSS project.

That's also the reason for the follow-up issue #1848264: Compare and merge PhpWiki diff*.php with MediaWiki's DairikiDiff.php and DiffEngine.php — ...and speaking of, before we move and convert all of the procedural code, I guess it would be best to perform that diff/review first - otherwise, it's going to be close to impossible to produce any kind of sane diff ;-)

Status:Needs review» Needs work

The last submitted patch, 3: 1848266.3.patch, failed testing.

Status:Needs work» Needs review
StatusFileSize
new18.79 KB
new79.74 KB
PASSED: [[SimpleTest]]: [MySQL] 64,313 pass(es).
[ View ]

Doh. Forgot to actually add the DiffEngine classes.

Q: Did you retain most the functional code as-is?

A: Changed as little as possible.

before we move and convert all of the procedural code

There is no procedural code. It is all old style PHP4 OO code :)

Changes so far:

  • All classes and methods have the same name - changed methods which had the same name as their class to __construct()
  • In #2102499: Convert DiffEngine to settings we converted some variables into Settings. The patch attached moves these properly into Config by separating the DrupalDiffFormatter to Drupal\Core\Diff\DiffFormatter - so it is allowed to have drupal specific code.
  • Global defines to class constants
  • A couple of functions that were returning a value to class constants too
  • Adds protected and public where necessary
  • Started to removed _ from protected property names
  • Adds a new method to Diff to getEdits() since Diff::$edits has become protected

Does it make sense to fix this in upstream of the MediaWiki?
Quickly goggled for psr-0+mediaWiki I found that they already started conversion

+++ b/core/lib/Drupal/Component/Diff/DiffFormatter.php
@@ -0,0 +1,188 @@
+  public function format(Diff $diff) {
...
+            $this->_block($x0, $ntrail + $xi - $x0, $y0, $ntrail + $yi - $y0, $block);
+++ b/core/modules/config/lib/Drupal/config/Tests/ConfigDiffTest.php
@@ -80,10 +82,11 @@ function testDiff() {
\ No newline at end of file
+++ b/core/modules/system/config/system.diff.yml
@@ -0,0 +1,3 @@
\ No newline at end of file

Seems this broken in original code ($x0, $y0) are undefined