Merge "Add help link to Special:Search"
[lhc/web/wiklou.git] / includes / jobqueue / jobs / RefreshLinksJob.php
index 935d2fb..26f4520 100644 (file)
@@ -41,19 +41,15 @@ class RefreshLinksJob extends Job {
 
        function __construct( Title $title, array $params ) {
                parent::__construct( 'refreshLinks', $title, $params );
-               // A separate type is used just for cascade-protected backlinks
-               if ( !empty( $this->params['prioritize'] ) ) {
-                       $this->command .= 'Prioritized';
-               }
                // Base backlink update jobs and per-title update jobs can be de-duplicated.
                // If template A changes twice before any jobs run, a clean queue will have:
-               //              (A base, A base)
+               //              (A base, A base)
                // The second job is ignored by the queue on insertion.
                // Suppose, many pages use template A, and that template itself uses template B.
                // An edit to both will first create two base jobs. A clean FIFO queue will have:
-               //              (A base, B base)
+               //              (A base, B base)
                // When these jobs run, the queue will have per-title and remnant partition jobs:
-               //              (titleX,titleY,titleZ,...,A remnant,titleM,titleN,titleO,...,B remnant)
+               //              (titleX,titleY,titleZ,...,A remnant,titleM,titleN,titleO,...,B remnant)
                // Some these jobs will be the same, and will automatically be ignored by
                // the queue upon insertion. Some title jobs will run before the duplicate is
                // inserted, so the work will still be done twice in those cases. More titles
@@ -64,6 +60,30 @@ class RefreshLinksJob extends Job {
                        && ( !isset( $params['pages'] ) || count( $params['pages'] ) == 1 );
        }
 
+       /**
+        * @param Title $title
+        * @param array $params
+        * @return RefreshLinksJob
+        */
+       public static function newPrioritized( Title $title, array $params ) {
+               $job = new self( $title, $params );
+               $job->command = 'refreshLinksPrioritized';
+
+               return $job;
+       }
+
+       /**
+        * @param Title $title
+        * @param array $params
+        * @return RefreshLinksJob
+        */
+       public static function newDynamic( Title $title, array $params ) {
+               $job = new self( $title, $params );
+               $job->command = 'refreshLinksDynamic';
+
+               return $job;
+       }
+
        function run() {
                global $wgUpdateRowsPerJob;
 
@@ -83,6 +103,7 @@ class RefreshLinksJob extends Job {
                        } else {
                                $extraParams['masterPos'] = false;
                        }
+                       $extraParams['triggeredRecursive'] = true;
                        // Convert this into no more than $wgUpdateRowsPerJob RefreshLinks per-title
                        // jobs and possibly a recursive RefreshLinks job for the rest of the backlinks
                        $jobs = BacklinkJobUtils::partitionBacklinkJob(
@@ -110,12 +131,7 @@ class RefreshLinksJob extends Job {
         * @param Title $title
         * @return bool
         */
-       protected function runForTitle( Title $title = null ) {
-               if ( is_null( $title ) ) {
-                       $this->setLastError( "refreshLinks: Invalid title" );
-                       return false;
-               }
-
+       protected function runForTitle( Title $title ) {
                // Wait for the DB of the current/next slave DB handle to catch up to the master.
                // This way, we get the correct page_latest for templates or files that just changed
                // milliseconds ago, having triggered this job to begin with.
@@ -196,7 +212,26 @@ class RefreshLinksJob extends Job {
                        }
                }
 
-               $updates = $content->getSecondaryDataUpdates( $title, null, false, $parserOutput );
+               $updates = $content->getSecondaryDataUpdates(
+                       $title, null, !empty( $this->params['useRecursiveLinksUpdate'] ), $parserOutput );
+               foreach ( $updates as $key => $update ) {
+                       if ( $update instanceof LinksUpdate ) {
+                               if ( isset( $this->params['triggeredRecursive'] ) ) {
+                                       $update->setTriggeredRecursive();
+                               }
+                               if ( isset( $this->params['triggeringUser'] ) && $this->params['triggeringUser'] ) {
+                                       $userInfo = $this->params['triggeringUser'];
+                                       if ( $userInfo['userId'] ) {
+                                               $user = User::newFromId( $userInfo['userId'] );
+                                       } else {
+                                               // Anonymous, use the username
+                                               $user = User::newFromName( $userInfo['userName'], false );
+                                       }
+                                       $update->setTriggeringUser( $user );
+                               }
+                       }
+               }
+
                DataUpdate::runUpdates( $updates );
 
                InfoAction::invalidateCache( $title );