Don't always count CASCADINGSOURCES as expensive
authorJackmcbarn <jackmcbarn@gmail.com>
Wed, 15 Jan 2014 21:13:13 +0000 (16:13 -0500)
committerJackmcbarn <jackmcbarn@gmail.com>
Wed, 15 Jan 2014 21:13:13 +0000 (16:13 -0500)
When a page's cascading protection sources have already been loaded, don't
count CASCADINGSOURCES as expensive.

Change-Id: Ia9d25790c534414f637f85d6a3fc4f2c1c0de790

includes/Title.php
includes/parser/CoreParserFunctions.php

index 108cf59..f2de4b8 100644 (file)
@@ -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.
         *
index 98c73dc..35e8bf8 100644 (file)
@@ -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 '';
        }
 
 }