jenkins-bot has submitted this change and it was merged.

Change subject: Refactor duplicate/misplaced code in SubmitEntityAction
......................................................................


Refactor duplicate/misplaced code in SubmitEntityAction

This does have one effect: Now there is always a patch applied via
getPatchedCopy(). Before this was not done for restore operations. I
believe this is acceptable, depending on how often a restore happens.

Bug: T147631
Change-Id: I05ee6b20a0a237ea6c0a8808c868ee8914d90f49
---
M repo/includes/Actions/EditEntityAction.php
M repo/includes/Actions/SubmitEntityAction.php
2 files changed, 51 insertions(+), 69 deletions(-)

Approvals:
  Thiemo Mättig (WMDE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/includes/Actions/EditEntityAction.php 
b/repo/includes/Actions/EditEntityAction.php
index b034617..47ebb65 100644
--- a/repo/includes/Actions/EditEntityAction.php
+++ b/repo/includes/Actions/EditEntityAction.php
@@ -46,13 +46,10 @@
        private $entityDiffVisualizer;
 
        /**
-        * @var SummaryFormatter
-        */
-       private $summaryFormatter;
-
-       /**
+        * @see Action::__construct
+        *
         * @param Page $page
-        * @param IContextSource $context
+        * @param IContextSource|null $context
         */
        public function __construct( Page $page, IContextSource $context = null 
) {
                parent::__construct( $page, $context );
@@ -66,9 +63,6 @@
                ) );
 
                $wikibaseRepo = WikibaseRepo::getDefaultInstance();
-
-               $this->summaryFormatter = $wikibaseRepo->getSummaryFormatter();
-
                $termLookup = new EntityRetrievingTermLookup( 
$wikibaseRepo->getEntityLookup() );
                $labelDescriptionLookup = new LanguageLabelDescriptionLookup( 
$termLookup, $languageCode );
                $htmlFormatterFactory = 
$wikibaseRepo->getEntityIdHtmlLinkFormatterFactory();
@@ -366,50 +360,6 @@
                $meta = $this->getOutput()->getProperty( 'wikibase-meta-tags' );
 
                return isset( $meta['title'] ) ? $meta['title'] : 
$this->getTitle()->getPrefixedText();
-       }
-
-       /**
-        * Returns an edit summary representing a restore-operation defined by 
the three given revisions.
-        *
-        * @since 0.1
-        *
-        * @param Revision $olderRevision
-        * @param string $userSummary User provided summary
-        *
-        * @return string
-        */
-       protected function makeRestoreSummary( Revision $olderRevision, 
$userSummary = '' ) {
-               $id = $olderRevision->getId();
-               $username = $olderRevision->getUserText();
-
-               $summary = new Summary;
-               $summary->setAction( 'restore' );
-               $summary->addAutoCommentArgs( $id, $username );
-               $summary->setUserSummary( $userSummary );
-
-               return $this->summaryFormatter->formatSummary( $summary );
-       }
-
-       /**
-        * Returns an edit summary representing an undo-operation defined by 
the three given revisions.
-        *
-        * @since 0.1
-        *
-        * @param Revision $newerRevision
-        * @param string $userSummary User provided summary
-        *
-        * @return string
-        */
-       protected function makeUndoSummary( Revision $newerRevision, 
$userSummary = '' ) {
-               $id = $newerRevision->getId();
-               $username = $newerRevision->getUserText();
-
-               $summary = new Summary;
-               $summary->setAction( 'undo' );
-               $summary->addAutoCommentArgs( $id, $username );
-               $summary->setUserSummary( $userSummary );
-
-               return $this->summaryFormatter->formatSummary( $summary );
        }
 
        /**
diff --git a/repo/includes/Actions/SubmitEntityAction.php 
b/repo/includes/Actions/SubmitEntityAction.php
index 8f17de2..46fcc1a 100644
--- a/repo/includes/Actions/SubmitEntityAction.php
+++ b/repo/includes/Actions/SubmitEntityAction.php
@@ -3,11 +3,14 @@
 namespace Wikibase;
 
 use Content;
+use IContextSource;
 use MWException;
+use Page;
 use Revision;
 use Status;
 use Title;
 use WatchAction;
+use Wikibase\Repo\WikibaseRepo;
 use WikiPage;
 
 /**
@@ -23,6 +26,24 @@
  * @author Daniel Kinzler
  */
 class SubmitEntityAction extends EditEntityAction {
+
+       /**
+        * @var SummaryFormatter
+        */
+       private $summaryFormatter;
+
+       /**
+        * @see EditEntityAction::__construct
+        *
+        * @param Page $page
+        * @param IContextSource|null $context
+        */
+       public function __construct( Page $page, IContextSource $context = null 
) {
+               parent::__construct( $page, $context );
+
+               $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+               $this->summaryFormatter = $wikibaseRepo->getSummaryFormatter();
+       }
 
        public function getName() {
                return 'submit';
@@ -103,25 +124,20 @@
                $diff = $newerContent->getDiff( $olderContent );
                $patchedContent = $latestContent->getPatchedCopy( $diff );
 
-               $summary = $request->getText( 'wpSummary' );
-               $editToken = $request->getText( 'wpEditToken' );
+               if ( $patchedContent->equals( $latestContent ) ) {
+                       $status = Status::newGood();
+                       $status->warning( 'wikibase-empty-undo' );
+               } else {
+                       $summary = $request->getText( 'wpSummary' );
 
-               if ( $request->getCheck( 'restore' ) ) { // restore
-                       if ( $patchedContent->equals( $latestContent ) ) {
-                               $status = Status::newGood();
-                               $status->warning( 'wikibase-empty-undo' );
+                       if ( $request->getCheck( 'restore' ) ) {
+                               $summary = $this->makeSummary( 'restore', 
$olderRevision, $summary );
                        } else {
-                               $summary = $this->makeRestoreSummary( 
$olderRevision, $summary );
-                               $status = $this->attemptSave( $title, 
$patchedContent, $summary, $editToken );
+                               $summary = $this->makeSummary( 'undo', 
$newerRevision, $summary );
                        }
-               } else { // undo
-                       if ( $patchedContent->equals( $latestContent ) ) {
-                               $status = Status::newGood();
-                               $status->warning( 'wikibase-empty-undo' );
-                       } else {
-                               $summary = $this->makeUndoSummary( 
$newerRevision, $summary );
-                               $status = $this->attemptSave( $title, 
$patchedContent, $summary, $editToken );
-                       }
+
+                       $editToken = $request->getText( 'wpEditToken' );
+                       $status = $this->attemptSave( $title, $patchedContent, 
$summary, $editToken );
                }
 
                if ( $status->isOK() ) {
@@ -132,6 +148,22 @@
        }
 
        /**
+        * @param string $actionName
+        * @param Revision $revision
+        * @param string $userSummary
+        *
+        * @return string
+        */
+       private function makeSummary( $actionName, Revision $revision, 
$userSummary ) {
+               $summary = new Summary();
+               $summary->setAction( $actionName );
+               $summary->addAutoCommentArgs( $revision->getId(), 
$revision->getUserText() );
+               $summary->setUserSummary( $userSummary );
+
+               return $this->summaryFormatter->formatSummary( $summary );
+       }
+
+       /**
         * @throws MWException
         */
        public function execute() {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I05ee6b20a0a237ea6c0a8808c868ee8914d90f49
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchane...@gmail.com>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to