[MediaWiki-commits] [Gerrit] Make transcluded special pages not disable cache in miser mode. - change (mediawiki/core)
jenkins-bot has submitted this change and it was merged. Change subject: Make transcluded special pages not disable cache in miser mode. .. Make transcluded special pages not disable cache in miser mode. Previously {{Special:Foo}} would cause parser cache to be disabled, now have a method in SpecialPage to control this behaviour and set arbitrary caching times. Note: This does not affect caching of direct views to the special page The new default is now disabling cache if not in miser mode, otherwise setting to 1 hour, except for Special:Recentchanges and Special:Newpages which set to 5 minutes. These values are possibly really low, but for now I think best to be close to the old behaviour. We had 0 caching for these things for years, and afaik it hasn't caused any big issues. Part of me wonders if Special:Recentchanges should stay at 0, but that sounds crazy. This change also causes transcluded special pages to not be "per-user" if they are being cached (Specificly $wgUser et al become 127.0.0.1). Bug: 60561 Change-Id: Id9ce987adeaa69d886eb1c5cd74c01072583e84d --- M includes/parser/Parser.php M includes/specialpage/SpecialPage.php M includes/specials/SpecialNewpages.php M includes/specials/SpecialRecentchanges.php 4 files changed, 58 insertions(+), 3 deletions(-) Approvals: Aaron Schulz: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index b563613..6c84623 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -3125,6 +3125,7 @@ && $this->mOptions->getAllowSpecialInclusion() && $this->ot['html'] ) { + $specialPage = SpecialPageFactory::getPage( $title->getDBkey() ); // Pass the template arguments as URL parameters. // "uselang" will have no effect since the Language object // is forced to the one defined in ParserOptions. @@ -3143,7 +3144,12 @@ $context = new RequestContext; $context->setTitle( $title ); $context->setRequest( new FauxRequest( $pageArgs ) ); - $context->setUser( $this->getUser() ); + if ( $specialPage && $specialPage->maxIncludeCacheTime() === 0 ) { + $context->setUser( $this->getUser() ); + } else { + // If this page is cached, then we better not be per user. + $context->setUser( User::newFromName( '127.0.0.1', false ) ); + } $context->setLanguage( $this->mOptions->getUserLangObj() ); $ret = SpecialPageFactory::capturePath( $title, $context ); if ( $ret ) { @@ -3151,8 +3157,9 @@ $this->mOutput->addOutputPageMetadata( $context->getOutput() ); $found = true; $isHTML = true; - // Severely reduce cache time to keep content dynamic - $this->mOutput->updateCacheExpiry( 30 ); + if ( $specialPage && $specialPage->maxIncludeCacheTime() !== false ) { + $this->mOutput->updateCacheExpiry( $specialPage->maxIncludeCacheTime() ); + } } } elseif ( MWNamespace::isNonincludable( $title->getNamespace() ) ) { $found = false; # access denied diff --git a/includes/specialpage/SpecialPage.php b/includes/specialpage/SpecialPage.php index 408c726..6624414 100644 --- a/includes/specialpage/SpecialPage.php +++ b/includes/specialpage/SpecialPage.php @@ -176,6 +176,25 @@ } /** +* How long to cache page when it is being included. +* +* @note If cache time is not 0, then the current user becomes an anon +* if you want to do any per-user customizations, than this method +* must be overriden to return 0. +* @since 1.26 +* @return int Time in seconds, 0 to disable caching altogether, +* false to use the parent page's cache settings +*/ + public function
[MediaWiki-commits] [Gerrit] Make transcluded special pages not disable cache in miser mode. - change (mediawiki/core)
Brian Wolff has uploaded a new change for review. https://gerrit.wikimedia.org/r/140945 Change subject: Make transcluded special pages not disable cache in miser mode. .. Make transcluded special pages not disable cache in miser mode. Previously {{Special:Foo}} would cause parser cache to be disabled, now have a method in SpecialPage to control this behaviour and set arbitrary caching times. Note: This does not affect caching of direct views to the special page The new default is now disabling cache if not in miser mode, otherwise setting to 1 hour, except for Special:Recentchanges and Special:Newpages which set to 5 minutes. These values are possibly really low, but for now I think best to be close to the old behaviour. We had 0 caching for these things for years, and afaik it hasn't caused any big issues. Part of me wonders if Special:Recentchanges should stay at 0, but that sounds crazy. This change also causes transcluded special pages to not be per-user if they are being cached (Specificly $wgUser et al become 127.0.0.1). Change-Id: Id9ce987adeaa69d886eb1c5cd74c01072583e84d --- M includes/parser/Parser.php M includes/specialpage/SpecialPage.php M includes/specials/SpecialNewpages.php M includes/specials/SpecialRecentchanges.php 4 files changed, 59 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/45/140945/1 diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index c1fce12..b3623f0 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -3484,6 +3484,7 @@ $this-mOptions-getAllowSpecialInclusion() $this-ot['html'] ) { + $specialPage = SpecialPageFactory::getPage( $title-getDBkey() ); // Pass the template arguments as URL parameters. // uselang will have no effect since the Language object // is forced to the one defined in ParserOptions. @@ -3502,7 +3503,12 @@ $context = new RequestContext; $context-setTitle( $title ); $context-setRequest( new FauxRequest( $pageArgs ) ); - $context-setUser( $this-getUser() ); + if ( $specialPage $specialPage-maxIncludeCacheTime() === 0 ) { + $context-setUser( $this-getUser() ); + } else { + // If this page is cached, then we better not be per user. + $context-setUser( new User ); + } $context-setLanguage( $this-mOptions-getUserLangObj() ); $ret = SpecialPageFactory::capturePath( $title, $context ); if ( $ret ) { @@ -3510,7 +3516,9 @@ $this-mOutput-addOutputPageMetadata( $context-getOutput() ); $found = true; $isHTML = true; - $this-disableCache(); + if ( $specialPage $specialPage-maxIncludeCacheTime() !== false ) { + $this-mOutput-updateCacheExpiry( $specialPage-maxIncludeCacheTime() ); + } } } elseif ( MWNamespace::isNonincludable( $title-getNamespace() ) ) { $found = false; # access denied diff --git a/includes/specialpage/SpecialPage.php b/includes/specialpage/SpecialPage.php index da51a33..bdfc2fa 100644 --- a/includes/specialpage/SpecialPage.php +++ b/includes/specialpage/SpecialPage.php @@ -183,6 +183,25 @@ } /** +* How long to cache page when it is being included. +* +* @note If cache time is not 0, then the current user becomes an anon +* if you want to do any per-user customizations, than this method +* must be overriden to return 0. +* @since 1.24 +* @return int|bool Time in seconds, 0 to disable caching altogether, +* false to use the parent page's cache settings +*/ + public function maxIncludeCacheTime() { + global $wgMiserMode; + if ( $wgMiserMode ) { + return 0; + } else { +