Allow extensions to run their own backlink-based updates:
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sat, 13 Aug 2011 22:42:09 +0000 (22:42 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sat, 13 Aug 2011 22:42:09 +0000 (22:42 +0000)
* 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
includes/BacklinkCache.php
includes/LinksUpdate.php
includes/job/RefreshLinksJob.php

index 2dfafb0..d3071c4 100644 (file)
@@ -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"
index 8d1571e..2263051 100644 (file)
@@ -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;
index ec7960f..3252fb6 100644 (file)
@@ -241,6 +241,7 @@ class LinksUpdate {
                foreach ( $batches as $batch ) {
                        list( $start, $end ) = $batch;
                        $params = array(
+                               'table' => 'templatelinks',
                                'start' => $start,
                                'end' => $end,
                        );
index 910f0c5..9c699bf 100644 (file)
@@ -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.