* (bug 20494) OutputPage::getArticleBodyOnly() no longer requires an useless argument
[lhc/web/wiklou.git] / includes / LinksUpdate.php
index 7cf7453..caacb49 100644 (file)
@@ -67,6 +67,7 @@ class LinksUpdate {
                }
 
                $this->mRecursive = $recursive;
+               $this->mTouchTmplLinks = false;
 
                wfRunHooks( 'LinksUpdateConstructed', array( &$this ) );
        }
@@ -74,7 +75,7 @@ class LinksUpdate {
        /**
         * Update link tables with outgoing links from an updated article
         */
-       function doUpdate() {
+       public function doUpdate() {
                global $wgUseDumbLinkUpdate;
 
                wfRunHooks( 'LinksUpdate', array( &$this ) );
@@ -84,10 +85,9 @@ class LinksUpdate {
                        $this->doIncrementalUpdate();
                }
                wfRunHooks( 'LinksUpdateComplete', array( &$this ) );
-
        }
 
-       function doIncrementalUpdate() {
+       protected function doIncrementalUpdate() {
                wfProfileIn( __METHOD__ );
 
                # Page links
@@ -99,11 +99,10 @@ class LinksUpdate {
                $existing = $this->getExistingImages();
 
                $imageDeletes = $this->getImageDeletions( $existing );
-               $imageInserts = $this->getImageInsertions( $existing );
-               $this->incrTableUpdate( 'imagelinks', 'il', $imageDeletes, $imageInserts );
+               $this->incrTableUpdate( 'imagelinks', 'il', $imageDeletes, $this->getImageInsertions( $existing ) );
 
                # Invalidate all image description pages which had links added or removed
-               $imageUpdates = $imageDeletions + $imageInsertions
+               $imageUpdates = $imageDeletes + array_diff_key( $this->mImages, $existing );
                $this->invalidateImageDescriptions( $imageUpdates );
 
                # External links
@@ -125,11 +124,11 @@ class LinksUpdate {
                $existing = $this->getExistingCategories();
 
                $categoryDeletes = $this->getCategoryDeletions( $existing );
-               $categoryInserts = $this->getCategoryInsertions( $existing );
 
-               $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes, $categoryInserts );
+               $this->incrTableUpdate( 'categorylinks', 'cl', $categoryDeletes, $this->getCategoryInsertions( $existing ) );
 
                # Invalidate all categories which were added, deleted or changed (set symmetric difference)
+               $categoryInserts = array_diff_assoc( $this->mCategories, $existing );
                $categoryUpdates = $categoryInserts + $categoryDeletes;
                $this->invalidateCategories( $categoryUpdates );
                $this->updateCategoryCounts( $categoryInserts, $categoryDeletes );
@@ -137,13 +136,12 @@ class LinksUpdate {
                # Page properties
                $existing = $this->getExistingProperties();
 
-               $propertiesDeletes = $this->getPropertiesDeletions( $existing );
-               $propertiesInserts = $this->getPropertiesInsertions( $existing );
+               $propertiesDeletes = $this->getPropertyDeletions( $existing );
 
-               $this->incrTableUpdate( 'page_props', 'pp', $propertiesDeletes, $propertiesInserts );
+               $this->incrTableUpdate( 'page_props', 'pp', $propertiesDeletes, $this->getPropertyInsertions( $existing ) );
 
                # Invalidate the necessary pages
-               $changed = $propertiesDeletes + $propertiesInserts;
+               $changed = $propertiesDeletes + array_diff_assoc( $this->mProperties, $existing );
                $this->invalidateProperties( $changed );
 
                # Refresh links of all pages including this page
@@ -160,13 +158,13 @@ class LinksUpdate {
         * May be slower or faster depending on level of lock contention and write speed of DB
         * Also useful where link table corruption needs to be repaired, e.g. in refreshLinks.php
         */
-       function doDumbUpdate() {
+       protected function doDumbUpdate() {
                wfProfileIn( __METHOD__ );
 
                # Refresh category pages and image description pages
                $existing = $this->getExistingCategories();
                $categoryInserts = array_diff_assoc( $this->mCategories, $existing );
-               $categoryDeletes = array_diff_assoc( $existing, $this->mCategoties );
+               $categoryDeletes = array_diff_assoc( $existing, $this->mCategories );
                $categoryUpdates = $categoryInserts + $categoryDeletes;
                $existing = $this->getExistingImages();
                $imageUpdates = array_diff_key( $existing, $this->mImages ) + array_diff_key( $this->mImages, $existing );
@@ -195,34 +193,26 @@ class LinksUpdate {
        }
 
        function queueRecursiveJobs() {
+               global $wgUpdateRowsPerJob;
                wfProfileIn( __METHOD__ );
 
-               $batchSize = 100;
-               $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( array( 'templatelinks', 'page' ),
-                       array( 'page_namespace', 'page_title' ),
-                       array(
-                               'page_id=tl_from',
-                               'tl_namespace' => $this->mTitle->getNamespace(),
-                               'tl_title' => $this->mTitle->getDBkey()
-                       ), __METHOD__
-               );
-
-               $done = false;
-               while ( !$done ) {
-                       $jobs = array();
-                       for ( $i = 0; $i < $batchSize; $i++ ) {
-                               $row = $dbr->fetchObject( $res );
-                               if ( !$row ) {
-                                       $done = true;
-                                       break;
-                               }
-                               $title = Title::makeTitle( $row->page_namespace, $row->page_title );
-                               $jobs[] = new RefreshLinksJob( $title, '' );
-                       }
-                       Job::batchInsert( $jobs );
+               $cache = $this->mTitle->getBacklinkCache();
+               $batches = $cache->partition( 'templatelinks', $wgUpdateRowsPerJob );
+               if ( !$batches ) {
+                       wfProfileOut( __METHOD__ );
+                       return;
                }
-               $dbr->freeResult( $res );
+               $jobs = array();
+               foreach ( $batches as $batch ) {
+                       list( $start, $end ) = $batch;
+                       $params = array(
+                               'start' => $start,
+                               'end' => $end,
+                       );
+                       $jobs[] = new RefreshLinksJob2( $this->mTitle, $params );
+               }
+               Job::batchInsert( $jobs );
+
                wfProfileOut( __METHOD__ );
        }
 
@@ -288,7 +278,7 @@ class LinksUpdate {
        }
 
        function invalidateImageDescriptions( $images ) {
-               $this->invalidatePages( NS_IMAGE, array_keys( $images ) );
+               $this->invalidatePages( NS_FILE, array_keys( $images ) );
        }
 
        function dumbTableUpdate( $table, $insertions, $fromField ) {
@@ -436,9 +426,12 @@ class LinksUpdate {
         * @private
         */
        function getCategoryInsertions( $existing = array() ) {
+               global $wgContLang;
                $diffs = array_diff_assoc( $this->mCategories, $existing );
                $arr = array();
                foreach ( $diffs as $name => $sortkey ) {
+                       $nt = Title::makeTitleSafe( NS_CATEGORY, $name );
+                       $wgContLang->findVariantLink( $name, $nt, true );
                        $arr[] = array(
                                'cl_from'    => $this->mId,
                                'cl_to'      => $name,