Merge "Turn off "reportDupes" in CachedBagOStuff"
[lhc/web/wiklou.git] / includes / logging / LogEntry.php
index ddcb636..7746d99 100644 (file)
@@ -168,27 +168,27 @@ class DatabaseLogEntry extends LogEntryBase {
         * @return array
         */
        public static function getSelectQueryData() {
-               $tables = array( 'logging', 'user' );
-               $fields = array(
+               $tables = [ 'logging', 'user' ];
+               $fields = [
                        'log_id', 'log_type', 'log_action', 'log_timestamp',
                        'log_user', 'log_user_text',
                        'log_namespace', 'log_title', // unused log_page
                        'log_comment', 'log_params', 'log_deleted',
                        'user_id', 'user_name', 'user_editcount',
-               );
+               ];
 
-               $joins = array(
+               $joins = [
                        // IPs don't have an entry in user table
-                       'user' => array( 'LEFT JOIN', 'log_user=user_id' ),
-               );
+                       'user' => [ 'LEFT JOIN', 'log_user=user_id' ],
+               ];
 
-               return array(
+               return [
                        'tables' => $tables,
                        'fields' => $fields,
-                       'conds' => array(),
-                       'options' => array(),
+                       'conds' => [],
+                       'options' => [],
                        'join_conds' => $joins,
-               );
+               ];
        }
 
        /**
@@ -399,10 +399,10 @@ class ManualLogEntry extends LogEntryBase {
        protected $subtype;
 
        /** @var array Parameters for log entry */
-       protected $parameters = array();
+       protected $parameters = [];
 
        /** @var array */
-       protected $relations = array();
+       protected $relations = [];
 
        /** @var User Performer of the action for the log entry */
        protected $performer;
@@ -419,12 +419,18 @@ 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 int Deletion state of the log entry */
        protected $deleted;
 
        /** @var int ID of the log entry */
        protected $id;
 
+       /** @var Can this log entry be patrolled? */
+       protected $isPatrollable = false;
+
        /** @var bool Whether this is a legacy log entry */
        protected $legacy = false;
 
@@ -529,6 +535,32 @@ class ManualLogEntry extends LogEntryBase {
                $this->revId = $revId;
        }
 
+       /**
+        * 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;
+       }
+
+       /**
+        * Set whether this log entry should be made patrollable
+        * This shouldn't depend on config, only on whether there is full support
+        * in the software for patrolling this log entry.
+        * False by default
+        *
+        * @since 1.27
+        * @param bool $patrollable
+        */
+       public function setIsPatrollable( $patrollable ) {
+               $this->isPatrollable = (bool)$patrollable;
+       }
+
        /**
         * Set the 'legacy' flag
         *
@@ -582,7 +614,7 @@ class ManualLogEntry extends LogEntryBase {
                        $relations['associated_rev_id'] = $revId;
                }
 
-               $data = array(
+               $data = [
                        'log_id' => $id,
                        'log_type' => $this->getType(),
                        'log_action' => $this->getSubtype(),
@@ -594,7 +626,7 @@ class ManualLogEntry extends LogEntryBase {
                        'log_page' => $this->getTarget()->getArticleID(),
                        'log_comment' => $comment,
                        'log_params' => LogEntryBase::makeParamBlob( $params ),
-               );
+               ];
                if ( isset( $this->deleted ) ) {
                        $data['log_deleted'] = $this->deleted;
                }
@@ -602,22 +634,22 @@ class ManualLogEntry extends LogEntryBase {
                $dbw->insert( 'logging', $data, __METHOD__ );
                $this->id = !is_null( $id ) ? $id : $dbw->insertId();
 
-               $rows = array();
+               $rows = [];
                foreach ( $relations as $tag => $values ) {
                        if ( !strlen( $tag ) ) {
                                throw new MWException( "Got empty log search tag." );
                        }
 
                        if ( !is_array( $values ) ) {
-                               $values = array( $values );
+                               $values = [ $values ];
                        }
 
                        foreach ( $values as $value ) {
-                               $rows[] = array(
+                               $rows[] = [
                                        'ls_field' => $tag,
                                        'ls_value' => $value,
                                        'ls_log_id' => $this->id
-                               );
+                               ];
                        }
                }
                if ( count( $rows ) ) {
@@ -663,7 +695,8 @@ class ManualLogEntry extends LogEntryBase {
                        LogEntryBase::makeParamBlob( $this->getParameters() ),
                        $newId,
                        $formatter->getIRCActionComment(), // Used for IRC feeds
-                       $this->getAssociatedRevId() // Used for e.g. moves and uploads
+                       $this->getAssociatedRevId(), // Used for e.g. moves and uploads
+                       $this->getIsPatrollable()
                );
        }
 
@@ -672,31 +705,41 @@ class ManualLogEntry extends LogEntryBase {
         *
         * @param int $newId Id of the log entry.
         * @param string $to One of: rcandudp (default), rc, udp
-        * @return RecentChange|null
         */
        public function publish( $newId, $to = 'rcandudp' ) {
-               $log = new LogPage( $this->getType() );
-               if ( $log->isRestricted() ) {
-                       return null;
-               }
-
-               $rc = $this->getRecentChange( $newId );
-
-               if ( $to === 'rc' || $to === 'rcandudp' ) {
-                       $rc->save( 'pleasedontudp' );
-               }
-
-               if ( $to === 'udp' || $to === 'rcandudp' ) {
-                       $rc->notifyRCFeeds();
-               }
-
-               // Log the autopatrol if an associated rev id was passed
-               if ( $this->getAssociatedRevId() > 0 &&
-                       $rc->getAttribute( 'rc_patrolled' ) === 1 ) {
-                       PatrolLog::record( $rc, true, $this->getPerformer() );
-               }
-
-               return $rc;
+               DeferredUpdates::addCallableUpdate(
+                       function () use ( $newId, $to ) {
+                               $log = new LogPage( $this->getType() );
+                               if ( !$log->isRestricted() ) {
+                                       $rc = $this->getRecentChange( $newId );
+
+                                       if ( $to === 'rc' || $to === 'rcandudp' ) {
+                                               $rc->save( 'pleasedontudp' );
+                                       }
+
+                                       if ( $to === 'udp' || $to === 'rcandudp' ) {
+                                               $rc->notifyRCFeeds();
+                                       }
+
+                                       // Log the autopatrol if the log entry is patrollable
+                                       if ( $this->getIsPatrollable() &&
+                                               $rc->getAttribute( 'rc_patrolled' ) === 1
+                                       ) {
+                                               PatrolLog::record( $rc, true, $this->getPerformer() );
+                                       }
+
+                                       // Add change tags to the log entry and (if applicable) the associated revision
+                                       $tags = $this->getTags();
+                                       if ( !is_null( $tags ) ) {
+                                               $rcId = $rc->getAttribute( 'rc_id' );
+                                               $revId = $this->getAssociatedRevId(); // Use null if $revId is 0
+                                               ChangeTags::addTags( $tags, $rcId, $revId > 0 ? $revId : null, $newId );
+                                       }
+                               }
+                       },
+                       DeferredUpdates::POSTSEND,
+                       wfGetDB( DB_MASTER )
+               );
        }
 
        public function getType() {
@@ -743,6 +786,24 @@ class ManualLogEntry extends LogEntryBase {
                return $this->revId;
        }
 
+       /**
+        * @since 1.27
+        * @return array
+        */
+       public function getTags() {
+               return $this->tags;
+       }
+
+       /**
+        * Whether this log entry is patrollable
+        *
+        * @since 1.27
+        * @return bool
+        */
+       public function getIsPatrollable() {
+               return $this->isPatrollable;
+       }
+
        /**
         * @since 1.25
         * @return bool