Jeroen De Dauw has submitted this change and it was merged.

Change subject: Move WikibaseDiffOpFactory class to own file
......................................................................


Move WikibaseDiffOpFactory class to own file

Change-Id: I98fe08c7e8bd721be5457e76335907ee099f2db5
---
M lib/WikibaseLib.php
A lib/includes/WikibaseDiffOpFactory.php
M lib/includes/changes/DiffChange.php
3 files changed, 68 insertions(+), 38 deletions(-)

Approvals:
  Jeroen De Dauw: Verified; Looks good to me, approved



diff --git a/lib/WikibaseLib.php b/lib/WikibaseLib.php
index caa867e..abe0c98 100644
--- a/lib/WikibaseLib.php
+++ b/lib/WikibaseLib.php
@@ -112,6 +112,7 @@
 $wgAutoloadClasses['Wikibase\SiteLink']                                = $dir 
. 'includes/SiteLink.php';
 $wgAutoloadClasses['Wikibase\Term']                                    = $dir 
. 'includes/Term.php';
 $wgAutoloadClasses['Wikibase\Utils']                                   = $dir 
. 'includes/Utils.php';
+$wgAutoloadClasses['Wikibase\WikibaseDiffOpFactory']   = $dir . 
'includes/WikibaseDiffOpFactory.php';
 
 // includes/changes
 $wgAutoloadClasses['Wikibase\Change']                          = $dir . 
'includes/changes/Change.php';
diff --git a/lib/includes/WikibaseDiffOpFactory.php 
b/lib/includes/WikibaseDiffOpFactory.php
new file mode 100644
index 0000000..8b14889
--- /dev/null
+++ b/lib/includes/WikibaseDiffOpFactory.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Wikibase;
+
+/**
+ * Class for changes that can be represented as a IDiff.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 0.4
+ *
+ * @file
+ * @ingroup WikibaseLib
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Kinzler
+ */
+class WikibaseDiffOpFactory extends \Diff\DiffOpFactory {
+       public function newFromArray( array $diffOp ) {
+               $this->assertHasKey( 'type', $diffOp );
+
+               // see EntityDiff::getType() and ItemDiff::getType()
+               if ( preg_match( '!^diff/(.*)$!', $diffOp['type'], $matches ) ) 
{
+                       $itemType = $matches[1];
+                       $this->assertHasKey( 'operations', $diffOp );
+
+                       $operations = $this->createOperations( 
$diffOp['operations'] );
+                       $diff = EntityDiff::newForType( $itemType, $operations 
);
+
+                       return $diff;
+               }
+
+               return parent::newFromArray( $diffOp );
+       }
+
+       /**
+        * Converts a list of diff operations represented by arrays into a list 
of
+        * DiffOp objects.
+        *
+        * @todo: pull this up into DiffOpFactory
+        *
+        * @param array $data the input data
+        * @return \Diff\DiffOp[] The diff ops
+        */
+       protected function createOperations( array $data ) {
+               $operations = array();
+
+               foreach ( $data as $key => $operation ) {
+                       $operations[$key] = $this->newFromArray( $operation );
+               }
+
+               return $operations;
+       }
+}
diff --git a/lib/includes/changes/DiffChange.php 
b/lib/includes/changes/DiffChange.php
index 1da1c8f..3823ef2 100644
--- a/lib/includes/changes/DiffChange.php
+++ b/lib/includes/changes/DiffChange.php
@@ -174,41 +174,3 @@
                return $data; // noop
        }
 }
-
-class WikibaseDiffOpFactory extends \Diff\DiffOpFactory {
-       public function newFromArray( array $diffOp ) {
-               $this->assertHasKey( 'type', $diffOp );
-
-               // see EntityDiff::getType() and ItemDiff::getType()
-               if ( preg_match( '!^diff/(.*)$!', $diffOp['type'], $matches ) ) 
{
-                       $itemType = $matches[1];
-                       $this->assertHasKey( 'operations', $diffOp );
-
-                       $operations = $this->createOperations( 
$diffOp['operations'] );
-                       $diff = EntityDiff::newForType( $itemType, $operations 
);
-
-                       return $diff;
-               }
-
-               return parent::newFromArray( $diffOp );
-       }
-
-       /**
-        * Converts a list of diff operations represented by arrays into a list 
of
-        * DiffOp objects.
-        *
-        * @todo: pull this up into DiffOpFactory
-        *
-        * @param array $data the input data
-        * @return \Diff\DiffOp[] The diff ops
-        */
-       protected function createOperations( array $data ) {
-               $operations = array();
-
-               foreach ( $data as $key => $operation ) {
-                       $operations[$key] = $this->newFromArray( $operation );
-               }
-
-               return $operations;
-       }
-}

-- 
To view, visit https://gerrit.wikimedia.org/r/49492
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I98fe08c7e8bd721be5457e76335907ee099f2db5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to