-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add Cache expiry settings #17
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,14 @@ | |
final class MediaWikiHooks { | ||
|
||
public static function onParserFirstCallInit( Parser $parser ): void { | ||
if ( $parser ) { | ||
if ( self::cacheIsDisabled() ) { | ||
$parser->getOutput()->updateCacheExpiry( 0 ); | ||
// We only need to set the External Content cache expiry if it is lower than the sitewide expiry | ||
} elseif ( is_int( self::getCacheExpiry() ) && !self::hasReducedExpiry() ) { | ||
$parser->getOutput()->updateCacheExpiry( self::getCacheExpiry() ); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The That said, this code should be elsewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the BitbucketFunction and EmbedFunction classes at https://github.com/ProfessionalWiki/ExternalContent/tree/master/src/EntryPoints for the code that handles calls to these parser functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I "don't repeat myself", should the code be added to the EmbedExtensionFactory, and then referenced from the entrypoints? |
||
if ( self::embedFunctionIsEnabled() ) { | ||
$parser->setFunctionHook( | ||
'embed', | ||
|
@@ -32,6 +40,22 @@ public static function onParserFirstCallInit( Parser $parser ): void { | |
} | ||
} | ||
|
||
/** | ||
* Compatibility shim for hasReducedExpiry() coming in 1.37 | ||
*/ | ||
private static function hasReducedExpiry(): bool { | ||
$parserCacheExpireTime = MediaWikiServices::getInstance()->getMainConfig()->get( 'ParserCacheExpireTime' ); | ||
return self::getCacheExpiry() < $parserCacheExpireTime; | ||
} | ||
|
||
private static function cacheIsDisabled(): bool { | ||
return MediaWikiServices::getInstance()->getMainConfig()->get( 'ExternalContentDisableCache' ); | ||
} | ||
|
||
private static function getCacheExpiry(): int { | ||
return MediaWikiServices::getInstance()->getMainConfig()->get( 'ExternalContentDefaultExpiry' ); | ||
} | ||
|
||
/** | ||
* @psalm-suppress MixedInferredReturnType | ||
* @psalm-suppress MixedReturnStatement | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should these be prefixed with 'wg'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With wg
I made it consistent in #18