var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables,
$mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex, $mPreprocessor,
$mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList, $mVarCache, $mConf,
- $mFunctionTagHooks;
+ $mFunctionTagHooks, $mDoTitleConvert, $mDoContentConvert;
# Cleared with clearState():
}
$this->mMarkerIndex = 0;
$this->mFirstCall = true;
+ $this->mDoTitleConvert = true;
+ $this->mDoContentConvert = true;
}
/**
}
$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 ) {
# No more strip!
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
$text = $this->internalParse( $text );
+ // internalParse took care of the notitleconvert bit, so title conversion is here.
+ if ( $this->mDoTitleConvert && !$this->mTitle->isConversionTable()) {
+ $this->setTitle( Title::newFromText( $wgContLang->convert( $title ) ) );
+ }
+
$text = $this->mStripState->unstripGeneral( $text );
# Clean up special characters, only run once, next-to-last before doBlockLevels
$this->replaceLinkHolders( $text );
- # the position of the parserConvert() call should not be changed. it
+ # 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.
- # Side-effects: this calls $this->mOutput->setTitleText()
- $text = $wgContLang->parserConvert( $text, $this );
+ if ( $this->mDoContentConvert && !$this->mTitle->isConversionTable()) {
+ $text = $wgContLang->convert( $text );
+ }
$text = $this->mStripState->unstripNoWiki( $text );
$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 );
}
/**
*/
function internalParse( $text, $isMain = true, $frame=false ) {
wfProfileIn( __METHOD__ );
-
+
$origText = $text;
# Hook to suspend the parser in this state
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 )
+ if( !$frame->depth )
$flag = 0;
else
$flag = Parser::PTD_FOR_INCLUSION;
$text = preg_replace( '/(^|\n)-----*/', '\\1<hr />', $text );
$text = $this->doDoubleUnderscore( $text );
+
$text = $this->doHeadings( $text );
if( $this->mOptions->getUseDynamicDates() ) {
$df = DateFormatter::getInstance();
/**
* Replace special strings like "ISBN xxx" and "RFC xxx" with
* magic external links.
- *
+ *
* DML
* @private
*/
$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
$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
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";
}
} 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;
$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 );
}
$lastPrefix = $prefix2;
}
-
+
// If we have no prefixes, go to paragraph mode.
if( 0 == $prefixLength ) {
wfProfileIn( __METHOD__."-paragraph" );
return null;
}
- if ( $index )
+ if ( $index )
$this->mVarCache[$index] = $value;
return $value;
* 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
*/
function limitationWarn( $limitationType, $current=null, $max=null) {
//does no harm if $current and $max are present but are unnecessary for the message
- $warning = wfMsgExt( "$limitationType-warning", array( 'parsemag', 'escape' ), $current, $max );
+ $warning = wfMsgExt( "$limitationType-warning", array( 'parsemag', 'escape' ), $current, $max );
$this->mOutput->addWarning( $warning );
$this->addTrackingCategory( "$limitationType-category" );
}
$found = true;
$noparse = true;
$preprocessFlags = 0;
-
+
if ( is_array( $result ) ) {
if ( isset( $result[0] ) ) {
$text = $result[0];
* Fills $this->mDoubleUnderscores, returns the modified text
*/
function doDoubleUnderscore( $text ) {
+ global $wgDisableLangConversion;
wfProfileIn( __METHOD__ );
+
// The position of __TOC__ needs to be recorded
$mw = MagicWord::get( 'toc' );
if( $mw->match( $text ) ) {
$this->mOutput->setIndexPolicy( 'index' );
$this->addTrackingCategory( 'index-category' );
}
+
+ if ( !$wgDisableLangConversion ) {
+ if( isset( $this->mDoubleUnderscores['notitleconvert'] ) ){
+ $this->mDoTitleConvert = false;
+ }
+
+ // Don't convert talk pages
+ if( isset( $this->mDoubleUnderscores['nocontentconvert'] )
+ && !$this->mTitle->isTalkPage() ){
+ $this->mDoContentConvert = false;
+ }
+ }
+
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.
*/
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() );
$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 ( $bits['i'] == $sectionIndex )
break;
}
- $byteOffset += mb_strlen( $this->mStripState->unstripBoth(
+ $byteOffset += mb_strlen( $this->mStripState->unstripBoth(
$frame->expand( $node, PPFrame::RECOVER_ORIG ) ) );
$node = $node->getNextSibling();
}
- $tocraw[] = array(
+ $tocraw[] = array(
'toclevel' => $toclevel,
'level' => $level,
'line' => $tocline,
'byteoffset' => ( $isTemplate ? null : $byteOffset ),
'anchor' => $anchor,
);
-
+
# give headline the correct <h#> tag
if( $showEditLink && $sectionIndex !== false ) {
if( $isTemplate ) {
$toc = $sk->tocList( $toc );
$this->mOutput->setTOCHTML( $toc );
}
-
+
if ( $isMain ) {
$this->mOutput->setSections( $tocraw );
}
$blocks = preg_split( '/<H[1-6].*?' . '>.*?<\/H[1-6]>/i', $text );
$i = 0;
-
+
foreach( $blocks as $block ) {
if( $showEditLink && $headlineCount > 0 && $i == 0 && $block !== "\n" ) {
# This is the [edit] link that appears for the top block of text when
return $full;
}
}
-
+
/**
* Merge $tree2 into $tree1 by replacing the section with index
* $section in $tree1 and its descendants with the sections in $tree2.
$numbering = array( 0 );
$titletext = $title->getPrefixedDBkey();
foreach ( $tree1 as $s ) {
- if ( $targetLevel !== false ) {
+ if ( $targetLevel !== false ) {
if ( $s['level'] <= $targetLevel )
// We've skipped enough
$targetLevel = false;
$s['fromtitle'] != $titletext ) {
self::incrementNumbering( $numbering,
$s['toclevel'], $lastLevel );
-
+
// Rewrite index, byteoffset and number
if ( $s['fromtitle'] == $titletext ) {
$s['index'] = $nextIndex++;
$s2['level'] += $s['level'] - 1;
$s2['index'] = $nextIndex++;
$s2['byteoffset'] += $s['byteoffset'];
-
+
self::incrementNumbering( $numbering,
$s2['toclevel'], $lastLevel );
$s2['number'] = implode( '.', array_map(
}
return $newTree;
}
-
+
/**
* Increment a section number. Helper function for mergeSectionTrees()
* @param $number array Array representing a section number
} else
$number[$level - 1]++;
}
-
+
/**
* Transform wiki markup when saving a page by doing \r\n -> \n
* conversion, substitting signatures, {{subst:}} templates, etc.
global $wgMaxSigChars;
$username = $user->getName();
-
+
// 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 ) {
* @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
unset( $params[ 'href' ] );
} else {
# Non-link <a> tag
- return Xml::openElement( 'a', $params ) . $content . Xml::closeElement( 'a' );
+ return Xml::openElement( 'a', $params ) . $content . Xml::closeElement( 'a' );
}
$sk = $this->mOptions->getSkin();
if ( count( $matches ) == 0 ) {
continue;
}
-
+
if ( strpos( $matches[0], '%' ) !== false )
$matches[1] = urldecode( $matches[1] );
$tp = Title::newFromText( $matches[1]/*, NS_FILE*/ );
# * 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
+ # * link Set the target of the image link. Can be external, interwiki, or local
# vertical-align values (no % or length right now):
# * baseline
# * sub
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
# remove the tags
$tooltip = $this->mStripState->unstripBoth( $tooltip );
$tooltip = Sanitizer::stripAllTags( $tooltip );
-
+
return $tooltip;
}
$links['interwiki'][] = $this->mLinkHolders->interwiki[$key];
$pos = $start_pos + strlen( "<!--IWLINK $key-->" );
}
-
+
$data['linkholder'] = $links;
return $data;
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 );
var $mTablesLoaded = false;
var $mTables;
var $mNamespaceTables;
- var $mDoTitleConvert = true, $mDoContentConvert = true;
// 'bidirectional' 'unidirectional' 'disable' for each variant
var $mManualLevel;
- var $mTitleFromFlag = false;
var $mCacheKey;
var $mLangObj;
var $mMarkup;
var $mFlags;
var $mDescCodeSep = ':', $mDescVarSep = ';';
var $mUcfirst = false;
- var $mTitleOriginal = '';
- var $mTitleDisplay = '';
- var $mHeaderVariant = null;
const CACHE_VERSION_KEY = 'VERSION 6';
// use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom
// conversion in title
$title = $convRule->getTitle();
- if ( $title ) {
- $this->mTitleFromFlag = true;
- $this->mTitleDisplay = $title;
- }
// apply manual conversion table to global table
$convTable = $convRule->getConvTable();
}
}
- /**
- * Convert text using a parser object for context.
- * @public
- */
- function parserConvert( $text, &$parser ) {
- global $wgDisableLangConversion;
- /* don't do anything if this is the conversion table */
- if ( $parser->getTitle()->getNamespace() == NS_MEDIAWIKI
- && strpos( $parser->mTitle->getText(),
- 'Conversiontable' ) !== false ) {
- return $text;
- }
-
- if ( $wgDisableLangConversion ) {
- return $text;
- }
-
- $text = $this->convert( $text );
-
- $this->convertTitle();
- $parser->mOutput->setTitleText( $this->mTitleDisplay );
-
- return $text;
- }
-
/**
* Convert namespace.
* @param string $title the title included namespace
}
/**
- * Pre convert title. Store the original title $this->mTitleOrginal;
- * store the default converted title to $this->mTitleDisplay.
- * @private
- */
- function preConvertTitle( $text, $variant ) {
- $this->mTitleOriginal = $text;
-
- $text = $this->convertNamespace( $text, $variant );
- $this->mTitleDisplay = $this->convert( $text );
- }
-
- /**
- * Convert title.
+ * Convert a text fragment.
+ *
+ * @param string $text text to be converted
+ * @param string $plang preferred variant
+ * @return string converted text
* @private
*/
- function convertTitle() {
- global $wgDisableTitleConversion, $wgUser, $wgRequest;
- $isredir = $wgRequest->getText( 'redirect', 'yes' );
- $action = $wgRequest->getText( 'action' );
- $linkconvert = $wgRequest->getText( 'linkconvert', 'yes' );
+ function convertFragment( $text, $plang ) {
+ $marked = explode( $this->mMarkup['begin'], $text, 2 );
+ $converted = '';
+
+ if ( $this->mDoContentConvert ) {
+ // Bug 19620: should convert a string immediately after a
+ // new rule added.
+ $converted .= $this->autoConvert( $marked[0], $plang );
+ } else {
+ $converted .= $marked[0];
+ }
- // check for the global variable, __NOTC__ magic word, and user setting
- if ( $wgDisableTitleConversion || !$this->mDoTitleConvert ||
- $wgUser->getOption( 'noconvertlink' ) == 1 ) {
- $this->mTitleDisplay = $this->mTitleOriginal;
- } elseif ( $isredir == 'no'
- || $action == 'edit'
- || $linkconvert == 'no' ) {
- // check for GET params
- $this->mTitleDisplay = $this->mTitleOriginal;
+ if ( array_key_exists( 1, $marked ) ) {
+ $crule = new ConverterRule( $marked[1], $this );
+ $crule->parse( $plang );
+ $converted .= $crule->getDisplay();
+ $this->applyManualConv( $crule );
+ } else {
+ $converted .= $this->mMarkup['end'];
}
+
+ return $converted;
}
/**
* -{text}- in which case no conversion should take place for text
*
* @param string $text text to be converted
- * @param bool $isTitle whether this conversion is for the article title
* @return string converted text
* @public
*/
- function convert( $text, $isTitle = false ) {
-
- $mw =& MagicWord::get( 'notitleconvert' );
- if ( $mw->matchAndRemove( $text ) ) {
- $this->mDoTitleConvert = false;
- }
- $mw =& MagicWord::get( 'nocontentconvert' );
- if ( $mw->matchAndRemove( $text ) ) {
- $this->mDoContentConvert = false;
- }
-
- // no conversion if redirecting
- $mw =& MagicWord::get( 'redirect' );
- if ( $mw->matchStart( $text ) ) {
- return $text;
- }
+ function convert( $text ) {
+ if ( $wgDisableLangConversion ) return $text;
$plang = $this->getPreferredVariant();
-
- // for title convertion
- if ( $isTitle ) {
- $this->preConvertTitle( $text, $plang );
- return $text;
- }
-
$tarray = StringUtils::explode( $this->mMarkup['end'], $text );
- $text = '';
+ $converted = '';
foreach ( $tarray as $txt ) {
-
- $marked = explode( $this->mMarkup['begin'], $txt, 2 );
-
- if ( $this->mDoContentConvert ) {
- // Bug 19620: should convert a string immediately after a
- // new rule added.
- $text .= $this->autoConvert( $marked[0], $plang );
- } else {
- $text .= $marked[0];
- }
-
- if ( array_key_exists( 1, $marked ) ) {
- $crule = new ConverterRule( $marked[1], $this );
- $crule->parse( $plang );
- $text .= $crule->getDisplay();
- $this->applyManualConv( $crule );
- } else {
- $text .= $this->mMarkup['end'];
- }
+ $converted .= $this->convertFragment( $txt, $plang );
}
// Remove the last delimiter (wasn't real)
- $text = substr( $text, 0, - strlen( $this->mMarkup['end'] ) );
- return $text;
+ $converted = substr( $converted, 0, - strlen( $this->mMarkup['end'] ) );
+ if ( $isTitle ) {
+ error_log("title2: $converted\n");
+ $this->mConvertedTitle = $converted;
+ }
+ return $converted;
}
/**
return '!' . $variant ;
}
- /**
- * Get title text as defined in the body of the article text.
- *
- * @public
- */
- function getParsedTitle() {
- return $this->mTitleDisplay;
- }
-
/**
* Load default conversion tables.
* This method must be implemented in derived class.
// proces H,- flag or T only: output nothing
$this->mRuleDisplay = '';
} elseif ( in_array( 'S', $flags ) ) {
- $this->mRuleDisplay = $this->getRuleConvertedStr( $variant,
- $this->mConverter->mDoContentConvert );
+ // true hard-coded now since we shouldn't be called if we're not converting
+ $this->mRuleDisplay = $this->getRuleConvertedStr( $variant, true );
} else {
$this->mRuleDisplay = $this->mManualCodeError;
}
- // proces T flag
+ // process T flag
if ( in_array( 'T', $flags ) ) {
- $this->mRuleTitle = $this->getRuleConvertedStr( $variant,
- $this->mConverter->mDoTitleConvert );
+ // true hard-coded now since we shouldn't be called if we're not converting
+ $this->mRuleTitle = $this->getRuleConvertedStr( $variant, true );
}
if ( in_array( '-', $flags ) ) {