# prefix for escaping, used in two functions at least
define( "UNIQ_PREFIX", "NaodW29");
-/* private */ $wgParserHooks = array();
-
class Parser
{
+ # Persistent:
+ var $mTagHooks;
+
# Cleared with clearState():
var $mOutput, $mAutonumber, $mDTopen, $mStripState = array();
var $mVariables, $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
# Temporary:
var $mOptions, $mTitle, $mOutputType;
- function Parser()
- {
+ function Parser() {
+ $this->mTagHooks = array();
$this->clearState();
}
- function clearState()
- {
+ function clearState() {
$this->mOutput = new ParserOutput;
$this->mAutonumber = 0;
$this->mLastSection = "";
#
# Returns a ParserOutput
#
- function parse( $text, &$title, $options, $linestart = true, $clearState = true )
- {
+ function parse( $text, &$title, $options, $linestart = true, $clearState = true ) {
global $wgUseTidy;
$fname = "Parser::parse";
wfProfileIn( $fname );
return $this->mOutput;
}
- /* static */ function getRandomString()
- {
+ /* static */ function getRandomString() {
return dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff));
}
# 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
- function strip( $text, &$state, $stripcomments = false )
- {
- global $wgParserHooks;
-
+ function strip( $text, &$state, $stripcomments = false ) {
$render = ($this->mOutputType == OT_HTML);
$nowiki_content = array();
$math_content = array();
}
# Extensions
- foreach ( $wgParserHooks as $tag => $callback ) {
+ foreach ( $this->mTagHooks as $tag => $callback ) {
$ext_contents[$tag] = array();
$text = Parser::extractTags( $tag, $text, $ext_content[$tag], $uniq_prefix );
foreach( $ext_content[$tag] as $marker => $content ) {
}
# always call unstripNoWiki() after this one
- function unstrip( $text, &$state )
- {
+ function unstrip( $text, &$state ) {
# Must expand in reverse order, otherwise nested tags will be corrupted
$contentDict = end( $state );
for ( $contentDict = end( $state ); $contentDict !== false; $contentDict = prev( $state ) ) {
return $text;
}
# always call this after unstrip() to preserve the order
- function unstripNoWiki( $text, &$state )
- {
+ function unstripNoWiki( $text, &$state ) {
# Must expand in reverse order, otherwise nested tags will be corrupted
for ( $content = end($state['nowiki']); $content !== false; $content = prev( $state['nowiki'] ) ) {
$text = str_replace( key( $state['nowiki'] ), $content, $text );
# Returns the unique tag which must be inserted into the stripped text
# The tag will be replaced with the original text in unstrip()
- function insertStripItem( $text, &$state )
- {
+ function insertStripItem( $text, &$state ) {
$rnd = UNIQ_PREFIX . '-item' . Parser::getRandomString();
if ( !$state ) {
$state = array(
# or the old code. The new code will not work properly for some
# languages due to sorting issues, so they might want to turn it
# off.
- function categoryMagic()
- {
+ function categoryMagic() {
$msg = wfMsg('usenewcategorypage');
if ( '0' == @$msg[0] )
{
}
# This method generates the list of subcategories and pages for a category
- function oldCategoryMagic ()
- {
+ function oldCategoryMagic () {
global $wgLang , $wgUser ;
if ( !$this->mOptions->getUseCategoryMagic() ) return ; # Doesn't use categories at all
- function newCategoryMagic ()
- {
+ function newCategoryMagic () {
global $wgLang , $wgUser ;
if ( !$this->mOptions->getUseCategoryMagic() ) return ; # Doesn't use categories at all
}
# Return allowed HTML attributes
- function getHTMLattrs ()
- {
+ function getHTMLattrs () {
$htmlattrs = array( # Allowed attributes--no scripting, etc.
'title', 'align', 'lang', 'dir', 'width', 'height',
'bgcolor', 'clear', /* BR */ 'noshade', /* HR */
}
# Remove non approved attributes and javascript in css
- function fixTagAttributes ( $t )
- {
+ function fixTagAttributes ( $t ) {
if ( trim ( $t ) == '' ) return '' ; # Saves runtime ;-)
$htmlattrs = $this->getHTMLattrs() ;
}
# parse the wiki syntax used to render tables
- function doTableStuff ( $t )
- {
+ function doTableStuff ( $t ) {
$t = explode ( "\n" , $t ) ;
$td = array () ; # Is currently a td tag open?
$ltd = array () ; # Was it TD or TH?
return $newline.$this->insertStripItem( $text, $this->mStripState );
}
- function internalParse( $text, $linestart, $args = array(), $isMain=true )
- {
+ function internalParse( $text, $linestart, $args = array(), $isMain=true ) {
$fname = 'Parser::internalParse';
wfProfileIn( $fname );
}
# Parse headers and return html
- /* private */ function doHeadings( $text )
- {
+ /* private */ function doHeadings( $text ) {
$fname = 'Parser::doHeadings';
wfProfileIn( $fname );
for ( $i = 6; $i >= 1; --$i ) {
return $text;
}
- /* private */ function doAllQuotes( $text )
- {
+ /* private */ function doAllQuotes( $text ) {
$fname = 'Parser::doAllQuotes';
wfProfileIn( $fname );
$outtext = '';
return $outtext;
}
- /* private */ function doQuotes( $pre, $text, $mode )
- {
+ /* private */ function doQuotes( $pre, $text, $mode ) {
if ( preg_match( "/^(.*)''(.*)$/sU", $text, $m ) ) {
$m1_strong = ($m[1] == "") ? "" : "<strong>{$m[1]}</strong>";
$m1_em = ($m[1] == "") ? "" : "<em>{$m[1]}</em>";
# and otherwise take great care in the order of things here, so
# that we don't end up interpreting some URLs twice.
- /* private */ function replaceExternalLinks( $text )
- {
+ /* private */ function replaceExternalLinks( $text ) {
$fname = 'Parser::replaceExternalLinks';
wfProfileIn( $fname );
$text = $this->subReplaceExternalLinks( $text, 'http', true );
return $text;
}
- /* private */ function subReplaceExternalLinks( $s, $protocol, $autonumber )
- {
+ /* private */ function subReplaceExternalLinks( $s, $protocol, $autonumber ) {
$unique = '4jzAfzB8hNvf4sqyO9Edd8pSmk9rE2in0Tgw3';
$uc = "A-Za-z0-9_\\/~%\\-+&*#?!=()@\\x80-\\xFF";
}
- /* private */ function replaceInternalLinks( $s )
- {
+ /* private */ function replaceInternalLinks( $s ) {
global $wgLang, $wgLinkCache;
global $wgNamespacesWithSubpages, $wgLanguageCode;
static $fname = 'Parser::replaceInternalLinks' ;
# Some functions here used by doBlockLevels()
#
- /* private */ function closeParagraph()
- {
+ /* private */ function closeParagraph() {
$result = '';
if ( '' != $this->mLastSection ) {
$result = '</' . $this->mLastSection . ">\n";
# getCommon() returns the length of the longest common substring
# of both arguments, starting at the beginning of both.
#
- /* private */ function getCommon( $st1, $st2 )
- {
+ /* private */ function getCommon( $st1, $st2 ) {
$fl = strlen( $st1 );
$shorter = strlen( $st2 );
if ( $fl < $shorter ) { $shorter = $fl; }
return $result;
}
- /* private */ function nextItem( $char )
- {
+ /* private */ function nextItem( $char ) {
if ( '*' == $char || '#' == $char ) { return '</li><li>'; }
else if ( ':' == $char || ';' == $char ) {
$close = "</dd>";
return '<!-- ERR 2 -->';
}
- /* private */function closeList( $char )
- {
+ /* private */function closeList( $char ) {
if ( '*' == $char ) { $text = '</li></ul>'; }
else if ( '#' == $char ) { $text = '</li></ol>'; }
else if ( ':' == $char ) {
}
# initialise the magic variables (like CURRENTMONTHNAME)
- function initialiseVariables()
- {
+ function initialiseVariables() {
global $wgVariableIDs;
$this->mVariables = array();
foreach ( $wgVariableIDs as $id ) {
}
}
- /* private */ function replaceVariables( $text, $args = array() )
- {
+ /* private */ function handleBraces( $text, $args = array() ) {
+
+
+
+
+
+ /* private */ function replaceVariables( $text, $args = array() ) {
global $wgLang, $wgScript, $wgArticlePath;
$fname = 'Parser::replaceVariables';
return $text;
}
- function variableSubstitution( $matches )
- {
+ function variableSubstitution( $matches ) {
if ( array_key_exists( $matches[1], $this->mVariables ) ) {
$text = $this->mVariables[$matches[1]];
$this->mOutput->mContainsOldMagic = true;
return $text;
}
- function braceSubstitution( $matches )
- {
+ function braceSubstitution( $matches ) {
global $wgLinkCache, $wgLang;
$fname = 'Parser::braceSubstitution';
$found = false;
}
# Triple brace replacement -- used for template arguments
- function argSubstitution( $matches )
- {
+ function argSubstitution( $matches ) {
$newline = $matches[1];
$arg = trim( $matches[2] );
$text = $matches[0];
}
# Returns true if the function is allowed to include this entity
- function incrementIncludeCount( $dbk )
- {
+ function incrementIncludeCount( $dbk ) {
if ( !array_key_exists( $dbk, $this->mIncludeCount ) ) {
$this->mIncludeCount[$dbk] = 0;
}
# Cleans up HTML, removes dangerous tags and attributes
- /* private */ function removeHTMLtags( $text )
- {
+ /* private */ function removeHTMLtags( $text ) {
global $wgUseTidy, $wgUserHtml;
$fname = 'Parser::removeHTMLtags';
wfProfileIn( $fname );
*
*/
- /* private */ function formatHeadings( $text, $isMain=true )
- {
+ /* private */ function formatHeadings( $text, $isMain=true ) {
global $wgInputEncoding;
$doNumberHeadings = $this->mOptions->getNumberHeadings();
}
# Return an HTML link for the "ISBN 123456" text
- /* private */ function magicISBN( $text )
- {
+ /* private */ function magicISBN( $text ) {
global $wgLang;
$a = split( 'ISBN ', " $text" );
}
# Return an HTML link for the "RFC 1234" text
- /* private */ function magicRFC( $text )
- {
+ /* private */ function magicRFC( $text ) {
global $wgLang;
$a = split( 'RFC ', ' '.$text );
return $text;
}
- function preSaveTransform( $text, &$title, &$user, $options, $clearState = true )
- {
+ function preSaveTransform( $text, &$title, &$user, $options, $clearState = true ) {
$this->mOptions = $options;
$this->mTitle =& $title;
$this->mOutputType = OT_WIKI;
return $text;
}
- /* private */ function pstPass2( $text, &$user )
- {
+ /* private */ function pstPass2( $text, &$user ) {
global $wgLang, $wgLocaltimezone, $wgCurParser;
# Variable replacement
# Set up some variables which are usually set up in parse()
# so that an external function can call some class members with confidence
- function startExternalParse( &$title, $options, $outputType, $clearState = true )
- {
+ function startExternalParse( &$title, $options, $outputType, $clearState = true ) {
$this->mTitle =& $title;
$this->mOptions = $options;
$this->mOutputType = $outputType;
# Create an HTML-style tag, e.g. <yourtag>special text</yourtag>
# Callback will be called with the text within
# Transform and return the text within
- /* static */ function setHook( $tag, $callback ) {
- global $wgParserHooks;
- $oldVal = @$wgParserHooks[$tag];
- $wgParserHooks[$tag] = $callback;
+ function setHook( $tag, $callback ) {
+ $oldVal = @$this->mTagHooks[$tag];
+ $this->mTagHooks[$tag] = $callback;
return $oldVal;
}
}
var $mNumberHeadings; # Automatically number headings
var $mShowToc; # Show table of contents
- function getUseTeX() { return $this->mUseTeX; }
- function getUseCategoryMagic() { return $this->mUseCategoryMagic; }
- function getUseDynamicDates() { return $this->mUseDynamicDates; }
- function getInterwikiMagic() { return $this->mInterwikiMagic; }
- function getAllowExternalImages() { return $this->mAllowExternalImages; }
- function getSkin() { return $this->mSkin; }
- function getDateFormat() { return $this->mDateFormat; }
- function getEditSection() { return $this->mEditSection; }
- function getEditSectionOnRightClick() { return $this->mEditSectionOnRightClick; }
- function getNumberHeadings() { return $this->mNumberHeadings; }
- function getShowToc() { return $this->mShowToc; }
-
- function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); }
- function setUseCategoryMagic( $x ) { return wfSetVar( $this->mUseCategoryMagic, $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 ); }
- function setSkin( $x ) { return wfSetRef( $this->mSkin, $x ); }
- function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); }
- function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); }
- function setEditSectionOnRightClick( $x ) { return wfSetVar( $this->mEditSectionOnRightClick, $x ); }
- function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); }
- function setShowToc( $x ) { return wfSetVar( $this->mShowToc, $x ); }
-
- /* static */ function newFromUser( &$user )
- {
+ function getUseTeX() { return $this->mUseTeX; }
+ function getUseCategoryMagic() { return $this->mUseCategoryMagic; }
+ function getUseDynamicDates() { return $this->mUseDynamicDates; }
+ function getInterwikiMagic() { return $this->mInterwikiMagic; }
+ function getAllowExternalImages() { return $this->mAllowExternalImages; }
+ function getSkin() { return $this->mSkin; }
+ function getDateFormat() { return $this->mDateFormat; }
+ function getEditSection() { return $this->mEditSection; }
+ function getEditSectionOnRightClick() { return $this->mEditSectionOnRightClick; }
+ function getNumberHeadings() { return $this->mNumberHeadings; }
+ function getShowToc() { return $this->mShowToc; }
+
+ function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); }
+ function setUseCategoryMagic( $x ) { return wfSetVar( $this->mUseCategoryMagic, $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 ); }
+ function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); }
+ function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); }
+ function setEditSectionOnRightClick( $x ) { return wfSetVar( $this->mEditSectionOnRightClick, $x ); }
+ function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); }
+ function setShowToc( $x ) { return wfSetVar( $this->mShowToc, $x ); }
+
+ function setSkin( &$x ) { $this->mSkin =& $x; }
+
+ /* static */ function newFromUser( &$user ) {
$popts = new ParserOptions;
$popts->initialiseFromUser( $user );
return $popts;
}
- function initialiseFromUser( &$userInput )
- {
+ function initialiseFromUser( &$userInput ) {
global $wgUseTeX, $wgUseCategoryMagic, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
if ( !$userInput ) {