Update cached user ID after user is added to the database
[lhc/web/wiklou.git] / includes / deferred / LinksUpdate.php
index d1386c6..dbfdab0 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;
@@ -276,7 +272,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 +912,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
@@ -989,11 +1003,32 @@ 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',
-                               array( 'prioritize' => true ),
+                               'refreshLinksPrioritized',
+                               array(
+                                       // Reuse the parser cache if it was saved
+                                       'rootJobTimestamp' => $this->mParserOutput->getCacheTime(),
+                                       'useRecursiveLinksUpdate' => $this->mRecursive,
+                                       'triggeringUser' => $userInfo,
+                                       'triggeringRevisionId' => $triggeringRevisionId,
+                               ),
                                array( 'removeDuplicates' => true ),
                                $this->getTitle()
                        )