, , etc.
$text = $this->strip( $text, $this->mStripState );
$text = Sanitizer::removeHTMLtags( $text, array( &$this, 'replaceVariables' ), $assocArgs );
}
$text = $this->replaceVariables( $text, $assocArgs );
# If the template begins with a table or block-level
# element, it should be treated as beginning a new line.
if (!$piece['lineStart'] && preg_match('/^({\\||:|;|#|\*)/', $text)) {
$text = "\n" . $text;
}
} elseif ( !$noargs ) {
# $noparse and !$noargs
# Just replace the arguments, not any double-brace items
# This is used for rendered interwiki transclusion
$text = $this->replaceVariables( $text, $assocArgs, true );
}
}
# Prune lower levels off the recursion check path
$this->mTemplatePath = $lastPathLevel;
if ( !$found ) {
wfProfileOut( $fname );
return $piece['text'];
} else {
if ( $isHTML ) {
# Replace raw HTML by a placeholder
# Add a blank line preceding, to prevent it from mucking up
# immediately preceding headings
$text = "\n\n" . $this->insertStripItem( $text, $this->mStripState );
} else {
# replace ==section headers==
# XXX this needs to go away once we have a better parser.
if ( $this->mOutputType != OT_WIKI && $replaceHeadings ) {
if( !is_null( $title ) )
$encodedname = base64_encode($title->getPrefixedDBkey());
else
$encodedname = base64_encode("");
$m = preg_split('/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1,
PREG_SPLIT_DELIM_CAPTURE);
$text = '';
$nsec = 0;
for( $i = 0; $i < count($m); $i += 2 ) {
$text .= $m[$i];
if (!isset($m[$i + 1]) || $m[$i + 1] == "") continue;
$hl = $m[$i + 1];
if( strstr($hl, "" . $m2[3];
$nsec++;
}
}
}
}
# Prune lower levels off the recursion check path
$this->mTemplatePath = $lastPathLevel;
if ( !$found ) {
wfProfileOut( $fname );
return $piece['text'];
} else {
wfProfileOut( $fname );
return $text;
}
}
/**
* Fetch the unparsed text of a template and register a reference to it.
*/
function fetchTemplate( $title ) {
$text = false;
// Loop to fetch the article, with up to 1 redirect
for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
$rev = Revision::newFromTitle( $title );
$this->mOutput->addTemplate( $title, $title->getArticleID() );
if ( !$rev ) {
break;
}
$text = $rev->getText();
if ( $text === false ) {
break;
}
// Redirect?
$title = Title::newFromRedirect( $text );
}
return $text;
}
/**
* Transclude an interwiki link.
*/
function interwikiTransclude( $title, $action ) {
global $wgEnableScaryTranscluding, $wgCanonicalNamespaceNames;
if (!$wgEnableScaryTranscluding)
return wfMsg('scarytranscludedisabled');
// The namespace will actually only be 0 or 10, depending on whether there was a leading :
// But we'll handle it generally anyway
if ( $title->getNamespace() ) {
// Use the canonical namespace, which should work anywhere
$articleName = $wgCanonicalNamespaceNames[$title->getNamespace()] . ':' . $title->getDBkey();
} else {
$articleName = $title->getDBkey();
}
$url = str_replace('$1', urlencode($articleName), Title::getInterwikiLink($title->getInterwiki()));
$url .= "?action=$action";
if (strlen($url) > 255)
return wfMsg('scarytranscludetoolong');
return $this->fetchScaryTemplateMaybeFromCache($url);
}
function fetchScaryTemplateMaybeFromCache($url) {
global $wgTranscludeCacheExpiry;
$dbr =& wfGetDB(DB_SLAVE);
$obj = $dbr->selectRow('transcache', array('tc_time', 'tc_contents'),
array('tc_url' => $url));
if ($obj) {
$time = $obj->tc_time;
$text = $obj->tc_contents;
if ($time && time() < $time + $wgTranscludeCacheExpiry ) {
return $text;
}
}
$text = wfGetHTTP($url);
if (!$text)
return wfMsg('scarytranscludefailed', $url);
$dbw =& wfGetDB(DB_MASTER);
$dbw->replace('transcache', array('tc_url'), array(
'tc_url' => $url,
'tc_time' => time(),
'tc_contents' => $text));
return $text;
}
/**
* Triple brace replacement -- used for template arguments
* @private
*/
function argSubstitution( $matches ) {
$arg = trim( $matches['title'] );
$text = $matches['text'];
$inputArgs = end( $this->mArgStack );
if ( array_key_exists( $arg, $inputArgs ) ) {
$text = $inputArgs[$arg];
} else if ($this->mOutputType == OT_HTML && null != $matches['parts'] && count($matches['parts']) > 0) {
$text = $matches['parts'][0];
}
return $text;
}
/**
* Returns true if the function is allowed to include this entity
* @private
*/
function incrementIncludeCount( $dbk ) {
if ( !array_key_exists( $dbk, $this->mIncludeCount ) ) {
$this->mIncludeCount[$dbk] = 0;
}
if ( ++$this->mIncludeCount[$dbk] <= MAX_INCLUDE_REPEAT ) {
return true;
} else {
return false;
}
}
/**
* This function accomplishes several tasks:
* 1) Auto-number headings if that option is enabled
* 2) Add an [edit] link to sections for logged in users who have enabled the option
* 3) Add a Table of contents on the top for users who have enabled the option
* 4) Auto-anchor headings
*
* It loops through all headlines, collects the necessary data, then splits up the
* string and re-inserts the newly formatted headlines.
*
* @param string $text
* @param boolean $isMain
* @private
*/
function formatHeadings( $text, $isMain=true ) {
global $wgMaxTocLevel, $wgContLang;
$doNumberHeadings = $this->mOptions->getNumberHeadings();
$doShowToc = true;
$forceTocHere = false;
if( !$this->mTitle->userCanEdit() ) {
$showEditLink = 0;
} else {
$showEditLink = $this->mOptions->getEditSection();
}
# Inhibit editsection links if requested in the page
$esw =& MagicWord::get( MAG_NOEDITSECTION );
if( $esw->matchAndRemove( $text ) ) {
$showEditLink = 0;
}
# if the string __NOTOC__ (not case-sensitive) occurs in the HTML,
# do not add TOC
$mw =& MagicWord::get( MAG_NOTOC );
if( $mw->matchAndRemove( $text ) ) {
$doShowToc = false;
}
# Get all headlines for numbering them and adding funky stuff like [edit]
# links - this is for later, but we need the number of headlines right now
$numMatches = preg_match_all( '/)(.*?)<\/H[1-6] *>/i', $text, $matches );
# if there are fewer than 4 headlines in the article, do not show TOC
if( $numMatches < 4 ) {
$doShowToc = false;
}
# Allow user to stipulate that a page should have a "new section"
# link added via __NEWSECTIONLINK__
$mw =& MagicWord::get( MAG_NEWSECTIONLINK );
if( $mw->matchAndRemove( $text ) )
$this->mOutput->setNewSection( true );
# if the string __TOC__ (not case-sensitive) occurs in the HTML,
# override above conditions and always show TOC at that place
$mw =& MagicWord::get( MAG_TOC );
if($mw->match( $text ) ) {
$doShowToc = true;
$forceTocHere = true;
} else {
# if the string __FORCETOC__ (not case-sensitive) occurs in the HTML,
# override above conditions and always show TOC above first header
$mw =& MagicWord::get( MAG_FORCETOC );
if ($mw->matchAndRemove( $text ) ) {
$doShowToc = true;
}
}
# Never ever show TOC if no headers
if( $numMatches < 1 ) {
$doShowToc = false;
}
# We need this to perform operations on the HTML
$sk =& $this->mOptions->getSkin();
# headline counter
$headlineCount = 0;
$sectionCount = 0; # headlineCount excluding template sections
# Ugh .. the TOC should have neat indentation levels which can be
# passed to the skin functions. These are determined here
$toc = '';
$full = '';
$head = array();
$sublevelCount = array();
$levelCount = array();
$toclevel = 0;
$level = 0;
$prevlevel = 0;
$toclevel = 0;
$prevtoclevel = 0;
foreach( $matches[3] as $headline ) {
$istemplate = 0;
$templatetitle = '';
$templatesection = 0;
$numbering = '';
if (preg_match("//", $headline, $mat)) {
$istemplate = 1;
$templatetitle = base64_decode($mat[1]);
$templatesection = 1 + (int)base64_decode($mat[2]);
$headline = preg_replace("//", "", $headline);
}
if( $toclevel ) {
$prevlevel = $level;
$prevtoclevel = $toclevel;
}
$level = $matches[1][$headlineCount];
if( $doNumberHeadings || $doShowToc ) {
if ( $level > $prevlevel ) {
# Increase TOC level
$toclevel++;
$sublevelCount[$toclevel] = 0;
if( $toclevel<$wgMaxTocLevel ) {
$toc .= $sk->tocIndent();
}
}
elseif ( $level < $prevlevel && $toclevel > 1 ) {
# Decrease TOC level, find level to jump to
if ( $toclevel == 2 && $level <= $levelCount[1] ) {
# Can only go down to level 1
$toclevel = 1;
} else {
for ($i = $toclevel; $i > 0; $i--) {
if ( $levelCount[$i] == $level ) {
# Found last matching level
$toclevel = $i;
break;
}
elseif ( $levelCount[$i] < $level ) {
# Found first matching level below current level
$toclevel = $i + 1;
break;
}
}
}
if( $toclevel<$wgMaxTocLevel ) {
$toc .= $sk->tocUnindent( $prevtoclevel - $toclevel );
}
}
else {
# No change in level, end TOC line
if( $toclevel<$wgMaxTocLevel ) {
$toc .= $sk->tocLineEnd();
}
}
$levelCount[$toclevel] = $level;
# count number of headlines for each level
@$sublevelCount[$toclevel]++;
$dot = 0;
for( $i = 1; $i <= $toclevel; $i++ ) {
if( !empty( $sublevelCount[$i] ) ) {
if( $dot ) {
$numbering .= '.';
}
$numbering .= $wgContLang->formatNum( $sublevelCount[$i] );
$dot = 1;
}
}
}
# The canonized header is a version of the header text safe to use for links
# Avoid insertion of weird stuff like