2019-03-15 00:23:26 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
|
|
|
|
use MediaWiki\HookContainer\HookRunner;
|
2021-05-07 22:19:29 +00:00
|
|
|
use MediaWiki\Page\PageIdentity;
|
2021-04-11 20:24:16 +00:00
|
|
|
use MediaWiki\Page\PageReference;
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
|
2019-03-15 00:23:26 +00:00
|
|
|
/**
|
|
|
|
|
* Class to invalidate the CDN and HTMLFileCache entries associated with URLs/titles
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Cache
|
|
|
|
|
* @since 1.35
|
|
|
|
|
*/
|
|
|
|
|
class HtmlCacheUpdater {
|
|
|
|
|
/** @var int Seconds between initial and rebound purges; 0 if disabled */
|
|
|
|
|
private $reboundDelay;
|
2022-03-08 19:01:54 +00:00
|
|
|
/** @var bool Whether filesystem-based HTML output caching is enabled */
|
2019-03-15 00:23:26 +00:00
|
|
|
private $useFileCache;
|
2020-05-21 09:40:16 +00:00
|
|
|
/** @var int Max seconds for CDN to served cached objects without revalidation */
|
|
|
|
|
private $cdnMaxAge;
|
2019-03-15 00:23:26 +00:00
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
/** @var HookRunner */
|
|
|
|
|
private $hookRunner;
|
|
|
|
|
|
2019-03-15 00:23:26 +00:00
|
|
|
/** @var int Issue purge immediately and do not schedule a rebound purge */
|
|
|
|
|
public const PURGE_NAIVE = 0;
|
|
|
|
|
/**
|
|
|
|
|
* @var int Defer purge via PRESEND deferred updates. The pending DeferrableUpdate instances
|
|
|
|
|
* will combined/de-duplicated into a single DeferrableUpdate instance; this lowers overhead
|
|
|
|
|
* and improves HTTP PURGE request pipelining.
|
|
|
|
|
*/
|
|
|
|
|
public const PURGE_PRESEND = 1;
|
|
|
|
|
/**
|
|
|
|
|
* @var int Upon purge, schedule a delayed CDN purge if rebound purges are enabled
|
|
|
|
|
* ($wgCdnReboundPurgeDelay). Rebound purges are schedule via the job queue.
|
|
|
|
|
*/
|
|
|
|
|
public const PURGE_REBOUND = 2;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int Defer purge until no LBFactory transaction round is pending and then schedule
|
|
|
|
|
* a delayed rebound purge if rebound purges are enabled ($wgCdnReboundPurgeDelay). This is
|
|
|
|
|
* useful for CDN purges triggered by data changes in the current or last transaction round.
|
|
|
|
|
* Even if the origin server uses lagged replicas, the use of rebound purges corrects the
|
|
|
|
|
* cache in cases where lag is less than the rebound delay. If the lag is anywhere near the
|
|
|
|
|
* rebound delay, then auxiliary mechanisms should lower the cache TTL ($wgCdnMaxageLagged).
|
|
|
|
|
*/
|
|
|
|
|
public const PURGE_INTENT_TXROUND_REFLECTED = self::PURGE_PRESEND | self::PURGE_REBOUND;
|
|
|
|
|
|
2020-04-16 20:44:35 +00:00
|
|
|
/**
|
|
|
|
|
* Reduce set of URLs to be purged to only those that may be affected by
|
|
|
|
|
* change propagation from LinksUpdate (e.g. after a used template was edited).
|
|
|
|
|
*
|
|
|
|
|
* Specifically, this means URLs only affected by direct revision edits,
|
|
|
|
|
* will not be purged.
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
public const PURGE_URLS_LINKSUPDATE_ONLY = 4;
|
|
|
|
|
|
2020-05-21 09:40:16 +00:00
|
|
|
/**
|
|
|
|
|
* Do not bother purging cache items if the default max cache TTL implies that no objects
|
|
|
|
|
* can still be in cache from before the given timestamp.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
public const UNLESS_CACHE_MTIME_AFTER = 'unless-timestamp-exceeds';
|
|
|
|
|
|
2021-04-11 20:24:16 +00:00
|
|
|
/** @var TitleFactory */
|
|
|
|
|
private $titleFactory;
|
|
|
|
|
|
2019-03-15 00:23:26 +00:00
|
|
|
/**
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
* @param HookContainer $hookContainer
|
2021-04-11 20:24:16 +00:00
|
|
|
* @param TitleFactory $titleFactory
|
2019-03-15 00:23:26 +00:00
|
|
|
* @param int $reboundDelay $wgCdnReboundPurgeDelay
|
|
|
|
|
* @param bool $useFileCache $wgUseFileCache
|
2020-05-21 09:40:16 +00:00
|
|
|
* @param int $cdnMaxAge $wgCdnMaxAge
|
2021-04-11 20:24:16 +00:00
|
|
|
*
|
2019-03-15 00:23:26 +00:00
|
|
|
* @internal For use with MediaWikiServices->getHtmlCacheUpdater()
|
|
|
|
|
*/
|
2021-04-11 20:24:16 +00:00
|
|
|
public function __construct(
|
|
|
|
|
HookContainer $hookContainer,
|
|
|
|
|
TitleFactory $titleFactory,
|
|
|
|
|
$reboundDelay,
|
|
|
|
|
$useFileCache,
|
|
|
|
|
$cdnMaxAge
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
) {
|
|
|
|
|
$this->hookRunner = new HookRunner( $hookContainer );
|
2021-04-11 20:24:16 +00:00
|
|
|
$this->titleFactory = $titleFactory;
|
2019-03-15 00:23:26 +00:00
|
|
|
$this->reboundDelay = $reboundDelay;
|
|
|
|
|
$this->useFileCache = $useFileCache;
|
2020-05-21 09:40:16 +00:00
|
|
|
$this->cdnMaxAge = $cdnMaxAge;
|
2019-03-15 00:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-16 20:44:35 +00:00
|
|
|
/**
|
|
|
|
|
* @param int $flags Bit field
|
|
|
|
|
* @param int $flag Constant to check for
|
|
|
|
|
* @return bool If $flags contains $flag
|
|
|
|
|
*/
|
|
|
|
|
private function fieldHasFlag( $flags, $flag ) {
|
|
|
|
|
return ( ( $flags & $flag ) === $flag );
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 00:23:26 +00:00
|
|
|
/**
|
|
|
|
|
* Purge the CDN for a URL or list of URLs
|
|
|
|
|
*
|
|
|
|
|
* @param string[]|string $urls URL or list of URLs
|
|
|
|
|
* @param int $flags Bit field of class PURGE_* constants
|
|
|
|
|
* [Default: HtmlCacheUpdater::PURGE_PRESEND]
|
2020-05-21 09:40:16 +00:00
|
|
|
* @param mixed[] $unless Optional map of (HtmlCacheUpdater::UNLESS_* constant => value)
|
2019-03-15 00:23:26 +00:00
|
|
|
*/
|
2020-05-21 09:40:16 +00:00
|
|
|
public function purgeUrls( $urls, $flags = self::PURGE_PRESEND, array $unless = [] ) {
|
|
|
|
|
$minFreshCacheMtime = $unless[self::UNLESS_CACHE_MTIME_AFTER] ?? null;
|
|
|
|
|
if ( $minFreshCacheMtime && time() > ( $minFreshCacheMtime + $this->cdnMaxAge ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 00:23:26 +00:00
|
|
|
$urls = is_string( $urls ) ? [ $urls ] : $urls;
|
|
|
|
|
|
2020-04-16 20:44:35 +00:00
|
|
|
$reboundDelay = $this->fieldHasFlag( $flags, self::PURGE_REBOUND )
|
2019-03-15 00:23:26 +00:00
|
|
|
? $this->reboundDelay
|
|
|
|
|
: 0; // no second purge
|
|
|
|
|
|
|
|
|
|
$update = new CdnCacheUpdate( $urls, [ 'reboundDelay' => $reboundDelay ] );
|
2020-04-16 20:44:35 +00:00
|
|
|
if ( $this->fieldHasFlag( $flags, self::PURGE_PRESEND ) ) {
|
2019-03-15 00:23:26 +00:00
|
|
|
DeferredUpdates::addUpdate( $update, DeferredUpdates::PRESEND );
|
|
|
|
|
} else {
|
|
|
|
|
$update->doUpdate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Purge the CDN/HTMLFileCache for a title or the titles yielded by an iterator
|
|
|
|
|
*
|
|
|
|
|
* All cacheable canonical URLs associated with the titles will be purged from CDN.
|
|
|
|
|
* All cacheable actions associated with the titles will be purged from HTMLFileCache.
|
|
|
|
|
*
|
2021-04-11 20:24:16 +00:00
|
|
|
* @param Traversable|PageReference[]|PageReference $pages PageReference or iterator yielding
|
|
|
|
|
* PageReference instances
|
2019-03-15 00:23:26 +00:00
|
|
|
* @param int $flags Bit field of class PURGE_* constants
|
|
|
|
|
* [Default: HtmlCacheUpdater::PURGE_PRESEND]
|
2020-05-21 09:40:16 +00:00
|
|
|
* @param mixed[] $unless Optional map of (HtmlCacheUpdater::UNLESS_* constant => value)
|
2019-03-15 00:23:26 +00:00
|
|
|
*/
|
2021-04-11 20:24:16 +00:00
|
|
|
public function purgeTitleUrls( $pages, $flags = self::PURGE_PRESEND, array $unless = [] ) {
|
|
|
|
|
$pages = is_iterable( $pages ) ? $pages : [ $pages ];
|
2021-05-07 22:19:29 +00:00
|
|
|
$pageIdentities = [];
|
2021-04-11 20:24:16 +00:00
|
|
|
|
|
|
|
|
foreach ( $pages as $page ) {
|
2021-05-07 22:19:29 +00:00
|
|
|
// TODO: We really only need to cast to PageIdentity. We could use a LinkBatch for that.
|
2021-04-11 20:24:16 +00:00
|
|
|
$title = $this->titleFactory->castFromPageReference( $page );
|
|
|
|
|
|
|
|
|
|
if ( $title->canExist() ) {
|
2021-05-07 22:19:29 +00:00
|
|
|
$pageIdentities[] = $title;
|
2021-04-11 20:24:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 22:19:29 +00:00
|
|
|
if ( !$pageIdentities ) {
|
2021-04-11 20:24:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2019-03-15 00:23:26 +00:00
|
|
|
|
|
|
|
|
if ( $this->useFileCache ) {
|
2021-05-07 22:19:29 +00:00
|
|
|
$update = HtmlFileCacheUpdate::newFromPages( $pageIdentities );
|
2020-04-16 20:44:35 +00:00
|
|
|
if ( $this->fieldHasFlag( $flags, self::PURGE_PRESEND ) ) {
|
2019-03-15 00:23:26 +00:00
|
|
|
DeferredUpdates::addUpdate( $update, DeferredUpdates::PRESEND );
|
|
|
|
|
} else {
|
|
|
|
|
$update->doUpdate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 09:40:16 +00:00
|
|
|
$minFreshCacheMtime = $unless[self::UNLESS_CACHE_MTIME_AFTER] ?? null;
|
|
|
|
|
if ( !$minFreshCacheMtime || time() <= ( $minFreshCacheMtime + $this->cdnMaxAge ) ) {
|
|
|
|
|
$urls = [];
|
2021-05-07 22:19:29 +00:00
|
|
|
foreach ( $pageIdentities as $pi ) {
|
|
|
|
|
/** @var PageIdentity $pi */
|
|
|
|
|
$urls = array_merge( $urls, $this->getUrls( $pi, $flags ) );
|
2020-05-21 09:40:16 +00:00
|
|
|
}
|
|
|
|
|
$this->purgeUrls( $urls, $flags );
|
2019-03-15 00:23:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-04-16 20:44:35 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a list of URLs to purge from the CDN cache when this page changes.
|
|
|
|
|
*
|
2021-04-11 20:24:16 +00:00
|
|
|
* @param PageReference $page
|
2020-04-16 20:44:35 +00:00
|
|
|
* @param int $flags Bit field of `PURGE_URLS_*` class constants (optional).
|
|
|
|
|
* @return string[] URLs
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
public function getUrls( PageReference $page, int $flags = 0 ): array {
|
2021-04-11 20:24:16 +00:00
|
|
|
$title = $this->titleFactory->castFromPageReference( $page );
|
|
|
|
|
|
|
|
|
|
if ( !$title->canExist() ) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 20:44:35 +00:00
|
|
|
// These urls are affected both by direct revisions as well,
|
|
|
|
|
// as re-rendering of the same content during a LinksUpdate.
|
|
|
|
|
$urls = [
|
|
|
|
|
$title->getInternalURL()
|
|
|
|
|
];
|
|
|
|
|
// Language variant page views are currently not cached
|
|
|
|
|
// and thus not purged (T250511).
|
|
|
|
|
|
|
|
|
|
// These urls are only affected by direct revisions, and do not require
|
|
|
|
|
// purging when a LinksUpdate merely rerenders the same content.
|
|
|
|
|
// This exists to avoid large amounts of redundant PURGE traffic (T250261).
|
|
|
|
|
if ( !$this->fieldHasFlag( $flags, self::PURGE_URLS_LINKSUPDATE_ONLY ) ) {
|
|
|
|
|
$urls[] = $title->getInternalURL( 'action=history' );
|
|
|
|
|
|
2020-08-29 03:55:32 +00:00
|
|
|
// Canonical action=raw URLs for user and site config pages (T58874, T261371).
|
|
|
|
|
if ( $title->isUserJsConfigPage() || $title->isSiteJsConfigPage() ) {
|
2020-04-16 20:44:35 +00:00
|
|
|
$urls[] = $title->getInternalURL( 'action=raw&ctype=text/javascript' );
|
2020-08-29 03:55:32 +00:00
|
|
|
} elseif ( $title->isUserJsonConfigPage() || $title->isSiteJsonConfigPage() ) {
|
2020-04-16 20:44:35 +00:00
|
|
|
$urls[] = $title->getInternalURL( 'action=raw&ctype=application/json' );
|
2020-08-29 03:55:32 +00:00
|
|
|
} elseif ( $title->isUserCssConfigPage() || $title->isSiteCssConfigPage() ) {
|
2020-04-16 20:44:35 +00:00
|
|
|
$urls[] = $title->getInternalURL( 'action=raw&ctype=text/css' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extensions may add novel ways to access this content
|
|
|
|
|
$append = [];
|
|
|
|
|
$mode = $flags & self::PURGE_URLS_LINKSUPDATE_ONLY;
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->hookRunner->onHtmlCacheUpdaterAppendUrls( $title, $mode, $append );
|
2020-04-16 20:44:35 +00:00
|
|
|
$urls = array_merge( $urls, $append );
|
|
|
|
|
|
|
|
|
|
// Extensions may add novel ways to access the site overall
|
|
|
|
|
$append = [];
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->hookRunner->onHtmlCacheUpdaterVaryUrls( $urls, $append );
|
2020-04-16 20:44:35 +00:00
|
|
|
$urls = array_merge( $urls, $append );
|
|
|
|
|
|
|
|
|
|
// Legacy. TODO: Deprecate this
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->hookRunner->onTitleSquidURLs( $title, $urls );
|
2020-04-16 20:44:35 +00:00
|
|
|
|
|
|
|
|
return $urls;
|
|
|
|
|
}
|
2019-03-15 00:23:26 +00:00
|
|
|
}
|