Merge "Replace strlen() calls with strict string comparisons"
[lhc/web/wiklou.git] / includes / deferred / LinksUpdate.php
index 101a1e2..14f86b7 100644 (file)
@@ -32,7 +32,7 @@ use Wikimedia\ScopedCallback;
  *
  * See docs/deferred.txt
  */
-class LinksUpdate extends DataUpdate {
+class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate {
        // @todo make members protected, but make sure extensions don't break
 
        /** @var int Page ID of the article linked from */
@@ -122,7 +122,11 @@ class LinksUpdate extends DataUpdate {
                parent::__construct();
 
                $this->mTitle = $title;
-               $this->mId = $title->getArticleID( Title::GAID_FOR_UPDATE );
+
+               if ( !$this->mId ) {
+                       // NOTE: subclasses may initialize mId before calling this constructor!
+                       $this->mId = $title->getArticleID( Title::GAID_FOR_UPDATE );
+               }
 
                if ( !$this->mId ) {
                        throw new InvalidArgumentException(
@@ -1180,11 +1184,46 @@ class LinksUpdate extends DataUpdate {
        /**
         * @return IDatabase
         */
-       private function getDB() {
+       protected function getDB() {
                if ( !$this->db ) {
                        $this->db = wfGetDB( DB_MASTER );
                }
 
                return $this->db;
        }
+
+       public function getAsJobSpecification() {
+               if ( $this->user ) {
+                       $userInfo = [
+                               'userId' => $this->user->getId(),
+                               'userName' => $this->user->getName(),
+                       ];
+               } else {
+                       $userInfo = false;
+               }
+
+               if ( $this->mRevision ) {
+                       $triggeringRevisionId = $this->mRevision->getId();
+               } else {
+                       $triggeringRevisionId = false;
+               }
+
+               return [
+                       'domain' => $this->getDB()->getDomainID(),
+                       'job'  => new JobSpecification(
+                               'refreshLinksPrioritized',
+                               [
+                                       // Reuse the parser cache if it was saved
+                                       'rootJobTimestamp' => $this->mParserOutput->getCacheTime(),
+                                       'useRecursiveLinksUpdate' => $this->mRecursive,
+                                       'triggeringUser' => $userInfo,
+                                       'triggeringRevisionId' => $triggeringRevisionId,
+                                       'causeAction' => $this->getCauseAction(),
+                                       'causeAgent' => $this->getCauseAgent()
+                               ],
+                               [ 'removeDuplicates' => true ],
+                               $this->getTitle()
+                       )
+               ];
+       }
 }