GWicke has submitted this change and it was merged.
Change subject: Adapt the extension to RESTBase's needs
..
Adapt the extension to RESTBase's needs
The extension monitors the following hooks:
- ArticleEditUpdates
- ArticleDeleteComplete
- ArticleUndelete
- ArticleRevisionVisibilitySet
- TitleMoveComplete
- FileUpload
For each case, a queue job is created invalidating RESTBase's version of
the page (by sending a request with the no-cache header). Additional
jobs are created for any dependent pages which transclude the edited or
deleted page.
Bug: T87520
Change-Id: I9814249f350e2278f3941d62255e4ee9bb89c4b1
---
M RestbaseUpdate.hooks.php
M RestbaseUpdate.php
M RestbaseUpdateJob.php
3 files changed, 232 insertions(+), 130 deletions(-)
Approvals:
GWicke: Verified; Looks good to me, approved
diff --git a/RestbaseUpdate.hooks.php b/RestbaseUpdate.hooks.php
index c7cfbc2..5948457 100644
--- a/RestbaseUpdate.hooks.php
+++ b/RestbaseUpdate.hooks.php
@@ -1,5 +1,6 @@
?php
+
/**
* Hooks for events that should trigger RESTBase updates.
*/
@@ -7,16 +8,57 @@
/**
+* Get the job parameters for a given title, job type and table name.
+*
+* @param Title $title
+* @param string $type the job type (OnEdit or OnDependencyChange)
+* @param string $table (optional for OnDependencyChange, templatelinks
or
+* imagelinks)
+* @return Array
+*/
+ private static function getJobParams( Title $title, $type, $table =
null ) {
+
+ $params = array( 'type' = $type );
+ if ( $type == 'OnDependencyChange' ) {
+ $params['table'] = $table;
+ $params['recursive'] = true;
+ return $params + Job::newRootJobParams(
+
RestbaseUpdateJob{$type}:{$table}:{$title-getPrefixedText()}:{$title-getLatestRevID()});
+ } else {
+ return $params;
+ }
+
+ }
+
+
+ /**
* Schedule an async update job in the job queue.
*
* @param Title $title
-* @param string $type
+* @param string $action
* @param array $extra_params
*/
- private static function schedule( $title, $type, $extra_params =
array() ) {
+ private static function schedule( $title, $action, $extra_params =
array() ) {
- $params = array( 'type' = $type ) + $extra_params;
- JobQueueGroup::singleton()-push( new RestbaseUpdateJob(
$title, $params ) );
+ wfDebug( RestbaseUpdateJobHook::schedule: .
$title-getText() . ' - ' . $action . \n );
+ if ( $title-getNamespace() == NS_FILE ) {
+ // File. For now we assume the actual image or file has
+ // changed, not just the description page.
+ $params = self::getJobParams( $title,
'OnDependencyChange', 'imagelinks' );
+ $job = new RestbaseUpdateJob( $title, $params );
+ JobQueueGroup::singleton()-push( $job );
+ JobQueueGroup::singleton()-deduplicateRootJob( $job );
+ } else {
+ // Push one job for the page itself
+ $params = self::getJobParams( $title, 'OnEdit' )
+ + array( 'mode' = $action ) + $extra_params;
+ JobQueueGroup::singleton()-push( new
RestbaseUpdateJob( $title, $params ) );
+ // and one for pages transcluding this page.
+ $params = self::getJobParams( $title,
'OnDependencyChange', 'templatelinks' );
+ $job = new RestbaseUpdateJob( $title, $params );
+ JobQueueGroup::singleton()-push( $job );
+ JobQueueGroup::singleton()-deduplicateRootJob( $job );
+ }
}
@@ -74,8 +116,7 @@
public static function onArticleRevisionVisibilitySet( $title, $revs ) {
// TODO complete here with more info / the hidden fields
perhaps ?
- // XXX do not forget that rev IDs are not yet actually returned
- self::schedule( $title, 'rev_delete', array( 'revs' = $revs )
);
+ self::schedule( $title, 'rev_visibility', array( 'revs' =
$revs ) );
return true;
}
@@ -94,5 +135,24 @@
}
+ /**
+* File upload hook. See filerepo/file/LocalFile.php.
+*
+* XXX gwicke: This tracks file uploads including re-uploads of a new
+* version of an image. These will implicitly also trigger null edits on
+* the associated WikiPage (which normally exists), which then triggers
+* the onArticleEditUpdates hook. Maybe we should thus drop this hook
and
+* simply assume that all edits to