Add RejectParserCacheValue hook
authorOri Livneh <ori@wikimedia.org>
Tue, 23 Jun 2015 05:09:53 +0000 (22:09 -0700)
committerKunal Mehta <legoktm@gmail.com>
Tue, 23 Jun 2015 18:23:57 +0000 (11:23 -0700)
Add a new hook, 'RejectParserCacheValue', which allows extensions to reject an
otherwise-successful parser cache lookup. The intent is to allow extensions to
manage the eviction of archaic HTML output from the cache.

Change-Id: I660679a48c46608f859bd52b31d6a888aabcc9ac

RELEASE-NOTES-1.26
docs/hooks.txt
includes/parser/ParserCache.php

index 852023b..e035de9 100644 (file)
@@ -21,6 +21,9 @@ production.
 * Revive the 'SpecialSearchResultsAppend' hook which occurs after the list of
   search results are rendered. The initial use case is to append a "give us
   feedback" link beneath the search results.
+* Added a new hook, 'RejectParserCacheValue', which allows extensions to
+  reject an otherwise-successful parser cache lookup. The intent is to allow
+  extensions to manage the eviction of archaic HTML output from the cache.
 
 
 ==== External libraries ====
index 4546f9e..8cfdee9 100644 (file)
@@ -2402,6 +2402,12 @@ names such as "oldid" that are preserved when using redirecting special pages
 such as Special:MyPage and Special:MyTalk.
 &$redirectParams: An array of parameters preserved by redirecting special pages.
 
+'RejectParserCacheValue': Return false to reject an otherwise usable
+cached value from the Parser cache.
+$parserOutput: ParserOutput value.
+$wikiPage: WikiPage object.
+$parserOptions: ParserOptions object.
+
 'RequestContextCreateSkin': Called when RequestContext::getSkin creates a skin
 instance. Can be used by an extension override what skin is used in certain
 contexts.
index 16dde0d..2919c6c 100644 (file)
@@ -225,6 +225,10 @@ class ParserCache {
                        $cachedRevId = $value->getCacheRevisionId();
                        wfDebug( "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n" );
                        $value = false;
+               } elseif ( Hooks::run( 'RejectParserCacheValue', array( $value, $article, $popts ) ) === false ) {
+                       wfIncrStats( 'pcache.miss.rejected' );
+                       wfDebug( "ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n" );
+                       $value = false;
                } else {
                        wfIncrStats( "pcache.hit" );
                }