Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/353060 )

Change subject: Move duplicate code to RecentChangeFactory::getEditCommentMulti
......................................................................

Move duplicate code to RecentChangeFactory::getEditCommentMulti

The motivation for this change is to make the problematic method
RecentChangeFactory::prepareChangeAttributes smaller. The method is
problematic mostly because of the array_merge and the only remaining
usage of ChangeRow::getFields.

Change-Id: Ia542e2febb91bdb38002751796989b546284cf22
---
M client/includes/RecentChanges/RecentChangeFactory.php
1 file changed, 21 insertions(+), 30 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/60/353060/1

diff --git a/client/includes/RecentChanges/RecentChangeFactory.php 
b/client/includes/RecentChanges/RecentChangeFactory.php
index b9c3e6a..722af01 100644
--- a/client/includes/RecentChanges/RecentChangeFactory.php
+++ b/client/includes/RecentChanges/RecentChangeFactory.php
@@ -83,15 +83,6 @@
                $fields = $change->getFields();
                $fields['entity_type'] = 
$change->getEntityId()->getEntityType();
 
-               $info = $change->getInfo();
-               if ( isset( $info['changes'] ) ) {
-                       $changesForComment = $info['changes'];
-               } else {
-                       $changesForComment = array( $change );
-               }
-
-               $comment = $this->getEditCommentMulti( $changesForComment );
-
                unset( $fields['info'] );
                $metadata = array_merge( $fields, $rcinfo );
 
@@ -118,7 +109,7 @@
                return array(
                        'rc_user' => 0,
                        'rc_user_text' => $userText,
-                       'rc_comment' => $comment,
+                       'rc_comment' => $this->getEditCommentMulti( $change ),
                        'rc_type' => RC_EXTERNAL,
                        'rc_minor' => true, // for now, always consider these 
minor
                        'rc_bot' => $isBot,
@@ -179,44 +170,44 @@
                        return null;
                }
 
-               $info = $change->getInfo();
-
-               if ( isset( $info['changes'] ) ) {
-                       $changesForComment = $info['changes'];
-               } else {
-                       $changesForComment = array( $change );
-               }
-
-               return $this->getEditCommentMulti( $changesForComment, $target 
);
+               return $this->getEditCommentMulti( $change, $target );
        }
 
        /**
         * Returns a human readable comment representing the given changes.
         *
-        * @param EntityChange[] $changes
+        * @param EntityChange $change
         * @param Title|null $target The page we create an edit summary for. 
Needed to create an article
         *         specific edit summary on site link changes. Ignored 
otherwise.
         *
         * @throws MWException
         * @return string
         */
-       private function getEditCommentMulti( array $changes, Title $target = 
null ) {
-               $comments = array();
-               $c = 0;
+       private function getEditCommentMulti( EntityChange $change, Title 
$target = null ) {
+               $info = $change->getInfo();
+
+               if ( isset( $info['changes'] ) ) {
+                       if ( $info['changes'] === [] ) {
+                               return '';
+                       }
+
+                       $changes = $info['changes'];
+               } else {
+                       $changes = [ $change ];
+               }
+
+               $comments = [];
 
                foreach ( $changes as $change ) {
-                       $c++;
                        $comments[] = $this->getEditComment( $change, $target );
                }
 
-               if ( $c === 0 ) {
-                       return '';
-               } elseif ( $c === 1 ) {
+               if ( count( $comments ) === 1 ) {
                        return reset( $comments );
-               } else {
-                       //@todo: handle overly long lists nicely!
-                       return $this->language->semicolonList( $comments );
                }
+
+               //@todo: handle overly long lists nicely!
+               return $this->language->semicolonList( $comments );
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia542e2febb91bdb38002751796989b546284cf22
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

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

Reply via email to