Do SearchUpdate::indexTitle after search-update is supported check
[lhc/web/wiklou.git] / includes / deferred / LinksUpdate.php
index b96fa46..c253e74 100644 (file)
@@ -77,6 +77,11 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
         */
        private $linkDeletions = null;
 
+       /**
+        * @var User|null
+        */
+       private $user;
+
        /**
         * Constructor
         *
@@ -85,25 +90,16 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
         * @param bool $recursive Queue jobs for recursive updates?
         * @throws MWException
         */
-       function __construct( $title, $parserOutput, $recursive = true ) {
+       function __construct( Title $title, ParserOutput $parserOutput, $recursive = true ) {
                parent::__construct( false ); // no implicit transaction
 
-               if ( !( $title instanceof Title ) ) {
-                       throw new MWException( "The calling convention to LinksUpdate::LinksUpdate() has changed. " .
-                               "Please see Article::editUpdates() for an invocation example.\n" );
-               }
-
-               if ( !( $parserOutput instanceof ParserOutput ) ) {
-                       throw new MWException( "The calling convention to LinksUpdate::__construct() has changed. " .
-                               "Please see WikiPage::doEditUpdates() for an invocation example.\n" );
-               }
-
                $this->mTitle = $title;
                $this->mId = $title->getArticleID();
 
                if ( !$this->mId ) {
-                       throw new MWException( "The Title object did not provide an article " .
-                               "ID. Perhaps the page doesn't exist?" );
+                       throw new InvalidArgumentException(
+                               "The Title object yields no ID. Perhaps the page doesn't exist?"
+                       );
                }
 
                $this->mParserOutput = $parserOutput;
@@ -149,7 +145,11 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
        public function doUpdate() {
                Hooks::run( 'LinksUpdate', array( &$this ) );
                $this->doIncrementalUpdate();
-               Hooks::run( 'LinksUpdateComplete', array( &$this ) );
+
+               $that = $this;
+               $this->mDb->onTransactionIdle( function() use ( $that ) {
+                       Hooks::run( 'LinksUpdateComplete', array( &$that ) );
+               } );
        }
 
        protected function doIncrementalUpdate() {
@@ -276,7 +276,7 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
                // Which ever runs first generally no-ops the other one.
                $jobs = array();
                foreach ( $bc->getCascadeProtectedLinks() as $title ) {
-                       $jobs[] = new RefreshLinksJob( $title, array( 'prioritize' => true ) );
+                       $jobs[] = RefreshLinksJob::newPrioritized( $title, array() );
                }
                JobQueueGroup::singleton()->push( $jobs );
        }
@@ -916,6 +916,24 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
                $this->mRevision = $revision;
        }
 
+       /**
+        * Set the User who triggered this LinksUpdate
+        *
+        * @since 1.27
+        * @param User $user
+        */
+       public function setTriggeringUser( User $user ) {
+               $this->user = $user;
+       }
+
+       /**
+        * @since 1.27
+        * @return null|User
+        */
+       public function getTriggeringUser() {
+               return $this->user;
+       }
+
        /**
         * Invalidate any necessary link lists related to page property changes
         * @param array $changed
@@ -930,8 +948,7 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
                                        $inv = array( $inv );
                                }
                                foreach ( $inv as $table ) {
-                                       $update = new HTMLCacheUpdate( $this->mTitle, $table );
-                                       $update->doUpdate();
+                                       DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->mTitle, $table ) );
                                }
                        }
                }
@@ -989,14 +1006,31 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
        }
 
        public function getAsJobSpecification() {
+               if ( $this->user ) {
+                       $userInfo = array(
+                               'userId' => $this->user->getId(),
+                               'userName' => $this->user->getName(),
+                       );
+               } else {
+                       $userInfo = false;
+               }
+
+               if ( $this->mRevision ) {
+                       $triggeringRevisionId = $this->mRevision->getId();
+               } else {
+                       $triggeringRevisionId = false;
+               }
+
                return array(
                        'wiki' => $this->mDb->getWikiID(),
                        'job'  => new JobSpecification(
-                               'refreshLinks',
+                               'refreshLinksPrioritized',
                                array(
-                                       'prioritize' => true,
                                        // Reuse the parser cache if it was saved
-                                       'rootJobTimestamp' => $this->mParserOutput->getCacheTime()
+                                       'rootJobTimestamp' => $this->mParserOutput->getCacheTime(),
+                                       'useRecursiveLinksUpdate' => $this->mRecursive,
+                                       'triggeringUser' => $userInfo,
+                                       'triggeringRevisionId' => $triggeringRevisionId,
                                ),
                                array( 'removeDuplicates' => true ),
                                $this->getTitle()