TTO has uploaded a new change for review.

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

Change subject: Allow users to apply change tags as they edit using the API
......................................................................

Allow users to apply change tags as they edit using the API

Users can add tags using the tags= parameter to API action=edit. It is
only available to those with the "applychangetags" right (available to
the "user" group by default).

Bug: T20670
Change-Id: I37275e0f73fa3127f55da0c320b892551b61ee80
---
M includes/DefaultSettings.php
M includes/EditPage.php
M includes/api/ApiBase.php
M includes/api/ApiEditPage.php
M includes/page/WikiPage.php
M languages/i18n/en.json
M languages/i18n/qqq.json
7 files changed, 65 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/43/188543/1

diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index e29e70e..96018bc 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -4560,6 +4560,7 @@
 $wgGroupPermissions['user']['minoredit'] = true;
 $wgGroupPermissions['user']['purge'] = true; // can use ?action=purge without 
clicking "ok"
 $wgGroupPermissions['user']['sendemail'] = true;
+$wgGroupPermissions['user']['applychangetags'] = true;
 
 // Implicit group for accounts that pass $wgAutoConfirmAge
 $wgGroupPermissions['autoconfirmed']['autoconfirmed'] = true;
diff --git a/includes/EditPage.php b/includes/EditPage.php
index cb79fd1..539db30 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -351,6 +351,9 @@
        /** @var null|string */
        public $contentFormat = null;
 
+       /** @var array */
+       protected $changeTags = array();
+
        # Placeholders for text injection by hooks (must be HTML)
        # extensions should take care to _append_ to the present value
 
@@ -447,6 +450,25 @@
 
        function submit() {
                $this->edit();
+       }
+
+       /**
+        * Gets the list of change tags to be applied to the revision.
+        *
+        * @return array
+        */
+
+       public function getChangeTags() {
+               return $this->changeTags;
+       }
+
+       /**
+        * Sets the change tags to be applied to the revision.
+        *
+        * @param array $changeTags
+        */
+       public function setChangeTags( $changeTags ) {
+               $this->changeTags = $changeTags;
        }
 
        /**
@@ -1889,7 +1911,8 @@
                        $flags,
                        false,
                        null,
-                       $content->getDefaultFormat()
+                       $content->getDefaultFormat(),
+                       $this->changeTags
                );
 
                if ( !$doEditStatus->isOK() ) {
diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php
index 3a31b2a..dc5f1a9 100644
--- a/includes/api/ApiBase.php
+++ b/includes/api/ApiBase.php
@@ -1791,6 +1791,10 @@
                        'code' => 'contentnotallowedhere',
                        'info' => 'Content model "$1" is not allowed at title 
"$2"'
                ),
+               'cannotapplytags' => array(
+                       'code' => 'cannotapplytags',
+                       'info' => "You don't have permission to apply custom 
tags"
+               ),
 
                // Messages from WikiPage::doEit()
                'edit-hook-aborted' => array(
diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php
index 8ad2ad9..b8e19f5 100644
--- a/includes/api/ApiEditPage.php
+++ b/includes/api/ApiEditPage.php
@@ -244,6 +244,15 @@
                if ( !is_null( $params['md5'] ) && md5( $toMD5 ) !== 
$params['md5'] ) {
                        $this->dieUsageMsg( 'hashcheckfailed' );
                }
+               
+               // Apply change tags
+               $changeTags = array();
+               if ( $user->isAllowed( 'applychangetags' ) ) {
+                       $changeTags = $params['tags'];
+               } else {
+                       // User isn't allowed to apply arbitrary tags. Just 
continue anyway
+                       $this->setWarning( 'You don\'t have permission to set 
change tags. The "tags" parameter will be ignored' );
+               }
 
                // EditPage wants to parse its stuff from a WebRequest
                // That interface kind of sucks, but it's workable
@@ -347,6 +356,7 @@
                $ep->allowNonTextContent = true;
 
                $ep->setContextTitle( $titleObj );
+               $ep->setChangeTags( $changeTags );
                $ep->importFormData( $req );
                $content = $ep->textbox1;
 
@@ -521,6 +531,10 @@
                        ),
                        'text' => null,
                        'summary' => null,
+                       'tags' => array(
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_TYPE => 'string',
+                       ),
                        'minor' => false,
                        'notminor' => false,
                        'bot' => false,
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index a0a3c69..06dac72 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -1672,6 +1672,8 @@
         * @param User $user The user doing the edit
         * @param string $serialFormat Format for storing the content in the
         *   database.
+        * @param string $changeTags Array of change tags to apply to the edit.
+        *   Extensions can modify this array via the PageContentSave hook.
         *
         * @throws MWException
         * @return Status Possible errors:
@@ -1691,7 +1693,7 @@
         * @since 1.21
         */
        public function doEditContent( Content $content, $summary, $flags = 0, 
$baseRevId = false,
-               User $user = null, $serialFormat = null
+               User $user = null, $serialFormat = null, $changeTags = array()
        ) {
                global $wgUser, $wgUseAutomaticEditSummaries, $wgUseRCPatrol, 
$wgUseNPPatrol;
 
@@ -1718,7 +1720,7 @@
 
                // handle hook
                $hook_args = array( &$this, &$user, &$content, &$summary,
-                                                       $flags & EDIT_MINOR, 
null, null, &$flags, &$status );
+                       $flags & EDIT_MINOR, null, null, &$flags, &$status, 
&$changeTags );
 
                if ( !Hooks::run( 'PageContentSave', $hook_args )
                        || !ContentHandler::runLegacyHooks( 'ArticleSave', 
$hook_args ) ) {
@@ -1843,6 +1845,13 @@
                                                        PatrolLog::record( $rc, 
true, $user );
                                                }
                                        }
