Merge "Make PROTECTIONLEVEL count as expensive"

This commit is contained in:
jenkins-bot 2014-01-15 16:28:11 +00:00 committed by Gerrit Code Review
commit 7c5acbe3f7
2 changed files with 37 additions and 5 deletions

View file

@ -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
*

View file

@ -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 '';
}
/**