Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / includes / logging / LogEntry.php
index 1d0a543..21864ee 100644 (file)
@@ -428,6 +428,9 @@ class ManualLogEntry extends LogEntryBase {
        /** @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;
 
@@ -545,6 +548,19 @@ class ManualLogEntry extends LogEntryBase {
                $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
         *
@@ -679,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()
                );
        }
 
@@ -688,39 +705,39 @@ 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() );
-               }
-
-               // 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 );
-               }
-
-               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' ) {
+                                               // save RC, passing tags so they are applied there
+                                               $tags = $this->getTags();
+                                               if ( is_null( $tags ) ) {
+                                                       $tags = [];
+                                               }
+                                               $rc->addTags( $tags );
+                                               $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() );
+                                       }
+                               }
+                       },
+                       DeferredUpdates::POSTSEND,
+                       wfGetDB( DB_MASTER )
+               );
        }
 
        public function getType() {
@@ -775,6 +792,16 @@ class ManualLogEntry extends LogEntryBase {
                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