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

Change subject: Support for custom edit summaries
......................................................................


Support for custom edit summaries

Current behavior: <autocomment> <usersummary>|<autosummary>, means
always display the autocomment and replace the autosummary with a
user-provided summary, if given

Bug: 41490
Bug: 50307
Bug: 46537
Bug: 49527

Change-Id: Ia8f988734f69043cb4214653bbf109f4bf271c60
---
M repo/includes/Summary.php
M repo/includes/api/ModifyEntity.php
M repo/tests/phpunit/includes/SummaryTest.php
3 files changed, 68 insertions(+), 5 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  Addshore: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/repo/includes/Summary.php b/repo/includes/Summary.php
index 989aefe..3e007fd 100644
--- a/repo/includes/Summary.php
+++ b/repo/includes/Summary.php
@@ -17,6 +17,7 @@
  * @licence GNU GPL v2+
  * @author John Erling Blad
  * @author Daniel Kinzler
+ * @author Tobias Gritschacher < [email protected] >
  */
 class Summary {
 
@@ -51,6 +52,11 @@
        protected $summaryType;
 
        /**
+        * @var string
+        */
+       protected $userSummary;
+
+       /**
         * indicates a specific type of formatting
         */
        const USE_COMMENT = 2;
@@ -74,6 +80,17 @@
                $this->language = $language === null ? null : (string)$language;
                $this->commentArgs = $commentArgs;
                $this->summaryArgs = $summaryArgs;
+       }
+
+       /**
+        * Set the user provided edit summary
+        *
+        * @since 0.4
+        *
+        * @param string $summary edit summary provided by the user
+        */
+       public function setUserSummary( $summary = null ) {
+               $this->userSummary = $summary === null ? null : 
(string)$summary;
        }
 
        /**
@@ -129,6 +146,17 @@
         */
        public function getActionName() {
                return $this->actionName;
+       }
+
+       /**
+        * Get the user-provided edit summary
+        *
+        * @since 0.4
+        *
+        * @return string|null
+        */
+       public function getUserSummary() {
+               return $this->userSummary;
        }
 
        /**
@@ -369,6 +397,7 @@
         *
         * @param string $comment autocomment part, will be placed in a block 
comment
         * @param string $summary human readable string to be appended after 
the autocomment part
+        * @param string $userSummary optional, individual summary provided by 
the user
         * @param int $length max length of the string
         *
         * @return string to be used for the summary
@@ -403,7 +432,12 @@
         */
        public function toString( $length = SUMMARY_MAX_LENGTH, $format = 
self::USE_ALL ) {
                $count = $this->summaryArgs ? count( $this->summaryArgs ) : 0;
-               $summary = self::formatAutoSummary( $this->summaryArgs );
+
+               if ( !is_null( $this->userSummary ) ) {
+                       $summary = $this->userSummary;
+               } else {
+                       $summary = self::formatAutoSummary( $this->summaryArgs 
);
+               }
 
                $comment = Summary::formatAutoComment(
                        $this->getMessageKey(),
@@ -415,8 +449,8 @@
 
                $normalizer = 
WikibaseRepo::getDefaultInstance()->getStringNormalizer();
 
-               $comment = ( $format & self::USE_COMMENT) ? 
$normalizer->trimToNFC( $comment ) : '';
-               $summary = ( $format & self::USE_SUMMARY) ? 
$normalizer->trimToNFC( $summary ) : '';
+               $comment = ( $format & self::USE_COMMENT ) ? 
$normalizer->trimToNFC( $comment ) : '';
+               $summary = ( $format & self::USE_SUMMARY ) ? 
$normalizer->trimToNFC( $summary ) : '';
 
                $totalSummary = self::formatTotalSummary( $comment, $summary, 
$length );
 
diff --git a/repo/includes/api/ModifyEntity.php 
b/repo/includes/api/ModifyEntity.php
index c502826..9e6bc4a 100644
--- a/repo/includes/api/ModifyEntity.php
+++ b/repo/includes/api/ModifyEntity.php
@@ -6,7 +6,6 @@
 use User;
 use Title;
 use ApiBase;
-
 use Wikibase\EntityId;
 use Wikibase\Entity;
 use Wikibase\EntityContent;
@@ -139,6 +138,9 @@
         */
        protected function createSummary( array $params ) {
                $summary = new Summary( $this->getModuleName() );
+               if ( !is_null( $params['summary'] ) ) {
+                       $summary->setUserSummary( $params['summary'] );
+               }
                return $summary;
        }
 
diff --git a/repo/tests/phpunit/includes/SummaryTest.php 
b/repo/tests/phpunit/includes/SummaryTest.php
index 6d3ddc5..bbd5b36 100644
--- a/repo/tests/phpunit/includes/SummaryTest.php
+++ b/repo/tests/phpunit/includes/SummaryTest.php
@@ -130,7 +130,7 @@
        /**
         * @dataProvider provideToString
         */
-       public function testToString( $module, $action, $language, 
$commentArgs, $summaryArgs, $expected ) {
+       public function testToString( $module, $action, $language, 
$commentArgs, $summaryArgs, $userSummary, $expected ) {
                $summary = new Summary( $module );
 
                if ( $action !== null ) {
@@ -149,6 +149,10 @@
                        $summary->addAutoSummaryArgs( $summaryArgs );
                }
 
+               if ( $userSummary !== null ) {
+                       $summary->setUserSummary( $userSummary );
+               }
+
                $this->assertEquals( $expected, $summary->toString() );
        }
 
@@ -156,6 +160,7 @@
                return array(
                        array( // #0
                                'summarytest',
+                               null,
                                null,
                                null,
                                null,
@@ -168,6 +173,7 @@
                                'nl',
                                null,
                                null,
+                               null,
                                '/* summarytest-testing:0|nl */'
                        ),
                        array( // #2
@@ -175,6 +181,7 @@
                                null,
                                null,
                                array( 'x' ),
+                               null,
                                null,
                                '/* summarytest:0||x */'
                        ),
@@ -184,6 +191,7 @@
                                'nl',
                                array( 'x', 'y' ),
                                array( 'A', 'B'),
+                               null,
                                '/* summarytest-testing:2|nl|x|y */ A, B'
                        ),
                        array( // #4
@@ -192,8 +200,27 @@
                                null,
                                null,
                                array( 'A', 'B' ),
+                               null,
                                '/* summarytest:2| */ A, B'
                        ),
+                       array( // #5
+                               'summarytest',
+                               'testing',
+                               'nl',
+                               array( 'x', 'y' ),
+                               array( 'A', 'B'),
+                               'can I haz world domination?',
+                               '/* summarytest-testing:2|nl|x|y */ can I haz 
world domination?'
+                               ),
+                       array( // #6
+                               'summarytest',
+                               null,
+                               null,
+                               null,
+                               null,
+                               'can I haz world domination?',
+                               '/* summarytest:0| */ can I haz world 
domination?'
+                               ),
                );
        }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia8f988734f69043cb4214653bbf109f4bf271c60
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to