本文整理汇总了PHP中Parser::incrementExpensiveFunctionCount方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::incrementExpensiveFunctionCount方法的具体用法?PHP Parser::incrementExpensiveFunctionCount怎么用?PHP Parser::incrementExpensiveFunctionCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser::incrementExpensiveFunctionCount方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: inCat
/**
* check if $page belongs to $category
* @param $page Title current page
* @param $category String category to check (not a title object!)
* @param $parser Parser
* @return boolean If $page is a member of $category
*/
private static function inCat( Title $page, $category, Parser $parser ) {
if ( $category === '' ) return false;
$catTitle = Title::makeTitleSafe(
NS_CATEGORY,
$category
);
if ( !$catTitle ) return false;
$catDBkey = $catTitle->getDBkey();
if ( !isset( $parser->pageInCat_cache ) ) {
$parser->pageInCat_cache = array();
} else {
if ( isset( $parser->pageInCat_cache[$catDBkey] ) ) {
# been there done that, return cached value
return $parser->pageInCat_cache[$catDBkey];
} elseif( isset( $parser->pageInCat_onlyCache ) && $parser->pageInCat_onlyCache ) {
# All categories have been preloaded into cache, so
# we must have hit a cat not in page.
# Mark it so can be checked for correctness later.
$parser->PageInCat_cache[$catDBkey] = false;
return false;
}
}
$pageId = $page->getArticleId();
if ( !$pageId ) {
// page hasn't yet been saved (preview)
// add to the cache list so the other hook
// will warn about incorrect value.
// Important to do this after checking cache
// in case categories were pre-loaded during preview.
$parser->pageInCat_cache[$catDBkey] = false;
return false;
}
if ( !$parser->incrementExpensiveFunctionCount() ) {
# expensive function limit reached.
return false;
}
if ( self::inCatCheckDb( $pageId, $catDBkey ) ) {
$parser->pageInCat_cache[$catDBkey] = true;
return true;
} /* else if false */
$parser->pageInCat_cache[$catDBkey] = false;
return false;
}
示例2: tryExecute
/**
* Execute the ParserFunction and throws exceptions if needed
*
* @param array $arguments Array of strings
* @return string output for parser
* @throws \MWException Internal errors + user errors
*/
public function tryExecute($arguments)
{
// if the limit has been exceeded, output is an error message
// an additional warning message is displayed in page edit mode
if (!$this->parser->incrementExpensiveFunctionCount()) {
return 'Expensive function count error.';
}
// initializes
$this->declareParameters();
// tries to set parameters by name
$arguments_without_name = $this->trySetParametersByName($arguments);
// tries to set parameters by order
$this->trySetParametersByOrder($arguments_without_name);
// check all parameters (required, ...)
$this->validate();
// returns the output
return $this->getOutputForParser();
}
示例3: cascadingsources
/**
* 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,
* unless cascading protection sources for the page have already been loaded.
*
* @param Parser $parser
* @param string $title
*
* @return string
* @since 1.23
*/
public static function cascadingsources($parser, $title = '')
{
$titleObject = Title::newFromText($title);
if (!$titleObject instanceof Title) {
$titleObject = $parser->mTitle;
}
if ($titleObject->areCascadeProtectionSourcesLoaded() || $parser->incrementExpensiveFunctionCount()) {
$names = [];
$sources = $titleObject->getCascadeProtectionSources();
foreach ($sources[0] as $sourceTitle) {
$names[] = $sourceTitle->getPrefixedText();
}
return implode($names, '|');
}
return '';
}