Merge "Provide a Taggable interface"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 18 Mar 2019 22:47:44 +0000 (22:47 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 18 Mar 2019 22:47:44 +0000 (22:47 +0000)
RELEASE-NOTES-1.33
autoload.php
includes/changes/RecentChange.php
includes/changetags/Taggable.php [new file with mode: 0644]
includes/logging/LogEntry.php

index bc449c7..d2abed5 100644 (file)
@@ -90,6 +90,7 @@ For notes on 1.32.x and older releases, see HISTORY.
   language where available.
 * Special:ActiveUsers will no longer filter out users who became inactive since
   the last time the active users query cache was updated.
+* (T215675) RecentChange and ManualLogEntry implement new Taggable interface.
 
 === New developer features in 1.33 ===
 * The AuthManagerLoginAuthenticateAudit hook has a new parameter for
@@ -388,6 +389,9 @@ because of Phabricator reports.
   deprecated and will be removed in the future.
 * The FileBasedSiteLookup class has been deprecated. For a cacheable SiteLookup
   implementation, use CachingSiteStore instead.
+* ManualLogEntry::setTags() is deprecated, use ManualLogEntry::addTags()
+  instead. The setTags() method was overriding the tags, addTags() doesn't
+  override, only adds new tags.
 
 === Other changes in 1.33 ===
 * (T201747) Html::openElement() warns if given an element name with a space
index 1c7c34e..8e771a3 100644 (file)
@@ -870,6 +870,7 @@ $wgAutoloadLocalClasses = [
        'MediaWikiSite' => __DIR__ . '/includes/site/MediaWikiSite.php',
        'MediaWikiTitleCodec' => __DIR__ . '/includes/title/MediaWikiTitleCodec.php',
        'MediaWikiVersionFetcher' => __DIR__ . '/includes/MediaWikiVersionFetcher.php',
+       'MediaWiki\\ChangeTags\\Taggable' => __DIR__ . '/includes/changetags/Taggable.php',
        'MediaWiki\\Config\\ConfigRepository' => __DIR__ . '/includes/config/ConfigRepository.php',
        'MediaWiki\\DB\\PatchFileLocation' => __DIR__ . '/includes/db/PatchFileLocation.php',
        'MediaWiki\\Diff\\ComplexityException' => __DIR__ . '/includes/diff/ComplexityException.php',
index 7f7d77d..2d37eac 100644 (file)
@@ -19,6 +19,7 @@
  *
  * @file
  */
+use MediaWiki\ChangeTags\Taggable;
 
 /**
  * Utility class for creating new RC entries
@@ -65,7 +66,7 @@
  *  we're having to include both rc_comment and rc_comment_text/rc_comment_data
  *  so random crap works right.
  */
-class RecentChange {
+class RecentChange implements Taggable {
        // Constants for the rc_source field.  Extensions may also have
        // their own source constants.
        const SRC_EDIT = 'mw.edit';
@@ -1198,7 +1199,7 @@ class RecentChange {
         *
         * @since 1.28
         *
-        * @param string|array $tags
+        * @param string|string[] $tags
         */
        public function addTags( $tags ) {
                if ( is_string( $tags ) ) {
diff --git a/includes/changetags/Taggable.php b/includes/changetags/Taggable.php
new file mode 100644 (file)
index 0000000..f624555
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Interface that defines how to tag objects
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Change tagging
+ * @author Piotr Miazga
+ * @license GPL-2.0-or-later
+ */
+namespace MediaWiki\ChangeTags;
+
+/**
+ * Interface that defines how to tag objects
+ *
+ * @since 1.33
+ */
+interface Taggable {
+
+       /**
+        * Append tags to the tagged object
+        *
+        * @since 1.33
+        * @param string|string[] $tags Tags to apply
+        */
+       public function addTags( $tags );
+
+}
index a154f64..19dcf0d 100644 (file)
  * @since 1.19
  */
 
+use MediaWiki\ChangeTags\Taggable;
 use MediaWiki\Linker\LinkTarget;
 use MediaWiki\User\UserIdentity;
 use Wikimedia\Rdbms\IDatabase;
+use Wikimedia\Assert\Assert;
 
 /**
  * Interface for log entries. Every log entry has these methods.
@@ -436,7 +438,7 @@ class RCDatabaseLogEntry extends DatabaseLogEntry {
  *
  * @since 1.19
  */
-class ManualLogEntry extends LogEntryBase {
+class ManualLogEntry extends LogEntryBase implements Taggable {
        /** @var string Type of log entry */
        protected $type;
 
@@ -586,14 +588,30 @@ class ManualLogEntry extends LogEntryBase {
         *
         * @since 1.27
         * @param string|string[]|null $tags
+        * @deprecated since 1.33 Please use addTags() instead
         */
        public function setTags( $tags ) {
-               if ( $tags === null ) {
-                       $tags = [];
-               } elseif ( is_string( $tags ) ) {
+               if ( $this->tags ) {
+                       wfDebug( 'Overwriting existing ManualLogEntry tags' );
+               }
+               $this->tags = [];
+               if ( $tags !== null ) {
+                       $this->addTags( $tags );
+               }
+       }
+
+       /**
+        * Add change tags for the log entry
+        *
+        * @since 1.33
+        * @param string|string[] $tags Tags to apply
+        */
+       public function addTags( $tags ) {
+               if ( is_string( $tags ) ) {
                        $tags = [ $tags ];
                }
-               $this->tags = $tags;
+               Assert::parameterElementType( 'string', $tags, 'tags' );
+               $this->tags = array_unique( array_merge( $this->tags, $tags ) );
        }
 
        /**