instead add some proper functions to MagicWord.php to deal with the situation.
return str_replace( "\\$1", "(.*?)", $this->getRegex() );
}
+ /**
+ * Get a regex for matching a prefix. Does not match parameters.
+ */
+ function getRegexStart() {
+ $base = $this->getBaseRegex();
+ $newRegex = array( '', '' );
+ if ( $base[0] !== '' ) {
+ $newRegex[0] = str_replace( "\\$1", "", "/^(?:{$base[0]})/iuS" );
+ }
+ if ( $base[1] !== '' ) {
+ $newRegex[1] = str_replace( "\\$1", "", "/^(?:{$base[1]})/S" );
+ }
+ return $newRegex;
+ }
+
/**
* Get an anchored regex for matching variables
*/
}
return $found;
}
+
+ /**
+ * Returns the magic word id removed from the start, or false
+ * 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 );
+ }
+ $text = preg_replace( $regex, '', $text );
+ }
+ return $found;
+ }
}
wfProfileIn( __METHOD__.'-modifiers' );
if ( !$found ) {
- $substMatch = $this->mSubsts->matchVariableStartToEnd( $part1 );
+ $substMatch = $this->mSubsts->matchStartAndRemove( $part1 );
- # Possibilities for substMatch[0]: "subst", "safesubst" or FALSE
+ # Possibilities for substMatch: "subst", "safesubst" or FALSE
# Whether to include depends also on whether we are in the pre-save-transform
#
- # safesubst || (subst && PST) => transclude (handled by if)
- # (false && PST) || (subst && !PST) => return input (handled by else if)
- # false && !PST => transclude (no handling needed here)
- if ( $substMatch[0] && ( $this->ot['wiki'] || $substMatch[0] == 'safesubst' ) ) {
- $part1 = $substMatch[1];
-
- } else if ( $substMatch[0] xor $this->ot['wiki'] ) {
+ # 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']) ) {
$text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args );
$isLocalObj = true;
$found = true;
'subjectpagename' => array( 1, 'SUBJECTPAGENAME', 'ARTICLEPAGENAME' ),
'subjectpagenamee' => array( 1, 'SUBJECTPAGENAMEE', 'ARTICLEPAGENAMEE' ),
'msg' => array( 0, 'MSG:' ),
- 'subst' => array( 0, 'SUBST:$1' ),
- 'safesubst' => array( 0, 'SAFESUBST:$1' ),
+ 'subst' => array( 0, 'SUBST:' ),
+ 'safesubst' => array( 0, 'SAFESUBST:' ),
'msgnw' => array( 0, 'MSGNW:' ),
'img_thumbnail' => array( 1, 'thumbnail', 'thumb' ),
'img_manualthumb' => array( 1, 'thumbnail=$1', 'thumb=$1'),