+
+                                       // Add change tags
+                                       ChangeTags::addTags( $changeTags,
+                                               isset( $rc ) ? 
$rc->mAttribs['rc_id'] : null,
+                                               $revisionId,
+                                               0 );
+
                                        $user->incEditCount();
                                } catch ( Exception $e ) {
                                        $dbw->rollback( __METHOD__ );
@@ -1945,6 +1954,13 @@
                                                PatrolLog::record( $rc, true, 
$user );
                                        }
                                }
+
+                               // Add change tags
+                               ChangeTags::addTags( $changeTags,
+                                       isset( $rc ) ? $rc->mAttribs['rc_id'] : 
null,
+                                       $revisionId,
+                                       0 );
+
                                $user->incEditCount();
 
                        } catch ( Exception $e ) {
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index cff74b4..586ed09 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -1147,6 +1147,7 @@
        "right-sendemail": "Send email to other users",
        "right-passwordreset": "View password reset emails",
        "right-managechangetags": "Create and delete [[Special:Tags|tags]] from 
the database",
+       "right-applychangetags": "Apply and remove arbitrary 
[[Special:Tags|tags]] on individual revisions",
        "newuserlogpage": "User creation log",
        "newuserlogpagetext": "This is a log of user creations.",
        "rightslog": "User rights log",
@@ -1194,6 +1195,7 @@
        "action-editmyprivateinfo": "edit your private information",
        "action-editcontentmodel": "edit the content model of a page",
        "action-managechangetags": "create and delete tags from the database",
+       "action-applychangetags": "apply or remove arbitrary tags on individual 
revisions",
        "nchanges": "$1 {{PLURAL:$1|change|changes}}",
        "enhancedrc-since-last-visit": "$1 {{PLURAL:$1|since last visit}}",
        "enhancedrc-history": "history",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index 5ce194c..2779d21 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -1311,6 +1311,7 @@
        "right-sendemail": "{{doc-right|sendemail}}",
        "right-passwordreset": "{{doc-right|passwordreset}}",
        "right-managechangetags": "{{doc-right|managechangetags}}",
+       "right-applychangetags": "{{doc-right|applychangetags}}",
        "newuserlogpage": "{{doc-logpage}}\n\nPart of the \"Newuserlog\" 
extension. It is both the title of [[Special:Log/newusers]] and the link you 
can see in [[Special:RecentChanges]].",
        "newuserlogpagetext": "Part of the \"Newuserlog\" extension. It is the 
description you can see on [[Special:Log/newusers]].",
        "rightslog": "{{doc-logpage}}\n\nIn [[Special:Log]]",
@@ -1358,6 +1359,7 @@
        "action-editmyprivateinfo": "{{doc-action|editmyprivateinfo}}",
        "action-editcontentmodel": "{{doc-action|editcontentmodel}}",
        "action-managechangetags": "{{doc-action|managechangetags}}",
+       "action-applychangetags": "{{doc-action|applychangetags}}",
        "nchanges": "Appears on enhanced watchlist and recent changes when page 
has more than one change on given date, linking to a diff of the 
changes.\n\nParameters:\n* $1 - the number of changes on that day (2 or 
more)\nThree messages are shown side-by-side: ({{msg-mw|Nchanges}} | 
{{msg-mw|Enhancedrc-since-last-visit}} | {{msg-mw|Enhancedrc-history}}).",
        "enhancedrc-since-last-visit": "Appears on enhanced watchlist and 
recent changes when page has more than one change on given date and at least 
one that the user hasn't seen yet, linking to a diff of the unviewed 
changes.\n\nParameters:\n* $1 - the number of unviewed changes (1 or 
more)\nThree messages are shown side-by-side: ({{msg-mw|nchanges}} | 
{{msg-mw|enhancedrc-since-last-visit}} | {{msg-mw|enhancedrc-history}}).",
        "enhancedrc-history": "Appears on enhanced watchlist and recent changes 
when page has more than one change on given date, linking to its 
history.\n\nThis is the same as {{msg-mw|hist}}, but not abbreviated.\n\nThree 
messages are shown side-by-side: ({{msg-mw|nchanges}} | 
{{msg-mw|enhancedrc-since-last-visit}} | 
{{msg-mw|enhancedrc-history}}).\n{{Identical|History}}",

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

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

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

Reply via email to