const HALF_PARSED_VERSION = 2;
# Flags for Parser::setFunctionHook
- # Also available as global constants from Defines.php
const SFH_NO_HASH = 1;
const SFH_OBJECT_ARGS = 2;
*/
public $mInParse = false;
+ /** @var SectionProfiler */
+ protected $mProfiler;
+
/**
* @param array $conf
*/
$this->mPreprocessor = null;
}
+ $this->mProfiler = new SectionProfiler();
+
wfRunHooks( 'ParserClearState', array( &$this ) );
wfProfileOut( __METHOD__ );
}
$limitReport = str_replace( array( '-', '&' ), array( '‐', '&' ), $limitReport );
$text .= "\n<!-- \n$limitReport-->\n";
+ // Add on template profiling data
+ $dataByFunc = $this->mProfiler->getFunctionStats();
+ uasort( $dataByFunc, function ( $a, $b ) {
+ return $a['real'] < $b['real']; // descending order
+ } );
+ $profileReport = "Transclusion expansion time report (%,ms,calls,template)\n";
+ foreach ( array_slice( $dataByFunc, 0, 10 ) as $item ) {
+ $profileReport .= sprintf( "%6.2f%% %8.3f %6d - %s\n",
+ $item['%real'], $item['real'], $item['calls'],
+ htmlspecialchars( $item['name'] ) );
+ }
+ $text .= "\n<!-- \n$profileReport-->\n";
+
if ( $this->mGeneratedPPNodeCount > $this->mOptions->getMaxGeneratedPPNodeCount() / 10 ) {
wfDebugLog( 'generated-pp-node-count', $this->mGeneratedPPNodeCount . ' ' .
$this->mTitle->getPrefixedDBkey() );
$args = ( null == $piece['parts'] ) ? array() : $piece['parts'];
wfProfileOut( __METHOD__ . '-setup' );
- $titleProfileIn = null; // profile templates
+ $profileSection = null; // profile templates
# SUBST
wfProfileIn( __METHOD__ . '-modifiers' );
# Load from database
if ( !$found && $title ) {
- if ( !Profiler::instance()->isPersistent() ) {
- # Too many unique items can kill profiling DBs/collectors
- $titleProfileIn = __METHOD__ . "-title-" . $title->getPrefixedDBkey();
- wfProfileIn( $titleProfileIn ); // template in
- }
+ $profileSection = $this->mProfiler->scopedProfileIn( $title->getPrefixedDBkey() );
wfProfileIn( __METHOD__ . '-loadtpl' );
if ( !$title->isExternal() ) {
if ( $title->isSpecialPage()
# Recover the source wikitext and return it
if ( !$found ) {
$text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args );
- if ( $titleProfileIn ) {
- wfProfileOut( $titleProfileIn ); // template out
+ if ( $profileSection ) {
+ $this->mProfiler->scopedProfileOut( $profileSection );
}
wfProfileOut( __METHOD__ );
return array( 'object' => $text );
$isLocalObj = false;
}
- if ( $titleProfileIn ) {
- wfProfileOut( $titleProfileIn ); // template out
+ if ( $profileSection ) {
+ $this->mProfiler->scopedProfileOut( $profileSection );
}
# Replace raw HTML by a placeholder
}
$allArgs = array( &$this );
- if ( $flags & SFH_OBJECT_ARGS ) {
+ if ( $flags & self::SFH_OBJECT_ARGS ) {
# Convert arguments to PPNodes and collect for appending to $allArgs
$funcArgs = array();
foreach ( $args as $k => $v ) {
* The callback function should have the form:
* function myParserFunction( &$parser, $arg1, $arg2, $arg3 ) { ... }
*
- * Or with SFH_OBJECT_ARGS:
+ * Or with Parser::SFH_OBJECT_ARGS:
* function myParserFunction( $parser, $frame, $args ) { ... }
*
* The callback may either return the text result of the function, or an array with the text
* @param string $id The magic word ID
* @param callable $callback The callback function (and object) to use
* @param int $flags A combination of the following flags:
- * SFH_NO_HASH No leading hash, i.e. {{plural:...}} instead of {{#if:...}}
+ * Parser::SFH_NO_HASH No leading hash, i.e. {{plural:...}} instead of {{#if:...}}
*
- * SFH_OBJECT_ARGS Pass the template arguments as PPNode objects instead of text. This
- * allows for conditional expansion of the parse tree, allowing you to eliminate dead
+ * Parser::SFH_OBJECT_ARGS Pass the template arguments as PPNode objects instead of text.
+ * This allows for conditional expansion of the parse tree, allowing you to eliminate dead
* branches and thus speed up parsing. It is also possible to analyse the parse tree of
* the arguments, and to control the way they are expanded.
*
$syn = $wgContLang->lc( $syn );
}
# Add leading hash
- if ( !( $flags & SFH_NO_HASH ) ) {
+ if ( !( $flags & self::SFH_NO_HASH ) ) {
$syn = '#' . $syn;
}
# Remove trailing colon
*
* @param string $text
* @param int $options
- *
- * @return array Array of link CSS classes, indexed by PDBK.
*/
public function replaceLinkHolders( &$text, $options = 0 ) {
- return $this->mLinkHolders->replace( $text );
+ $this->mLinkHolders->replace( $text );
}
/**