Georggi199 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/330133 )

Change subject: Add tags support to FlaggedRevs extension
......................................................................

Add tags support to FlaggedRevs extension

Bug: T97720
Change-Id: Ic40bf9928fcb723bcf81b2b1d2df6a64d43243c2
---
M api/actions/ApiReview.php
M backend/FlaggedRevsLog.php
M business/RevisionReviewForm.php
M i18n/api/en.json
M i18n/api/qqq.json
5 files changed, 49 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FlaggedRevs 
refs/changes/33/330133/1

diff --git a/api/actions/ApiReview.php b/api/actions/ApiReview.php
index 6f3aa71..cc1aeb9 100644
--- a/api/actions/ApiReview.php
+++ b/api/actions/ApiReview.php
@@ -53,6 +53,16 @@
                        }
                }
 
+               $tags = $params['tags'];
+
+               // Check if user can add tags
+               if ( !is_null( $tags ) ) {
+                       $ableToTag = ChangeTags::canAddTagsAccompanyingChange( 
$tags, $wgUser );
+                       if ( !$ableToTag->isOK() ) {
+                               $this->dieStatus( $ableToTag );
+                       }
+               }
+
                // Get target rev and title
                $revid = (int)$params['revid'];
                $rev = Revision::newFromId( $revid );
@@ -210,7 +220,11 @@
                        'revid'         => null,
                        'token'         => null,
                        'comment'       => null,
