Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | */ |
96 | 96 | # Persistent: |
97 | 97 | var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables, |
98 | | - $mSubsts, $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex, |
| 98 | + $mSubstWords, $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex, |
99 | 99 | $mPreprocessor, $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList, |
100 | 100 | $mVarCache, $mConf, $mFunctionTagHooks; |
101 | 101 | |
— | — | @@ -2690,7 +2690,7 @@ |
2691 | 2691 | $substIDs = MagicWord::getSubstIDs(); |
2692 | 2692 | |
2693 | 2693 | $this->mVariables = new MagicWordArray( $variableIDs ); |
2694 | | - $this->mSubsts = new MagicWordArray( $substIDs ); |
| 2694 | + $this->mSubstWords = new MagicWordArray( $substIDs ); |
2695 | 2695 | wfProfileOut( __METHOD__ ); |
2696 | 2696 | } |
2697 | 2697 | |
— | — | @@ -2862,14 +2862,25 @@ |
2863 | 2863 | wfProfileIn( __METHOD__.'-modifiers' ); |
2864 | 2864 | if ( !$found ) { |
2865 | 2865 | |
2866 | | - $substMatch = $this->mSubsts->matchStartAndRemove( $part1 ); |
| 2866 | + $substMatch = $this->mSubstWords->matchStartAndRemove( $part1 ); |
2867 | 2867 | |
2868 | 2868 | # Possibilities for substMatch: "subst", "safesubst" or FALSE |
2869 | | - # Whether to include depends also on whether we are in the pre-save-transform |
2870 | | - # |
2871 | | - # safesubst || (subst && PST) || (false && !PST) => transclude (skip the if) |
2872 | | - # (false && PST) || (subst && !PST) => return input (handled by if) |
2873 | | - if ( $substMatch != 'safesubst' && ($substMatch == 'subst' xor $this->ot['wiki']) ) { |
| 2869 | + # Decide whether to expand template or keep wikitext as-is. |
| 2870 | + if ( $this->ot['wiki'] ) |
| 2871 | + { |
| 2872 | + if ( $substMatch === false ) { |
| 2873 | + $literal = true; # literal when in PST with no prefix |
| 2874 | + } else { |
| 2875 | + $literal = false; # expand when in PST with subst: or safesubst: |
| 2876 | + } |
| 2877 | + } else { |
| 2878 | + if ( $substMatch == 'subst' ) { |
| 2879 | + $literal = true; # literal when not in PST with plain subst: |
| 2880 | + } else { |
| 2881 | + $literal = false; # expand when not in PST with safesubst: or no prefix |
| 2882 | + } |
| 2883 | + } |
| 2884 | + if ( $literal ) { |
2874 | 2885 | $text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args ); |
2875 | 2886 | $isLocalObj = true; |
2876 | 2887 | $found = true; |
Index: trunk/phase3/includes/MagicWord.php |
— | — | @@ -572,7 +572,7 @@ |
573 | 573 | } |
574 | 574 | |
575 | 575 | /** |
576 | | - * Get an unanchored regex |
| 576 | + * Get an unanchored regex that does not match parameters |
577 | 577 | */ |
578 | 578 | function getRegex() { |
579 | 579 | if ( is_null( $this->regex ) ) { |
— | — | @@ -589,29 +589,29 @@ |
590 | 590 | } |
591 | 591 | |
592 | 592 | /** |
593 | | - * Get a regex for matching variables |
| 593 | + * Get a regex for matching variables with parameters |
594 | 594 | */ |
595 | 595 | function getVariableRegex() { |
596 | 596 | return str_replace( "\\$1", "(.*?)", $this->getRegex() ); |
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
600 | | - * Get a regex for matching a prefix. Does not match parameters. |
| 600 | + * Get a regex anchored to the start of the string that does not match parameters |
601 | 601 | */ |
602 | 602 | function getRegexStart() { |
603 | 603 | $base = $this->getBaseRegex(); |
604 | 604 | $newRegex = array( '', '' ); |
605 | 605 | if ( $base[0] !== '' ) { |
606 | | - $newRegex[0] = str_replace( "\\$1", "", "/^(?:{$base[0]})/iuS" ); |
| 606 | + $newRegex[0] = "/^(?:{$base[0]})/iuS"; |
607 | 607 | } |
608 | 608 | if ( $base[1] !== '' ) { |
609 | | - $newRegex[1] = str_replace( "\\$1", "", "/^(?:{$base[1]})/S" ); |
| 609 | + $newRegex[1] = "/^(?:{$base[1]})/S"; |
610 | 610 | } |
611 | 611 | return $newRegex; |
612 | 612 | } |
613 | 613 | |
614 | 614 | /** |
615 | | - * Get an anchored regex for matching variables |
| 615 | + * Get an anchored regex for matching variables with parameters |
616 | 616 | */ |
617 | 617 | function getVariableStartToEndRegex() { |
618 | 618 | $base = $this->getBaseRegex(); |
— | — | @@ -710,22 +710,24 @@ |
711 | 711 | } |
712 | 712 | |
713 | 713 | /** |
714 | | - * Returns the magic word id removed from the start, or false |
715 | | - * does not match parameters. |
| 714 | + * Return the ID of the magic word at the start of $text, and remove |
| 715 | + * the prefix from $text. |
| 716 | + * Return false if no match found and $text is not modified. |
| 717 | + * Does not match parameters. |
716 | 718 | */ |
717 | 719 | public function matchStartAndRemove( &$text ) { |
718 | | - $found = FALSE; |
719 | 720 | $regexes = $this->getRegexStart(); |
720 | 721 | foreach ( $regexes as $regex ) { |
721 | 722 | if ( $regex === '' ) { |
722 | 723 | continue; |
723 | 724 | } |
724 | | - preg_match_all( $regex, $text, $matches, PREG_SET_ORDER ); |
725 | | - foreach ( $matches as $m ) { |
726 | | - list( $found, $param ) = $this->parseMatch( $m ); |
| 725 | + preg_match( $regex, $text, $match ); |
| 726 | + if ( $match ) { |
| 727 | + list( $found, $param ) = $this->parseMatch( $match ); |
| 728 | + $text = substr( $text, strlen( $found ) + 1 ); |
| 729 | + return $found; |
727 | 730 | } |
728 | | - $text = preg_replace( $regex, '', $text ); |
729 | 731 | } |
730 | | - return $found; |
| 732 | + return false; |
731 | 733 | } |
732 | 734 | } |