}
$this->mFirstCall = false;
- wfProfileIn( __METHOD__ );
-
CoreParserFunctions::register( $this );
CoreTagHooks::register( $this );
$this->initialiseVariables();
Hooks::run( 'ParserFirstCallInit', array( &$this ) );
- wfProfileOut( __METHOD__ );
}
/**
* @private
*/
public function clearState() {
- wfProfileIn( __METHOD__ );
if ( $this->mFirstCall ) {
$this->firstCallInit();
}
$this->mProfiler = new SectionProfiler();
Hooks::run( 'ParserClearState', array( &$this ) );
- wfProfileOut( __METHOD__ );
}
/**
global $wgShowHostnames;
$fname = __METHOD__ . '-' . wfGetCaller();
- wfProfileIn( __METHOD__ );
- wfProfileIn( $fname );
if ( $clearState ) {
$magicScopeVariable = $this->lock();
$this->mRevisionSize = $oldRevisionSize;
$this->mInputSize = false;
$this->currentRevisionCache = null;
- wfProfileOut( $fname );
- wfProfileOut( __METHOD__ );
return $this->mOutput;
}
* @return string UNSAFE half-parsed HTML
*/
public function recursiveTagParse( $text, $frame = false ) {
- wfProfileIn( __METHOD__ );
Hooks::run( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
Hooks::run( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
$text = $this->internalParse( $text, false, $frame );
- wfProfileOut( __METHOD__ );
return $text;
}
* @return string Fully parsed HTML
*/
public function recursiveTagParseFully( $text, $frame = false ) {
- wfProfileIn( __METHOD__ );
$text = $this->recursiveTagParse( $text, $frame );
$text = $this->internalParseHalfParsed( $text, false );
- wfProfileOut( __METHOD__ );
return $text;
}
public function preprocess( $text, Title $title = null,
ParserOptions $options, $revid = null, $frame = false
) {
- wfProfileIn( __METHOD__ );
$magicScopeVariable = $this->lock();
$this->startParse( $title, $options, self::OT_PREPROCESS, true );
if ( $revid !== null ) {
Hooks::run( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
$text = $this->replaceVariables( $text, $frame );
$text = $this->mStripState->unstripBoth( $text );
- wfProfileOut( __METHOD__ );
return $text;
}
* @since 1.19
*/
public function recursivePreprocess( $text, $frame = false ) {
- wfProfileIn( __METHOD__ );
$text = $this->replaceVariables( $text, $frame );
$text = $this->mStripState->unstripBoth( $text );
- wfProfileOut( __METHOD__ );
return $text;
}
* @return string
*/
public function doTableStuff( $text ) {
- wfProfileIn( __METHOD__ );
$lines = StringUtils::explode( "\n", $text );
$out = '';
$out = '';
}
- wfProfileOut( __METHOD__ );
-
return $out;
}
* @return string
*/
public function internalParse( $text, $isMain = true, $frame = false ) {
- wfProfileIn( __METHOD__ );
$origText = $text;
# Hook to suspend the parser in this state
if ( !Hooks::run( 'ParserBeforeInternalParse', array( &$this, &$text, &$this->mStripState ) ) ) {
- wfProfileOut( __METHOD__ );
return $text;
}
$text = $this->doMagicLinks( $text );
$text = $this->formatHeadings( $text, $origText, $isMain );
- wfProfileOut( __METHOD__ );
return $text;
}
* @return string
*/
public function doMagicLinks( $text ) {
- wfProfileIn( __METHOD__ );
$prots = wfUrlProtocolsWithoutProtRel();
$urlChar = self::EXT_LINK_URL_CLASS;
$space = self::SPACE_NOT_NL; # non-newline space
[0-9Xx] # check digit
)\b
)!xu", array( &$this, 'magicLinkCallback' ), $text );
- wfProfileOut( __METHOD__ );
return $text;
}
* @private
*/
public function makeFreeExternalLink( $url ) {
- wfProfileIn( __METHOD__ );
$trail = '';
$pasteurized = self::normalizeLinkUrl( $url );
$this->mOutput->addExternalLink( $pasteurized );
}
- wfProfileOut( __METHOD__ );
return $text . $trail;
}
* @return string
*/
public function doHeadings( $text ) {
- wfProfileIn( __METHOD__ );
for ( $i = 6; $i >= 1; --$i ) {
$h = str_repeat( '=', $i );
$text = preg_replace( "/^$h(.+)$h\\s*$/m", "<h$i>\\1</h$i>", $text );
}
- wfProfileOut( __METHOD__ );
return $text;
}
* @return string The altered text
*/
public function doAllQuotes( $text ) {
- wfProfileIn( __METHOD__ );
$outtext = '';
$lines = StringUtils::explode( "\n", $text );
foreach ( $lines as $line ) {
$outtext .= $this->doQuotes( $line ) . "\n";
}
$outtext = substr( $outtext, 0, -1 );
- wfProfileOut( __METHOD__ );
return $outtext;
}
* @return string
*/
public function replaceExternalLinks( $text ) {
- wfProfileIn( __METHOD__ );
$bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
if ( $bits === false ) {
- wfProfileOut( __METHOD__ );
throw new MWException( "PCRE needs to be compiled with "
. "--enable-unicode-properties in order for MediaWiki to function" );
}
$this->mOutput->addExternalLink( $pasteurized );
}
- wfProfileOut( __METHOD__ );
return $s;
}
*/
public function replaceInternalLinks2( &$s ) {
global $wgExtraInterlanguageLinkPrefixes;
- wfProfileIn( __METHOD__ );
- wfProfileIn( __METHOD__ . '-setup' );
static $tc = false, $e1, $e1_img;
# the % is needed to support urlencoded titles as well
if ( !$tc ) {
}
if ( is_null( $this->mTitle ) ) {
- wfProfileOut( __METHOD__ . '-setup' );
- wfProfileOut( __METHOD__ );
throw new MWException( __METHOD__ . ": \$this->mTitle is null\n" );
}
$nottalk = !$this->mTitle->isTalkPage();
}
$useSubpages = $this->areSubpagesAllowed();
- wfProfileOut( __METHOD__ . '-setup' );
// @codingStandardsIgnoreStart Squiz.WhiteSpace.SemicolonSpacing.Incorrect
# Loop for each link
}
if ( $useLinkPrefixExtension ) {
- wfProfileIn( __METHOD__ . '-prefixhandling' );
if ( preg_match( $e2, $s, $m ) ) {
$prefix = $m[2];
$s = $m[1];
$prefix = $first_prefix;
$first_prefix = false;
}
- wfProfileOut( __METHOD__ . '-prefixhandling' );
}
$might_be_img = false;
- wfProfileIn( __METHOD__ . "-e1" );
if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
$text = $m[2];
# If we get a ] at the beginning of $m[3] that means we have a link that's something like:
$trail = "";
} else { # Invalid form; output directly
$s .= $prefix . '[[' . $line;
- wfProfileOut( __METHOD__ . "-e1" );
continue;
}
- wfProfileOut( __METHOD__ . "-e1" );
- wfProfileIn( __METHOD__ . "-misc" );
$origLink = $m[1];
# should be external links.
if ( preg_match( '/^(?i:' . $this->mUrlProtocols . ')/', $origLink ) ) {
$s .= $prefix . '[[' . $line;
- wfProfileOut( __METHOD__ . "-misc" );
continue;
}
$link = substr( $link, 1 );
}
- wfProfileOut( __METHOD__ . "-misc" );
- wfProfileIn( __METHOD__ . "-title" );
$nt = Title::newFromText( $this->mStripState->unstripNoWiki( $link ) );
if ( $nt === null ) {
$s .= $prefix . '[[' . $line;
- wfProfileOut( __METHOD__ . "-title" );
continue;
}
$ns = $nt->getNamespace();
$iw = $nt->getInterwiki();
- wfProfileOut( __METHOD__ . "-title" );
if ( $might_be_img ) { # if this is actually an invalid link
- wfProfileIn( __METHOD__ . "-might_be_img" );
if ( $ns == NS_FILE && $noforce ) { # but might be an image
$found = false;
while ( true ) {
$holders->merge( $this->replaceInternalLinks2( $text ) );
$s .= "{$prefix}[[$link|$text";
# note: no $trail, because without an end, there *is* no trail
- wfProfileOut( __METHOD__ . "-might_be_img" );
continue;
}
} else { # it's not an image, so output it raw
$s .= "{$prefix}[[$link|$text";
# note: no $trail, because without an end, there *is* no trail
- wfProfileOut( __METHOD__ . "-might_be_img" );
continue;
}
- wfProfileOut( __METHOD__ . "-might_be_img" );
}
$wasblank = ( $text == '' );
# Link not escaped by : , create the various objects
if ( $noforce && !$nt->wasLocalInterwiki() ) {
# Interwikis
- wfProfileIn( __METHOD__ . "-interwiki" );
if (
$iw && $this->mOptions->getInterwikiMagic() && $nottalk && (
Language::fetchLanguageName( $iw, null, 'mw' ) ||
$s = rtrim( $s . $prefix );
$s .= trim( $trail, "\n" ) == '' ? '': $prefix . $trail;
- wfProfileOut( __METHOD__ . "-interwiki" );
continue;
}
- wfProfileOut( __METHOD__ . "-interwiki" );
if ( $ns == NS_FILE ) {
- wfProfileIn( __METHOD__ . "-image" );
if ( !wfIsBadImage( $nt->getDBkey(), $this->mTitle ) ) {
if ( $wasblank ) {
# if no parameters were passed, $text
} else {
$s .= $prefix . $trail;
}
- wfProfileOut( __METHOD__ . "-image" );
continue;
}
if ( $ns == NS_CATEGORY ) {
- wfProfileIn( __METHOD__ . "-category" );
$s = rtrim( $s . "\n" ); # bug 87
if ( $wasblank ) {
*/
$s .= trim( $prefix . $trail, "\n" ) == '' ? '' : $prefix . $trail;
- wfProfileOut( __METHOD__ . "-category" );
continue;
}
}
# NS_MEDIA is a pseudo-namespace for linking directly to a file
# @todo FIXME: Should do batch file existence checks, see comment below
if ( $ns == NS_MEDIA ) {
- wfProfileIn( __METHOD__ . "-media" );
# Give extensions a chance to select the file revision for us
$options = array();
$descQuery = false;
# Cloak with NOPARSE to avoid replacement in replaceExternalLinks
$s .= $prefix . $this->armorLinks(
Linker::makeMediaLinkFile( $nt, $file, $text ) ) . $trail;
- wfProfileOut( __METHOD__ . "-media" );
continue;
}
- wfProfileIn( __METHOD__ . "-always_known" );
# Some titles, such as valid special pages or files in foreign repos, should
# be shown as bluelinks even though they're not included in the page table
#
# Links will be added to the output link list after checking
$s .= $holders->makeHolder( $nt, $text, array(), $trail, $prefix );
}
- wfProfileOut( __METHOD__ . "-always_known" );
}
- wfProfileOut( __METHOD__ );
return $holders;
}
* @return string The lists rendered as HTML
*/
public function doBlockLevels( $text, $linestart ) {
- wfProfileIn( __METHOD__ );
# Parsing through the text line by line. The main thing
# happening here is handling of block-level elements p, pre,
# If we have no prefixes, go to paragraph mode.
if ( 0 == $prefixLength ) {
- wfProfileIn( __METHOD__ . "-paragraph" );
# No prefix (not in list)--go to paragraph mode
# XXX: use a stack for nestable elements like span, table and div
$openmatch = preg_match(
}
}
}
- wfProfileOut( __METHOD__ . "-paragraph" );
}
# somewhere above we forget to get out of pre block (bug 785)
if ( $preCloseMatch && $this->mInPre ) {
$this->mLastSection = '';
}
- wfProfileOut( __METHOD__ );
return $output;
}
* @return string The position of the ':', or false if none found
*/
public function findColonNoLinks( $str, &$before, &$after ) {
- wfProfileIn( __METHOD__ );
$pos = strpos( $str, ':' );
if ( $pos === false ) {
# Nothing to find!
- wfProfileOut( __METHOD__ );
return false;
}
# Easy; no tag nesting to worry about
$before = substr( $str, 0, $pos );
$after = substr( $str, $pos + 1 );
- wfProfileOut( __METHOD__ );
return $pos;
}
# We found it!
$before = substr( $str, 0, $i );
$after = substr( $str, $i + 1 );
- wfProfileOut( __METHOD__ );
return $i;
}
# Embedded in a tag; don't break it.
$colon = strpos( $str, ':', $i );
if ( $colon === false ) {
# Nothing else interesting
- wfProfileOut( __METHOD__ );
return false;
}
$lt = strpos( $str, '<', $i );
# We found it!
$before = substr( $str, 0, $colon );
$after = substr( $str, $colon + 1 );
- wfProfileOut( __METHOD__ );
return $i;
}
}
$stack--;
if ( $stack < 0 ) {
wfDebug( __METHOD__ . ": Invalid input; too many close tags\n" );
- wfProfileOut( __METHOD__ );
return false;
}
$state = self::COLON_STATE_TEXT;
}
break;
default:
- wfProfileOut( __METHOD__ );
throw new MWException( "State machine error in " . __METHOD__ );
}
}
if ( $stack > 0 ) {
wfDebug( __METHOD__ . ": Invalid input; not enough close tags (stack $stack, state $state)\n" );
- wfProfileOut( __METHOD__ );
return false;
}
- wfProfileOut( __METHOD__ );
return false;
}
* @private
*/
public function initialiseVariables() {
- wfProfileIn( __METHOD__ );
$variableIDs = MagicWord::getVariableIDs();
$substIDs = MagicWord::getSubstIDs();
$this->mVariables = new MagicWordArray( $variableIDs );
$this->mSubstWords = new MagicWordArray( $substIDs );
- wfProfileOut( __METHOD__ );
}
/**
if ( strlen( $text ) < 1 || strlen( $text ) > $this->mOptions->getMaxIncludeSize() ) {
return $text;
}
- wfProfileIn( __METHOD__ );
if ( $frame === false ) {
$frame = $this->getPreprocessor()->newFrame();
$flags = $argsOnly ? PPFrame::NO_TEMPLATES : 0;
$text = $frame->expand( $dom, $flags );
- wfProfileOut( __METHOD__ );
return $text;
}
* @return string The text of the template
*/
public function braceSubstitution( $piece, $frame ) {
- wfProfileIn( __METHOD__ );
- wfProfileIn( __METHOD__ . '-setup' );
// Flags
# @todo FIXME: If piece['parts'] is null then the call to getLength()
# below won't work b/c this $args isn't an object
$args = ( null == $piece['parts'] ) ? array() : $piece['parts'];
- wfProfileOut( __METHOD__ . '-setup' );
$profileSection = null; // profile templates
# SUBST
- wfProfileIn( __METHOD__ . '-modifiers' );
if ( !$found ) {
$substMatch = $this->mSubstWords->matchStartAndRemove( $part1 );
$forceRawInterwiki = true;
}
}
- wfProfileOut( __METHOD__ . '-modifiers' );
# Parser functions
if ( !$found ) {
- wfProfileIn( __METHOD__ . '-pfunc' );
$colonPos = strpos( $part1, ':' );
if ( $colonPos !== false ) {
try {
$result = $this->callParserFunction( $frame, $func, $funcArgs );
} catch ( Exception $ex ) {
- wfProfileOut( __METHOD__ . '-pfunc' );
- wfProfileOut( __METHOD__ );
throw $ex;
}
# here.
extract( $result );
}
- wfProfileOut( __METHOD__ . '-pfunc' );
}
# Finish mangling title and then check for loops.
# Load from database
if ( !$found && $title ) {
$profileSection = $this->mProfiler->scopedProfileIn( $title->getPrefixedDBkey() );
- wfProfileIn( __METHOD__ . '-loadtpl' );
if ( !$title->isExternal() ) {
if ( $title->isSpecialPage()
&& $this->mOptions->getAllowSpecialInclusion()
. '</span>';
wfDebug( __METHOD__ . ": template loop broken at '$titleText'\n" );
}
- wfProfileOut( __METHOD__ . '-loadtpl' );
}
# If we haven't found text to substitute by now, we're done
if ( $profileSection ) {
$this->mProfiler->scopedProfileOut( $profileSection );
}
- wfProfileOut( __METHOD__ );
return array( 'object' => $text );
}
$ret = array( 'text' => $text );
}
- wfProfileOut( __METHOD__ );
return $ret;
}
public function callParserFunction( $frame, $function, array $args = array() ) {
global $wgContLang;
- wfProfileIn( __METHOD__ );
# Case sensitive functions
if ( isset( $this->mFunctionSynonyms[1][$function] ) ) {
if ( isset( $this->mFunctionSynonyms[0][$function] ) ) {
$function = $this->mFunctionSynonyms[0][$function];
} else {
- wfProfileOut( __METHOD__ );
return array( 'found' => false );
}
}
- wfProfileIn( __METHOD__ . '-pfunc-' . $function );
list( $callback, $flags ) = $this->mFunctionHooks[$function];
# Workaround for PHP bug 35229 and similar
if ( !is_callable( $callback ) ) {
- wfProfileOut( __METHOD__ . '-pfunc-' . $function );
- wfProfileOut( __METHOD__ );
throw new MWException( "Tag hook for $function is not callable\n" );
}
$result['text'] = $this->preprocessToDom( $result['text'], $preprocessFlags );
$result['isChildObj'] = true;
}
- wfProfileOut( __METHOD__ . '-pfunc-' . $function );
- wfProfileOut( __METHOD__ );
return $result;
}
* @return array
*/
public function argSubstitution( $piece, $frame ) {
- wfProfileIn( __METHOD__ );
$error = false;
$parts = $piece['parts'];
$ret = array( 'text' => $text );
}
- wfProfileOut( __METHOD__ );
return $ret;
}
* @return string
*/
public function doDoubleUnderscore( $text ) {
- wfProfileIn( __METHOD__ );
# The position of __TOC__ needs to be recorded
$mw = MagicWord::get( 'toc' );
$this->mOutput->setProperty( $key, '' );
}
- wfProfileOut( __METHOD__ );
return $text;
}
# links - this is for later, but we need the number of headlines right now
$matches = array();
$numMatches = preg_match_all(
- '/<H(?P<level>[1-6])(?P<attrib>.*?' . '>)\s*(?P<header>[\s\S]*?)\s*<\/H[1-6] *>/i',
+ '/<H(?P<level>[1-6])(?P<attrib>.*?>)\s*(?P<header>[\s\S]*?)\s*<\/H[1-6] *>/i',
$text,
$matches
);
# to allow setting directionality in toc items.
$tocline = preg_replace(
array(
- '#<(?!/?(span|sup|sub|bdi|i|b)(?: [^>]*)?>).*?' . '>#',
- '#<(/?(?:span(?: dir="(?:rtl|ltr)")?|sup|sub|bdi|i|b))(?: .*?)?' . '>#'
+ '#<(?!/?(span|sup|sub|bdi|i|b)(?: [^>]*)?>).*?>#',
+ '#<(/?(?:span(?: dir="(?:rtl|ltr)")?|sup|sub|bdi|i|b))(?: .*?)?>#'
),
array( '', '<$1>' ),
$safeHeadline
$tocline = trim( $tocline );
# For the anchor, strip out HTML-y stuff period
- $safeHeadline = preg_replace( '/<.*?' . '>/', '', $safeHeadline );
+ $safeHeadline = preg_replace( '/<.*?>/', '', $safeHeadline );
$safeHeadline = Sanitizer::normalizeSectionNameWhitespace( $safeHeadline );
# Save headline for section edit hint before it's escaped
}
# split up and insert constructed headlines
- $blocks = preg_split( '/<H[1-6].*?' . '>[\s\S]*?<\/H[1-6]>/i', $text );
+ $blocks = preg_split( '/<H[1-6].*?>[\s\S]*?<\/H[1-6]>/i', $text );
$i = 0;
// build an array of document sections
}
$executing = true;
- wfProfileIn( __METHOD__ );
if ( !$title ) {
global $wgTitle;
$title = $wgTitle;
$text = $this->preprocess( $text, $title, $options );
$executing = false;
- wfProfileOut( __METHOD__ );
return $text;
}
* @return string HTML
*/
public function renderImageGallery( $text, $params ) {
- wfProfileIn( __METHOD__ );
$mode = false;
if ( isset( $params['mode'] ) ) {
try {
$ig = ImageGalleryBase::factory( $mode );
- } catch ( MWException $e ) {
+ } catch ( Exception $e ) {
// If invalid type set, fallback to default.
$ig = ImageGalleryBase::factory( false );
}
$file = $this->fetchFileNoRegister( $title, $options );
$handler = $file ? $file->getHandler() : false;
- wfProfileIn( __METHOD__ . '-getMagicWord' );
$paramMap = array(
'img_alt' => 'gallery-internal-alt',
'img_link' => 'gallery-internal-link',
}
$mwArray = new MagicWordArray( array_keys( $paramMap ) );
- wfProfileOut( __METHOD__ . '-getMagicWord' );
$label = '';
$alt = '';
}
$html = $ig->toHTML();
Hooks::run( 'AfterParserFetchFileAndTitle', array( $this, $ig, &$html ) );
- wfProfileOut( __METHOD__ );
return $html;
}
*/
public function getRevisionTimestamp() {
if ( is_null( $this->mRevisionTimestamp ) ) {
- wfProfileIn( __METHOD__ );
global $wgContLang;
# it needs to be consistent for all visitors.
$this->mRevisionTimestamp = $wgContLang->userAdjust( $timestamp, '' );
- wfProfileOut( __METHOD__ );
}
return $this->mRevisionTimestamp;
}
* @return array
*/
public function serializeHalfParsedText( $text ) {
- wfProfileIn( __METHOD__ );
$data = array(
'text' => $text,
'version' => self::HALF_PARSED_VERSION,
'stripState' => $this->mStripState->getSubState( $text ),
'linkHolders' => $this->mLinkHolders->getSubArray( $text )
);
- wfProfileOut( __METHOD__ );
return $data;
}