-                       'unapprove' => false
+                       'unapprove' => false,
+                       'tags' => [
+                               ApiBase::PARAM_TYPE => 'tags',
+                               ApiBase::PARAM_ISMULTI => true
+                       ]
                );
                if ( !FlaggedRevs::binaryFlagging() ) {
                        /** @todo Once support for MediaWiki < 1.25 is dropped, 
just use ApiBase::PARAM_HELP_MSG directly */
@@ -234,7 +248,8 @@
                        'revid'         => 'The revision ID for which to set 
the flags',
                        'token'         => 'An edit token retrieved through 
prop=info',
                        'comment'       => 'Comment for the review (optional)',
-                       'unapprove' => 'If set, revision will be unapproved 
rather than approved.'
+                       'unapprove' => 'If set, revision will be unapproved 
rather than approved.',
+                       'tags'          => 'Array of change tags to add to the 
log entry'
                );
                if ( !FlaggedRevs::binaryFlagging() ) {
                        foreach ( FlaggedRevs::getTags() as $flagname ) {
diff --git a/backend/FlaggedRevsLog.php b/backend/FlaggedRevsLog.php
index 5c44b5e..37357ef 100644
--- a/backend/FlaggedRevsLog.php
+++ b/backend/FlaggedRevsLog.php
@@ -12,10 +12,11 @@
         * @param bool $approve, approved? (otherwise unapproved)
         * @param bool $auto
         * @param User $user performing the action
+        * @param array $tags
         */
        public static function updateReviewLog(
                Title $title, array $dims, array $oldDims,
-               $comment, $revId, $stableId, $approve, $auto = false, $user
+               $comment, $revId, $stableId, $approve, $auto = false, $user, 
$tags
        ) {
                # Tag rating list (e.g. accuracy=x, depth=y, style=z)
                $ratings = array();
@@ -62,6 +63,9 @@
                $logEntry->setPerformer( $user );
                $logEntry->setTarget( $title );
                $logEntry->setComment( $comment );
+               if ( count( $tags ) ) {
+                       $logEntry->setTags( $tags );
+               }
 
                # Param format is <rev id, old stable id, rev timestamp>
                $logEntry->setParameters( array( $revId, $stableId, $ts ) );
diff --git a/business/RevisionReviewForm.php b/business/RevisionReviewForm.php
index 2036b09..37a661b 100644
--- a/business/RevisionReviewForm.php
+++ b/business/RevisionReviewForm.php
@@ -25,6 +25,8 @@
        protected $dims = array();              # Review flags (for approval)
        protected $lastChangeTime = null;       # Conflict handling
        protected $newLastChangeTime = null;    # Conflict handling
+       /** @var array Change tags add to the log entry */
+       protected $tags = null;
 
        protected $oldFrev = null;              # Prior FlaggedRevision for Rev 
with ID $oldid
        protected $oldFlags = array();          # Prior flags for Rev with ID 
$oldid
@@ -139,6 +141,27 @@
 
        public function bypassValidationKey() {
                $this->skipValidationKey = true;
+       }
+
+       /**
+        * Set change tags for the log entry.
+        *
+        * @since 1.27
+        * @param string|string[] $tags
+        */
+       public function setTags( $tags ) {
+               if ( is_string( $tags ) ) {
+                       $tags = [ $tags ];
+               }
+               $this->tags = $tags;
+       }
+
+       /**
+        * @since 1.27
+        * @return array
+        */
+       public function getTags() {
+               return $this->tags;
        }
 
        /**
@@ -466,7 +489,7 @@
                # Update the article review log...
                $oldSvId = $oldSv ? $oldSv->getRevId() : 0;
                FlaggedRevsLog::updateReviewLog( $this->page, $this->dims, 
$this->oldFlags,
-                       $this->comment, $this->oldid, $oldSvId, true, false, 
$this->user );
+                       $this->comment, $this->oldid, $oldSvId, true, false, 
$this->user, $this->tags );
 
                # Get the new stable version as of now
                $sv = FlaggedRevision::determineStable( $this->page, FR_MASTER 
/*consistent*/ );
@@ -502,7 +525,7 @@
                # Update the article review log
                $svId = $sv ? $sv->getRevId() : 0;
                FlaggedRevsLog::updateReviewLog( $this->page, $this->dims, 
$this->oldFlags,
-                       $this->comment, $this->oldid, $svId, false, false, 
$this->user );
+                       $this->comment, $this->oldid, $svId, false, false, 
$this->user, $this->tags );
 
                # Update recent changes
                self::updateRecentChanges( $frev->getRevision(), 'unpatrol', 
$sv );
diff --git a/i18n/api/en.json b/i18n/api/en.json
index b32240e..23917d3 100644
--- a/i18n/api/en.json
+++ b/i18n/api/en.json
@@ -51,6 +51,7 @@
        "apihelp-review-param-revid": "The revision ID for which to set the 
flags.",
        "apihelp-review-param-comment": "Comment for the review.",
        "apihelp-review-param-unapprove": "If set, revision will be unapproved 
rather than approved.",
+       "apihelp-review-param-tags": "Change tags to apply to the entry in the 
review log.",
        "apihelp-review-param-flag": "Set the flag ''$1'' to the specified 
value.",
        "apihelp-review-example-1": "Approve revision 12345 with comment 
\"Ok\"",
        "apihelp-reviewactivity-description": "Advertise or de-advertise 
yourself as reviewing an unreviewed page or unreviewed changes.",
diff --git a/i18n/api/qqq.json b/i18n/api/qqq.json
index 280dddd..b84f04f 100644
--- a/i18n/api/qqq.json
+++ b/i18n/api/qqq.json
@@ -54,6 +54,7 @@
        "apihelp-review-param-revid": "{{doc-apihelp-param|review|revid}}",
        "apihelp-review-param-comment": "{{doc-apihelp-param|review|comment}}",
        "apihelp-review-param-unapprove": 
"{{doc-apihelp-param|review|unapprove}}",
+       "apihelp-review-param-tags": "{{doc-apihelp-param|review|tags}}",
        "apihelp-review-param-flag": 
"{{doc-apihelp-param|review|flag|description=parameters beginning \"flag_\" to 
the \"review\" module}}",
        "apihelp-review-example-1": "{{doc-apihelp-example|review}}",
        "apihelp-reviewactivity-description": 
"{{doc-apihelp-description|reviewactivity}}",

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic40bf9928fcb723bcf81b2b1d2df6a64d43243c2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/FlaggedRevs
Gerrit-Branch: master
Gerrit-Owner: Georggi199 <bmp2...@gmail.com>

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

Reply via email to