summaryrefslogtreecommitdiff
path: root/includes/parser
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2010-07-28 11:52:48 +0200
committerPierre Schmitz <pierre@archlinux.de>2010-07-28 11:52:48 +0200
commit222b01f5169f1c7e69762e0e8904c24f78f71882 (patch)
tree8e932e12546bb991357ec48eb1638d1770be7a35 /includes/parser
parent00ab76a6b686e98a914afc1975812d2b1aaa7016 (diff)
update to MediaWiki 1.16.0
Diffstat (limited to 'includes/parser')
-rw-r--r--includes/parser/CoreParserFunctions.php148
-rw-r--r--includes/parser/CoreTagHooks.php49
-rw-r--r--includes/parser/DateFormatter.php10
-rw-r--r--includes/parser/LinkHolderArray.php3
-rw-r--r--includes/parser/Parser.php1121
-rw-r--r--includes/parser/ParserCache.php75
-rw-r--r--includes/parser/ParserOptions.php27
-rw-r--r--includes/parser/ParserOutput.php31
-rw-r--r--includes/parser/Preprocessor.php15
-rw-r--r--includes/parser/Preprocessor_DOM.php31
-rw-r--r--includes/parser/Preprocessor_Hash.php18
11 files changed, 966 insertions, 562 deletions
diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php
index 774e96a7..8abcc04f 100644
--- a/includes/parser/CoreParserFunctions.php
+++ b/includes/parser/CoreParserFunctions.php
@@ -16,6 +16,7 @@ class CoreParserFunctions {
$parser->setFunctionHook( 'int', array( __CLASS__, 'intFunction' ), SFH_NO_HASH );
$parser->setFunctionHook( 'ns', array( __CLASS__, 'ns' ), SFH_NO_HASH );
+ $parser->setFunctionHook( 'nse', array( __CLASS__, 'nse' ), SFH_NO_HASH );
$parser->setFunctionHook( 'urlencode', array( __CLASS__, 'urlencode' ), SFH_NO_HASH );
$parser->setFunctionHook( 'lcfirst', array( __CLASS__, 'lcfirst' ), SFH_NO_HASH );
$parser->setFunctionHook( 'ucfirst', array( __CLASS__, 'ucfirst' ), SFH_NO_HASH );
@@ -67,7 +68,7 @@ class CoreParserFunctions {
$parser->setFunctionHook( 'subjectpagename', array( __CLASS__, 'subjectpagename' ), SFH_NO_HASH );
$parser->setFunctionHook( 'subjectpagenamee', array( __CLASS__, 'subjectpagenamee' ), SFH_NO_HASH );
$parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS );
- $parser->setFunctionHook( 'formatdate', array( __CLASS__, 'formatDate' ) );
+ $parser->setFunctionHook( 'formatdate', array( __CLASS__, 'formatDate' ) );
if ( $wgAllowDisplayTitle ) {
$parser->setFunctionHook( 'displaytitle', array( __CLASS__, 'displaytitle' ), SFH_NO_HASH );
@@ -88,20 +89,20 @@ class CoreParserFunctions {
return array( 'found' => false );
}
}
-
+
static function formatDate( $parser, $date, $defaultPref = null ) {
$df = DateFormatter::getInstance();
-
- $date = trim($date);
-
+
+ $date = trim( $date );
+
$pref = $parser->mOptions->getDateFormat();
-
+
// Specify a different default date format other than the the normal default
- // iff the user has 'default' for their setting
- if ($pref == 'default' && $defaultPref)
+ // iff the user has 'default' for their setting
+ if ( $pref == 'default' && $defaultPref )
$pref = $defaultPref;
-
- $date = $df->reformat( $pref, $date, array('match-whole') );
+
+ $date = $df->reformat( $pref, $date, array( 'match-whole' ) );
return $date;
}
@@ -119,6 +120,10 @@ class CoreParserFunctions {
}
}
+ static function nse( $parser, $part1 = '' ) {
+ return wfUrlencode( str_replace( ' ', '_', self::ns( $parser, $part1 ) ) );
+ }
+
static function urlencode( $parser, $s = '' ) {
return urlencode( $s );
}
@@ -163,11 +168,11 @@ class CoreParserFunctions {
# and the variable will fail. If we can't get a decent title from the first
# attempt, url-decode and try for a second.
if( is_null( $title ) )
- $title = Title::newFromUrl( urldecode( $s ) );
+ $title = Title::newFromURL( urldecode( $s ) );
if( !is_null( $title ) ) {
# Convert NS_MEDIA -> NS_FILE
if( $title->getNamespace() == NS_MEDIA ) {
- $title = Title::makeTitle( NS_FILE, $title->getDBKey() );
+ $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
}
if( !is_null( $arg ) ) {
$text = $title->$func( $arg );
@@ -193,15 +198,16 @@ class CoreParserFunctions {
}
static function gender( $parser, $user ) {
+ wfProfileIn( __METHOD__ );
$forms = array_slice( func_get_args(), 2);
// default
$gender = User::getDefaultOption( 'gender' );
-
+
// allow prefix.
$title = Title::newFromText( $user );
-
- if (is_object( $title ) && $title->getNamespace() == NS_USER)
+
+ if ( is_object( $title ) && $title->getNamespace() == NS_USER )
$user = $title->getText();
// check parameter, or use $wgUser if in interface message
@@ -212,10 +218,12 @@ class CoreParserFunctions {
global $wgUser;
$gender = $wgUser->getOption( 'gender' );
}
- return $parser->getFunctionLang()->gender( $gender, $forms );
+ $ret = $parser->getFunctionLang()->gender( $gender, $forms );
+ wfProfileOut( __METHOD__ );
+ return $ret;
}
- static function plural( $parser, $text = '') {
- $forms = array_slice( func_get_args(), 2);
+ static function plural( $parser, $text = '' ) {
+ $forms = array_slice( func_get_args(), 2 );
$text = $parser->getFunctionLang()->parseFormattedNumber( $text );
return $parser->getFunctionLang()->convertPlural( $text, $forms );
}
@@ -224,21 +232,39 @@ class CoreParserFunctions {
* Override the title of the page when viewed, provided we've been given a
* title which will normalise to the canonical title
*
- * @param Parser $parser Parent parser
- * @param string $text Desired title text
- * @return string
+ * @param $parser Parser: parent parser
+ * @param $text String: desired title text
+ * @return String
*/
static function displaytitle( $parser, $text = '' ) {
global $wgRestrictDisplayTitle;
- $text = trim( Sanitizer::decodeCharReferences( $text ) );
- if ( !$wgRestrictDisplayTitle ) {
+ #parse a limited subset of wiki markup (just the single quote items)
+ $text = $parser->doQuotes( $text );
+
+ #remove stripped text (e.g. the UNIQ-QINU stuff) that was generated by tag extensions/whatever
+ $text = preg_replace( '/' . preg_quote( $parser->uniqPrefix(), '/' ) . '.*?'
+ . preg_quote( Parser::MARKER_SUFFIX, '/' ) . '/', '', $text );
+
+ #list of disallowed tags for DISPLAYTITLE
+ #these will be escaped even though they are allowed in normal wiki text
+ $bad = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'blockquote', 'ol', 'ul', 'li', 'hr',
+ 'table', 'tr', 'th', 'td', 'dl', 'dd', 'caption', 'p', 'ruby', 'rb', 'rt', 'rp', 'br' );
+
+ #only requested titles that normalize to the actual title are allowed through
+ #if $wgRestrictDisplayTitle is true (it is by default)
+ #mimic the escaping process that occurs in OutputPage::setPageTitle
+ $text = Sanitizer::normalizeCharReferences( Sanitizer::removeHTMLtags( $text, null, array(), array(), $bad ) );
+ $title = Title::newFromText( Sanitizer::stripAllTags( $text ) );
+
+ if( !$wgRestrictDisplayTitle ) {
$parser->mOutput->setDisplayTitle( $text );
} else {
- $title = Title::newFromText( $text );
- if( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) )
+ if ( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) ) {
$parser->mOutput->setDisplayTitle( $text );
+ }
}
+
return '';
}
@@ -291,9 +317,9 @@ class CoreParserFunctions {
}
static function numberingroup( $parser, $name = '', $raw = null) {
return self::formatRaw( SiteStats::numberingroup( strtolower( $name ) ), $raw );
- }
+ }
+
-
/**
* Given a title, return the namespace name that would be given by the
* corresponding magic word
@@ -302,37 +328,37 @@ class CoreParserFunctions {
*/
static function mwnamespace( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return str_replace( '_', ' ', $t->getNsText() );
}
static function namespacee( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return wfUrlencode( $t->getNsText() );
}
static function talkspace( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) || !$t->canTalk() )
+ if ( is_null( $t ) || !$t->canTalk() )
return '';
return str_replace( '_', ' ', $t->getTalkNsText() );
}
static function talkspacee( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) || !$t->canTalk() )
+ if ( is_null( $t ) || !$t->canTalk() )
return '';
return wfUrlencode( $t->getTalkNsText() );
}
static function subjectspace( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return str_replace( '_', ' ', $t->getSubjectNsText() );
}
static function subjectspacee( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return wfUrlencode( $t->getSubjectNsText() );
}
@@ -342,77 +368,77 @@ class CoreParserFunctions {
*/
static function pagename( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return wfEscapeWikiText( $t->getText() );
}
static function pagenamee( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return $t->getPartialURL();
}
static function fullpagename( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) || !$t->canTalk() )
+ if ( is_null( $t ) || !$t->canTalk() )
return '';
return wfEscapeWikiText( $t->getPrefixedText() );
}
static function fullpagenamee( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) || !$t->canTalk() )
+ if ( is_null( $t ) || !$t->canTalk() )
return '';
return $t->getPrefixedURL();
}
static function subpagename( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return $t->getSubpageText();
}
static function subpagenamee( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return $t->getSubpageUrlForm();
}
static function basepagename( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return $t->getBaseText();
}
static function basepagenamee( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return wfUrlEncode( str_replace( ' ', '_', $t->getBaseText() ) );
- }
+ }
static function talkpagename( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) || !$t->canTalk() )
+ if ( is_null( $t ) || !$t->canTalk() )
return '';
return wfEscapeWikiText( $t->getTalkPage()->getPrefixedText() );
}
static function talkpagenamee( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) || !$t->canTalk() )
+ if ( is_null( $t ) || !$t->canTalk() )
return '';
return $t->getTalkPage()->getPrefixedUrl();
}
static function subjectpagename( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedText() );
}
static function subjectpagenamee( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null($t) )
+ if ( is_null( $t ) )
return '';
return $t->getSubjectPage()->getPrefixedUrl();
}
-
+
/**
* Return the number of pages in the given category, or 0 if it's nonexis-
* tent. This is an expensive parser function and can't be called too many
@@ -443,16 +469,16 @@ class CoreParserFunctions {
* Return the size of the given page, or 0 if it's nonexistent. This is an
* expensive parser function and can't be called too many times per page.
*
- * @FIXME This doesn't work correctly on preview for getting the size of
- * the current page.
- * @FIXME Title::getLength() documentation claims that it adds things to
- * the link cache, so the local cache here should be unnecessary, but in
- * fact calling getLength() repeatedly for the same $page does seem to
+ * @todo Fixme: This doesn't work correctly on preview for getting the size
+ * of the current page.
+ * @todo Fixme: Title::getLength() documentation claims that it adds things
+ * to the link cache, so the local cache here should be unnecessary, but
+ * in fact calling getLength() repeatedly for the same $page does seem to
* run one query for each call?
*/
static function pagesize( $parser, $page = '', $raw = null ) {
static $cache = array();
- $title = Title::newFromText($page);
+ $title = Title::newFromText( $page );
if( !is_object( $title ) ) {
$cache[$page] = 0;
@@ -466,16 +492,16 @@ class CoreParserFunctions {
if( isset( $cache[$page] ) ) {
$length = $cache[$page];
} elseif( $parser->incrementExpensiveFunctionCount() ) {
- $rev = Revision::newFromTitle($title);
+ $rev = Revision::newFromTitle( $title );
$id = $rev ? $rev->getPage() : 0;
$length = $cache[$page] = $rev ? $rev->getSize() : 0;
-
+
// Register dependency in templatelinks
$parser->mOutput->addTemplate( $title, $id, $rev ? $rev->getId() : 0 );
- }
+ }
return self::formatRaw( $length, $raw );
}
-
+
/**
* Returns the requested protection level for the current page
*/
@@ -496,12 +522,12 @@ class CoreParserFunctions {
* Unicode-safe str_pad with the restriction that $length is forced to be <= 500
*/
static function pad( $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) {
- $lengthOfPadding = mb_strlen( $padding );
+ $lengthOfPadding = mb_strlen( $padding );
if ( $lengthOfPadding == 0 ) return $string;
-
+
# The remaining length to add counts down to 0 as padding is added
$length = min( $length, 500 ) - mb_strlen( $string );
- # $finalPadding is just $padding repeated enough times so that
+ # $finalPadding is just $padding repeated enough times so that
# mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
$finalPadding = '';
while ( $length > 0 ) {
@@ -510,7 +536,7 @@ class CoreParserFunctions {
$finalPadding .= mb_substr( $padding, 0, $length );
$length -= $lengthOfPadding;
}
-
+
if ( $direction == STR_PAD_LEFT ) {
return $finalPadding . $string;
} else {
diff --git a/includes/parser/CoreTagHooks.php b/includes/parser/CoreTagHooks.php
new file mode 100644
index 00000000..7cc8260e
--- /dev/null
+++ b/includes/parser/CoreTagHooks.php
@@ -0,0 +1,49 @@
+<?php
+
+class CoreTagHooks {
+ static function register( $parser ) {
+ global $wgRawHtml, $wgUseTeX;
+ $parser->setHook( 'pre', array( __CLASS__, 'pre' ) );
+ $parser->setHook( 'nowiki', array( __CLASS__, 'nowiki' ) );
+ $parser->setHook( 'gallery', array( __CLASS__, 'gallery' ) );
+ if ( $wgRawHtml ) {
+ $parser->setHook( 'html', array( __CLASS__, 'html' ) );
+ }
+ if ( $wgUseTeX ) {
+ $parser->setHook( 'math', array( __CLASS__, 'math' ) );
+ }
+ }
+
+ static function pre( $text, $attribs, $parser ) {
+ // Backwards-compatibility hack
+ $content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' );
+
+ $attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' );
+ return Xml::openElement( 'pre', $attribs ) .
+ Xml::escapeTagsOnly( $content ) .
+ '</pre>';
+ }
+
+ static function html( $content, $attributes, $parser ) {
+ global $wgRawHtml;
+ if( $wgRawHtml ) {
+ return array( $content, 'markerType' => 'nowiki' );
+ } else {
+ throw new MWException( '<html> extension tag encountered unexpectedly' );
+ }
+ }
+
+ static function nowiki( $content, $attributes, $parser ) {
+ $content = strtr( $content, array( '-{' => '-&#123;', '}-' => '&#125;-' ) );
+ return array( Xml::escapeTagsOnly( $content ), 'markerType' => 'nowiki' );
+ }
+
+ static function math( $content, $attributes, $parser ) {
+ global $wgContLang;
+ return $wgContLang->armourMath( MathRenderer::renderMath( $content, $attributes ) );
+ }
+
+ static function gallery( $content, $attributes, $parser ) {
+ return $parser->renderImageGallery( $content, $attributes );
+ }
+}
diff --git a/includes/parser/DateFormatter.php b/includes/parser/DateFormatter.php
index aa6415e4..602bcff3 100644
--- a/includes/parser/DateFormatter.php
+++ b/includes/parser/DateFormatter.php
@@ -48,10 +48,10 @@ class DateFormatter
$this->prxISO2 = '\[\[(-?\d{4})-(\d{2})-(\d{2})\]\]';
# Real regular expressions
- $this->regexes[self::DMY] = "/{$this->prxDM} *,? *{$this->prxY}{$this->regexTrail}";
- $this->regexes[self::YDM] = "/{$this->prxY} *,? *{$this->prxDM}{$this->regexTrail}";
- $this->regexes[self::MDY] = "/{$this->prxMD} *,? *{$this->prxY}{$this->regexTrail}";
- $this->regexes[self::YMD] = "/{$this->prxY} *,? *{$this->prxMD}{$this->regexTrail}";
+ $this->regexes[self::DMY] = "/{$this->prxDM}(?: *, *| +){$this->prxY}{$this->regexTrail}";
+ $this->regexes[self::YDM] = "/{$this->prxY}(?: *, *| +){$this->prxDM}{$this->regexTrail}";
+ $this->regexes[self::MDY] = "/{$this->prxMD}(?: *, *| +){$this->prxY}{$this->regexTrail}";
+ $this->regexes[self::YMD] = "/{$this->prxY}(?: *, *| +){$this->prxMD}{$this->regexTrail}";
$this->regexes[self::DM] = "/{$this->prxDM}{$this->regexTrail}";
$this->regexes[self::MD] = "/{$this->prxMD}{$this->regexTrail}";
$this->regexes[self::ISO1] = "/{$this->prxISO1}{$this->regexTrail}";
@@ -268,7 +268,7 @@ class DateFormatter
$isoDate = implode( '-', $isoBits );;
// Output is not strictly HTML (it's wikitext), but <span> is whitelisted.
- $text = Xml::tags( 'span',
+ $text = Html::rawElement( 'span',
array( 'class' => 'mw-formatted-date', 'title' => $isoDate ), $text );
return $text;
diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php
index 35b672b9..4f382a4f 100644
--- a/includes/parser/LinkHolderArray.php
+++ b/includes/parser/LinkHolderArray.php
@@ -105,6 +105,7 @@ class LinkHolderArray {
}
/**
+ * FIXME: update documentation. makeLinkObj() is deprecated.
* Replace <!--LINK--> link placeholders with actual links, in the buffer
* Placeholders created in Skin::makeLinkObj()
* Returns an array of link CSS classes, indexed by PDBK.
@@ -228,10 +229,12 @@ class LinkHolderArray {
$linkCache->addBadLinkObj( $title );
$colours[$pdbk] = 'new';
$output->addLink( $title, 0 );
+ // FIXME: replace deprecated makeBrokenLinkObj() by link()
$replacePairs[$searchkey] = $sk->makeBrokenLinkObj( $title,
$entry['text'],
$query );
} else {
+ // FIXME: replace deprecated makeColouredLinkObj() by link()
$replacePairs[$searchkey] = $sk->makeColouredLinkObj( $title, $colours[$pdbk],
$entry['text'],
$query );
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index e6a68782..4f672f5b 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -91,8 +91,9 @@ class Parser
*/
# Persistent:
var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables,
- $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex, $mPreprocessor,
- $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList, $mVarCache, $mConf;
+ $mSubstWords, $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex,
+ $mPreprocessor, $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList,
+ $mVarCache, $mConf, $mFunctionTagHooks;
# Cleared with clearState():
@@ -103,7 +104,6 @@ class Parser
var $mTplExpandCache; // empty-frame expansion cache
var $mTplRedirCache, $mTplDomCache, $mHeadings, $mDoubleUnderscores;
var $mExpensiveFunctionCount; // number of expensive parser function calls
- var $mFileCache;
# Temporary
# These are variables reset at least once per parse regardless of $clearState
@@ -127,8 +127,9 @@ class Parser
$this->mTagHooks = array();
$this->mTransparentTagHooks = array();
$this->mFunctionHooks = array();
+ $this->mFunctionTagHooks = array();
$this->mFunctionSynonyms = array( 0 => array(), 1 => array() );
- $this->mDefaultStripList = $this->mStripList = array( 'nowiki', 'gallery' );
+ $this->mDefaultStripList = $this->mStripList = array();
$this->mUrlProtocols = wfUrlProtocols();
$this->mExtLinkBracketedRegex = '/\[(\b(' . wfUrlProtocols() . ')'.
'[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x0a\\x0d]*?)\]/S';
@@ -171,8 +172,8 @@ class Parser
wfProfileIn( __METHOD__ );
- $this->setHook( 'pre', array( $this, 'renderPreTag' ) );
CoreParserFunctions::register( $this );
+ CoreTagHooks::register( $this );
$this->initialiseVariables();
wfRunHooks( 'ParserFirstCallInit', array( &$this ) );
@@ -200,6 +201,7 @@ class Parser
$this->mLinkHolders = new LinkHolderArray( $this );
$this->mLinkID = 0;
$this->mRevisionTimestamp = $this->mRevisionId = null;
+ $this->mVarCache = array();
/**
* Prefix for temporary replacement strings for the multipass parser.
@@ -230,7 +232,6 @@ class Parser
$this->mHeadings = array();
$this->mDoubleUnderscores = array();
$this->mExpensiveFunctionCount = 0;
- $this->mFileCache = array();
# Fix cloning
if ( isset( $this->mPreprocessor ) && $this->mPreprocessor->parser !== $this ) {
@@ -255,9 +256,10 @@ class Parser
* Set the context title
*/
function setTitle( $t ) {
- if ( !$t || $t instanceof FakeTitle ) {
- $t = Title::newFromText( 'NO TITLE' );
- }
+ if ( !$t || $t instanceof FakeTitle ) {
+ $t = Title::newFromText( 'NO TITLE' );
+ }
+
if ( strval( $t->getFragment() ) !== '' ) {
# Strip the fragment to avoid various odd effects
$this->mTitle = clone $t;
@@ -274,7 +276,7 @@ class Parser
*/
function uniqPrefix() {
if( !isset( $this->mUniqPrefix ) ) {
- // @fixme this is probably *horribly wrong*
+ // @todo Fixme: this is probably *horribly wrong*
// LanguageConverter seems to want $wgParser's uniqPrefix, however
// if this is called for a parser cache hit, the parser may not
// have ever been initialized in the first place.
@@ -303,7 +305,7 @@ class Parser
* to internalParse() which does all the real work.
*/
- global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang;
+ global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang, $wgDisableLangConversion, $wgDisableTitleConversion;
$fname = __METHOD__.'-' . wfGetCaller();
wfProfileIn( __METHOD__ );
wfProfileIn( $fname );
@@ -313,7 +315,8 @@ class Parser
}
$this->mOptions = $options;
- $this->setTitle( $title );
+ $this->setTitle( $title ); // Page title has to be set for the pre-processor
+
$oldRevisionId = $this->mRevisionId;
$oldRevisionTimestamp = $this->mRevisionTimestamp;
if( $revid !== null ) {
@@ -325,6 +328,7 @@ class Parser
# No more strip!
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
$text = $this->internalParse( $text );
+
$text = $this->mStripState->unstripGeneral( $text );
# Clean up special characters, only run once, next-to-last before doBlockLevels
@@ -342,11 +346,51 @@ class Parser
$this->replaceLinkHolders( $text );
- # the position of the parserConvert() call should not be changed. it
- # assumes that the links are all replaced and the only thing left
- # is the <nowiki> mark.
- # Side-effects: this calls $this->mOutput->setTitleText()
- $text = $wgContLang->parserConvert( $text, $this );
+ /**
+ * The page doesn't get language converted if
+ * a) It's disabled
+ * b) Content isn't converted
+ * c) It's a conversion table
+ */
+ if ( !( $wgDisableLangConversion
+ || isset( $this->mDoubleUnderscores['nocontentconvert'] )
+ || $this->mTitle->isConversionTable() ) ) {
+
+ # The position of the convert() call should not be changed. it
+ # assumes that the links are all replaced and the only thing left
+ # is the <nowiki> mark.
+
+ $text = $wgContLang->convert( $text );
+ }
+
+ /**
+ * A page get its title converted except:
+ * a) Language conversion is globally disabled
+ * b) Title convert is globally disabled
+ * c) The page is a redirect page
+ * d) User request with a "linkconvert" set to "no"
+ * e) A "nocontentconvert" magic word has been set
+ * f) A "notitleconvert" magic word has been set
+ * g) User sets "noconvertlink" in his/her preference
+ *
+ * Note that if a user tries to set a title in a conversion
+ * rule but content conversion was not done, then the parser
+ * won't pick it up. This is probably expected behavior.
+ */
+ if ( !( $wgDisableLangConversion
+ || $wgDisableTitleConversion
+ || isset( $this->mDoubleUnderscores['nocontentconvert'] )
+ || isset( $this->mDoubleUnderscores['notitleconvert'] )
+ || $this->mOutput->getDisplayTitle() !== false ) )
+ {
+ $convruletitle = $wgContLang->getConvRuleTitle();
+ if ( $convruletitle ) {
+ $this->mOutput->setTitleText( $convruletitle );
+ } else {
+ $titleText = $wgContLang->convertTitle( $title );
+ $this->mOutput->setTitleText( $titleText );
+ }
+ }
$text = $this->mStripState->unstripNoWiki( $text );
@@ -412,7 +456,6 @@ class Parser
# Information on include size limits, for the benefit of users who try to skirt them
if ( $this->mOptions->getEnableLimitReport() ) {
- global $wgExpensiveParserFunctionLimit;
$max = $this->mOptions->getMaxIncludeSize();
$PFreport = "Expensive parser function count: {$this->mExpensiveFunctionCount}/$wgExpensiveParserFunctionLimit\n";
$limitReport =
@@ -425,6 +468,7 @@ class Parser
$text .= "\n<!-- \n$limitReport-->\n";
}
$this->mOutput->setText( $text );
+
$this->mRevisionId = $oldRevisionId;
$this->mRevisionTimestamp = $oldRevisionTimestamp;
wfProfileOut( $fname );
@@ -436,12 +480,17 @@ class Parser
/**
* Recursive parser entry point that can be called from an extension tag
* hook.
+ *
+ * If $frame is not provided, then template variables (e.g., {{{1}}}) within $text are not expanded
+ *
+ * @param $text String: text extension wants to have parsed
+ * @param PPFrame $frame: The frame to use for expanding any template variables
*/
- function recursiveTagParse( $text ) {
+ function recursiveTagParse( $text, $frame=false ) {
wfProfileIn( __METHOD__ );
wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
- $text = $this->internalParse( $text );
+ $text = $this->internalParse( $text, false, $frame );
wfProfileOut( __METHOD__ );
return $text;
}
@@ -529,9 +578,9 @@ class Parser
$matches = array();
$taglist = implode( '|', $elements );
- $start = "/<($taglist)(\\s+[^>]*?|\\s*?)(\/?>)|<(!--)/i";
+ $start = "/<($taglist)(\\s+[^>]*?|\\s*?)(\/?" . ">)|<(!--)/i";
- while ( '' != $text ) {
+ while ( $text != '' ) {
$p = preg_split( $start, $text, 2, PREG_SPLIT_DELIM_CAPTURE );
$stripped .= $p[0];
if( count( $p ) < 5 ) {
@@ -589,15 +638,7 @@ class Parser
* Get a list of strippable XML-like elements
*/
function getStripList() {
- global $wgRawHtml;
- $elements = $this->mStripList;
- if( $wgRawHtml ) {
- $elements[] = 'html';
- }
- if( $this->mOptions->getUseTeX() ) {
- $elements[] = 'math';
- }
- return $elements;
+ return $this->mStripList;
}
/**
@@ -648,14 +689,14 @@ class Parser
$this->mStripState->general->setPair( $rnd, $text );
return $rnd;
}
-
+
/**
* Interface with html tidy
* @deprecated Use MWTidy::tidy()
*/
public static function tidy( $text ) {
wfDeprecated( __METHOD__ );
- return MWTidy::tidy( $text );
+ return MWTidy::tidy( $text );
}
/**
@@ -693,11 +734,11 @@ class Parser
$attributes = Sanitizer::fixTagAttributes ( $attributes , 'table' );
$outLine = str_repeat( '<dl><dd>' , $indent_level ) . "<table{$attributes}>";
- array_push ( $td_history , false );
- array_push ( $last_tag_history , '' );
- array_push ( $tr_history , false );
- array_push ( $tr_attributes , '' );
- array_push ( $has_opened_tr , false );
+ array_push( $td_history , false );
+ array_push( $last_tag_history , '' );
+ array_push( $tr_history , false );
+ array_push( $tr_attributes , '' );
+ array_push( $has_opened_tr , false );
} else if ( count ( $td_history ) == 0 ) {
// Don't do any of the following
$out .= $outLine."\n";
@@ -726,9 +767,9 @@ class Parser
// Whats after the tag is now only attributes
$attributes = $this->mStripState->unstripBoth( $line );
- $attributes = Sanitizer::fixTagAttributes ( $attributes , 'tr' );
- array_pop ( $tr_attributes );
- array_push ( $tr_attributes , $attributes );
+ $attributes = Sanitizer::fixTagAttributes( $attributes, 'tr' );
+ array_pop( $tr_attributes );
+ array_push( $tr_attributes, $attributes );
$line = '';
$last_tag = array_pop ( $last_tag_history );
@@ -862,17 +903,33 @@ class Parser
*
* @private
*/
- function internalParse( $text ) {
- $isMain = true;
+ function internalParse( $text, $isMain = true, $frame=false ) {
wfProfileIn( __METHOD__ );
+ $origText = $text;
+
# Hook to suspend the parser in this state
if ( !wfRunHooks( 'ParserBeforeInternalParse', array( &$this, &$text, &$this->mStripState ) ) ) {
wfProfileOut( __METHOD__ );
return $text ;
}
- $text = $this->replaceVariables( $text );
+ // if $frame is provided, then use $frame for replacing any variables
+ if ($frame) {
+ // use frame depth to infer how include/noinclude tags should be handled
+ // depth=0 means this is the top-level document; otherwise it's an included document
+ if( !$frame->depth )
+ $flag = 0;
+ else
+ $flag = Parser::PTD_FOR_INCLUSION;
+ $dom = $this->preprocessToDom( $text, $flag );
+ $text = $frame->expand( $dom );
+ }
+ // if $frame is not provided, then use old-style replaceVariables
+ else {
+ $text = $this->replaceVariables( $text );
+ }
+
$text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ), false, array_keys( $this->mTransparentTagHooks ) );
wfRunHooks( 'InternalParseBeforeLinks', array( &$this, &$text, &$this->mStripState ) );
@@ -885,6 +942,7 @@ class Parser
$text = preg_replace( '/(^|\n)-----*/', '\\1<hr />', $text );
$text = $this->doDoubleUnderscore( $text );
+
$text = $this->doHeadings( $text );
if( $this->mOptions->getUseDynamicDates() ) {
$df = DateFormatter::getInstance();
@@ -899,7 +957,7 @@ class Parser
$text = str_replace($this->mUniqPrefix.'NOPARSE', '', $text);
$text = $this->doMagicLinks( $text );
- $text = $this->formatHeadings( $text, $isMain );
+ $text = $this->formatHeadings( $text, $origText, $isMain );
wfProfileOut( __METHOD__ );
return $text;
@@ -908,7 +966,7 @@ class Parser
/**
* Replace special strings like "ISBN xxx" and "RFC xxx" with
* magic external links.
- *
+ *
* DML
* @private
*/
@@ -918,7 +976,7 @@ class Parser
$urlChar = self::EXT_LINK_URL_CLASS;
$text = preg_replace_callback(
'!(?: # Start cases
- (<a.*?</a>) | # m[1]: Skip link text
+ (<a.*?</a>) | # m[1]: Skip link text
(<.*?>) | # m[2]: Skip stuff inside HTML elements' . "
(\\b(?:$prots)$urlChar+) | # m[3]: Free external links" . '
(?:RFC|PMID)\s+([0-9]+) | # m[4]: RFC or PMID, capture number
@@ -944,13 +1002,16 @@ class Parser
return $this->makeFreeExternalLink( $m[0] );
} elseif ( isset( $m[4] ) && $m[4] !== '' ) {
# RFC or PMID
+ $CssClass = '';
if ( substr( $m[0], 0, 3 ) === 'RFC' ) {
$keyword = 'RFC';
$urlmsg = 'rfcurl';
+ $CssClass = 'mw-magiclink-rfc';
$id = $m[4];
} elseif ( substr( $m[0], 0, 4 ) === 'PMID' ) {
$keyword = 'PMID';
$urlmsg = 'pubmedurl';
+ $CssClass = 'mw-magiclink-pmid';
$id = $m[4];
} else {
throw new MWException( __METHOD__.': unrecognised match type "' .
@@ -958,7 +1019,7 @@ class Parser
}
$url = wfMsg( $urlmsg, $id);
$sk = $this->mOptions->getSkin();
- $la = $sk->getExternalLinkAttributes( $url, $keyword.$id );
+ $la = $sk->getExternalLinkAttributes( "external $CssClass" );
return "<a href=\"{$url}\"{$la}>{$keyword} {$id}</a>";
} elseif ( isset( $m[5] ) && $m[5] !== '' ) {
# ISBN
@@ -971,7 +1032,7 @@ class Parser
$titleObj = SpecialPage::getTitleFor( 'Booksources', $num );
return'<a href="' .
$titleObj->escapeLocalUrl() .
- "\" class=\"internal\">ISBN $isbn</a>";
+ "\" class=\"internal mw-magiclink-isbn\">ISBN $isbn</a>";
} else {
return $m[0];
}
@@ -1017,7 +1078,7 @@ class Parser
$text = $this->maybeMakeExternalImage( $url );
if ( $text === false ) {
# Not an image, make a link
- $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free',
+ $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free',
$this->getExternalLinkAttribs( $url ) );
# Register it in the output object...
# Replace unnecessary URL escape codes with their equivalent characters
@@ -1457,7 +1518,7 @@ class Parser
wfProfileIn( __METHOD__.'-setup' );
static $tc = FALSE, $e1, $e1_img;
# the % is needed to support urlencoded titles as well
- if ( !$tc ) {
+ if ( !$tc ) {
$tc = Title::legalChars() . '#%';
# Match a link having the form [[namespace:link|alternate]]trail
$e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
@@ -1581,29 +1642,29 @@ class Parser
# Don't allow internal links to pages containing
# PROTO: where PROTO is a valid URL protocol; these
# should be external links.
- if (preg_match('/^\b(?:' . wfUrlProtocols() . ')/', $m[1])) {
+ if ( preg_match( '/^\b(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
$s .= $prefix . '[[' . $line ;
wfProfileOut( __METHOD__."-misc" );
continue;
}
# Make subpage if necessary
- if( $useSubpages ) {
+ if ( $useSubpages ) {
$link = $this->maybeDoSubpageLink( $m[1], $text );
} else {
$link = $m[1];
}
- $noforce = (substr($m[1], 0, 1) !== ':');
+ $noforce = (substr( $m[1], 0, 1 ) !== ':');
if (!$noforce) {
# Strip off leading ':'
- $link = substr($link, 1);
+ $link = substr( $link, 1 );
}
wfProfileOut( __METHOD__."-misc" );
wfProfileIn( __METHOD__."-title" );
- $nt = Title::newFromText( $this->mStripState->unstripNoWiki($link) );
- if( $nt === NULL ) {
+ $nt = Title::newFromText( $this->mStripState->unstripNoWiki( $link ) );
+ if ( $nt === null ) {
$s .= $prefix . '[[' . $line;
wfProfileOut( __METHOD__."-title" );
continue;
@@ -1613,9 +1674,9 @@ class Parser
$iw = $nt->getInterWiki();
wfProfileOut( __METHOD__."-title" );
- if ($might_be_img) { # if this is actually an invalid link
+ 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
+ if ( $ns == NS_FILE && $noforce ) { #but might be an image
$found = false;
while ( true ) {
#look at the next 'line' to see if we can close it there
@@ -1658,15 +1719,15 @@ class Parser
wfProfileOut( __METHOD__."-might_be_img" );
}
- $wasblank = ( '' == $text );
- if( $wasblank ) $text = $link;
+ $wasblank = ( $text == '' );
+ if ( $wasblank ) $text = $link;
# Link not escaped by : , create the various objects
- if( $noforce ) {
+ if ( $noforce ) {
# Interwikis
wfProfileIn( __METHOD__."-interwiki" );
- if( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
+ if ( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
$this->mOutput->addLanguageLink( $nt->getFullText() );
$s = rtrim($s . $prefix);
$s .= trim($trail, "\n") == '' ? '': $prefix . $trail;
@@ -1678,14 +1739,23 @@ class Parser
if ( $ns == NS_FILE ) {
wfProfileIn( __METHOD__."-image" );
if ( !wfIsBadImage( $nt->getDBkey(), $this->mTitle ) ) {
- # recursively parse links inside the image caption
- # actually, this will parse them in any other parameters, too,
- # but it might be hard to fix that, and it doesn't matter ATM
- $text = $this->replaceExternalLinks($text);
- $holders->merge( $this->replaceInternalLinks2( $text ) );
-
+ if ( $wasblank ) {
+ # if no parameters were passed, $text
+ # becomes something like "File:Foo.png",
+ # which we don't want to pass on to the
+ # image generator
+ $text = '';
+ } else {
+ # recursively parse links inside the image caption
+ # actually, this will parse them in any other parameters, too,
+ # but it might be hard to fix that, and it doesn't matter ATM
+ $text = $this->replaceExternalLinks($text);
+ $holders->merge( $this->replaceInternalLinks2( $text ) );
+ }
# cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
$s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text, $holders ) ) . $trail;
+ } else {
+ $s .= $prefix . $trail;
}
$this->mOutput->addImage( $nt->getDBkey() );
wfProfileOut( __METHOD__."-image" );
@@ -1793,6 +1863,7 @@ class Parser
function makeKnownLinkHolder( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
list( $inside, $trail ) = Linker::splitTrail( $trail );
$sk = $this->mOptions->getSkin();
+ // FIXME: use link() instead of deprecated makeKnownLinkObj()
$link = $sk->makeKnownLinkObj( $nt, $text, $query, $inside, $prefix );
return $this->armorLinks( $link ) . $trail;
}
@@ -1829,75 +1900,7 @@ class Parser
* @private
*/
function maybeDoSubpageLink($target, &$text) {
- # Valid link forms:
- # Foobar -- normal
- # :Foobar -- override special treatment of prefix (images, language links)
- # /Foobar -- convert to CurrentPage/Foobar
- # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
- # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
- # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
-
- wfProfileIn( __METHOD__ );
- $ret = $target; # default return value is no change
-
- # Some namespaces don't allow subpages,
- # so only perform processing if subpages are allowed
- if( $this->areSubpagesAllowed() ) {
- $hash = strpos( $target, '#' );
- if( $hash !== false ) {
- $suffix = substr( $target, $hash );
- $target = substr( $target, 0, $hash );
- } else {
- $suffix = '';
- }
- # bug 7425
- $target = trim( $target );
- # Look at the first character
- if( $target != '' && $target{0} === '/' ) {
- # / at end means we don't want the slash to be shown
- $m = array();
- $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
- if( $trailingSlashes ) {
- $noslash = $target = substr( $target, 1, -strlen($m[0][0]) );
- } else {
- $noslash = substr( $target, 1 );
- }
-
- $ret = $this->mTitle->getPrefixedText(). '/' . trim($noslash) . $suffix;
- if( '' === $text ) {
- $text = $target . $suffix;
- } # this might be changed for ugliness reasons
- } else {
- # check for .. subpage backlinks
- $dotdotcount = 0;
- $nodotdot = $target;
- while( strncmp( $nodotdot, "../", 3 ) == 0 ) {
- ++$dotdotcount;
- $nodotdot = substr( $nodotdot, 3 );
- }
- if($dotdotcount > 0) {
- $exploded = explode( '/', $this->mTitle->GetPrefixedText() );
- if( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
- $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
- # / at the end means don't show full path
- if( substr( $nodotdot, -1, 1 ) === '/' ) {
- $nodotdot = substr( $nodotdot, 0, -1 );
- if( '' === $text ) {
- $text = $nodotdot . $suffix;
- }
- }
- $nodotdot = trim( $nodotdot );
- if( $nodotdot != '' ) {
- $ret .= '/' . $nodotdot;
- }
- $ret .= $suffix;
- }
- }
- }
- }
-
- wfProfileOut( __METHOD__ );
- return $ret;
+ return Linker::normalizeSubpageLink( $this->mTitle, $target, $text );
}
/**#@+
@@ -1906,7 +1909,7 @@ class Parser
*/
/* private */ function closeParagraph() {
$result = '';
- if ( '' != $this->mLastSection ) {
+ if ( $this->mLastSection != '' ) {
$result = '</' . $this->mLastSection . ">\n";
}
$this->mInPre = false;
@@ -1933,9 +1936,9 @@ class Parser
$result = $this->closeParagraph();
if ( '*' === $char ) { $result .= '<ul><li>'; }
- else if ( '#' === $char ) { $result .= '<ol><li>'; }
- else if ( ':' === $char ) { $result .= '<dl><dd>'; }
- else if ( ';' === $char ) {
+ elseif ( '#' === $char ) { $result .= '<ol><li>'; }
+ elseif ( ':' === $char ) { $result .= '<dl><dd>'; }
+ elseif ( ';' === $char ) {
$result .= '<dl><dt>';
$this->mDTopen = true;
}
@@ -1946,7 +1949,7 @@ class Parser
/* private */ function nextItem( $char ) {
if ( '*' === $char || '#' === $char ) { return '</li><li>'; }
- else if ( ':' === $char || ';' === $char ) {
+ elseif ( ':' === $char || ';' === $char ) {
$close = '</dd>';
if ( $this->mDTopen ) { $close = '</dt>'; }
if ( ';' === $char ) {
@@ -1962,8 +1965,8 @@ class Parser
/* private */ function closeList( $char ) {
if ( '*' === $char ) { $text = '</li></ul>'; }
- else if ( '#' === $char ) { $text = '</li></ol>'; }
- else if ( ':' === $char ) {
+ elseif ( '#' === $char ) { $text = '</li></ol>'; }
+ elseif ( ':' === $char ) {
if ( $this->mDTopen ) {
$this->mDTopen = false;
$text = '</dt></dl>';
@@ -1979,6 +1982,7 @@ class Parser
/**
* Make lists from lines starting with ':', '*', '#', etc. (DBL)
*
+ * @param $linestart bool whether or not this is at the start of a line.
* @private
* @return string the lists rendered as HTML
*/
@@ -2003,16 +2007,24 @@ class Parser
$linestart = true;
continue;
}
+ // * = ul
+ // # = ol
+ // ; = dt
+ // : = dd
$lastPrefixLength = strlen( $lastPrefix );
$preCloseMatch = preg_match('/<\\/pre/i', $oLine );
$preOpenMatch = preg_match('/<pre/i', $oLine );
+ // If not in a <pre> element, scan for and figure out what prefixes are there.
if ( !$this->mInPre ) {
# Multiple prefixes may abut each other for nested lists.
$prefixLength = strspn( $oLine, '*#:;' );
$prefix = substr( $oLine, 0, $prefixLength );
# eh?
+ // ; and : are both from definition-lists, so they're equivalent
+ // for the purposes of determining whether or not we need to open/close
+ // elements.
$prefix2 = str_replace( ';', ':', $prefix );
$t = substr( $oLine, $prefixLength );
$this->mInPre = (bool)$preOpenMatch;
@@ -2041,17 +2053,24 @@ class Parser
}
}
} elseif( $prefixLength || $lastPrefixLength ) {
+ // We need to open or close prefixes, or both.
+
# Either open or close a level...
$commonPrefixLength = $this->getCommon( $prefix, $lastPrefix );
$paragraphStack = false;
+ // Close all the prefixes which aren't shared.
while( $commonPrefixLength < $lastPrefixLength ) {
$output .= $this->closeList( $lastPrefix[$lastPrefixLength-1] );
--$lastPrefixLength;
}
+
+ // Continue the current prefix if appropriate.
if ( $prefixLength <= $commonPrefixLength && $commonPrefixLength > 0 ) {
$output .= $this->nextItem( $prefix[$commonPrefixLength-1] );
}
+
+ // Open prefixes where appropriate.
while ( $prefixLength > $commonPrefixLength ) {
$char = substr( $prefix, $commonPrefixLength, 1 );
$output .= $this->openList( $char );
@@ -2067,6 +2086,8 @@ class Parser
}
$lastPrefix = $prefix2;
}
+
+ // If we have no prefixes, go to paragraph mode.
if( 0 == $prefixLength ) {
wfProfileIn( __METHOD__."-paragraph" );
# No prefix (not in list)--go to paragraph mode
@@ -2098,7 +2119,7 @@ class Parser
$t = substr( $t, 1 );
} else {
// paragraph
- if ( '' == trim($t) ) {
+ if ( trim($t) == '' ) {
if ( $paragraphStack ) {
$output .= $paragraphStack.'<br />';
$paragraphStack = false;
@@ -2138,7 +2159,7 @@ class Parser
$output .= $this->closeList( $prefix2[$prefixLength-1] );
--$prefixLength;
}
- if ( '' != $this->mLastSection ) {
+ if ( $this->mLastSection != '' ) {
$output .= '</' . $this->mLastSection . '>';
$this->mLastSection = '';
}
@@ -2315,8 +2336,9 @@ class Parser
*
* @private
*/
- function getVariableValue( $index ) {
- global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath;
+ function getVariableValue( $index, $frame=false ) {
+ global $wgContLang, $wgSitename, $wgServer, $wgServerName;
+ global $wgScriptPath, $wgStylePath;
/**
* Some of these require message or data lookups and can be
@@ -2334,13 +2356,13 @@ class Parser
# Use the time zone
global $wgLocaltimezone;
if ( isset( $wgLocaltimezone ) ) {
- $oldtz = getenv( 'TZ' );
- putenv( 'TZ='.$wgLocaltimezone );
+ $oldtz = date_default_timezone_get();
+ date_default_timezone_set( $wgLocaltimezone );
}
- wfSuppressWarnings(); // E_STRICT system time bitching
$localTimestamp = date( 'YmdHis', $ts );
$localMonth = date( 'm', $ts );
+ $localMonth1 = date( 'n', $ts );
$localMonthName = date( 'n', $ts );
$localDay = date( 'j', $ts );
$localDay2 = date( 'd', $ts );
@@ -2349,175 +2371,240 @@ class Parser
$localYear = date( 'Y', $ts );
$localHour = date( 'H', $ts );
if ( isset( $wgLocaltimezone ) ) {
- putenv( 'TZ='.$oldtz );
+ date_default_timezone_set( $oldtz );
}
- wfRestoreWarnings();
switch ( $index ) {
case 'currentmonth':
- return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'm', $ts ) );
+ $value = $wgContLang->formatNum( gmdate( 'm', $ts ) );
+ break;
+ case 'currentmonth1':
+ $value = $wgContLang->formatNum( gmdate( 'n', $ts ) );
+ break;
case 'currentmonthname':
- return $this->mVarCache[$index] = $wgContLang->getMonthName( gmdate( 'n', $ts ) );
+ $value = $wgContLang->getMonthName( gmdate( 'n', $ts ) );
+ break;
case 'currentmonthnamegen':
- return $this->mVarCache[$index] = $wgContLang->getMonthNameGen( gmdate( 'n', $ts ) );
+ $value = $wgContLang->getMonthNameGen( gmdate( 'n', $ts ) );
+ break;
case 'currentmonthabbrev':
- return $this->mVarCache[$index] = $wgContLang->getMonthAbbreviation( gmdate( 'n', $ts ) );
+ $value = $wgContLang->getMonthAbbreviation( gmdate( 'n', $ts ) );
+ break;
case 'currentday':
- return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'j', $ts ) );
+ $value = $wgContLang->formatNum( gmdate( 'j', $ts ) );
+ break;
case 'currentday2':
- return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'd', $ts ) );
+ $value = $wgContLang->formatNum( gmdate( 'd', $ts ) );
+ break;
case 'localmonth':
- return $this->mVarCache[$index] = $wgContLang->formatNum( $localMonth );
+ $value = $wgContLang->formatNum( $localMonth );
+ break;
+ case 'localmonth1':
+ $value = $wgContLang->formatNum( $localMonth1 );
+ break;
case 'localmonthname':
- return $this->mVarCache[$index] = $wgContLang->getMonthName( $localMonthName );
+ $value = $wgContLang->getMonthName( $localMonthName );
+ break;
case 'localmonthnamegen':
- return $this->mVarCache[$index] = $wgContLang->getMonthNameGen( $localMonthName );
+ $value = $wgContLang->getMonthNameGen( $localMonthName );
+ break;
case 'localmonthabbrev':
- return $this->mVarCache[$index] = $wgContLang->getMonthAbbreviation( $localMonthName );
+ $value = $wgContLang->getMonthAbbreviation( $localMonthName );
+ break;
case 'localday':
- return $this->mVarCache[$index] = $wgContLang->formatNum( $localDay );
+ $value = $wgContLang->formatNum( $localDay );
+ break;
case 'localday2':
- return $this->mVarCache[$index] = $wgContLang->formatNum( $localDay2 );
+ $value = $wgContLang->formatNum( $localDay2 );
+ break;
case 'pagename':
- return wfEscapeWikiText( $this->mTitle->getText() );
+ $value = wfEscapeWikiText( $this->mTitle->getText() );
+ break;
case 'pagenamee':
- return $this->mTitle->getPartialURL();
+ $value = $this->mTitle->getPartialURL();
+ break;
case 'fullpagename':
- return wfEscapeWikiText( $this->mTitle->getPrefixedText() );
+ $value = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
+ break;
case 'fullpagenamee':
- return $this->mTitle->getPrefixedURL();
+ $value = $this->mTitle->getPrefixedURL();
+ break;
case 'subpagename':
- return wfEscapeWikiText( $this->mTitle->getSubpageText() );
+ $value = wfEscapeWikiText( $this->mTitle->getSubpageText() );
+ break;
case 'subpagenamee':
- return $this->mTitle->getSubpageUrlForm();
+ $value = $this->mTitle->getSubpageUrlForm();
+ break;
case 'basepagename':
- return wfEscapeWikiText( $this->mTitle->getBaseText() );
+ $value = wfEscapeWikiText( $this->mTitle->getBaseText() );
+ break;
case 'basepagenamee':
- return wfUrlEncode( str_replace( ' ', '_', $this->mTitle->getBaseText() ) );
+ $value = wfUrlEncode( str_replace( ' ', '_', $this->mTitle->getBaseText() ) );
+ break;
case 'talkpagename':
if( $this->mTitle->canTalk() ) {
$talkPage = $this->mTitle->getTalkPage();
- return wfEscapeWikiText( $talkPage->getPrefixedText() );
+ $value = wfEscapeWikiText( $talkPage->getPrefixedText() );
} else {
- return '';
+ $value = '';
}
+ break;
case 'talkpagenamee':
if( $this->mTitle->canTalk() ) {
$talkPage = $this->mTitle->getTalkPage();
- return $talkPage->getPrefixedUrl();
+ $value = $talkPage->getPrefixedUrl();
} else {
- return '';
+ $value = '';
}
+ break;
case 'subjectpagename':
$subjPage = $this->mTitle->getSubjectPage();
- return wfEscapeWikiText( $subjPage->getPrefixedText() );
+ $value = wfEscapeWikiText( $subjPage->getPrefixedText() );
+ break;
case 'subjectpagenamee':
$subjPage = $this->mTitle->getSubjectPage();
- return $subjPage->getPrefixedUrl();
+ $value = $subjPage->getPrefixedUrl();
+ break;
case 'revisionid':
// Let the edit saving system know we should parse the page
// *after* a revision ID has been assigned.
$this->mOutput->setFlag( 'vary-revision' );
wfDebug( __METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n" );
- return $this->mRevisionId;
+ $value = $this->mRevisionId;
+ break;
case 'revisionday':
// Let the edit saving system know we should parse the page
// *after* a revision ID has been assigned. This is for null edits.
$this->mOutput->setFlag( 'vary-revision' );
wfDebug( __METHOD__ . ": {{REVISIONDAY}} used, setting vary-revision...\n" );
- return intval( substr( $this->getRevisionTimestamp(), 6, 2 ) );
+ $value = intval( substr( $this->getRevisionTimestamp(), 6, 2 ) );
+ break;
case 'revisionday2':
// Let the edit saving system know we should parse the page
// *after* a revision ID has been assigned. This is for null edits.
$this->mOutput->setFlag( 'vary-revision' );
wfDebug( __METHOD__ . ": {{REVISIONDAY2}} used, setting vary-revision...\n" );
- return substr( $this->getRevisionTimestamp(), 6, 2 );
+ $value = substr( $this->getRevisionTimestamp(), 6, 2 );
+ break;
case 'revisionmonth':
// Let the edit saving system know we should parse the page
// *after* a revision ID has been assigned. This is for null edits.
$this->mOutput->setFlag( 'vary-revision' );
wfDebug( __METHOD__ . ": {{REVISIONMONTH}} used, setting vary-revision...\n" );
- return intval( substr( $this->getRevisionTimestamp(), 4, 2 ) );
+ $value = intval( substr( $this->getRevisionTimestamp(), 4, 2 ) );
+ break;
case 'revisionyear':
// Let the edit saving system know we should parse the page
// *after* a revision ID has been assigned. This is for null edits.
$this->mOutput->setFlag( 'vary-revision' );
wfDebug( __METHOD__ . ": {{REVISIONYEAR}} used, setting vary-revision...\n" );
- return substr( $this->getRevisionTimestamp(), 0, 4 );
+ $value = substr( $this->getRevisionTimestamp(), 0, 4 );
+ break;
case 'revisiontimestamp':
// Let the edit saving system know we should parse the page
// *after* a revision ID has been assigned. This is for null edits.
$this->mOutput->setFlag( 'vary-revision' );
wfDebug( __METHOD__ . ": {{REVISIONTIMESTAMP}} used, setting vary-revision...\n" );
- return $this->getRevisionTimestamp();
+ $value = $this->getRevisionTimestamp();
+ break;
case 'revisionuser':
// Let the edit saving system know we should parse the page
// *after* a revision ID has been assigned. This is for null edits.
$this->mOutput->setFlag( 'vary-revision' );
wfDebug( __METHOD__ . ": {{REVISIONUSER}} used, setting vary-revision...\n" );
- return $this->getRevisionUser();
+ $value = $this->getRevisionUser();
+ break;
case 'namespace':
- return str_replace('_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) );
+ $value = str_replace('_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) );
+ break;
case 'namespacee':
- return wfUrlencode( $wgContLang->getNsText( $this->mTitle->getNamespace() ) );
+ $value = wfUrlencode( $wgContLang->getNsText( $this->mTitle->getNamespace() ) );
+ break;
case 'talkspace':
- return $this->mTitle->canTalk() ? str_replace('_',' ',$this->mTitle->getTalkNsText()) : '';
+ $value = $this->mTitle->canTalk() ? str_replace('_',' ',$this->mTitle->getTalkNsText()) : '';
+ break;
case 'talkspacee':
- return $this->mTitle->canTalk() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : '';
+ $value = $this->mTitle->canTalk() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : '';
+ break;
case 'subjectspace':
- return $this->mTitle->getSubjectNsText();
+ $value = $this->mTitle->getSubjectNsText();
+ break;
case 'subjectspacee':
- return( wfUrlencode( $this->mTitle->getSubjectNsText() ) );
+ $value = ( wfUrlencode( $this->mTitle->getSubjectNsText() ) );
+ break;
case 'currentdayname':
- return $this->mVarCache[$index] = $wgContLang->getWeekdayName( gmdate( 'w', $ts ) + 1 );
+ $value = $wgContLang->getWeekdayName( gmdate( 'w', $ts ) + 1 );
+ break;
case 'currentyear':
- return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'Y', $ts ), true );
+ $value = $wgContLang->formatNum( gmdate( 'Y', $ts ), true );
+ break;
case 'currenttime':
- return $this->mVarCache[$index] = $wgContLang->time( wfTimestamp( TS_MW, $ts ), false, false );
+ $value = $wgContLang->time( wfTimestamp( TS_MW, $ts ), false, false );
+ break;
case 'currenthour':
- return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'H', $ts ), true );
+ $value = $wgContLang->formatNum( gmdate( 'H', $ts ), true );
+ break;
case 'currentweek':
// @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
// int to remove the padding
- return $this->mVarCache[$index] = $wgContLang->formatNum( (int)gmdate( 'W', $ts ) );
+ $value = $wgContLang->formatNum( (int)gmdate( 'W', $ts ) );
+ break;
case 'currentdow':
- return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'w', $ts ) );
+ $value = $wgContLang->formatNum( gmdate( 'w', $ts ) );
+ break;
case 'localdayname':
- return $this->mVarCache[$index] = $wgContLang->getWeekdayName( $localDayOfWeek + 1 );
+ $value = $wgContLang->getWeekdayName( $localDayOfWeek + 1 );
+ break;
case 'localyear':
- return $this->mVarCache[$index] = $wgContLang->formatNum( $localYear, true );
+ $value = $wgContLang->formatNum( $localYear, true );
+ break;
case 'localtime':
- return $this->mVarCache[$index] = $wgContLang->time( $localTimestamp, false, false );
+ $value = $wgContLang->time( $localTimestamp, false, false );
+ break;
case 'localhour':
- return $this->mVarCache[$index] = $wgContLang->formatNum( $localHour, true );
+ $value = $wgContLang->formatNum( $localHour, true );
+ break;
case 'localweek':
// @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
// int to remove the padding
- return $this->mVarCache[$index] = $wgContLang->formatNum( (int)$localWeek );
+ $value = $wgContLang->formatNum( (int)$localWeek );
+ break;
case 'localdow':
- return $this->mVarCache[$index] = $wgContLang->formatNum( $localDayOfWeek );
+ $value = $wgContLang->formatNum( $localDayOfWeek );
+ break;
case 'numberofarticles':
- return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::articles() );
+ $value = $wgContLang->formatNum( SiteStats::articles() );
+ break;
case 'numberoffiles':
- return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::images() );
+ $value = $wgContLang->formatNum( SiteStats::images() );
+ break;
case 'numberofusers':
- return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::users() );
+ $value = $wgContLang->formatNum( SiteStats::users() );
+ break;
case 'numberofactiveusers':
- return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::activeUsers() );
+ $value = $wgContLang->formatNum( SiteStats::activeUsers() );
+ break;
case 'numberofpages':
- return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::pages() );
+ $value = $wgContLang->formatNum( SiteStats::pages() );
+ break;
case 'numberofadmins':
- return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::numberingroup('sysop') );
+ $value = $wgContLang->formatNum( SiteStats::numberingroup('sysop') );
+ break;
case 'numberofedits':
- return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::edits() );
+ $value = $wgContLang->formatNum( SiteStats::edits() );
+ break;
case 'numberofviews':
- return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::views() );
+ $value = $wgContLang->formatNum( SiteStats::views() );
+ break;
case 'currenttimestamp':
- return $this->mVarCache[$index] = wfTimestamp( TS_MW, $ts );
+ $value = wfTimestamp( TS_MW, $ts );
+ break;
case 'localtimestamp':
- return $this->mVarCache[$index] = $localTimestamp;
+ $value = $localTimestamp;
+ break;
case 'currentversion':
- return $this->mVarCache[$index] = SpecialVersion::getVersion();
+ $value = SpecialVersion::getVersion();
+ break;
case 'sitename':
return $wgSitename;
case 'server':
@@ -2526,6 +2613,8 @@ class Parser
return $wgServerName;
case 'scriptpath':
return $wgScriptPath;
+ case 'stylepath':
+ return $wgStylePath;
case 'directionmark':
return $wgContLang->getDirMark();
case 'contentlanguage':
@@ -2533,23 +2622,30 @@ class Parser
return $wgContLanguageCode;
default:
$ret = null;
- if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret ) ) )
+ if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ) )
return $ret;
else
return null;
}
+
+ if ( $index )
+ $this->mVarCache[$index] = $value;
+
+ return $value;
}
/**
- * initialise the magic variables (like CURRENTMONTHNAME)
+ * initialise the magic variables (like CURRENTMONTHNAME) and substitution modifiers
*
* @private
*/
function initialiseVariables() {
wfProfileIn( __METHOD__ );
$variableIDs = MagicWord::getVariableIDs();
+ $substIDs = MagicWord::getSubstIDs();
$this->mVariables = new MagicWordArray( $variableIDs );
+ $this->mSubstWords = new MagicWordArray( $substIDs );
wfProfileOut( __METHOD__ );
}
@@ -2607,7 +2703,7 @@ class Parser
* self::OT_HTML: all templates and extension tags
*
* @param string $tex The text to transform
- * @param PPFrame $frame Object describing the arguments passed to the template.
+ * @param PPFrame $frame Object describing the arguments passed to the template.
* Arguments may also be provided as an associative array, as was the usual case before MW1.12.
* Providing arguments this way may be useful for extensions wishing to perform variable replacement explicitly.
* @param bool $argsOnly Only do argument (triple-brace) expansion, not double-brace expansion
@@ -2670,14 +2766,10 @@ class Parser
* exceeded, provide the values (optional)
*/
function limitationWarn( $limitationType, $current=null, $max=null) {
- $msgName = $limitationType . '-warning';
//does no harm if $current and $max are present but are unnecessary for the message
- $warning = wfMsgExt( $msgName, array( 'parsemag', 'escape' ), $current, $max );
+ $warning = wfMsgExt( "$limitationType-warning", array( 'parsemag', 'escape' ), $current, $max );
$this->mOutput->addWarning( $warning );
- $cat = Title::makeTitleSafe( NS_CATEGORY, wfMsgForContent( $limitationType . '-category' ) );
- if ( $cat ) {
- $this->mOutput->addCategory( $cat->getDBkey(), $this->getDefaultSort() );
- }
+ $this->addTrackingCategory( "$limitationType-category" );
}
/**
@@ -2706,7 +2798,7 @@ class Parser
$isLocalObj = false; # $text is a DOM node needing expansion in the current frame
# Title object, where $text came from
- $title = NULL;
+ $title = null;
# $part1 is the bit before the first |, and must contain only title characters.
# Various prefixes will be stripped from it later.
@@ -2724,12 +2816,25 @@ class Parser
# SUBST
wfProfileIn( __METHOD__.'-modifiers' );
if ( !$found ) {
- $mwSubst = MagicWord::get( 'subst' );
- if ( $mwSubst->matchStartAndRemove( $part1 ) xor $this->ot['wiki'] ) {
- # One of two possibilities is true:
- # 1) Found SUBST but not in the PST phase
- # 2) Didn't find SUBST and in the PST phase
- # In either case, return without further processing
+
+ $substMatch = $this->mSubstWords->matchStartAndRemove( $part1 );
+
+ # Possibilities for substMatch: "subst", "safesubst" or FALSE
+ # Decide whether to expand template or keep wikitext as-is.
+ if ( $this->ot['wiki'] ) {
+ if ( $substMatch === false ) {
+ $literal = true; # literal when in PST with no prefix
+ } else {
+ $literal = false; # expand when in PST with subst: or safesubst:
+ }
+ } else {
+ if ( $substMatch == 'subst' ) {
+ $literal = true; # literal when not in PST with plain subst:
+ } else {
+ $literal = false; # expand when not in PST with safesubst: or no prefix
+ }
+ }
+ if ( $literal ) {
$text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args );
$isLocalObj = true;
$found = true;
@@ -2740,7 +2845,7 @@ class Parser
if ( !$found && $args->getLength() == 0 ) {
$id = $this->mVariables->matchStartToEnd( $part1 );
if ( $id !== false ) {
- $text = $this->getVariableValue( $id );
+ $text = $this->getVariableValue( $id, $frame );
if (MagicWord::getCacheTTL($id)>-1)
$this->mOutput->mContainsOldMagic = true;
$found = true;
@@ -2779,7 +2884,7 @@ class Parser
$function = $this->mFunctionSynonyms[1][$function];
} else {
# Case insensitive functions
- $function = strtolower( $function );
+ $function = $wgContLang->lc( $function );
if ( isset( $this->mFunctionSynonyms[0][$function] ) ) {
$function = $this->mFunctionSynonyms[0][$function];
} else {
@@ -2808,13 +2913,15 @@ class Parser
# Workaround for PHP bug 35229 and similar
if ( !is_callable( $callback ) ) {
+ wfProfileOut( __METHOD__ . '-pfunc' );
+ wfProfileOut( __METHOD__ );
throw new MWException( "Tag hook for $function is not callable\n" );
}
$result = call_user_func_array( $callback, $allArgs );
$found = true;
$noparse = true;
$preprocessFlags = 0;
-
+
if ( is_array( $result ) ) {
if ( isset( $result[0] ) ) {
$text = $result[0];
@@ -3118,14 +3225,11 @@ class Parser
function fetchScaryTemplateMaybeFromCache($url) {
global $wgTranscludeCacheExpiry;
$dbr = wfGetDB(DB_SLAVE);
+ $tsCond = $dbr->timestamp( time() - $wgTranscludeCacheExpiry );
$obj = $dbr->selectRow('transcache', array('tc_time', 'tc_contents'),
- array('tc_url' => $url));
+ array('tc_url' => $url, "tc_time >= " . $dbr->addQuotes( $tsCond ) ) );
if ($obj) {
- $time = $obj->tc_time;
- $text = $obj->tc_contents;
- if ($time && time() < $time + $wgTranscludeCacheExpiry ) {
- return $text;
- }
+ return $obj->tc_contents;
}
$text = Http::get($url);
@@ -3135,7 +3239,7 @@ class Parser
$dbw = wfGetDB(DB_MASTER);
$dbw->replace('transcache', array('tc_url'), array(
'tc_url' => $url,
- 'tc_time' => time(),
+ 'tc_time' => $dbw->timestamp( time() ),
'tc_contents' => $text));
return $text;
}
@@ -3204,47 +3308,47 @@ class Parser
$name = $frame->expand( $params['name'] );
$attrText = !isset( $params['attr'] ) ? null : $frame->expand( $params['attr'] );
$content = !isset( $params['inner'] ) ? null : $frame->expand( $params['inner'] );
-
$marker = "{$this->mUniqPrefix}-$name-" . sprintf('%08X', $this->mMarkerIndex++) . self::MARKER_SUFFIX;
- if ( $this->ot['html'] ) {
+ $isFunctionTag = isset( $this->mFunctionTagHooks[strtolower($name)] ) &&
+ ( $this->ot['html'] || $this->ot['pre'] );
+ if ( $isFunctionTag ) {
+ $markerType = 'none';
+ } else {
+ $markerType = 'general';
+ }
+ if ( $this->ot['html'] || $isFunctionTag ) {
$name = strtolower( $name );
-
$attributes = Sanitizer::decodeTagAttributes( $attrText );
if ( isset( $params['attributes'] ) ) {
$attributes = $attributes + $params['attributes'];
}
- switch ( $name ) {
- case 'html':
- if( $wgRawHtml ) {
- $output = $content;
- break;
- } else {
- throw new MWException( '<html> extension tag encountered unexpectedly' );
- }
- case 'nowiki':
- $content = strtr($content, array('-{' => '-&#123;', '}-' => '&#125;-'));
- $output = Xml::escapeTagsOnly( $content );
- break;
- case 'math':
- $output = $wgContLang->armourMath(
- MathRenderer::renderMath( $content, $attributes ) );
- break;
- case 'gallery':
- $output = $this->renderImageGallery( $content, $attributes );
- break;
- default:
- if( isset( $this->mTagHooks[$name] ) ) {
- # Workaround for PHP bug 35229 and similar
- if ( !is_callable( $this->mTagHooks[$name] ) ) {
- throw new MWException( "Tag hook for $name is not callable\n" );
- }
- $output = call_user_func_array( $this->mTagHooks[$name],
- array( $content, $attributes, $this ) );
- } else {
- $output = '<span class="error">Invalid tag extension name: ' .
- htmlspecialchars( $name ) . '</span>';
- }
+
+ if( isset( $this->mTagHooks[$name] ) ) {
+ # Workaround for PHP bug 35229 and similar
+ if ( !is_callable( $this->mTagHooks[$name] ) ) {
+ throw new MWException( "Tag hook for $name is not callable\n" );
+ }
+ $output = call_user_func_array( $this->mTagHooks[$name],
+ array( $content, $attributes, $this, $frame ) );
+ } elseif( isset( $this->mFunctionTagHooks[$name] ) ) {
+ list( $callback, $flags ) = $this->mFunctionTagHooks[$name];
+ if( !is_callable( $callback ) )
+ throw new MWException( "Tag hook for $name is not callable\n" );
+
+ $output = call_user_func_array( $callback,
+ array( &$this, $frame, $content, $attributes ) );
+ } else {
+ $output = '<span class="error">Invalid tag extension name: ' .
+ htmlspecialchars( $name ) . '</span>';
+ }
+
+ if ( is_array( $output ) ) {
+ // Extract flags to local scope (to override $markerType)
+ $flags = $output;
+ $output = $flags[0];
+ unset( $flags[0] );
+ extract( $flags );
}
} else {
if ( is_null( $attrText ) ) {
@@ -3264,10 +3368,14 @@ class Parser
}
}
- if ( $name === 'html' || $name === 'nowiki' ) {
+ if( $markerType === 'none' ) {
+ return $output;
+ } elseif ( $markerType === 'nowiki' ) {
$this->mStripState->nowiki->setPair( $marker, $output );
- } else {
+ } elseif ( $markerType === 'general' ) {
$this->mStripState->general->setPair( $marker, $output );
+ } else {
+ throw new MWException( __METHOD__.': invalid marker type' );
}
return $marker;
}
@@ -3308,6 +3416,7 @@ class Parser
*/
function doDoubleUnderscore( $text ) {
wfProfileIn( __METHOD__ );
+
// The position of __TOC__ needs to be recorded
$mw = MagicWord::get( 'toc' );
if( $mw->match( $text ) ) {
@@ -3333,28 +3442,48 @@ class Parser
}
if ( isset( $this->mDoubleUnderscores['hiddencat'] ) && $this->mTitle->getNamespace() == NS_CATEGORY ) {
$this->mOutput->setProperty( 'hiddencat', 'y' );
-
- $containerCategory = Title::makeTitleSafe( NS_CATEGORY, wfMsgForContent( 'hidden-category-category' ) );
- if ( $containerCategory ) {
- $this->mOutput->addCategory( $containerCategory->getDBkey(), $this->getDefaultSort() );
- } else {
- wfDebug( __METHOD__.": [[MediaWiki:hidden-category-category]] is not a valid title!\n" );
- }
+ $this->addTrackingCategory( 'hidden-category-category' );
}
# (bug 8068) Allow control over whether robots index a page.
#
# FIXME (bug 14899): __INDEX__ always overrides __NOINDEX__ here! This
# is not desirable, the last one on the page should win.
- if( isset( $this->mDoubleUnderscores['noindex'] ) ) {
+ if( isset( $this->mDoubleUnderscores['noindex'] ) && $this->mTitle->canUseNoindex() ) {
$this->mOutput->setIndexPolicy( 'noindex' );
- } elseif( isset( $this->mDoubleUnderscores['index'] ) ) {
+ $this->addTrackingCategory( 'noindex-category' );
+ }
+ if( isset( $this->mDoubleUnderscores['index'] ) && $this->mTitle->canUseNoindex() ){
$this->mOutput->setIndexPolicy( 'index' );
+ $this->addTrackingCategory( 'index-category' );
}
+
wfProfileOut( __METHOD__ );
return $text;
}
/**
+ * Add a tracking category, getting the title from a system message,
+ * or print a debug message if the title is invalid.
+ * @param $msg String message key
+ * @return Bool whether the addition was successful
+ */
+ protected function addTrackingCategory( $msg ){
+ $cat = wfMsgForContent( $msg );
+
+ # Allow tracking categories to be disabled by setting them to "-"
+ if( $cat === '-' ) return false;
+
+ $containerCategory = Title::makeTitleSafe( NS_CATEGORY, $cat );
+ if ( $containerCategory ) {
+ $this->mOutput->addCategory( $containerCategory->getDBkey(), $this->getDefaultSort() );
+ return true;
+ } else {
+ wfDebug( __METHOD__.": [[MediaWiki:$msg]] is not a valid title!\n" );
+ return false;
+ }
+ }
+
+ /**
* This function accomplishes several tasks:
* 1) Auto-number headings if that option is enabled
* 2) Add an [edit] link to sections for users who have enabled the option and can edit the page
@@ -3365,11 +3494,12 @@ class Parser
* string and re-inserts the newly formatted headlines.
*
* @param string $text
+ * @param string $origText Original, untouched wikitext
* @param boolean $isMain
* @private
*/
- function formatHeadings( $text, $isMain=true ) {
- global $wgMaxTocLevel, $wgContLang, $wgEnforceHtmlIds;
+ function formatHeadings( $text, $origText, $isMain=true ) {
+ global $wgMaxTocLevel, $wgContLang, $wgHtml5, $wgExperimentalHtmlIds;
$doNumberHeadings = $this->mOptions->getNumberHeadings();
$showEditLink = $this->mOptions->getEditSection();
@@ -3434,6 +3564,12 @@ class Parser
$prevtoclevel = 0;
$markerRegex = "{$this->mUniqPrefix}-h-(\d+)-" . self::MARKER_SUFFIX;
$baseTitleText = $this->mTitle->getPrefixedDBkey();
+ $oldType = $this->mOutputType;
+ $this->setOutputType( self::OT_WIKI );
+ $frame = $this->getPreprocessor()->newFrame();
+ $root = $this->preprocessToDom( $origText );
+ $node = $root->getFirstChild();
+ $byteOffset = 0;
$tocraw = array();
foreach( $matches[3] as $headline ) {
@@ -3455,68 +3591,61 @@ class Parser
}
$level = $matches[1][$headlineCount];
- if( $doNumberHeadings || $enoughToc ) {
-
- if ( $level > $prevlevel ) {
- # Increase TOC level
- $toclevel++;
- $sublevelCount[$toclevel] = 0;
- if( $toclevel<$wgMaxTocLevel ) {
- $prevtoclevel = $toclevel;
- $toc .= $sk->tocIndent();
- $numVisible++;
- }
+ if ( $level > $prevlevel ) {
+ # Increase TOC level
+ $toclevel++;
+ $sublevelCount[$toclevel] = 0;
+ if( $toclevel<$wgMaxTocLevel ) {
+ $prevtoclevel = $toclevel;
+ $toc .= $sk->tocIndent();
+ $numVisible++;
}
- elseif ( $level < $prevlevel && $toclevel > 1 ) {
- # Decrease TOC level, find level to jump to
+ }
+ 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;
- }
- }
+ for ($i = $toclevel; $i > 0; $i--) {
+ if ( $levelCount[$i] == $level ) {
+ # Found last matching level
+ $toclevel = $i;
+ break;
}
- if( $toclevel<$wgMaxTocLevel ) {
- if($prevtoclevel < $wgMaxTocLevel) {
- # Unindent only if the previous toc level was shown :p
- $toc .= $sk->tocUnindent( $prevtoclevel - $toclevel );
- $prevtoclevel = $toclevel;
- } else {
- $toc .= $sk->tocLineEnd();
- }
+ elseif ( $levelCount[$i] < $level ) {
+ # Found first matching level below current level
+ $toclevel = $i + 1;
+ break;
}
}
- else {
- # No change in level, end TOC line
- if( $toclevel<$wgMaxTocLevel ) {
+ if( $i == 0 ) $toclevel = 1;
+ if( $toclevel<$wgMaxTocLevel ) {
+ if($prevtoclevel < $wgMaxTocLevel) {
+ # Unindent only if the previous toc level was shown :p
+ $toc .= $sk->tocUnindent( $prevtoclevel - $toclevel );
+ $prevtoclevel = $toclevel;
+ } else {
$toc .= $sk->tocLineEnd();
}
}
+ }
+ else {
+ # No change in level, end TOC line
+ if( $toclevel<$wgMaxTocLevel ) {
+ $toc .= $sk->tocLineEnd();
+ }
+ }
- $levelCount[$toclevel] = $level;
+ $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;
+ # 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;
}
}
@@ -3540,16 +3669,13 @@ class Parser
# For the anchor, strip out HTML-y stuff period
$safeHeadline = preg_replace( '/<.*?'.'>/', '', $safeHeadline );
+ $safeHeadline = preg_replace( '/[ _]+/', ' ', $safeHeadline );
$safeHeadline = trim( $safeHeadline );
# Save headline for section edit hint before it's escaped
$headlineHint = $safeHeadline;
- if ( $wgEnforceHtmlIds ) {
- $legacyHeadline = false;
- $safeHeadline = Sanitizer::escapeId( $safeHeadline,
- 'noninitial' );
- } else {
+ if ( $wgHtml5 && $wgExperimentalHtmlIds ) {
# For reverse compatibility, provide an id that's
# HTML4-compatible, like we used to.
#
@@ -3561,20 +3687,17 @@ class Parser
# to type in section names like "abc_.D7.93.D7.90.D7.A4"
# manually, so let's not bother worrying about it.
$legacyHeadline = Sanitizer::escapeId( $safeHeadline,
- 'noninitial' );
- $safeHeadline = Sanitizer::escapeId( $safeHeadline, 'xml' );
+ array( 'noninitial', 'legacy' ) );
+ $safeHeadline = Sanitizer::escapeId( $safeHeadline );
if ( $legacyHeadline == $safeHeadline ) {
# No reason to have both (in fact, we can't)
$legacyHeadline = false;
- } elseif ( $legacyHeadline != Sanitizer::escapeId(
- $legacyHeadline, 'xml' ) ) {
- # The legacy id is invalid XML. We used to allow this, but
- # there's no reason to do so anymore. Backward
- # compatibility will fail slightly in this case, but it's
- # no big deal.
- $legacyHeadline = false;
}
+ } else {
+ $legacyHeadline = false;
+ $safeHeadline = Sanitizer::escapeId( $safeHeadline,
+ 'noninitial' );
}
# HTML names must be case-insensitively unique (bug 10721). FIXME:
@@ -3602,7 +3725,7 @@ class Parser
# Don't number the heading if it is the only one (looks silly)
if( $doNumberHeadings && count( $matches[3] ) > 1) {
# the two are different if the line contains a link
- $headline=$numbering . ' ' . $headline;
+ $headline = $numbering . ' ' . $headline;
}
# Create the anchor for linking from the TOC to the section
@@ -3615,9 +3738,33 @@ class Parser
$legacyAnchor .= '_' . $refers[$legacyArrayKey];
}
if( $enoughToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) {
- $toc .= $sk->tocLine($anchor, $tocline, $numbering, $toclevel);
- $tocraw[] = array( 'toclevel' => $toclevel, 'level' => $level, 'line' => $tocline, 'number' => $numbering );
+ $toc .= $sk->tocLine($anchor, $tocline,
+ $numbering, $toclevel, ($isTemplate ? false : $sectionIndex));
+ }
+
+ # Add the section to the section tree
+ # Find the DOM node for this header
+ while ( $node && !$isTemplate ) {
+ if ( $node->getName() === 'h' ) {
+ $bits = $node->splitHeading();
+ if ( $bits['i'] == $sectionIndex )
+ break;
+ }
+ $byteOffset += mb_strlen( $this->mStripState->unstripBoth(
+ $frame->expand( $node, PPFrame::RECOVER_ORIG ) ) );
+ $node = $node->getNextSibling();
}
+ $tocraw[] = array(
+ 'toclevel' => $toclevel,
+ 'level' => $level,
+ 'line' => $tocline,
+ 'number' => $numbering,
+ 'index' => ($isTemplate ? 'T-' : '' ) . $sectionIndex,
+ 'fromtitle' => $titleText,
+ 'byteoffset' => ( $isTemplate ? null : $byteOffset ),
+ 'anchor' => $anchor,
+ );
+
# give headline the correct <h#> tag
if( $showEditLink && $sectionIndex !== false ) {
if( $isTemplate ) {
@@ -3637,7 +3784,7 @@ class Parser
$headlineCount++;
}
- $this->mOutput->setSections( $tocraw );
+ $this->setOutputType( $oldType );
# Never ever show TOC if no headers
if( $numVisible < 1 ) {
@@ -3649,6 +3796,11 @@ class Parser
$toc .= $sk->tocUnindent( $prevtoclevel - 1 );
}
$toc = $sk->tocList( $toc );
+ $this->mOutput->setTOCHTML( $toc );
+ }
+
+ if ( $isMain ) {
+ $this->mOutput->setSections( $tocraw );
}
# split up and insert constructed headlines
@@ -3684,6 +3836,96 @@ class Parser
}
/**
+ * Merge $tree2 into $tree1 by replacing the section with index
+ * $section in $tree1 and its descendants with the sections in $tree2.
+ * Note that in the returned section tree, only the 'index' and
+ * 'byteoffset' fields are guaranteed to be correct.
+ * @param $tree1 array Section tree from ParserOutput::getSectons()
+ * @param $tree2 array Section tree
+ * @param $section int Section index
+ * @param $title Title Title both section trees come from
+ * @param $len2 int Length of the original wikitext for $tree2
+ * @return array Merged section tree
+ */
+ public static function mergeSectionTrees( $tree1, $tree2, $section, $title, $len2 ) {
+ global $wgContLang;
+ $newTree = array();
+ $targetLevel = false;
+ $merged = false;
+ $lastLevel = 1;
+ $nextIndex = 1;
+ $numbering = array( 0 );
+ $titletext = $title->getPrefixedDBkey();
+ foreach ( $tree1 as $s ) {
+ if ( $targetLevel !== false ) {
+ if ( $s['level'] <= $targetLevel )
+ // We've skipped enough
+ $targetLevel = false;
+ else
+ continue;
+ }
+ if ( $s['index'] != $section ||
+ $s['fromtitle'] != $titletext ) {
+ self::incrementNumbering( $numbering,
+ $s['toclevel'], $lastLevel );
+
+ // Rewrite index, byteoffset and number
+ if ( $s['fromtitle'] == $titletext ) {
+ $s['index'] = $nextIndex++;
+ if ( $merged )
+ $s['byteoffset'] += $len2;
+ }
+ $s['number'] = implode( '.', array_map(
+ array( $wgContLang, 'formatnum' ),
+ $numbering ) );
+ $lastLevel = $s['toclevel'];
+ $newTree[] = $s;
+ } else {
+ // We're at $section
+ // Insert sections from $tree2 here
+ foreach ( $tree2 as $s2 ) {
+ // Rewrite the fields in $s2
+ // before inserting it
+ $s2['toclevel'] += $s['toclevel'] - 1;
+ $s2['level'] += $s['level'] - 1;
+ $s2['index'] = $nextIndex++;
+ $s2['byteoffset'] += $s['byteoffset'];
+
+ self::incrementNumbering( $numbering,
+ $s2['toclevel'], $lastLevel );
+ $s2['number'] = implode( '.', array_map(
+ array( $wgContLang, 'formatnum' ),
+ $numbering ) );
+ $lastLevel = $s2['toclevel'];
+ $newTree[] = $s2;
+ }
+ // Skip all descendants of $section in $tree1
+ $targetLevel = $s['level'];
+ $merged = true;
+ }
+ }
+ return $newTree;
+ }
+
+ /**
+ * Increment a section number. Helper function for mergeSectionTrees()
+ * @param $number array Array representing a section number
+ * @param $level int Current TOC level (depth)
+ * @param $lastLevel int Level of previous TOC entry
+ */
+ private static function incrementNumbering( &$number, $level, $lastLevel ) {
+ if ( $level > $lastLevel )
+ $number[$level - 1] = 1;
+ else if ( $level < $lastLevel ) {
+ foreach ( $number as $key => $unused )
+ if ( $key >= $level )
+ unset( $number[$key] );
+ $number[$level - 1]++;
+ } else
+ $number[$level - 1]++;
+ }
+
+ /**
* Transform wiki markup when saving a page by doing \r\n -> \n
* conversion, substitting signatures, {{subst:}} templates, etc.
*
@@ -3728,26 +3970,29 @@ class Parser
* (see also bug 12815)
*/
$ts = $this->mOptions->getTimestamp();
- $tz = wfMsgForContent( 'timezone-utc' );
if ( isset( $wgLocaltimezone ) ) {
- $unixts = wfTimestamp( TS_UNIX, $ts );
- $oldtz = getenv( 'TZ' );
- putenv( 'TZ='.$wgLocaltimezone );
- $ts = date( 'YmdHis', $unixts );
- $tz = date( 'T', $unixts ); # might vary on DST changeover!
+ $tz = $wgLocaltimezone;
+ } else {
+ $tz = date_default_timezone_get();
+ }
- /* Allow translation of timezones trough wiki. date() can return
- * whatever crap the system uses, localised or not, so we cannot
- * ship premade translations.
- */
- $key = 'timezone-' . strtolower( trim( $tz ) );
- $value = wfMsgForContent( $key );
- if ( !wfEmptyMsg( $key, $value ) ) $tz = $value;
+ $unixts = wfTimestamp( TS_UNIX, $ts );
+ $oldtz = date_default_timezone_get();
+ date_default_timezone_set( $tz );
+ $ts = date( 'YmdHis', $unixts );
+ $tzMsg = date( 'T', $unixts ); # might vary on DST changeover!
- putenv( 'TZ='.$oldtz );
- }
+ /* Allow translation of timezones trough wiki. date() can return
+ * whatever crap the system uses, localised or not, so we cannot
+ * ship premade translations.
+ */
+ $key = 'timezone-' . strtolower( trim( $tzMsg ) );
+ $value = wfMsgForContent( $key );
+ if ( !wfEmptyMsg( $key, $value ) ) $tzMsg = $value;
+
+ date_default_timezone_set( $oldtz );
- $d = $wgContLang->timeanddate( $ts, false, false ) . " ($tz)";
+ $d = $wgContLang->timeanddate( $ts, false, false ) . " ($tzMsg)";
# Variable replacement
# Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags
@@ -3781,7 +4026,7 @@ class Parser
$m = array();
if ( preg_match( "/^($nc+:|)$tc+?( \\($tc+\\))$/", $t, $m ) ) {
$text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
- } elseif ( preg_match( "/^($nc+:|)$tc+?(, $tc+|)$/", $t, $m ) && '' != "$m[1]$m[2]" ) {
+ } elseif ( preg_match( "/^($nc+:|)$tc+?(, $tc+|)$/", $t, $m ) && "$m[1]$m[2]" != '' ) {
$text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
} else {
# if there's no context, don't bother duplicating the title
@@ -3797,22 +4042,30 @@ class Parser
/**
* Fetch the user's signature text, if any, and normalize to
* validated, ready-to-insert wikitext.
+ * If you have pre-fetched the nickname or the fancySig option, you can
+ * specify them here to save a database query.
*
* @param User $user
* @return string
- * @private
*/
- function getUserSig( &$user ) {
+ function getUserSig( &$user, $nickname = false, $fancySig = null ) {
global $wgMaxSigChars;
$username = $user->getName();
- $nickname = $user->getOption( 'nickname' );
- $nickname = $nickname === '' ? $username : $nickname;
+
+ // If not given, retrieve from the user object.
+ if ( $nickname === false )
+ $nickname = $user->getOption( 'nickname' );
+
+ if ( is_null( $fancySig ) )
+ $fancySig = $user->getBoolOption( 'fancysig' );
+
+ $nickname = $nickname == null ? $username : $nickname;
if( mb_strlen( $nickname ) > $wgMaxSigChars ) {
$nickname = $username;
wfDebug( __METHOD__ . ": $username has overlong signature.\n" );
- } elseif( $user->getBoolOption( 'fancysig' ) !== false ) {
+ } elseif( $fancySig !== false ) {
# Sig. might contain markup; validate this
if( $this->validateSig( $nickname ) !== false ) {
# Validated; clean up (if needed) and return it
@@ -4005,28 +4258,30 @@ class Parser
* @param integer $flags a combination of the following flags:
* 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
+ * 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
+ * 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.
*
* The $frame parameter is a PPFrame. This can be used to produce expanded text from the
* arguments, for instance:
* $text = isset( $args[0] ) ? $frame->expand( $args[0] ) : '';
*
- * For technical reasons, $args[0] is pre-expanded and will be a string. This may change in
+ * For technical reasons, $args[0] is pre-expanded and will be a string. This may change in
* future versions. Please call $frame->expand() on it anyway so that your code keeps
* working if/when this is changed.
*
* If you want whitespace to be trimmed from $args, you need to do it yourself, post-
* expansion.
*
- * Please read the documentation in includes/parser/Preprocessor.php for more information
+ * Please read the documentation in includes/parser/Preprocessor.php for more information
* about the methods available in PPFrame and PPNode.
*
* @return The old callback function for this name, if any
*/
function setFunctionHook( $id, $callback, $flags = 0 ) {
+ global $wgContLang;
+
$oldVal = isset( $this->mFunctionHooks[$id] ) ? $this->mFunctionHooks[$id][0] : null;
$this->mFunctionHooks[$id] = array( $callback, $flags );
@@ -4041,7 +4296,7 @@ class Parser
foreach ( $synonyms as $syn ) {
# Case
if ( !$sensitive ) {
- $syn = strtolower( $syn );
+ $syn = $wgContLang->lc( $syn );
}
# Add leading hash
if ( !( $flags & SFH_NO_HASH ) ) {
@@ -4066,6 +4321,25 @@ class Parser
}
/**
+ * Create a tag function, e.g. <test>some stuff</test>.
+ * Unlike tag hooks, tag functions are parsed at preprocessor level.
+ * Unlike parser functions, their content is not preprocessed.
+ */
+ function setFunctionTagHook( $tag, $callback, $flags ) {
+ $tag = strtolower( $tag );
+ $old = isset( $this->mFunctionTagHooks[$tag] ) ?
+ $this->mFunctionTagHooks[$tag] : null;
+ $this->mFunctionTagHooks[$tag] = array( $callback, $flags );
+
+ if( !in_array( $tag, $this->mStripList ) ) {
+ $this->mStripList[] = $tag;
+ }
+
+ return $old;
+ }
+
+ /**
+ * FIXME: update documentation. makeLinkObj() is deprecated.
* Replace <!--LINK--> link placeholders with actual links, in the buffer
* Placeholders created in Skin::makeLinkObj()
* Returns an array of link CSS classes, indexed by PDBK.
@@ -4085,19 +4359,6 @@ class Parser
}
/**
- * Tag hook handler for 'pre'.
- */
- function renderPreTag( $text, $attribs ) {
- // Backwards-compatibility hack
- $content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' );
-
- $attribs = Sanitizer::validateTagAttributes( $attribs, 'pre' );
- return Xml::openElement( 'pre', $attribs ) .
- Xml::escapeTagsOnly( $content ) .
- '</pre>';
- }
-
- /**
* Renders an image gallery from a text with one line per image.
* text labels may be given by using |-style alternative text. E.g.
* Image:one.jpg|The number "1"
@@ -4145,7 +4406,7 @@ class Parser
if ( count( $matches ) == 0 ) {
continue;
}
-
+
if ( strpos( $matches[0], '%' ) !== false )
$matches[1] = urldecode( $matches[1] );
$tp = Title::newFromText( $matches[1]/*, NS_FILE*/ );
@@ -4227,11 +4488,13 @@ class Parser
# * none same, but not aligned
# * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
# * center center the image
- # * framed Keep original image size, no magnify-button.
+ # * frame Keep original image size, no magnify-button.
+ # * framed Same as "frame"
# * frameless like 'thumb' but without a frame. Keeps user preferences for width
# * upright reduce width for upright images, rounded to full __0 px
# * border draw a 1px border around the image
# * alt Text for HTML alt attribute (defaults to empty)
+ # * link Set the target of the image link. Can be external, interwiki, or local
# vertical-align values (no % or length right now):
# * baseline
# * sub
@@ -4255,15 +4518,7 @@ class Parser
# Get the file
$imagename = $title->getDBkey();
- if ( isset( $this->mFileCache[$imagename][$time] ) ) {
- $file = $this->mFileCache[$imagename][$time];
- } else {
- $file = wfFindFile( $title, $time );
- if ( count( $this->mFileCache ) > 1000 ) {
- $this->mFileCache = array();
- }
- $this->mFileCache[$imagename][$time] = $file;
- }
+ $file = wfFindFile( $title, array( 'time' => $time ) );
# Get parameter map
$handler = $file ? $file->getHandler() : false;
@@ -4312,7 +4567,7 @@ class Parser
switch( $paramName ) {
case 'manualthumb':
case 'alt':
- // @fixme - possibly check validity here for
+ // @todo Fixme: possibly check validity here for
// manualthumb? downstream behavior seems odd with
// missing manual thumbs.
$validated = true;
@@ -4367,7 +4622,11 @@ class Parser
$params['frame']['caption'] = $caption;
- $params['frame']['title'] = $this->stripAltText( $caption, $holders );
+ # Will the image be presented in a frame, with the caption below?
+ $imageIsFramed = isset( $params['frame']['frame'] ) ||
+ isset( $params['frame']['framed'] ) ||
+ isset( $params['frame']['thumbnail'] ) ||
+ isset( $params['frame']['manualthumb'] );
# In the old days, [[Image:Foo|text...]] would set alt text. Later it
# came to also set the caption, ordinary text after the image -- which
@@ -4385,11 +4644,27 @@ class Parser
# named parameter entirely for images without a caption; adding an ex-
# plicit caption= parameter and preserving the old magic unnamed para-
# meter for BC; ...
- if( $caption !== '' && !isset( $params['frame']['alt'] )
- && !isset( $params['frame']['framed'] )
- && !isset( $params['frame']['thumbnail'] )
- && !isset( $params['frame']['manualthumb'] ) ) {
- $params['frame']['alt'] = $params['frame']['title'];
+ if ( $imageIsFramed ) { # Framed image
+ if ( $caption === '' && !isset( $params['frame']['alt'] ) ) {
+ # No caption or alt text, add the filename as the alt text so
+ # that screen readers at least get some description of the image
+ $params['frame']['alt'] = $title->getText();
+ }
+ # Do not set $params['frame']['title'] because tooltips don't make sense
+ # for framed images
+ } else { # Inline image
+ if ( !isset( $params['frame']['alt'] ) ) {
+ # No alt text, use the "caption" for the alt text
+ if ( $caption !== '') {
+ $params['frame']['alt'] = $this->stripAltText( $caption, $holders );
+ } else {
+ # No caption, fall back to using the filename for the
+ # alt text
+ $params['frame']['alt'] = $title->getText();
+ }
+ }
+ # Use the "caption" for the tooltip text
+ $params['frame']['title'] = $this->stripAltText( $caption, $holders );
}
wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );
@@ -4404,7 +4679,7 @@ class Parser
return $ret;
}
-
+
protected function stripAltText( $caption, $holders ) {
# Strip bad stuff out of the title (tooltip). We can't just use
# replaceLinkHoldersText() here, because if this function is called
@@ -4420,7 +4695,7 @@ class Parser
# remove the tags
$tooltip = $this->mStripState->unstripBoth( $tooltip );
$tooltip = Sanitizer::stripAllTags( $tooltip );
-
+
return $tooltip;
}
@@ -4452,9 +4727,9 @@ class Parser
/**#@+
* Accessor/mutator
*/
- function Title( $x = NULL ) { return wfSetVar( $this->mTitle, $x ); }
- function Options( $x = NULL ) { return wfSetVar( $this->mOptions, $x ); }
- function OutputType( $x = NULL ) { return wfSetVar( $this->mOutputType, $x ); }
+ function Title( $x = null ) { return wfSetVar( $this->mTitle, $x ); }
+ function Options( $x = null ) { return wfSetVar( $this->mOptions, $x ); }
+ function OutputType( $x = null ) { return wfSetVar( $this->mOutputType, $x ); }
/**#@-*/
/**#@+
@@ -4856,7 +5131,7 @@ class Parser
$links['interwiki'][] = $this->mLinkHolders->interwiki[$key];
$pos = $start_pos + strlen( "<!--IWLINK $key-->" );
}
-
+
$data['linkholder'] = $links;
return $data;
@@ -4865,7 +5140,7 @@ class Parser
function unserialiseHalfParsedText( $data, $intPrefix = null /* Unique identifying prefix */ ) {
if (!$intPrefix)
$intPrefix = $this->getRandomString();
-
+
// First, extract the strip state.
$stripState = $data['stripstate'];
$this->mStripState->general->merge( $stripState->general );
diff --git a/includes/parser/ParserCache.php b/includes/parser/ParserCache.php
index d17214c3..524d6be5 100644
--- a/includes/parser/ParserCache.php
+++ b/includes/parser/ParserCache.php
@@ -7,7 +7,7 @@ class ParserCache {
/**
* Get an instance of this object
*/
- public static function &singleton() {
+ public static function singleton() {
static $instance;
if ( !isset( $instance ) ) {
global $parserMemc;
@@ -22,11 +22,11 @@ class ParserCache {
*
* @param object $memCached
*/
- function __construct( &$memCached ) {
- $this->mMemc =& $memCached;
+ function __construct( $memCached ) {
+ $this->mMemc = $memCached;
}
- function getKey( &$article, $popts ) {
+ function getKey( $article, $popts ) {
global $wgRequest;
if( $popts instanceof User ) // It used to be getKey( &$article, &$user )
@@ -47,52 +47,55 @@ class ParserCache {
return $key;
}
- function getETag( &$article, $popts ) {
+ function getETag( $article, $popts ) {
return 'W/"' . $this->getKey($article, $popts) . "--" . $article->mTouched. '"';
}
- function get( &$article, $popts ) {
- global $wgCacheEpoch;
- $fname = 'ParserCache::get';
- wfProfileIn( $fname );
-
+ function getDirty( $article, $popts ) {
$key = $this->getKey( $article, $popts );
-
wfDebug( "Trying parser cache $key\n" );
$value = $this->mMemc->get( $key );
- if ( is_object( $value ) ) {
- wfDebug( "Found.\n" );
- # Delete if article has changed since the cache was made
- $canCache = $article->checkTouched();
- $cacheTime = $value->getCacheTime();
- $touched = $article->mTouched;
- if ( !$canCache || $value->expired( $touched ) ) {
- if ( !$canCache ) {
- wfIncrStats( "pcache_miss_invalid" );
- wfDebug( "Invalid cached redirect, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
- } else {
- wfIncrStats( "pcache_miss_expired" );
- wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
- }
- $this->mMemc->delete( $key );
- $value = false;
- } else {
- if ( isset( $value->mTimestamp ) ) {
- $article->mTimestamp = $value->mTimestamp;
- }
- wfIncrStats( "pcache_hit" );
- }
- } else {
+ return is_object( $value ) ? $value : false;
+ }
+
+ function get( $article, $popts ) {
+ global $wgCacheEpoch;
+ wfProfileIn( __METHOD__ );
+
+ $value = $this->getDirty( $article, $popts );
+ if ( !$value ) {
wfDebug( "Parser cache miss.\n" );
wfIncrStats( "pcache_miss_absent" );
+ wfProfileOut( __METHOD__ );
+ return false;
+ }
+
+ wfDebug( "Found.\n" );
+ # Invalid if article has changed since the cache was made
+ $canCache = $article->checkTouched();
+ $cacheTime = $value->getCacheTime();
+ $touched = $article->mTouched;
+ if ( !$canCache || $value->expired( $touched ) ) {
+ if ( !$canCache ) {
+ wfIncrStats( "pcache_miss_invalid" );
+ wfDebug( "Invalid cached redirect, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
+ } else {
+ wfIncrStats( "pcache_miss_expired" );
+ wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
+ }
$value = false;
+ } else {
+ if ( isset( $value->mTimestamp ) ) {
+ $article->mTimestamp = $value->mTimestamp;
+ }
+ wfIncrStats( "pcache_hit" );
}
- wfProfileOut( $fname );
+ wfProfileOut( __METHOD__ );
return $value;
}
- function save( $parserOutput, &$article, $popts ){
+ function save( $parserOutput, $article, $popts ){
global $wgParserCacheExpireTime;
$key = $this->getKey( $article, $popts );
diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php
index e6a9f3a7..985bba28 100644
--- a/includes/parser/ParserOptions.php
+++ b/includes/parser/ParserOptions.php
@@ -5,10 +5,8 @@
* @todo document
* @ingroup Parser
*/
-class ParserOptions
-{
+class ParserOptions {
# All variables are supposed to be private in theory, although in practise this is not the case.
- var $mUseTeX; # Use texvc to expand <math> tags
var $mUseDynamicDates; # Use DateFormatter to format dates
var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
var $mAllowExternalImages; # Allow external images inline
@@ -35,9 +33,8 @@ class ParserOptions
var $mUser; # Stored user object, just used to initialise the skin
var $mIsPreview; # Parsing the page for a "preview" operation
var $mIsSectionPreview; # Parsing the page for a "preview" operation on a single section
- var $mIsPrintable; # Parsing the printable version of the page
+ var $mIsPrintable; # Parsing the printable version of the page
- function getUseTeX() { return $this->mUseTeX; }
function getUseDynamicDates() { return $this->mUseDynamicDates; }
function getInterwikiMagic() { return $this->mInterwikiMagic; }
function getAllowExternalImages() { return $this->mAllowExternalImages; }
@@ -59,8 +56,8 @@ class ParserOptions
function getExternalLinkTarget() { return $this->mExternalLinkTarget; }
function getIsPreview() { return $this->mIsPreview; }
function getIsSectionPreview() { return $this->mIsSectionPreview; }
- function getIsPrintable() { return $this->mIsPrintable; }
-
+ function getIsPrintable() { return $this->mIsPrintable; }
+
function getSkin() {
if ( !isset( $this->mSkin ) ) {
$this->mSkin = $this->mUser->getSkin();
@@ -82,7 +79,6 @@ class ParserOptions
return $this->mTimestamp;
}
- function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); }
function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); }
function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic, $x ); }
function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); }
@@ -107,8 +103,8 @@ class ParserOptions
function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget, $x ); }
function setIsPreview( $x ) { return wfSetVar( $this->mIsPreview, $x ); }
function setIsSectionPreview( $x ) { return wfSetVar( $this->mIsSectionPreview, $x ); }
- function setIsPrintable( $x ) { return wfSetVar( $this->mIsPrintable, $x ); }
-
+ function setIsPrintable( $x ) { return wfSetVar( $this->mIsPrintable, $x ); }
+
function __construct( $user = null ) {
$this->initialiseFromUser( $user );
}
@@ -123,12 +119,13 @@ class ParserOptions
/** Get user options */
function initialiseFromUser( $userInput ) {
- global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
+ global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize;
global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures;
global $wgExternalLinkTarget;
- $fname = 'ParserOptions::initialiseFromUser';
- wfProfileIn( $fname );
+
+ wfProfileIn( __METHOD__ );
+
if ( !$userInput ) {
global $wgUser;
if ( isset( $wgUser ) ) {
@@ -142,7 +139,6 @@ class ParserOptions
$this->mUser = $user;
- $this->mUseTeX = $wgUseTeX;
$this->mUseDynamicDates = $wgUseDynamicDates;
$this->mInterwikiMagic = $wgInterwikiMagic;
$this->mAllowExternalImages = $wgAllowExternalImages;
@@ -167,6 +163,7 @@ class ParserOptions
$this->mExternalLinkTarget = $wgExternalLinkTarget;
$this->mIsPreview = false;
$this->mIsSectionPreview = false;
- wfProfileOut( $fname );
+
+ wfProfileOut( __METHOD__ );
}
}
diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php
index 22c1dfba..ea5840e6 100644
--- a/includes/parser/ParserOutput.php
+++ b/includes/parser/ParserOutput.php
@@ -24,14 +24,10 @@ class ParserOutput
$mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
$mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
$mSections = array(), # Table of contents
- $mProperties = array(); # Name/value pairs to be cached in the DB
+ $mProperties = array(), # Name/value pairs to be cached in the DB
+ $mTOCHTML = ''; # HTML of the TOC
private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
- /**
- * Overridden title for display
- */
- private $displayTitle = false;
-
function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
$containsOldMagic = false, $titletext = '' )
{
@@ -54,10 +50,12 @@ class ParserOutput
function &getImages() { return $this->mImages; }
function &getExternalLinks() { return $this->mExternalLinks; }
function getNoGallery() { return $this->mNoGallery; }
+ function getHeadItems() { return $this->mHeadItems; }
function getSubtitle() { return $this->mSubtitle; }
function getOutputHooks() { return (array)$this->mOutputHooks; }
function getWarnings() { return array_keys( $this->mWarnings ); }
function getIndexPolicy() { return $this->mIndexPolicy; }
+ function getTOCHTML() { return $this->mTOCHTML; }
function containsOldMagic() { return $this->mContainsOldMagic; }
function setText( $text ) { return wfSetVar( $this->mText, $text ); }
@@ -68,10 +66,10 @@ class ParserOutput
function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); }
function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); }
function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); }
+ function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML, $tochtml ); }
function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
- function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
function addWarning( $s ) { $this->mWarnings[$s] = 1; }
function addOutputHook( $hook, $data = false ) {
@@ -91,7 +89,18 @@ class ParserOutput
return (bool)$this->mNewSection;
}
+ function addExternalLink( $url ) {
+ # We don't register links pointing to our own server, unless... :-)
+ global $wgServer, $wgRegisterInternalExternals;
+ if( $wgRegisterInternalExternals or stripos($url,$wgServer.'/')!==0)
+ $this->mExternalLinks[$url] = 1;
+ }
+
function addLink( $title, $id = null ) {
+ if ( $title->isExternal() ) {
+ // Don't record interwikis in pagelinks
+ return;
+ }
$ns = $title->getNamespace();
$dbk = $title->getDBkey();
if ( $ns == NS_MEDIA ) {
@@ -170,7 +179,7 @@ class ParserOutput
* @param string $text Desired title text
*/
public function setDisplayTitle( $text ) {
- $this->displayTitle = $text;
+ $this->setTitleText( $text );
}
/**
@@ -179,7 +188,11 @@ class ParserOutput
* @return string
*/
public function getDisplayTitle() {
- return $this->displayTitle;
+ $t = $this->getTitleText( );
+ if( $t === '' ) {
+ return false;
+ }
+ return $t;
}
/**
diff --git a/includes/parser/Preprocessor.php b/includes/parser/Preprocessor.php
index 1a33ac7f..9c417d23 100644
--- a/includes/parser/Preprocessor.php
+++ b/includes/parser/Preprocessor.php
@@ -66,6 +66,21 @@ interface PPFrame {
function isEmpty();
/**
+ * Returns all arguments of this frame
+ */
+ function getArguments();
+
+ /**
+ * Returns all numbered arguments of this frame
+ */
+ function getNumberedArguments();
+
+ /**
+ * Returns all named arguments of this frame
+ */
+ function getNamedArguments();
+
+ /**
* Get an argument to this frame by name
*/
function getArgument( $name );
diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php
index 2e114545..673ac241 100644
--- a/includes/parser/Preprocessor_DOM.php
+++ b/includes/parser/Preprocessor_DOM.php
@@ -419,7 +419,8 @@ class Preprocessor_DOM implements Preprocessor {
'count' => $count );
$stack->push( $piece );
$accum =& $stack->getAccum();
- extract( $stack->getFlags() );
+ $flags = $stack->getFlags();
+ extract( $flags );
$i += $count;
}
}
@@ -470,7 +471,8 @@ class Preprocessor_DOM implements Preprocessor {
// Unwind the stack
$stack->pop();
$accum =& $stack->getAccum();
- extract( $stack->getFlags() );
+ $flags = $stack->getFlags();
+ extract( $flags );
// Append the result to the enclosing accumulator
$accum .= $element;
@@ -497,7 +499,8 @@ class Preprocessor_DOM implements Preprocessor {
$stack->push( $piece );
$accum =& $stack->getAccum();
- extract( $stack->getFlags() );
+ $flags = $stack->getFlags();
+ extract( $flags );
} else {
# Add literal brace(s)
$accum .= htmlspecialchars( str_repeat( $curChar, $count ) );
@@ -597,8 +600,8 @@ class Preprocessor_DOM implements Preprocessor {
}
$enclosingAccum .= str_repeat( $piece->open, $skippedBraces );
}
-
- extract( $stack->getFlags() );
+ $flags = $stack->getFlags();
+ extract( $flags );
# Add XML element to the enclosing accumulator
$accum .= $element;
@@ -1189,6 +1192,18 @@ class PPFrame_DOM implements PPFrame {
}
}
+ function getArguments() {
+ return array();
+ }
+
+ function getNumberedArguments() {
+ return array();
+ }
+
+ function getNamedArguments() {
+ return array();
+ }
+
/**
* Returns true if there are no arguments in this frame
*/
@@ -1224,8 +1239,7 @@ class PPTemplateFrame_DOM extends PPFrame_DOM {
var $numberedExpansionCache, $namedExpansionCache;
function __construct( $preprocessor, $parent = false, $numberedArgs = array(), $namedArgs = array(), $title = false ) {
- $this->preprocessor = $preprocessor;
- $this->parser = $preprocessor->parser;
+ PPFrame_DOM::__construct( $preprocessor );
$this->parent = $parent;
$this->numberedArgs = $numberedArgs;
$this->namedArgs = $namedArgs;
@@ -1337,8 +1351,7 @@ class PPCustomFrame_DOM extends PPFrame_DOM {
var $args;
function __construct( $preprocessor, $args ) {
- $this->preprocessor = $preprocessor;
- $this->parser = $preprocessor->parser;
+ PPFrame_DOM::__construct( $preprocessor );
$this->args = $args;
}
diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php
index f46ee40c..c5d69685 100644
--- a/includes/parser/Preprocessor_Hash.php
+++ b/includes/parser/Preprocessor_Hash.php
@@ -1139,6 +1139,18 @@ class PPFrame_Hash implements PPFrame {
}
}
+ function getArguments() {
+ return array();
+ }
+
+ function getNumberedArguments() {
+ return array();
+ }
+
+ function getNamedArguments() {
+ return array();
+ }
+
/**
* Returns true if there are no arguments in this frame
*/
@@ -1174,8 +1186,7 @@ class PPTemplateFrame_Hash extends PPFrame_Hash {
var $numberedExpansionCache, $namedExpansionCache;
function __construct( $preprocessor, $parent = false, $numberedArgs = array(), $namedArgs = array(), $title = false ) {
- $this->preprocessor = $preprocessor;
- $this->parser = $preprocessor->parser;
+ PPFrame_Hash::__construct( $preprocessor );
$this->parent = $parent;
$this->numberedArgs = $numberedArgs;
$this->namedArgs = $namedArgs;
@@ -1287,8 +1298,7 @@ class PPCustomFrame_Hash extends PPFrame_Hash {
var $args;
function __construct( $preprocessor, $args ) {
- $this->preprocessor = $preprocessor;
- $this->parser = $preprocessor->parser;
+ PPFrame_Hash::__construct( $preprocessor );
$this->args = $args;
}