Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/69297


Change subject: Complexity reduction in ModifyEntity
......................................................................

Complexity reduction in ModifyEntity

Change-Id: Ic2ddb65cf3476c50e66f48d903d1d22476e4ea2c
---
M repo/includes/api/ModifyEntity.php
1 file changed, 44 insertions(+), 26 deletions(-)


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

diff --git a/repo/includes/api/ModifyEntity.php 
b/repo/includes/api/ModifyEntity.php
index 4792033..a89e32e 100644
--- a/repo/includes/api/ModifyEntity.php
+++ b/repo/includes/api/ModifyEntity.php
@@ -2,7 +2,10 @@
 
 namespace Wikibase\Api;
 
-use User, Title, ApiBase;
+use Status;
+use User;
+use Title;
+use ApiBase;
 
 use Wikibase\EntityId;
 use Wikibase\Entity;
@@ -11,7 +14,6 @@
 use Wikibase\ItemHandler;
 use Wikibase\Summary;
 use Wikibase\Utils;
-use Wikibase\Settings;
 
 /**
  * Base class for API modules modifying a single entity identified based on id 
xor a combination of site and page title.
@@ -23,7 +25,6 @@
  * @ingroup API
  *
  * @licence GNU GPL v2+
- * @author Jeroen De Dauw < jeroended...@gmail.com >
  * @author John Erling Blad < jeb...@gmail.com >
  * @author Daniel Kinzler
  */
@@ -198,21 +199,34 @@
                        $summary = new Summary( $this->getModuleName() );
                }
 
-               // if the entity is not up for creation, set the EDIT_UPDATE 
flags
-               if ( !$entityContent->isNew() && ( $this->flags & EDIT_NEW ) 
=== 0 ) {
-                       $this->flags |= EDIT_UPDATE;
-               }
-
-               $this->flags |= ( $user->isAllowed( 'bot' ) && $params['bot'] ) 
? EDIT_FORCE_BOT : 0;
+               $this->addFlags( $entityContent->isNew() );
 
                //NOTE: EDIT_NEW will not be set automatically. If the entity 
doesn't exist, and EDIT_NEW was
                //      not added to $this->flags explicitly, the save will 
fail.
 
                // collect information and create an EditEntity
-               $status = $this->attemptSaveEntity( $entityContent,
+               $status = $this->attemptSaveEntity(
+                       $entityContent,
                        $summary->toString(),
-                       $this->flags );
+                       $this->flags
+               );
 
+               $this->addToOutput( $entityContent, $status );
+
+               wfProfileOut( __METHOD__ );
+       }
+
+       protected function addFlags( $entityContentIsNew ) {
+               // if the entity is not up for creation, set the EDIT_UPDATE 
flags
+               if ( !$entityContentIsNew && ( $this->flags & EDIT_NEW ) === 0 
) {
+                       $this->flags |= EDIT_UPDATE;
+               }
+
+               $params = $this->extractRequestParams();
+               $this->flags |= ( $this->getUser()->isAllowed( 'bot' ) && 
$params['bot'] ) ? EDIT_FORCE_BOT : 0;
+       }
+
+       protected function addToOutput( EntityContent $entityContent, Status 
$status ) {
                $this->getResult()->addValue(
                        'entity',
                        'id', $entityContent->getEntity()->getPrefixedId()
@@ -225,21 +239,10 @@
 
                $this->addRevisionIdFromStatusToResult( 'entity', 'lastrevid', 
$status );
 
+               $params = $this->extractRequestParams();
+
                if ( isset( $params['site'] ) && isset( $params['title'] ) ) {
-                       $normalized = array();
-
-                       $normTitle = Utils::trimToNFC( $params['title'] );
-                       if ( $normTitle !== $params['title'] ) {
-                               $normalized['from'] = $params['title'];
-                               $normalized['to'] = $normTitle;
-                       }
-
-                       if ( $normalized !== array() ) {
-                               $this->getResult()->addValue(
-                                       'entity',
-                                       'normalized', $normalized
-                               );
-                       }
+                       $this->addToAndFromToOutput( $params['title'] );
                }
 
                $this->getResult()->addValue(
@@ -247,8 +250,23 @@
                        'success',
                        1
                );
+       }
 
-               wfProfileOut( __METHOD__ );
+       protected function addToAndFromToOutput( $title ) {
+               $normalized = array();
+
+               $normTitle = Utils::trimToNFC( $title );
+               if ( $normTitle !== $title ) {
+                       $normalized['from'] = $title;
+                       $normalized['to'] = $normTitle;
+               }
+
+               if ( $normalized !== array() ) {
+                       $this->getResult()->addValue(
+                               'entity',
+                               'normalized', $normalized
+                       );
+               }
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic2ddb65cf3476c50e66f48d903d1d22476e4ea2c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to