From: Jackmcbarn Date: Mon, 13 Jan 2014 20:01:17 +0000 (-0500) Subject: Make PROTECTIONLEVEL count as expensive X-Git-Tag: 1.31.0-rc.0~17248^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=a87e109e67d76c7bb1640a497973867beb054d35;p=lhc%2Fweb%2Fwiklou.git Make PROTECTIONLEVEL count as expensive When protection levels for a page have not previously loaded, make calls to PROTECTIONLEVEL for that page count as expensive. Also, add new accessors for the protection information. Change-Id: Ic088a9f482154d5353ccf580bbe5c359371a8cdd --- diff --git a/includes/Title.php b/includes/Title.php index 096a04d3fd..108cf597a3 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2655,6 +2655,17 @@ class Title { return array( $sources, $pagerestrictions ); } + /** + * Accessor for mRestrictionsLoaded + * + * @return bool Whether or not the page's restrictions have already been + * loaded from the database + * @since 1.23 + */ + public function areRestrictionsLoaded() { + return $this->mRestrictionsLoaded; + } + /** * Accessor/initialisation for mRestrictions * @@ -2670,6 +2681,21 @@ class Title { : array(); } + /** + * Accessor/initialisation for mRestrictions + * + * @return Array of Arrays of Strings the first level indexed by + * action, the second level containing the names of the groups + * allowed to perform each action + * @since 1.23 + */ + public function getAllRestrictions() { + if ( !$this->mRestrictionsLoaded ) { + $this->loadRestrictions(); + } + return $this->mRestrictions; + } + /** * Get the expiry time for the restriction against a given action * diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index df0f1187cb..87ee1cdd33 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -704,7 +704,10 @@ class CoreParserFunctions { } /** - * Returns the requested protection level for the current page + * Returns the requested protection level for the current page. This + * is an expensive parser function and can't be called too many times + * per page, unless the protection levels for the given title have + * already been retrieved * * @param Parser $parser * @param string $type @@ -717,10 +720,13 @@ class CoreParserFunctions { if ( !( $titleObject instanceof Title ) ) { $titleObject = $parser->mTitle; } - $restrictions = $titleObject->getRestrictions( strtolower( $type ) ); - # Title::getRestrictions returns an array, its possible it may have - # multiple values in the future - return implode( $restrictions, ',' ); + if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) { + $restrictions = $titleObject->getRestrictions( strtolower( $type ) ); + # Title::getRestrictions returns an array, its possible it may have + # multiple values in the future + return implode( $restrictions, ',' ); + } + return ''; } /**