Merge "logging: Start using LinkTarget & UserIdentity in ManualLogEntry"
[lhc/web/wiklou.git] / includes / logging / LogEntry.php
index b53a486..35f1a06 100644 (file)
@@ -28,6 +28,8 @@
  * @since 1.19
  */
 
+use MediaWiki\Linker\LinkTarget;
+use MediaWiki\User\UserIdentity;
 use Wikimedia\Rdbms\IDatabase;
 
 /**
@@ -462,8 +464,8 @@ class ManualLogEntry extends LogEntryBase {
        /** @var int A rev id associated to the log entry */
        protected $revId = 0;
 
-       /** @var array Change tags add to the log entry */
-       protected $tags = null;
+       /** @var string[] Change tags add to the log entry */
+       protected $tags = [];
 
        /** @var int Deletion state of the log entry */
        protected $deleted;
@@ -527,20 +529,20 @@ class ManualLogEntry extends LogEntryBase {
         * Set the user that performed the action being logged.
         *
         * @since 1.19
-        * @param User $performer
+        * @param UserIdentity $performer
         */
-       public function setPerformer( User $performer ) {
-               $this->performer = $performer;
+       public function setPerformer( UserIdentity $performer ) {
+               $this->performer = User::newFromIdentity( $performer );
        }
 
        /**
         * Set the title of the object changed.
         *
         * @since 1.19
-        * @param Title $target
+        * @param LinkTarget $target
         */
-       public function setTarget( Title $target ) {
-               $this->target = $target;
+       public function setTarget( LinkTarget $target ) {
+               $this->target = Title::newFromLinkTarget( $target );
        }
 
        /**
@@ -579,11 +581,16 @@ class ManualLogEntry extends LogEntryBase {
        /**
         * Set change tags for the log entry.
         *
+        * Passing `null` means the same as empty array,
+        * for compatibility with WikiPage::doUpdateRestrictions().
+        *
         * @since 1.27
-        * @param string|string[] $tags
+        * @param string|string[]|null $tags
         */
        public function setTags( $tags ) {
-               if ( is_string( $tags ) ) {
+               if ( $tags === null ) {
+                       $tags = [];
+               } elseif ( is_string( $tags ) ) {
                        $tags = [ $tags ];
                }
                $this->tags = $tags;
@@ -645,7 +652,7 @@ class ManualLogEntry extends LogEntryBase {
                $relations = $this->relations;
 
                // Ensure actor relations are set
-               if ( $wgActorTableSchemaMigrationStage >= MIGRATION_WRITE_BOTH &&
+               if ( ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) &&
                        empty( $relations['target_author_actor'] )
                ) {
                        $actorIds = [];
@@ -664,7 +671,7 @@ class ManualLogEntry extends LogEntryBase {
                                $params['authorActors'] = $actorIds;
                        }
                }
-               if ( $wgActorTableSchemaMigrationStage >= MIGRATION_WRITE_NEW ) {
+               if ( !( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_OLD ) ) {
                        unset( $relations['target_author_id'], $relations['target_author_ip'] );
                        unset( $params['authorIds'], $params['authorIPs'] );
                }
@@ -776,11 +783,7 @@ class ManualLogEntry extends LogEntryBase {
 
                                        if ( $to === 'rc' || $to === 'rcandudp' ) {
                                                // save RC, passing tags so they are applied there
-                                               $tags = $this->getTags();
-                                               if ( is_null( $tags ) ) {
-                                                       $tags = [];
-                                               }
-                                               $rc->addTags( $tags );
+                                               $rc->addTags( $this->getTags() );
                                                $rc->save( $rc::SEND_NONE );
                                        }
 
@@ -840,7 +843,7 @@ class ManualLogEntry extends LogEntryBase {
 
        /**
         * @since 1.27
-        * @return array
+        * @return string[]
         */
        public function getTags() {
                return $this->tags;