}
/**
- * Get an unanchored regex
+ * Get an unanchored regex that does not match parameters
*/
function getRegex() {
if ( is_null( $this->regex ) ) {
}
/**
- * Get a regex for matching variables
+ * Get a regex for matching variables with parameters
*/
function getVariableRegex() {
return str_replace( "\\$1", "(.*?)", $this->getRegex() );
}
/**
- * Get a regex for matching a prefix. Does not match parameters.
+ * Get a regex anchored to the start of the string that does not match parameters
*/
function getRegexStart() {
$base = $this->getBaseRegex();
$newRegex = array( '', '' );
if ( $base[0] !== '' ) {
- $newRegex[0] = str_replace( "\\$1", "", "/^(?:{$base[0]})/iuS" );
+ $newRegex[0] = "/^(?:{$base[0]})/iuS";
}
if ( $base[1] !== '' ) {
- $newRegex[1] = str_replace( "\\$1", "", "/^(?:{$base[1]})/S" );
+ $newRegex[1] = "/^(?:{$base[1]})/S";
}
return $newRegex;
}
/**
- * Get an anchored regex for matching variables
+ * Get an anchored regex for matching variables with parameters
*/
function getVariableStartToEndRegex() {
$base = $this->getBaseRegex();
}
/**
- * Returns the magic word id removed from the start, or false
- * does not match parameters.
+ * Return the ID of the magic word at the start of $text, and remove
+ * the prefix from $text.
+ * Return false if no match found and $text is not modified.
+ * Does not match parameters.
*/
public function matchStartAndRemove( &$text ) {
- $found = FALSE;
$regexes = $this->getRegexStart();
foreach ( $regexes as $regex ) {
if ( $regex === '' ) {
continue;
}
- preg_match_all( $regex, $text, $matches, PREG_SET_ORDER );
- foreach ( $matches as $m ) {
- list( $found, $param ) = $this->parseMatch( $m );
+ preg_match( $regex, $text, $match );
+ if ( $match ) {
+ list( $found, $param ) = $this->parseMatch( $match );
+ $text = substr( $text, strlen( $found ) + 1 );
+ return $found;
}
- $text = preg_replace( $regex, '', $text );
}
- return $found;
+ return false;
}
}
*/
# Persistent:
var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables,
- $mSubsts, $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex,
+ $mSubstWords, $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex,
$mPreprocessor, $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList,
$mVarCache, $mConf, $mFunctionTagHooks;
$substIDs = MagicWord::getSubstIDs();
$this->mVariables = new MagicWordArray( $variableIDs );
- $this->mSubsts = new MagicWordArray( $substIDs );
+ $this->mSubstWords = new MagicWordArray( $substIDs );
wfProfileOut( __METHOD__ );
}
wfProfileIn( __METHOD__.'-modifiers' );
if ( !$found ) {
- $substMatch = $this->mSubsts->matchStartAndRemove( $part1 );
+ $substMatch = $this->mSubstWords->matchStartAndRemove( $part1 );
# Possibilities for substMatch: "subst", "safesubst" or FALSE
- # Whether to include depends also on whether we are in the pre-save-transform
- #
- # safesubst || (subst && PST) || (false && !PST) => transclude (skip the if)
- # (false && PST) || (subst && !PST) => return input (handled by if)
- if ( $substMatch != 'safesubst' && ($substMatch == 'subst' xor $this->ot['wiki']) ) {
+ # 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;