From c95ec07359b3d2be484f74fe3411d80eb73f93a3 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 18 Mar 2015 18:21:25 +0100 Subject: [PATCH] New hook: OpportunisticLinksUpdate Change-Id: I8b9238cd6b0010ad91fae24d4eb1e7cd0c201931 --- RELEASE-NOTES-1.25 | 2 ++ docs/hooks.txt | 11 +++++++++++ includes/page/WikiPage.php | 13 ++++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 0bf7a8083c..a31461c7bd 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -408,6 +408,8 @@ changes to languages because of Bugzilla reports. addSecondaryDataUpdate throwing an exception. These functions will be removed in 1.26, since they interfere with caching of ParserOutput objects. * Introduced new hook 'SecondaryDataUpdates' that allows extensions to inject custom updates. +* Introduced new hook 'OpportunisticLinksUpdate' that allows extensions to perform + updates when a page is re-rendered. * EditPage::attemptSave has been modified not to call handleStatus itself and instead just returns the Status object. Extension calling it should be aware of this. diff --git a/docs/hooks.txt b/docs/hooks.txt index f2c47cac6e..877b7ed709 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2012,6 +2012,17 @@ return false to omit the line from RecentChanges and Watchlist special pages. can alter or append to the array of URLs for search & suggestion formats. &$urls: array of associative arrays with Url element attributes +'OpportunisticLinksUpdate': Called by WikiPage::triggerOpportunisticLinksUpdate +when a page view triggers a re-rendering of the page. This may happen +particularly if the parser cache is split by user language, and no cached +rendering of the page exists in the user's language. The hook is called +before checking whether page_links_updated indicates that the links are up +to date. Returning false will cause triggerOpportunisticLinksUpdate() to abort +without triggering any updates. +$page: the Page that was rendered. +$title: the Title of the rendered page. +$parserOutput: ParserOutput resulting from rendering the page. + 'OtherBlockLogLink': Get links to the block log from extensions which blocks users and/or IP addresses too. $otherBlockLink: An array with links to other block logs diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 0452c41500..d96e2711c6 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -3394,12 +3394,15 @@ class WikiPage implements Page, IDBAccessObject { * Opportunistically enqueue link update jobs given fresh parser output if useful * * @param ParserOutput $parserOutput Current version page output - * @return bool Whether a job was pushed * @since 1.25 */ public function triggerOpportunisticLinksUpdate( ParserOutput $parserOutput ) { if ( wfReadOnly() ) { - return false; + return; + } + + if ( !Hooks::run( 'OpportunisticLinksUpdate', array( $this, $this->mTitle, $parserOutput ) ) ) { + return; } if ( $this->mTitle->areRestrictionsCascading() ) { @@ -3410,7 +3413,7 @@ class WikiPage implements Page, IDBAccessObject { $params = array(); } else { // If the inclusions are deterministic, the edit-triggered link jobs are enough - return false; + return; } // Check if the last link refresh was before page_touched @@ -3418,10 +3421,10 @@ class WikiPage implements Page, IDBAccessObject { JobQueueGroup::singleton()->push( EnqueueJob::newFromLocalJobs( new JobSpecification( 'refreshLinks', $params, array(), $this->mTitle ) ) ); - return true; + return; } - return false; + return; } /** -- 2.20.1