Sn1per has uploaded a new change for review.

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

Change subject: Add tags support to ApiProtect
......................................................................

Add tags support to ApiProtect

WikiPage::doUpdateRestrictions updated to return protection log ID
in Status::$value so that a tag can be added to the log entry.

Bug: T97720
Change-Id: I98c52da7985623bfdafda2dc2dae937b39b72419
---
M includes/api/ApiProtect.php
M includes/api/i18n/en.json
M includes/api/i18n/qqq.json
M includes/page/WikiPage.php
4 files changed, 26 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/85/266185/1

diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php
index d07301c..20840cf 100644
--- a/includes/api/ApiProtect.php
+++ b/includes/api/ApiProtect.php
@@ -55,6 +55,15 @@
                        }
                }
 
+               // If change tagging was requested, check that the user is 
allowed to tag,
+               // and the tags are valid
+               if ( count( $params['tags'] ) ) {
+                       $tagStatus = ChangeTags::canAddTagsAccompanyingChange( 
$params['tags'], $user );
+                       if ( !$tagStatus->isOK() ) {
+                               $this->dieStatus( $tagStatus );
+                       }
+               }
+
                $restrictionTypes = $titleObj->getRestrictionTypes();
 
                $protections = array();
@@ -114,6 +123,12 @@
                if ( !$status->isOK() ) {
                        $this->dieStatus( $status );
                }
+
+               // Apply change tags to the log entry, if requested
+               if ( count( $params['tags'] ) ) {
+                       ChangeTags::addTags( $params['tags'], null, null, 
$status->value, null );
+               }
+
                $res = array(
                        'title' => $titleObj->getPrefixedText(),
                        'reason' => $params['reason']
@@ -153,6 +168,10 @@
                                ApiBase::PARAM_DFLT => 'infinite',
                        ),
                        'reason' => '',
+                       'tags' => array(
+                               ApiBase::PARAM_TYPE => 'tags',
+                               ApiBase::PARAM_ISMULTI => true,
+                       ),
                        'cascade' => false,
                        'watch' => array(
                                ApiBase::PARAM_DFLT => false,
diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json
index 2fb9a50..5236ba6 100644
--- a/includes/api/i18n/en.json
+++ b/includes/api/i18n/en.json
@@ -342,6 +342,7 @@
        "apihelp-protect-param-protections": "List of protection levels, 
formatted <kbd>action=level</kbd> (e.g. 
<kbd>edit=sysop</kbd>).\n\n<strong>Note:</strong> Any actions not listed will 
have restrictions removed.",
        "apihelp-protect-param-expiry": "Expiry timestamps. If only one 
timestamp is set, it'll be used for all protections. Use <kbd>infinite</kbd>, 
<kbd>indefinite</kbd>, <kbd>infinity</kbd>, or <kbd>never</kbd>, for a 
never-expiring protection.",
        "apihelp-protect-param-reason": "Reason for (un)protecting.",
+       "apihelp-protect-param-tags": "Change tags to apply to the entry in the 
protection log.",
        "apihelp-protect-param-cascade": "Enable cascading protection (i.e. 
protect transcluded templates and images used in this page). Ignored if none of 
the given protection levels support cascading.",
        "apihelp-protect-param-watch": "If set, add the page being 
(un)protected to the current user's watchlist.",
        "apihelp-protect-param-watchlist": "Unconditionally add or remove the 
page from the current user's watchlist, use preferences or do not change 
watch.",
diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json
index 804a8d6..9ddfb0a 100644
--- a/includes/api/i18n/qqq.json
+++ b/includes/api/i18n/qqq.json
@@ -324,6 +324,7 @@
        "apihelp-protect-param-protections": 
"{{doc-apihelp-param|protect|protections}}",
        "apihelp-protect-param-expiry": "{{doc-apihelp-param|protect|expiry}}",
        "apihelp-protect-param-reason": "{{doc-apihelp-param|protect|reason}}",
+       "apihelp-protect-param-tags": "{{doc-apihelp-param|protect|tags}}",
        "apihelp-protect-param-cascade": 
"{{doc-apihelp-param|protect|cascade}}",
        "apihelp-protect-param-watch": "{{doc-apihelp-param|protect|watch}}",
        "apihelp-protect-param-watchlist": 
"{{doc-apihelp-param|protect|watchlist}}",
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 6f4c296..4f66273 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -2373,7 +2373,8 @@
         * @param int &$cascade Set to false if cascading protection isn't 
allowed.
         * @param string $reason
         * @param User $user The user updating the restrictions
-        * @return Status
+        * @return Status Status object; if successful, $status->value is the 
log_id of the
+        *   deletion log entry.
         */
        public function doUpdateRestrictions( array $limit, array $expiry,
                &$cascade, $reason, User $user
@@ -2607,7 +2608,9 @@
                $logId = $logEntry->insert();
                $logEntry->publish( $logId );
 
-               return Status::newGood();
+               $status = Status::newGood();
+               $status->value = $logId;
+               return $status;
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I98c52da7985623bfdafda2dc2dae937b39b72419
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Sn1per <[email protected]>

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

Reply via email to