X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FParser.php;h=14d45bd3de174d78dfb459032f40b92ebe13b4f5;hb=4e250a20b9fde4e72128f391fae65760196795fb;hp=2123630731a6ce5fb303df494facf8777b9a2ace;hpb=51e44c9f4ca395fb94e159c22c37bf129a767daa;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/Parser.php b/includes/Parser.php
index 2123630731..14d45bd3de 100644
--- a/includes/Parser.php
+++ b/includes/Parser.php
@@ -2,8 +2,7 @@
/**
* File for Parser and related classes
*
- * @package MediaWiki
- * @subpackage Parser
+ * @addtogroup Parser
*/
/**
@@ -62,13 +61,15 @@ define( 'MW_COLON_STATE_COMMENTDASHDASH', 7 );
* Processes wiki markup
*
*
- * There are three main entry points into the Parser class:
+ * There are four main entry points into the Parser class:
* parse()
* produces HTML output
* preSaveTransform().
* produces altered wiki markup.
* transformMsg()
* performs brace substitution on MediaWiki messages
+ * preprocess()
+ * removes HTML comments and expands templates
*
* Globals used:
* objects: $wgLang, $wgContLang
@@ -78,16 +79,16 @@ define( 'MW_COLON_STATE_COMMENTDASHDASH', 7 );
* settings:
* $wgUseTex*, $wgUseDynamicDates*, $wgInterwikiMagic*,
* $wgNamespacesWithSubpages, $wgAllowExternalImages*,
- * $wgLocaltimezone, $wgAllowSpecialInclusion*,
+ * $wgLocaltimezone, $wgAllowSpecialInclusion*,
* $wgMaxArticleSize*
*
* * only within ParserOptions
*
*
- * @package MediaWiki
*/
class Parser
{
+ const VERSION = MW_PARSER_VERSION;
/**#@+
* @private
*/
@@ -95,10 +96,10 @@ class Parser
var $mTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables;
# Cleared with clearState():
- var $mOutput, $mAutonumber, $mDTopen, $mStripState = array();
+ var $mOutput, $mAutonumber, $mDTopen, $mStripState;
var $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
var $mInterwikiLinkHolders, $mLinkHolders, $mUniqPrefix;
- var $mIncludeSizes;
+ var $mIncludeSizes, $mDefaultSort;
var $mTemplates, // cache of already loaded templates, avoids
// multiple SQL queries for the same string
$mTemplatePath; // stores an unsorted hash of all the templates already loaded
@@ -110,7 +111,9 @@ class Parser
$mTitle, // Title context, used for self-link rendering and similar things
$mOutputType, // Output type, one of the OT_xxx constants
$ot, // Shortcut alias, see setOutputType()
- $mRevisionId; // ID to display in {{REVISIONID}} tags
+ $mRevisionId, // ID to display in {{REVISIONID}} tags
+ $mRevisionTimestamp, // The timestamp of the specified revision ID
+ $mRevIdForTs; // The revision ID which was used to fetch the timestamp
/**#@-*/
@@ -139,6 +142,7 @@ class Parser
$this->setHook( 'pre', array( $this, 'renderPreTag' ) );
+ $this->setFunctionHook( 'int', array( 'CoreParserFunctions', 'intFunction' ), SFH_NO_HASH );
$this->setFunctionHook( 'ns', array( 'CoreParserFunctions', 'ns' ), SFH_NO_HASH );
$this->setFunctionHook( 'urlencode', array( 'CoreParserFunctions', 'urlencode' ), SFH_NO_HASH );
$this->setFunctionHook( 'lcfirst', array( 'CoreParserFunctions', 'lcfirst' ), SFH_NO_HASH );
@@ -160,6 +164,9 @@ class Parser
$this->setFunctionHook( 'language', array( 'CoreParserFunctions', 'language' ), SFH_NO_HASH );
$this->setFunctionHook( 'padleft', array( 'CoreParserFunctions', 'padleft' ), SFH_NO_HASH );
$this->setFunctionHook( 'padright', array( 'CoreParserFunctions', 'padright' ), SFH_NO_HASH );
+ $this->setFunctionHook( 'anchorencode', array( 'CoreParserFunctions', 'anchorencode' ), SFH_NO_HASH );
+ $this->setFunctionHook( 'special', array( 'CoreParserFunctions', 'special' ) );
+ $this->setFunctionHook( 'defaultsort', array( 'CoreParserFunctions', 'defaultsort' ), SFH_NO_HASH );
if ( $wgAllowDisplayTitle ) {
$this->setFunctionHook( 'displaytitle', array( 'CoreParserFunctions', 'displaytitle' ), SFH_NO_HASH );
@@ -167,12 +174,11 @@ class Parser
if ( $wgAllowSlowParserFunctions ) {
$this->setFunctionHook( 'pagesinnamespace', array( 'CoreParserFunctions', 'pagesinnamespace' ), SFH_NO_HASH );
}
-
- $this->initialiseVariables();
+ $this->initialiseVariables();
$this->mFirstCall = false;
wfProfileOut( __METHOD__ );
- }
+ }
/**
* Clear Parser state
@@ -189,7 +195,7 @@ class Parser
$this->mLastSection = '';
$this->mDTopen = false;
$this->mIncludeCount = array();
- $this->mStripState = array();
+ $this->mStripState = new StripState;
$this->mArgStack = array();
$this->mInPre = false;
$this->mInterwikiLinkHolders = array(
@@ -203,8 +209,8 @@ class Parser
'texts' => array(),
'titles' => array()
);
- $this->mRevisionId = null;
-
+ $this->mRevisionTimestamp = $this->mRevisionId = null;
+
/**
* Prefix for temporary replacement strings for the multipass parser.
* \x07 should never appear in input as it's disallowed in XML.
@@ -225,6 +231,7 @@ class Parser
'post-expand' => 0,
'arg' => 0
);
+ $this->mDefaultSort = false;
wfRunHooks( 'ParserClearState', array( &$this ) );
wfProfileOut( __METHOD__ );
@@ -254,7 +261,6 @@ class Parser
* Convert wikitext to HTML
* Do not call this function recursively.
*
- * @private
* @param string $text Text we want to parse
* @param Title &$title A title object
* @param array $options
@@ -263,14 +269,15 @@ class Parser
* @param int $revid number to pass in {{REVISIONID}}
* @return ParserOutput a ParserOutput
*/
- function parse( $text, &$title, $options, $linestart = true, $clearState = true, $revid = null ) {
+ public function parse( $text, &$title, $options, $linestart = true, $clearState = true, $revid = null ) {
/**
* First pass--just handle sections, pass the rest off
* to internalParse() which does all the real work.
*/
global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang;
- $fname = 'Parser::parse';
+ $fname = 'Parser::parse-' . wfGetCaller();
+ wfProfileIn( __METHOD__ );
wfProfileIn( $fname );
if ( $clearState ) {
@@ -280,22 +287,17 @@ class Parser
$this->mOptions = $options;
$this->mTitle =& $title;
$oldRevisionId = $this->mRevisionId;
+ $oldRevisionTimestamp = $this->mRevisionTimestamp;
if( $revid !== null ) {
$this->mRevisionId = $revid;
+ $this->mRevisionTimestamp = null;
}
$this->setOutputType( OT_HTML );
-
- //$text = $this->strip( $text, $this->mStripState );
- // VOODOO MAGIC FIX! Sometimes the above segfaults in PHP5.
- $x =& $this->mStripState;
-
- wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$x ) );
- $text = $this->strip( $text, $x );
- wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$x ) );
-
+ wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
+ $text = $this->strip( $text, $this->mStripState );
+ wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
$text = $this->internalParse( $text );
-
- $text = $this->unstrip( $text, $this->mStripState );
+ $text = $this->mStripState->unstripGeneral( $text );
# Clean up special characters, only run once, next-to-last before doBlockLevels
$fixtags = array(
@@ -318,7 +320,7 @@ class Parser
# Side-effects: this calls $this->mOutput->setTitleText()
$text = $wgContLang->parserConvert( $text, $this );
- $text = $this->unstripNoWiki( $text, $this->mStripState );
+ $text = $this->mStripState->unstripNoWiki( $text );
wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
@@ -368,7 +370,9 @@ class Parser
}
$this->mOutput->setText( $text );
$this->mRevisionId = $oldRevisionId;
+ $this->mRevisionTimestamp = $oldRevisionTimestamp;
wfProfileOut( $fname );
+ wfProfileOut( __METHOD__ );
return $this->mOutput;
}
@@ -379,10 +383,9 @@ class Parser
*/
function recursiveTagParse( $text ) {
wfProfileIn( __METHOD__ );
- $x =& $this->mStripState;
- wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$x ) );
- $text = $this->strip( $text, $x );
- wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$x ) );
+ wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
+ $text = $this->strip( $text, $this->mStripState );
+ wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
$text = $this->internalParse( $text );
wfProfileOut( __METHOD__ );
return $text;
@@ -398,16 +401,14 @@ class Parser
$this->setOutputType( OT_PREPROCESS );
$this->mOptions = $options;
$this->mTitle = $title;
- $x =& $this->mStripState;
- wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$x ) );
- $text = $this->strip( $text, $x );
- wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$x ) );
+ wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
+ $text = $this->strip( $text, $this->mStripState );
+ wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
if ( $this->mOptions->getRemoveComments() ) {
$text = Sanitizer::removeHTMLcomments( $text );
}
$text = $this->replaceVariables( $text );
- $text = $this->unstrip( $text, $x );
- $text = $this->unstripNowiki( $text, $x );
+ $text = $this->mStripState->unstripBoth( $text );
wfProfileOut( __METHOD__ );
return $text;
}
@@ -501,7 +502,7 @@ class Parser
$text = $q[2];
}
}
-
+
$matches[$marker] = array( $element,
$content,
Sanitizer::decodeTagAttributes( $attributes ),
@@ -514,25 +515,29 @@ class Parser
* Strips and renders nowiki, pre, math, hiero
* If $render is set, performs necessary rendering operations on plugins
* Returns the text, and fills an array with data needed in unstrip()
- * If the $state is already a valid strip state, it adds to the state
+ *
+ * @param StripState $state
*
* @param bool $stripcomments when set, HTML comments
* will be stripped in addition to other tags. This is important
* for section editing, where these comments cause confusion when
* counting the sections in the wikisource
- *
+ *
* @param array dontstrip contains tags which should not be stripped;
* used to prevent stipping of when saving (fixes bug 2700)
*
* @private
*/
- function strip( $text, &$state, $stripcomments = false , $dontstrip = array () ) {
+ function strip( $text, $state, $stripcomments = false , $dontstrip = array () ) {
+ global $wgContLang;
wfProfileIn( __METHOD__ );
$render = ($this->mOutputType == OT_HTML);
$uniq_prefix = $this->mUniqPrefix;
- $commentState = array();
-
+ $commentState = new ReplacementArray;
+ $nowikiItems = array();
+ $generalItems = array();
+
$elements = array_merge(
array( 'nowiki', 'gallery' ),
array_keys( $this->mTagHooks ) );
@@ -543,13 +548,13 @@ class Parser
if( $this->mOptions->getUseTeX() ) {
$elements[] = 'math';
}
-
+
# Removing $dontstrip tags from $elements list (currently only 'gallery', fixing bug 2700)
foreach ( $elements AS $k => $v ) {
if ( !in_array ( $v , $dontstrip ) ) continue;
unset ( $elements[$k] );
}
-
+
$matches = array();
$text = Parser::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
@@ -576,10 +581,10 @@ class Parser
}
// Shouldn't happen otherwise. :)
case 'nowiki':
- $output = wfEscapeHTMLTagsOnly( $content );
+ $output = Xml::escapeTagsOnly( $content );
break;
case 'math':
- $output = MathRenderer::renderMath( $content );
+ $output = $wgContLang->armourMath( MathRenderer::renderMath( $content ) );
break;
case 'gallery':
$output = $this->renderImageGallery( $content, $params );
@@ -598,18 +603,22 @@ class Parser
$output = $tag;
}
- // Unstrip the output, because unstrip() is no longer recursive so
- // it won't do it itself
- $output = $this->unstrip( $output, $state );
+ // Unstrip the output, to support recursive strip() calls
+ $output = $state->unstripBoth( $output );
if( !$stripcomments && $element == '!--' ) {
- $commentState[$marker] = $output;
+ $commentState->setPair( $marker, $output );
} elseif ( $element == 'html' || $element == 'nowiki' ) {
- $state['nowiki'][$marker] = $output;
+ $nowikiItems[$marker] = $output;
} else {
- $state['general'][$marker] = $output;
+ $generalItems[$marker] = $output;
}
}
+ # Add the new items to the state
+ # We do this after the loop instead of during it to avoid slowing
+ # down the recursive unstrip
+ $state->nowiki->mergeArray( $nowikiItems );
+ $state->general->mergeArray( $generalItems );
# Unstrip comments unless explicitly told otherwise.
# (The comments are always stripped prior to this point, so as to
@@ -617,7 +626,7 @@ class Parser
# a comment.)
if ( !$stripcomments ) {
// Put them all back and forget them
- $text = strtr( $text, $commentState );
+ $text = $commentState->replace( $text );
}
wfProfileOut( __METHOD__ );
@@ -629,35 +638,27 @@ class Parser
*
* always call unstripNoWiki() after this one
* @private
+ * @deprecated use $this->mStripState->unstrip()
*/
- function unstrip( $text, &$state ) {
- if ( !isset( $state['general'] ) ) {
- return $text;
- }
-
- wfProfileIn( __METHOD__ );
- # TODO: good candidate for FSS
- $text = strtr( $text, $state['general'] );
- wfProfileOut( __METHOD__ );
- return $text;
+ function unstrip( $text, $state ) {
+ return $state->unstripGeneral( $text );
}
/**
* Always call this after unstrip() to preserve the order
*
* @private
+ * @deprecated use $this->mStripState->unstrip()
*/
- function unstripNoWiki( $text, &$state ) {
- if ( !isset( $state['nowiki'] ) ) {
- return $text;
- }
+ function unstripNoWiki( $text, $state ) {
+ return $state->unstripNoWiki( $text );
+ }
- wfProfileIn( __METHOD__ );
- # TODO: good candidate for FSS
- $text = strtr( $text, $state['nowiki'] );
- wfProfileOut( __METHOD__ );
-
- return $text;
+ /**
+ * @deprecated use $this->mStripState->unstripBoth()
+ */
+ function unstripForHTML( $text ) {
+ return $this->mStripState->unstripBoth( $text );
}
/**
@@ -669,10 +670,7 @@ class Parser
*/
function insertStripItem( $text, &$state ) {
$rnd = $this->mUniqPrefix . '-item' . Parser::getRandomString();
- if ( !$state ) {
- $state = array();
- }
- $state['general'][$rnd] = $text;
+ $state->general->setPair( $rnd, $text );
return $rnd;
}
@@ -724,7 +722,7 @@ class Parser
$descriptorspec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
- 2 => array('file', '/dev/null', 'a')
+ 2 => array('file', '/dev/null', 'a') // FIXME: this line in UNIX-specific, it generates a warning on Windows, because /dev/null is not a valid Windows file.
);
$pipes = array();
$process = proc_open("$wgTidyBin -config $wgTidyConf $wgTidyOpts$opts", $descriptorspec, $pipes);
@@ -789,135 +787,191 @@ class Parser
*
* @private
*/
- function doTableStuff ( $t ) {
+ function doTableStuff ( $text ) {
$fname = 'Parser::doTableStuff';
wfProfileIn( $fname );
- $t = explode ( "\n" , $t ) ;
- $td = array () ; # Is currently a td tag open?
- $ltd = array () ; # Was it TD or TH?
- $tr = array () ; # Is currently a tr tag open?
- $ltr = array () ; # tr attributes
- $has_opened_tr = array(); # Did this table open a element?
- $indent_level = 0; # indent level of the table
- foreach ( $t AS $k => $x )
+ $lines = explode ( "\n" , $text );
+ $td_history = array (); // Is currently a td tag open?
+ $last_tag_history = array (); // Save history of last lag activated (td, th or caption)
+ $tr_history = array (); // Is currently a tr tag open?
+ $tr_attributes = array (); // history of tr attributes
+ $has_opened_tr = array(); // Did this table open a
element?
+ $indent_level = 0; // indent level of the table
+ foreach ( $lines as $key => $line )
{
- $x = trim ( $x ) ;
- $fc = substr ( $x , 0 , 1 ) ;
- if ( preg_match( '/^(:*)\{\|(.*)$/', $x, $matches ) ) {
+ $line = trim ( $line );
+
+ if( $line == '' ) { // empty line, go to next line
+ continue;
+ }
+ $first_character = $line{0};
+ $matches = array();
+
+ if ( preg_match( '/^(:*)\{\|(.*)$/' , $line , $matches ) ) {
+ // First check if we are starting a new table
$indent_level = strlen( $matches[1] );
- $attributes = $this->unstripForHTML( $matches[2] );
+ $attributes = $this->mStripState->unstripBoth( $matches[2] );
+ $attributes = Sanitizer::fixTagAttributes ( $attributes , 'table' );
+
+ $lines[$key] = str_repeat( '- ' , $indent_level ) . "
";
+ 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
+ continue;
+ } else if ( substr ( $line , 0 , 2 ) == '|}' ) {
+ // We are ending a table
+ $line = '
' . substr ( $line , 2 );
+ $last_tag = array_pop ( $last_tag_history );
- $t[$k] = str_repeat( '- ', $indent_level ) .
- '
' ;
- array_push ( $td , false ) ;
- array_push ( $ltd , '' ) ;
- array_push ( $tr , false ) ;
- array_push ( $ltr , '' ) ;
- array_push ( $has_opened_tr, false );
- }
- else if ( count ( $td ) == 0 ) { } # Don't do any of the following
- else if ( '|}' == substr ( $x , 0 , 2 ) ) {
- $z = "
" . substr ( $x , 2);
- $l = array_pop ( $ltd ) ;
- if ( !array_pop ( $has_opened_tr ) ) $z = " |
" . $z ;
- if ( array_pop ( $tr ) ) $z = '
' . $z ;
- if ( array_pop ( $td ) ) $z = ''.$l.'>' . $z ;
- array_pop ( $ltr ) ;
- $t[$k] = $z . str_repeat( '', $indent_level );
- }
- else if ( '|-' == substr ( $x , 0 , 2 ) ) { # Allows for |---------------
- $x = substr ( $x , 1 ) ;
- while ( $x != '' && substr ( $x , 0 , 1 ) == '-' ) $x = substr ( $x , 1 ) ;
- $z = '' ;
- $l = array_pop ( $ltd ) ;
+ if ( !array_pop ( $has_opened_tr ) ) {
+ $line = " |
{$line}";
+ }
+
+ if ( array_pop ( $tr_history ) ) {
+ $line = "{$line}";
+ }
+
+ if ( array_pop ( $td_history ) ) {
+ $line = "{$last_tag}>{$line}";
+ }
+ array_pop ( $tr_attributes );
+ $lines[$key] = $line . str_repeat( '' , $indent_level );
+ } else if ( substr ( $line , 0 , 2 ) == '|-' ) {
+ // Now we have a table row
+ $line = preg_replace( '#^\|-+#', '', $line );
+
+ // 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 );
+
+ $line = '';
+ $last_tag = array_pop ( $last_tag_history );
array_pop ( $has_opened_tr );
- array_push ( $has_opened_tr , true ) ;
- if ( array_pop ( $tr ) ) $z = '' . $z ;
- if ( array_pop ( $td ) ) $z = ''.$l.'>' . $z ;
- array_pop ( $ltr ) ;
- $t[$k] = $z ;
- array_push ( $tr , false ) ;
- array_push ( $td , false ) ;
- array_push ( $ltd , '' ) ;
- $attributes = $this->unstripForHTML( $x );
- array_push ( $ltr , Sanitizer::fixTagAttributes ( $attributes, 'tr' ) ) ;
+ array_push ( $has_opened_tr , true );
+
+ if ( array_pop ( $tr_history ) ) {
+ $line = '';
+ }
+
+ if ( array_pop ( $td_history ) ) {
+ $line = "{$last_tag}>{$line}";
+ }
+
+ $lines[$key] = $line;
+ array_push ( $tr_history , false );
+ array_push ( $td_history , false );
+ array_push ( $last_tag_history , '' );
}
- else if ( '|' == $fc || '!' == $fc || '|+' == substr ( $x , 0 , 2 ) ) { # Caption
- # $x is a table row
- if ( '|+' == substr ( $x , 0 , 2 ) ) {
- $fc = '+' ;
- $x = substr ( $x , 1 ) ;
+ else if ( $first_character == '|' || $first_character == '!' || substr ( $line , 0 , 2 ) == '|+' ) {
+ // This might be cell elements, td, th or captions
+ if ( substr ( $line , 0 , 2 ) == '|+' ) {
+ $first_character = '+';
+ $line = substr ( $line , 1 );
+ }
+
+ $line = substr ( $line , 1 );
+
+ if ( $first_character == '!' ) {
+ $line = str_replace ( '!!' , '||' , $line );
}
- $after = substr ( $x , 1 ) ;
- if ( $fc == '!' ) $after = str_replace ( '!!' , '||' , $after ) ;
// Split up multiple cells on the same line.
- // FIXME: This can result in improper nesting of tags processed
+ // FIXME : This can result in improper nesting of tags processed
// by earlier parser steps, but should avoid splitting up eg
// attribute values containing literal "||".
- $after = wfExplodeMarkup( '||', $after );
+ $cells = StringUtils::explodeMarkup( '||' , $line );
- $t[$k] = '' ;
+ $lines[$key] = '';
- # Loop through each table cell
- foreach ( $after AS $theline )
+ // Loop through each table cell
+ foreach ( $cells as $cell )
{
- $z = '' ;
- if ( $fc != '+' )
+ $previous = '';
+ if ( $first_character != '+' )
{
- $tra = array_pop ( $ltr ) ;
- if ( !array_pop ( $tr ) ) $z = '\n" ;
- array_push ( $tr , true ) ;
- array_push ( $ltr , '' ) ;
+ $tr_after = array_pop ( $tr_attributes );
+ if ( !array_pop ( $tr_history ) ) {
+ $previous = "
\n";
+ }
+ array_push ( $tr_history , true );
+ array_push ( $tr_attributes , '' );
array_pop ( $has_opened_tr );
- array_push ( $has_opened_tr , true ) ;
+ array_push ( $has_opened_tr , true );
}
- $l = array_pop ( $ltd ) ;
- if ( array_pop ( $td ) ) $z = ''.$l.'>' . $z ;
- if ( $fc == '|' ) $l = 'td' ;
- else if ( $fc == '!' ) $l = 'th' ;
- else if ( $fc == '+' ) $l = 'caption' ;
- else $l = '' ;
- array_push ( $ltd , $l ) ;
-
- # Cell parameters
- $y = explode ( '|' , $theline , 2 ) ;
- # Note that a '|' inside an invalid link should not
- # be mistaken as delimiting cell parameters
- if ( strpos( $y[0], '[[' ) !== false ) {
- $y = array ($theline);
+ $last_tag = array_pop ( $last_tag_history );
+
+ if ( array_pop ( $td_history ) ) {
+ $previous = "{$last_tag}>{$previous}";
+ }
+
+ if ( $first_character == '|' ) {
+ $last_tag = 'td';
+ } else if ( $first_character == '!' ) {
+ $last_tag = 'th';
+ } else if ( $first_character == '+' ) {
+ $last_tag = 'caption';
+ } else {
+ $last_tag = '';
}
- if ( count ( $y ) == 1 )
- $y = "{$z}<{$l}>{$y[0]}" ;
+
+ array_push ( $last_tag_history , $last_tag );
+
+ // A cell could contain both parameters and data
+ $cell_data = explode ( '|' , $cell , 2 );
+
+ // Bug 553: Note that a '|' inside an invalid link should not
+ // be mistaken as delimiting cell parameters
+ if ( strpos( $cell_data[0], '[[' ) !== false ) {
+ $cell = "{$previous}<{$last_tag}>{$cell}";
+ } else if ( count ( $cell_data ) == 1 )
+ $cell = "{$previous}<{$last_tag}>{$cell_data[0]}";
else {
- $attributes = $this->unstripForHTML( $y[0] );
- $y = "{$z}<{$l}".Sanitizer::fixTagAttributes($attributes, $l).">{$y[1]}" ;
+ $attributes = $this->mStripState->unstripBoth( $cell_data[0] );
+ $attributes = Sanitizer::fixTagAttributes( $attributes , $last_tag );
+ $cell = "{$previous}<{$last_tag}{$attributes}>{$cell_data[1]}";
}
- $t[$k] .= $y ;
- array_push ( $td , true ) ;
+
+ $lines[$key] .= $cell;
+ array_push ( $td_history , true );
}
}
}
- # Closing open td, tr && table
- while ( count ( $td ) > 0 )
+ // Closing open td, tr && table
+ while ( count ( $td_history ) > 0 )
{
- $l = array_pop ( $ltd ) ;
- if ( array_pop ( $td ) ) $t[] = '' ;
- if ( array_pop ( $tr ) ) $t[] = '
' ;
- if ( !array_pop ( $has_opened_tr ) ) $t[] = " |
" ;
- $t[] = '' ;
+ if ( array_pop ( $td_history ) ) {
+ $lines[] = '' ;
+ }
+ if ( array_pop ( $tr_history ) ) {
+ $lines[] = '' ;
+ }
+ if ( !array_pop ( $has_opened_tr ) ) {
+ $lines[] = " |
" ;
+ }
+
+ $lines[] = '' ;
+ }
+
+ $output = implode ( "\n" , $lines ) ;
+
+ // special case: don't return empty table
+ if( $output == "" ) {
+ $output = '';
}
- $t = implode ( "\n" , $t ) ;
- # special case: don't return empty table
- if($t == "")
- $t = '';
wfProfileOut( $fname );
- return $t ;
+
+ return $output;
}
/**
@@ -933,7 +987,7 @@ class Parser
wfProfileIn( $fname );
# Hook to suspend the parser in this state
- if ( !wfRunHooks( 'ParserBeforeInternalParse', array( &$this, &$text, &$x ) ) ) {
+ if ( !wfRunHooks( 'ParserBeforeInternalParse', array( &$this, &$text, &$this->mStripState ) ) ) {
wfProfileOut( $fname );
return $text ;
}
@@ -941,7 +995,7 @@ class Parser
# Remove tags and sections
$text = strtr( $text, array( '' => '' , '' => '' ) );
$text = strtr( $text, array( '' => '', '' => '') );
- $text = preg_replace( '/.*?<\/includeonly>/s', '', $text );
+ $text = StringUtils::delimiterReplace( '', '', '', $text );
$text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ) );
@@ -985,15 +1039,19 @@ class Parser
*/
function &doMagicLinks( &$text ) {
wfProfileIn( __METHOD__ );
- $text = preg_replace_callback(
+ $text = preg_replace_callback(
'!(?: # Start cases
| # Skip link text
<.*?> | # Skip stuff inside HTML elements
(?:RFC|PMID)\s+([0-9]+) | # RFC or PMID, capture number as m[1]
- ISBN\s+([0-9Xx-]+) # ISBN, capture number as m[2]
+ ISBN\s+(\b # ISBN, capture number as m[2]
+ (?: 97[89] [\ \-]? )? # optional 13-digit ISBN prefix
+ (?: [0-9] [\ \-]? ){9} # 9 digits with opt. delimiters
+ [0-9Xx] # check digit
+ \b)
)!x', array( &$this, 'magicLinkCallback' ), $text );
wfProfileOut( __METHOD__ );
- return $text;
+ return $text;
}
function magicLinkCallback( $m ) {
@@ -1002,12 +1060,12 @@ class Parser
return $m[0];
} elseif ( substr( $m[0], 0, 4 ) == 'ISBN' ) {
$isbn = $m[2];
- $num = strtr( $isbn, array(
+ $num = strtr( $isbn, array(
'-' => '',
' ' => '',
'x' => 'X',
));
- $titleObj = Title::makeTitle( NS_SPECIAL, 'Booksources' );
+ $titleObj = SpecialPage::getTitleFor( 'Booksources' );
$text = 'ISBN $isbn";
@@ -1021,12 +1079,12 @@ class Parser
$urlmsg = 'pubmedurl';
$id = $m[1];
} else {
- throw new MWException( __METHOD__.': unrecognised match type "' .
+ throw new MWException( __METHOD__.': unrecognised match type "' .
substr($m[0], 0, 20 ) . '"' );
}
-
+
$url = wfMsg( $urlmsg, $id);
- $sk =& $this->mOptions->getSkin();
+ $sk = $this->mOptions->getSkin();
$la = $sk->getExternalLinkAttributes( $url, $keyword.$id );
$text = "{$keyword} {$id}";
}
@@ -1104,9 +1162,9 @@ class Parser
}
# Count the number of occurrences of bold and italics mark-ups.
# We are not counting sequences of five apostrophes.
- if ( strlen( $arr[$i] ) == 2 ) $numitalics++; else
- if ( strlen( $arr[$i] ) == 3 ) $numbold++; else
- if ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; }
+ if ( strlen( $arr[$i] ) == 2 ) { $numitalics++; }
+ else if ( strlen( $arr[$i] ) == 3 ) { $numbold++; }
+ else if ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; }
}
$i++;
}
@@ -1246,7 +1304,7 @@ class Parser
$fname = 'Parser::replaceExternalLinks';
wfProfileIn( $fname );
- $sk =& $this->mOptions->getSkin();
+ $sk = $this->mOptions->getSkin();
$bits = preg_split( EXT_LINK_BRACKETED, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
@@ -1262,6 +1320,7 @@ class Parser
# The characters '<' and '>' (which were escaped by
# removeHTMLtags()) should not be included in
# URLs, per RFC 2396.
+ $m2 = array();
if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
$text = substr($url, $m2[0][1]) . ' ' . $text;
$url = substr($url, 0, $m2[0][1]);
@@ -1297,7 +1356,7 @@ class Parser
}
$text = $wgContLang->markNoConversion($text);
-
+
$url = Sanitizer::cleanUrl( $url );
# Process the trail (i.e. everything after this link up until start of the next link),
@@ -1334,12 +1393,13 @@ class Parser
$s = array_shift( $bits );
$i = 0;
- $sk =& $this->mOptions->getSkin();
+ $sk = $this->mOptions->getSkin();
while ( $i < count( $bits ) ){
$protocol = $bits[$i++];
$remainder = $bits[$i++];
+ $m = array();
if ( preg_match( '/^('.EXT_LINK_URL_CLASS.'+)(.*)$/s', $remainder, $m ) ) {
# Found some characters after the protocol that look promising
$url = $protocol . $m[1];
@@ -1347,10 +1407,10 @@ class Parser
# special case: handle urls as url args:
# http://www.example.com/foo?=http://www.example.com/bar
- if(strlen($trail) == 0 &&
+ if(strlen($trail) == 0 &&
isset($bits[$i]) &&
preg_match('/^'. wfUrlProtocols() . '$/S', $bits[$i]) &&
- preg_match( '/^('.EXT_LINK_URL_CLASS.'+)(.*)$/s', $bits[$i + 1], $m ))
+ preg_match( '/^('.EXT_LINK_URL_CLASS.'+)(.*)$/s', $bits[$i + 1], $m ))
{
# add protocol, arg
$url .= $bits[$i] . $m[1]; # protocol, url as arg to previous link
@@ -1361,6 +1421,7 @@ class Parser
# The characters '<' and '>' (which were escaped by
# removeHTMLtags()) should not be included in
# URLs, per RFC 2396.
+ $m2 = array();
if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
$trail = substr($url, $m2[0][1]) . $trail;
$url = substr($url, 0, $m2[0][1]);
@@ -1440,7 +1501,7 @@ class Parser
* @private
*/
function maybeMakeExternalImage( $url ) {
- $sk =& $this->mOptions->getSkin();
+ $sk = $this->mOptions->getSkin();
$imagesfrom = $this->mOptions->getAllowExternalImagesFrom();
$imagesexception = !empty($imagesfrom);
$text = false;
@@ -1470,7 +1531,7 @@ class Parser
# the % is needed to support urlencoded titles as well
if ( !$tc ) { $tc = Title::legalChars() . '#%'; }
- $sk =& $this->mOptions->getSkin();
+ $sk = $this->mOptions->getSkin();
#split the entire text string on occurences of [[
$a = explode( '[[', ' ' . $s );
@@ -1489,13 +1550,13 @@ class Parser
$e2 = wfMsgForContent( 'linkprefix' );
$useLinkPrefixExtension = $wgContLang->linkPrefixExtension();
-
if( is_null( $this->mTitle ) ) {
throw new MWException( __METHOD__.": \$this->mTitle is null\n" );
}
$nottalk = !$this->mTitle->isTalkPage();
if ( $useLinkPrefixExtension ) {
+ $m = array();
if ( preg_match( $e2, $s, $m ) ) {
$first_prefix = $m[2];
} else {
@@ -1505,8 +1566,11 @@ class Parser
$prefix = '';
}
- $selflink = $this->mTitle->getPrefixedText();
- $checkVariantLink = sizeof($wgContLang->getVariants())>1;
+ if($wgContLang->hasVariants()) {
+ $selflink = $wgContLang->convertLinkToAllVariants($this->mTitle->getPrefixedText());
+ } else {
+ $selflink = array($this->mTitle->getPrefixedText());
+ }
$useSubpages = $this->areSubpagesAllowed();
wfProfileOut( $fname.'-setup' );
@@ -1542,10 +1606,10 @@ class Parser
# Still some problems for cases where the ] is meant to be outside punctuation,
# and no image is in sight. See bug 2095.
#
- if( $text !== '' &&
- substr( $m[3], 0, 1 ) === ']' &&
- strpos($text, '[') !== false
- )
+ if( $text !== '' &&
+ substr( $m[3], 0, 1 ) === ']' &&
+ strpos($text, '[') !== false
+ )
{
$text .= ']'; # so that replaceExternalLinks($text) works later
$m[3] = substr( $m[3], 1 );
@@ -1594,24 +1658,17 @@ class Parser
wfProfileOut( "$fname-misc" );
wfProfileIn( "$fname-title" );
- $nt = Title::newFromText( $this->unstripNoWiki($link, $this->mStripState) );
+ $nt = Title::newFromText( $this->mStripState->unstripNoWiki($link) );
if( !$nt ) {
$s .= $prefix . '[[' . $line;
wfProfileOut( "$fname-title" );
continue;
}
- #check other language variants of the link
- #if the article does not exist
- if( $checkVariantLink
- && $nt->getArticleID() == 0 ) {
- $wgContLang->findVariantLink($link, $nt);
- }
-
$ns = $nt->getNamespace();
$iw = $nt->getInterWiki();
wfProfileOut( "$fname-title" );
-
+
if ($might_be_img) { # if this is actually an invalid link
wfProfileIn( "$fname-might_be_img" );
if ($ns == NS_IMAGE && $noforce) { #but might be an image
@@ -1664,8 +1721,8 @@ class Parser
wfProfileIn( "$fname-interwiki" );
if( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
$this->mOutput->addLanguageLink( $nt->getFullText() );
- $s = rtrim($s . "\n");
- $s .= trim($prefix . $trail, "\n") == '' ? '': $prefix . $trail;
+ $s = rtrim($s . $prefix);
+ $s .= trim($trail, "\n") == '' ? '': $prefix . $trail;
wfProfileOut( "$fname-interwiki" );
continue;
}
@@ -1673,7 +1730,7 @@ class Parser
if ( $ns == NS_IMAGE ) {
wfProfileIn( "$fname-image" );
- if ( !wfIsBadImage( $nt->getDBkey() ) ) {
+ 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
@@ -1699,11 +1756,7 @@ class Parser
$s = rtrim($s . "\n"); # bug 87
if ( $wasblank ) {
- if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
- $sortkey = $this->mTitle->getText();
- } else {
- $sortkey = $this->mTitle->getPrefixedText();
- }
+ $sortkey = $this->getDefaultSort();
} else {
$sortkey = $text;
}
@@ -1723,11 +1776,12 @@ class Parser
}
}
- if( ( $nt->getPrefixedText() === $selflink ) &&
- ( $nt->getFragment() === '' ) ) {
- # Self-links are handled specially; generally de-link and change to bold.
- $s .= $prefix . $sk->makeSelfLinkObj( $nt, $text, '', $trail );
- continue;
+ # Self-link checking
+ if( $nt->getFragment() === '' ) {
+ if( in_array( $nt->getPrefixedText(), $selflink, true ) ) {
+ $s .= $prefix . $sk->makeSelfLinkObj( $nt, $text, '', $trail );
+ continue;
+ }
}
# Special and Media are pseudo-namespaces; no pages actually exist in them
@@ -1807,7 +1861,7 @@ class Parser
*/
function makeKnownLinkHolder( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
list( $inside, $trail ) = Linker::splitTrail( $trail );
- $sk =& $this->mOptions->getSkin();
+ $sk = $this->mOptions->getSkin();
$link = $sk->makeKnownLinkObj( $nt, $text, $query, $inside, $prefix );
return $this->armorLinks( $link ) . $trail;
}
@@ -1825,7 +1879,7 @@ class Parser
* @return string less-or-more HTML with NOPARSE bits
*/
function armorLinks( $text ) {
- return preg_replace( "/\b(" . wfUrlProtocols() . ')/',
+ return preg_replace( '/\b(' . wfUrlProtocols() . ')/',
"{$this->mUniqPrefix}NOPARSE$1", $text );
}
@@ -1859,15 +1913,18 @@ class Parser
wfProfileIn( $fname );
$ret = $target; # default return value is no change
+ # bug 7425
+ $target = trim( $target );
+
# Some namespaces don't allow subpages,
# so only perform processing if subpages are allowed
if( $this->areSubpagesAllowed() ) {
# Look at the first character
if( $target != '' && $target{0} == '/' ) {
# / at end means we don't want the slash to be shown
- if( substr( $target, -1, 1 ) == '/' ) {
- $target = substr( $target, 1, -1 );
- $noslash = $target;
+ $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
+ if( $trailingSlashes ) {
+ $noslash = $target = substr( $target, 1, -strlen($m[0][0]) );
} else {
$noslash = substr( $target, 1 );
}
@@ -2076,10 +2133,10 @@ class Parser
wfProfileIn( "$fname-paragraph" );
# No prefix (not in list)--go to paragraph mode
// XXX: use a stack for nestable elements like span, table and div
- $openmatch = preg_match('/(mUniqPrefix.'-pre|<\\/li|<\\/ul|<\\/ol|mUniqPrefix.'-pre|<\\/li|<\\/ul|<\\/ol|<\\/?center)/iS', $t );
if ( $openmatch or $closematch ) {
$paragraphStack = false;
#Â TODO bug 5718: paragraph closed
@@ -2329,9 +2386,11 @@ class Parser
* expensive to check many times.
*/
static $varCache = array();
- if ( wfRunHooks( 'ParserGetVariableValueVarCache', array( &$this, &$varCache ) ) )
- if ( isset( $varCache[$index] ) )
+ if ( wfRunHooks( 'ParserGetVariableValueVarCache', array( &$this, &$varCache ) ) ) {
+ if ( isset( $varCache[$index] ) ) {
return $varCache[$index];
+ }
+ }
$ts = time();
wfRunHooks( 'ParserGetVariableValueTs', array( &$this, &$ts ) );
@@ -2418,6 +2477,16 @@ class Parser
return $subjPage->getPrefixedUrl();
case 'revisionid':
return $this->mRevisionId;
+ case 'revisionday':
+ return intval( substr( $this->getRevisionTimestamp(), 6, 2 ) );
+ case 'revisionday2':
+ return substr( $this->getRevisionTimestamp(), 6, 2 );
+ case 'revisionmonth':
+ return intval( substr( $this->getRevisionTimestamp(), 4, 2 ) );
+ case 'revisionyear':
+ return substr( $this->getRevisionTimestamp(), 0, 4 );
+ case 'revisiontimestamp':
+ return $this->getRevisionTimestamp();
case 'namespace':
return str_replace('_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) );
case 'namespacee':
@@ -2459,22 +2528,21 @@ class Parser
case 'localdow':
return $varCache[$index] = $wgContLang->formatNum( $localDayOfWeek );
case 'numberofarticles':
- return $varCache[$index] = $wgContLang->formatNum( wfNumberOfArticles() );
+ return $varCache[$index] = $wgContLang->formatNum( SiteStats::articles() );
case 'numberoffiles':
- return $varCache[$index] = $wgContLang->formatNum( wfNumberOfFiles() );
+ return $varCache[$index] = $wgContLang->formatNum( SiteStats::images() );
case 'numberofusers':
- return $varCache[$index] = $wgContLang->formatNum( wfNumberOfUsers() );
+ return $varCache[$index] = $wgContLang->formatNum( SiteStats::users() );
case 'numberofpages':
- return $varCache[$index] = $wgContLang->formatNum( wfNumberOfPages() );
+ return $varCache[$index] = $wgContLang->formatNum( SiteStats::pages() );
case 'numberofadmins':
- return $varCache[$index] = $wgContLang->formatNum( wfNumberOfAdmins() );
+ return $varCache[$index] = $wgContLang->formatNum( SiteStats::admins() );
case 'currenttimestamp':
return $varCache[$index] = wfTimestampNow();
case 'localtimestamp':
return $varCache[$index] = $localTimestamp;
case 'currentversion':
- global $wgVersion;
- return $wgVersion;
+ return $varCache[$index] = SpecialVersion::getVersion();
case 'sitename':
return $wgSitename;
case 'server':
@@ -2537,7 +2605,7 @@ class Parser
$lastOpeningBrace = -1; # last not closed parentheses
$validOpeningBraces = implode( '', array_keys( $callbacks ) );
-
+
$i = 0;
while ( $i < strlen( $text ) ) {
# Find next opening brace, closing brace or pipe
@@ -2555,9 +2623,14 @@ class Parser
$found = 'pipe';
} elseif ( $text[$i] == $currentClosing ) {
$found = 'close';
- } else {
+ } elseif ( isset( $callbacks[$text[$i]] ) ) {
$found = 'open';
$rule = $callbacks[$text[$i]];
+ } else {
+ # Some versions of PHP have a strcspn which stops on null characters
+ # Ignore and continue
+ ++$i;
+ continue;
}
} else {
# All done
@@ -2586,13 +2659,13 @@ class Parser
$maxCount = $openingBraceStack[$lastOpeningBrace]['count'];
$count = strspn( $text, $text[$i], $i, $maxCount );
- # check for maximum matching characters (if there are 5 closing
+ # check for maximum matching characters (if there are 5 closing
# characters, we will probably need only 3 - depending on the rules)
$matchingCount = 0;
$matchingCallback = null;
$cbType = $callbacks[$openingBraceStack[$lastOpeningBrace]['brace']];
if ( $count > $cbType['max'] ) {
- # The specified maximum exists in the callback array, unless the caller
+ # The specified maximum exists in the callback array, unless the caller
# has made an error
$matchingCount = $cbType['max'];
} else {
@@ -2613,12 +2686,12 @@ class Parser
# let's set a title or last part (if '|' was found)
if (null === $openingBraceStack[$lastOpeningBrace]['parts']) {
- $openingBraceStack[$lastOpeningBrace]['title'] =
- substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
+ $openingBraceStack[$lastOpeningBrace]['title'] =
+ substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
$i - $openingBraceStack[$lastOpeningBrace]['partStart']);
} else {
- $openingBraceStack[$lastOpeningBrace]['parts'][] =
- substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
+ $openingBraceStack[$lastOpeningBrace]['parts'][] =
+ substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
$i - $openingBraceStack[$lastOpeningBrace]['partStart']);
}
@@ -2668,13 +2741,13 @@ class Parser
} elseif ( $found == 'pipe' ) {
# lets set a title if it is a first separator, or next part otherwise
if (null === $openingBraceStack[$lastOpeningBrace]['parts']) {
- $openingBraceStack[$lastOpeningBrace]['title'] =
- substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
+ $openingBraceStack[$lastOpeningBrace]['title'] =
+ substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
$i - $openingBraceStack[$lastOpeningBrace]['partStart']);
$openingBraceStack[$lastOpeningBrace]['parts'] = array();
} else {
- $openingBraceStack[$lastOpeningBrace]['parts'][] =
- substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
+ $openingBraceStack[$lastOpeningBrace]['parts'][] =
+ substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
$i - $openingBraceStack[$lastOpeningBrace]['partStart']);
}
$openingBraceStack[$lastOpeningBrace]['partStart'] = ++$i;
@@ -2716,19 +2789,19 @@ class Parser
if ( !$argsOnly ) {
$braceCallbacks[2] = array( &$this, 'braceSubstitution' );
}
- if ( !$this->mOutputType != OT_MSG ) {
+ if ( $this->mOutputType != OT_MSG ) {
$braceCallbacks[3] = array( &$this, 'argSubstitution' );
}
if ( $braceCallbacks ) {
- $callbacks = array(
+ $callbacks = array(
'{' => array(
'end' => '}',
'cb' => $braceCallbacks,
'min' => $argsOnly ? 3 : 2,
'max' => isset( $braceCallbacks[3] ) ? 3 : 2,
),
- '[' => array(
- 'end' => ']',
+ '[' => array(
+ 'end' => ']',
'cb' => array(2=>null),
'min' => 2,
'max' => 2,
@@ -2747,8 +2820,9 @@ class Parser
* @private
*/
function variableSubstitution( $matches ) {
+ global $wgContLang;
$fname = 'Parser::variableSubstitution';
- $varname = $matches[1];
+ $varname = $wgContLang->lc($matches[1]);
wfProfileIn( $fname );
$skip = false;
if ( $this->mOutputType == OT_WIKI ) {
@@ -2762,8 +2836,14 @@ class Parser
}
if ( !$skip && array_key_exists( $varname, $this->mVariables ) ) {
$id = $this->mVariables[$varname];
- $text = $this->getVariableValue( $id );
- $this->mOutput->mContainsOldMagic = true;
+ # Now check if we did really match, case sensitive or not
+ $mw =& MagicWord::get( $id );
+ if ($mw->match($matches[1])) {
+ $text = $this->getVariableValue( $id );
+ $this->mOutput->mContainsOldMagic = true;
+ } else {
+ $text = $matches[0];
+ }
} else {
$text = $matches[0];
}
@@ -2771,29 +2851,28 @@ class Parser
return $text;
}
- # Split template arguments
- function getTemplateArgs( $argsString ) {
- if ( $argsString === '' ) {
- return array();
- }
-
- $args = explode( '|', substr( $argsString, 1 ) );
-
- # If any of the arguments contains a '[[' but no ']]', it needs to be
- # merged with the next arg because the '|' character between belongs
- # to the link syntax and not the template parameter syntax.
- $argc = count($args);
- for ( $i = 0; $i < $argc-1; $i++ ) {
- if ( substr_count ( $args[$i], '[[' ) != substr_count ( $args[$i], ']]' ) ) {
- $args[$i] .= '|'.$args[$i+1];
- array_splice($args, $i+1, 1);
- $i--;
- $argc--;
+ /// Clean up argument array - refactored in 1.9 so parserfunctions can use it, too.
+ static function createAssocArgs( $args ) {
+ $assocArgs = array();
+ $index = 1;
+ foreach( $args as $arg ) {
+ $eqpos = strpos( $arg, '=' );
+ if ( $eqpos === false ) {
+ $assocArgs[$index++] = $arg;
+ } else {
+ $name = trim( substr( $arg, 0, $eqpos ) );
+ $value = trim( substr( $arg, $eqpos+1 ) );
+ if ( $value === false ) {
+ $value = '';
+ }
+ if ( $name !== false ) {
+ $assocArgs[$name] = $value;
+ }
}
}
- return $args;
+ return $assocArgs;
}
/**
@@ -2808,7 +2887,7 @@ class Parser
* @private
*/
function braceSubstitution( $piece ) {
- global $wgContLang, $wgLang, $wgAllowDisplayTitle, $action;
+ global $wgContLang, $wgLang, $wgAllowDisplayTitle, $wgNonincludableNamespaces;
$fname = __METHOD__ /*. '-L' . count( $this->mArgStack )*/;
wfProfileIn( $fname );
wfProfileIn( __METHOD__.'-setup' );
@@ -2819,6 +2898,7 @@ class Parser
$noparse = false; # Unsafe HTML tags should not be stripped, etc.
$noargs = false; # Don't replace triple-brace arguments in $text
$replaceHeadings = false; # Make the edit section links go to the template not the article
+ $headingOffset = 0; # Skip headings when number, to account for those that weren't transcluded.
$isHTML = false; # $text is HTML, armour it against wikitext transformation
$forceRawInterwiki = false; # Force interwiki transclusion to be done in raw mode not rendered
@@ -2827,7 +2907,7 @@ class Parser
$linestart = '';
-
+
# $part1 is the bit before the first |, and must contain only title characters
# $args is a list of arguments, starting from index 0, not including $part1
@@ -2845,7 +2925,6 @@ class Parser
}
$args = (null == $piece['parts']) ? array() : $piece['parts'];
- $argc = count( $args );
wfProfileOut( __METHOD__.'-setup' );
# SUBST
@@ -2864,7 +2943,7 @@ class Parser
}
}
- # MSG, MSGNW, INT and RAW
+ # MSG, MSGNW and RAW
if ( !$found ) {
# Check for MSGNW:
$mwMsgnw =& MagicWord::get( 'msgnw' );
@@ -2875,26 +2954,22 @@ class Parser
$mwMsg =& MagicWord::get( 'msg' );
$mwMsg->matchStartAndRemove( $part1 );
}
-
+
# Check for RAW:
$mwRaw =& MagicWord::get( 'raw' );
if ( $mwRaw->matchStartAndRemove( $part1 ) ) {
$forceRawInterwiki = true;
}
-
- # Check if it is an internal message
- $mwInt =& MagicWord::get( 'int' );
- if ( $mwInt->matchStartAndRemove( $part1 ) ) {
- $text = $linestart . wfMsgReal( $part1, $args, true );
- $found = true;
- }
}
wfProfileOut( __METHOD__.'-modifiers' );
+ //save path level before recursing into functions & templates.
+ $lastPathLevel = $this->mTemplatePath;
+
# Parser functions
if ( !$found ) {
wfProfileIn( __METHOD__ . '-pfunc' );
-
+
$colonPos = strpos( $part1, ':' );
if ( $colonPos !== false ) {
# Case sensitive functions
@@ -2959,7 +3034,6 @@ class Parser
}
# Load from database
- $lastPathLevel = $this->mTemplatePath;
if ( !$found ) {
wfProfileIn( __METHOD__ . '-loadtpl' );
$ns = NS_TEMPLATE;
@@ -2976,9 +3050,8 @@ class Parser
if ( !is_null( $title ) ) {
$titleText = $title->getPrefixedText();
- $checkVariantLink = sizeof($wgContLang->getVariants())>1;
# Check for language variants if the template is not found
- if($checkVariantLink && $title->getArticleID() == 0){
+ if($wgContLang->hasVariants() && $title->getArticleID() == 0){
$wgContLang->findVariantLink($part1, $title);
}
@@ -2992,6 +3065,9 @@ class Parser
$isHTML = true;
$this->disableCache();
}
+ } else if ( $wgNonincludableNamespaces && in_array( $title->getNamespace(), $wgNonincludableNamespaces ) ) {
+ $found = false; //access denied
+ wfDebug( "$fname: template inclusion denied for " . $title->getPrefixedDBkey() );
} else {
$articleContent = $this->fetchTemplate( $title );
if ( $articleContent !== false ) {
@@ -3003,7 +3079,7 @@ class Parser
# If the title is valid but undisplayable, make a link to it
if ( !$found && ( $this->ot['html'] || $this->ot['pre'] ) ) {
- $text = "[[$titleText]]";
+ $text = "[[:$titleText]]";
$found = true;
}
} elseif ( $title->isTrans() ) {
@@ -3051,24 +3127,7 @@ class Parser
$assocArgs = array();
} else {
# Clean up argument array
- $assocArgs = array();
- $index = 1;
- foreach( $args as $arg ) {
- $eqpos = strpos( $arg, '=' );
- if ( $eqpos === false ) {
- $assocArgs[$index++] = $arg;
- } else {
- $name = trim( substr( $arg, 0, $eqpos ) );
- $value = trim( substr( $arg, $eqpos+1 ) );
- if ( $value === false ) {
- $value = '';
- }
- if ( $name !== false ) {
- $assocArgs[$name] = $value;
- }
- }
- }
-
+ $assocArgs = self::createAssocArgs($args);
# Add a new element to the templace recursion path
$this->mTemplatePath[$part1] = 1;
}
@@ -3076,13 +3135,13 @@ class Parser
if ( !$noparse ) {
# If there are any tags, only include them
if ( in_string( '', $text ) && in_string( '', $text ) ) {
- preg_match_all( '/(.*?)\n?<\/onlyinclude>/s', $text, $m );
- $text = '';
- foreach ($m[1] as $piece)
- $text .= $piece;
+ $replacer = new OnlyIncludeReplacer;
+ StringUtils::delimiterReplaceCallback( '', '',
+ array( &$replacer, 'replace' ), $text );
+ $text = $replacer->output;
}
# Remove sections and tags
- $text = preg_replace( '/.*?<\/noinclude>/s', '', $text );
+ $text = StringUtils::delimiterReplace( '', '', '', $text );
$text = strtr( $text, array( '' => '' , '' => '' ) );
if( $this->ot['html'] || $this->ot['pre'] ) {
@@ -3098,7 +3157,7 @@ class Parser
# If the template begins with a table or block-level
# element, it should be treated as beginning a new line.
- if (!$piece['lineStart'] && preg_match('/^({\\||:|;|#|\*)/', $text)) /*}*/{
+ if (!$piece['lineStart'] && preg_match('/^({\\||:|;|#|\*)/', $text)) /*}*/{
$text = "\n" . $text;
}
} elseif ( !$noargs ) {
@@ -3140,7 +3199,7 @@ class Parser
$m = preg_split('/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1,
PREG_SPLIT_DELIM_CAPTURE);
$text = '';
- $nsec = 0;
+ $nsec = $headingOffset;
for( $i = 0; $i < count($m); $i += 2 ) {
$text .= $m[$i];
if (!isset($m[$i + 1]) || $m[$i + 1] == "") continue;
@@ -3149,6 +3208,7 @@ class Parser
$text .= $hl;
continue;
}
+ $m2 = array();
preg_match('/^(={1,6})(.*?)(={1,6})\s*?$/m', $hl, $m2);
$text .= $m2[1] . $m2[2] . "" . $m2[3];
@@ -3181,10 +3241,19 @@ class Parser
for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
$rev = Revision::newFromTitle( $title );
$this->mOutput->addTemplate( $title, $title->getArticleID() );
- if ( !$rev ) {
+ if ( $rev ) {
+ $text = $rev->getText();
+ } elseif( $title->getNamespace() == NS_MEDIAWIKI ) {
+ global $wgLang;
+ $message = $wgLang->lcfirst( $title->getText() );
+ $text = wfMsgForContentNoTrans( $message );
+ if( wfEmptyMsg( $message, $text ) ) {
+ $text = false;
+ break;
+ }
+ } else {
break;
}
- $text = $rev->getText();
if ( $text === false ) {
break;
}
@@ -3198,22 +3267,13 @@ class Parser
* Transclude an interwiki link.
*/
function interwikiTransclude( $title, $action ) {
- global $wgEnableScaryTranscluding, $wgCanonicalNamespaceNames;
+ global $wgEnableScaryTranscluding;
if (!$wgEnableScaryTranscluding)
return wfMsg('scarytranscludedisabled');
- // The namespace will actually only be 0 or 10, depending on whether there was a leading :
- // But we'll handle it generally anyway
- if ( $title->getNamespace() ) {
- // Use the canonical namespace, which should work anywhere
- $articleName = $wgCanonicalNamespaceNames[$title->getNamespace()] . ':' . $title->getDBkey();
- } else {
- $articleName = $title->getDBkey();
- }
+ $url = $title->getFullUrl( "action=$action" );
- $url = str_replace('$1', urlencode($articleName), Title::getInterwikiLink($title->getInterwiki()));
- $url .= "?action=$action";
if (strlen($url) > 255)
return wfMsg('scarytranscludetoolong');
return $this->fetchScaryTemplateMaybeFromCache($url);
@@ -3221,7 +3281,7 @@ class Parser
function fetchScaryTemplateMaybeFromCache($url) {
global $wgTranscludeCacheExpiry;
- $dbr =& wfGetDB(DB_SLAVE);
+ $dbr = wfGetDB(DB_SLAVE);
$obj = $dbr->selectRow('transcache', array('tc_time', 'tc_contents'),
array('tc_url' => $url));
if ($obj) {
@@ -3236,7 +3296,7 @@ class Parser
if (!$text)
return wfMsg('scarytranscludefailed', $url);
- $dbw =& wfGetDB(DB_MASTER);
+ $dbw = wfGetDB(DB_MASTER);
$dbw->replace('transcache', array('tc_url'), array(
'tc_url' => $url,
'tc_time' => time(),
@@ -3256,7 +3316,7 @@ class Parser
if ( array_key_exists( $arg, $inputArgs ) ) {
$text = $inputArgs[$arg];
- } else if (($this->mOutputType == OT_HTML || $this->mOutputType == OT_PREPROCESS ) &&
+ } else if (($this->mOutputType == OT_HTML || $this->mOutputType == OT_PREPROCESS ) &&
null != $matches['parts'] && count($matches['parts']) > 0) {
$text = $matches['parts'][0];
}
@@ -3337,7 +3397,7 @@ class Parser
global $wgMaxTocLevel, $wgContLang;
$doNumberHeadings = $this->mOptions->getNumberHeadings();
- if( !$this->mTitle->userCanEdit() ) {
+ if( !$this->mTitle->quickUserCan( 'edit' ) ) {
$showEditLink = 0;
} else {
$showEditLink = $this->mOptions->getEditSection();
@@ -3351,7 +3411,8 @@ class Parser
# Get all headlines for numbering them and adding funky stuff like [edit]
# links - this is for later, but we need the number of headlines right now
- $numMatches = preg_match_all( '/)(.*?)<\/H[1-6] *>/i', $text, $matches );
+ $matches = array();
+ $numMatches = preg_match_all( '/[1-6])(?P.*?'.'>)(?P.*?)<\/H[1-6] *>/i', $text, $matches );
# if there are fewer than 4 headlines in the article, do not show TOC
# unless it's been explicitly enabled.
@@ -3378,7 +3439,7 @@ class Parser
}
# We need this to perform operations on the HTML
- $sk =& $this->mOptions->getSkin();
+ $sk = $this->mOptions->getSkin();
# headline counter
$headlineCount = 0;
@@ -3402,7 +3463,7 @@ class Parser
$templatetitle = '';
$templatesection = 0;
$numbering = '';
-
+ $mat = array();
if (preg_match("//", $headline, $mat)) {
$istemplate = 1;
$templatetitle = base64_decode($mat[1]);
@@ -3475,8 +3536,7 @@ class Parser
# The canonized header is a version of the header text safe to use for links
# Avoid insertion of weird stuff like