* 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
# may want to use in wikisyntax
define( 'STRIP_COMMENTS', 'HTMLCommentStrip' );
-# prefix for escaping, used in two functions at least
-define( 'UNIQ_PREFIX', 'NaodW29');
-
# Constants needed for external link processing
define( 'HTTP_PROTOCOLS', 'http:\/\/|https:\/\/' );
# Everything except bracket, space, or control characters
-define( 'EXT_LINK_URL_CLASS', '[^]<>"\\x00-\\x20\\x7F]' );
+define( 'EXT_LINK_URL_CLASS', '[^][<>"\\x00-\\x20\\x7F]' );
# Including space
define( 'EXT_LINK_TEXT_CLASS', '[^\]\\x00-\\x1F\\x7F]' );
define( 'EXT_IMAGE_FNAME_CLASS', '[A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]' );
* performs brace substitution on MediaWiki messages
*
* Globals used:
- * objects: $wgLang, $wgLinkCache
+ * objects: $wgLang
*
* NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
*
# Cleared with clearState():
var $mOutput, $mAutonumber, $mDTopen, $mStripState = array();
var $mVariables, $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
- var $mInterwikiLinkHolders, $mLinkHolders;
+ var $mInterwikiLinkHolders, $mLinkHolders, $mUniqPrefix;
# Temporary:
- var $mOptions, $mTitle, $mOutputType,
+ var $mOptions, // ParserOptions object
+ $mTitle, // Title context, used for self-link rendering and similar things
+ $mOutputType, // Output type, one of the OT_xxx constants
$mTemplates, // cache of already loaded templates, avoids
// multiple SQL queries for the same string
- $mTemplatePath; // stores an unsorted hash of all the templates already loaded
+ $mTemplatePath, // stores an unsorted hash of all the templates already loaded
// in this path. Used for loop detection.
-
- var $mIWTransData = array();
+ $mIWTransData = array(),
+ $mRevisionId; // ID to display in {{REVISIONID}} tags
/**#@-*/
'titles' => array()
);
$this->mRevisionId = null;
+ $this->mUniqPrefix = 'UNIQ' . Parser::getRandomString();
+
+ wfRunHooks( 'ParserClearState', array( &$this ) );
}
/**
- * First pass--just handle <nowiki> sections, pass the rest off
- * to internalParse() which does all the real work.
+ * Convert wikitext to HTML
+ * Do not call this function recursively.
*
* @access private
* @param string $text Text we want to parse
* @return ParserOutput a ParserOutput
*/
function parse( $text, &$title, $options, $linestart = true, $clearState = true, $revid = null ) {
+ /**
+ * 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( 'ParserAfterStrip', array( &$this, &$text, &$x ) );
# Hook to suspend the parser in this state
- if ( !wfRunHooks( 'ParserBeforeInternalParse', array( &$this, &$text, &$x ) ) )
+ if ( !wfRunHooks( 'ParserBeforeInternalParse', array( &$this, &$text, &$x ) ) ) {
+ wfProfileOut( $fname );
return $text ;
+ }
$text = $this->internalParse( $text );
wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
$text = Sanitizer::normalizeCharReferences( $text );
-
+
if ($wgUseTidy) {
$text = Parser::tidy($text);
}
$this->mOutput->setText( $text );
wfProfileOut( $fname );
+
return $this->mOutput;
}
$gallery_content = array();
# Replace any instances of the placeholders
- $uniq_prefix = UNIQ_PREFIX;
+ $uniq_prefix = $this->mUniqPrefix;
#$text = str_replace( $uniq_prefix, wfHtmlEscapeFirst( $uniq_prefix ), $text );
# html
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' ) {
* @access private
*/
function insertStripItem( $text, &$state ) {
- $rnd = UNIQ_PREFIX . '-item' . Parser::getRandomString();
+ $rnd = $this->mUniqPrefix . '-item' . Parser::getRandomString();
if ( !$state ) {
$state = array(
'html' => array(),
$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 ) .
# replaceInternalLinks may sometimes leave behind
# absolute URLs, which have to be masked to hide them from replaceExternalLinks
- $text = str_replace(UNIQ_PREFIX."NOPARSE", "", $text);
+ $text = str_replace($this->mUniqPrefix."NOPARSE", "", $text);
$text = $this->doMagicLinks( $text );
$text = $this->doTableStuff( $text );
$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 );
# Interwikis
if( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
- array_push( $this->mOutput->mLanguageLinks, $nt->getFullText() );
+ $this->mOutput->addLanguageLink( $nt->getFullText() );
$s = rtrim($s . "\n");
$s .= trim($prefix . $trail, "\n") == '' ? '': $prefix . $trail;
continue;
$text = $this->replaceInternalLinks($text);
# cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
- $s .= $prefix . preg_replace( "/\b(" . wfUrlProtocols() . ')/', UNIQ_PREFIX."NOPARSE$1", $this->makeImage( $nt, $text) ) . $trail;
- $wgLinkCache->addImageLinkObj( $nt );
+ $s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text ) ) . $trail;
+ $this->mOutput->addImage( $nt->getDBkey() );
wfProfileOut( "$fname-image" );
continue;
if ( $ns == NS_CATEGORY ) {
wfProfileIn( "$fname-category" );
- $t = $wgContLang->convertHtml( $nt->getText() );
$s = rtrim($s . "\n"); # bug 87
- $wgLinkCache->suspend(); # Don't save in links/brokenlinks
- $t = $sk->makeLinkObj( $nt, $t, '', '' , $prefix );
- $wgLinkCache->resume();
-
if ( $wasblank ) {
if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
$sortkey = $this->mTitle->getText();
}
$sortkey = Sanitizer::decodeCharReferences( $sortkey );
$sortkey = $wgContLang->convertCategoryKey( $sortkey );
- $wgLinkCache->addCategoryLinkObj( $nt, $sortkey );
- $this->mOutput->addCategoryLink( $t );
+ $this->mOutput->addCategory( $nt->getDBkey(), $sortkey );
/**
* Strip the whitespace Category links produce, see bug 87
# Special and Media are pseudo-namespaces; no pages actually exist in them
if( $ns == NS_MEDIA ) {
- $s .= $prefix . $sk->makeMediaLinkObj( $nt, $text, true ) . $trail;
- $wgLinkCache->addImageLinkObj( $nt );
+ $link = $sk->makeMediaLinkObj( $nt, $text );
+ # Cloak with NOPARSE to avoid replacement in replaceExternalLinks
+ $s .= $prefix . $this->armorLinks( $link ) . $trail;
+ $this->mOutput->addImage( $nt->getDBkey() );
continue;
} elseif( $ns == NS_SPECIAL ) {
- $s .= $prefix . $sk->makeKnownLinkObj( $nt, $text, '', $trail );
+ $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix );
continue;
} elseif( $ns == NS_IMAGE ) {
$img = Image::newFromTitle( $nt );
// Force a blue link if the file exists; may be a remote
// upload on the shared repository, and we want to see its
// auto-generated page.
- $s .= $prefix . $sk->makeKnownLinkObj( $nt, $text, '', $trail );
+ $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix );
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.
+ * Since this little disaster has to split off the trail text to avoid
+ * breaking URLs in the following text without breaking trails on the
+ * wiki links, it's been made into a horrible function.
+ *
+ * @param Title $nt
+ * @param string $text
+ * @param string $query
+ * @param string $trail
+ * @param string $prefix
+ * @return string HTML-wikitext mix oh yuck
+ */
+ function makeKnownLinkHolder( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
+ list( $inside, $trail ) = Linker::splitTrail( $trail );
+ $sk =& $this->mOptions->getSkin();
+ $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.
+ *
+ * In particular this is important when using action=render, which causes
+ * full URLs to be included.
+ *
+ * Oh man I hate our multi-layer parser!
+ *
+ * @param string more-or-less HTML
+ * @return string less-or-more HTML with NOPARSE bits
+ */
+ function armorLinks( $text ) {
+ return preg_replace( "/\b(" . wfUrlProtocols() . ')/',
+ "{$this->mUniqPrefix}NOPARSE$1", $text );
+ }
+
/**
* Return true if subpage links should be expanded on this page.
* @return bool
if( 0 == $prefixLength ) {
wfProfileIn( "$fname-paragraph" );
# No prefix (not in list)--go to paragraph mode
- $uniq_prefix = UNIQ_PREFIX;
// XXX: use a stack for nestable elements like span, table and div
$openmatch = preg_match('/(<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<p|<ul|<li|<\\/tr|<\\/td|<\\/th)/iS', $t );
$closematch = preg_match(
'/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|'.
- '<td|<th|<div|<\\/div|<hr|<\\/pre|<\\/p|'.$uniq_prefix.'-pre|<\\/li|<\\/ul)/iS', $t );
+ '<td|<th|<div|<\\/div|<hr|<\\/pre|<\\/p|'.$this->mUniqPrefix.'-pre|<\\/li|<\\/ul)/iS', $t );
if ( $openmatch or $closematch ) {
$paragraphStack = false;
$output .= $this->closeParagraph();
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;
}
}
* @access private
*/
function variableSubstitution( $matches ) {
- $fname = 'parser::variableSubstitution';
+ $fname = 'Parser::variableSubstitution';
$varname = $matches[1];
wfProfileIn( $fname );
if ( !$this->mVariables ) {
* @access private
*/
function braceSubstitution( $piece ) {
- global $wgLinkCache, $wgContLang;
+ global $wgContLang;
$fname = 'Parser::braceSubstitution';
wfProfileIn( $fname );
$mwLocalE =& MagicWord::get( MAG_LOCALURLE );
$mwFull =& MagicWord::get( MAG_FULLURL );
$mwFullE =& MagicWord::get( MAG_FULLURLE );
-
+
if ( $mwLocal->matchStartAndRemove( $part1 ) ) {
$func = 'getLocalURL';
$text = $articleContent;
$replaceHeadings = true;
}
+ # Register a template reference whether or not the template exists
+ $this->mOutput->addTemplate( $title, $article->getID() );
}
}
# 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 );
}
$text = $this->replaceVariables( $text, $assocArgs );
- # Resume the link cache and register the inclusion as a link
- if ( $this->mOutputType == OT_HTML && !is_null( $title ) ) {
- $wgLinkCache->addLinkObj( $title );
- }
-
# 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)) {
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' );
# Generate query
$query = false;
- foreach ( $this->mLinkHolders['namespaces'] as $key => $val ) {
+ foreach ( $this->mLinkHolders['namespaces'] as $key => $ns ) {
# Make title object
$title = $this->mLinkHolders['titles'][$key];
}
$pdbk = $pdbks[$key] = $title->getPrefixedDBkey();
- # Check if it's in the link cache already
- if ( $title->isAlwaysKnown() || $wgLinkCache->getGoodLinkID( $pdbk ) ) {
+ # Check if it's a static known link, e.g. interwiki
+ if ( $title->isAlwaysKnown() ) {
$colours[$pdbk] = 1;
- } elseif ( $wgLinkCache->isBadLink( $pdbk ) ) {
+ } elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) {
+ $colours[$pdbk] = 1;
+ $this->mOutput->addLink( $title, $id );
+ } elseif ( $linkCache->isBadLink( $pdbk ) ) {
$colours[$pdbk] = 0;
} else {
# Not in the link cache, add it to the query
if ( !isset( $current ) ) {
- $current = $val;
+ $current = $ns;
$query = "SELECT page_id, page_namespace, page_title";
if ( $threshold > 0 ) {
$query .= ', page_len, page_is_redirect';
}
- $query .= " FROM $page WHERE (page_namespace=$val AND page_title IN(";
- } elseif ( $current != $val ) {
- $current = $val;
- $query .= ")) OR (page_namespace=$val AND page_title IN(";
+ $query .= " FROM $page WHERE (page_namespace=$ns AND page_title IN(";
+ } elseif ( $current != $ns ) {
+ $current = $ns;
+ $query .= ")) OR (page_namespace=$ns AND page_title IN(";
} else {
$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 ) {
$size = $s->page_len;
$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,
$this->mLinkHolders['texts'][$key],
$this->mLinkHolders['queries'][$key] );
* @return string
*/
function replaceLinkHoldersText( $text ) {
- global $wgUser, $wgLinkCache;
+ global $wgUser;
global $wgOutputReplace;
$fname = 'Parser::replaceLinkHoldersText';
* 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 $wgUser, $wgTitle;
- $parserOptions = ParserOptions::newFromUser( $wgUser );
+ $parserOptions = new ParserOptions;
$localParser = new Parser();
- global $wgLinkCache;
$ig = new ImageGallery();
$ig->setShowBytes( false );
$ig->setShowFilename( false );
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 );
- $wgLinkCache->addImageLinkObj( $nt );
+ $this->mOutput->addImage( $nt->getDBkey() );
}
return $ig->toHTML();
}
}
/**
- * 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 );
*/
class ParserOutput
{
- var $mText, $mLanguageLinks, $mCategoryLinks, $mContainsOldMagic;
- var $mCacheTime; # Timestamp on this article, or -1 for uncacheable. Used in ParserCache.
- var $mVersion; # Compatibility check
- var $mTitleText; # title text of the chosen language variant
+ var $mText, # The output text
+ $mLanguageLinks, # List of the full text of language links, in the order they appear
+ $mCategories, # Map of category names to sort keys
+ $mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
+ $mCacheTime, # Timestamp on this article, or -1 for uncacheable. Used in ParserCache.
+ $mVersion, # Compatibility check
+ $mTitleText, # title text of the chosen language variant
+ $mLinks, # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
+ $mTemplates, # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
+ $mImages; # DB keys of the images used, in the array key only
function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
$containsOldMagic = false, $titletext = '' )
{
$this->mText = $text;
$this->mLanguageLinks = $languageLinks;
- $this->mCategoryLinks = $categoryLinks;
+ $this->mCategories = $categoryLinks;
$this->mContainsOldMagic = $containsOldMagic;
$this->mCacheTime = '';
$this->mVersion = MW_PARSER_VERSION;
$this->mTitleText = $titletext;
+ $this->mLinks = array();
+ $this->mTemplates = array();
+ $this->mImages = array();
}
function getText() { return $this->mText; }
function getLanguageLinks() { return $this->mLanguageLinks; }
- function getCategoryLinks() { return array_keys( $this->mCategoryLinks ); }
+ function getCategoryLinks() { return array_keys( $this->mCategories ); }
+ function &getCategories() { return $this->mCategories; }
function getCacheTime() { return $this->mCacheTime; }
function getTitleText() { return $this->mTitleText; }
+ function &getLinks() { return $this->mLinks; }
+ function &getTemplates() { return $this->mTemplates; }
+ function &getImages() { return $this->mImages; }
+
function containsOldMagic() { return $this->mContainsOldMagic; }
function setText( $text ) { return wfSetVar( $this->mText, $text ); }
function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
- function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategoryLinks, $cl ); }
+ function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); }
function setTitleText( $t ) { return wfSetVar ($this->mTitleText, $t); }
- function addCategoryLink( $c ) { $this->mCategoryLinks[$c] = 1; }
+ function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
+ function addImage( $name ) { $this->mImages[$name] = 1; }
+ function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
+
+ function addLink( $title, $id ) {
+ $ns = $title->getNamespace();
+ $dbk = $title->getDBkey();
+ if ( !isset( $this->mLinks[$ns] ) ) {
+ $this->mLinks[$ns] = array();
+ }
+ $this->mLinks[$ns][$dbk] = $id;
+ }
+
+ function addTemplate( $title, $id ) {
+ $ns = $title->getNamespace();
+ $dbk = $title->getDBkey();
+ if ( !isset( $this->mTemplates[$ns] ) ) {
+ $this->mTemplates[$ns] = array();
+ }
+ $this->mTemplates[$ns][$dbk] = $id;
+ }
+ /**
+ * @deprecated
+ */
+ /*
function merge( $other ) {
$this->mLanguageLinks = array_merge( $this->mLanguageLinks, $other->mLanguageLinks );
- $this->mCategoryLinks = array_merge( $this->mCategoryLinks, $this->mLanguageLinks );
+ $this->mCategories = array_merge( $this->mCategories, $this->mLanguageLinks );
$this->mContainsOldMagic = $this->mContainsOldMagic || $other->mContainsOldMagic;
- }
+ }*/
/**
* Return true if this cached output object predates the global or
/**
* Get various statistics from the database
- * @private
+ * @access private
*/
function wfLoadSiteStats() {
global $wgNumberOfArticles, $wgTotalViews, $wgTotalEdits;
/**
* Escape html tags
- * Basicly replacing " > and < with HTML entities ( ", >, <)
+ * Basically replacing " > and < with HTML entities ( ", >, <)
*
* @param string $in Text that might contain HTML tags
* @return string Escaped string