diff options
Diffstat (limited to 'includes/LinksUpdate.php')
-rw-r--r-- | includes/LinksUpdate.php | 100 |
1 files changed, 57 insertions, 43 deletions
diff --git a/includes/LinksUpdate.php b/includes/LinksUpdate.php index 87db4d60..d99ae22d 100644 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@ -49,6 +49,7 @@ class LinksUpdate extends SqlDataUpdate { * @param $title Title of the page we're updating * @param $parserOutput ParserOutput: output from a full parse of this page * @param $recursive Boolean: queue jobs for recursive updates? + * @throws MWException */ function __construct( $title, $parserOutput, $recursive = true ) { parent::__construct( false ); // no implicit transaction @@ -71,6 +72,7 @@ class LinksUpdate extends SqlDataUpdate { } $this->mParserOutput = $parserOutput; + $this->mLinks = $parserOutput->getLinks(); $this->mImages = $parserOutput->getImages(); $this->mTemplates = $parserOutput->getTemplates(); @@ -211,14 +213,14 @@ class LinksUpdate extends SqlDataUpdate { $existing = $this->getExistingImages(); $imageUpdates = array_diff_key( $existing, $this->mImages ) + array_diff_key( $this->mImages, $existing ); - $this->dumbTableUpdate( 'pagelinks', $this->getLinkInsertions(), 'pl_from' ); - $this->dumbTableUpdate( 'imagelinks', $this->getImageInsertions(), 'il_from' ); + $this->dumbTableUpdate( 'pagelinks', $this->getLinkInsertions(), 'pl_from' ); + $this->dumbTableUpdate( 'imagelinks', $this->getImageInsertions(), 'il_from' ); $this->dumbTableUpdate( 'categorylinks', $this->getCategoryInsertions(), 'cl_from' ); $this->dumbTableUpdate( 'templatelinks', $this->getTemplateInsertions(), 'tl_from' ); $this->dumbTableUpdate( 'externallinks', $this->getExternalInsertions(), 'el_from' ); - $this->dumbTableUpdate( 'langlinks', $this->getInterlangInsertions(),'ll_from' ); - $this->dumbTableUpdate( 'iwlinks', $this->getInterwikiInsertions(),'iwl_from' ); - $this->dumbTableUpdate( 'page_props', $this->getPropertyInsertions(), 'pp_page' ); + $this->dumbTableUpdate( 'langlinks', $this->getInterlangInsertions(), 'll_from' ); + $this->dumbTableUpdate( 'iwlinks', $this->getInterwikiInsertions(), 'iwl_from' ); + $this->dumbTableUpdate( 'page_props', $this->getPropertyInsertions(), 'pp_page' ); # Update the cache of all the category pages and image description # pages which were changed, and fix the category table count @@ -236,26 +238,20 @@ class LinksUpdate extends SqlDataUpdate { } function queueRecursiveJobs() { - global $wgUpdateRowsPerJob; wfProfileIn( __METHOD__ ); - $cache = $this->mTitle->getBacklinkCache(); - $batches = $cache->partition( 'templatelinks', $wgUpdateRowsPerJob ); - if ( !$batches ) { - wfProfileOut( __METHOD__ ); - return; - } - $jobs = array(); - foreach ( $batches as $batch ) { - list( $start, $end ) = $batch; - $params = array( - 'table' => 'templatelinks', - 'start' => $start, - 'end' => $end, + if ( $this->mTitle->getBacklinkCache()->hasLinks( 'templatelinks' ) ) { + $job = new RefreshLinksJob2( + $this->mTitle, + array( + 'table' => 'templatelinks', + ) + Job::newRootJobParams( // "overall" refresh links job info + "refreshlinks:templatelinks:{$this->mTitle->getPrefixedText()}" + ) ); - $jobs[] = new RefreshLinksJob2( $this->mTitle, $params ); + JobQueueGroup::singleton()->push( $job ); + JobQueueGroup::singleton()->deduplicateRootJob( $job ); } - Job::batchInsert( $jobs ); wfProfileOut( __METHOD__ ); } @@ -269,8 +265,8 @@ class LinksUpdate extends SqlDataUpdate { /** * Update all the appropriate counts in the category table. - * @param $added array associative array of category name => sort key - * @param $deleted array associative array of category name => sort key + * @param array $added associative array of category name => sort key + * @param array $deleted associative array of category name => sort key */ function updateCategoryCounts( $added, $deleted ) { $a = WikiPage::factory( $this->mTitle ); @@ -295,7 +291,7 @@ class LinksUpdate extends SqlDataUpdate { $this->mDb->delete( $table, array( $fromField => $this->mId ), __METHOD__ ); if ( count( $insertions ) ) { # The link array was constructed without FOR UPDATE, so there may - # be collisions. This may cause minor link table inconsistencies, + # be collisions. This may cause minor link table inconsistencies, # which is better than crippling the site with lock contention. $this->mDb->insert( $table, $insertions, __METHOD__, array( 'IGNORE' ) ); } @@ -346,6 +342,7 @@ class LinksUpdate extends SqlDataUpdate { } if ( count( $insertions ) ) { $this->mDb->insert( $table, $insertions, __METHOD__, 'IGNORE' ); + wfRunHooks( 'LinksUpdateAfterInsert', array( $this, $table, $insertions ) ); } } @@ -363,9 +360,9 @@ class LinksUpdate extends SqlDataUpdate { : $dbkeys; foreach ( $diffs as $dbk => $id ) { $arr[] = array( - 'pl_from' => $this->mId, + 'pl_from' => $this->mId, 'pl_namespace' => $ns, - 'pl_title' => $dbk + 'pl_title' => $dbk ); } } @@ -383,9 +380,9 @@ class LinksUpdate extends SqlDataUpdate { $diffs = isset( $existing[$ns] ) ? array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys; foreach ( $diffs as $dbk => $id ) { $arr[] = array( - 'tl_from' => $this->mId, + 'tl_from' => $this->mId, 'tl_namespace' => $ns, - 'tl_title' => $dbk + 'tl_title' => $dbk ); } } @@ -404,7 +401,7 @@ class LinksUpdate extends SqlDataUpdate { foreach( $diffs as $iname => $dummy ) { $arr[] = array( 'il_from' => $this->mId, - 'il_to' => $iname + 'il_to' => $iname ); } return $arr; @@ -421,9 +418,9 @@ class LinksUpdate extends SqlDataUpdate { foreach( $diffs as $url => $dummy ) { foreach( wfMakeUrlIndexes( $url ) as $index ) { $arr[] = array( - 'el_from' => $this->mId, - 'el_to' => $url, - 'el_index' => $index, + 'el_from' => $this->mId, + 'el_to' => $url, + 'el_index' => $index, ); } } @@ -433,7 +430,7 @@ class LinksUpdate extends SqlDataUpdate { /** * Get an array of category insertions * - * @param $existing array mapping existing category names to sort keys. If both + * @param array $existing mapping existing category names to sort keys. If both * match a link in $this, the link will be omitted from the output * * @return array @@ -462,8 +459,8 @@ class LinksUpdate extends SqlDataUpdate { $this->mTitle->getCategorySortkey( $prefix ) ); $arr[] = array( - 'cl_from' => $this->mId, - 'cl_to' => $name, + 'cl_from' => $this->mId, + 'cl_to' => $name, 'cl_sortkey' => $sortkey, 'cl_timestamp' => $this->mDb->timestamp(), 'cl_sortkey_prefix' => $prefix, @@ -477,7 +474,7 @@ class LinksUpdate extends SqlDataUpdate { /** * Get an array of interlanguage link insertions * - * @param $existing Array mapping existing language codes to titles + * @param array $existing mapping existing language codes to titles * * @return array */ @@ -486,8 +483,8 @@ class LinksUpdate extends SqlDataUpdate { $arr = array(); foreach( $diffs as $lang => $title ) { $arr[] = array( - 'll_from' => $this->mId, - 'll_lang' => $lang, + 'll_from' => $this->mId, + 'll_lang' => $lang, 'll_title' => $title ); } @@ -504,9 +501,9 @@ class LinksUpdate extends SqlDataUpdate { $arr = array(); foreach ( $diffs as $name => $value ) { $arr[] = array( - 'pp_page' => $this->mId, - 'pp_propname' => $name, - 'pp_value' => $value, + 'pp_page' => $this->mId, + 'pp_propname' => $name, + 'pp_value' => $value, ); } return $arr; @@ -524,9 +521,9 @@ class LinksUpdate extends SqlDataUpdate { $diffs = isset( $existing[$prefix] ) ? array_diff_key( $dbkeys, $existing[$prefix] ) : $dbkeys; foreach ( $diffs as $dbk => $id ) { $arr[] = array( - 'iwl_from' => $this->mId, + 'iwl_from' => $this->mId, 'iwl_prefix' => $prefix, - 'iwl_title' => $dbk + 'iwl_title' => $dbk ); } } @@ -823,11 +820,16 @@ class LinksDeletionUpdate extends SqlDataUpdate { * Constructor * * @param $page WikiPage Page we are updating + * @throws MWException */ function __construct( WikiPage $page ) { parent::__construct( false ); // no implicit transaction $this->mPage = $page; + + if ( !$page->exists() ) { + throw new MWException( "Page ID not known, perhaps the page doesn't exist?" ); + } } /** @@ -879,4 +881,16 @@ class LinksDeletionUpdate extends SqlDataUpdate { __METHOD__ ); } } + + /** + * Update all the appropriate counts in the category table. + * @param array $added associative array of category name => sort key + * @param array $deleted associative array of category name => sort key + */ + function updateCategoryCounts( $added, $deleted ) { + $a = WikiPage::factory( $this->mTitle ); + $a->updateCategoryCounts( + array_keys( $added ), array_keys( $deleted ) + ); + } } |