* changes in an incompatible way, so the parser cache
* can automatically discard old data.
*/
-define( 'MW_PARSER_VERSION', '1.5.0' );
+define( 'MW_PARSER_VERSION', '1.6.0' );
/**
* Variable substitution O(N^2) attack
* performs brace substitution on MediaWiki messages
*
* Globals used:
- * objects: $wgLang, $wgLinkCache
+ * objects: $wgLang
*
* NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
*
wfRunHooks( 'ParserClearState', array( &$this ) );
}
- /**
+ /**
* Convert wikitext to HTML
* Do not call this function recursively.
*
* First pass--just handle <nowiki> sections, pass the rest off
* to internalParse() which does all the real work.
*/
-
+
global $wgUseTidy, $wgContLang;
$fname = 'Parser::parse';
wfProfileIn( $fname );
wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
$text = Sanitizer::normalizeCharReferences( $text );
-
+
if ($wgUseTidy) {
$text = Parser::tidy($text);
}
foreach( $gallery_content as $marker => $content ) {
require_once( 'ImageGallery.php' );
if ( $render ) {
- $gallery_content[$marker] = Parser::renderImageGallery( $content );
+ $gallery_content[$marker] = $this->renderImageGallery( $content );
} else {
$gallery_content[$marker] = '<gallery>'.$content.'</gallery>';
}
if ( !is_array( $state ) ) {
return $text;
}
-
+
# Must expand in reverse order, otherwise nested tags will be corrupted
foreach( array_reverse( $state, true ) as $tag => $contentDict ) {
if( $tag != 'nowiki' && $tag != 'html' ) {
$fc = substr ( $x , 0 , 1 ) ;
if ( preg_match( '/^(:*)\{\|(.*)$/', $x, $matches ) ) {
$indent_level = strlen( $matches[1] );
-
+
$attributes = $this->unstripForHTML( $matches[2] );
$t[$k] = str_repeat( '<dl><dd>', $indent_level ) .
$imagesfrom = $this->mOptions->getAllowExternalImagesFrom();
$imagesexception = !empty($imagesfrom);
$text = false;
- if ( $this->mOptions->getAllowExternalImages()
+ if ( $this->mOptions->getAllowExternalImages()
|| ( $imagesexception && strpos( $url, $imagesfrom ) === 0 ) ) {
if ( preg_match( EXT_IMAGE_REGEX, $url ) ) {
# Image found
* @access private
*/
function replaceInternalLinks( $s ) {
- global $wgContLang, $wgLinkCache;
+ global $wgContLang;
static $fname = 'Parser::replaceInternalLinks' ;
wfProfileIn( $fname );
# cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
$s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text ) ) . $trail;
- $this->mOutput->addImage( $nt->getDBkey() );
+ $this->mOutput->addImage( $nt->getDBkey() );
wfProfileOut( "$fname-image" );
continue;
}
return $retVal;
}
-
+
/**
* Render a forced-blue link inline; protect against double expansion of
* URLs if we're in a mode that prepends full URL prefixes to internal links.
$link = $sk->makeKnownLinkObj( $nt, $text, $query, $inside, $prefix );
return $this->armorLinks( $link ) . $trail;
}
-
+
/**
* Insert a NOPARSE hacky thing into any inline links in a chunk that's
* going to go through further parsing steps before inline URL expansion.
case MAG_FULLPAGENAME:
return $this->mTitle->getPrefixedText();
case MAG_FULLPAGENAMEE:
- return wfUrlencode( $this->mTitle->getPrefixedText() );
+ return $this->mTitle->getPrefixedURL();
case MAG_REVISIONID:
return $this->mRevisionId;
case MAG_NAMESPACE:
if ($lastOpeningBrace >= 0) {
$pos = strpos ($text, $openingBraceStack[$lastOpeningBrace]['braceEnd'], $i);
-
+
if (false !== $pos && (-1 == $nextPos || $pos < $nextPos)){
$rule = null;
$nextPos = $pos;
}
$pos = strpos ($text, '|', $i);
-
+
if (false !== $pos && (-1 == $nextPos || $pos < $nextPos)){
$rule = null;
$nextPos = $pos;
'title' => '',
'parts' => null);
- # count openning brace characters
+ # count openning brace characters
while ($i+1 < strlen($text) && $text[$i+1] == $piece['brace']) {
$piece['count']++;
$i++;
}
- $piece['startAt'] = $i+1;
- $piece['partStart'] = $i+1;
+ $piece['startAt'] = $i+1;
+ $piece['partStart'] = $i+1;
# we need to add to stack only if openning brace count is enough for any given rule
foreach ($rule['cb'] as $cnt => $fn) {
$matchingCallback = $fn;
}
}
-
+
if ($matchingCount == 0) {
$i += $count - 1;
continue;
$pieceStart = $openingBraceStack[$lastOpeningBrace]['startAt'] - $matchingCount;
$pieceEnd = $i + $matchingCount;
-
+
if( is_callable( $matchingCallback ) ) {
$cbArgs = array (
'text' => substr($text, $pieceStart, $pieceEnd - $pieceStart),
}
else
$openingBraceStack[$lastOpeningBrace]['parts'][] = substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'], $i - $openingBraceStack[$lastOpeningBrace]['partStart']);
-
+
$openingBraceStack[$lastOpeningBrace]['partStart'] = $i + 1;
}
}
$mwLocalE =& MagicWord::get( MAG_LOCALURLE );
$mwFull =& MagicWord::get( MAG_FULLURL );
$mwFullE =& MagicWord::get( MAG_FULLURLE );
-
+
if ( $mwLocal->matchStartAndRemove( $part1 ) ) {
$func = 'getLocalURL';
# Remove <noinclude> sections and <includeonly> tags
$text = preg_replace( '/<noinclude>.*?<\/noinclude>/s', '', $text );
$text = strtr( $text, array( '<includeonly>' => '' , '</includeonly>' => '' ) );
-
+
if( $this->mOutputType == OT_HTML ) {
# Strip <nowiki>, <pre>, etc.
$text = $this->strip( $text, $this->mStripState );
return $text;
}
}
-
+
/**
* Translude an interwiki link.
*/
# strip out HTML
$canonized_headline = preg_replace( '/<.*?' . '>/','',$canonized_headline );
$tocline = trim( $canonized_headline );
- $canonized_headline = urlencode( Sanitizer::decodeCharReferences( str_replace(' ', '_', $tocline) ) );
- $replacearray = array(
- '%3A' => ':',
- '%' => '.'
- );
- $canonized_headline = str_replace(array_keys($replacearray),array_values($replacearray),$canonized_headline);
+ $canonized_headline = Sanitizer::escapeId( $tocline );
$refers[$headlineCount] = $canonized_headline;
# count how many in assoc. array so we can track dupes in anchors
global $wgLegalTitleChars;
$tc = "[$wgLegalTitleChars]";
$np = str_replace( array( '(', ')' ), array( '', '' ), $tc ); # No parens
-
+
$namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
$conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
return $text;
}
-
+
/**
* Fetch the user's signature text, if any, and normalize to
* validated, ready-to-insert wikitext.
if ( '' == $nick ) {
$nick = $name;
}
-
+
if( $user->getOption( 'fancysig' ) ) {
// A wikitext signature.
$valid = $this->validateSig( $nick );
return $nick;
}
}
-
+
// Plain text linking to the user's homepage
global $wgContLang;
$page = $user->getUserPage();
wfEscapeWikIText( $nick ) .
"]]";
}
-
+
/**
* We want to enforce two rules on wikitext sigs here:
* 1) Expand any templates at save time (forced subst:)
function setHook( $tag, $callback ) {
$oldVal = @$this->mTagHooks[$tag];
$this->mTagHooks[$tag] = $callback;
-
+
return $oldVal;
}
* $options is a bit field, RLH_FOR_UPDATE to select for update
*/
function replaceLinkHolders( &$text, $options = 0 ) {
- global $wgUser, $wgLinkCache;
+ global $wgUser;
global $wgOutputReplace;
$fname = 'Parser::replaceLinkHolders';
$pdbks = array();
$colours = array();
- $sk = $this->mOptions->getSkin();
+ $sk =& $this->mOptions->getSkin();
+ $linkCache =& LinkCache::singleton();
if ( !empty( $this->mLinkHolders['namespaces'] ) ) {
wfProfileIn( $fname.'-check' );
# Check if it's a static known link, e.g. interwiki
if ( $title->isAlwaysKnown() ) {
$colours[$pdbk] = 1;
- } elseif ( ( $id = $wgLinkCache->getGoodLinkID( $pdbk ) ) != 0 ) {
+ } elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) {
$colours[$pdbk] = 1;
$this->mOutput->addLink( $title, $id );
- } elseif ( $wgLinkCache->isBadLink( $pdbk ) ) {
+ } elseif ( $linkCache->isBadLink( $pdbk ) ) {
$colours[$pdbk] = 0;
} else {
# Not in the link cache, add it to the query
while ( $s = $dbr->fetchObject($res) ) {
$title = Title::makeTitle( $s->page_namespace, $s->page_title );
$pdbk = $title->getPrefixedDBkey();
- $wgLinkCache->addGoodLinkObj( $s->page_id, $title );
+ $linkCache->addGoodLinkObj( $s->page_id, $title );
$this->mOutput->addLink( $title, $s->page_id );
if ( $threshold > 0 ) {
$searchkey = "<!--LINK $key-->";
$title = $this->mLinkHolders['titles'][$key];
if ( empty( $colours[$pdbk] ) ) {
- $wgLinkCache->addBadLinkObj( $title );
+ $linkCache->addBadLinkObj( $title );
$colours[$pdbk] = 0;
$this->mOutput->addLink( $title, 0 );
$wgOutputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title,
* given as text will return the HTML of a gallery with two images,
* labeled 'The number "1"' and
* 'A tree'.
- *
- * @static
*/
function renderImageGallery( $text ) {
# Setup the parser
- global $wgTitle;
$parserOptions = new ParserOptions;
$localParser = new Parser();
if ( count( $matches ) == 0 ) {
continue;
}
- $nt = Title::newFromURL( $matches[1] );
+ $nt =& Title::newFromText( $matches[1] );
if( is_null( $nt ) ) {
# Bogus title. Ignore these so we don't bomb out later.
continue;
$label = '';
}
- $html = $localParser->parse( $label , $wgTitle, $parserOptions );
- $html = $html->mText;
+ $pout = $localParser->parse( $label , $this->mTitle, $parserOptions );
+ $html = $pout->getText();
$ig->add( new Image( $nt ), $html );
$this->mOutput->addImage( $nt->getDBkey() );
}
/**
- * Set a flag in the output object indicating that the content is dynamic and
+ * Set a flag in the output object indicating that the content is dynamic and
* shouldn't be cached.
*/
function disableCache() {
$this->mOutput->mCacheTime = -1;
}
-
+
/**
* Callback from the Sanitizer for expanding items found in HTML attribute
* values, so they can be safely tested and escaped.
$text = $this->unstripForHTML( $text );
return $text;
}
-
+
function unstripForHTML( $text ) {
$text = $this->unstrip( $text, $this->mStripState );
$text = $this->unstripNoWiki( $text, $this->mStripState );
function addImage( $name ) { $this->mImages[$name] = 1; }
function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
- function addLink( $title, $id ) {
+ function addLink( $title, $id ) {
$ns = $title->getNamespace();
$dbk = $title->getDBkey();
if ( !isset( $this->mLinks[$ns] ) ) {
$this->mLinks[$ns] = array();
}
- $this->mLinks[$ns][$dbk] = $id;
+ $this->mLinks[$ns][$dbk] = $id;
}
function addTemplate( $title, $id ) {
$ns = $title->getNamespace();
- $dbk = $title->getDBkey();
+ $dbk = $title->getDBkey();
if ( !isset( $this->mTemplates[$ns] ) ) {
$this->mTemplates[$ns] = array();
}
/**
* Get various statistics from the database
- * @private
+ * @access private
*/
function wfLoadSiteStats() {
global $wgNumberOfArticles, $wgTotalViews, $wgTotalEdits;