From 80a7648a42509dcc6283f9b0bd9cdadb9369952d Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Sat, 13 Aug 2011 22:42:09 +0000 Subject: [PATCH] Allow extensions to run their own backlink-based updates: * Introduce new hooks which allow BacklinkCache to handle non-core tables * Make table name a parameter to RefreshLinks2 job (instead of hardcoded templatelinks) --- docs/hooks.txt | 10 ++++++++++ includes/BacklinkCache.php | 13 +++++++++++-- includes/LinksUpdate.php | 1 + includes/job/RefreshLinksJob.php | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 2dfafb0d61..d3071c4c23 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -564,6 +564,16 @@ $args: arguments $user: user $result: result of checking autopromote condition +'BacklinkCacheGetPrefix': allows to set prefix for a spefific link table +$table: table name +&$prefix: prefix + +'BacklinkCacheGetConditions': allows to set conditions for query when links to certain title +are fetched +$table: table name +$title: title of the page to which backlinks are sought +&$conds: query conditions + 'BadImage': When checking against the bad image list $name: Image name being checked &$bad: Whether or not the image is "bad" diff --git a/includes/BacklinkCache.php b/includes/BacklinkCache.php index 8d1571ec69..2263051456 100644 --- a/includes/BacklinkCache.php +++ b/includes/BacklinkCache.php @@ -190,7 +190,13 @@ class BacklinkCache { if ( isset( $prefixes[$table] ) ) { return $prefixes[$table]; } else { - throw new MWException( "Invalid table \"$table\" in " . __CLASS__ ); + $prefix = null; + wfRunHooks( 'BacklinkCacheGetPrefix', array( $table, &$prefix ) ); + if( $prefix ) { + return $prefix; + } else { + throw new MWException( "Invalid table \"$table\" in " . __CLASS__ ); + } } } @@ -237,7 +243,10 @@ class BacklinkCache { ); break; default: - throw new MWException( "Invalid table \"$table\" in " . __CLASS__ ); + $conds = null; + wfRunHooks( 'BacklinkCacheGetConditions', array( $table, $this->title, &$conds ) ); + if( !$conds ) + throw new MWException( "Invalid table \"$table\" in " . __CLASS__ ); } return $conds; diff --git a/includes/LinksUpdate.php b/includes/LinksUpdate.php index ec7960f449..3252fb655f 100644 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@ -241,6 +241,7 @@ class LinksUpdate { foreach ( $batches as $batch ) { list( $start, $end ) = $batch; $params = array( + 'table' => 'templatelinks', 'start' => $start, 'end' => $end, ); diff --git a/includes/job/RefreshLinksJob.php b/includes/job/RefreshLinksJob.php index 910f0c5810..9c699bfea5 100644 --- a/includes/job/RefreshLinksJob.php +++ b/includes/job/RefreshLinksJob.php @@ -89,7 +89,7 @@ class RefreshLinksJob2 extends Job { return false; } $titles = $this->title->getBacklinkCache()->getLinks( - 'templatelinks', $this->params['start'], $this->params['end']); + $this->params['table'], $this->params['start'], $this->params['end']); # Not suitable for page load triggered job running! # Gracefully switch to refreshLinks jobs if this happens. -- 2.20.1