From b2e20f5d57d8488e15824bb3a390760748802df3 Mon Sep 17 00:00:00 2001 From: Jackmcbarn Date: Wed, 15 Jan 2014 16:13:13 -0500 Subject: [PATCH] Don't always count CASCADINGSOURCES as expensive When a page's cascading protection sources have already been loaded, don't count CASCADINGSOURCES as expensive. Change-Id: Ia9d25790c534414f637f85d6a3fc4f2c1c0de790 --- includes/Title.php | 13 +++++++++++++ includes/parser/CoreParserFunctions.php | 13 ++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 108cf597a3..f2de4b8d1f 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2555,6 +2555,19 @@ class Title { return ( $sources > 0 ); } + /** + * Determines whether cascading protection sources have already been loaded from + * the database. + * + * @param bool $getPages True to check if the pages are loaded, or false to check + * if the status is loaded. + * @return bool Whether or not the specified information has been loaded + * @since 1.23 + */ + public function areCascadeProtectionSourcesLoaded( $getPages = true ) { + return $getPages ? isset( $this->mCascadeSources ) : isset( $this->mHasCascadingRestrictions ); + } + /** * Cascading protection: Get the source of any cascading restrictions on this page. * diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 98c73dc8d7..35e8bf84f9 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -1153,7 +1153,8 @@ class CoreParserFunctions { /** * Returns the sources of any cascading protection acting on a specified page. * Pages will not return their own title unless they transclude themselves. - * This is an expensive parser function and can't be called too many times per page. + * This is an expensive parser function and can't be called too many times per page, + * unless cascading protection sources for the page have already been loaded. * * @param Parser $parser * @param string $title @@ -1166,15 +1167,17 @@ class CoreParserFunctions { if ( !( $titleObject instanceof Title ) ) { $titleObject = $parser->mTitle; } - $names = array(); - if ( $parser->incrementExpensiveFunctionCount() ) { + if ( $titleObject->areCascadeProtectionSourcesLoaded() + || $parser->incrementExpensiveFunctionCount() + ) { + $names = array(); $sources = $titleObject->getCascadeProtectionSources(); foreach ( $sources[0] as $sourceTitle ) { $names[] = $sourceTitle->getPrefixedText(); } + return implode( $names, '|' ); } - - return implode( $names, '|' ); + return ''; } } -- 2.20.1